data: function signature handling

* functions will only display their names in the graph view. hovering the nodes shows the signature as a tooltip. However, nodes in the database will be created and used regarding their signature.
* improved lambda handling. All calls to generated lambda functions (constructor, call operator) will now point to the lambda class instead.
* implemented handling of the "auto" type.
* improved the CxxParserTestSuite to use function strings instead of function names for template related functions.
This commit is contained in:
malte_langkabel
2015-12-16 11:27:29 +01:00
parent 28c1a0048b
commit a44af51122
8 changed files with 118 additions and 71 deletions
+14 -16
View File
@@ -433,24 +433,20 @@ std::vector<StorageEdge> SqliteStorage::getEdgesByTargetType(Id targetId, int ty
StorageNode SqliteStorage::getNodeById(Id id) const
{
std::vector<StorageNode> nodes = getAllNodes("WHERE id == " + std::to_string(id));
if (nodes.size())
if (id != 0)
{
return nodes[0];
std::vector<StorageNode> nodes = getAllNodes("WHERE id == " + std::to_string(id));
if (nodes.size())
{
return nodes[0];
}
}
return StorageNode(0, 0, 0, false);
}
StorageNode SqliteStorage::getNodeByNameId(Id nameId) const
std::vector<StorageNode> SqliteStorage::getNodesByNameId(Id nameId) const
{
std::vector<StorageNode> nodes = getAllNodes("WHERE name_id == " + std::to_string(nameId));
if (nodes.size())
{
return nodes[0];
}
return StorageNode(0, 0, 0, false);
return getAllNodes("WHERE name_id == " + std::to_string(nameId));
}
std::vector<StorageNode> SqliteStorage::getNodesByIds(const std::vector<Id>& nodeIds) const
@@ -736,18 +732,20 @@ std::vector<StorageComponentAccess> SqliteStorage::getComponentAccessByMemberEdg
return accesses;
}
Id SqliteStorage::getNodeIdBySignature(const std::string& signature) const
std::vector<Id> SqliteStorage::getNodeIdsBySignature(const std::string& signature) const
{
CppSQLite3Query q = m_database.execQuery((
"SELECT id, signature FROM function_signature WHERE signature == '" + signature + "';"
"SELECT id FROM function_signature WHERE signature == '" + signature + "';"
).c_str());
std::vector<Id> ids;
while (!q.eof())
{
return q.getIntField(0, 0);
ids.push_back(q.getIntField(0, 0));
q.nextRow();
}
return 0;
return ids;
}
std::string SqliteStorage::getSignatureByNodeId(Id nodeId) const
+2 -2
View File
@@ -78,7 +78,7 @@ public:
std::vector<StorageEdge> getEdgesByTargetType(Id targetId, int type) const;
StorageNode getNodeById(Id id) const;
StorageNode getNodeByNameId(Id nameId) const;
std::vector<StorageNode> getNodesByNameId(Id nameId) const;
std::vector<StorageNode> getNodesByIds(const std::vector<Id>& nodeIds) const;
StorageFile getFileById(const Id id) const;
@@ -107,7 +107,7 @@ public:
StorageComponentAccess getComponentAccessByMemberEdgeId(Id memberEdgeId) const;
std::vector<StorageComponentAccess> getComponentAccessByMemberEdgeIds(const std::vector<Id>& memberEdgeIds) const;
Id getNodeIdBySignature(const std::string& signature) const;
std::vector<Id> getNodeIdsBySignature(const std::string& signature) const;
std::string getSignatureByNodeId(Id nodeId) const;
std::vector<StorageCommentLocation> getCommentLocationsInFile(const FilePath& filePath) const;
+59 -9
View File
@@ -772,7 +772,12 @@ Id Storage::getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) co
currentId = m_sqliteStorage.getNameHierarchyElementIdByName(nameHierarchy[i]->getFullName(), currentId);
}
return m_sqliteStorage.getNodeByNameId(currentId).id;
std::vector<StorageNode> nodes = m_sqliteStorage.getNodesByNameId(currentId);
if (nodes.size() > 0) // TODO: make it impossible that one name id referrs to n nodes.
{
return nodes[0].id;
}
return 0;
}
Id Storage::getIdForEdge(
@@ -1307,24 +1312,64 @@ Id Storage::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarch
for (size_t i = 0; i < nameIds.size(); i++)
{
Id nameId = nameIds[i];
bool lastName = (i == nameHierarchy.size() - 1);
const bool isLastElement = (i == nameHierarchy.size() - 1);
const std::string& signature = nameHierarchy[i]->getFullSignature();
const bool hasSignature = (signature.size() > 0);
Node::NodeType type = (lastName ? nodeType : Node::NODE_UNDEFINED);
Node::NodeType type = (isLastElement ? nodeType : Node::NODE_UNDEFINED);
StorageNode node(0, 0, 0, false);
if (hasSignature)
{
std::vector<Id> potentialIds = m_sqliteStorage.getNodeIdsBySignature(signature);
if (parentNodeId != 0)
{
for (size_t i = 0; i < potentialIds.size(); i++)
{
if (m_sqliteStorage.getEdgeBySourceTargetType(parentNodeId, potentialIds[i], Edge::EDGE_MEMBER).id != 0)
{
node = m_sqliteStorage.getNodeById(potentialIds[i]);
break;
}
}
}
else if (potentialIds.size() > 0)
{
node = m_sqliteStorage.getNodeById(potentialIds[0]);
}
}
else
{
std::vector<StorageNode> potentialIds = m_sqliteStorage.getNodesByNameId(nameId);
if (parentNodeId != 0)
{
for (size_t i = 0; i < potentialIds.size(); i++)
{
if (m_sqliteStorage.getEdgeBySourceTargetType(parentNodeId, potentialIds[i].id, Edge::EDGE_MEMBER).id != 0)
{
node = potentialIds[i];
break;
}
}
}
else if (potentialIds.size() > 0)
{
node = potentialIds[0];
}
}
const StorageNode node = m_sqliteStorage.getNodeByNameId(nameId);
Id nodeId = node.id;
if (nodeId && !node.defined && lastName && defined)
if (nodeId && !node.defined && isLastElement && defined)
{
m_sqliteStorage.setNodeDefined(true, nodeId);
}
if (nodeId == 0)
{
nodeId = m_sqliteStorage.addNode(Node::typeToInt(type), nameId, lastName && defined);
nodeId = m_sqliteStorage.addNode(Node::typeToInt(type), nameId, isLastElement && defined);
std::string signature = nameHierarchy[i]->getFullSignature();
if (signature.size() != 0)
if (hasSignature)
{
m_sqliteStorage.addSignature(nodeId, signature);
}
@@ -1334,7 +1379,7 @@ Id Storage::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarch
addEdge(parentNodeId, nodeId, Edge::EDGE_MEMBER);
}
}
else if (lastName) // Update the type of the last node if the new type is more specific.
else if (isLastElement) // Update the type of the last node if the new type is more specific.
{
Node::NodeType storedType = Node::intToType(node.type);
if (type > storedType)
@@ -1433,6 +1478,11 @@ Id Storage::addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type)
Id Storage::addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type, ParseLocation location)
{
if (!sourceNodeId || !targetNodeId)
{
return 0;
}
Id edgeId = addEdge(sourceNodeId, targetNodeId, type);
addSourceLocation(edgeId, location, false);
+2 -3
View File
@@ -107,10 +107,9 @@ std::string ParserClient::parameterStr(const std::vector<ParseTypeUsage> paramet
std::string ParserClient::functionStr(const ParseFunction& function)
{
//return function.getFullName();
std::string str =
function.returnType.dataType->getFullTypeName() + " " + function.getFullName();
return addStaticPrefix(str, function.isStatic);
function.returnType.dataType->getFullTypeName() + " " + function.getFullName() + parameterStr(function.parameters);
return addConstPrefix(addStaticPrefix(str, function.isStatic), function.isConst, false);
}
ParserClient::ParserClient()