data: saving macro definition scopes

This commit is contained in:
Eberhard Graether
2015-11-04 13:47:33 +01:00
parent 884e42a30c
commit 5dada05bc5
8 changed files with 33 additions and 16 deletions
+1
View File
@@ -21,6 +21,7 @@ int calculate(int i)
return a;
}
#define PI 3.1415
#define CALL_CALCULATE() \
do \
+4 -2
View File
@@ -687,12 +687,14 @@ Id Storage::onFileIncludeParsed(const ParseLocation& location, const FileInfo& f
return fileNodeId;
}
Id Storage::onMacroDefineParsed(const ParseLocation& location, const NameHierarchy& macroNameHierarchy)
{
Id Storage::onMacroDefineParsed(
const ParseLocation& location, const NameHierarchy& macroNameHierarchy, const ParseLocation& scopeLocation
){
log("macro", macroNameHierarchy.getFullName(), location);
Id macroId = addNodeHierarchy(Node::NODE_MACRO, macroNameHierarchy, true);
addSourceLocation(macroId, location);
addSourceLocation(macroId, scopeLocation, true);
Id fileNodeId = getFileNodeId(location.filePath);
addEdge(fileNodeId, macroId, Edge::EDGE_MACRO_USAGE, location);
+2 -1
View File
@@ -123,7 +123,8 @@ public:
virtual Id onFileIncludeParsed(
const ParseLocation& location, const FileInfo& fileInfo, const FileInfo& includedFileInfo);
virtual Id onMacroDefineParsed(const ParseLocation& location, const NameHierarchy& macroNameHierarchy);
virtual Id onMacroDefineParsed(
const ParseLocation& location, const NameHierarchy& macroNameHierarchy, const ParseLocation& scopeLocation);
virtual Id onMacroExpandParsed(const ParseLocation& location, const NameHierarchy& macroNameHierarchy);
// StorageAccess implementation
+2 -1
View File
@@ -141,7 +141,8 @@ public:
const ParseLocation& location, const FileInfo& fileInfo, const FileInfo& includedFileInfo) = 0;
virtual Id onMacroDefineParsed(const ParseLocation& location, const NameHierarchy& macroNameHierarchy) = 0;
virtual Id onMacroDefineParsed(
const ParseLocation& location, const NameHierarchy& macroNameHierarchy, const ParseLocation& scopeLocation) = 0;
virtual Id onMacroExpandParsed(
const ParseLocation& location, const NameHierarchy& macroNameHierarchy) = 0;
};
+5 -5
View File
@@ -18,11 +18,11 @@ public:
virtual ~ASTVisitor();
// Left for debugging purposes. Uncomment to see a colored ast-dump of the parsed file.
// virtual bool VisitTranslationUnitDecl(clang::TranslationUnitDecl* decl)
// {
// decl->dump();
// return true;
// }
// virtual bool VisitTranslationUnitDecl(clang::TranslationUnitDecl* decl)
// {
// decl->dump();
// return true;
// }
// RecursiveASTVisitor implementation
virtual bool VisitStmt(const clang::Stmt* statement); // avoid visiting
@@ -88,7 +88,8 @@ void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, con
NameHierarchy nameHierarchy;
nameHierarchy.push(std::make_shared<NameElement>(macroNameToken.getIdentifierInfo()->getName().str()));
m_client->onMacroDefineParsed(getParseLocation(macroNameToken), nameHierarchy);
m_client->onMacroDefineParsed(
getParseLocation(macroNameToken), nameHierarchy, getParseLocation(macroDirective->getMacroInfo()));
}
}
@@ -124,7 +125,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::Token& macroN
);
}
ParseLocation PreprocessorCallbacks::getParseLocation(clang::MacroInfo* macroInfo) const
ParseLocation PreprocessorCallbacks::getParseLocation(const clang::MacroInfo* macroInfo) const
{
clang::SourceLocation location = macroInfo->getDefinitionLoc();
clang::SourceLocation endLocation = macroInfo->getDefinitionEndLoc();
@@ -32,9 +32,9 @@ public:
);
private:
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
ParseLocation getParseLocation(const clang::Token& macroNameToc) const;
ParseLocation getParseLocation(clang::MacroInfo* macroNameToc) const;
ParseLocation getParseLocation(const clang::MacroInfo* macroNameToc) const;
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
const clang::SourceManager& m_sourceManager;
ParserClient* m_client;
+14 -3
View File
@@ -1211,7 +1211,17 @@ public:
"};\n"
);
TS_ASSERT_EQUALS(client->macros.size(),1);
TS_ASSERT_EQUALS(client->macros[0], "PI <1:9 1:10>");
TS_ASSERT_EQUALS(client->macros[0], "PI <1:9 <1:9 1:10> 1:8>");
}
void test_cxx_parser_finds_macro_define_scope()
{
std::shared_ptr<TestParserClient> client = parseCode(
"#define MAX(a,b) \\\n"
" ((a)>(b)?(a):(b))"
);
TS_ASSERT_EQUALS(client->macros.size(),1);
TS_ASSERT_EQUALS(client->macros[0], "MAX <1:9 <1:9 1:11> 2:17>");
}
void test_cxx_parser_finds_macro_expand()
@@ -2784,9 +2794,10 @@ private:
return 0;
}
virtual Id onMacroDefineParsed(const ParseLocation& location, const NameHierarchy& macroNameHierarchy)
virtual Id onMacroDefineParsed(
const ParseLocation& location, const NameHierarchy& macroNameHierarchy, const ParseLocation& scopeLocation)
{
macros.push_back(addLocationSuffix(macroNameHierarchy.getFullName() ,location));
macros.push_back(addLocationSuffix(macroNameHierarchy.getFullName(), location, scopeLocation));
return 0;
}