data: showing local symbols

- added local symbols to storage
- added tests for local symbol parsing
- added MessageActivateLocalSymbols to activate local symbols in code view
- TokenLocations now store their LocationType instead of a plain bool "isScope"
- moved LocationType from TokenLocation to separate file, since it is also used in Annotations now.
- added local_symbol in stylesheet to define a style for hovering and activating these elements
- renamed location to token in stylesheet
This commit is contained in:
malte_langkabel
2016-04-12 13:28:37 +02:00
parent a448485b35
commit b9c4bd05cd
38 changed files with 767 additions and 299 deletions
+38 -3
View File
@@ -108,7 +108,25 @@ Id IntermediateStorage::addFile(const std::string& filePath)
return id;
}
void IntermediateStorage::addSourceLocation(Id elementId, const ParseLocation& location, bool isScope)
Id IntermediateStorage::addLocalSymbol(const std::string& name)
{
std::shared_ptr<StorageLocalSymbol> localSymbol = std::make_shared<StorageLocalSymbol>(0, name);
std::string serialized = serialize(*(localSymbol.get()));
std::unordered_map<std::string, Id>::const_iterator it = m_localSymbolNamesToIds.find(serialized);
if (it != m_localSymbolNamesToIds.end())
{
return it->second;
}
Id id = m_nextId++;
m_localSymbolNamesToIds[serialized] = id;
m_localSymbolIdsToData[id] = localSymbol;
return id;
}
void IntermediateStorage::addSourceLocation(Id elementId, const ParseLocation& location, int type)
{
Id fileNodeId = addFile(location.filePath.str());
m_sourceLocations.push_back(StorageSourceLocation(
@@ -119,7 +137,7 @@ void IntermediateStorage::addSourceLocation(Id elementId, const ParseLocation& l
location.startColumnNumber,
location.endLineNumber,
location.endColumnNumber,
isScope
type
));
}
@@ -238,6 +256,18 @@ void IntermediateStorage::transferToStorage(SqliteStorage& storage)
clientIdToStorageId[it->first] = edgeId;
}
for (std::map<Id, std::shared_ptr<StorageLocalSymbol>>::const_iterator it = m_localSymbolIdsToData.begin(); it != m_localSymbolIdsToData.end(); it++)
{
StorageLocalSymbol clientLocalSymbol = *(it->second.get());
StorageLocalSymbol storageLocalSymbol = storage.getLocalSymbolByName(clientLocalSymbol.name);
Id storageLocalSymbolId = storageLocalSymbol.id;
if (storageLocalSymbolId == 0)
{
storageLocalSymbolId = storage.addLocalSymbol(clientLocalSymbol.name);
}
clientIdToStorageId[it->first] = storageLocalSymbolId;
}
for (size_t i = 0; i < m_sourceLocations.size(); i++)
{
StorageSourceLocation sourceLocation = m_sourceLocations[i];
@@ -263,7 +293,7 @@ void IntermediateStorage::transferToStorage(SqliteStorage& storage)
sourceLocation.startCol,
sourceLocation.endLine,
sourceLocation.endCol,
sourceLocation.isScope
sourceLocation.type
);
}
@@ -393,3 +423,8 @@ std::string IntermediateStorage::serialize(const StorageFile& file)
{
return file.filePath;
}
std::string IntermediateStorage::serialize(const StorageLocalSymbol& localSymbol)
{
return localSymbol.name;
}
+7 -1
View File
@@ -21,7 +21,8 @@ public:
Id addNode(int type, const NameHierarchy& nameHierarchy, int definitionType);
Id addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime);
Id addFile(const std::string& filePath);
void addSourceLocation(Id elementId, const ParseLocation& location, bool isScope);
Id addLocalSymbol(const std::string& name);
void addSourceLocation(Id elementId, const ParseLocation& location, int type);
void addComponentAccess(Id nodeId , int type);
void addCommentLocation(const ParseLocation& location);
void addError(const std::string& message, bool fatal, const ParseLocation& location);
@@ -40,6 +41,7 @@ private:
std::string serialize(const StorageEdge& edge);
std::string serialize(const StorageNode& node);
std::string serialize(const StorageFile& file);
std::string serialize(const StorageLocalSymbol& localSymbol);
std::unordered_map<std::string, Id> m_fileNamesToIds; // this is used to prevent duplicates (unique)
std::unordered_map<Id, std::shared_ptr<StorageFile>> m_fileIdsToData;
@@ -50,6 +52,10 @@ private:
std::unordered_map<std::string, Id> m_edgeNamesToIds; // this is used to prevent duplicates (unique)
std::map<Id, std::shared_ptr<StorageEdge>> m_edgeIdsToData;
std::unordered_map<std::string, Id> m_localSymbolNamesToIds; // this is used to prevent duplicates (unique)
std::map<Id, std::shared_ptr<StorageLocalSymbol>> m_localSymbolIdsToData;
std::vector<StorageSourceLocation> m_sourceLocations;
std::vector<StorageComponentAccess> m_componentAccesses;
std::vector<StorageCommentLocation> m_commentLocations;
+52 -16
View File
@@ -136,14 +136,29 @@ Id SqliteStorage::addFile(const std::string& serializedName, const std::string&
return id;
}
Id SqliteStorage::addLocalSymbol(const std::string& name)
{
m_database.execDML(
"INSERT INTO element(id) VALUES(NULL);"
);
Id id = m_database.lastRowId();
m_database.execDML((
"INSERT INTO local_symbol(id, name) VALUES("
+ std::to_string(id) + ", '" + name + "');"
).c_str());
return id;
}
Id SqliteStorage::addSourceLocation(
Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, bool isScope)
Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type)
{
m_database.execDML((
"INSERT INTO source_location(id, element_id, file_node_id, start_line, start_column, end_line, end_column, is_scope) "
"INSERT INTO source_location(id, element_id, file_node_id, start_line, start_column, end_line, end_column, type) "
"VALUES(NULL, " + std::to_string(elementId) + ", " + std::to_string(fileNodeId) + ", "
+ std::to_string(startLine) + ", " + std::to_string(startCol) + ", "
+ std::to_string(endLine) + ", " + std::to_string(endCol) + ", " + std::to_string(isScope) + ");"
+ std::to_string(endLine) + ", " + std::to_string(endCol) + ", " + std::to_string(type) + ");"
).c_str());
return m_database.lastRowId();
@@ -420,6 +435,18 @@ std::vector<StorageNode> SqliteStorage::getNodesByIds(const std::vector<Id>& nod
return getAllNodes("WHERE id IN (" + utility::join(utility::toStrings(nodeIds), ',') + ")");
}
StorageLocalSymbol SqliteStorage::getLocalSymbolByName(const std::string& name) const
{
StorageLocalSymbol localSymbol(
getFirstResult<Id>(
"SELECT id FROM local_symbol WHERE "
"name == '" + name + "';"
),
name
);
return localSymbol;
}
StorageFile SqliteStorage::getFileById(const Id id) const
{
return getFirstFile(
@@ -474,7 +501,7 @@ void SqliteStorage::setNodeDefinitionType(int definitionType, Id nodeId)
StorageSourceLocation SqliteStorage::getSourceLocationById(const Id id) const
{
return getFirstSourceLocation(
"SELECT id, element_id, file_node_id, start_line, start_column, end_line, end_column, is_scope FROM source_location WHERE id == " + std::to_string(id) + ";"
"SELECT id, element_id, file_node_id, start_line, start_column, end_line, end_column, type FROM source_location WHERE id == " + std::to_string(id) + ";"
);
}
@@ -489,7 +516,7 @@ std::shared_ptr<TokenLocationFile> SqliteStorage::getTokenLocationsForFile(const
}
CppSQLite3Query q = m_database.execQuery((
"SELECT id, element_id, start_line, start_column, end_line, end_column, is_scope FROM source_location WHERE file_node_id == " + std::to_string(fileNodeId) + ";"
"SELECT id, element_id, start_line, start_column, end_line, end_column, type FROM source_location WHERE file_node_id == " + std::to_string(fileNodeId) + ";"
).c_str());
while (!q.eof())
@@ -500,12 +527,12 @@ std::shared_ptr<TokenLocationFile> SqliteStorage::getTokenLocationsForFile(const
const int startColNumber = q.getIntField(3, -1);
const int endLineNumber = q.getIntField(4, -1);
const int endColNumber = q.getIntField(5, -1);
const int isScope = q.getIntField(6, -1);
const int type = q.getIntField(6, -1);
if (locationId != 0 && elementId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 && endColNumber != -1 && isScope != -1)
if (locationId != 0 && elementId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 && endColNumber != -1 && type != -1)
{
TokenLocation* loc = ret->addTokenLocation(locationId, elementId, startLineNumber, startColNumber, endLineNumber, endColNumber);
loc->setType(isScope ? TokenLocation::LOCATION_SCOPE : TokenLocation::LOCATION_TOKEN);
loc->setType(intToLocationType(type));
}
q.nextRow();
}
@@ -524,7 +551,7 @@ std::vector<StorageSourceLocation> SqliteStorage::getTokenLocationsForElementIds
std::vector<StorageSourceLocation> locations;
CppSQLite3Query q = m_database.execQuery((
"SELECT id, element_id, file_node_id, start_line, start_column, end_line, end_column, is_scope FROM source_location WHERE element_id IN (" + utility::join(utility::toStrings(elementIds), ',') + ");"
"SELECT id, element_id, file_node_id, start_line, start_column, end_line, end_column, type FROM source_location WHERE element_id IN (" + utility::join(utility::toStrings(elementIds), ',') + ");"
).c_str());
while (!q.eof())
@@ -536,12 +563,12 @@ std::vector<StorageSourceLocation> SqliteStorage::getTokenLocationsForElementIds
const int startColNumber = q.getIntField(4, -1);
const int endLineNumber = q.getIntField(5, -1);
const int endColNumber = q.getIntField(6, -1);
const int isScope = q.getIntField(7, -1);
const int type = q.getIntField(7, -1);
if (id != 0 && elementId != 0 && fileNodeId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 && endColNumber != -1 && isScope != -1)
if (id != 0 && elementId != 0 && fileNodeId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 && endColNumber != -1 && type != -1)
{
locations.push_back(StorageSourceLocation(
id, elementId, fileNodeId, startLineNumber, startColNumber, endLineNumber, endColNumber, isScope
id, elementId, fileNodeId, startLineNumber, startColNumber, endLineNumber, endColNumber, type
));
}
q.nextRow();
@@ -700,6 +727,7 @@ void SqliteStorage::clearTables()
m_database.execDML("DROP TABLE IF EXISTS main.comment_location;");
m_database.execDML("DROP TABLE IF EXISTS main.component_access;");
m_database.execDML("DROP TABLE IF EXISTS main.source_location;");
m_database.execDML("DROP TABLE IF EXISTS main.local_symbol;");
m_database.execDML("DROP TABLE IF EXISTS main.file;");
m_database.execDML("DROP TABLE IF EXISTS main.node;");
m_database.execDML("DROP TABLE IF EXISTS main.edge;");
@@ -764,6 +792,14 @@ void SqliteStorage::setupTables()
"FOREIGN KEY(id) REFERENCES node(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS local_symbol("
"id INTEGER NOT NULL, "
"name TEXT, "
"PRIMARY KEY(id), "
"FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS source_location("
"id INTEGER NOT NULL, "
@@ -773,7 +809,7 @@ void SqliteStorage::setupTables()
"start_column INTEGER, "
"end_line INTEGER, "
"end_column INTEGER, "
"is_scope INTEGER, "
"type INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(element_id) REFERENCES element(id) ON DELETE CASCADE, "
"FOREIGN KEY(file_node_id) REFERENCES node(id) ON DELETE CASCADE);"
@@ -907,12 +943,12 @@ StorageSourceLocation SqliteStorage::getFirstSourceLocation(const std::string& q
const int startColNumber = q.getIntField(4, -1);
const int endLineNumber = q.getIntField(5, -1);
const int endColNumber = q.getIntField(6, -1);
const int isScope = q.getIntField(7, -1);
const int type = q.getIntField(7, -1);
if (id != 0 && elementId != 0 && fileNodeId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 && endColNumber != -1 && isScope != -1)
if (id != 0 && elementId != 0 && fileNodeId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 && endColNumber != -1 && type != -1)
{
return StorageSourceLocation(
id, elementId, fileNodeId, startLineNumber, startColNumber, endLineNumber, endColNumber, isScope
id, elementId, fileNodeId, startLineNumber, startColNumber, endLineNumber, endColNumber, type
);
}
}
+4 -1
View File
@@ -37,7 +37,8 @@ public:
Id addEdge(int type, Id sourceNodeId, Id targetNodeId);
Id addNode(int type, const std::string& serializedName, int definitionType);
Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime);
Id addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, bool isScope);
Id addLocalSymbol(const std::string& name);
Id addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
Id addComponentAccess(Id memberEdgeId, int type);
@@ -75,6 +76,8 @@ public:
StorageNode getNodeBySerializedName(const std::string& serializedName) const;
std::vector<StorageNode> getNodesByIds(const std::vector<Id>& nodeIds) const;
StorageLocalSymbol getLocalSymbolByName(const std::string& name) const;
StorageFile getFileById(const Id id) const;
StorageFile getFileByPath(const std::string& filePath) const;
std::vector<StorageFile> getAllFiles() const;
+21 -4
View File
@@ -456,7 +456,7 @@ std::vector<Id> Storage::getNodeIdsForLocationIds(const std::vector<Id>& locatio
{
edgeIds.insert(edge.targetNodeId);
}
else
else if(m_sqliteStorage.isNode(elementId))
{
StorageNode node = m_sqliteStorage.getNodeById(elementId);
if (node.id != 0 && intToDefinitionType(node.definitionType) == DEFINITION_EXPLICIT)
@@ -474,6 +474,23 @@ std::vector<Id> Storage::getNodeIdsForLocationIds(const std::vector<Id>& locatio
return utility::toVector(edgeIds);
}
std::vector<Id> Storage::getLocalSymbolIdsForLocationIds(const std::vector<Id>& locationIds) const
{
std::set<Id> localSymbolIds;
for (Id locationId : locationIds)
{
Id elementId = m_sqliteStorage.getElementIdByLocationId(locationId);
if (m_sqliteStorage.getNodeById(elementId).id == 0 && m_sqliteStorage.getEdgeById(elementId).id == 0)
{
localSymbolIds.insert(elementId);
}
}
return utility::toVector(localSymbolIds);
}
std::vector<Id> Storage::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
{
std::set<Id> idSet;
@@ -584,7 +601,7 @@ std::shared_ptr<TokenLocationCollection> Storage::getTokenLocationsForTokenIds(c
if (loc)
{
loc->setType(location.isScope ? TokenLocation::LOCATION_SCOPE : TokenLocation::LOCATION_TOKEN);
loc->setType(intToLocationType(location.type));
}
}
@@ -605,8 +622,8 @@ std::shared_ptr<TokenLocationCollection> Storage::getTokenLocationsForLocationId
location.startLine,
location.startCol,
location.endLine,
location.endCol)->setType(location.isScope ? TokenLocation::LOCATION_SCOPE : TokenLocation::LOCATION_TOKEN
);
location.endCol
)->setType(intToLocationType(location.type));
}
return collection;
+1
View File
@@ -62,6 +62,7 @@ public:
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::vector<Id> getLocalSymbolIdsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const;
virtual Id getTokenIdForFileNode(const FilePath& filePath) const;
+14 -3
View File
@@ -50,9 +50,20 @@ struct StorageFile
std::string modificationTime;
};
struct StorageLocalSymbol
{
StorageLocalSymbol(Id id, const std::string& name)
: id(id)
, name(name)
{}
Id id;
std::string name;
};
struct StorageSourceLocation
{
StorageSourceLocation(Id id, Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, bool isScope)
StorageSourceLocation(Id id, Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type)
: id(id)
, elementId(elementId)
, fileNodeId(fileNodeId)
@@ -60,7 +71,7 @@ struct StorageSourceLocation
, startCol(startCol)
, endLine(endLine)
, endCol(endCol)
, isScope(isScope)
, type(type)
{}
Id id;
@@ -70,7 +81,7 @@ struct StorageSourceLocation
uint startCol;
uint endLine;
uint endCol;
bool isScope;
int type;
};
struct StorageComponentAccess
+1
View File
@@ -44,6 +44,7 @@ public:
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const = 0;
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const = 0;
virtual std::vector<Id> getLocalSymbolIdsForLocationIds(const std::vector<Id>& locationIds) const = 0;
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const = 0;
virtual Id getTokenIdForFileNode(const FilePath& filePath) const = 0;
@@ -143,6 +143,16 @@ std::vector<Id> StorageAccessProxy::getNodeIdsForLocationIds(const std::vector<I
return std::vector<Id>();
}
std::vector<Id> StorageAccessProxy::getLocalSymbolIdsForLocationIds(const std::vector<Id>& locationIds) const
{
if (hasSubject())
{
return m_subject->getLocalSymbolIdsForLocationIds(locationIds);
}
return std::vector<Id>();
}
std::vector<Id> StorageAccessProxy::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
{
if (hasSubject())
+1
View File
@@ -31,6 +31,7 @@ public:
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::vector<Id> getLocalSymbolIdsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const;
virtual Id getTokenIdForFileNode(const FilePath& filePath) const;
+27
View File
@@ -0,0 +1,27 @@
#include "data/location/LocationType.h"
int locationTypeToInt(LocationType type)
{
switch (type)
{
case LOCATION_TOKEN:
return 0;
case LOCATION_SCOPE:
return 1;
case LOCATION_LOCAL_SYMBOL:
return 2;
}
}
LocationType intToLocationType(int value)
{
switch (value)
{
case 0:
return LOCATION_TOKEN;
case 1:
return LOCATION_SCOPE;
case 2:
return LOCATION_LOCAL_SYMBOL;
}
}
+14
View File
@@ -0,0 +1,14 @@
#ifndef LOCATION_TYPE_H
#define LOCATION_TYPE_H
enum LocationType
{
LOCATION_TOKEN,
LOCATION_SCOPE,
LOCATION_LOCAL_SYMBOL
};
int locationTypeToInt(LocationType type);
LocationType intToLocationType(int value);
#endif // LOCATION_TYPE_H
+1 -1
View File
@@ -69,7 +69,7 @@ Id TokenLocation::getTokenId() const
return m_tokenId;
}
TokenLocation::LocationType TokenLocation::getType() const
LocationType TokenLocation::getType() const
{
return m_type;
}
+1 -7
View File
@@ -5,6 +5,7 @@
#include <ostream>
#include <string>
#include "data/location/LocationType.h"
#include "utility/file/FilePath.h"
#include "utility/types.h"
@@ -15,13 +16,6 @@ class TokenLocationLine;
class TokenLocation
{
public:
enum LocationType
{
LOCATION_TOKEN,
LOCATION_SCOPE
};
TokenLocation(Id tokenId, TokenLocationLine* line, unsigned int columnNumber, bool isStart);
TokenLocation(Id locationId, Id tokenId, TokenLocationLine* line, unsigned int columnNumber, bool isStart);
TokenLocation(TokenLocation* other, TokenLocationLine* line, unsigned int columnNumber, bool isStart);
TokenLocation(const TokenLocation& other, TokenLocationLine* line);
+2
View File
@@ -105,6 +105,8 @@ public:
virtual Id onTemplateMemberFunctionSpecializationParsed(
const ParseLocation& location, const NameHierarchy& instantiatedFunction, const NameHierarchy& specializedFunction) = 0;
virtual Id onLocalSymbolParsed(const std::string& name, const ParseLocation& location) = 0;
virtual Id onFileParsed(const FileInfo& fileInfo) = 0;
virtual Id onFileIncludeParsed(
const ParseLocation& location, const FileInfo& fileInfo, const FileInfo& includedFileInfo) = 0;
+59 -35
View File
@@ -5,6 +5,7 @@
#include "data/graph/Edge.h"
#include "utility/logging/logging.h"
#include "utility/utility.h"
#include "data/location/TokenLocation.h"
ParserClientImpl::ParserClientImpl()
{
@@ -58,7 +59,7 @@ Id ParserClientImpl::onTypedefParsed(
log("typedef", typedefName.getQualifiedName(), location);
Id nodeId = addNodeHierarchy(Node::NODE_TYPEDEF, typedefName, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
addAccess(nodeId, access);
return 0;
@@ -75,8 +76,8 @@ Id ParserClientImpl::onClassParsed(
nameHierarchy,
(isImplicit ? DEFINITION_IMPLICIT : (scopeLocation.isValid() ? DEFINITION_EXPLICIT : DEFINITION_NONE))
);
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, scopeLocation, true);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
addSourceLocation(nodeId, scopeLocation, locationTypeToInt(LOCATION_SCOPE));
addAccess(nodeId, access);
return 0;
@@ -93,8 +94,8 @@ Id ParserClientImpl::onStructParsed(
nameHierarchy,
(isImplicit ? DEFINITION_IMPLICIT : (scopeLocation.isValid() ? DEFINITION_EXPLICIT : DEFINITION_NONE))
);
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, scopeLocation, true);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
addSourceLocation(nodeId, scopeLocation, locationTypeToInt(LOCATION_SCOPE));
addAccess(nodeId, access);
return 0;
@@ -105,7 +106,7 @@ Id ParserClientImpl::onGlobalVariableParsed(const ParseLocation& location, const
log("global", variable.getQualifiedName(), location);
Id nodeId = addNodeHierarchy(Node::NODE_GLOBAL_VARIABLE, variable, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
return 0;
}
@@ -115,7 +116,7 @@ Id ParserClientImpl::onFieldParsed(const ParseLocation& location, const NameHier
log("field", field.getQualifiedName(), location);
Id nodeId = addNodeHierarchy(Node::NODE_FIELD, field, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
addAccess(nodeId, access);
return 0;
@@ -127,8 +128,8 @@ Id ParserClientImpl::onFunctionParsed(
log("function", function.getQualifiedNameWithSignature(), location);
Id nodeId = addNodeHierarchy(Node::NODE_FUNCTION, function, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, scopeLocation, true);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
addSourceLocation(nodeId, scopeLocation, locationTypeToInt(LOCATION_SCOPE));
return 0;
}
@@ -144,8 +145,8 @@ Id ParserClientImpl::onMethodParsed(
method,
(isImplicit ? DEFINITION_IMPLICIT : ((location.isValid() && scopeLocation.isValid()) ? (DEFINITION_EXPLICIT) : DEFINITION_NONE))
);
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, scopeLocation, true);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
addSourceLocation(nodeId, scopeLocation, locationTypeToInt(LOCATION_SCOPE));
addAccess(nodeId, access);
return 0;
@@ -157,8 +158,8 @@ Id ParserClientImpl::onNamespaceParsed(
log("namespace", nameHierarchy.getQualifiedName(), location);
Id nodeId = addNodeHierarchy(Node::NODE_NAMESPACE, nameHierarchy, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, scopeLocation, true);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
addSourceLocation(nodeId, scopeLocation, locationTypeToInt(LOCATION_SCOPE));
return 0;
}
@@ -170,8 +171,8 @@ Id ParserClientImpl::onEnumParsed(
log("enum", nameHierarchy.getQualifiedName(), location);
Id nodeId = addNodeHierarchy(Node::NODE_ENUM, nameHierarchy, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, scopeLocation, true);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
addSourceLocation(nodeId, scopeLocation, locationTypeToInt(LOCATION_SCOPE));
addAccess(nodeId, access);
return 0;
@@ -182,7 +183,7 @@ Id ParserClientImpl::onEnumConstantParsed(const ParseLocation& location, const N
log("enum constant", nameHierarchy.getQualifiedName(), location);
Id nodeId = addNodeHierarchy(Node::NODE_ENUM_CONSTANT, nameHierarchy, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
return 0;
}
@@ -193,7 +194,7 @@ Id ParserClientImpl::onTemplateParameterTypeParsed(
log("template parameter type", templateParameterTypeNameHierarchy.getQualifiedName(), location);
Id nodeId = addNodeHierarchy(Node::NODE_TEMPLATE_PARAMETER_TYPE, templateParameterTypeNameHierarchy, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
addSourceLocation(nodeId, location, false);
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
addAccess(nodeId, TokenComponentAccess::ACCESS_TEMPLATE);
return 0;
@@ -208,7 +209,7 @@ Id ParserClientImpl::onInheritanceParsed(
Id childNodeId = addNodeHierarchy(Node::NODE_TYPE, childNameHierarchy, DEFINITION_NONE);
Id parentNodeId = addNodeHierarchy(Node::NODE_TYPE, parentNameHierarchy, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_INHERITANCE, childNodeId, parentNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
@@ -221,7 +222,7 @@ Id ParserClientImpl::onMethodOverrideParsed(
Id overriddenNodeId = addNodeHierarchy(Node::NODE_FUNCTION, overridden, DEFINITION_NONE);
Id overriderNodeId = addNodeHierarchy(Node::NODE_FUNCTION, overrider, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_OVERRIDE, overriderNodeId, overriddenNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
@@ -233,7 +234,7 @@ Id ParserClientImpl::onCallParsed(const ParseLocation& location, const NameHiera
Id callerNodeId = addNodeHierarchy(Node::NODE_FUNCTION, caller, DEFINITION_NONE);
Id calleeNodeId = addNodeHierarchy(Node::NODE_FUNCTION, callee, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_CALL, callerNodeId, calleeNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
@@ -246,7 +247,7 @@ Id ParserClientImpl::onFieldUsageParsed(
Id userNodeId = addNodeHierarchy(Node::NODE_FUNCTION, userNameHierarchy, DEFINITION_NONE);
Id usedNodeId = addNodeHierarchy(Node::NODE_FIELD, usedNameHierarchy, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_USAGE, userNodeId, usedNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
@@ -259,7 +260,7 @@ Id ParserClientImpl::onGlobalVariableUsageParsed( // or static variable used
Id userNodeId = addNodeHierarchy(Node::NODE_FUNCTION, userNameHierarchy, DEFINITION_NONE);
Id usedNodeId = addNodeHierarchy(Node::NODE_GLOBAL_VARIABLE, usedNameHierarchy, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_USAGE, userNodeId, usedNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
@@ -272,7 +273,7 @@ Id ParserClientImpl::onEnumConstantUsageParsed(
Id userNodeId = addNodeHierarchy(Node::NODE_UNDEFINED, userNameHierarchy, DEFINITION_NONE);
Id usedNodeId = addNodeHierarchy(Node::NODE_ENUM_CONSTANT, usedNameHierarchy, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_USAGE, userNodeId, usedNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
@@ -289,7 +290,7 @@ Id ParserClientImpl::onTypeUsageParsed(const ParseLocation& location, const Name
Id functionNodeId = addNodeHierarchy(Node::NODE_UNDEFINED, user, DEFINITION_NONE);
Id typeNodeId = addNodeHierarchy(Node::NODE_TYPE, used, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_TYPE_USAGE, functionNodeId, typeNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
@@ -307,7 +308,7 @@ Id ParserClientImpl::onTemplateArgumentTypeParsed(
Id argumentNodeId = addNodeHierarchy(Node::NODE_TYPE, argumentTypeNameHierarchy, DEFINITION_NONE);
Id templateNodeId = addNodeHierarchy(Node::NODE_UNDEFINED, templateNameHierarchy, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_TEMPLATE_ARGUMENT, templateNodeId, argumentNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return argumentNodeId;
}
@@ -325,7 +326,7 @@ Id ParserClientImpl::onTemplateDefaultArgumentTypeParsed(
Id defaultArgumentNodeId = addNodeHierarchy(Node::NODE_TYPE, defaultArgumentTypeNameHierarchy, DEFINITION_NONE);
Id parameterNodeId = addNodeHierarchy(Node::NODE_TYPE, templateParameterNameHierarchy, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_TEMPLATE_DEFAULT_ARGUMENT, parameterNodeId, defaultArgumentNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return defaultArgumentNodeId;
}
@@ -343,7 +344,7 @@ Id ParserClientImpl::onTemplateSpecializationParsed(
Id specializedId = addNodeHierarchy(Node::NODE_TYPE, specializedNameHierarchy, DEFINITION_NONE);
Id recordNodeId = addNodeHierarchy(Node::NODE_TYPE, specializedFromNameHierarchy, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_TEMPLATE_SPECIALIZATION_OF, specializedId, recordNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
@@ -355,16 +356,30 @@ Id ParserClientImpl::onTemplateMemberFunctionSpecializationParsed(
"template member function specialization",
instantiatedFunction.getQualifiedNameWithSignature() + " -> " + specializedFunction.getQualifiedNameWithSignature(),
location
);
);
Id instantiatedFunctionNodeId = addNodeHierarchy(Node::NODE_FUNCTION, instantiatedFunction, DEFINITION_NONE);
Id specializedFunctionNodeId = addNodeHierarchy(Node::NODE_FUNCTION, specializedFunction, DEFINITION_NONE);
Id edgeId = addEdge(Edge::EDGE_TEMPLATE_MEMBER_SPECIALIZATION_OF, instantiatedFunctionNodeId, specializedFunctionNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
Id ParserClientImpl::onLocalSymbolParsed(const std::string& name, const ParseLocation& location)
{
log(
"local symbol",
name,
location
);
Id localSymbolId = addLocalSymbol(name);
addSourceLocation(localSymbolId, location, locationTypeToInt(LOCATION_LOCAL_SYMBOL));
return localSymbolId;
}
Id ParserClientImpl::onFileParsed(const FileInfo& fileInfo) // TODO: move up to nodes
{
log("file", fileInfo.path.str(), ParseLocation());
@@ -381,7 +396,7 @@ Id ParserClientImpl::onFileIncludeParsed(const ParseLocation& location, const Fi
Id fileNodeId = addFile(fileInfo.path.fileName(), fileInfo.path.str(), utility::timeToString(fileInfo.lastWriteTime));
Id includedFileNodeId = addFile(includedFileInfo.path.fileName(), includedFileInfo.path.str(), utility::timeToString(includedFileInfo.lastWriteTime));
Id edgeId = addEdge(Edge::EDGE_INCLUDE, fileNodeId, includedFileNodeId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return fileNodeId;
}
@@ -392,8 +407,8 @@ Id ParserClientImpl::onMacroDefineParsed(
log("macro", macroNameHierarchy.getQualifiedName(), location);
Id macroId = addNodeHierarchy(Node::NODE_MACRO, macroNameHierarchy, DEFINITION_EXPLICIT);
addSourceLocation(macroId, location, false);
addSourceLocation(macroId, scopeLocation, true);
addSourceLocation(macroId, location, locationTypeToInt(LOCATION_TOKEN));
addSourceLocation(macroId, scopeLocation, locationTypeToInt(LOCATION_SCOPE));
//Id fileNodeId = getFileNodeId(location.filePath); // do we need this???
//addEdge(Edge::EDGE_MACRO_USAGE, fileNodeId, macroId, , location);
@@ -407,7 +422,7 @@ Id ParserClientImpl::onMacroExpandParsed(const ParseLocation &location, const Na
Id macroExpandId = addNodeHierarchy(Node::NODE_MACRO, macroNameHierarchy, DEFINITION_NONE);
Id fileNodeId = addFile(location.filePath.str());
Id edgeId = addEdge(Edge::EDGE_MACRO_USAGE, fileNodeId, macroExpandId);
addSourceLocation(edgeId, location, false);
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
return edgeId;
}
@@ -531,8 +546,17 @@ Id ParserClientImpl::addEdge(int type, Id sourceId, Id targetId)
return m_storage->addEdge(type, sourceId, targetId);
}
Id ParserClientImpl::addLocalSymbol(const std::string& name)
{
if (!m_storage)
{
return 0;
}
void ParserClientImpl::addSourceLocation(Id elementId, const ParseLocation& location, bool isScope)
return m_storage->addLocalSymbol(name);
}
void ParserClientImpl::addSourceLocation(Id elementId, const ParseLocation& location, int type)
{
if (!m_storage)
{
@@ -550,7 +574,7 @@ void ParserClientImpl::addSourceLocation(Id elementId, const ParseLocation& loca
return;
}
m_storage->addSourceLocation(elementId, location, isScope);
m_storage->addSourceLocation(elementId, location, type);
}
void ParserClientImpl::addComponentAccess(Id nodeId , int type)
+4 -1
View File
@@ -78,6 +78,8 @@ public:
virtual Id onTemplateMemberFunctionSpecializationParsed(
const ParseLocation& location, const NameHierarchy& instantiatedFunction, const NameHierarchy& specializedFunction);
virtual Id onLocalSymbolParsed(const std::string& name, const ParseLocation& location);
virtual Id onFileParsed(const FileInfo& fileInfo);
virtual Id onFileIncludeParsed(
const ParseLocation& location, const FileInfo& fileInfo, const FileInfo& includedFileInfo);
@@ -99,7 +101,8 @@ private:
Id addFile(const std::string& filePath);
Id addNode(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType);
Id addEdge(int type, Id sourceId, Id targetId);
void addSourceLocation(Id elementId, const ParseLocation& location, bool isScope);
Id addLocalSymbol(const std::string& name);
void addSourceLocation(Id elementId, const ParseLocation& location, int type);
void addComponentAccess(Id nodeId , int type);
void addCommentLocation(const ParseLocation& location);
void addError(const std::string& message, bool fatal, const ParseLocation& location);