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:
+5
-1
@@ -54,7 +54,11 @@ if(UNIX AND NOT APPLE)
|
||||
find_package(LLVM REQUIRED PATHS "$ENV{CLANG_DIR}/build_debug/share/llvm/cmake")
|
||||
endif()
|
||||
else()
|
||||
find_package(LLVM REQUIRED PATHS "$ENV{CLANG_DIR}/build/share/llvm/cmake")
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
||||
find_package(LLVM REQUIRED PATHS "$ENV{CLANG_DIR}/build_release/share/llvm/cmake")
|
||||
else()
|
||||
find_package(LLVM REQUIRED PATHS "$ENV{CLANG_DIR}/build/share/llvm/cmake")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(CLANG REQUIRED PATHS "${CMAKE_SOURCE_DIR}/cmake")
|
||||
|
||||
@@ -27,3 +27,25 @@ For Win32:
|
||||
|
||||
Run setup script:
|
||||
$ ./script/setup.sh
|
||||
|
||||
##### Updating Clang on UNIX
|
||||
|
||||
$ cd .../clang_llvm
|
||||
|
||||
$ cd llvm
|
||||
$ git pull origin master
|
||||
|
||||
$ cd tools/clang
|
||||
$ git pull origin master
|
||||
|
||||
$ cd tools/extra/
|
||||
$ git pull origin master
|
||||
|
||||
$ cd ../../../../../build
|
||||
$ cmake -G Ninja ../llvm
|
||||
$ ninja -j 4 check-all
|
||||
|
||||
$ cd ../release_build
|
||||
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ../llvm
|
||||
$ ninja -j 4 clang
|
||||
|
||||
|
||||
@@ -179,6 +179,11 @@
|
||||
<normal>#DDD</normal>
|
||||
<hover>#CCC</hover>
|
||||
</file>
|
||||
|
||||
<undefined_macro>
|
||||
<normal>#DDD</normal>
|
||||
<hover>#CCC</hover>
|
||||
</undefined_macro>
|
||||
<macro>
|
||||
<normal>#DDD</normal>
|
||||
<hover>#CCC</hover>
|
||||
|
||||
@@ -179,6 +179,11 @@
|
||||
<normal>#1B564E</normal>
|
||||
<hover>#247368</hover>
|
||||
</file>
|
||||
|
||||
<undefined_macro>
|
||||
<normal>#1B564E</normal>
|
||||
<hover>#247368</hover>
|
||||
</undefined_macro>
|
||||
<macro>
|
||||
<normal>#1B564E</normal>
|
||||
<hover>#247368</hover>
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
if(UNIX AND NOT APPLE)
|
||||
if (UNIX AND NOT APPLE)
|
||||
|
||||
execute_process(
|
||||
COMMAND $ENV{CLANG_DIR}/build_debug/bin/llvm-config --cxxflags
|
||||
OUTPUT_VARIABLE CLANG_DEFINITIONS
|
||||
)
|
||||
|
||||
|
||||
set(CLANG_INCLUDE_DIRS
|
||||
"$ENV{CLANG_DIR}/llvm/tools/clang/include"
|
||||
"$ENV{CLANG_DIR}/build_debug/tools/clang/include"
|
||||
@@ -25,15 +24,19 @@ else()
|
||||
OUTPUT_VARIABLE CLANG_DEFINITIONS
|
||||
)
|
||||
|
||||
# Remove unwanted flags
|
||||
string(REPLACE "-fno-exceptions" "" CLANG_DEFINITIONS ${CLANG_DEFINITIONS})
|
||||
string(REPLACE "-fno-rtti" "" CLANG_DEFINITIONS ${CLANG_DEFINITIONS})
|
||||
|
||||
set(CLANG_INCLUDE_DIRS
|
||||
"$ENV{CLANG_DIR}/llvm/tools/clang/include"
|
||||
"$ENV{CLANG_DIR}/build/tools/clang/include"
|
||||
)
|
||||
|
||||
set(CLANG_LIBRARY_DIRS "$ENV{CLANG_DIR}/build_debug/lib")
|
||||
set(CLANG_LIBRARY_DIRS "$ENV{CLANG_DIR}/build/lib")
|
||||
if (UNIX)
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
||||
set(CLANG_LIBRARY_DIRS "$ENV{CLANG_DIR}/build/Release+Asserts/lib")
|
||||
set(CLANG_LIBRARY_DIRS "$ENV{CLANG_DIR}/build_release/lib")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ size_t GraphViewStyle::getFontSizeForNodeType(Node::NodeType type)
|
||||
case Node::NODE_TYPEDEF:
|
||||
case Node::NODE_TEMPLATE_PARAMETER_TYPE:
|
||||
case Node::NODE_FILE:
|
||||
case Node::NODE_UNDEFINED_MACRO:
|
||||
case Node::NODE_MACRO:
|
||||
return s_fontSize;
|
||||
|
||||
@@ -198,6 +199,7 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
|
||||
case Node::NODE_GLOBAL_VARIABLE:
|
||||
case Node::NODE_FIELD:
|
||||
case Node::NODE_ENUM_CONSTANT:
|
||||
case Node::NODE_UNDEFINED_MACRO:
|
||||
case Node::NODE_MACRO:
|
||||
margins.left = margins.right = 5;
|
||||
margins.top = margins.bottom = 3;
|
||||
@@ -347,6 +349,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
|
||||
|
||||
case Node::NODE_UNDEFINED_FUNCTION:
|
||||
case Node::NODE_UNDEFINED_VARIABLE:
|
||||
case Node::NODE_UNDEFINED_MACRO:
|
||||
style.hatchingColor = scheme->getColor("graph/hatching");
|
||||
|
||||
case Node::NODE_FUNCTION:
|
||||
|
||||
+18
-26
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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