From 5370541a0f4648e1a82c3fc4fd3504c188299a9c Mon Sep 17 00:00:00 2001 From: malte_langkabel Date: Fri, 27 Feb 2015 16:07:51 +0100 Subject: [PATCH] data: filename info * Changed the TokenLocation of TemplateArguments to have at least a valid file name. * Extended name of anonymous namespace by the containing file's name. * Adjusted tests to reflect these changes. --- src/lib/data/Storage.cpp | 5 ++++- src/lib/data/parser/cxx/ASTVisitor.cpp | 7 +++++-- src/lib/data/parser/cxx/utilityCxx.cpp | 4 +++- src/test/CxxParserTestSuite.h | 6 +++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index dcb05365..3c4c0c9e 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -310,7 +310,10 @@ Id Storage::onNamespaceParsed( log("namespace", utility::join(nameHierarchy, "::"), location); Node* node = addNodeHierarchy(Node::NODE_NAMESPACE, nameHierarchy); - addTokenLocation(node, location); + if (location.isValid()) + { + addTokenLocation(node, location); + } addTokenLocation(node, scopeLocation, true); return node->getId(); diff --git a/src/lib/data/parser/cxx/ASTVisitor.cpp b/src/lib/data/parser/cxx/ASTVisitor.cpp index 38251c1f..537c97ca 100644 --- a/src/lib/data/parser/cxx/ASTVisitor.cpp +++ b/src/lib/data/parser/cxx/ASTVisitor.cpp @@ -331,14 +331,17 @@ bool ASTVisitor::VisitClassTemplateDecl(clang::ClassTemplateDecl* declaration) getParseLocationForNamedDecl(*it), specializedRecordNameHierarchy, specializedRecordType, specializationParentNameHierarchy ); + std::string specializationFilePath = getParseLocationForNamedDecl(specializationDecl).filePath; + const clang::TemplateArgumentList &argList = specializationDecl->getTemplateArgs(); for (size_t i = 0; i < argList.size(); i++) { std::vector argumentNameHierarchy = utility::templateArgumentToDataType(argList.get(i)).getTypeNameHierarchy(); + if (argumentNameHierarchy.size()) // FIXME: Some TemplateArgument kinds are not handled yet. { m_client->onTemplateArgumentParsed( - ParseLocation(), // TODO: Find a valid ParseLocation here! + ParseLocation(specializationFilePath, 0, 0), // TODO: Find a valid ParseLocation here! argumentNameHierarchy, specializedRecordNameHierarchy ); @@ -457,7 +460,7 @@ bool ASTVisitor::VisitFunctionTemplateDecl(clang::FunctionTemplateDecl *declarat const clang::QualType argumentType = argument.getAsType(); m_client->onTemplateArgumentParsed( - ParseLocation(), // TODO: get ParseLocation + ParseLocation(specializedFunctionLocation.filePath, 0, 0), // TODO: Find a valid ParseLocation here! utility::qualTypeToDataType(argumentType).getTypeNameHierarchy(), specializedFunction.nameHierarchy); } diff --git a/src/lib/data/parser/cxx/utilityCxx.cpp b/src/lib/data/parser/cxx/utilityCxx.cpp index c160106a..cd72ca69 100644 --- a/src/lib/data/parser/cxx/utilityCxx.cpp +++ b/src/lib/data/parser/cxx/utilityCxx.cpp @@ -299,7 +299,9 @@ namespace utility } else if (clang::isa(declaration) && clang::dyn_cast(declaration)->isAnonymousNamespace()) { - declName = "(anonymous namespace)"; + const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager(); + const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart()); + declName = "anonymous namespace (" + std::string(presumedBegin.getFilename()) + ")"; } return declName; } diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index 1324d27a..8cdb7f54 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -213,7 +213,7 @@ public: ); TS_ASSERT_EQUALS(client->functions.size(), 1); - TS_ASSERT_EQUALS(client->functions[0], "int (anonymous namespace)::sum(int, int) <3:6 3:8>"); + TS_ASSERT_EQUALS(client->functions[0], "int anonymous namespace (input.cc)::sum(int, int) <3:6 3:8>"); } void test_cxx_parser_finds_static_function_in_global_namespace() @@ -326,7 +326,7 @@ public: ); TS_ASSERT_EQUALS(client->namespaces.size(), 1); - TS_ASSERT_EQUALS(client->namespaces[0], "(anonymous namespace) <1:1 3:1>"); + TS_ASSERT_EQUALS(client->namespaces[0], "anonymous namespace (input.cc) <1:1 3:1>"); } void test_cxx_parser_finds_nested_named_namespace() @@ -434,7 +434,7 @@ public: ); TS_ASSERT_EQUALS(client->typedefs.size(), 1); - TS_ASSERT_EQUALS(client->typedefs[0], "unsigned int -> (anonymous namespace)::uint <3:23 3:26>"); + TS_ASSERT_EQUALS(client->typedefs[0], "unsigned int -> anonymous namespace (input.cc)::uint <3:23 3:26>"); } void test_cxx_parser_finds_typedef_that_uses_type_defined_in_named_namespace()