diff --git a/src/app/main.cpp b/src/app/main.cpp index 877811d4..bbf36481 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -281,13 +281,15 @@ int main(int argc, char *argv[]) else { #ifdef _WIN32 - HWND consoleWnd = GetConsoleWindow(); - DWORD dwProcessId; - GetWindowThreadProcessId(consoleWnd, &dwProcessId); - if (GetCurrentProcessId() == dwProcessId) { - // Sourcetrail has not been started from console and thus has it's own console - ShowWindow(consoleWnd, SW_HIDE); + HWND consoleWnd = GetConsoleWindow(); + DWORD dwProcessId; + GetWindowThreadProcessId(consoleWnd, &dwProcessId); + if (GetCurrentProcessId() == dwProcessId) + { + // Sourcetrail has not been started from console and thus has it's own console + ShowWindow(consoleWnd, SW_HIDE); + } } #endif QtApplication qtApp(argc, argv); diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp index e013fb62..fdf8c60a 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp @@ -461,6 +461,12 @@ bool CxxAstVisitor::TraverseBinComma(clang::BinaryOperator* s) return true; } +bool CxxAstVisitor::TraverseDeclarationNameInfo(clang::DeclarationNameInfo NameInfo) +{ + // we don't visit any children here + return true; +} + void CxxAstVisitor::traverseDeclContextHelper(clang::DeclContext* d) { if (!d) @@ -682,15 +688,18 @@ ParseLocation CxxAstVisitor::getParseLocation(const clang::SourceRange& sourceRa { const clang::SourceManager& sourceManager = m_astContext->getSourceManager(); - const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(sourceRange.getBegin(), false); - const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false); + const clang::SourceLocation startLoc = sourceRange.getBegin(); + const clang::SourceLocation endLoc = m_preprocessor->getLocForEndOfToken(sourceRange.getEnd()); + + const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(startLoc, false); + const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(endLoc, false); parseLocation = ParseLocation( m_canonicalFilePathCache->getValue(presumedBegin.getFilename()), presumedBegin.getLine(), presumedBegin.getColumn(), presumedEnd.getLine(), - presumedEnd.getColumn() + presumedEnd.getColumn() - 1 ); } return parseLocation; diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h index 215b750e..5e1e2493 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h @@ -91,6 +91,8 @@ public: virtual bool TraverseLambdaCapture(clang::LambdaExpr* lambdaExpr, const clang::LambdaCapture* capture, clang::Expr *Init); virtual bool TraverseBinComma(clang::BinaryOperator* s); + virtual bool TraverseDeclarationNameInfo(clang::DeclarationNameInfo NameInfo); + #define OPERATOR(NAME) virtual bool TraverseBin##NAME##Assign(clang::CompoundAssignOperator *s) { return TraverseAssignCommon(s); } OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor) diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp index 973fa0e0..16c18590 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp @@ -230,7 +230,7 @@ void CxxAstVisitorComponentIndexer::visitFunctionDecl(clang::FunctionDecl* d) m_client->recordSymbol( getAstVisitor()->getDeclNameCache()->getValue(d), clang::isa(d) ? SYMBOL_METHOD : SYMBOL_FUNCTION, - getParseLocation(d->getLocation()), + getParseLocation(d->getNameInfo().getSourceRange()), getParseLocationOfFunctionBody(d), utility::convertAccessSpecifier(d->getAccess()), utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index 8185c2f4..9c001783 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -186,6 +186,21 @@ public: )); } + void test_cxx_parser_finds_overloaded_operator_declaration() + { + std::shared_ptr client = parseCode( + "class B\n" + "{\n" + "public:\n" + " B& operator=(const B& other);\n" + "};\n" + ); + + TS_ASSERT(utility::containsElement( + client->methods, "public B & B::operator=(const B &) <4:5 4:13>" + )); + } + void test_cxx_parser_finds_method_declaration_and_definition() { std::shared_ptr client = parseCode( @@ -1295,8 +1310,8 @@ public: "}\n" ); - TS_ASSERT(utility::containsElement(client->methods, "public void TestClass::TestClass() <1:7 <1:7 1:15> 1:7>")); - TS_ASSERT(utility::containsElement(client->methods, "public void TestClass::TestClass(const TestClass &) <1:7 <1:7 1:15> 1:7>")); + TS_ASSERT(utility::containsElement(client->methods, "public void TestClass::TestClass() <1:7 <1:7 1:15> 1:15>")); + TS_ASSERT(utility::containsElement(client->methods, "public void TestClass::TestClass(const TestClass &) <1:7 <1:7 1:15> 1:15>")); TS_ASSERT(utility::containsElement(client->methods, "public void TestClass::TestClass(TestClass &) <1:7 1:15>")); } @@ -3394,7 +3409,7 @@ public: TS_ASSERT_EQUALS(client->inheritances.size(), 1); TS_ASSERT_EQUALS(client->calls.size(), 3); TS_ASSERT_EQUALS(client->usages.size(), 3); - TS_ASSERT_EQUALS(client->typeUses.size(), 17); + TS_ASSERT_EQUALS(client->typeUses.size(), 16); TS_ASSERT_EQUALS(client->files.size(), 2); TS_ASSERT_EQUALS(client->includes.size(), 1);