data: Refactored ParserClient API to return and use Ids instead of NameHierarchies for faster indexing

* Pass NameHierarchy to record new symbol returning an Id
* Cache symbol Ids in Parser implementation
* Reuse symbol Ids as reference when recording related data
* Pass FilePath to record new file returning an Id
* Cache file Ids in CanonicalFilePathCache
* Store file Id in ParseLocation instead of FilePath

fortune cookie message = You know a silent way to impose your will.
This commit is contained in:
Eberhard Graether
2018-10-16 00:54:38 +02:00
parent aab29b241e
commit 4ae052cb9c
169 changed files with 43427 additions and 43502 deletions
-1
View File
@@ -202,7 +202,6 @@ add_files(
data/parser/ParseLocation.h
data/parser/Parser.cpp
data/parser/Parser.h
data/parser/ParserClient.cpp
data/parser/ParserClient.h
data/parser/ParserClientImpl.cpp
data/parser/ParserClientImpl.h
+1 -1
View File
@@ -65,7 +65,7 @@ std::shared_ptr<IntermediateStorage> Indexer<T>::index(std::shared_ptr<IndexerCo
doIndex(castCommand, parserClient, m_indexerStateInfo);
if (parserClient->hasFatalErrors())
if (storage->hasFatalErrors())
{
storage->setAllFilesIncomplete();
}
+6 -6
View File
@@ -1,7 +1,7 @@
#include "ParseLocation.h"
ParseLocation::ParseLocation()
: filePath(L"")
: fileId(0)
, startLineNumber(0)
, startColumnNumber(0)
, endLineNumber(0)
@@ -10,11 +10,11 @@ ParseLocation::ParseLocation()
}
ParseLocation::ParseLocation(
FilePath filePath,
Id fileId,
uint lineNumber,
uint columnNumber
)
: filePath(std::move(filePath.makeCanonical()))
: fileId(fileId)
, startLineNumber(lineNumber)
, startColumnNumber(columnNumber)
, endLineNumber(lineNumber)
@@ -23,11 +23,11 @@ ParseLocation::ParseLocation(
}
ParseLocation::ParseLocation(
FilePath filePath,
Id fileId,
uint startLineNumber, uint startColumnNumber,
uint endLineNumber, uint endColumnNumber
)
: filePath(std::move(filePath.makeCanonical()))
: fileId(fileId)
, startLineNumber(startLineNumber)
, startColumnNumber(startColumnNumber)
, endLineNumber(endLineNumber)
@@ -37,5 +37,5 @@ ParseLocation::ParseLocation(
bool ParseLocation::isValid() const
{
return !filePath.empty();
return fileId;
}
+12 -3
View File
@@ -6,23 +6,32 @@
#include "FilePath.h"
#include "types.h"
enum class ParseLocationType
{
TOKEN,
SCOPE,
SIGNATURE,
QUALIFIER,
LOCAL
};
struct ParseLocation
{
ParseLocation();
ParseLocation(
FilePath filePath,
Id fileId,
uint lineNumber,
uint columnNumber
);
ParseLocation(
FilePath filePath,
Id fileId,
uint startLineNumber, uint startColumnNumber,
uint endLineNumber, uint endColumnNumber
);
bool isValid() const;
FilePath filePath;
Id fileId;
uint startLineNumber;
uint startColumnNumber;
uint endLineNumber;
-119
View File
@@ -1,119 +0,0 @@
#include "ParserClient.h"
#include <sstream>
#include "ParseLocation.h"
std::wstring ParserClient::addAccessPrefix(const std::wstring& str, AccessKind access)
{
switch (access)
{
case ACCESS_PUBLIC:
return L"public " + str;
case ACCESS_PROTECTED:
return L"protected " + str;
case ACCESS_PRIVATE:
return L"private " + str;
case ACCESS_DEFAULT:
return L"default " + str;
default:
break;
}
return str;
}
std::wstring ParserClient::addStaticPrefix(const std::wstring& str, bool isStatic)
{
if (isStatic)
{
return L"static " + str;
}
return str;
}
std::wstring ParserClient::addConstPrefix(const std::wstring& str, bool isConst, bool atFront)
{
if (isConst)
{
return atFront ? L"const " + str : str + L" const";
}
return str;
}
std::wstring ParserClient::addLocationSuffix(const std::wstring& str, const ParseLocation& location)
{
std::wstringstream ss;
ss << str;
ss << L" <" << location.startLineNumber << L":" << location.startColumnNumber << L" ";
ss << location.endLineNumber << L":" << location.endColumnNumber << L">";
return ss.str();
}
std::wstring ParserClient::addLocationSuffix(
const std::wstring& str, const ParseLocation& location, const ParseLocation& scopeLocation
) {
if (!location.isValid())
{
return addLocationSuffix(str, scopeLocation);
}
else if (!scopeLocation.isValid())
{
return addLocationSuffix(str, location);
}
std::wstringstream ss;
ss << str;
ss << L" <" << scopeLocation.startLineNumber << L":" << scopeLocation.startColumnNumber;
ss << L" <" << location.startLineNumber << L":" << location.startColumnNumber << L" ";
ss << location.endLineNumber << L":" << location.endColumnNumber << L"> ";
ss << scopeLocation.endLineNumber << L":" << scopeLocation.endColumnNumber << L">";
return ss.str();
}
std::wstring ParserClient::addLocationSuffix(
const std::wstring& str, const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation
) {
if (!location.isValid())
{
return addLocationSuffix(str, scopeLocation, signatureLocation);
}
if (!scopeLocation.isValid())
{
return addLocationSuffix(str, location, signatureLocation);
}
if (!signatureLocation.isValid())
{
return addLocationSuffix(str, location, scopeLocation);
}
std::wstringstream ss;
ss << str;
ss << L" <" << scopeLocation.startLineNumber << L":" << scopeLocation.startColumnNumber;
ss << L" <" << signatureLocation.startLineNumber << L":" << signatureLocation.startColumnNumber << L" ";
ss << L" <" << location.startLineNumber << L":" << location.startColumnNumber << L" ";
ss << location.endLineNumber << L":" << location.endColumnNumber << L"> ";
ss << signatureLocation.endLineNumber << L":" << signatureLocation.endColumnNumber << L"> ";
ss << scopeLocation.endLineNumber << L":" << scopeLocation.endColumnNumber << L">";
return ss.str();
}
ParserClient::ParserClient()
: m_hasFatalErrors(false)
{
}
void ParserClient::recordError(
const ParseLocation& errorLocation, const std::wstring& message, bool fatal, bool indexed, const FilePath& translationUnit)
{
doRecordError(errorLocation, message, fatal, indexed, translationUnit);
if (fatal)
{
m_hasFatalErrors = true;
}
}
bool ParserClient::hasFatalErrors() const
{
return m_hasFatalErrors;
}
+12 -54
View File
@@ -2,78 +2,36 @@
#define PARSER_CLIENT_H
#include <string>
#include <vector>
#include "NameHierarchy.h"
#include "AccessKind.h"
#include "DefinitionKind.h"
#include "NameHierarchy.h"
#include "ParseLocation.h"
#include "ReferenceKind.h"
#include "SymbolKind.h"
#include "DefinitionKind.h"
#include "FileInfo.h"
#include "types.h"
struct ParseLocation;
class DataType;
class ParserClient
{
public:
static std::wstring addAccessPrefix(const std::wstring& str, AccessKind access);
static std::wstring addStaticPrefix(const std::wstring& str, bool isStatic);
static std::wstring addConstPrefix(const std::wstring& str, bool isConst, bool atFront);
static std::wstring addLocationSuffix(const std::wstring& str, const ParseLocation& location);
static std::wstring addLocationSuffix(
const std::wstring& str, const ParseLocation& location, const ParseLocation& scopeLocation);
static std::wstring addLocationSuffix(
const std::wstring& str,
const ParseLocation& location,
const ParseLocation& scopeLocation,
const ParseLocation& signatureLocation
);
ParserClient();
virtual ~ParserClient() = default;
virtual Id recordSymbol(
const NameHierarchy& symbolName, SymbolKind symbolKind,
AccessKind access, DefinitionKind definitionKind) = 0;
virtual Id recordFile(const FilePath& filePath, bool indexed) = 0;
virtual Id recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind) = 0;
virtual Id recordSymbol(const NameHierarchy& symbolName) = 0;
virtual void recordSymbolKind(Id symbolId, SymbolKind symbolKind) = 0;
virtual void recordAccessKind(Id symbolId, AccessKind accessKind) = 0;
virtual void recordDefinitionKind(Id symbolId, DefinitionKind definitionKind) = 0;
virtual Id recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind) = 0;
virtual Id recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind) = 0;
virtual void recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
virtual Id recordReference(ReferenceKind referenceKind, Id referencedSymbolId, Id contextSymbolId,
const ParseLocation& location) = 0;
virtual void recordQualifierLocation(
const NameHierarchy& qualifierName, const ParseLocation& location) = 0;
void recordError(
const ParseLocation& errorLocation, const std::wstring& message, bool fatal, bool indexed, const FilePath& translationUnit);
virtual void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) = 0;
virtual void recordFile(const FilePath& filePath, bool indexed) = 0;
virtual void recordLocation(Id elementId, const ParseLocation& location, ParseLocationType type) = 0;
virtual void recordComment(const ParseLocation& location) = 0;
bool hasFatalErrors() const;
protected:
virtual void doRecordError(
const ParseLocation& errorLocation, const std::wstring& message, bool fatal, bool indexed, const FilePath& translationUnit) = 0;
bool m_hasFatalErrors;
virtual void recordError(const FilePath& filePath, uint lineNumber, uint columnNumber, const std::wstring& message,
bool fatal, bool indexed, const FilePath& translationUnit) = 0;
};
#endif // PARSER_CLIENT_H
+59 -73
View File
@@ -3,76 +3,50 @@
#include "Edge.h"
#include "Node.h"
#include "ParseLocation.h"
#include "logging.h"
ParserClientImpl::ParserClientImpl(IntermediateStorage* const storage)
: m_storage(storage)
{
}
Id ParserClientImpl::recordSymbol(
const NameHierarchy& symbolName, SymbolKind symbolKind,
AccessKind access, DefinitionKind definitionKind
)
Id ParserClientImpl::recordFile(const FilePath& filePath, bool indexed)
{
Id fileId = addFileName(filePath);
m_storage->addFile(StorageFile(fileId, filePath.wstr(), indexed, true));
return fileId;
}
Id ParserClientImpl::recordSymbol(const NameHierarchy& symbolName)
{
return addNodeHierarchy(symbolName);
}
void ParserClientImpl::recordSymbolKind(Id symbolId, SymbolKind symbolKind)
{
m_storage->setNodeType(symbolId, NodeType::typeToInt(symbolKindToNodeType(symbolKind).getType()));
}
void ParserClientImpl::recordAccessKind(Id symbolId, AccessKind accessKind)
{
if (accessKind != ACCESS_NONE)
{
m_storage->addComponentAccess(StorageComponentAccess(symbolId, accessKindToInt(accessKind)));
}
}
void ParserClientImpl::recordDefinitionKind(Id symbolId, DefinitionKind definitionKind)
{
Id nodeId = addNodeHierarchy(symbolName, symbolKindToNodeType(symbolKind));
if (definitionKind != DEFINITION_NONE)
{
m_storage->addSymbol(StorageSymbol(nodeId, definitionKindToInt(definitionKind)));
m_storage->addSymbol(StorageSymbol(symbolId, definitionKindToInt(definitionKind)));
}
if (access != ACCESS_NONE)
{
m_storage->addComponentAccess(StorageComponentAccess(nodeId, accessKindToInt(access)));
}
return nodeId;
}
Id ParserClientImpl::recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind
)
Id ParserClientImpl::recordReference(ReferenceKind referenceKind, Id referencedSymbolId, Id contextSymbolId, const ParseLocation& location)
{
Id nodeId = recordSymbol(symbolName, symbolKind, access, definitionKind);
addSourceLocation(nodeId, location, LOCATION_TOKEN);
return nodeId;
}
Id ParserClientImpl::recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind
)
{
Id nodeId = recordSymbolWithLocation(symbolName, symbolKind, location, access, definitionKind);
addSourceLocation(nodeId, scopeLocation, LOCATION_SCOPE);
return nodeId;
}
Id ParserClientImpl::recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind)
{
Id nodeId = recordSymbolWithLocationAndScope(symbolName, symbolKind, location, scopeLocation, access, definitionKind);
addSourceLocation(nodeId, signatureLocation, LOCATION_SIGNATURE);
return nodeId;
}
void ParserClientImpl::recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
const ParseLocation& location)
{
Id contextNodeId = addNodeHierarchy(contextName);
Id referencedNodeId = addNodeHierarchy(referencedName);
Id edgeId = addEdge(referenceKindToEdgeType(referenceKind), contextNodeId, referencedNodeId);
Id edgeId = addEdge(referenceKindToEdgeType(referenceKind), contextSymbolId, referencedSymbolId);
addSourceLocation(edgeId, location, LOCATION_TOKEN);
}
void ParserClientImpl::recordQualifierLocation(const NameHierarchy& qualifierName, const ParseLocation& location)
{
Id nodeId = addNodeHierarchy(qualifierName, NodeType::NODE_SYMBOL);
addSourceLocation(nodeId, location, LOCATION_QUALIFIER);
return edgeId;
}
void ParserClientImpl::recordLocalSymbol(const std::wstring& name, const ParseLocation& location)
@@ -81,10 +55,9 @@ void ParserClientImpl::recordLocalSymbol(const std::wstring& name, const ParseLo
addSourceLocation(localSymbolId, location, LOCATION_LOCAL_SYMBOL);
}
void ParserClientImpl::recordFile(const FilePath& filePath, bool indexed)
void ParserClientImpl::recordLocation(Id elementId, const ParseLocation& location, ParseLocationType type)
{
const Id fileId = addFileName(filePath);
m_storage->addFile(StorageFile(fileId, filePath.wstr(), indexed, true));
addSourceLocation(elementId, location, parseLocationTypeToLocationType(type));
}
void ParserClientImpl::recordComment(const ParseLocation& location)
@@ -95,7 +68,7 @@ void ParserClientImpl::recordComment(const ParseLocation& location)
}
m_storage->addSourceLocation(StorageSourceLocationData(
addFileName(location.filePath),
location.fileId,
location.startLineNumber,
location.startColumnNumber,
location.endLineNumber,
@@ -104,16 +77,17 @@ void ParserClientImpl::recordComment(const ParseLocation& location)
));
}
void ParserClientImpl::doRecordError(
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed, const FilePath& translationUnit)
void ParserClientImpl::recordError(
const FilePath& filePath, uint lineNumber, uint columnNumber, const std::wstring& message, bool fatal, bool indexed,
const FilePath& translationUnit)
{
if (location.isValid())
if (!filePath.empty())
{
m_storage->addError(StorageErrorData(
message,
location.filePath.wstr(),
location.startLineNumber,
location.startColumnNumber,
filePath.wstr(),
lineNumber,
columnNumber,
translationUnit.wstr(),
fatal,
indexed
@@ -205,6 +179,24 @@ Edge::EdgeType ParserClientImpl::referenceKindToEdgeType(ReferenceKind reference
return Edge::EDGE_UNDEFINED;
}
LocationType ParserClientImpl::parseLocationTypeToLocationType(ParseLocationType type) const
{
switch (type)
{
case ParseLocationType::TOKEN:
return LOCATION_TOKEN;
case ParseLocationType::SCOPE:
return LOCATION_SCOPE;
case ParseLocationType::SIGNATURE:
return LOCATION_SIGNATURE;
case ParseLocationType::QUALIFIER:
return LOCATION_QUALIFIER;
case ParseLocationType::LOCAL:
return LOCATION_LOCAL_SYMBOL;
}
return LOCATION_TOKEN;
}
Id ParserClientImpl::addNodeHierarchy(const NameHierarchy& nameHierarchy, NodeType nodeType)
{
Id childNodeId = 0;
@@ -267,14 +259,8 @@ void ParserClientImpl::addSourceLocation(Id elementId, const ParseLocation& loca
return;
}
if (location.filePath.empty())
{
LOG_ERROR("no filename set!");
return;
}
Id sourceLocationId = m_storage->addSourceLocation(StorageSourceLocationData(
addFileName(location.filePath),
location.fileId,
location.startLineNumber,
location.startColumnNumber,
location.endLineNumber,
+11 -29
View File
@@ -15,42 +15,26 @@ class ParserClientImpl
public:
ParserClientImpl(IntermediateStorage* const storage);
Id recordSymbol(
const NameHierarchy& symbolName, SymbolKind symbolKind,
AccessKind access, DefinitionKind definitionKind) override;
Id recordFile(const FilePath& filePath, bool indexed) override;
Id recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind) override;
Id recordSymbol(const NameHierarchy& symbolName) override;
void recordSymbolKind(Id symbolId, SymbolKind symbolKind) override;
void recordAccessKind(Id symbolId, AccessKind accessKind) override;
void recordDefinitionKind(Id symbolId, DefinitionKind definitionKind) override;
Id recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind) override;
Id recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind) override;
void recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
const ParseLocation& location) override;
void recordQualifierLocation(
const NameHierarchy& qualifierName, const ParseLocation& location) override;
Id recordReference(ReferenceKind referenceKind, Id referencedSymbolId, Id contextSymbolId, const ParseLocation& location) override;
void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) override;
void recordFile(const FilePath& filePath, bool indexed) override;
void recordLocation(Id elementId, const ParseLocation& location, ParseLocationType type) override;
void recordComment(const ParseLocation& location) override;
private:
void doRecordError(
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed, const FilePath& sourceFilePath) override;
void recordError(const FilePath& filePath, uint lineNumber, uint columnNumber, const std::wstring& message, bool fatal, bool indexed, const FilePath& translationUnit) override;
private:
NodeType symbolKindToNodeType(SymbolKind symbolType) const;
Edge::EdgeType referenceKindToEdgeType(ReferenceKind referenceKind) const;
LocationType parseLocationTypeToLocationType(ParseLocationType type) const;
void addAccess(Id nodeId, AccessKind access);
Id addNodeHierarchy(const NameHierarchy& nameHierarchy, NodeType nodeType = NodeType::NODE_SYMBOL);
@@ -58,8 +42,6 @@ private:
Id addEdge(int type, Id sourceId, Id targetId);
void addSourceLocation(Id elementId, const ParseLocation& location, LocationType type);
void addError(const std::wstring& message, bool fatal, bool indexed,
const ParseLocation& location, const FilePath& sourceFilePath);
IntermediateStorage* const m_storage;
std::map<std::wstring, Id> m_fileIdMap;
@@ -10,6 +10,7 @@ IntermediateStorage::IntermediateStorage()
void IntermediateStorage::clear()
{
m_nodesIndex.clear();
m_nodeIdIndex.clear();
m_nodes.clear();
m_filesIndex.clear();
@@ -75,6 +76,19 @@ size_t IntermediateStorage::getSourceLocationCount() const
return m_sourceLocations.size();
}
bool IntermediateStorage::hasFatalErrors() const
{
for (const StorageErrorData& error : m_errors)
{
if (error.fatal)
{
return true;
}
}
return false;
}
void IntermediateStorage::setAllFilesIncomplete()
{
for (StorageFile& file : m_files)
@@ -116,6 +130,7 @@ std::pair<Id, bool> IntermediateStorage::addNode(const StorageNodeData& nodeData
Id nodeId = m_nextId++;
m_nodes.emplace_back(nodeId, nodeData);
m_nodesIndex.emplace(nodeData, m_nodes.size() - 1);
m_nodeIdIndex.emplace(nodeId, m_nodes.size() - 1);
return std::make_pair(nodeId, true);
}
@@ -130,6 +145,15 @@ std::vector<Id> IntermediateStorage::addNodes(const std::vector<StorageNode>& no
return nodeIds;
}
void IntermediateStorage::setNodeType(Id nodeId, int nodeType)
{
auto it = m_nodeIdIndex.find(nodeId);
if (it != m_nodeIdIndex.end() && m_nodes[it->second].type < nodeType)
{
m_nodes[it->second].type = nodeType;
}
}
void IntermediateStorage::addSymbol(const StorageSymbol& symbol)
{
m_symbols.push_back(symbol);
@@ -316,9 +340,11 @@ void IntermediateStorage::setStorageNodes(std::vector<StorageNode> storageNodes)
m_nodes = std::move(storageNodes);
m_nodesIndex.clear();
m_nodeIdIndex.clear();
for (size_t i = 0; i < m_nodes.size(); i++)
{
m_nodesIndex.emplace(m_nodes[i], i);
m_nodeIdIndex.emplace(m_nodes[i].id, i);
}
}
@@ -18,11 +18,13 @@ public:
size_t getByteSize(size_t stringSize) const;
size_t getSourceLocationCount() const;
bool hasFatalErrors() const;
void setAllFilesIncomplete();
void setFilesWithErrorsIncomplete();
std::pair<Id, bool> addNode(const StorageNodeData& nodeData) override;
std::vector<Id> addNodes(const std::vector<StorageNode>& nodes) override;
void setNodeType(Id nodeId, int nodeType);
void addSymbol(const StorageSymbol& symbol) override;
void addSymbols(const std::vector<StorageSymbol>& symbols) override;
void addFile(const StorageFile& file) override;
@@ -65,6 +67,7 @@ private:
std::wstring serialize(const StorageErrorData& errorData) const;
std::map<StorageNodeData, size_t> m_nodesIndex;
std::map<Id, size_t> m_nodeIdIndex;
std::vector<StorageNode> m_nodes;
std::map<StorageFile, size_t> m_filesIndex; // this is used to prevent duplicates (unique)
@@ -26,7 +26,6 @@ class TextAccess;
class Version;
class SourceLocationCollection;
class SourceLocationFile;
struct ParseLocation;
class SqliteIndexStorage
: public SqliteStorage
@@ -62,7 +62,63 @@ FilePath CanonicalFilePathCache::getCanonicalFilePath(const std::wstring& path)
return canonicalPath;
}
bool CanonicalFilePathCache::isProjectFile(const clang::FileID fileId, const clang::SourceManager& sourceManager)
FilePath CanonicalFilePathCache::getCanonicalFilePath(const Id symbolId)
{
auto it = m_symbolIdFileIdMap.find(symbolId);
if (it != m_symbolIdFileIdMap.end())
{
auto it2 = m_fileIdMap.find(it->second);
if (it2 != m_fileIdMap.end())
{
return it2->second;
}
}
return FilePath();
}
void CanonicalFilePathCache::addFileSymbolId(const clang::FileID& fileId, const FilePath& path, Id symbolId)
{
m_fileIdSymbolIdMap.emplace(fileId, symbolId);
m_symbolIdFileIdMap.emplace(symbolId, fileId);
m_fileStringSymbolIdMap.emplace(utility::toLowerCase(path.wstr()), symbolId);
}
Id CanonicalFilePathCache::getFileSymbolId(const clang::FileID& fileId)
{
if (!fileId.isValid())
{
return 0;
}
auto it = m_fileIdSymbolIdMap.find(fileId);
if (it != m_fileIdSymbolIdMap.end())
{
return it->second;
}
return 0;
}
Id CanonicalFilePathCache::getFileSymbolId(const clang::FileEntry* entry)
{
return getFileSymbolId(utility::getFileNameOfFileEntry(entry));
}
Id CanonicalFilePathCache::getFileSymbolId(const std::wstring& path)
{
std::wstring canonicalPath = utility::toLowerCase(getCanonicalFilePath(path).wstr());
auto it = m_fileStringSymbolIdMap.find(canonicalPath);
if (it != m_fileStringSymbolIdMap.end())
{
return it->second;
}
return 0;
}
bool CanonicalFilePathCache::isProjectFile(const clang::FileID& fileId, const clang::SourceManager& sourceManager)
{
if (!fileId.isValid())
{
@@ -1,6 +1,7 @@
#ifndef CANONICAL_FILE_PATH_CACHE_H
#define CANONICAL_FILE_PATH_CACHE_H
#include <map>
#include <string>
#include <unordered_map>
@@ -8,6 +9,7 @@
#include "FilePath.h"
#include "FileRegister.h"
#include "types.h"
class CanonicalFilePathCache
{
@@ -19,24 +21,26 @@ public:
FilePath getCanonicalFilePath(const clang::FileID& fileId, const clang::SourceManager& sourceManager);
FilePath getCanonicalFilePath(const clang::FileEntry* entry);
FilePath getCanonicalFilePath(const std::wstring& path);
FilePath getCanonicalFilePath(const Id symbolId);
bool isProjectFile(const clang::FileID fileId, const clang::SourceManager& sourceManager);
void addFileSymbolId(const clang::FileID& fileId, const FilePath& path, Id symbolId);
Id getFileSymbolId(const clang::FileID& fileId);
Id getFileSymbolId(const clang::FileEntry* entry);
Id getFileSymbolId(const std::wstring& path);
bool isProjectFile(const clang::FileID& fileId, const clang::SourceManager& sourceManager);
private:
struct FileIdHash
{
size_t operator()(clang::FileID fileID) const
{
return fileID.getHashValue();
}
};
std::shared_ptr<FileRegister> m_fileRegister;
std::unordered_map<clang::FileID, FilePath, FileIdHash> m_fileIdMap;
std::map<clang::FileID, FilePath> m_fileIdMap;
std::unordered_map<std::wstring, FilePath> m_fileStringMap;
std::unordered_map<clang::FileID, bool, FileIdHash> m_isProjectFileMap;
std::map<clang::FileID, Id> m_fileIdSymbolIdMap;
std::map<Id, clang::FileID> m_symbolIdFileIdMap;
std::unordered_map<std::wstring, Id> m_fileStringSymbolIdMap;
std::map<clang::FileID, bool> m_isProjectFileMap;
};
#endif // CANONICAL_FILE_PATH_CACHE_H
@@ -23,15 +23,15 @@ bool CommentHandler::HandleComment(clang::Preprocessor& preprocessor, clang::Sou
const clang::SourceManager& sourceManager = preprocessor.getSourceManager();
const clang::FileID fileId = sourceManager.getFileID(sourceRange.getBegin());
FilePath filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileId, sourceManager);
Id fileSymbolId = m_canonicalFilePathCache->getFileSymbolId(fileId);
if (m_canonicalFilePathCache->isProjectFile(fileId, sourceManager))
if (fileSymbolId && m_canonicalFilePathCache->isProjectFile(fileId, sourceManager))
{
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(sourceRange.getBegin(), false);
const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
m_client->recordComment(ParseLocation(
std::move(filePath),
fileSymbolId,
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
+1 -37
View File
@@ -31,32 +31,6 @@ CxxAstVisitor::CxxAstVisitor(
, m_implicitCodeComponent(this)
, m_indexerComponent(this, astContext, client)
, m_braceRecorderComponent(this, astContext, client)
, m_declNameCache([&](const clang::NamedDecl* decl) -> NameHierarchy
{
if (decl)
{
std::shared_ptr<CxxDeclName> declName = CxxDeclNameResolver(m_canonicalFilePathCache.get()).getName(decl);
if (declName)
{
return declName->toNameHierarchy();
}
}
return NameHierarchy(L"global", NAME_DELIMITER_UNKNOWN);
}
)
, m_typeNameCache([&](const clang::Type* type) -> NameHierarchy
{
if (type)
{
std::shared_ptr<CxxTypeName> typeName = CxxTypeNameResolver(m_canonicalFilePathCache.get()).getName(type);
if (typeName)
{
return typeName->toNameHierarchy();
}
}
return NameHierarchy(L"global", NAME_DELIMITER_UNKNOWN);
}
)
{
}
@@ -84,17 +58,7 @@ CxxAstVisitorComponentIndexer* CxxAstVisitor::getComponent()
return &m_indexerComponent;
}
DeclNameCache* CxxAstVisitor::getDeclNameCache()
{
return &m_declNameCache;
}
TypeNameCache* CxxAstVisitor::getTypeNameCache()
{
return &m_typeNameCache;
}
CanonicalFilePathCache* CxxAstVisitor::getCanonicalFilePathCache()
CanonicalFilePathCache* CxxAstVisitor::getCanonicalFilePathCache() const
{
return m_canonicalFilePathCache.get();
}
+2 -7
View File
@@ -47,9 +47,7 @@ public:
template <typename T>
T* getComponent();
DeclNameCache* getDeclNameCache();
TypeNameCache* getTypeNameCache();
CanonicalFilePathCache* getCanonicalFilePathCache();
CanonicalFilePathCache* getCanonicalFilePathCache() const;
// Indexing entry point
void indexDecl(clang::Decl *d);
@@ -153,7 +151,7 @@ public:
bool isLocatedInProjectFile(clang::SourceLocation loc) const;
private:
protected:
typedef clang::RecursiveASTVisitor<CxxAstVisitor> Base;
clang::ASTContext* m_astContext;
@@ -168,9 +166,6 @@ private:
CxxAstVisitorComponentImplicitCode m_implicitCodeComponent;
CxxAstVisitorComponentIndexer m_indexerComponent;
CxxAstVisitorComponentBraceRecorder m_braceRecorderComponent;
DeclNameCache m_declNameCache;
TypeNameCache m_typeNameCache;
};
template <>
@@ -2,6 +2,7 @@
#include <clang/Lex/Preprocessor.h>
#include "CanonicalFilePathCache.h"
#include "CxxAstVisitor.h"
#include "CxxAstVisitorComponentContext.h"
#include "utilityClang.h"
@@ -26,7 +27,11 @@ void CxxAstVisitorComponentBraceRecorder::visitTagDecl(clang::TagDecl* d)
clang::dyn_cast<clang::CXXRecordDecl>(d)->getTemplateSpecializationKind() != clang::TSK_ImplicitInstantiation
))
{
recordBraces(getParseLocation(d->getBraceRange().getBegin()), getParseLocation(d->getBraceRange().getEnd()));
recordBraces(
getFilePath(d->getBraceRange().getBegin()),
getParseLocation(d->getBraceRange().getBegin()),
getParseLocation(d->getBraceRange().getEnd())
);
}
}
}
@@ -36,6 +41,7 @@ void CxxAstVisitorComponentBraceRecorder::visitNamespaceDecl(clang::NamespaceDec
if (getAstVisitor()->shouldVisitDecl(d))
{
recordBraces(
getFilePath(d->getLocStart()),
getParseLocation(getFirstLBraceLocation(d->getLocStart())),
getParseLocation(getLastRBraceLocation(d->getLocStart(), d->getLocEnd()))
);
@@ -46,10 +52,15 @@ void CxxAstVisitorComponentBraceRecorder::visitCompoundStmt(clang::CompoundStmt*
{
if (getAstVisitor()->shouldVisitStmt(s))
{
const clang::NamedDecl* contextDecl = getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl();
const clang::NamedDecl* contextDecl =
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl();
if (!contextDecl || !utility::isImplicit(contextDecl))
{
recordBraces(getParseLocation(s->getLBracLoc()), getParseLocation(s->getRBracLoc()));
recordBraces(
getFilePath(s->getLBracLoc()),
getParseLocation(s->getLBracLoc()),
getParseLocation(s->getRBracLoc())
);
}
}
}
@@ -60,10 +71,14 @@ void CxxAstVisitorComponentBraceRecorder::visitInitListExpr(clang::InitListExpr*
{
if (s->isSyntacticForm())
{
const clang::NamedDecl* contextDecl = getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl();
const clang::NamedDecl* contextDecl =
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl();
if (!contextDecl || !utility::isImplicit(contextDecl))
{
recordBraces(getParseLocation(s->getLBraceLoc()), getParseLocation(s->getRBraceLoc()));
recordBraces(
getFilePath(s->getLBraceLoc()),
getParseLocation(s->getLBraceLoc()),
getParseLocation(s->getRBraceLoc()));
}
}
}
@@ -75,10 +90,12 @@ void CxxAstVisitorComponentBraceRecorder::visitMSAsmStmt(clang::MSAsmStmt* s)
{
if (s->hasBraces())
{
const clang::NamedDecl* contextDecl = getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl();
const clang::NamedDecl* contextDecl =
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl();
if (!contextDecl || !utility::isImplicit(contextDecl))
{
recordBraces(
getFilePath(s->getLBraceLoc()),
getParseLocation(s->getLBraceLoc()),
getParseLocation(getLastRBraceLocation(s->getLocStart(), s->getLocEnd()))
);
@@ -92,18 +109,25 @@ ParseLocation CxxAstVisitorComponentBraceRecorder::getParseLocation(const clang:
return getAstVisitor()->getParseLocation(loc);
}
void CxxAstVisitorComponentBraceRecorder::recordBraces(const ParseLocation& lbraceLoc, const ParseLocation& rbraceLoc)
FilePath CxxAstVisitorComponentBraceRecorder::getFilePath(const clang::SourceLocation& loc)
{
std::wstring name =
lbraceLoc.filePath.fileName() + L"<" +
std::to_wstring(lbraceLoc.startLineNumber) + L":" +
std::to_wstring(lbraceLoc.startColumnNumber) + L">";
const clang::SourceManager& sm = m_astContext->getSourceManager();
return getAstVisitor()->getCanonicalFilePathCache()->getCanonicalFilePath(sm.getFileID(loc), sm);
}
void CxxAstVisitorComponentBraceRecorder::recordBraces(
const FilePath& filePath, const ParseLocation& lbraceLoc, const ParseLocation& rbraceLoc)
{
if (lbraceLoc.startColumnNumber != rbraceLoc.startColumnNumber ||
lbraceLoc.endColumnNumber != rbraceLoc.endColumnNumber ||
lbraceLoc.startLineNumber != rbraceLoc.startLineNumber ||
lbraceLoc.endLineNumber != rbraceLoc.endLineNumber)
{
std::wstring name =
filePath.fileName() + L"<" +
std::to_wstring(lbraceLoc.startLineNumber) + L":" +
std::to_wstring(lbraceLoc.startColumnNumber) + L">";
if (lbraceLoc.startColumnNumber == lbraceLoc.endColumnNumber &&
lbraceLoc.startLineNumber == lbraceLoc.endLineNumber)
{
@@ -117,7 +141,8 @@ void CxxAstVisitorComponentBraceRecorder::recordBraces(const ParseLocation& lbra
}
}
clang::SourceLocation CxxAstVisitorComponentBraceRecorder::getFirstLBraceLocation(clang::SourceLocation searchStartLoc) const
clang::SourceLocation CxxAstVisitorComponentBraceRecorder::getFirstLBraceLocation(
clang::SourceLocation searchStartLoc) const
{
const clang::SourceManager& sm = m_astContext->getSourceManager();
const clang::LangOptions& opts = m_astContext->getLangOpts();
@@ -152,7 +177,8 @@ clang::SourceLocation CxxAstVisitorComponentBraceRecorder::getFirstLBraceLocatio
return clang::SourceLocation();
}
clang::SourceLocation CxxAstVisitorComponentBraceRecorder::getLastRBraceLocation(clang::SourceLocation searchStartLoc, clang::SourceLocation searchEndLoc) const
clang::SourceLocation CxxAstVisitorComponentBraceRecorder::getLastRBraceLocation(
const clang::SourceLocation& searchStartLoc, clang::SourceLocation searchEndLoc) const
{
const clang::SourceManager& sm = m_astContext->getSourceManager();
const clang::LangOptions& opts = m_astContext->getLangOpts();
@@ -11,7 +11,8 @@ class CxxAstVisitorComponentBraceRecorder
: public CxxAstVisitorComponent
{
public:
CxxAstVisitorComponentBraceRecorder(CxxAstVisitor* astVisitor, clang::ASTContext* astContext, std::shared_ptr<ParserClient> client);
CxxAstVisitorComponentBraceRecorder(
CxxAstVisitor* astVisitor, clang::ASTContext* astContext, std::shared_ptr<ParserClient> client);
void visitTagDecl(clang::TagDecl* d);
void visitNamespaceDecl(clang::NamespaceDecl* d);
@@ -21,9 +22,12 @@ public:
private:
ParseLocation getParseLocation(const clang::SourceLocation& loc) const;
void recordBraces(const ParseLocation& lbraceLoc, const ParseLocation& rbraceLoc);
FilePath getFilePath(const clang::SourceLocation& loc);
void recordBraces(const FilePath& filePath, const ParseLocation& lbraceLoc, const ParseLocation& rbraceLoc);
clang::SourceLocation getFirstLBraceLocation(clang::SourceLocation searchStartLoc) const;
clang::SourceLocation getLastRBraceLocation(clang::SourceLocation searchStartLoc, clang::SourceLocation searchEndLoc) const;
clang::SourceLocation getLastRBraceLocation(
const clang::SourceLocation& searchStartLoc, clang::SourceLocation searchEndLoc) const;
clang::ASTContext* m_astContext;
std::shared_ptr<ParserClient> m_client;
@@ -23,7 +23,7 @@ const clang::NamedDecl* CxxAstVisitorComponentContext::getTopmostContextDecl() c
return nullptr;
}
NameHierarchy CxxAstVisitorComponentContext::getContextName(const size_t skip)
const CxxContext* CxxAstVisitorComponentContext::getContext(const size_t skip)
{
size_t skipped = 0;
@@ -33,7 +33,7 @@ NameHierarchy CxxAstVisitorComponentContext::getContextName(const size_t skip)
{
if (skipped >= skip)
{
return (*it)->getName();
return it->get();
}
else
{
@@ -41,19 +41,7 @@ NameHierarchy CxxAstVisitorComponentContext::getContextName(const size_t skip)
}
}
}
return getAstVisitor()->getDeclNameCache()->getValue(nullptr);
}
NameHierarchy CxxAstVisitorComponentContext::getContextName(const NameHierarchy& fallback)
{
for (auto it = m_contextStack.rbegin(); it != m_contextStack.rend(); it++)
{
if (*it)
{
return (*it)->getName();
}
}
return fallback;
return nullptr;
}
void CxxAstVisitorComponentContext::beginTraverseDecl(clang::Decl* d)
@@ -69,7 +57,7 @@ void CxxAstVisitorComponentContext::beginTraverseDecl(clang::Decl* d)
!clang::isa<clang::NamespaceDecl>(d) // no namespace
){
clang::NamedDecl* nd = clang::dyn_cast<clang::NamedDecl>(d);
context = std::make_shared<CxxContextDecl>(nd, getAstVisitor()->getDeclNameCache());
context = std::make_shared<CxxContextDecl>(nd);
}
m_contextStack.push_back(context);
@@ -86,7 +74,7 @@ void CxxAstVisitorComponentContext::beginTraverseTypeLoc(const clang::TypeLoc& t
if (!getAstVisitor()->checkIgnoresTypeLoc(tl))
{
context = std::make_shared<CxxContextType>(tl.getTypePtr(), getAstVisitor()->getTypeNameCache());
context = std::make_shared<CxxContextType>(tl.getTypePtr());
}
m_contextStack.push_back(context);
@@ -99,7 +87,7 @@ void CxxAstVisitorComponentContext::endTraverseTypeLoc(const clang::TypeLoc& tl)
void CxxAstVisitorComponentContext::beginTraverseLambdaExpr(clang::LambdaExpr* s)
{
m_contextStack.push_back(std::make_shared<CxxContextDecl>(s->getCallOperator(), getAstVisitor()->getDeclNameCache()));
m_contextStack.push_back(std::make_shared<CxxContextDecl>(s->getCallOperator()));
}
void CxxAstVisitorComponentContext::endTraverseLambdaExpr(clang::LambdaExpr* s)
@@ -109,7 +97,7 @@ void CxxAstVisitorComponentContext::endTraverseLambdaExpr(clang::LambdaExpr* s)
void CxxAstVisitorComponentContext::beginTraverseFunctionDecl(clang::FunctionDecl* d)
{
m_templateArgumentContext.push_back(std::make_shared<CxxContextDecl>(d, getAstVisitor()->getDeclNameCache()));
m_templateArgumentContext.push_back(std::make_shared<CxxContextDecl>(d));
}
void CxxAstVisitorComponentContext::endTraverseFunctionDecl(clang::FunctionDecl* d)
@@ -119,7 +107,7 @@ void CxxAstVisitorComponentContext::endTraverseFunctionDecl(clang::FunctionDecl*
void CxxAstVisitorComponentContext::beginTraverseClassTemplateSpecializationDecl(clang::ClassTemplateSpecializationDecl *d)
{
m_templateArgumentContext.push_back(std::make_shared<CxxContextDecl>(d, getAstVisitor()->getDeclNameCache()));
m_templateArgumentContext.push_back(std::make_shared<CxxContextDecl>(d));
}
void CxxAstVisitorComponentContext::endTraverseClassTemplateSpecializationDecl(clang::ClassTemplateSpecializationDecl *d)
@@ -129,7 +117,7 @@ void CxxAstVisitorComponentContext::endTraverseClassTemplateSpecializationDecl(c
void CxxAstVisitorComponentContext::beginTraverseClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl* d)
{
m_templateArgumentContext.push_back(std::make_shared<CxxContextDecl>(d, getAstVisitor()->getDeclNameCache()));
m_templateArgumentContext.push_back(std::make_shared<CxxContextDecl>(d));
}
void CxxAstVisitorComponentContext::endTraverseClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl* d)
@@ -139,7 +127,7 @@ void CxxAstVisitorComponentContext::endTraverseClassTemplatePartialSpecializatio
void CxxAstVisitorComponentContext::beginTraverseDeclRefExpr(clang::DeclRefExpr* s)
{
m_templateArgumentContext.push_back(std::make_shared<CxxContextDecl>(s->getDecl(), getAstVisitor()->getDeclNameCache()));
m_templateArgumentContext.push_back(std::make_shared<CxxContextDecl>(s->getDecl()));
}
void CxxAstVisitorComponentContext::endTraverseDeclRefExpr(clang::DeclRefExpr* s)
@@ -149,7 +137,7 @@ void CxxAstVisitorComponentContext::endTraverseDeclRefExpr(clang::DeclRefExpr* s
void CxxAstVisitorComponentContext::beginTraverseTemplateSpecializationTypeLoc(const clang::TemplateSpecializationTypeLoc& loc)
{
m_templateArgumentContext.push_back(std::make_shared<CxxContextType>(loc.getTypePtr(), getAstVisitor()->getTypeNameCache()));
m_templateArgumentContext.push_back(std::make_shared<CxxContextType>(loc.getTypePtr()));
}
void CxxAstVisitorComponentContext::endTraverseTemplateSpecializationTypeLoc(const clang::TemplateSpecializationTypeLoc& loc)
@@ -14,8 +14,7 @@ public:
CxxAstVisitorComponentContext(CxxAstVisitor* astVisitor);
const clang::NamedDecl* getTopmostContextDecl() const;
NameHierarchy getContextName(const size_t skip = 0);
NameHierarchy getContextName(const NameHierarchy& fallback);
const CxxContext* getContext(const size_t skip = 0);
void beginTraverseDecl(clang::Decl* d);
void endTraverseDecl(clang::Decl* d);
@@ -10,6 +10,8 @@
#include "CxxAstVisitorComponentContext.h"
#include "CxxAstVisitorComponentDeclRefKind.h"
#include "CxxAstVisitorComponentTypeRefKind.h"
#include "CxxDeclNameResolver.h"
#include "CxxTypeNameResolver.h"
#include "utilityClang.h"
#include "ParserClient.h"
@@ -35,35 +37,18 @@ void CxxAstVisitorComponentIndexer::beginTraverseNestedNameSpecifierLoc(const cl
break;
case clang::NestedNameSpecifier::Namespace:
{
const NameHierarchy symbolName = getAstVisitor()->getDeclNameCache()->getValue(loc.getNestedNameSpecifier()->getAsNamespace());
m_client->recordSymbol(
symbolName,
SYMBOL_NAMESPACE,
ACCESS_NONE,
DEFINITION_NONE
);
m_client->recordQualifierLocation(
symbolName,
getParseLocation(loc.getLocalBeginLoc())
);
Id symbolId = getOrCreateSymbolId(loc.getNestedNameSpecifier()->getAsNamespace());
m_client->recordSymbolKind(symbolId, SYMBOL_NAMESPACE);
m_client->recordLocation(symbolId, getParseLocation(loc.getLocalBeginLoc()), ParseLocationType::QUALIFIER);
}
break;
case clang::NestedNameSpecifier::NamespaceAlias:
{
m_client->recordSymbol(
getAstVisitor()->getDeclNameCache()->getValue(loc.getNestedNameSpecifier()->getAsNamespaceAlias()),
SYMBOL_NAMESPACE,
ACCESS_NONE,
DEFINITION_NONE
);
Id symbolId = getOrCreateSymbolId(loc.getNestedNameSpecifier()->getAsNamespaceAlias());
m_client->recordSymbolKind(symbolId, SYMBOL_NAMESPACE);
m_client->recordSymbol(
getAstVisitor()->getDeclNameCache()->getValue(loc.getNestedNameSpecifier()->getAsNamespaceAlias()->getAliasedNamespace()),
SYMBOL_NAMESPACE,
ACCESS_NONE,
DEFINITION_NONE
);
symbolId = getOrCreateSymbolId(loc.getNestedNameSpecifier()->getAsNamespaceAlias()->getAliasedNamespace());
m_client->recordSymbolKind(symbolId, SYMBOL_NAMESPACE);
}
break;
case clang::NestedNameSpecifier::Global:
@@ -89,26 +74,15 @@ void CxxAstVisitorComponentIndexer::beginTraverseNestedNameSpecifierLoc(const cl
if (symbolKind != SYMBOL_KIND_MAX)
{
const NameHierarchy symbolName = getAstVisitor()->getDeclNameCache()->getValue(recordDecl);
m_client->recordSymbol(
symbolName,
symbolKind,
ACCESS_NONE,
DEFINITION_NONE
);
m_client->recordQualifierLocation(
symbolName,
getParseLocation(loc.getLocalBeginLoc())
);
Id symbolId = getOrCreateSymbolId(recordDecl);
m_client->recordSymbolKind(symbolId, symbolKind);
m_client->recordLocation(symbolId, getParseLocation(loc.getLocalBeginLoc()), ParseLocationType::QUALIFIER);
}
}
else if (const clang::Type* type = loc.getNestedNameSpecifier()->getAsType())
{
m_client->recordQualifierLocation(
getAstVisitor()->getTypeNameCache()->getValue(type),
getParseLocation(loc.getLocalBeginLoc())
);
Id symbolId = getOrCreateSymbolId(type);
m_client->recordLocation(symbolId, getParseLocation(loc.getLocalBeginLoc()), ParseLocationType::QUALIFIER);
}
}
}
@@ -122,8 +96,8 @@ void CxxAstVisitorComponentIndexer::beginTraverseTemplateArgumentLoc(const clang
// TODO: maybe move this to VisitTemplateName
m_client->recordReference(
getAstVisitor()->getComponent<CxxAstVisitorComponentTypeRefKind>()->getReferenceKind(),
getAstVisitor()->getDeclNameCache()->getValue(loc.getArgument().getAsTemplate().getAsTemplateDecl()),
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContextName(),
getOrCreateSymbolId(loc.getArgument().getAsTemplate().getAsTemplateDecl()),
getOrCreateSymbolId(getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContext()),
getParseLocation(loc.getLocation())
);
}
@@ -139,12 +113,7 @@ void CxxAstVisitorComponentIndexer::beginTraverseLambdaCapture(clang::LambdaExpr
{
if (!d->getNameAsString().empty()) // don't record anonymous parameters
{
ParseLocation declLocation = getParseLocation(d->getLocation());
std::wstring name =
declLocation.filePath.fileName() + L"<" +
std::to_wstring(declLocation.startLineNumber) + L":" +
std::to_wstring(declLocation.startColumnNumber) + L">";
m_client->recordLocalSymbol(name, getParseLocation(capture->getLocation()));
m_client->recordLocalSymbol(getLocalSymbolName(d->getLocation()), getParseLocation(capture->getLocation()));
}
}
}
@@ -161,30 +130,31 @@ void CxxAstVisitorComponentIndexer::visitTagDecl(clang::TagDecl* d)
}
const SymbolKind symbolKind = utility::convertTagKind(d->getTagKind());
m_client->recordSymbolWithLocationAndScope(
getAstVisitor()->getDeclNameCache()->getValue(d),
symbolKind,
getParseLocation(d->getLocation()),
getParseLocationOfTagDeclBody(d),
utility::convertAccessSpecifier(d->getAccess()),
definitionKind
);
const ParseLocation location = getParseLocation(d->getLocation());
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId, symbolKind);
m_client->recordLocation(symbolId, location, ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, getParseLocationOfTagDeclBody(d), ParseLocationType::SCOPE);
m_client->recordAccessKind(symbolId, utility::convertAccessSpecifier(d->getAccess()));
m_client->recordDefinitionKind(symbolId, definitionKind);
if (clang::EnumDecl* enumDecl = clang::dyn_cast_or_null<clang::EnumDecl>(d))
{
recordTemplateMemberSpecialization(
enumDecl->getMemberSpecializationInfo(),
getAstVisitor()->getDeclNameCache()->getValue(d),
getParseLocation(d->getLocation()),
symbolId,
location,
symbolKind
);
}
if(clang::CXXRecordDecl* recordDecl = clang::dyn_cast_or_null<clang::CXXRecordDecl>(d))
if (clang::CXXRecordDecl* recordDecl = clang::dyn_cast_or_null<clang::CXXRecordDecl>(d))
{
recordTemplateMemberSpecialization(
recordDecl->getMemberSpecializationInfo(),
getAstVisitor()->getDeclNameCache()->getValue(d),
getParseLocation(d->getLocation()),
symbolId,
location,
symbolKind
);
}
@@ -210,8 +180,8 @@ void CxxAstVisitorComponentIndexer::visitClassTemplateSpecializationDecl(clang::
m_client->recordReference(
REFERENCE_TEMPLATE_SPECIALIZATION,
getAstVisitor()->getDeclNameCache()->getValue(specializedFromDecl),
getAstVisitor()->getDeclNameCache()->getValue(d),
getOrCreateSymbolId(specializedFromDecl),
getOrCreateSymbolId(d),
getParseLocation(d->getLocation())
);
}
@@ -226,28 +196,23 @@ void CxxAstVisitorComponentIndexer::visitVarDecl(clang::VarDecl* d)
{
if (!d->getNameAsString().empty()) // don't record anonymous parameters
{
ParseLocation declLocation = getParseLocation(d->getLocation());
std::wstring name =
declLocation.filePath.fileName() + L"<" +
std::to_wstring(declLocation.startLineNumber) + L":" +
std::to_wstring(declLocation.startColumnNumber) + L">";
m_client->recordLocalSymbol(name, getParseLocation(d->getLocation()));
m_client->recordLocalSymbol(getLocalSymbolName(d->getLocation()), getParseLocation(d->getLocation()));
}
}
else
{
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
symbolKind,
getParseLocation(d->getLocation()),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
const ParseLocation location = getParseLocation(d->getLocation());
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId, symbolKind);
m_client->recordLocation(symbolId, location, ParseLocationType::TOKEN);
m_client->recordAccessKind(symbolId, utility::convertAccessSpecifier(d->getAccess()));
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
recordTemplateMemberSpecialization(
d->getMemberSpecializationInfo(),
getAstVisitor()->getDeclNameCache()->getValue(d),
getParseLocation(d->getLocation()),
symbolId,
location,
symbolKind
);
}
@@ -273,8 +238,8 @@ void CxxAstVisitorComponentIndexer::visitVarTemplateSpecializationDecl(clang::Va
m_client->recordReference(
REFERENCE_TEMPLATE_SPECIALIZATION,
getAstVisitor()->getDeclNameCache()->getValue(specializedFromDecl),
getAstVisitor()->getDeclNameCache()->getValue(d),
getOrCreateSymbolId(specializedFromDecl),
getOrCreateSymbolId(d),
getParseLocation(d->getLocation())
);
}
@@ -284,13 +249,13 @@ void CxxAstVisitorComponentIndexer::visitFieldDecl(clang::FieldDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_FIELD,
getParseLocation(d->getLocation()),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
const ParseLocation location = getParseLocation(d->getLocation());
Id fieldId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(fieldId, SYMBOL_FIELD);
m_client->recordLocation(fieldId, location, ParseLocationType::TOKEN);
m_client->recordAccessKind(fieldId, utility::convertAccessSpecifier(d->getAccess()));
m_client->recordDefinitionKind(fieldId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
if (clang::CXXRecordDecl* declaringRecordDecl = clang::dyn_cast_or_null<clang::CXXRecordDecl>(d->getParent()))
{
@@ -300,15 +265,13 @@ void CxxAstVisitorComponentIndexer::visitFieldDecl(clang::FieldDecl* d)
{
if (d->getName() == templateFieldDecl->getName())
{
const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(templateFieldDecl);
m_client->recordSymbol(referencedName, SYMBOL_FIELD, ACCESS_NONE, DEFINITION_NONE);
Id templateFieldId = getOrCreateSymbolId(templateFieldDecl);
m_client->recordSymbolKind(templateFieldId, SYMBOL_FIELD);
m_client->recordReference(
REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION,
referencedName,
getAstVisitor()->getDeclNameCache()->getValue(d),
getParseLocation(d->getLocation())
templateFieldId,
fieldId,
location
);
break;
}
@@ -322,40 +285,26 @@ void CxxAstVisitorComponentIndexer::visitFunctionDecl(clang::FunctionDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId, clang::isa<clang::CXXMethodDecl>(d) ? SYMBOL_METHOD : SYMBOL_FUNCTION);
m_client->recordLocation(symbolId, getParseLocation(d->getNameInfo().getSourceRange()), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, getParseLocationOfFunctionBody(d), ParseLocationType::SCOPE);
m_client->recordAccessKind(symbolId, utility::convertAccessSpecifier(d->getAccess()));
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
if (d->isFirstDecl())
{
m_client->recordSymbolWithLocationAndScopeAndSignature(
getAstVisitor()->getDeclNameCache()->getValue(d),
clang::isa<clang::CXXMethodDecl>(d) ? SYMBOL_METHOD : SYMBOL_FUNCTION,
getParseLocation(d->getNameInfo().getSourceRange()),
getParseLocationOfFunctionBody(d),
getSignatureLocation(d),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
}
else
{
m_client->recordSymbolWithLocationAndScope(
getAstVisitor()->getDeclNameCache()->getValue(d),
clang::isa<clang::CXXMethodDecl>(d) ? SYMBOL_METHOD : SYMBOL_FUNCTION,
getParseLocation(d->getNameInfo().getSourceRange()),
getParseLocationOfFunctionBody(d),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
m_client->recordLocation(symbolId, getSignatureLocation(d), ParseLocationType::SIGNATURE);
}
if (d->isFunctionTemplateSpecialization())
{
const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(d->getPrimaryTemplate()->getTemplatedDecl()); // todo: use context and childcontext!!
m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE);
Id templateId = getOrCreateSymbolId(d->getPrimaryTemplate()->getTemplatedDecl());
m_client->recordSymbolKind(templateId, SYMBOL_FUNCTION);
m_client->recordReference(
REFERENCE_TEMPLATE_SPECIALIZATION,
referencedName,
getAstVisitor()->getDeclNameCache()->getValue(d),
templateId,
symbolId,
getParseLocation(d->getLocation())
);
}
@@ -367,25 +316,26 @@ void CxxAstVisitorComponentIndexer::visitCXXMethodDecl(clang::CXXMethodDecl* d)
// Decl has been recorded in VisitFunctionDecl
if (getAstVisitor()->shouldVisitDecl(d))
{
Id symbolId = getOrCreateSymbolId(d);
ParseLocation location = getParseLocation(d->getLocation());
for (clang::CXXMethodDecl::method_iterator it = d->begin_overridden_methods(); // TODO: iterate in traversal and use REFERENCE_OVERRIDE or so..
it != d->end_overridden_methods(); it++)
{
const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(*it);
m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE);
Id overrideId = getOrCreateSymbolId(*it);
m_client->recordSymbolKind(overrideId, SYMBOL_FUNCTION);
m_client->recordReference(
REFERENCE_OVERRIDE,
referencedName,
getAstVisitor()->getDeclNameCache()->getValue(d),
getParseLocation(d->getLocation())
overrideId,
symbolId,
location
);
}
recordTemplateMemberSpecialization(
d->getMemberSpecializationInfo(),
getAstVisitor()->getDeclNameCache()->getValue(d),
getParseLocation(d->getLocation()),
symbolId,
location,
SYMBOL_FUNCTION
);
}
@@ -395,13 +345,10 @@ void CxxAstVisitorComponentIndexer::visitEnumConstantDecl(clang::EnumConstantDec
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_ENUM_CONSTANT,
getParseLocation(d->getLocation()),
ACCESS_NONE,
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId, SYMBOL_ENUM_CONSTANT);
m_client->recordLocation(symbolId, getParseLocation(d->getLocation()), ParseLocationType::TOKEN);
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
}
}
@@ -409,14 +356,12 @@ void CxxAstVisitorComponentIndexer::visitNamespaceDecl(clang::NamespaceDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbolWithLocationAndScope(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_NAMESPACE,
getParseLocation(d->getLocation()),
getParseLocation(d->getSourceRange()),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId, SYMBOL_NAMESPACE);
m_client->recordLocation(symbolId, getParseLocation(d->getLocation()), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, getParseLocation(d->getSourceRange()), ParseLocationType::SCOPE);
m_client->recordAccessKind(symbolId, utility::convertAccessSpecifier(d->getAccess()));
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
}
}
@@ -424,18 +369,16 @@ void CxxAstVisitorComponentIndexer::visitNamespaceAliasDecl(clang::NamespaceAlia
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_NAMESPACE,
getParseLocation(d->getLocation()),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId, SYMBOL_NAMESPACE);
m_client->recordLocation(symbolId, getParseLocation(d->getLocation()), ParseLocationType::TOKEN);
m_client->recordAccessKind(symbolId, utility::convertAccessSpecifier(d->getAccess()));
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
m_client->recordReference(
REFERENCE_USAGE,
getAstVisitor()->getDeclNameCache()->getValue(d->getAliasedNamespace()),
getAstVisitor()->getDeclNameCache()->getValue(d),
getOrCreateSymbolId(d->getAliasedNamespace()),
symbolId,
getParseLocation(d->getTargetNameLoc())
);
@@ -447,13 +390,12 @@ void CxxAstVisitorComponentIndexer::visitTypedefDecl(clang::TypedefDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
d->getAnonDeclWithTypedefName() == nullptr ? SYMBOL_TYPEDEF : utility::convertTagKind(d->getAnonDeclWithTypedefName()->getTagKind()),
getParseLocation(d->getLocation()),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId,
d->getAnonDeclWithTypedefName() == nullptr ? SYMBOL_TYPEDEF : utility::convertTagKind(d->getAnonDeclWithTypedefName()->getTagKind()));
m_client->recordLocation(symbolId, getParseLocation(d->getLocation()), ParseLocationType::TOKEN);
m_client->recordAccessKind(symbolId, utility::convertAccessSpecifier(d->getAccess()));
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
}
}
@@ -461,13 +403,12 @@ void CxxAstVisitorComponentIndexer::visitTypeAliasDecl(clang::TypeAliasDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
d->getAnonDeclWithTypedefName() == nullptr ? SYMBOL_TYPEDEF : utility::convertTagKind(d->getAnonDeclWithTypedefName()->getTagKind()),
getParseLocation(d->getLocation()),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId,
d->getAnonDeclWithTypedefName() == nullptr ? SYMBOL_TYPEDEF : utility::convertTagKind(d->getAnonDeclWithTypedefName()->getTagKind()));
m_client->recordLocation(symbolId, getParseLocation(d->getLocation()), ParseLocationType::TOKEN);
m_client->recordAccessKind(symbolId, utility::convertAccessSpecifier(d->getAccess()));
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
}
}
@@ -475,16 +416,18 @@ void CxxAstVisitorComponentIndexer::visitUsingDirectiveDecl(clang::UsingDirectiv
{
if (getAstVisitor()->shouldVisitDecl(d))
{
const NameHierarchy nameHierarchy = getAstVisitor()->getDeclNameCache()->getValue(d->getNominatedNamespaceAsWritten());
Id symbolId = getOrCreateSymbolId(d->getNominatedNamespaceAsWritten());
m_client->recordSymbolKind(symbolId, SYMBOL_NAMESPACE);
m_client->recordSymbol(nameHierarchy, SYMBOL_NAMESPACE, ACCESS_NONE, DEFINITION_NONE);
const ParseLocation location = getParseLocation(d->getLocation());
ParseLocation loc = getParseLocation(d->getLocation());
m_client->recordReference(
REFERENCE_USAGE,
nameHierarchy,
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContextName(NameHierarchy(loc.filePath.wstr(), NAME_DELIMITER_FILE)),
loc
symbolId,
getOrCreateSymbolId(
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContext(),
NameHierarchy(getAstVisitor()->getCanonicalFilePathCache()->getCanonicalFilePath(location.fileId).wstr(), NAME_DELIMITER_FILE)),
location
);
}
}
@@ -493,12 +436,15 @@ void CxxAstVisitorComponentIndexer::visitUsingDecl(clang::UsingDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
ParseLocation loc = getParseLocation(d->getLocation());
const ParseLocation location = getParseLocation(d->getLocation());
m_client->recordReference(
REFERENCE_USAGE,
getAstVisitor()->getDeclNameCache()->getValue(d),
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContextName(NameHierarchy(loc.filePath.wstr(), NAME_DELIMITER_FILE)),
loc
getOrCreateSymbolId(d),
getOrCreateSymbolId(
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContext(),
NameHierarchy(getAstVisitor()->getCanonicalFilePathCache()->getCanonicalFilePath(location.fileId).wstr(), NAME_DELIMITER_FILE)),
location
);
}
}
@@ -507,13 +453,11 @@ void CxxAstVisitorComponentIndexer::visitNonTypeTemplateParmDecl(clang::NonTypeT
{
if (getAstVisitor()->shouldVisitDecl(d) && !d->getName().empty()) // We don't create symbols for unnamed template parameters.
{
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_TEMPLATE_PARAMETER,
getParseLocation(d->getLocation()),
ACCESS_TEMPLATE_PARAMETER,
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId, SYMBOL_TEMPLATE_PARAMETER);
m_client->recordLocation(symbolId, getParseLocation(d->getLocation()), ParseLocationType::TOKEN);
m_client->recordAccessKind(symbolId, ACCESS_TEMPLATE_PARAMETER);
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
}
}
@@ -521,13 +465,11 @@ void CxxAstVisitorComponentIndexer::visitTemplateTypeParmDecl(clang::TemplateTyp
{
if (getAstVisitor()->shouldVisitDecl(d) && !d->getName().empty()) // We don't create symbols for unnamed template parameters.
{
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_TEMPLATE_PARAMETER,
getParseLocation(d->getLocation()),
ACCESS_TEMPLATE_PARAMETER,
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId, SYMBOL_TEMPLATE_PARAMETER);
m_client->recordLocation(symbolId, getParseLocation(d->getLocation()), ParseLocationType::TOKEN);
m_client->recordAccessKind(symbolId, ACCESS_TEMPLATE_PARAMETER);
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
}
}
@@ -535,13 +477,11 @@ void CxxAstVisitorComponentIndexer::visitTemplateTemplateParmDecl(clang::Templat
{
if (getAstVisitor()->shouldVisitDecl(d) && !d->getName().empty()) // We don't create symbols for unnamed template parameters.
{
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_TEMPLATE_PARAMETER,
getParseLocation(d->getLocation()),
ACCESS_TEMPLATE_PARAMETER,
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
Id symbolId = getOrCreateSymbolId(d);
m_client->recordSymbolKind(symbolId, SYMBOL_TEMPLATE_PARAMETER);
m_client->recordLocation(symbolId, getParseLocation(d->getLocation()), ParseLocationType::TOKEN);
m_client->recordAccessKind(symbolId, ACCESS_TEMPLATE_PARAMETER);
m_client->recordDefinitionKind(symbolId, utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
}
}
@@ -550,9 +490,12 @@ void CxxAstVisitorComponentIndexer::visitTypeLoc(clang::TypeLoc tl)
if ((getAstVisitor()->shouldVisitReference(tl.getBeginLoc(), getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl())) &&
(!getAstVisitor()->checkIgnoresTypeLoc(tl)))
{
Id symbolId = getOrCreateSymbolId(tl.getTypePtr());
if (clang::dyn_cast_or_null<clang::BuiltinType>(tl.getTypePtr()))
{
m_client->recordSymbol(getAstVisitor()->getTypeNameCache()->getValue(tl.getTypePtr()), SYMBOL_BUILTIN_TYPE, ACCESS_NONE, DEFINITION_EXPLICIT);
m_client->recordSymbolKind(symbolId, SYMBOL_BUILTIN_TYPE);
m_client->recordDefinitionKind(symbolId, DEFINITION_EXPLICIT);
}
clang::SourceLocation loc;
@@ -568,8 +511,8 @@ void CxxAstVisitorComponentIndexer::visitTypeLoc(clang::TypeLoc tl)
m_client->recordReference(
getAstVisitor()->getComponent<CxxAstVisitorComponentTypeRefKind>()->getReferenceKind(),
getAstVisitor()->getTypeNameCache()->getValue(tl.getTypePtr()),
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContextName(1), // we skip the last element because it refers to this typeloc.
symbolId,
getOrCreateSymbolId(getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContext(1)), // we skip the last element because it refers to this typeloc.
getParseLocation(loc)
);
}
@@ -583,27 +526,22 @@ void CxxAstVisitorComponentIndexer::visitDeclRefExpr(clang::DeclRefExpr* s)
if ((clang::isa<clang::ParmVarDecl>(decl)) ||
(clang::isa<clang::VarDecl>(decl) && decl->getParentFunctionOrMethod() != nullptr)
) {
ParseLocation declLocation = getParseLocation(decl->getLocation());
std::wstring name = declLocation.filePath.fileName() + L"<" +
std::to_wstring(declLocation.startLineNumber) + L":" +
std::to_wstring(declLocation.startColumnNumber) + L">";
m_client->recordLocalSymbol(name, getParseLocation(s->getLocation()));
m_client->recordLocalSymbol(getLocalSymbolName(decl->getLocation()), getParseLocation(s->getLocation()));
}
else
{
const ReferenceKind refKind = consumeDeclRefContextKind();
const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(s->getDecl());
Id symbolId = getOrCreateSymbolId(decl);
const ReferenceKind refKind = consumeDeclRefContextKind();
if (refKind == REFERENCE_CALL)
{
m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE);
m_client->recordSymbolKind(symbolId, SYMBOL_FUNCTION);
}
m_client->recordReference(
refKind,
referencedName,
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContextName(),
symbolId,
getOrCreateSymbolId(getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContext()),
getParseLocation(s->getLocation())
);
}
@@ -614,18 +552,18 @@ void CxxAstVisitorComponentIndexer::visitMemberExpr(clang::MemberExpr* s)
{
if (getAstVisitor()->shouldVisitReference(s->getMemberLoc(), getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getTopmostContextDecl()))
{
const ReferenceKind refKind = consumeDeclRefContextKind();
const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(s->getMemberDecl());
Id symbolId = getOrCreateSymbolId(s->getMemberDecl());
const ReferenceKind refKind = consumeDeclRefContextKind();
if (refKind == REFERENCE_CALL)
{
m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE);
m_client->recordSymbolKind(symbolId, SYMBOL_FUNCTION);
}
m_client->recordReference(
refKind,
referencedName,
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContextName(),
symbolId,
getOrCreateSymbolId(getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContext()),
getParseLocation(s->getMemberLoc())
);
}
@@ -693,18 +631,18 @@ void CxxAstVisitorComponentIndexer::visitCXXConstructExpr(clang::CXXConstructExp
}
loc = clang::Lexer::GetBeginningOfToken(loc, m_astContext->getSourceManager(), m_astContext->getLangOpts());
const ReferenceKind refKind = consumeDeclRefContextKind();
const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(s->getConstructor());
Id symbolId = getOrCreateSymbolId(s->getConstructor());
const ReferenceKind refKind = consumeDeclRefContextKind();
if (refKind == REFERENCE_CALL)
{
m_client->recordSymbol(referencedName, SYMBOL_FUNCTION, ACCESS_NONE, DEFINITION_NONE);
m_client->recordSymbolKind(symbolId, SYMBOL_FUNCTION);
}
m_client->recordReference(
refKind,
referencedName,
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContextName(),
symbolId,
getOrCreateSymbolId(getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContext()),
getParseLocation(loc)
);
}
@@ -715,14 +653,11 @@ void CxxAstVisitorComponentIndexer::visitLambdaExpr(clang::LambdaExpr* s)
clang::CXXMethodDecl* methodDecl = s->getCallOperator();
if (getAstVisitor()->shouldVisitDecl(methodDecl))
{
m_client->recordSymbolWithLocationAndScope(
getAstVisitor()->getDeclNameCache()->getValue(methodDecl),
SYMBOL_FUNCTION,
getParseLocation(s->getLocStart()),
getParseLocationOfFunctionBody(methodDecl),
ACCESS_NONE, // TODO: introduce AccessLambda
utility::isImplicit(methodDecl) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
Id symbolId = getOrCreateSymbolId(methodDecl);
m_client->recordSymbolKind(symbolId, SYMBOL_FUNCTION);
m_client->recordLocation(symbolId, getParseLocation(s->getLocStart()), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, getParseLocationOfFunctionBody(methodDecl), ParseLocationType::SCOPE);
m_client->recordDefinitionKind(symbolId, utility::isImplicit(methodDecl) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
}
}
@@ -735,8 +670,8 @@ void CxxAstVisitorComponentIndexer::visitConstructorInitializer(clang::CXXCtorIn
{
m_client->recordReference(
REFERENCE_USAGE,
getAstVisitor()->getDeclNameCache()->getValue(memberDecl),
getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContextName(),
getOrCreateSymbolId(memberDecl),
getOrCreateSymbolId(getAstVisitor()->getComponent<CxxAstVisitorComponentContext>()->getContext()),
getParseLocation(init->getMemberLocation())
);
}
@@ -744,19 +679,16 @@ void CxxAstVisitorComponentIndexer::visitConstructorInitializer(clang::CXXCtorIn
}
void CxxAstVisitorComponentIndexer::recordTemplateMemberSpecialization(
const clang::MemberSpecializationInfo* memberSpecializationInfo, const NameHierarchy& context, const ParseLocation& location, SymbolKind symbolKind)
const clang::MemberSpecializationInfo* memberSpecializationInfo, Id contextId, const ParseLocation& location, SymbolKind symbolKind)
{
if (memberSpecializationInfo != nullptr)
{
clang::NamedDecl* specializedNamedDecl = memberSpecializationInfo->getInstantiatedFrom();
const NameHierarchy referencedName = getAstVisitor()->getDeclNameCache()->getValue(specializedNamedDecl);
m_client->recordSymbol(referencedName, symbolKind, ACCESS_NONE, DEFINITION_NONE);
Id symbolId = getOrCreateSymbolId(memberSpecializationInfo->getInstantiatedFrom());
m_client->recordSymbolKind(symbolId, symbolKind);
m_client->recordReference(
REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION,
referencedName,
context,
symbolId,
contextId,
location
);
}
@@ -834,6 +766,14 @@ ParseLocation CxxAstVisitorComponentIndexer::getParseLocation(const clang::Sourc
return getAstVisitor()->getParseLocation(sourceRange);
}
std::wstring CxxAstVisitorComponentIndexer::getLocalSymbolName(const clang::SourceLocation& loc) const
{
const ParseLocation location = getParseLocation(loc);
return getAstVisitor()->getCanonicalFilePathCache()->getCanonicalFilePath(location.fileId).fileName() + L"<" +
std::to_wstring(location.startLineNumber) + L":" +
std::to_wstring(location.startColumnNumber) + L">";
}
ReferenceKind CxxAstVisitorComponentIndexer::consumeDeclRefContextKind()
{
ReferenceKind refKind = REFERENCE_UNDEFINED;
@@ -849,3 +789,86 @@ ReferenceKind CxxAstVisitorComponentIndexer::consumeDeclRefContextKind()
}
return refKind;
}
Id CxxAstVisitorComponentIndexer::getOrCreateSymbolId(const clang::NamedDecl* decl)
{
auto it = m_declSymbolIds.find(decl);
if (it != m_declSymbolIds.end())
{
return it->second;
}
NameHierarchy symbolName(L"global", NAME_DELIMITER_UNKNOWN);
if (decl)
{
std::unique_ptr<CxxDeclName> declName =
CxxDeclNameResolver(getAstVisitor()->getCanonicalFilePathCache()).getName(decl);
if (declName)
{
symbolName = declName->toNameHierarchy();
}
}
Id symbolId = m_client->recordSymbol(symbolName);
m_declSymbolIds.emplace(decl, symbolId);
return symbolId;
}
Id CxxAstVisitorComponentIndexer::getOrCreateSymbolId(const clang::Type* type)
{
auto it = m_typeSymbolIds.find(type);
if (it != m_typeSymbolIds.end())
{
return it->second;
}
NameHierarchy symbolName(L"global", NAME_DELIMITER_UNKNOWN);
if (type)
{
std::unique_ptr<CxxTypeName> typeName =
CxxTypeNameResolver(getAstVisitor()->getCanonicalFilePathCache()).getName(type);
if (typeName)
{
symbolName = typeName->toNameHierarchy();
}
}
Id symbolId = m_client->recordSymbol(symbolName);
m_typeSymbolIds.emplace(type, symbolId);
return symbolId;
}
Id CxxAstVisitorComponentIndexer::getOrCreateSymbolId(const CxxContext* context)
{
if (context)
{
if (context->getDecl())
{
return getOrCreateSymbolId(context->getDecl());
}
else
{
return getOrCreateSymbolId(context->getType());
}
}
const clang::NamedDecl* decl { nullptr };
return getOrCreateSymbolId(decl);
}
Id CxxAstVisitorComponentIndexer::getOrCreateSymbolId(const CxxContext* context, const NameHierarchy& fallback)
{
if (context)
{
if (context->getDecl())
{
return getOrCreateSymbolId(context->getDecl());
}
else if (context->getType())
{
return getOrCreateSymbolId(context->getType());
}
}
return m_client->recordSymbol(fallback); // TODO: cache result somehow
}
@@ -8,6 +8,7 @@
#include "ReferenceKind.h"
#include "SymbolKind.h"
class CxxContext;
class ParserClient;
class NameHierarchy;
@@ -52,7 +53,7 @@ public:
private:
void recordTemplateMemberSpecialization(
const clang::MemberSpecializationInfo* memberSpecializationInfo,
const NameHierarchy& context,
Id contextId,
const ParseLocation& location,
SymbolKind symbolKind
);
@@ -63,10 +64,21 @@ private:
ParseLocation getParseLocation(const clang::SourceLocation& loc) const;
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
std::wstring getLocalSymbolName(const clang::SourceLocation& loc) const;
ReferenceKind consumeDeclRefContextKind();
Id getOrCreateSymbolId(const clang::NamedDecl* decl);
Id getOrCreateSymbolId(const clang::Type* type);
Id getOrCreateSymbolId(const CxxContext* context);
Id getOrCreateSymbolId(const CxxContext* context, const NameHierarchy& fallback);
clang::ASTContext* m_astContext;
std::shared_ptr<ParserClient> m_client;
std::map<const clang::NamedDecl*, Id> m_declSymbolIds;
std::map<const clang::Type*, Id> m_typeSymbolIds;
};
#endif // CXX_AST_VISITOR_COMPONENT_INDEXER_H
+16 -17
View File
@@ -1,34 +1,33 @@
#include "CxxContext.h"
CxxContextDecl::CxxContextDecl(const clang::NamedDecl* decl, DeclNameCache* nameCache)
const clang::NamedDecl* CxxContext::getDecl() const
{
return nullptr;
}
const clang::Type* CxxContext::getType() const
{
return nullptr;
}
CxxContextDecl::CxxContextDecl(const clang::NamedDecl* decl)
: m_decl(decl)
, m_nameCache(nameCache)
{
}
NameHierarchy CxxContextDecl::getName()
{
return m_nameCache->getValue(m_decl);
}
const clang::NamedDecl* CxxContextDecl::getDecl()
const clang::NamedDecl* CxxContextDecl::getDecl() const
{
return m_decl;
}
CxxContextType::CxxContextType(const clang::Type* type, TypeNameCache* nameCache)
CxxContextType::CxxContextType(const clang::Type* type)
: m_type(type)
, m_nameCache(nameCache)
{
}
NameHierarchy CxxContextType::getName()
const clang::Type* CxxContextType::getType() const
{
return m_nameCache->getValue(m_type);
}
const clang::NamedDecl* CxxContextType::getDecl()
{
return nullptr;
return m_type;
}
+6 -16
View File
@@ -3,18 +3,12 @@
#include <clang/AST/Decl.h>
#include "NameHierarchy.h"
#include "OrderedCache.h"
typedef OrderedCache<const clang::NamedDecl*, NameHierarchy> DeclNameCache;
typedef OrderedCache<const clang::Type*, NameHierarchy> TypeNameCache;
class CxxContext
{
public:
virtual ~CxxContext() = default;
virtual NameHierarchy getName() = 0;
virtual const clang::NamedDecl* getDecl() = 0;
virtual const clang::NamedDecl* getDecl() const;
virtual const clang::Type* getType() const;
};
@@ -22,13 +16,11 @@ class CxxContextDecl
: public CxxContext
{
public:
CxxContextDecl(const clang::NamedDecl* decl, DeclNameCache* nameCache);
NameHierarchy getName() override;
const clang::NamedDecl* getDecl() override;
CxxContextDecl(const clang::NamedDecl* decl);
const clang::NamedDecl* getDecl() const override;
private:
const clang::NamedDecl* m_decl;
DeclNameCache* m_nameCache;
};
@@ -36,13 +28,11 @@ class CxxContextType
: public CxxContext
{
public:
CxxContextType(const clang::Type* type, TypeNameCache* nameCache);
NameHierarchy getName() override;
const clang::NamedDecl* getDecl() override;
CxxContextType(const clang::Type* type);
const clang::Type* getType() const override;
private:
const clang::Type* m_type;
TypeNameCache* m_nameCache;
};
#endif // CXX_CONTEXT_H
@@ -63,7 +63,9 @@ void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level lev
return;
}
ParseLocation location(FilePath(), 0, 0);
FilePath filePath;
uint lineNumber = 0;
uint columnNumber = 0;
if (info.getLocation().isValid() && info.hasSourceManager())
{
const clang::SourceManager& sourceManager = info.getSourceManager();
@@ -79,28 +81,38 @@ void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level lev
if (fileEntry != nullptr && fileEntry->isValid())
{
location = utility::getParseLocation(loc, sourceManager, nullptr, m_canonicalFilePathCache);
ParseLocation location = utility::getParseLocation(loc, sourceManager, nullptr, m_canonicalFilePathCache);
filePath = m_canonicalFilePathCache->getCanonicalFilePath(location.fileId);
lineNumber = location.startLineNumber;
columnNumber = location.startColumnNumber;
}
else
{
fileEntry = sourceManager.getFileEntryForID(sourceManager.getMainFileID());
if (fileEntry != nullptr && fileEntry->isValid())
{
location = ParseLocation(m_canonicalFilePathCache->getCanonicalFilePath(fileEntry), 1, 1);
filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
lineNumber = 1;
columnNumber = 1;
}
}
}
else
{
location = ParseLocation(m_canonicalFilePathCache->getCanonicalFilePath(m_sourceFilePath.wstr()), 1, 1);
filePath = m_sourceFilePath;
lineNumber = 1;
columnNumber = 1;
}
if (location.isValid())
if (!filePath.empty())
{
m_client->recordError(
location,
filePath,
lineNumber,
columnNumber,
utility::decodeFromUtf8(message),
level == clang::DiagnosticsEngine::Fatal,
m_canonicalFilePathCache->getFileRegister()->hasFilePath(location.filePath),
m_canonicalFilePathCache->getFileRegister()->hasFilePath(filePath),
m_sourceFilePath
);
}
@@ -5,10 +5,10 @@
#include <clang/Basic/SourceLocation.h>
#include <clang/Basic/SourceManager.h>
#include "CanonicalFilePathCache.h"
#include "logging.h"
#include "ParseLocation.h"
#include "ParserClient.h"
#include "logging.h"
#include "ScopedSwitcher.h"
CxxVerboseAstVisitor::CxxVerboseAstVisitor(
@@ -19,7 +19,6 @@ CxxVerboseAstVisitor::CxxVerboseAstVisitor(
std::shared_ptr<IndexerStateInfo> indexerStateInfo
)
: base(context, preprocessor, client, canonicalFilePathCache, indexerStateInfo)
, m_currentFilePath(L"")
, m_indentation(0)
{
}
@@ -38,10 +37,13 @@ bool CxxVerboseAstVisitor::TraverseDecl(clang::Decl* d)
ParseLocation loc = getParseLocation(d->getSourceRange());
stream << " <" << loc.startLineNumber << ":" << loc.startColumnNumber << ", " << loc.endLineNumber << ":" << loc.endColumnNumber << ">";
if (m_currentFilePath != loc.filePath.wstr())
const clang::SourceManager& sm = m_astContext->getSourceManager();
FilePath currentFilePath =
getCanonicalFilePathCache()->getCanonicalFilePath(sm.getFileID(d->getSourceRange().getBegin()), sm);
if (m_currentFilePath != currentFilePath)
{
m_currentFilePath = loc.filePath.wstr();
LOG_INFO_BARE(L"Indexer - Traversing \"" + m_currentFilePath + L"\"" );
m_currentFilePath = currentFilePath;
LOG_INFO_BARE(L"Indexer - Traversing \"" + currentFilePath.wstr() + L"\"" );
}
LOG_INFO_STREAM_BARE(<< "Indexer - " << stream.str());
@@ -46,7 +46,7 @@ private:
return "";
}
std::wstring m_currentFilePath;
FilePath m_currentFilePath;
unsigned int m_indentation;
};
@@ -26,18 +26,24 @@ void PreprocessorCallbacks::FileChanged(
clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID prevID)
{
const clang::FileID fileId = m_sourceManager.getFileID(location);
m_currentPath = m_canonicalFilePathCache->getCanonicalFilePath(fileId, m_sourceManager);
const FilePath currentPath = m_canonicalFilePathCache->getCanonicalFilePath(fileId, m_sourceManager);
m_currentPathIsProjectFile = false;
if (!m_currentPath.empty())
if (!currentPath.empty())
{
m_currentPathIsProjectFile = m_canonicalFilePathCache->getFileRegister()->hasFilePath(m_currentPath);
m_currentPathIsProjectFile = m_canonicalFilePathCache->isProjectFile(fileId, m_sourceManager);
if (m_fileWasRecorded.find(fileId) == m_fileWasRecorded.end())
{
m_client->recordFile(m_currentPath, m_currentPathIsProjectFile); // todo: fix for tests
m_currentFileSymbolId = m_client->recordFile(currentPath, m_currentPathIsProjectFile); // todo: fix for tests
m_canonicalFilePathCache->addFileSymbolId(fileId, currentPath, m_currentFileSymbolId);
m_fileWasRecorded.insert(fileId);
}
else
{
m_currentFileSymbolId = m_canonicalFilePathCache->getFileSymbolId(fileId);
}
}
}
@@ -46,16 +52,17 @@ void PreprocessorCallbacks::InclusionDirective(
clang::CharSourceRange fileNameRange, const clang::FileEntry* fileEntry, llvm::StringRef searchPath,
llvm::StringRef relativePath, const clang::Module* imported
){
if (!m_currentPath.empty() && fileEntry)
if (m_currentFileSymbolId && fileEntry)
{
const FilePath includedFilePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
const NameHierarchy referencedNameHierarchy(includedFilePath.wstr(), NAME_DELIMITER_FILE);
const NameHierarchy contextNameHierarchy(m_currentPath.wstr(), NAME_DELIMITER_FILE);
const NameHierarchy includedFileNameHierarchy(includedFilePath.wstr(), NAME_DELIMITER_FILE);
Id includedFileSymbolId = m_client->recordSymbol(includedFileNameHierarchy);
m_client->recordReference(
REFERENCE_INCLUDE,
referencedNameHierarchy,
contextNameHierarchy,
includedFileSymbolId,
m_currentFileSymbolId,
getParseLocation(fileNameRange.getAsRange())
);
}
@@ -74,14 +81,11 @@ void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, con
const NameHierarchy nameHierarchy(
utility::decodeFromUtf8(macroNameToken.getIdentifierInfo()->getName().str()), NAME_DELIMITER_CXX);
m_client->recordSymbolWithLocationAndScope(
nameHierarchy,
SYMBOL_MACRO,
getParseLocation(macroNameToken),
getParseLocation(macroDirective->getMacroInfo()),
ACCESS_NONE,
DEFINITION_EXPLICIT
);
Id symbolId = m_client->recordSymbol(nameHierarchy);
m_client->recordSymbolKind(symbolId, SYMBOL_MACRO);
m_client->recordDefinitionKind(symbolId, DEFINITION_EXPLICIT);
m_client->recordLocation(symbolId, getParseLocation(macroNameToken), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, getParseLocation(macroDirective->getMacroInfo()), ParseLocationType::SCOPE);
}
}
@@ -125,12 +129,11 @@ void PreprocessorCallbacks::onMacroUsage(const clang::Token& macroNameToken)
const NameHierarchy referencedNameHierarchy(
utility::decodeFromUtf8(macroNameToken.getIdentifierInfo()->getName().str()), NAME_DELIMITER_CXX);
const NameHierarchy contextNameHierarchy(loc.filePath.wstr(), NAME_DELIMITER_FILE);
m_client->recordReference(
REFERENCE_MACRO_USAGE,
referencedNameHierarchy,
contextNameHierarchy,
m_client->recordSymbol(referencedNameHierarchy),
loc.fileId,
loc
);
}
@@ -141,11 +144,11 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::Token& macroN
const clang::SourceLocation& location = m_sourceManager.getSpellingLoc(macroNameTok.getLocation());
const clang::SourceLocation& endLocation = m_sourceManager.getSpellingLoc(macroNameTok.getEndLoc());
FilePath filePath = m_canonicalFilePathCache->getCanonicalFilePath(m_sourceManager.getFileID(location), m_sourceManager);
if (!filePath.empty())
Id fileSymbolId = m_canonicalFilePathCache->getFileSymbolId(m_sourceManager.getFileID(location));
if (fileSymbolId)
{
return ParseLocation(
std::move(filePath),
fileSymbolId,
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
@@ -161,11 +164,11 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::MacroInfo* ma
clang::SourceLocation location = macroInfo->getDefinitionLoc();
clang::SourceLocation endLocation = macroInfo->getDefinitionEndLoc();
FilePath filePath = m_canonicalFilePathCache->getCanonicalFilePath(m_sourceManager.getFileID(location), m_sourceManager);
if (!filePath.empty())
Id fileSymbolId = m_canonicalFilePathCache->getFileSymbolId(m_sourceManager.getFileID(location));
if (fileSymbolId)
{
return ParseLocation(
std::move(filePath),
fileSymbolId,
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
@@ -183,13 +186,13 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::SourceRange&
const clang::PresumedLoc& presumedBegin = m_sourceManager.getPresumedLoc(sourceRange.getBegin(), false);
const clang::PresumedLoc& presumedEnd = m_sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
FilePath filePath = m_canonicalFilePathCache->getCanonicalFilePath(
m_sourceManager.getFileID(sourceRange.getBegin()), m_sourceManager);
Id fileSymbolId = m_canonicalFilePathCache->getFileSymbolId(
m_sourceManager.getFileID(sourceRange.getBegin()));
if (!filePath.empty())
if (fileSymbolId)
{
return ParseLocation(
std::move(filePath),
fileSymbolId,
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
@@ -10,6 +10,7 @@
#include <clang/Lex/Token.h>
#include "FilePath.h"
#include "types.h"
class CanonicalFilePathCache;
class ParserClient;
@@ -63,7 +64,7 @@ private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
FilePath m_currentPath;
Id m_currentFileSymbolId;
bool m_currentPathIsProjectFile = false;
std::set<clang::FileID> m_fileWasRecorded;
+8 -7
View File
@@ -124,7 +124,8 @@ std::wstring utility::getFileNameOfFileEntry(const clang::FileEntry* entry)
}
else
{
fileName = FilePath(utility::decodeFromUtf8(entry->getName().str())).getParentDirectory().concatenate(FilePath(fileName).fileName()).wstr();
fileName = FilePath(utility::decodeFromUtf8(entry->getName().str()))
.getParentDirectory().concatenate(FilePath(fileName).fileName()).wstr();
}
}
return fileName;
@@ -161,7 +162,7 @@ ParseLocation utility::getParseLocation(
const unsigned int endOffset = sourceManager.getFileOffset(endSloc);
return ParseLocation(
canonicalFilePathCache->getCanonicalFilePath(fileId, sourceManager),
canonicalFilePathCache->getFileSymbolId(fileId),
sourceManager.getLineNumber(fileId, startOffset),
sourceManager.getColumnNumber(fileId, startOffset),
sourceManager.getLineNumber(fileId, endOffset),
@@ -171,7 +172,7 @@ ParseLocation utility::getParseLocation(
else
{
return ParseLocation(
canonicalFilePathCache->getCanonicalFilePath(fileId, sourceManager),
canonicalFilePathCache->getFileSymbolId(fileId),
sourceManager.getLineNumber(fileId, startOffset),
sourceManager.getColumnNumber(fileId, startOffset)
);
@@ -219,14 +220,14 @@ ParseLocation utility::getParseLocation(
const clang::PresumedLoc presumedBegin = sourceManager.getPresumedLoc(beginLoc, false);
const clang::PresumedLoc presumedEnd = sourceManager.getPresumedLoc(endLoc.isValid() ? endLoc : range.getEnd(), false);
FilePath filePath = canonicalFilePathCache->getCanonicalFilePath(sourceManager.getFileID(beginLoc), sourceManager);
if (filePath.empty())
Id fileSymbolId = canonicalFilePathCache->getFileSymbolId(sourceManager.getFileID(beginLoc));
if (!fileSymbolId)
{
filePath = canonicalFilePathCache->getCanonicalFilePath(utility::decodeFromUtf8(presumedBegin.getFilename()));
fileSymbolId = canonicalFilePathCache->getFileSymbolId(utility::decodeFromUtf8(presumedBegin.getFilename()));
}
return ParseLocation(
std::move(filePath),
fileSymbolId,
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
@@ -6,6 +6,7 @@
#include "AccessKind.h"
#include "SymbolKind.h"
struct ParseLocation;
struct ParseLocation;
class CanonicalFilePathCache;
+50 -54
View File
@@ -34,6 +34,7 @@ JavaParser::JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<Ind
: Parser(client)
, m_indexerStateInfo(indexerStateInfo)
, m_id(s_nextParserId++)
, m_currentFileId(0)
{
const std::string errorString = utility::prepareJavaEnvironment();
if (!errorString.empty())
@@ -101,8 +102,7 @@ void JavaParser::buildIndex(
if (m_javaEnvironment)
{
m_currentFilePath = sourceFilePath;
m_client->recordFile(sourceFilePath, true);
m_currentFileId = m_client->recordFile(sourceFilePath, true);
// remove tabs because they screw with javaparser's location resolver
std::string fileContent = utility::replace(textAccess->getText(), "\t", " ");
@@ -165,15 +165,10 @@ void JavaParser::doRecordSymbol(
jint jAccess, jint jDefinitionKind
)
{
AccessKind access = intToAccessKind(jAccess);
DefinitionKind definitionKind = intToDefinitionKind(jDefinitionKind);
m_client->recordSymbol(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName))),
intToSymbolKind(jSymbolKind),
access,
definitionKind
);
Id symbolId = getOrCreateSymbolId(jSymbolName);
m_client->recordSymbolKind(symbolId, intToSymbolKind(jSymbolKind));
m_client->recordAccessKind(symbolId, intToAccessKind(jAccess));
m_client->recordDefinitionKind(symbolId, intToDefinitionKind(jDefinitionKind));
}
void JavaParser::doRecordSymbolWithLocation(
@@ -182,16 +177,11 @@ void JavaParser::doRecordSymbolWithLocation(
jint jAccess, jint jDefinitionKind
)
{
AccessKind access = intToAccessKind(jAccess);
DefinitionKind definitionKind = intToDefinitionKind(jDefinitionKind);
m_client->recordSymbolWithLocation(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName))),
intToSymbolKind(jSymbolKind),
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn),
access,
definitionKind
);
Id symbolId = getOrCreateSymbolId(jSymbolName);
m_client->recordSymbolKind(symbolId, intToSymbolKind(jSymbolKind));
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn), ParseLocationType::TOKEN);
m_client->recordAccessKind(symbolId, intToAccessKind(jAccess));
m_client->recordDefinitionKind(symbolId, intToDefinitionKind(jDefinitionKind));
}
void JavaParser::doRecordSymbolWithLocationAndScope(
@@ -201,17 +191,12 @@ void JavaParser::doRecordSymbolWithLocationAndScope(
jint jAccess, jint jDefinitionKind
)
{
AccessKind access = intToAccessKind(jAccess);
DefinitionKind definitionKind = intToDefinitionKind(jDefinitionKind);
m_client->recordSymbolWithLocationAndScope(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName))),
intToSymbolKind(jSymbolKind),
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn),
ParseLocation(m_currentFilePath, scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn),
access,
definitionKind
);
Id symbolId = getOrCreateSymbolId(jSymbolName);
m_client->recordSymbolKind(symbolId, intToSymbolKind(jSymbolKind));
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn), ParseLocationType::SCOPE);
m_client->recordAccessKind(symbolId, intToAccessKind(jAccess));
m_client->recordDefinitionKind(symbolId, intToDefinitionKind(jDefinitionKind));
}
void JavaParser::doRecordSymbolWithLocationAndScopeAndSignature(
@@ -222,18 +207,13 @@ void JavaParser::doRecordSymbolWithLocationAndScopeAndSignature(
jint jAccess, jint jDefinitionKind
)
{
AccessKind access = intToAccessKind(jAccess);
DefinitionKind definitionKind = intToDefinitionKind(jDefinitionKind);
m_client->recordSymbolWithLocationAndScopeAndSignature(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName))),
intToSymbolKind(jSymbolKind),
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn),
ParseLocation(m_currentFilePath, scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn),
ParseLocation(m_currentFilePath, signatureBeginLine, signatureBeginColumn, signatureEndLine, signatureEndColumn),
access,
definitionKind
);
Id symbolId = getOrCreateSymbolId(jSymbolName);
m_client->recordSymbolKind(symbolId, intToSymbolKind(jSymbolKind));
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn), ParseLocationType::SCOPE);
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, signatureBeginLine, signatureBeginColumn, signatureEndLine, signatureEndColumn), ParseLocationType::SIGNATURE);
m_client->recordAccessKind(symbolId, intToAccessKind(jAccess));
m_client->recordDefinitionKind(symbolId, intToDefinitionKind(jDefinitionKind));
}
void JavaParser::doRecordReference(
@@ -243,9 +223,9 @@ void JavaParser::doRecordReference(
{
m_client->recordReference(
intToReferenceKind(jReferenceKind),
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jReferencedName))),
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jContextName))),
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn)
getOrCreateSymbolId(jReferencedName),
getOrCreateSymbolId(jContextName),
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn)
);
}
@@ -254,17 +234,15 @@ void JavaParser::doRecordQualifierLocation(
jint beginLine, jint beginColumn, jint endLine, jint endColumn
)
{
m_client->recordQualifierLocation(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jQualifierName))),
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn)
);
Id symbolId = getOrCreateSymbolId(jQualifierName);
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn), ParseLocationType::QUALIFIER);
}
void JavaParser::doRecordLocalSymbol(jstring jSymbolName, jint beginLine, jint beginColumn, jint endLine, jint endColumn)
{
m_client->recordLocalSymbol(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName))).getQualifiedName(),
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn)
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn)
);
}
@@ -273,7 +251,7 @@ void JavaParser::doRecordComment(
)
{
m_client->recordComment(
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn)
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn)
);
}
@@ -286,10 +264,28 @@ void JavaParser::doRecordError(
bool indexed = jIndexed;
m_client->recordError(
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn),
m_currentFilePath,
beginLine,
beginColumn,
utility::decodeFromUtf8(m_javaEnvironment->toStdString(jMessage)),
fatal,
indexed,
FilePath()
);
}
Id JavaParser::getOrCreateSymbolId(jstring jSymbolName)
{
std::string name = m_javaEnvironment->toStdString(jSymbolName);
auto it = m_symbolNameToIdMap.find(name);
if (it != m_symbolNameToIdMap.end())
{
return it->second;
}
Id symbolId = m_client->recordSymbol(NameHierarchy::deserialize(utility::decodeFromUtf8(name)));
m_symbolNameToIdMap.emplace(name, symbolId);
return symbolId;
}
+8 -2
View File
@@ -11,6 +11,7 @@
#include "JavaEnvironment.h"
#include "logging.h"
#include "Parser.h"
#include "types.h"
struct JNIEnv_;
typedef JNIEnv_ JNIEnv;
@@ -227,11 +228,16 @@ private:
void doRecordComment(jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordError(jstring jMessage, jint jFatal, jint jIndexed, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
std::shared_ptr<JavaEnvironment> m_javaEnvironment;
Id getOrCreateSymbolId(jstring jSymbolName);
FilePath m_currentFilePath;
std::shared_ptr<JavaEnvironment> m_javaEnvironment;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
const int m_id;
FilePath m_currentFilePath;
Id m_currentFileId;
std::map<std::string, Id> m_symbolNameToIdMap;
};
#endif // JAVA_PARSER_H
+1 -1
View File
@@ -258,7 +258,7 @@ private:
ParseLocation validLocation(Id locationId = 0) const
{
return ParseLocation(m_filePath, 1, locationId, 1, locationId);
return ParseLocation(1, 1, locationId, 1, locationId);
}
NameHierarchy createFunctionNameHierarchy(std::wstring ret, std::wstring name, std::wstring parameters) const