data: Fixes and features for loading Coati into Coati

This change facilitates loading Coati into Coati:
* removed error logs for TokenComponent setting
* fixed edge checks regarding template stuff
* separated CommonSettings to be inherited by Project- and ApplicationSettings for common settings
* pluralized SourcePaths setting in xml to allow for loading multiple directories and single files
* added CompilerFlags section to settings
* passing Compiler arguments to Parser via struct Parser::Arguments
* setting -isystem for all header search paths to avoid distinction between "" and <> headers
* parsing all headers from the SourcePaths, even the ones that are not included
* fixed parsing time measurement and display
* added utility.h file for general utility functionality
This commit is contained in:
Eberhard Graether
2015-03-16 10:07:57 +01:00
parent 0e0553c90b
commit 03cf9eeb5f
44 changed files with 442 additions and 260 deletions
+7 -5
View File
@@ -97,7 +97,8 @@ void Edge::addComponentAccess(std::shared_ptr<TokenComponentAccess> component)
{
if (getComponent<TokenComponentAccess>())
{
LOG_ERROR("TokenComponentAccess has been set before!");
// LOG_ERROR("TokenComponentAccess has been set before!");
return;
}
else if (m_type != EDGE_MEMBER && m_type != EDGE_INHERITANCE)
{
@@ -182,7 +183,7 @@ std::ostream& operator<<(std::ostream& ostream, const Edge& edge)
bool Edge::checkType() const
{
Node::NodeTypeMask complexTypeMask = Node::NODE_UNDEFINED_TYPE | Node::NODE_CLASS | Node::NODE_STRUCT;
Node::NodeTypeMask complexTypeMask = Node::NODE_UNDEFINED_TYPE | Node::NODE_CLASS | Node::NODE_STRUCT | Node:: NODE_TEMPLATE_PARAMETER_TYPE;
Node::NodeTypeMask typeMask = Node::NODE_UNDEFINED | Node::NODE_ENUM | Node::NODE_TYPEDEF | complexTypeMask;
Node::NodeTypeMask variableMask = Node::NODE_UNDEFINED | Node::NODE_UNDEFINED_VARIABLE | Node::NODE_GLOBAL_VARIABLE | Node::NODE_FIELD;
Node::NodeTypeMask functionMask = Node::NODE_UNDEFINED_FUNCTION | Node::NODE_FUNCTION | Node::NODE_METHOD;
@@ -190,9 +191,10 @@ bool Edge::checkType() const
switch (m_type)
{
case EDGE_MEMBER:
if (!m_from->isType(typeMask | Node::NODE_NAMESPACE) ||
if (!m_from->isType(typeMask | Node::NODE_NAMESPACE | functionMask) ||
(!m_from->isType(Node::NODE_UNDEFINED | Node::NODE_NAMESPACE) && m_to->isType(Node::NODE_NAMESPACE)) ||
(m_from->isType(Node::NODE_ENUM) && !m_to->isType(Node::NODE_ENUM_CONSTANT)))
(m_from->isType(Node::NODE_ENUM) && !m_to->isType(Node::NODE_ENUM_CONSTANT)) ||
(m_from->isType(functionMask) && !m_to->isType(Node::NODE_TEMPLATE_PARAMETER_TYPE)))
{
break;
}
@@ -259,7 +261,7 @@ bool Edge::checkType() const
case EDGE_TEMPLATE_ARGUMENT_OF:
case EDGE_TEMPLATE_DEFAULT_ARGUMENT_OF:
if (!m_from->isType(typeMask) || !m_to->isType(typeMask))
if (!m_from->isType(typeMask) || !m_to->isType(typeMask | functionMask))
{
break;
}
+9 -5
View File
@@ -251,7 +251,8 @@ void Node::addComponentAbstraction(std::shared_ptr<TokenComponentAbstraction> co
{
if (getComponent<TokenComponentAbstraction>())
{
LOG_ERROR("TokenComponentAbstraction has been set before!");
// LOG_ERROR("TokenComponentAbstraction has been set before!");
return;
}
else if (!isType(NODE_METHOD))
{
@@ -267,7 +268,8 @@ void Node::addComponentConst(std::shared_ptr<TokenComponentConst> component)
{
if (getComponent<TokenComponentConst>())
{
LOG_ERROR("TokenComponentConst has been set before!");
// LOG_ERROR("TokenComponentConst has been set before!");
return;
}
else if (!isType(NODE_METHOD))
{
@@ -283,7 +285,8 @@ void Node::addComponentStatic(std::shared_ptr<TokenComponentStatic> component)
{
if (getComponent<TokenComponentStatic>())
{
LOG_ERROR("TokenComponentStatic has been set before!");
// LOG_ERROR("TokenComponentStatic has been set before!");
return;
}
else if (!isType(NODE_GLOBAL_VARIABLE | NODE_FIELD | NODE_FUNCTION | NODE_METHOD))
{
@@ -315,11 +318,12 @@ void Node::addComponentFilePath(std::shared_ptr<TokenComponentFilePath> componen
{
if (getComponent<TokenComponentFilePath>())
{
LOG_ERROR("TokenComponentFilePath has been set before!");
// LOG_ERROR("TokenComponentFilePath has been set before!");
return;
}
else if (!isType(NODE_FILE))
{
LOG_ERROR("TokenComponentSignature can't be set on node of type: " + getTypeString());
LOG_ERROR("TokenComponentFilePath can't be set on node of type: " + getTypeString());
}
else
{
+2 -2
View File
@@ -24,9 +24,9 @@ public:
enum NodeType : NodeTypeMask
{
NODE_UNDEFINED = 0x1,
NODE_UNDEFINED_FUNCTION = 0x2,
NODE_UNDEFINED_TYPE = 0x2,
NODE_UNDEFINED_VARIABLE = 0x4,
NODE_UNDEFINED_TYPE = 0x8,
NODE_UNDEFINED_FUNCTION = 0x8,
NODE_STRUCT = 0x10,
NODE_CLASS = 0x20,
+5
View File
@@ -1,5 +1,10 @@
#include "data/parser/Parser.h"
Parser::Arguments::Arguments()
: logErrors(true)
{
}
Parser::Parser(ParserClient* client)
: m_client(client)
{
+13 -8
View File
@@ -13,17 +13,22 @@ class TextAccess;
class Parser
{
public:
struct Arguments
{
Arguments();
std::vector<std::string> headerSearchPaths;
std::vector<std::string> systemHeaderSearchPaths;
std::vector<std::string> frameworkSearchPaths;
std::vector<std::string> compilerFlags;
bool logErrors;
};
Parser(ParserClient* client);
virtual ~Parser();
virtual void parseFiles(
const std::vector<FilePath>& filePaths,
const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths) = 0;
virtual void parseFile(
std::shared_ptr<TextAccess> textAccess,
const std::vector<std::string>& systemHeaderSearchPaths,
bool logErrors) = 0;
virtual void parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments) = 0;
virtual void parseFile(std::shared_ptr<TextAccess> textAccess, const Arguments& arguments) = 0;
protected:
ParserClient* m_client;
+1 -1
View File
@@ -703,7 +703,7 @@ bool ASTVisitor::isLocatedInUnparsedProjectFile(const clang::Decl* declaration)
return true;
}
return m_fileRegister->includeFileIsParsing(m_context->getSourceManager().getFilename(location));
return m_fileRegister->includeFileIsParsing(FilePath(m_context->getSourceManager().getFilename(location)));
}
bool ASTVisitor::isLocatedInProjectFile(const clang::Decl* declaration) const
+36 -21
View File
@@ -58,12 +58,10 @@ CxxParser::~CxxParser()
{
}
void CxxParser::parseFiles(
const std::vector<FilePath>& filePaths,
const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths
){
std::vector<std::string> args = getArgs(systemHeaderSearchPaths, headerSearchPaths);
void CxxParser::parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments)
{
// Commandline flags passed to the programm. Everything after '--' will be interpreted by the ClangTool.
std::vector<std::string> args = getCommandlineArguments(arguments);
args.insert(args.begin(), "app");
args.insert(args.begin() + 1, "--");
@@ -93,22 +91,34 @@ void CxxParser::parseFiles(
}
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client);
CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client, arguments.logErrors);
ASTActionFactory actionFactory(m_client, &fileRegister);
clang::tooling::ClangTool tool(*compilationDatabase, sourcePaths);
tool.setDiagnosticConsumer(&reporter);
tool.run(&actionFactory);
std::vector<FilePath> unparsedHeaders = fileRegister.getUnparsedIncludeFilePaths();
for (const FilePath& path : unparsedHeaders)
{
if (!fileRegister.includeFileIsParsed(path))
{
clang::tooling::ClangTool tool(*compilationDatabase, std::vector<std::string>(1, path.str()));
tool.setDiagnosticConsumer(&reporter);
tool.run(&actionFactory);
}
}
delete argv;
}
void CxxParser::parseFile(
std::shared_ptr<TextAccess> textAccess, const std::vector<std::string>& systemHeaderSearchPaths, bool logErrors
){
std::vector<std::string> args = getArgs(systemHeaderSearchPaths, std::vector<std::string>());
void CxxParser::parseFile(std::shared_ptr<TextAccess> textAccess, const Arguments& arguments)
{
std::vector<std::string> args = getCommandlineArguments(arguments);
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client, logErrors);
CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client, arguments.logErrors);
FileRegister fileRegister(m_fileManager, std::vector<FilePath>());
@@ -116,10 +126,8 @@ void CxxParser::parseFile(
runToolOnCodeWithArgs(&reporter, actionFactory.create(), textAccess->getText(), args);
}
std::vector<std::string> CxxParser::getArgs(
const std::vector<std::string>& systemHeaderSearchPaths, const std::vector<std::string>& headerSearchPaths
) const {
// Commandline flags passed to the programm. Everything after '--' will be interpreted by the ClangTool.
std::vector<std::string> CxxParser::getCommandlineArguments(const Arguments& arguments) const
{
std::vector<std::string> args;
// verbose
@@ -138,15 +146,22 @@ std::vector<std::string> CxxParser::getArgs(
args.push_back("-std=c++11");
for (const std::string& path : systemHeaderSearchPaths)
{
args.push_back("-isystem" + path);
}
args.insert(args.begin(), arguments.compilerFlags.begin(), arguments.compilerFlags.end());
for (const std::string& path : headerSearchPaths)
for (const std::string& path : arguments.headerSearchPaths)
{
args.push_back("-I" + path);
}
for (const std::string& path : arguments.systemHeaderSearchPaths)
{
args.push_back("-isystem" + path);
}
for (const std::string& path : arguments.frameworkSearchPaths)
{
args.push_back("-iframework" + path);
}
return args;
}
+3 -11
View File
@@ -10,19 +10,11 @@ public:
CxxParser(ParserClient* client, const FileManager* fileManager);
~CxxParser();
virtual void parseFiles(
const std::vector<FilePath>& filePaths,
const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths);
virtual void parseFile(
std::shared_ptr<TextAccess> textAccess,
const std::vector<std::string>& systemHeaderSearchPaths,
bool logErrors);
virtual void parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments);
virtual void parseFile(std::shared_ptr<TextAccess> textAccess, const Arguments& arguments);
private:
std::vector<std::string> getArgs(
const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths) const;
std::vector<std::string> getCommandlineArguments(const Arguments& arguments) const;
const FileManager* m_fileManager;
};