build: updated to new clang and other fixes

* don't save macros from external files
* fixed macro and include saving duplicates
* added NODE_UNDEFINED_MACRO

TIL = You need to cut a 1kg cake about 85 times in half until you have a piece with only a single atom.
This commit is contained in:
Eberhard Graether
2015-09-29 14:22:52 +02:00
parent e3696df5e1
commit eeed22f478
13 changed files with 126 additions and 65 deletions
+18 -26
View File
@@ -664,40 +664,28 @@ 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)
{
log("macro", macroNameHierarchy.getFullName(), location);
Id macroId = 0;
Id macroId = addNodeHierarchy(Node::NODE_MACRO, macroNameHierarchy);
addSourceLocation(macroId, location);
Id fileId = m_sqliteStorage.getFileByName(location.filePath.fileName()).id;
if(fileId != 0)
{
macroId = addNodeHierarchy(Node::NODE_MACRO, macroNameHierarchy);
addSourceLocation(macroId, location);
}
else
{
//TODO: What to do with this ones?
//LOG_ERROR("External MacroDefined :" + macroNameHierarchy.getFullName());
}
Id fileNodeId = getFileNodeId(location.filePath);
addEdge(fileNodeId, macroId, Edge::EDGE_MACRO_USAGE, location);
return macroId;
}
Id Storage::onMacroExpandParsed(const ParseLocation &location, const NameHierarchy& macroNameHierarchy) {
Id macroExpandId = addNodeHierarchy(Node::NODE_UNDEFINED, macroNameHierarchy);
Id fileId = m_sqliteStorage.getFileByName(location.filePath.fileName()).id;
Id Storage::onMacroExpandParsed(const ParseLocation &location, const NameHierarchy& macroNameHierarchy)
{
log("macro use", macroNameHierarchy.getFullName(), location);
if(fileId != 0)
{
addEdge(fileId, macroExpandId,Edge::EDGE_MACRO_USAGE, location);
}
else
{
//TODO: What to do with this ones?
//LOG_ERROR("External MacroExpand :" + macroNameHierarchy.getFullName());
}
Id macroExpandId = addNodeHierarchy(Node::NODE_UNDEFINED_MACRO, macroNameHierarchy);
Id fileNodeId = getFileNodeId(location.filePath);
Id edgeId = addEdge(fileNodeId, macroExpandId, Edge::EDGE_MACRO_USAGE, location);
return 0;
return edgeId;
}
Id Storage::getIdForNodeWithName(const std::string& fullName) const // use name hierarchy here
@@ -876,6 +864,10 @@ std::vector<Id> Storage::getActiveTokenIdsForTokenIds(const std::vector<Id>& tok
}
}
std::set<Id> idSet(activeIds.begin(), activeIds.end());
activeIds.clear();
activeIds.insert(activeIds.end(), idSet.begin(), idSet.end());
return activeIds;
}
+1 -1
View File
@@ -364,7 +364,7 @@ bool Edge::checkType() const
}
return true;
case EDGE_MACRO_USAGE:
if(!m_to->isType(Node::NODE_MACRO) || !m_from->isType(Node::NODE_FILE))
if(!m_to->isType(Node::NODE_MACRO | Node::NODE_UNDEFINED_MACRO) || !m_from->isType(Node::NODE_FILE))
{
break;
}
+4
View File
@@ -47,6 +47,8 @@ std::string Node::getTypeString(NodeType type)
return "template_parameter_type";
case NODE_FILE:
return "file";
case NODE_UNDEFINED_MACRO:
return "undefined_macro";
case NODE_MACRO:
return "macro";
}
@@ -96,6 +98,8 @@ Node::NodeType Node::intToType(int value)
case 0x8000:
return NODE_FILE;
case 0x10000:
return NODE_UNDEFINED_MACRO;
case 0x20000:
return NODE_MACRO;
}
+3 -1
View File
@@ -41,7 +41,9 @@ public:
NODE_TEMPLATE_PARAMETER_TYPE = 0x4000,
NODE_FILE = 0x8000,
NODE_MACRO = 0x10000,
NODE_UNDEFINED_MACRO = 0x10000,
NODE_MACRO = 0x20000,
};
static std::string getTypeString(NodeType type);
+1 -1
View File
@@ -25,7 +25,7 @@ void ASTBodyVisitor::VisitStmt(clang::Stmt* stmt)
void ASTBodyVisitor::VisitChildren(clang::Stmt* stmt)
{
for (clang::Stmt::child_range it = stmt->children(); it; it++)
for (clang::Stmt::child_iterator it = stmt->child_begin(); it != stmt->child_end(); it++)
{
if (*it)
{
@@ -56,7 +56,8 @@ void PreprocessorCallbacks::InclusionDirective(
std::string includedFilePath = fileEntry->getName();
const FileManager* fileManager = m_fileRegister->getFileManager();
if (fileManager->hasFilePath(baseFilePath) && fileManager->hasFilePath(includedFilePath))
if (fileManager->hasFilePath(baseFilePath) && fileManager->hasFilePath(includedFilePath) &&
!m_fileRegister->includeFileIsParsed(baseFilePath))
{
m_client->onFileIncludeParsed(
getParseLocation(fileNameRange.getAsRange()),
@@ -67,53 +68,73 @@ void PreprocessorCallbacks::InclusionDirective(
}
}
void PreprocessorCallbacks::MacroDefined( const clang::Token &MacroNameTok, const clang::MacroDirective *MD)
void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, const clang::MacroDirective* macroDirective)
{
// ignore builtin macros
if(m_sourceManager.getSpellingLoc(MacroNameTok.getLocation()).printToString(m_sourceManager)[0] == '<')
const std::string& fileStr = m_sourceManager.getFilename(macroNameToken.getLocation());
if (!fileStr.size())
{
return;
}
m_sourceManager.getSpellingLoc(MacroNameTok.getLocation()).dump(m_sourceManager);
NameHierarchy nameHierarchy;
nameHierarchy.push(std::make_shared<NameElement>(MacroNameTok.getIdentifierInfo()->getName().str()));
m_client->onMacroDefineParsed( getParseLocation(MacroNameTok), nameHierarchy);
FilePath filePath = FilePath(fileStr);
if (m_fileRegister->getFileManager()->hasFilePath(filePath) && !m_fileRegister->includeFileIsParsed(filePath))
{
// ignore builtin macros
if (m_sourceManager.getSpellingLoc(macroNameToken.getLocation()).printToString(m_sourceManager)[0] == '<')
{
return;
}
NameHierarchy nameHierarchy;
nameHierarchy.push(std::make_shared<NameElement>(macroNameToken.getIdentifierInfo()->getName().str()));
m_client->onMacroDefineParsed(getParseLocation(macroNameToken), nameHierarchy);
}
}
void PreprocessorCallbacks::MacroExpands(
const clang::Token &MacroNameTok, const clang::MacroDefinition &MD,
clang::SourceRange Range, const clang::MacroArgs *Args
const clang::Token& macroNameToken, const clang::MacroDefinition& macroDirective,
clang::SourceRange range, const clang::MacroArgs* args
){
NameHierarchy nameHierarchy;
nameHierarchy.push(std::make_shared<NameElement>(MacroNameTok.getIdentifierInfo()->getName().str()));
const std::string& fileStr = m_sourceManager.getFilename(macroNameToken.getLocation());
if (!fileStr.size())
{
return;
}
m_client->onMacroExpandParsed( getParseLocation(MacroNameTok), nameHierarchy);
FilePath filePath = FilePath(fileStr);
if (m_fileRegister->getFileManager()->hasFilePath(filePath) && !m_fileRegister->includeFileIsParsed(filePath))
{
NameHierarchy nameHierarchy;
nameHierarchy.push(std::make_shared<NameElement>(macroNameToken.getIdentifierInfo()->getName().str()));
m_client->onMacroExpandParsed(getParseLocation(macroNameToken), nameHierarchy);
}
}
ParseLocation PreprocessorCallbacks::getParseLocation(const clang::Token &MacroNameTok) const
ParseLocation PreprocessorCallbacks::getParseLocation(const clang::Token& macroNameTok) const
{
clang::SourceLocation location = MacroNameTok.getLocation();
clang::SourceLocation location = macroNameTok.getLocation();
return ParseLocation(
m_sourceManager.getFilename(location),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(MacroNameTok.getEndLoc()),
m_sourceManager.getSpellingColumnNumber(MacroNameTok.getEndLoc()) - 1
m_sourceManager.getFilename(location),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(macroNameTok.getEndLoc()),
m_sourceManager.getSpellingColumnNumber(macroNameTok.getEndLoc()) - 1
);
}
ParseLocation PreprocessorCallbacks::getParseLocation(clang::MacroInfo *macroInfo) const
ParseLocation PreprocessorCallbacks::getParseLocation(clang::MacroInfo* macroInfo) const
{
clang::SourceLocation location = macroInfo->getDefinitionLoc();
clang::SourceLocation endLocation = macroInfo->getDefinitionEndLoc();
return ParseLocation(
m_sourceManager.getFilename(location),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
m_sourceManager.getSpellingColumnNumber(endLocation) - 1
m_sourceManager.getFilename(location),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
m_sourceManager.getSpellingColumnNumber(endLocation) - 1
);
}
@@ -24,17 +24,17 @@ public:
clang::CharSourceRange fileNameRange, const clang::FileEntry* fileEntry, llvm::StringRef searchPath,
llvm::StringRef relativePath, const clang::Module* imported);
virtual void MacroDefined(const clang::Token &MacroNameTok, const clang::MacroDirective *MD );
virtual void MacroDefined(const clang::Token& macroNameToken, const clang::MacroDirective* macroDirective);
virtual void MacroExpands(
const clang::Token &MacroNameTok, const clang::MacroDefinition &MD,
clang::SourceRange Range, const clang::MacroArgs *Args
const clang::Token& macroNameToken, const clang::MacroDefinition& macroDirective,
clang::SourceRange range, const clang::MacroArgs* args
);
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::Token& macroNameToc) const;
ParseLocation getParseLocation(clang::MacroInfo* macroNameToc) const;
const clang::SourceManager& m_sourceManager;
ParserClient* m_client;