data: Added HeaderSearchPaths to Application- and ProjectSettings
This change allows for parsing of a real codebase by specifying the system header search paths in ApplicationSettings.xml and the additional header search paths in ProjectSettings.xml. Both settings files are now documented in ApplicationSettings_template.xml and ProjectSettings_template.xml, which show all possible settings for each file. This change also fixes some parsing edge cases that occured.
This commit is contained in:
@@ -24,5 +24,12 @@ ParseLocation::ParseLocation(
|
||||
|
||||
bool ParseLocation::isValid() const
|
||||
{
|
||||
return startLineNumber > 0 && endLineNumber >= startLineNumber;
|
||||
if (startLineNumber == endLineNumber)
|
||||
{
|
||||
return startLineNumber > 0 && startColumnNumber <= endColumnNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
return startLineNumber > 0 && startLineNumber < endLineNumber;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,10 @@ public:
|
||||
Parser(ParserClient* client);
|
||||
virtual ~Parser();
|
||||
|
||||
virtual void parseFiles(const std::vector<std::string>& filePaths) = 0;
|
||||
virtual void parseFiles(
|
||||
const std::vector<std::string>& filePaths,
|
||||
const std::vector<std::string>& systemHeaderSearchPaths,
|
||||
const std::vector<std::string>& headerSearchPaths) = 0;
|
||||
virtual void parseFile(std::shared_ptr<TextAccess> textAccess) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -281,6 +281,12 @@ void ASTVisitor::VisitCallExprInDeclBody(clang::FunctionDecl* decl, clang::CallE
|
||||
|
||||
// return nullptr;
|
||||
|
||||
if (!expr->getDirectCallee())
|
||||
{
|
||||
// TODO: Save error at location.
|
||||
return;
|
||||
}
|
||||
|
||||
m_client->onCallParsed(
|
||||
getParseLocation(expr->getSourceRange()),
|
||||
getParseFunction(decl),
|
||||
@@ -290,6 +296,12 @@ void ASTVisitor::VisitCallExprInDeclBody(clang::FunctionDecl* decl, clang::CallE
|
||||
|
||||
void ASTVisitor::VisitCallExprInDeclBody(clang::VarDecl* decl, clang::CallExpr* expr)
|
||||
{
|
||||
if (!expr->getDirectCallee())
|
||||
{
|
||||
// TODO: Save error at location.
|
||||
return;
|
||||
}
|
||||
|
||||
m_client->onCallParsed(
|
||||
getParseLocation(expr->getSourceRange()),
|
||||
getParseVariable(decl),
|
||||
@@ -478,7 +490,10 @@ std::vector<ParseTypeUsage> ASTVisitor::getParameters(clang::FunctionDecl* decla
|
||||
for (unsigned i = 0; i < declaration->getNumParams(); i++)
|
||||
{
|
||||
clang::ParmVarDecl* paramDecl = declaration->getParamDecl(i);
|
||||
parameters.push_back(getParseTypeUsage(paramDecl->getTypeSourceInfo()->getTypeLoc(), paramDecl->getType()));
|
||||
if (paramDecl->getTypeSourceInfo())
|
||||
{
|
||||
parameters.push_back(getParseTypeUsage(paramDecl->getTypeSourceInfo()->getTypeLoc(), paramDecl->getType()));
|
||||
}
|
||||
}
|
||||
|
||||
return parameters;
|
||||
|
||||
@@ -13,12 +13,41 @@ CxxParser::~CxxParser()
|
||||
{
|
||||
}
|
||||
|
||||
void CxxParser::parseFiles(const std::vector<std::string>& filePaths)
|
||||
{
|
||||
// Fake commandline flags passed to the programm. Everything after '--' will be interpreted by the ClangTool.
|
||||
void CxxParser::parseFiles(
|
||||
const std::vector<std::string>& filePaths,
|
||||
const std::vector<std::string>& systemHeaderSearchPaths,
|
||||
const std::vector<std::string>& headerSearchPaths
|
||||
){
|
||||
// Commandline flags passed to the programm. Everything after '--' will be interpreted by the ClangTool.
|
||||
std::vector<std::string> args;
|
||||
args.push_back("app");
|
||||
args.push_back("--");
|
||||
|
||||
// verbose
|
||||
// args.push_back("-v");
|
||||
|
||||
// The option '-x c++' treats subsequent input files as C++.
|
||||
const char* argv[] = { "app", "--", "-x", "c++" };
|
||||
int argc = 4;
|
||||
args.push_back("-x");
|
||||
args.push_back("c++");
|
||||
|
||||
args.push_back("-std=c++11");
|
||||
|
||||
for (const std::string& path : systemHeaderSearchPaths)
|
||||
{
|
||||
args.push_back("-isystem" + path);
|
||||
}
|
||||
|
||||
for (const std::string& path : headerSearchPaths)
|
||||
{
|
||||
args.push_back("-I" + path);
|
||||
}
|
||||
|
||||
int argc = args.size();
|
||||
const char** argv = new const char*[argc];
|
||||
for (size_t i = 0; i < args.size(); i++)
|
||||
{
|
||||
argv[i] = args[i].c_str();
|
||||
}
|
||||
|
||||
std::shared_ptr<clang::tooling::FixedCompilationDatabase> compilationDatabase(
|
||||
clang::tooling::FixedCompilationDatabase::loadFromCommandLine(argc, argv)
|
||||
|
||||
@@ -9,7 +9,10 @@ public:
|
||||
CxxParser(ParserClient* client);
|
||||
~CxxParser();
|
||||
|
||||
virtual void parseFiles(const std::vector<std::string>& filePaths);
|
||||
virtual void parseFiles(
|
||||
const std::vector<std::string>& filePaths,
|
||||
const std::vector<std::string>& systemHeaderSearchPaths,
|
||||
const std::vector<std::string>& headerSearchPaths);
|
||||
virtual void parseFile(std::shared_ptr<TextAccess> textAccess);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user