diff --git a/src/lib/data/parser/ParseLocation.cpp b/src/lib/data/parser/ParseLocation.cpp index 5905a5d1..52f43399 100644 --- a/src/lib/data/parser/ParseLocation.cpp +++ b/src/lib/data/parser/ParseLocation.cpp @@ -10,7 +10,7 @@ ParseLocation::ParseLocation() } ParseLocation::ParseLocation( - const std::string& filePath, + const FilePath& filePath, uint lineNumber, uint columnNumber ) @@ -27,7 +27,7 @@ ParseLocation::ParseLocation( } ParseLocation::ParseLocation( - const std::string& filePath, + const FilePath& filePath, uint startLineNumber, uint startColumnNumber, uint endLineNumber, uint endColumnNumber ) diff --git a/src/lib/data/parser/ParseLocation.h b/src/lib/data/parser/ParseLocation.h index 14ab6633..f1a0f1cc 100644 --- a/src/lib/data/parser/ParseLocation.h +++ b/src/lib/data/parser/ParseLocation.h @@ -10,12 +10,12 @@ struct ParseLocation { ParseLocation(); ParseLocation( - const std::string& filePath, + const FilePath& filePath, uint lineNumber, uint columnNumber ); ParseLocation( - const std::string& filePath, + const FilePath& filePath, uint startLineNumber, uint startColumnNumber, uint endLineNumber, uint endColumnNumber ); diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp index 31500ffe..732f741f 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp @@ -169,9 +169,13 @@ void CxxAstVisitorComponentIndexer::visitFunctionDecl(clang::FunctionDecl* d) if (d->isFunctionTemplateSpecialization()) { + const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(d->getPrimaryTemplate()->getTemplatedDecl()); // todo: use context and childcontext!! + + m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE); + m_client->recordReference( REFERENCE_TEMPLATE_SPECIALIZATION_OF, // TODO: call this REFERENCE_TEMPLATE_SPECIALIZATION and reverse the following arguments - getAstVisitor()->getDeclNameCache()->getValue(d->getPrimaryTemplate()->getTemplatedDecl()), // todo: use context and childcontext!! + referencedName, getAstVisitor()->getDeclNameCache()->getValue(d), getParseLocation(d->getLocation()) ); @@ -184,12 +188,16 @@ void CxxAstVisitorComponentIndexer::visitCXXMethodDecl(clang::CXXMethodDecl* d) // Decl has been recorded in VisitFunctionDecl if (shouldVisitDecl(d)) { - for (clang::CXXMethodDecl::method_iterator it = d->begin_overridden_methods(); // TODO: iterate in traversal and use RT_Overridden or so.. + for (clang::CXXMethodDecl::method_iterator it = d->begin_overridden_methods(); // TODO: iterate in traversal and use REFERENCE_OVERRIDE or so.. it != d->end_overridden_methods(); it++) { + const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(*it); + + m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE); + m_client->recordReference( REFERENCE_OVERRIDE, - getAstVisitor()->getDeclNameCache()->getValue(*it), + referencedName, getAstVisitor()->getDeclNameCache()->getValue(d), getParseLocation(d->getLocation()) ); @@ -201,9 +209,13 @@ void CxxAstVisitorComponentIndexer::visitCXXMethodDecl(clang::CXXMethodDecl* d) clang::NamedDecl* specializedNamedDecl = memberSpecializationInfo->getInstantiatedFrom(); if (clang::isa(specializedNamedDecl)) { + const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(specializedNamedDecl); + + m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE); + m_client->recordReference( REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION_OF, - getAstVisitor()->getDeclNameCache()->getValue(specializedNamedDecl), + referencedName, getAstVisitor()->getDeclNameCache()->getValue(d), getParseLocation(d->getLocation()) ); @@ -402,9 +414,17 @@ void CxxAstVisitorComponentIndexer::visitDeclRefExpr(clang::DeclRefExpr* s) } else { + const ReferenceKind refKind = consumeDeclRefContextKind(); + const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(s->getDecl()); + + if (refKind == REFERENCE_CALL) + { + m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE); + } + m_client->recordReference( - consumeDeclRefContextKind(), - getAstVisitor()->getDeclNameCache()->getValue(s->getDecl()), + refKind, + referencedName, getAstVisitor()->getComponent()->getContextName(), getParseLocation(s->getLocation()) ); @@ -416,9 +436,17 @@ void CxxAstVisitorComponentIndexer::visitMemberExpr(clang::MemberExpr* s) { if (shouldVisitReference(s->getMemberLoc(), getAstVisitor()->getComponent()->getTopmostContextDecl())) { + const ReferenceKind refKind = consumeDeclRefContextKind(); + const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(s->getMemberDecl()); + + if (refKind == REFERENCE_CALL) + { + m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE); + } + m_client->recordReference( - consumeDeclRefContextKind(), - getAstVisitor()->getDeclNameCache()->getValue(s->getMemberDecl()), + refKind, + referencedName, getAstVisitor()->getComponent()->getContextName(), getParseLocation(s->getMemberLoc()) ); @@ -472,9 +500,17 @@ void CxxAstVisitorComponentIndexer::visitCXXConstructExpr(clang::CXXConstructExp } loc = clang::Lexer::GetBeginningOfToken(loc, m_astContext->getSourceManager(), m_astContext->getLangOpts()); + const ReferenceKind refKind = consumeDeclRefContextKind(); + const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(s->getConstructor()); + + if (refKind == REFERENCE_CALL) + { + m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE); + } + m_client->recordReference( - consumeDeclRefContextKind(), - getAstVisitor()->getDeclNameCache()->getValue(s->getConstructor()), + refKind, + referencedName, getAstVisitor()->getComponent()->getContextName(), getParseLocation(loc) ); diff --git a/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp b/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp index 0c9966e3..b228f092 100644 --- a/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp +++ b/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp @@ -157,7 +157,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::Token& macroN const clang::SourceLocation& endLocation = m_sourceManager.getSpellingLoc(macroNameTok.getEndLoc()); return ParseLocation( - m_sourceManager.getFilename(location), + m_sourceManager.getFilename(location).str(), m_sourceManager.getSpellingLineNumber(location), m_sourceManager.getSpellingColumnNumber(location), m_sourceManager.getSpellingLineNumber(endLocation), @@ -171,7 +171,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::MacroInfo* ma clang::SourceLocation endLocation = macroInfo->getDefinitionEndLoc(); return ParseLocation( - m_sourceManager.getFilename(location), + m_sourceManager.getFilename(location).str(), m_sourceManager.getSpellingLineNumber(location), m_sourceManager.getSpellingColumnNumber(location), m_sourceManager.getSpellingLineNumber(endLocation), diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index 0db23647..e04d4450 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -3308,7 +3308,7 @@ public: TS_ASSERT_EQUALS(client.classes.size(), 4); TS_ASSERT_EQUALS(client.enums.size(), 1); TS_ASSERT_EQUALS(client.enumConstants.size(), 2); - TS_ASSERT_EQUALS(client.functions.size(), 2); + TS_ASSERT_EQUALS(client.functions.size(), 5); // used methods are also recorded as functions (these get overridden in the intermediate storage) TS_ASSERT_EQUALS(client.fields.size(), 4); TS_ASSERT_EQUALS(client.globalVariables.size(), 2); TS_ASSERT_EQUALS(client.methods.size(), 15);