data: fix anonymous record crash

* implemented handling of anonymous classes and structs.
This commit is contained in:
malte_langkabel
2015-12-11 12:27:38 +01:00
parent 3da20e3e32
commit 52352baa8e
2 changed files with 40 additions and 15 deletions
+5
View File
@@ -168,7 +168,12 @@ ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path i
ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config. ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config.
ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config. ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config.
ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config. ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config.
CxxDeclNameResolver.cpp INFO: could not resolve name of decl at: input.cc:3:2
CxxDeclNameResolver.cpp INFO: could not resolve name of decl at: input.cc:3:2
ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config. ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config.
CxxDeclNameResolver.cpp INFO: could not resolve name of decl at: input.cc:4:2
CxxDeclNameResolver.cpp INFO: could not resolve name of decl at: input.cc:4:2
CxxDeclNameResolver.cpp INFO: could not resolve name of decl at: input.cc:4:2
ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config. ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config.
ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config. ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config.
ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config. ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config.
@@ -40,20 +40,28 @@ NameHierarchy CxxDeclNameResolver::getDeclNameHierarchy()
LOG_INFO("unhandled declaration type: " + std::string(m_declaration->getDeclKindName())); LOG_INFO("unhandled declaration type: " + std::string(m_declaration->getDeclKindName()));
} }
contextNameHierarchy = getContextNameHierarchy(m_declaration->getDeclContext()); if (declName)
if ((clang::isa<clang::NonTypeTemplateParmDecl>(m_declaration) ||
clang::isa<clang::TemplateTypeParmDecl>(m_declaration) ||
clang::isa<clang::TemplateTemplateParmDecl>(m_declaration)) &&
contextNameHierarchy.size() > 0)
{ {
std::string lastContextElementName = contextNameHierarchy.back()->getFullName(); // TODO: what about the signature in this case? contextNameHierarchy = getContextNameHierarchy(m_declaration->getDeclContext());
contextNameHierarchy.pop();
contextNameHierarchy.push(std::make_shared<NameElement>(lastContextElementName + "::" + declName->getFullName())); if ((clang::isa<clang::NonTypeTemplateParmDecl>(m_declaration) ||
clang::isa<clang::TemplateTypeParmDecl>(m_declaration) ||
clang::isa<clang::TemplateTemplateParmDecl>(m_declaration)) &&
contextNameHierarchy.size() > 0)
{
std::string lastContextElementName = contextNameHierarchy.back()->getFullName(); // TODO: what about the signature in this case?
contextNameHierarchy.pop();
contextNameHierarchy.push(std::make_shared<NameElement>(lastContextElementName + "::" + declName->getFullName()));
}
else
{
contextNameHierarchy.push(declName);
}
} }
else else
{ {
contextNameHierarchy.push(declName); const clang::SourceManager& sourceManager = m_declaration->getASTContext().getSourceManager();
LOG_INFO("could not resolve name of decl at: " + m_declaration->getLocation().printToString(sourceManager));
} }
} }
return contextNameHierarchy; return contextNameHierarchy;
@@ -71,13 +79,18 @@ NameHierarchy CxxDeclNameResolver::getContextNameHierarchy(const clang::DeclCont
contextNameHierarchy = getContextNameHierarchy(parentContext); contextNameHierarchy = getContextNameHierarchy(parentContext);
} }
if (clang::isa<clang::NamedDecl>(declContext)) if (const clang::NamedDecl* contextNamedDecl = clang::dyn_cast_or_null<clang::NamedDecl>(declContext))
{ {
std::shared_ptr<NameElement> declName = getDeclName(clang::dyn_cast<clang::NamedDecl>(declContext)); std::shared_ptr<NameElement> declName = getDeclName(contextNamedDecl);
if (declName) if (declName)
{ {
contextNameHierarchy.push(declName); contextNameHierarchy.push(declName);
} }
else
{
const clang::SourceManager& sourceManager = contextNamedDecl->getASTContext().getSourceManager();
LOG_INFO("could not resolve name of decl at: " + contextNamedDecl->getLocation().printToString(sourceManager));
}
} }
} }
return contextNameHierarchy; return contextNameHierarchy;
@@ -87,9 +100,9 @@ std::shared_ptr<NameElement> CxxDeclNameResolver::getDeclName()
{ {
const clang::NamedDecl* declaration = clang::dyn_cast<clang::NamedDecl>(m_declaration); const clang::NamedDecl* declaration = clang::dyn_cast<clang::NamedDecl>(m_declaration);
std::string declNameString = declaration->getNameAsString(); std::string declNameString = declaration->getNameAsString();
if (clang::isa<clang::CXXRecordDecl>(declaration)) if (const clang::CXXRecordDecl* recordDecl = clang::dyn_cast_or_null<clang::CXXRecordDecl>(declaration))
{ {
clang::ClassTemplateDecl* templateClassDeclaration = clang::dyn_cast<clang::CXXRecordDecl>(declaration)->getDescribedClassTemplate(); clang::ClassTemplateDecl* templateClassDeclaration = recordDecl->getDescribedClassTemplate();
if (templateClassDeclaration) if (templateClassDeclaration)
{ {
return getDeclName(templateClassDeclaration); return getDeclName(templateClassDeclaration);
@@ -118,7 +131,7 @@ std::shared_ptr<NameElement> CxxDeclNameResolver::getDeclName()
{ {
//this if fixes the crash, but not the problem TODO //this if fixes the crash, but not the problem TODO
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager(); const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
LOG_INFO("Template getParam out of Range "+declaration->getLocation().printToString(sourceManager)); LOG_INFO("Template getParam out of Range " + declaration->getLocation().printToString(sourceManager));
} }
currentParameterIndex++; currentParameterIndex++;
} }
@@ -143,6 +156,13 @@ std::shared_ptr<NameElement> CxxDeclNameResolver::getDeclName()
templateArgumentNamePart += ">"; templateArgumentNamePart += ">";
return std::make_shared<NameElement>(declNameString + templateArgumentNamePart); return std::make_shared<NameElement>(declNameString + templateArgumentNamePart);
} }
else if (!recordDecl->isLambda() && declNameString.size() == 0)
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
const std::string recordType = (recordDecl->isStruct() ? "struct" : "class");
return std::make_shared<NameElement>("anonymous " + recordType + " (" + FilePath(presumedBegin.getFilename()).fileName() + ")");
}
} }
else if (clang::isa<clang::FunctionDecl>(declaration)) else if (clang::isa<clang::FunctionDecl>(declaration))
{ {