data: saving macro definition scopes
This commit is contained in:
@@ -21,6 +21,7 @@ int calculate(int i)
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PI 3.1415
|
||||||
|
|
||||||
#define CALL_CALCULATE() \
|
#define CALL_CALCULATE() \
|
||||||
do \
|
do \
|
||||||
|
|||||||
@@ -687,12 +687,14 @@ Id Storage::onFileIncludeParsed(const ParseLocation& location, const FileInfo& f
|
|||||||
return fileNodeId;
|
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);
|
log("macro", macroNameHierarchy.getFullName(), location);
|
||||||
|
|
||||||
Id macroId = addNodeHierarchy(Node::NODE_MACRO, macroNameHierarchy, true);
|
Id macroId = addNodeHierarchy(Node::NODE_MACRO, macroNameHierarchy, true);
|
||||||
addSourceLocation(macroId, location);
|
addSourceLocation(macroId, location);
|
||||||
|
addSourceLocation(macroId, scopeLocation, true);
|
||||||
|
|
||||||
Id fileNodeId = getFileNodeId(location.filePath);
|
Id fileNodeId = getFileNodeId(location.filePath);
|
||||||
addEdge(fileNodeId, macroId, Edge::EDGE_MACRO_USAGE, location);
|
addEdge(fileNodeId, macroId, Edge::EDGE_MACRO_USAGE, location);
|
||||||
|
|||||||
@@ -123,7 +123,8 @@ public:
|
|||||||
virtual Id onFileIncludeParsed(
|
virtual Id onFileIncludeParsed(
|
||||||
const ParseLocation& location, const FileInfo& fileInfo, const FileInfo& includedFileInfo);
|
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);
|
virtual Id onMacroExpandParsed(const ParseLocation& location, const NameHierarchy& macroNameHierarchy);
|
||||||
|
|
||||||
// StorageAccess implementation
|
// StorageAccess implementation
|
||||||
|
|||||||
@@ -141,7 +141,8 @@ public:
|
|||||||
const ParseLocation& location, const FileInfo& fileInfo, const FileInfo& includedFileInfo) = 0;
|
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(
|
virtual Id onMacroExpandParsed(
|
||||||
const ParseLocation& location, const NameHierarchy& macroNameHierarchy) = 0;
|
const ParseLocation& location, const NameHierarchy& macroNameHierarchy) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ public:
|
|||||||
virtual ~ASTVisitor();
|
virtual ~ASTVisitor();
|
||||||
|
|
||||||
// Left for debugging purposes. Uncomment to see a colored ast-dump of the parsed file.
|
// Left for debugging purposes. Uncomment to see a colored ast-dump of the parsed file.
|
||||||
// virtual bool VisitTranslationUnitDecl(clang::TranslationUnitDecl* decl)
|
// virtual bool VisitTranslationUnitDecl(clang::TranslationUnitDecl* decl)
|
||||||
// {
|
// {
|
||||||
// decl->dump();
|
// decl->dump();
|
||||||
// return true;
|
// return true;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// RecursiveASTVisitor implementation
|
// RecursiveASTVisitor implementation
|
||||||
virtual bool VisitStmt(const clang::Stmt* statement); // avoid visiting
|
virtual bool VisitStmt(const clang::Stmt* statement); // avoid visiting
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, con
|
|||||||
NameHierarchy nameHierarchy;
|
NameHierarchy nameHierarchy;
|
||||||
nameHierarchy.push(std::make_shared<NameElement>(macroNameToken.getIdentifierInfo()->getName().str()));
|
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 location = macroInfo->getDefinitionLoc();
|
||||||
clang::SourceLocation endLocation = macroInfo->getDefinitionEndLoc();
|
clang::SourceLocation endLocation = macroInfo->getDefinitionEndLoc();
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
|
|
||||||
ParseLocation getParseLocation(const clang::Token& macroNameToc) 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;
|
const clang::SourceManager& m_sourceManager;
|
||||||
ParserClient* m_client;
|
ParserClient* m_client;
|
||||||
|
|||||||
@@ -1211,7 +1211,17 @@ public:
|
|||||||
"};\n"
|
"};\n"
|
||||||
);
|
);
|
||||||
TS_ASSERT_EQUALS(client->macros.size(),1);
|
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()
|
void test_cxx_parser_finds_macro_expand()
|
||||||
@@ -2784,9 +2794,10 @@ private:
|
|||||||
return 0;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user