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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user