data, utility: Fixes to run Opensource Projects

templateSpecializationArgsAsWritten returning null caused a crash
VisitMemberExprInDeclBody for vardecl was missing
subdirectories for headersearchpaths, that the user does not need to add a hugh amount of folders
This commit is contained in:
Andreas Stallinger
2015-09-16 17:08:16 +02:00
parent fb5316cb7f
commit 73b1b77ca8
14 changed files with 110 additions and 16 deletions
+2
View File
@@ -95,6 +95,8 @@ public:
const ParseLocation& location, const ParseVariable& caller, const ParseFunction& callee) = 0;
virtual Id onFieldUsageParsed(
const ParseLocation& location, const ParseFunction& user, const NameHierarchy& usedNameHierarchy) = 0;
virtual Id onFieldUsageParsed(
const ParseLocation& location, const ParseVariable& user, const NameHierarchy& usedNameHierarchy) = 0;
virtual Id onGlobalVariableUsageParsed(
const ParseLocation& location, const ParseFunction& user, const NameHierarchy& usedNameHierarchy) = 0;
virtual Id onGlobalVariableUsageParsed(
+8 -1
View File
@@ -80,7 +80,14 @@ void ASTBodyVisitor::VisitMemberExpr(clang::make_ptr<clang::MemberExpr>::type ex
{
if (expr->getMemberDecl()->getKind() == clang::Decl::Kind::Field)
{
m_client->VisitMemberExprInDeclBody(m_functionDecl, expr);
if(m_functionDecl)
{
m_client->VisitMemberExprInDeclBody(m_functionDecl, expr);
}
else
{
m_client->VisitMemberExprInDeclBody(m_varDecl, expr);
}
}
VisitStmt(expr);
}
@@ -18,6 +18,7 @@ public:
virtual void VisitCXXNewExprInDeclBody(clang::FunctionDecl* decl, clang::CXXNewExpr* expr) = 0;
virtual void VisitCXXNewExprInDeclBody(clang::VarDecl* decl, clang::CXXNewExpr* expr) = 0;
virtual void VisitMemberExprInDeclBody(clang::FunctionDecl* decl, clang::MemberExpr* expr) = 0;
virtual void VisitMemberExprInDeclBody(clang::VarDecl* decl, clang::MemberExpr* expr) = 0;
virtual void VisitGlobalVariableExprInDeclBody(clang::FunctionDecl* decl, clang::DeclRefExpr* expr) = 0;
virtual void VisitGlobalVariableExprInDeclBody(clang::VarDecl* decl, clang::DeclRefExpr* expr) = 0;
virtual void VisitEnumExprInDeclBody(clang::FunctionDecl* decl, clang::DeclRefExpr* expr) = 0;
+39 -8
View File
@@ -456,16 +456,33 @@ bool ASTVisitor::VisitFunctionTemplateDecl(clang::FunctionTemplateDecl *declarat
specializedFunction,
templateFunction);
const clang::ASTTemplateArgumentListInfo* argumentInfoList = specializedFunctionDecl->getTemplateSpecializationArgsAsWritten();
for (size_t i = 0; i < argumentInfoList->NumTemplateArgs; i++)
if(specializedFunctionDecl->getTemplateSpecializationArgsAsWritten())
{
const clang::TemplateArgumentLoc& argumentLoc = argumentInfoList->operator[](i);
const clang::QualType argumentType = argumentLoc.getArgument().getAsType();
const clang::ASTTemplateArgumentListInfo* argumentInfoList = specializedFunctionDecl->getTemplateSpecializationArgsAsWritten();
for (size_t i = 0; i < argumentInfoList->NumTemplateArgs; i++)
{
const clang::TemplateArgumentLoc& argumentLoc = argumentInfoList->operator[](i);
const clang::QualType argumentType = argumentLoc.getArgument().getAsType();
m_client->onTemplateArgumentTypeParsed(
getParseLocation(argumentLoc.getSourceRange()),
utility::qualTypeToDataType(argumentType)->getTypeNameHierarchy(),
specializedFunction.nameHierarchy);
m_client->onTemplateArgumentTypeParsed(
getParseLocation(argumentLoc.getSourceRange()),
utility::qualTypeToDataType(argumentType)->getTypeNameHierarchy(),
specializedFunction.nameHierarchy);
}
}
else
{
const clang::TemplateArgumentList* argumentList = specializedFunctionDecl->getTemplateSpecializationArgs();
for(size_t i = 0; i < argumentList->size(); ++i)
{
const clang::TemplateArgumentLoc& argumentLoc = clang::TemplateArgumentLoc(argumentList->get(i), specializedFunctionDecl->getTypeSourceInfo());
const clang::QualType argumentType = argumentLoc.getArgument().getAsType();
m_client->onTemplateArgumentTypeParsed(
getParseLocation(argumentLoc.getSourceRange()),
utility::qualTypeToDataType(argumentType)->getTypeNameHierarchy(),
specializedFunction.nameHierarchy);
}
}
}
}
@@ -649,6 +666,20 @@ void ASTVisitor::VisitMemberExprInDeclBody(clang::FunctionDecl* decl, clang::Mem
);
}
void ASTVisitor::VisitMemberExprInDeclBody(clang::VarDecl* decl, clang::MemberExpr* expr)
{
ParseLocation parseLocation = getParseLocation(expr->getSourceRange());
const std::string exprName = expr->getMemberNameInfo().getAsString();
parseLocation.endColumnNumber += exprName.size() - 1;
m_client->onFieldUsageParsed(
parseLocation,
getParseVariable(decl),
utility::getDeclNameHierarchy(expr->getMemberDecl())
);
}
void ASTVisitor::VisitGlobalVariableExprInDeclBody(clang::FunctionDecl* decl, clang::DeclRefExpr* expr)
{
ParseLocation parseLocation = getParseLocation(expr->getSourceRange());
+1
View File
@@ -52,6 +52,7 @@ public:
virtual void VisitCXXNewExprInDeclBody(clang::FunctionDecl* decl, clang::CXXNewExpr* expr); // type use of new operator
virtual void VisitCXXNewExprInDeclBody(clang::VarDecl* decl, clang::CXXNewExpr* expr); // type use of new operator in global space
virtual void VisitMemberExprInDeclBody(clang::FunctionDecl* decl, clang::MemberExpr* expr); // field usages
virtual void VisitMemberExprInDeclBody(clang::VarDecl* decl, clang::MemberExpr* expr); // field usages
virtual void VisitGlobalVariableExprInDeclBody(clang::FunctionDecl* decl, clang::DeclRefExpr* expr); // global variable usage
virtual void VisitGlobalVariableExprInDeclBody(clang::VarDecl* decl, clang::DeclRefExpr* expr); // global variable usage
virtual void VisitEnumExprInDeclBody(clang::FunctionDecl* decl, clang::DeclRefExpr* expr); // enum field usage
@@ -99,7 +99,7 @@ std::string CxxDeclNameResolver::getDeclName()
clang::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(declaration);
clang::TemplateParameterList* parameterList = partialSpecializationDecl->getTemplateParameters();
int currentParameterIndex = 0;
unsigned int currentParameterIndex = 0;
std::string specializedParameterNamePart = "<";
int templateArgumentCount = partialSpecializationDecl->getTemplateArgs().size();
@@ -109,7 +109,16 @@ std::string CxxDeclNameResolver::getDeclName()
const clang::TemplateArgument& templateArgument = templateArgumentList.get(i);
if (templateArgument.isDependent()) // IMPORTANT_TODO: fix case when arg depends on template parameter of outer template class, or depends on first template parameter.
{
specializedParameterNamePart += getTemplateParameterString(parameterList->getParam(currentParameterIndex));
if(currentParameterIndex < parameterList->size())
{
specializedParameterNamePart += getTemplateParameterString(parameterList->getParam(currentParameterIndex));
}
else
{
//this if fixes the crash, but not the problem TODO
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
LOG_ERROR("Template getParam out of Range "+declaration->getLocation().printToString(sourceManager));
}
currentParameterIndex++;
}
else
@@ -250,4 +259,3 @@ std::string CxxDeclNameResolver::getTemplateArgumentName(const clang::TemplateAr
CxxTemplateArgumentNameResolver resolver(getIgnoredContextDecls());
return resolver.getTemplateArgumentName(argument);
}