data: anonymous unions

* fixed crashes that occurred when parsing unnamed unions.
This commit is contained in:
malte_langkabel
2015-12-14 17:12:19 +01:00
parent 7b6c83d441
commit 6b750de333
2 changed files with 27 additions and 13 deletions
+12 -2
View File
@@ -424,7 +424,7 @@ Id Storage::onFieldUsageParsed(
log("field usage", user.getFullName() + " -> " + usedNameHierarchy.getFullName(), location);
Id userNodeId = addNodeHierarchy(Node::NODE_FUNCTION, user, false);
Id usedNodeId = addNodeHierarchy(Node::NODE_GLOBAL_VARIABLE, usedNameHierarchy, false);
Id usedNodeId = addNodeHierarchy(Node::NODE_FIELD, usedNameHierarchy, false);
Id edgeId = addEdge(userNodeId, usedNodeId, Edge::EDGE_USAGE, location);
@@ -437,7 +437,7 @@ Id Storage::onFieldUsageParsed(
log("global usage", user.getFullName() + " -> " + usedNameHierarchy.getFullName(), location);
Id userNodeId = addNodeHierarchy(Node::NODE_FUNCTION, user.nameHierarchy, false);
Id usedNodeId = addNodeHierarchy(Node::NODE_GLOBAL_VARIABLE, usedNameHierarchy, false);
Id usedNodeId = addNodeHierarchy(Node::NODE_FIELD, usedNameHierarchy, false);
Id edgeId = addEdge(userNodeId, usedNodeId, Edge::EDGE_USAGE, location);
@@ -1296,6 +1296,11 @@ TimePoint Storage::getFileModificationTime(const FilePath& filePath) const
Id Storage::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, bool defined)
{
if (nameHierarchy.size() == 0)
{
return 0;
}
std::vector<Id> nameIds = addNameHierarchyElements(nameHierarchy);
Id parentNodeId = 0;
@@ -1411,6 +1416,11 @@ Id Storage::addSourceLocation(Id elementNodeId, const ParseLocation &location, b
Id Storage::addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type)
{
if (!sourceNodeId || !targetNodeId)
{
return 0;
}
Id edgeId = m_sqliteStorage.getEdgeBySourceTargetType(sourceNodeId, targetNodeId, type).id;
if (!edgeId)
@@ -37,7 +37,7 @@ NameHierarchy CxxDeclNameResolver::getDeclNameHierarchy()
}
else
{
LOG_INFO("unhandled declaration type: " + std::string(m_declaration->getDeclKindName()));
LOG_ERROR("unhandled declaration type: " + std::string(m_declaration->getDeclKindName()));
}
if (declName)
@@ -61,7 +61,7 @@ NameHierarchy CxxDeclNameResolver::getDeclNameHierarchy()
else
{
const clang::SourceManager& sourceManager = m_declaration->getASTContext().getSourceManager();
LOG_INFO("could not resolve name of decl at: " + m_declaration->getLocation().printToString(sourceManager));
LOG_ERROR("could not resolve name of decl at: " + m_declaration->getLocation().printToString(sourceManager));
}
}
return contextNameHierarchy;
@@ -86,11 +86,6 @@ NameHierarchy CxxDeclNameResolver::getContextNameHierarchy(const clang::DeclCont
{
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;
@@ -131,7 +126,7 @@ std::shared_ptr<NameElement> CxxDeclNameResolver::getDeclName()
{
//this if fixes the crash, but not the problem TODO
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
LOG_INFO("Template getParam out of Range " + declaration->getLocation().printToString(sourceManager));
LOG_ERROR("Template getParam out of Range " + declaration->getLocation().printToString(sourceManager));
}
currentParameterIndex++;
}
@@ -156,6 +151,11 @@ std::shared_ptr<NameElement> CxxDeclNameResolver::getDeclName()
templateArgumentNamePart += ">";
return std::make_shared<NameElement>(declNameString + templateArgumentNamePart);
}
else if (recordDecl->isLambda())
{
// return empty pointer since lambdas will be handled at the level of the individual functions... not optimal.
return std::shared_ptr<NameElement>();
}
else if (!recordDecl->isLambda() && declNameString.size() == 0)
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
@@ -258,12 +258,16 @@ std::shared_ptr<NameElement> CxxDeclNameResolver::getDeclName()
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
return std::make_shared<NameElement>("anonymous enum (" + FilePath(presumedBegin.getFilename()).fileName() + ")");
}
if (declNameString.size() > 0)
{
return std::make_shared<NameElement>(declNameString);
}
return std::shared_ptr<NameElement>();
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
LOG_ERROR("could not resolve name of decl at: " + declaration->getLocation().printToString(sourceManager));
return std::make_shared<NameElement>("anonymous symbol (" + FilePath(presumedBegin.getFilename()).fileName() + ")");
}
std::shared_ptr<NameElement> CxxDeclNameResolver::getDeclName(const clang::NamedDecl* declaration)
@@ -289,7 +293,7 @@ std::string CxxDeclNameResolver::getTemplateParameterString(const clang::NamedDe
templateParameterTypeString = getTemplateParameterTypeString(clang::dyn_cast<clang::TemplateTemplateParmDecl>(parameter));
break;
default:
LOG_INFO("Unhandled kind of template parameter.");
LOG_ERROR("Unhandled kind of template parameter.");
}
std::string parameterName = parameter->getName();