logic: reduced overhead in storage data types
* node represents something that is not yet defines * nodes that are defined are either files or symbols fortune cookie message = trust your intuition
This commit is contained in:
@@ -65,9 +65,7 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
m_fileContent = fileContent;
|
||||
m_typeSolver = typeSolver;
|
||||
|
||||
String[] filePathParts = filePath.split("/");
|
||||
String fileName = filePathParts[filePathParts.length - 1];
|
||||
m_context.add(new DeclContext(fileName + "\ts\tp"));
|
||||
m_context.add(new DeclContext(filePath + "\ts\tp"));
|
||||
}
|
||||
|
||||
// --- record declarations ---
|
||||
|
||||
@@ -14,10 +14,10 @@ IntermediateStorage::~IntermediateStorage()
|
||||
|
||||
void IntermediateStorage::clear()
|
||||
{
|
||||
m_fileNamesToIds.clear();
|
||||
m_fileIdsToData.clear();
|
||||
m_symbolNamesToIds.clear();
|
||||
m_symbolIdsToData.clear();
|
||||
m_nodeNamesToIds.clear();
|
||||
m_nodeIdsToData.clear();
|
||||
m_files.clear();
|
||||
m_symbols.clear();
|
||||
m_edgeNamesToIds.clear();
|
||||
m_edgeIdsToData.clear();
|
||||
m_localSymbolNamesToIds.clear();
|
||||
@@ -36,65 +36,40 @@ size_t IntermediateStorage::getSourceLocationCount() const
|
||||
return m_sourceLocationNamesToIds.size();
|
||||
}
|
||||
|
||||
Id IntermediateStorage::addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime)
|
||||
Id IntermediateStorage::addNode(int type, const std::string& serializedName)
|
||||
{
|
||||
std::shared_ptr<StorageFile> file = std::make_shared<StorageFile>(0, serializedName, filePath, modificationTime);
|
||||
std::shared_ptr<StorageNode> node = std::make_shared<StorageNode>(0, type, serializedName);
|
||||
|
||||
std::string serialized = serialize(*(file.get()));
|
||||
std::unordered_map<std::string, Id>::const_iterator it = m_fileNamesToIds.find(serialized);
|
||||
if (it != m_fileNamesToIds.end())
|
||||
std::string serialized = serialize(*(node.get()));
|
||||
std::unordered_map<std::string, Id>::const_iterator it = m_nodeNamesToIds.find(serialized);
|
||||
if (it != m_nodeNamesToIds.end())
|
||||
{
|
||||
Id id = it->second;
|
||||
if (m_fileIdsToData[id]->filePath.size() == 0) // stored information is incomplete.
|
||||
std::map<Id, std::shared_ptr<StorageNode>>::const_iterator it2 = m_nodeIdsToData.find(it->second);
|
||||
std::shared_ptr<StorageNode> storedNode = it2->second;
|
||||
if (storedNode->type < type)
|
||||
{
|
||||
m_fileIdsToData[id]->filePath = filePath; // so we replace it.
|
||||
}
|
||||
if (m_fileIdsToData[id]->modificationTime.size() == 0) // stored information is incomplete.
|
||||
{
|
||||
m_fileIdsToData[id]->modificationTime = modificationTime; // so we replace it.
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
Id id = m_nextId++;
|
||||
m_fileNamesToIds[serialized] = id;
|
||||
m_fileIdsToData[id] = file;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Id IntermediateStorage::addSymbol(int type, const std::string& serializedName, int definitionType)
|
||||
{
|
||||
std::shared_ptr<StorageSymbol> symbol = std::make_shared<StorageSymbol>(0, type, serializedName, definitionType);
|
||||
|
||||
std::string serialized = serialize(*(symbol.get()));
|
||||
std::unordered_map<std::string, Id>::const_iterator it = m_symbolNamesToIds.find(serialized);
|
||||
if (it != m_symbolNamesToIds.end())
|
||||
{
|
||||
std::map<Id, std::shared_ptr<StorageSymbol>>::const_iterator it2 = m_symbolIdsToData.find(it->second);
|
||||
std::shared_ptr<StorageSymbol> storedSymbol = it2->second;
|
||||
if (storedSymbol->definitionType == 0)
|
||||
{
|
||||
if (definitionType > 0)
|
||||
{
|
||||
storedSymbol->definitionType = definitionType;
|
||||
}
|
||||
|
||||
if (storedSymbol->type < type)
|
||||
{
|
||||
storedSymbol->type = type;
|
||||
}
|
||||
storedNode->type = type;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Id id = m_nextId++;
|
||||
m_symbolNamesToIds[serialized] = id;
|
||||
m_symbolIdsToData[id] = symbol;
|
||||
const Id id = m_nextId++;
|
||||
m_nodeNamesToIds[serialized] = id;
|
||||
m_nodeIdsToData[id] = node;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void IntermediateStorage::addFile(const Id id, const std::string& filePath, const std::string& modificationTime)
|
||||
{
|
||||
m_files.push_back(StorageFile(id, filePath, modificationTime));
|
||||
}
|
||||
|
||||
void IntermediateStorage::addSymbol(const Id id, int definitionType)
|
||||
{
|
||||
m_symbols.push_back(StorageSymbol(id, definitionType));
|
||||
}
|
||||
|
||||
Id IntermediateStorage::addEdge(int type, Id sourceId, Id targetId)
|
||||
{
|
||||
std::shared_ptr<StorageEdge> edge = std::make_shared<StorageEdge>(0, type, sourceId, targetId);
|
||||
@@ -106,7 +81,7 @@ Id IntermediateStorage::addEdge(int type, Id sourceId, Id targetId)
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Id id = m_nextId++;
|
||||
const Id id = m_nextId++;
|
||||
m_edgeNamesToIds[serialized] = id;
|
||||
m_edgeIdsToData[id] = edge;
|
||||
|
||||
@@ -124,7 +99,7 @@ Id IntermediateStorage::addLocalSymbol(const std::string& name)
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Id id = m_nextId++;
|
||||
const Id id = m_nextId++;
|
||||
m_localSymbolNamesToIds[serialized] = id;
|
||||
m_localSymbolIdsToData[id] = localSymbol;
|
||||
|
||||
@@ -150,7 +125,7 @@ Id IntermediateStorage::addSourceLocation(Id fileNodeId, uint startLine, uint st
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Id id = m_nextId++;
|
||||
const Id id = m_nextId++;
|
||||
m_sourceLocationNamesToIds[serialized] = id;
|
||||
m_sourceLocationIdsToData[id] = sourceLocation;
|
||||
|
||||
@@ -192,19 +167,27 @@ void IntermediateStorage::addError(const std::string& message, const FilePath& f
|
||||
));
|
||||
}
|
||||
|
||||
void IntermediateStorage::forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const
|
||||
void IntermediateStorage::forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const
|
||||
{
|
||||
for (std::unordered_map<Id, std::shared_ptr<StorageFile>>::const_iterator it = m_fileIdsToData.begin(); it != m_fileIdsToData.end(); it++)
|
||||
for (std::map<Id, std::shared_ptr<StorageNode>>::const_iterator it = m_nodeIdsToData.begin(); it != m_nodeIdsToData.end(); it++)
|
||||
{
|
||||
callback(it->first, *(it->second.get()));
|
||||
}
|
||||
}
|
||||
|
||||
void IntermediateStorage::forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const
|
||||
void IntermediateStorage::forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const
|
||||
{
|
||||
for (std::map<Id, std::shared_ptr<StorageSymbol>>::const_iterator it = m_symbolIdsToData.begin(); it != m_symbolIdsToData.end(); it++)
|
||||
for (std::vector<StorageFile>::const_iterator it = m_files.begin(); it != m_files.end(); it++)
|
||||
{
|
||||
callback(it->first, *(it->second.get()));
|
||||
callback(*it);
|
||||
}
|
||||
}
|
||||
|
||||
void IntermediateStorage::forEachSymbol(std::function<void(const StorageSymbol& /*data*/)> callback) const
|
||||
{
|
||||
for (std::vector<StorageSymbol>::const_iterator it = m_symbols.begin(); it != m_symbols.end(); it++)
|
||||
{
|
||||
callback(*it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,14 +256,9 @@ std::string IntermediateStorage::serialize(const StorageEdge& edge) const
|
||||
);
|
||||
}
|
||||
|
||||
std::string IntermediateStorage::serialize(const StorageSymbol& symbol) const
|
||||
std::string IntermediateStorage::serialize(const StorageNode& node) const
|
||||
{
|
||||
return symbol.serializedName;
|
||||
}
|
||||
|
||||
std::string IntermediateStorage::serialize(const StorageFile& file) const
|
||||
{
|
||||
return file.filePath;
|
||||
return node.serializedName;
|
||||
}
|
||||
|
||||
std::string IntermediateStorage::serialize(const StorageLocalSymbol& localSymbol) const
|
||||
|
||||
@@ -17,8 +17,9 @@ public:
|
||||
void clear();
|
||||
size_t getSourceLocationCount() const;
|
||||
|
||||
virtual Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime);
|
||||
virtual Id addSymbol(int type, const std::string& serializedName, int definitionType);
|
||||
virtual Id addNode(int type, const std::string& serializedName);
|
||||
virtual void addFile(const Id id, const std::string& filePath, const std::string& modificationTime);
|
||||
virtual void addSymbol(const Id id, int definitionType);
|
||||
virtual Id addEdge(int type, Id sourceId, Id targetId);
|
||||
virtual Id addLocalSymbol(const std::string& name);
|
||||
virtual Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
@@ -27,8 +28,9 @@ public:
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
|
||||
|
||||
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const;
|
||||
virtual void forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
|
||||
virtual void forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const;
|
||||
virtual void forEachSymbol(std::function<void(const StorageSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachEdge(std::function<void(const Id /*id*/, const StorageEdge& /*data*/)> callback) const;
|
||||
virtual void forEachLocalSymbol(std::function<void(const Id /*id*/, const StorageLocalSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachSourceLocation(std::function<void(const Id /*id*/, const StorageSourceLocation& /*data*/)> callback) const;
|
||||
@@ -39,16 +41,15 @@ public:
|
||||
|
||||
private:
|
||||
std::string serialize(const StorageEdge& edge) const;
|
||||
std::string serialize(const StorageSymbol& symbol) const;
|
||||
std::string serialize(const StorageFile& file) const;
|
||||
std::string serialize(const StorageNode& node) const;
|
||||
std::string serialize(const StorageLocalSymbol& localSymbol) const;
|
||||
std::string serialize(const StorageSourceLocation& sourceLocation) const;
|
||||
|
||||
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;
|
||||
std::unordered_map<std::string, Id> m_nodeNamesToIds; // this is used to prevent duplicates (unique)
|
||||
std::map<Id, std::shared_ptr<StorageNode>> m_nodeIdsToData;
|
||||
|
||||
std::unordered_map<std::string, Id> m_symbolNamesToIds; // this is used to prevent duplicates (unique)
|
||||
std::map<Id, std::shared_ptr<StorageSymbol>> m_symbolIdsToData;
|
||||
std::vector<StorageFile> m_files;
|
||||
std::vector<StorageSymbol> m_symbols;
|
||||
|
||||
std::unordered_map<std::string, Id> m_edgeNamesToIds; // this is used to prevent duplicates (unique)
|
||||
std::map<Id, std::shared_ptr<StorageEdge>> m_edgeIdsToData;
|
||||
|
||||
+162
-117
@@ -37,46 +37,40 @@ PersistentStorage::~PersistentStorage()
|
||||
{
|
||||
}
|
||||
|
||||
Id PersistentStorage::addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime)
|
||||
Id PersistentStorage::addNode(int type, const std::string& serializedName)
|
||||
{
|
||||
Id fileId = m_sqliteStorage.getFileByPath(filePath).id;
|
||||
if (fileId == 0)
|
||||
const StorageNode storedNode = m_sqliteStorage.getNodeBySerializedName(serializedName);
|
||||
Id id = storedNode.id;
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
fileId = m_sqliteStorage.addFile(
|
||||
serializedName,
|
||||
filePath,
|
||||
modificationTime
|
||||
);
|
||||
}
|
||||
return fileId;
|
||||
}
|
||||
|
||||
Id PersistentStorage::addSymbol(int type, const std::string& serializedName, int definitionType)
|
||||
{
|
||||
const StorageSymbol storedSymbol = m_sqliteStorage.getSymbolBySerializedName(serializedName);
|
||||
|
||||
Id symbolId = storedSymbol.id;
|
||||
|
||||
if (symbolId == 0)
|
||||
{
|
||||
symbolId = m_sqliteStorage.addSymbol(type, serializedName, definitionType);
|
||||
id = m_sqliteStorage.addNode(type, serializedName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (storedSymbol.definitionType == 0)
|
||||
if (storedNode.type < type)
|
||||
{
|
||||
if (definitionType > 0)
|
||||
{
|
||||
m_sqliteStorage.setSymbolDefinitionType(definitionType, symbolId);
|
||||
}
|
||||
|
||||
if (storedSymbol.type < type)
|
||||
{
|
||||
m_sqliteStorage.setNodeType(type, symbolId);
|
||||
}
|
||||
m_sqliteStorage.setNodeType(type, id);
|
||||
}
|
||||
}
|
||||
return symbolId;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void PersistentStorage::addFile(const Id id, const std::string& filePath, const std::string& modificationTime)
|
||||
{
|
||||
if (m_sqliteStorage.getFirstById<StorageFile>(id).id == 0)
|
||||
{
|
||||
m_sqliteStorage.addFile(id, filePath, modificationTime);
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::addSymbol(const Id id, int definitionType)
|
||||
{
|
||||
if (m_sqliteStorage.getFirstById<StorageSymbol>(id).id == 0)
|
||||
{
|
||||
m_sqliteStorage.addSymbol(id, definitionType);
|
||||
}
|
||||
}
|
||||
|
||||
Id PersistentStorage::addEdge(int type, Id sourceId, Id targetId)
|
||||
@@ -154,19 +148,27 @@ void PersistentStorage::addError(
|
||||
);
|
||||
}
|
||||
|
||||
void PersistentStorage::forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const
|
||||
void PersistentStorage::forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageFile& file: m_sqliteStorage.getAll<StorageFile>())
|
||||
for (StorageNode& node: m_sqliteStorage.getAll<StorageNode>())
|
||||
{
|
||||
callback(file.id, file);
|
||||
callback(node.id, node);
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const
|
||||
void PersistentStorage::forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageFile& file: m_sqliteStorage.getAll<StorageFile>())
|
||||
{
|
||||
callback(file);
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::forEachSymbol(std::function<void(const StorageSymbol& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageSymbol& symbol: m_sqliteStorage.getAll<StorageSymbol>())
|
||||
{
|
||||
callback(symbol.id, symbol);
|
||||
callback(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,14 +537,13 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::set<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const
|
||||
{
|
||||
// search in indices
|
||||
std::vector<SearchResult> results = m_symbolIndex.search(query, maxResultsCount, maxResultsCount); // TODO: rename symbolIndex
|
||||
std::vector<SearchResult> results = m_symbolIndex.search(query, maxResultsCount, maxResultsCount);
|
||||
|
||||
// fetch StorageNodes for node ids
|
||||
std::map<Id, StorageNode> storageNodeMap;
|
||||
std::map<Id, StorageSymbol> storageSymbolMap;
|
||||
{
|
||||
std::vector<Id> elementIds;
|
||||
@@ -552,14 +553,14 @@ std::set<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const st
|
||||
elementIds.insert(elementIds.end(), result.elementIds.begin(), result.elementIds.end());
|
||||
}
|
||||
|
||||
std::vector<StorageSymbol> storageSymbols = m_sqliteStorage.getAllByIds<StorageSymbol>(elementIds);
|
||||
|
||||
for (StorageSymbol& symbol : storageSymbols)
|
||||
for (StorageNode& node : m_sqliteStorage.getAllByIds<StorageNode>(elementIds))
|
||||
{
|
||||
if (symbol.id > 0)
|
||||
{
|
||||
storageSymbolMap.emplace(symbol.id, symbol);
|
||||
}
|
||||
storageNodeMap[node.id] = node;
|
||||
}
|
||||
|
||||
for (StorageSymbol& symbol : m_sqliteStorage.getAllByIds<StorageSymbol>(elementIds))
|
||||
{
|
||||
storageSymbolMap[symbol.id] = symbol;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,22 +570,22 @@ std::set<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const st
|
||||
{
|
||||
SearchMatch match;
|
||||
|
||||
const StorageSymbol* firstSymbol = nullptr;
|
||||
const StorageNode* firstNode = nullptr;
|
||||
for (const Id& elementId : result.elementIds)
|
||||
{
|
||||
if (elementId != 0)
|
||||
{
|
||||
const StorageSymbol& symbol = storageSymbolMap[elementId];
|
||||
match.nameHierarchies.push_back(NameHierarchy::deserialize(symbol.serializedName));
|
||||
const StorageNode& node = storageNodeMap[elementId];
|
||||
match.nameHierarchies.push_back(NameHierarchy::deserialize(node.serializedName));
|
||||
|
||||
if (!match.hasChildren)
|
||||
{
|
||||
match.hasChildren = m_hierarchyCache.nodeHasChildren(symbol.id);
|
||||
match.hasChildren = m_hierarchyCache.nodeHasChildren(node.id);
|
||||
}
|
||||
|
||||
if (!firstSymbol)
|
||||
if (!firstNode)
|
||||
{
|
||||
firstSymbol = &symbol;
|
||||
firstNode = &node;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -592,18 +593,18 @@ std::set<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const st
|
||||
match.name = result.text;
|
||||
|
||||
match.text = result.text;
|
||||
const size_t idx = m_hierarchyCache.getIndexOfLastVisibleParentNode(firstSymbol->id);
|
||||
const size_t idx = m_hierarchyCache.getIndexOfLastVisibleParentNode(firstNode->id);
|
||||
const NameHierarchy& name = match.nameHierarchies[0];
|
||||
match.text = name.getRange(idx, name.size()).getQualifiedName();
|
||||
match.subtext = name.getRange(0, idx).getQualifiedName();
|
||||
|
||||
match.indices = result.indices;
|
||||
match.score = result.score;
|
||||
match.nodeType = Node::intToType(firstSymbol->type);
|
||||
match.nodeType = Node::intToType(firstNode->type);
|
||||
match.typeName = Node::getTypeString(match.nodeType);
|
||||
match.searchType = SearchMatch::SEARCH_TOKEN;
|
||||
|
||||
if (intToDefinitionType(firstSymbol->definitionType) == DEFINITION_NONE
|
||||
if (storageSymbolMap.find(firstNode->id) == storageSymbolMap.end()
|
||||
&& match.nodeType != Node::NODE_UNDEFINED)
|
||||
{
|
||||
match.typeName = "undefined " + match.typeName;
|
||||
@@ -682,8 +683,15 @@ std::vector<SearchMatch> PersistentStorage::getSearchMatchesForTokenIds(const st
|
||||
{
|
||||
SearchMatch match;
|
||||
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(m_sqliteStorage.getFirstById<StorageNode>(elementId).serializedName);
|
||||
match.name = nameHierarchy.getQualifiedName();
|
||||
match.text = nameHierarchy.getRawName();
|
||||
match.nameHierarchies.push_back(nameHierarchy.getQualifiedName());
|
||||
match.searchType = SearchMatch::SEARCH_TOKEN;
|
||||
|
||||
if (m_sqliteStorage.isFile(elementId))
|
||||
{
|
||||
match.text = FilePath(match.text).fileName();
|
||||
match.nodeType = Node::NODE_FILE;
|
||||
}
|
||||
else if (m_sqliteStorage.isNode(elementId))
|
||||
@@ -696,12 +704,6 @@ std::vector<SearchMatch> PersistentStorage::getSearchMatchesForTokenIds(const st
|
||||
continue;
|
||||
}
|
||||
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(m_sqliteStorage.getFirstById<StorageNode>(elementId).serializedName);
|
||||
match.name = nameHierarchy.getQualifiedName();
|
||||
match.text = nameHierarchy.getRawName();
|
||||
match.nameHierarchies.push_back(nameHierarchy.getQualifiedName());
|
||||
match.searchType = SearchMatch::SEARCH_TOKEN;
|
||||
|
||||
matches.push_back(match);
|
||||
}
|
||||
|
||||
@@ -714,20 +716,29 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForAll() const
|
||||
|
||||
std::shared_ptr<Graph> graph = std::make_shared<Graph>();
|
||||
|
||||
std::vector<Id> tokenIds;
|
||||
std::unordered_set<Id> explicitlyDefinedSymbolIds;
|
||||
for (StorageSymbol symbol: m_sqliteStorage.getAll<StorageSymbol>())
|
||||
{
|
||||
if (intToDefinitionType(symbol.definitionType) == DEFINITION_EXPLICIT &&
|
||||
if (intToDefinitionType(symbol.definitionType) == DEFINITION_EXPLICIT)
|
||||
{
|
||||
explicitlyDefinedSymbolIds.insert(symbol.id);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Id> tokenIds;
|
||||
for (StorageNode node: m_sqliteStorage.getAll<StorageNode>())
|
||||
{
|
||||
if (explicitlyDefinedSymbolIds.find(node.id) != explicitlyDefinedSymbolIds.end() &&
|
||||
(
|
||||
!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(symbol.id) ||
|
||||
!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(node.id) ||
|
||||
(
|
||||
Node::intToType(symbol.type) == Node::NODE_NAMESPACE || // TODO: use & operator here
|
||||
Node::intToType(symbol.type) == Node::NODE_PACKAGE
|
||||
Node::intToType(node.type) == Node::NODE_NAMESPACE || // TODO: use & operator here
|
||||
Node::intToType(node.type) == Node::NODE_PACKAGE
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
tokenIds.push_back(symbol.id);
|
||||
tokenIds.push_back(node.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1384,49 +1395,64 @@ void PersistentStorage::addNodesToGraph(const std::vector<Id>& nodeIds, Graph* g
|
||||
return;
|
||||
}
|
||||
|
||||
for (const StorageSymbol& storageSymbol : m_sqliteStorage.getAllByIds<StorageSymbol>(nodeIds))
|
||||
std::unordered_map<Id, StorageSymbol> symbolMap;
|
||||
for (const StorageSymbol& symbol : m_sqliteStorage.getAllByIds<StorageSymbol>(nodeIds))
|
||||
{
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(storageSymbol.serializedName);
|
||||
|
||||
Node::NodeType type = Node::intToType(storageSymbol.type);
|
||||
DefinitionType defType = intToDefinitionType(storageSymbol.definitionType);
|
||||
Node* node = graph->createNode(
|
||||
storageSymbol.id,
|
||||
type,
|
||||
nameHierarchy,
|
||||
defType != DEFINITION_NONE
|
||||
);
|
||||
|
||||
if (defType == DEFINITION_IMPLICIT)
|
||||
{
|
||||
node->setImplicit(true);
|
||||
}
|
||||
else if (defType == DEFINITION_EXPLICIT)
|
||||
{
|
||||
node->setExplicit(true);
|
||||
}
|
||||
|
||||
if (type == Node::NODE_FUNCTION || type == Node::NODE_METHOD)
|
||||
{
|
||||
std::string signatureString = nameHierarchy.getRawNameWithSignature();
|
||||
if (signatureString.size() > 0) // this should always be the case since functions and methods must have sigs.
|
||||
{
|
||||
node->addComponentSignature(
|
||||
std::make_shared<TokenComponentSignature>(signatureString)
|
||||
);
|
||||
}
|
||||
}
|
||||
symbolMap[symbol.id] = symbol;
|
||||
}
|
||||
|
||||
for (const StorageFile& storageFile : m_sqliteStorage.getAllByIds<StorageFile>(nodeIds))
|
||||
for (const StorageNode& storageNode : m_sqliteStorage.getAllByIds<StorageNode>(nodeIds))
|
||||
{
|
||||
Node* node = graph->createNode(
|
||||
storageFile.id,
|
||||
Node::NODE_FILE,
|
||||
NameHierarchy::deserialize(storageFile.serializedName),
|
||||
true
|
||||
);
|
||||
node->setExplicit(true);
|
||||
const Node::NodeType type = Node::intToType(storageNode.type);
|
||||
if (type == Node::NODE_FILE)
|
||||
{
|
||||
const FilePath filePath(NameHierarchy::deserialize(storageNode.serializedName).getRawName());
|
||||
Node* node = graph->createNode(
|
||||
storageNode.id,
|
||||
Node::NODE_FILE,
|
||||
NameHierarchy(filePath.fileName()),
|
||||
true
|
||||
);
|
||||
node->setExplicit(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
const NameHierarchy nameHierarchy = NameHierarchy::deserialize(storageNode.serializedName);
|
||||
|
||||
DefinitionType defType = DEFINITION_NONE;
|
||||
auto it = symbolMap.find(storageNode.id);
|
||||
if (it != symbolMap.end())
|
||||
{
|
||||
defType = intToDefinitionType(it->second.definitionType);
|
||||
}
|
||||
|
||||
Node* node = graph->createNode(
|
||||
storageNode.id,
|
||||
type,
|
||||
nameHierarchy,
|
||||
defType != DEFINITION_NONE
|
||||
);
|
||||
|
||||
if (defType == DEFINITION_IMPLICIT)
|
||||
{
|
||||
node->setImplicit(true);
|
||||
}
|
||||
else if (defType == DEFINITION_EXPLICIT)
|
||||
{
|
||||
node->setExplicit(true);
|
||||
}
|
||||
|
||||
if (type == Node::NODE_FUNCTION || type == Node::NODE_METHOD)
|
||||
{
|
||||
std::string signatureString = nameHierarchy.getRawNameWithSignature();
|
||||
if (signatureString.size() > 0) // this should always be the case since functions and methods must have sigs.
|
||||
{
|
||||
node->addComponentSignature(
|
||||
std::make_shared<TokenComponentSignature>(signatureString)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1622,25 +1648,44 @@ void PersistentStorage::buildSearchIndex()
|
||||
|
||||
FilePath dbPath = getDbFilePath();
|
||||
|
||||
std::unordered_map<Id, StorageSymbol> symbolMap;
|
||||
for (StorageSymbol symbol : m_sqliteStorage.getAll<StorageSymbol>())
|
||||
{
|
||||
if (intToDefinitionType(symbol.definitionType) != DEFINITION_IMPLICIT)
|
||||
{
|
||||
// we don't use the signature here, so elements with the same signature share the same node.
|
||||
m_symbolIndex.addNode(symbol.id, NameHierarchy::deserialize(symbol.serializedName).getQualifiedName());
|
||||
}
|
||||
symbolMap[symbol.id] = symbol;
|
||||
}
|
||||
|
||||
std::unordered_map<Id, StorageFile> fileMap;
|
||||
for (StorageFile file : m_sqliteStorage.getAll<StorageFile>())
|
||||
{
|
||||
FilePath filePath = file.filePath;
|
||||
fileMap[file.id] = file;
|
||||
}
|
||||
|
||||
if (filePath.exists())
|
||||
for (StorageNode node : m_sqliteStorage.getAll<StorageNode>())
|
||||
{
|
||||
if (Node::intToType(node.type) == Node::NODE_FILE)
|
||||
{
|
||||
filePath = filePath.relativeTo(dbPath);
|
||||
}
|
||||
auto it = fileMap.find(node.id);
|
||||
if (it != fileMap.end())
|
||||
{
|
||||
FilePath filePath = it->second.filePath;
|
||||
|
||||
m_fileIndex.addNode(file.id, filePath.str());
|
||||
if (filePath.exists())
|
||||
{
|
||||
filePath = filePath.relativeTo(dbPath);
|
||||
}
|
||||
|
||||
m_fileIndex.addNode(it->second.id, filePath.str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = symbolMap.find(node.id);
|
||||
if (it == symbolMap.end() || intToDefinitionType(it->second.definitionType) != DEFINITION_IMPLICIT)
|
||||
{
|
||||
// we don't use the signature here, so elements with the same signature share the same node.
|
||||
m_symbolIndex.addNode(node.id, NameHierarchy::deserialize(node.serializedName).getQualifiedName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_symbolIndex.finishSetup();
|
||||
|
||||
@@ -27,8 +27,9 @@ public:
|
||||
PersistentStorage(const FilePath& dbPath);
|
||||
virtual ~PersistentStorage();
|
||||
|
||||
virtual Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime);
|
||||
virtual Id addSymbol(int type, const std::string& serializedName, int definitionType);
|
||||
virtual Id addNode(int type, const std::string& serializedName);
|
||||
virtual void addFile(const Id id, const std::string& filePath, const std::string& modificationTime);
|
||||
virtual void addSymbol(const Id id, int definitionType);
|
||||
virtual Id addEdge(int type, Id sourceId, Id targetId);
|
||||
virtual Id addLocalSymbol(const std::string& name);
|
||||
virtual Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
@@ -37,8 +38,9 @@ public:
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
|
||||
|
||||
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const;
|
||||
virtual void forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
|
||||
virtual void forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const;
|
||||
virtual void forEachSymbol(std::function<void(const StorageSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachEdge(std::function<void(const Id /*id*/, const StorageEdge& /*data*/)> callback) const;
|
||||
virtual void forEachLocalSymbol(std::function<void(const Id /*id*/, const StorageLocalSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachSourceLocation(std::function<void(const Id /*id*/, const StorageSourceLocation& /*data*/)> callback) const;
|
||||
|
||||
@@ -182,7 +182,7 @@ Id SqliteStorage::addEdge(int type, Id sourceNodeId, Id targetNodeId)
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteStorage::addNode(int type, const std::string& serializedName)
|
||||
Id SqliteStorage::addNode(const int type, const std::string& serializedName)
|
||||
{
|
||||
executeStatement("INSERT INTO element(id) VALUES(NULL);");
|
||||
Id id = m_database.lastRowId();
|
||||
@@ -198,21 +198,16 @@ Id SqliteStorage::addNode(int type, const std::string& serializedName)
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteStorage::addSymbol(int type, const std::string& serializedName, int definitionType)
|
||||
void SqliteStorage::addSymbol(const int id, const int definitionType)
|
||||
{
|
||||
Id id = addNode(type, serializedName);
|
||||
|
||||
executeStatement(
|
||||
"INSERT INTO symbol(id, definition_type) VALUES("
|
||||
+ std::to_string(id) + ", " + std::to_string(definitionType) + ");"
|
||||
);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteStorage::addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime)
|
||||
void SqliteStorage::addFile(const int id, const std::string& filePath, const std::string& modificationTime)
|
||||
{
|
||||
Id id = addNode(Node::NODE_FILE, serializedName);
|
||||
std::shared_ptr<TextAccess> content = TextAccess::createFromFile(filePath);
|
||||
unsigned int lineCount = content->getLineCount();
|
||||
|
||||
@@ -228,8 +223,6 @@ Id SqliteStorage::addFile(const std::string& serializedName, const std::string&
|
||||
|
||||
stmt.bind(1, content->getText().c_str());
|
||||
executeStatement(stmt);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteStorage::addLocalSymbol(const std::string& name)
|
||||
@@ -530,31 +523,6 @@ StorageNode SqliteStorage::getNodeBySerializedName(const std::string& serialized
|
||||
return StorageNode();
|
||||
}
|
||||
|
||||
StorageSymbol SqliteStorage::getSymbolBySerializedName(const std::string& serializedName) const
|
||||
{
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(
|
||||
"SELECT node.id, node.type, node.serialized_name, symbol.definition_type FROM node INNER JOIN symbol ON node.id = symbol.id WHERE node.serialized_name == ? LIMIT 1;"
|
||||
);
|
||||
|
||||
stmt.bind(1, serializedName.c_str());
|
||||
CppSQLite3Query q = executeQuery(stmt);
|
||||
|
||||
if (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const int type = q.getIntField(1, -1);
|
||||
const std::string serializedName = q.getStringField(2, "");
|
||||
const int definitionType = q.getIntField(3, 0);
|
||||
|
||||
if (id != 0 && type != -1)
|
||||
{
|
||||
return StorageSymbol(id, type, serializedName, definitionType);
|
||||
}
|
||||
}
|
||||
|
||||
return StorageSymbol();
|
||||
}
|
||||
|
||||
StorageLocalSymbol SqliteStorage::getLocalSymbolByName(const std::string& name) const
|
||||
{
|
||||
return doGetFirst<StorageLocalSymbol>("WHERE name == '" + name + "'");
|
||||
@@ -1031,38 +999,6 @@ void SqliteStorage::setApplicationVersion()
|
||||
insertOrUpdateMetaValue("version", Version::getApplicationVersion().toString());
|
||||
}
|
||||
|
||||
template <>
|
||||
StorageSymbol SqliteStorage::getFirstById<StorageSymbol>(const Id id) const
|
||||
{
|
||||
if (id != 0)
|
||||
{
|
||||
return doGetFirst<StorageSymbol>("WHERE node.id == " + std::to_string(id));
|
||||
}
|
||||
return StorageSymbol();
|
||||
}
|
||||
|
||||
template <>
|
||||
StorageFile SqliteStorage::getFirstById<StorageFile>(const Id id) const
|
||||
{
|
||||
if (id != 0)
|
||||
{
|
||||
return doGetFirst<StorageFile>("WHERE node.id == " + std::to_string(id));
|
||||
}
|
||||
return StorageFile();
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageSymbol> SqliteStorage::getAllByIds<StorageSymbol>(const std::vector<Id>& ids) const
|
||||
{
|
||||
return doGetAll<StorageSymbol>("WHERE node.id IN (" + utility::join(utility::toStrings(ids), ',') + ")");
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageFile> SqliteStorage::getAllByIds<StorageFile>(const std::vector<Id>& ids) const
|
||||
{
|
||||
return doGetAll<StorageFile>("WHERE node.id IN (" + utility::join(utility::toStrings(ids), ',') + ")");
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageEdge> SqliteStorage::doGetAll<StorageEdge>(const std::string& query) const
|
||||
{
|
||||
@@ -1116,20 +1052,18 @@ template <>
|
||||
std::vector<StorageSymbol> SqliteStorage::doGetAll<StorageSymbol>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT node.id, node.type, node.serialized_name, symbol.definition_type FROM node INNER JOIN symbol ON node.id == symbol.id " + query + ";"
|
||||
"SELECT id, definition_type FROM symbol " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageSymbol> symbols;
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const int type = q.getIntField(1, -1);
|
||||
const std::string serializedName = q.getStringField(2, "");
|
||||
const int definitionType = q.getIntField(3, 0);
|
||||
const int definitionType = q.getIntField(1, 0);
|
||||
|
||||
if (id != 0 && type != -1)
|
||||
if (id != 0)
|
||||
{
|
||||
symbols.push_back(StorageSymbol(id, type, serializedName, definitionType));
|
||||
symbols.push_back(StorageSymbol(id, definitionType));
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
@@ -1141,21 +1075,19 @@ template <>
|
||||
std::vector<StorageFile> SqliteStorage::doGetAll<StorageFile>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT file.id, node.serialized_name, file.path, file.modification_time FROM file "
|
||||
"INNER JOIN node ON file.id = node.id " + query + ";"
|
||||
"SELECT id, path, modification_time FROM file " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageFile> files;
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const std::string serializedName = q.getStringField(1, "");
|
||||
const std::string filePath = q.getStringField(2, "");
|
||||
const std::string modificationTime = q.getStringField(3, "");
|
||||
const std::string filePath = q.getStringField(1, "");
|
||||
const std::string modificationTime = q.getStringField(2, "");
|
||||
|
||||
if (id != 0)
|
||||
{
|
||||
files.push_back(StorageFile(id, serializedName, filePath, modificationTime));
|
||||
files.push_back(StorageFile(id, filePath, modificationTime));
|
||||
}
|
||||
q.nextRow();
|
||||
}
|
||||
|
||||
@@ -57,11 +57,9 @@ public:
|
||||
|
||||
Id addEdge(int type, Id sourceNodeId, Id targetNodeId);
|
||||
|
||||
private:
|
||||
Id addNode(int type, const std::string& serializedName);
|
||||
public:
|
||||
Id addSymbol(int type, const std::string& serializedName, int definitionType);
|
||||
Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime);
|
||||
Id addNode(const int type, const std::string& serializedName);
|
||||
void addSymbol(const int id, int definitionType);
|
||||
void addFile(const int id, const std::string& filePath, const std::string& modificationTime);
|
||||
Id addLocalSymbol(const std::string& name);
|
||||
Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
bool addOccurrence(Id elementId, Id sourceLocationId);
|
||||
@@ -93,7 +91,6 @@ public:
|
||||
std::vector<StorageEdge> getEdgesByTargetType(const std::vector<Id>& targetIds, int type) const;
|
||||
|
||||
StorageNode getNodeBySerializedName(const std::string& serializedName) const;
|
||||
StorageSymbol getSymbolBySerializedName(const std::string& serializedName) const;
|
||||
|
||||
StorageLocalSymbol getLocalSymbolByName(const std::string& name) const;
|
||||
|
||||
@@ -190,16 +187,6 @@ private:
|
||||
std::vector<std::pair<int, SqliteIndex>> m_indices;
|
||||
};
|
||||
|
||||
template <>
|
||||
StorageSymbol SqliteStorage::getFirstById<StorageSymbol>(const Id id) const;
|
||||
template <>
|
||||
StorageFile SqliteStorage::getFirstById<StorageFile>(const Id id) const;
|
||||
|
||||
template <>
|
||||
std::vector<StorageSymbol> SqliteStorage::getAllByIds<StorageSymbol>(const std::vector<Id>& ids) const;
|
||||
template <>
|
||||
std::vector<StorageFile> SqliteStorage::getAllByIds<StorageFile>(const std::vector<Id>& ids) const;
|
||||
|
||||
template <>
|
||||
std::vector<StorageEdge> SqliteStorage::doGetAll<StorageEdge>(const std::string& query) const;
|
||||
template <>
|
||||
|
||||
+37
-23
@@ -24,15 +24,10 @@ void Storage::inject(Storage* injected)
|
||||
|
||||
std::unordered_map<Id, Id> injectedIdToOwnId;
|
||||
|
||||
injected->forEachFile(
|
||||
[&](Id injectedId, const StorageFile& injectedData)
|
||||
injected->forEachNode(
|
||||
[&](Id injectedId, const StorageNode& injectedData)
|
||||
{
|
||||
if (injectedData.serializedName.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Id ownId = addFile(injectedData.serializedName, injectedData.filePath, injectedData.modificationTime);
|
||||
const Id ownId = addNode(injectedData.type, injectedData.serializedName);
|
||||
if (ownId != 0)
|
||||
{
|
||||
injectedIdToOwnId[injectedId] = ownId;
|
||||
@@ -40,14 +35,33 @@ void Storage::inject(Storage* injected)
|
||||
}
|
||||
);
|
||||
|
||||
injected->forEachSymbol(
|
||||
[&](Id injectedId, const StorageSymbol& injectedData)
|
||||
injected->forEachFile(
|
||||
[&](const StorageFile& injectedData)
|
||||
{
|
||||
Id ownId = addSymbol(injectedData.type, injectedData.serializedName, injectedData.definitionType);
|
||||
if (ownId != 0)
|
||||
std::unordered_map<Id, Id>::const_iterator it;
|
||||
it = injectedIdToOwnId.find(injectedData.id);
|
||||
if (it == injectedIdToOwnId.end())
|
||||
{
|
||||
injectedIdToOwnId[injectedId] = ownId;
|
||||
return;
|
||||
}
|
||||
const Id ownId = it->second;
|
||||
|
||||
addFile(ownId, injectedData.filePath, injectedData.modificationTime);
|
||||
}
|
||||
);
|
||||
|
||||
injected->forEachSymbol(
|
||||
[&](const StorageSymbol& injectedData)
|
||||
{
|
||||
std::unordered_map<Id, Id>::const_iterator it;
|
||||
it = injectedIdToOwnId.find(injectedData.id);
|
||||
if (it == injectedIdToOwnId.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
const Id ownId = it->second;
|
||||
|
||||
addSymbol(ownId, injectedData.definitionType);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -60,16 +74,16 @@ void Storage::inject(Storage* injected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id ownSourceId = it->second;
|
||||
const Id ownSourceId = it->second;
|
||||
|
||||
it = injectedIdToOwnId.find(injectedData.targetNodeId);
|
||||
if (it == injectedIdToOwnId.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id ownTargetId = it->second;
|
||||
const Id ownTargetId = it->second;
|
||||
|
||||
Id ownId = addEdge(injectedData.type, ownSourceId, ownTargetId);
|
||||
const Id ownId = addEdge(injectedData.type, ownSourceId, ownTargetId);
|
||||
|
||||
if (ownId != 0)
|
||||
{
|
||||
@@ -81,7 +95,7 @@ void Storage::inject(Storage* injected)
|
||||
injected->forEachLocalSymbol(
|
||||
[&](const Id injectedId, const StorageLocalSymbol& injectedData)
|
||||
{
|
||||
Id ownId = addLocalSymbol(injectedData.name);
|
||||
const Id ownId = addLocalSymbol(injectedData.name);
|
||||
if (ownId != 0)
|
||||
{
|
||||
injectedIdToOwnId[injectedId] = ownId;
|
||||
@@ -98,9 +112,9 @@ void Storage::inject(Storage* injected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id ownFileNodeId = it->second;
|
||||
const Id ownFileNodeId = it->second;
|
||||
|
||||
Id ownId = addSourceLocation(
|
||||
const Id ownId = addSourceLocation(
|
||||
ownFileNodeId,
|
||||
injectedData.startLine,
|
||||
injectedData.startCol,
|
||||
@@ -124,14 +138,14 @@ void Storage::inject(Storage* injected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id ownElementId = it->second;
|
||||
const Id ownElementId = it->second;
|
||||
|
||||
it = injectedIdToOwnId.find(injectedData.sourceLocationId);
|
||||
if (it == injectedIdToOwnId.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id ownSourceLocationId = it->second;
|
||||
const Id ownSourceLocationId = it->second;
|
||||
|
||||
addOccurrence(ownElementId, ownSourceLocationId);
|
||||
}
|
||||
@@ -146,7 +160,7 @@ void Storage::inject(Storage* injected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id ownNodeId = it->second;
|
||||
const Id ownNodeId = it->second;
|
||||
|
||||
addComponentAccess(ownNodeId, injectedData.type);
|
||||
}
|
||||
@@ -161,7 +175,7 @@ void Storage::inject(Storage* injected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id ownFileNodeId = it->second;
|
||||
const Id ownFileNodeId = it->second;
|
||||
|
||||
addCommentLocation(
|
||||
ownFileNodeId,
|
||||
|
||||
@@ -15,8 +15,9 @@ public:
|
||||
Storage();
|
||||
virtual ~Storage();
|
||||
|
||||
virtual Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime) = 0;
|
||||
virtual Id addSymbol(int type, const std::string& serializedName, int definitionType) = 0;
|
||||
virtual Id addNode(int type, const std::string& serializedName) = 0;
|
||||
virtual void addFile(const Id id, const std::string& filePath, const std::string& modificationTime) = 0;
|
||||
virtual void addSymbol(const Id id, int definitionType) = 0;
|
||||
virtual Id addEdge(int type, Id sourceId, Id targetId) = 0;
|
||||
virtual Id addLocalSymbol(const std::string& name) = 0;
|
||||
virtual Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) = 0;
|
||||
@@ -25,8 +26,9 @@ public:
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) = 0;
|
||||
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed) = 0;
|
||||
|
||||
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const = 0;
|
||||
virtual void forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const = 0;
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const = 0;
|
||||
virtual void forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const = 0;
|
||||
virtual void forEachSymbol(std::function<void(const StorageSymbol& /*data*/)> callback) const = 0;
|
||||
virtual void forEachEdge(std::function<void(const Id /*id*/, const StorageEdge& /*data*/)> callback) const = 0;
|
||||
virtual void forEachLocalSymbol(std::function<void(const Id /*id*/, const StorageLocalSymbol& /*data*/)> callback) const = 0;
|
||||
virtual void forEachSourceLocation(std::function<void(const Id /*id*/, const StorageSourceLocation& /*data*/)> callback) const = 0;
|
||||
|
||||
@@ -53,21 +53,15 @@ struct StorageSymbol
|
||||
{
|
||||
StorageSymbol()
|
||||
: id(0)
|
||||
, type(0)
|
||||
, serializedName("")
|
||||
, definitionType(definitionTypeToInt(DEFINITION_NONE))
|
||||
{}
|
||||
|
||||
StorageSymbol(Id id, int type, const std::string& serializedName, int definitionType)
|
||||
StorageSymbol(Id id, int definitionType)
|
||||
: id(id)
|
||||
, type(type)
|
||||
, serializedName(serializedName)
|
||||
, definitionType(definitionType)
|
||||
{}
|
||||
|
||||
Id id;
|
||||
int type;
|
||||
std::string serializedName;
|
||||
int definitionType;
|
||||
};
|
||||
|
||||
@@ -75,20 +69,17 @@ struct StorageFile
|
||||
{
|
||||
StorageFile()
|
||||
: id(0)
|
||||
, serializedName("")
|
||||
, filePath("")
|
||||
, modificationTime("")
|
||||
{}
|
||||
|
||||
StorageFile(Id id, const std::string& serializedName, const std::string& filePath, const std::string& modificationTime)
|
||||
StorageFile(Id id, const std::string& filePath, const std::string& modificationTime)
|
||||
: id(id)
|
||||
, serializedName(serializedName)
|
||||
, filePath(filePath)
|
||||
, modificationTime(modificationTime)
|
||||
{}
|
||||
|
||||
Id id;
|
||||
std::string serializedName;
|
||||
std::string filePath;
|
||||
std::string modificationTime;
|
||||
};
|
||||
|
||||
@@ -38,7 +38,8 @@ Id ParserClientImpl::recordSymbol(
|
||||
AccessKind access, DefinitionType definitionType
|
||||
)
|
||||
{
|
||||
Id nodeId = addNodeHierarchy(symbolKindToNodeType(symbolType), symbolName, definitionType);
|
||||
Id nodeId = addNodeHierarchy(symbolName, symbolKindToNodeType(symbolType));
|
||||
addSymbol(nodeId, definitionType);
|
||||
addAccess(nodeId, access);
|
||||
return nodeId;
|
||||
}
|
||||
@@ -69,8 +70,8 @@ void ParserClientImpl::recordReference(
|
||||
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
|
||||
const ParseLocation& location)
|
||||
{
|
||||
Id contextNodeId = addNodeHierarchy(Node::NODE_UNDEFINED, contextName, DEFINITION_NONE);
|
||||
Id referencedNodeId = addNodeHierarchy(Node::NODE_UNDEFINED, referencedName, DEFINITION_NONE);
|
||||
Id contextNodeId = addNodeHierarchy(contextName);
|
||||
Id referencedNodeId = addNodeHierarchy(referencedName);
|
||||
Id edgeId = addEdge(referenceKindToEdgeType(referenceKind), contextNodeId, referencedNodeId);
|
||||
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
|
||||
}
|
||||
@@ -85,18 +86,19 @@ void ParserClientImpl::onError(const ParseLocation& location, const std::string&
|
||||
|
||||
void ParserClientImpl::onLocalSymbolParsed(const std::string& name, const ParseLocation& location)
|
||||
{
|
||||
Id localSymbolId = addLocalSymbol(name);
|
||||
const Id localSymbolId = addLocalSymbol(name);
|
||||
addSourceLocation(localSymbolId, location, locationTypeToInt(LOCATION_LOCAL_SYMBOL));
|
||||
}
|
||||
|
||||
void ParserClientImpl::onFileParsed(const FileInfo& fileInfo)
|
||||
{
|
||||
addFile(fileInfo.path, fileInfo.lastWriteTime.toString());
|
||||
const Id nodeId = addNodeHierarchy(NameHierarchy(fileInfo.path.str()), Node::NODE_FILE);
|
||||
addFile(nodeId, fileInfo.path, fileInfo.lastWriteTime.toString());
|
||||
}
|
||||
|
||||
void ParserClientImpl::onCommentParsed(const ParseLocation& location)
|
||||
{
|
||||
addFile(location.filePath);
|
||||
addNodeHierarchy(NameHierarchy(location.filePath.str()), Node::NODE_FILE);
|
||||
addCommentLocation(location);
|
||||
}
|
||||
|
||||
@@ -188,7 +190,7 @@ void ParserClientImpl::addAccess(Id nodeId, AccessKind access)
|
||||
}
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType)
|
||||
Id ParserClientImpl::addNodeHierarchy(NameHierarchy nameHierarchy, Node::NodeType nodeType)
|
||||
{
|
||||
if (nameHierarchy.size() == 0)
|
||||
{
|
||||
@@ -202,10 +204,9 @@ Id ParserClientImpl::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nam
|
||||
{
|
||||
currentNameHierarchy.push(nameHierarchy[i]);
|
||||
const bool currentIsLastElement = (i == nameHierarchy.size() - 1);
|
||||
Node::NodeType currentType = (currentIsLastElement ? nodeType : Node::NODE_UNDEFINED); // TODO: rename to unknown!
|
||||
DefinitionType currentDefinitionType = (currentIsLastElement ? definitionType : DEFINITION_NONE);
|
||||
const Node::NodeType currentType = (currentIsLastElement ? nodeType : Node::NODE_UNDEFINED); // TODO: rename to unknown!
|
||||
|
||||
Id nodeId = addSymbol(currentType, currentNameHierarchy, currentDefinitionType);
|
||||
Id nodeId = addNode(currentType, currentNameHierarchy);
|
||||
|
||||
// Todo: performance optimization: check if node exists. dont add edge if it existed before...
|
||||
if (parentNodeId != 0)
|
||||
@@ -218,34 +219,34 @@ Id ParserClientImpl::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nam
|
||||
return parentNodeId;
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addFile(const FilePath& filePath, const std::string& modificationTime)
|
||||
Id ParserClientImpl::addNode(Node::NodeType nodeType, NameHierarchy nameHierarchy)
|
||||
{
|
||||
if (!m_storage)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_storage->addFile(NameHierarchy::serialize(NameHierarchy(filePath.fileName())), filePath.str(), modificationTime);
|
||||
return m_storage->addNode(Node::typeToInt(nodeType), NameHierarchy::serialize(nameHierarchy));
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addFile(const FilePath& filePath)
|
||||
void ParserClientImpl::addFile(Id id, const FilePath& filePath, const std::string& modificationTime)
|
||||
{
|
||||
if (!m_storage)
|
||||
{
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
return m_storage->addFile("", filePath.str(), "");
|
||||
return m_storage->addFile(id, filePath.str(), modificationTime);
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addSymbol(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType)
|
||||
void ParserClientImpl::addSymbol(Id id, DefinitionType definitionType)
|
||||
{
|
||||
if (!m_storage)
|
||||
{
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
return m_storage->addSymbol(Node::typeToInt(nodeType), NameHierarchy::serialize(nameHierarchy), definitionTypeToInt(definitionType));
|
||||
return m_storage->addSymbol(id, definitionTypeToInt(definitionType));
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addEdge(int type, Id sourceId, Id targetId)
|
||||
@@ -292,7 +293,7 @@ void ParserClientImpl::addSourceLocation(Id elementId, const ParseLocation& loca
|
||||
}
|
||||
|
||||
Id sourceLocationId = m_storage->addSourceLocation(
|
||||
addFile(location.filePath),
|
||||
addNodeHierarchy(NameHierarchy(location.filePath.str()), Node::NODE_FILE),
|
||||
location.startLineNumber,
|
||||
location.startColumnNumber,
|
||||
location.endLineNumber,
|
||||
@@ -324,7 +325,7 @@ void ParserClientImpl::addCommentLocation(const ParseLocation& location)
|
||||
}
|
||||
|
||||
m_storage->addCommentLocation(
|
||||
addFile(location.filePath),
|
||||
addNodeHierarchy(NameHierarchy(location.filePath.str()), Node::NODE_FILE),
|
||||
location.startLineNumber,
|
||||
location.startColumnNumber,
|
||||
location.endLineNumber,
|
||||
|
||||
@@ -49,11 +49,11 @@ private:
|
||||
Node::NodeType symbolKindToNodeType(SymbolKind symbolType) const;
|
||||
Edge::EdgeType referenceKindToEdgeType(ReferenceKind referenceKind) const;
|
||||
void addAccess(Id nodeId, AccessKind access);
|
||||
Id addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType);
|
||||
Id addNodeHierarchy(NameHierarchy nameHierarchy, Node::NodeType nodeType = Node::NODE_UNDEFINED);
|
||||
|
||||
Id addFile(const FilePath& filePath, const std::string& modificationTime);
|
||||
Id addFile(const FilePath& filePath);
|
||||
Id addSymbol(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType);
|
||||
Id addNode(Node::NodeType nodeType, NameHierarchy nameHierarchy);
|
||||
void addFile(Id id, const FilePath& filePath, const std::string& modificationTime);
|
||||
void addSymbol(Id id, DefinitionType definitionType);
|
||||
Id addEdge(int type, Id sourceId, Id targetId);
|
||||
Id addLocalSymbol(const std::string& name);
|
||||
void addSourceLocation(Id elementId, const ParseLocation& location, int type);
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
SqliteStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
storage.addSymbol(0, "a", false);
|
||||
storage.addNode(0, "a");
|
||||
storage.commitTransaction();
|
||||
nodeCount = storage.getNodeCount();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
SqliteStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
int nodeId = storage.addSymbol(0, "a", false);
|
||||
int nodeId = storage.addNode(0, "a");
|
||||
storage.removeElement(nodeId);
|
||||
storage.commitTransaction();
|
||||
nodeCount = storage.getNodeCount();
|
||||
@@ -51,8 +51,8 @@ public:
|
||||
SqliteStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
int sourceNodeId = storage.addSymbol(0, "a", false);
|
||||
int targetNodeId = storage.addSymbol(0, "b", false);
|
||||
int sourceNodeId = storage.addNode(0, "a");
|
||||
int targetNodeId = storage.addNode(0, "b");
|
||||
storage.addEdge(0, sourceNodeId, targetNodeId);
|
||||
storage.commitTransaction();
|
||||
edgeCount = storage.getEdgeCount();
|
||||
@@ -70,8 +70,8 @@ public:
|
||||
SqliteStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
int sourceNodeId = storage.addSymbol(0, "a", false);
|
||||
int targetNodeId = storage.addSymbol(0, "b", false);
|
||||
int sourceNodeId = storage.addNode(0, "a");
|
||||
int targetNodeId = storage.addNode(0, "b");
|
||||
int edgeId = storage.addEdge(0, sourceNodeId, targetNodeId);
|
||||
storage.removeElement(edgeId);
|
||||
storage.commitTransaction();
|
||||
|
||||
@@ -21,12 +21,15 @@ public:
|
||||
{
|
||||
TestStorage storage;
|
||||
|
||||
std::string filePath = "path/to/test.h";
|
||||
|
||||
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
|
||||
Id id = intermetiateStorage->addFile(NameHierarchy::serialize(NameHierarchy("test.h")), "path/to/test.h", "someTime");
|
||||
Id id = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_FILE), NameHierarchy::serialize(NameHierarchy(filePath)));
|
||||
intermetiateStorage->addFile(id, filePath, "someTime");
|
||||
|
||||
storage.inject(intermetiateStorage.get());
|
||||
|
||||
TS_ASSERT_EQUALS(storage.getNameHierarchyForNodeWithId(id).getQualifiedNameWithSignature(), "test.h");
|
||||
TS_ASSERT_EQUALS(storage.getNameHierarchyForNodeWithId(id).getQualifiedName(), filePath);
|
||||
TS_ASSERT_EQUALS(storage.getNodeTypeForNodeWithId(id), Node::NODE_FILE);
|
||||
|
||||
}
|
||||
@@ -37,7 +40,7 @@ public:
|
||||
TestStorage storage;
|
||||
|
||||
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
|
||||
intermetiateStorage->addSymbol(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(a), true);
|
||||
intermetiateStorage->addNode(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(a));
|
||||
|
||||
storage.inject(intermetiateStorage.get());
|
||||
|
||||
@@ -56,8 +59,12 @@ public:
|
||||
TestStorage storage;
|
||||
|
||||
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
|
||||
Id aId = intermetiateStorage->addSymbol(Node::typeToInt(Node::NODE_STRUCT), NameHierarchy::serialize(a), true);
|
||||
Id bId = intermetiateStorage->addSymbol(Node::typeToInt(Node::NODE_FIELD), NameHierarchy::serialize(b), true);
|
||||
|
||||
Id aId = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_STRUCT), NameHierarchy::serialize(a));
|
||||
intermetiateStorage->addSymbol(aId, DEFINITION_EXPLICIT);
|
||||
|
||||
Id bId = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_FIELD), NameHierarchy::serialize(b));
|
||||
intermetiateStorage->addSymbol(bId, DEFINITION_EXPLICIT);
|
||||
intermetiateStorage->addEdge(Edge::typeToInt(Edge::EDGE_MEMBER), aId, bId);
|
||||
|
||||
storage.inject(intermetiateStorage.get());
|
||||
|
||||
Reference in New Issue
Block a user