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
+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;
};