logic: fixed filepaths to always use a canonical casing (issue #516)

* added CanonicalFilePathCache to also reserve the initially recorded casing of file names
* use canonical file path cache to resolve filepaths in names of symbols (anonymous, static, ...)
* null reference fixes
This commit is contained in:
mlangkabel
2017-11-12 16:29:12 +01:00
parent 85207c6355
commit 6488c6538e
88 changed files with 277 additions and 3151 deletions
+2 -1
View File
@@ -45,6 +45,8 @@ add_files(
data/parser/cxx/ASTActionFactory.h
data/parser/cxx/ASTConsumer.cpp
data/parser/cxx/ASTConsumer.h
data/parser/cxx/CanonicalFilePathCache.cpp
data/parser/cxx/CanonicalFilePathCache.h
data/parser/cxx/CommentHandler.cpp
data/parser/cxx/CommentHandler.h
data/parser/cxx/CxxAstVisitor.cpp
@@ -61,7 +63,6 @@ add_files(
data/parser/cxx/CxxAstVisitorComponentIndexer.h
data/parser/cxx/CxxAstVisitorComponentTypeRefKind.cpp
data/parser/cxx/CxxAstVisitorComponentTypeRefKind.h
data/parser/cxx/cxxCacheTypes.h
data/parser/cxx/CxxCompilationDatabaseSingle.cpp
data/parser/cxx/CxxCompilationDatabaseSingle.h
data/parser/cxx/CxxContext.cpp
+2 -3
View File
@@ -8,7 +8,6 @@
#include "clang/Lex/Preprocessor.h"
#include "data/parser/cxx/ASTConsumer.h"
#include "data/parser/cxx/cxxCacheTypes.h"
#include "data/parser/cxx/CommentHandler.h"
#include "data/parser/cxx/PreprocessorCallbacks.h"
#include "utility/file/FileRegister.h"
@@ -21,7 +20,7 @@ public:
explicit ASTAction(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
)
: m_client(client)
, m_fileRegister(fileRegister)
@@ -50,7 +49,7 @@ protected:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
CommentHandler m_commentHandler;
};
@@ -6,7 +6,7 @@
ASTActionFactory::ASTActionFactory(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
bool preprocessorOnly
)
: m_client(client)
@@ -3,9 +3,9 @@
#include "clang/Tooling/Tooling.h"
#include "data/parser/cxx/cxxCacheTypes.h"
#include "utility/file/FileRegister.h"
class CanonicalFilePathCache;
class ParserClient;
class ASTActionFactory
@@ -15,7 +15,7 @@ public:
explicit ASTActionFactory(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
bool preprocessorOnly
);
@@ -26,7 +26,7 @@ public:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
bool m_preprocessorOnly;
};
+1 -1
View File
@@ -9,7 +9,7 @@ ASTConsumer::ASTConsumer(
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
)
{
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
+2 -3
View File
@@ -4,8 +4,7 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "data/parser/cxx/cxxCacheTypes.h"
class CanonicalFilePathCache;
class CxxAstVisitor;
class FileRegister;
class ParserClient;
@@ -19,7 +18,7 @@ public:
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
);
virtual ~ASTConsumer();
@@ -0,0 +1,30 @@
#include "data/parser/cxx/CanonicalFilePathCache.h"
#include "utility/file/FilePath.h"
#include "utility/utilityString.h"
#include "data/parser/cxx/utilityClang.h"
FilePath CanonicalFilePathCache::getCanonicalFilePath(const clang::FileEntry* entry)
{
return getCanonicalFilePath(utility::getFileNameOfFileEntry(entry));
}
FilePath CanonicalFilePathCache::getCanonicalFilePath(const std::string& path)
{
const std::string lowercasePath = utility::toLowerCase(path);
std::unordered_map<std::string, FilePath>::const_iterator it = m_map.find(lowercasePath);
if (it != m_map.end())
{
return it->second;
}
const FilePath canonicalPath = FilePath(path).canonical();
const std::string lowercaseCanonicalPath = utility::toLowerCase(canonicalPath.str());
m_map.insert(std::make_pair(lowercasePath, canonicalPath));
m_map.insert(std::make_pair(lowercaseCanonicalPath, canonicalPath));
return canonicalPath;
}
@@ -0,0 +1,22 @@
#ifndef CANONICAL_FILE_PATH_CACHE_H
#define CANONICAL_FILE_PATH_CACHE_H
#include <string>
#include <unordered_map>
#include "clang/Basic/FileManager.h"
class FilePath;
class CanonicalFilePathCache
{
public:
FilePath getCanonicalFilePath(const clang::FileEntry* entry);
FilePath getCanonicalFilePath(const std::string& path);
private:
std::unordered_map<std::string, FilePath> m_map;
};
#endif // CANONICAL_FILE_PATH_CACHE_H
@@ -1,5 +1,6 @@
#include "data/parser/cxx/CommentHandler.h"
#include "data/parser/cxx/CanonicalFilePathCache.h"
#include "data/parser/cxx/utilityClang.h"
#include "data/parser/ParseLocation.h"
#include "data/parser/ParserClient.h"
@@ -8,7 +9,7 @@
CommentHandler::CommentHandler(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
)
: m_client(client)
, m_fileRegister(fileRegister)
@@ -29,12 +30,12 @@ bool CommentHandler::HandleComment(clang::Preprocessor& preprocessor, clang::Sou
clang::FileID fileId = sourceManager.getFileID(sourceRange.getBegin());
// find the location file
if (!fileId.isInvalid())
if (fileId.isValid())
{
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
if (fileEntry != nullptr && fileEntry->isValid())
{
FilePath filePath = m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry));
FilePath filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsIndexed(filePath))
{
m_client->onCommentParsed(ParseLocation(
+3 -4
View File
@@ -3,8 +3,7 @@
#include "clang/Lex/Preprocessor.h"
#include "data/parser/cxx/cxxCacheTypes.h"
class CanonicalFilePathCache;
class FileRegister;
class ParserClient;
@@ -15,7 +14,7 @@ public:
CommentHandler(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
);
virtual ~CommentHandler();
@@ -25,7 +24,7 @@ public:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
};
#endif // COMMENT_HANDLER_H
+24 -10
View File
@@ -6,6 +6,7 @@
#include "data/parser/cxx/name_resolver/CxxDeclNameResolver.h"
#include "data/parser/cxx/name_resolver/CxxTypeNameResolver.h"
#include "data/parser/cxx/CanonicalFilePathCache.h"
#include "data/parser/cxx/CxxAstVisitorComponent.h"
#include "data/parser/cxx/CxxAstVisitorComponentContext.h"
#include "data/parser/cxx/CxxAstVisitorComponentDeclRefKind.h"
@@ -22,7 +23,7 @@ CxxAstVisitor::CxxAstVisitor(
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
)
: m_astContext(astContext)
, m_preprocessor(preprocessor)
@@ -30,11 +31,11 @@ CxxAstVisitor::CxxAstVisitor(
, m_fileRegister(fileRegister)
, m_canonicalFilePathCache(canonicalFilePathCache)
{
m_declNameCache = std::make_shared<DeclNameCache>([](const clang::NamedDecl* decl) -> NameHierarchy
m_declNameCache = std::make_shared<DeclNameCache>([&](const clang::NamedDecl* decl) -> NameHierarchy
{
if (decl)
{
CxxDeclNameResolver resolver;
CxxDeclNameResolver resolver(m_canonicalFilePathCache);
if (std::shared_ptr<CxxDeclName> declName = resolver.getName(decl))
{
return declName->toNameHierarchy();
@@ -43,11 +44,11 @@ CxxAstVisitor::CxxAstVisitor(
return NameHierarchy("global", NAME_DELIMITER_UNKNOWN);
}
);
m_typeNameCache = std::make_shared<TypeNameCache>([](const clang::Type* type) -> NameHierarchy
m_typeNameCache = std::make_shared<TypeNameCache>([&](const clang::Type* type) -> NameHierarchy
{
if (type)
{
CxxTypeNameResolver resolver;
CxxTypeNameResolver resolver(m_canonicalFilePathCache);
if (std::shared_ptr<CxxTypeName> typeName = resolver.getName(type))
{
return typeName->toNameHierarchy();
@@ -107,7 +108,7 @@ std::shared_ptr<TypeNameCache> CxxAstVisitor::getTypeNameCache()
return m_typeNameCache;
}
std::shared_ptr<FilePathCache> CxxAstVisitor::getCanonicalFilePathCache()
std::shared_ptr<CanonicalFilePathCache> CxxAstVisitor::getCanonicalFilePathCache()
{
return m_canonicalFilePathCache;
}
@@ -657,9 +658,9 @@ ParseLocation CxxAstVisitor::getParseLocation(const clang::SourceLocation& loc)
if (!fileId.isInvalid())
{
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
if (fileEntry != nullptr && fileEntry->isValid())
{
parseLocation.filePath = m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry));
parseLocation.filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
}
}
@@ -688,14 +689,27 @@ ParseLocation CxxAstVisitor::getParseLocation(const clang::SourceRange& sourceRa
if (sourceRange.isValid())
{
const clang::SourceManager& sourceManager = m_astContext->getSourceManager();
const clang::SourceLocation endLoc = m_preprocessor->getLocForEndOfToken(sourceRange.getEnd());
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(sourceRange.getBegin(), false);
const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(endLoc.isValid() ? endLoc : sourceRange.getEnd(), false);
FilePath filePath;
{
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(sourceManager.getFileID(sourceRange.getBegin()));
if (fileEntry != nullptr && fileEntry->isValid())
{
filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
}
else
{
filePath = m_canonicalFilePathCache->getCanonicalFilePath(presumedBegin.getFilename());
}
}
parseLocation = ParseLocation(
m_canonicalFilePathCache->getValue(presumedBegin.getFilename()),
filePath,
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
+4 -4
View File
@@ -5,10 +5,10 @@
#include <clang/AST/RecursiveASTVisitor.h>
#include "data/parser/cxx/cxxCacheTypes.h"
#include "data/parser/cxx/CxxContext.h"
#include "utility/messaging/MessageInterruptTasksCounter.h"
class CanonicalFilePathCache;
class ParserClient;
struct ParseLocation;
class FileRegister;
@@ -41,7 +41,7 @@ public:
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
);
virtual ~CxxAstVisitor();
@@ -50,7 +50,7 @@ public:
std::shared_ptr<DeclNameCache> getDeclNameCache();
std::shared_ptr<TypeNameCache> getTypeNameCache();
std::shared_ptr<FilePathCache> getCanonicalFilePathCache();
std::shared_ptr<CanonicalFilePathCache> getCanonicalFilePathCache();
// Indexing entry point
void indexDecl(clang::Decl *d);
@@ -151,7 +151,7 @@ private:
clang::Preprocessor* m_preprocessor;
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
MessageInterruptTasksCounter m_interruptCounter;
@@ -5,10 +5,10 @@
#include <clang/Basic/SourceManager.h>
#include <clang/Lex/Preprocessor.h>
#include "data/parser/cxx/CanonicalFilePathCache.h"
#include "data/parser/cxx/CxxAstVisitorComponentContext.h"
#include "data/parser/cxx/CxxAstVisitorComponentDeclRefKind.h"
#include "data/parser/cxx/CxxAstVisitorComponentTypeRefKind.h"
#include "data/parser/cxx/utilityClang.h"
#include "data/parser/ParseLocation.h"
#include "data/parser/ParserClient.h"
@@ -798,19 +798,17 @@ bool CxxAstVisitorComponentIndexer::shouldVisitReference(const clang::SourceLoca
bool CxxAstVisitorComponentIndexer::isLocatedInUnparsedProjectFile(clang::SourceLocation loc)
{
clang::SourceManager& sourceManager = m_astContext->getSourceManager();
clang::SourceLocation spellingLoc = sourceManager.getSpellingLoc(loc);
const clang::SourceManager& sourceManager = m_astContext->getSourceManager();
clang::FileID fileId;
if (spellingLoc.isValid())
if (loc.isValid())
{
if (sourceManager.isWrittenInMainFile(spellingLoc))
if (sourceManager.isWrittenInMainFile(loc))
{
return true;
}
fileId = sourceManager.getFileID(spellingLoc);
fileId = sourceManager.getFileID(loc);
}
if (fileId.isValid())
@@ -823,10 +821,9 @@ bool CxxAstVisitorComponentIndexer::isLocatedInUnparsedProjectFile(clang::Source
bool ret = false;
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
if (fileEntry != nullptr && fileEntry->isValid())
{
FilePath filePath =
getAstVisitor()->getCanonicalFilePathCache()->getValue(utility::getFileNameOfFileEntry(fileEntry));
FilePath filePath = getAstVisitor()->getCanonicalFilePathCache()->getCanonicalFilePath(fileEntry);
if (m_fileRegister->hasFilePath(filePath))
{
@@ -843,14 +840,13 @@ bool CxxAstVisitorComponentIndexer::isLocatedInUnparsedProjectFile(clang::Source
bool CxxAstVisitorComponentIndexer::isLocatedInProjectFile(clang::SourceLocation loc)
{
clang::SourceManager& sourceManager = m_astContext->getSourceManager();
clang::SourceLocation spellingLoc = sourceManager.getSpellingLoc(loc);
const clang::SourceManager& sourceManager = m_astContext->getSourceManager();
clang::FileID fileId;
if (spellingLoc.isValid())
if (loc.isValid())
{
fileId = sourceManager.getFileID(spellingLoc);
fileId = sourceManager.getFileID(loc);
}
if (!fileId.isInvalid())
@@ -862,10 +858,9 @@ bool CxxAstVisitorComponentIndexer::isLocatedInProjectFile(clang::SourceLocation
}
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
if (fileEntry != nullptr && fileEntry->isValid())
{
FilePath filePath =
getAstVisitor()->getCanonicalFilePathCache()->getValue(utility::getFileNameOfFileEntry(fileEntry));
FilePath filePath = getAstVisitor()->getCanonicalFilePathCache()->getCanonicalFilePath(fileEntry);
bool ret = m_fileRegister->hasFilePath(filePath);
m_inProjectFileMap[fileId] = ret;
return ret;
@@ -3,6 +3,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Tooling/Tooling.h"
#include "data/parser/cxx/CanonicalFilePathCache.h"
#include "data/parser/cxx/utilityClang.h"
#include "data/parser/ParseLocation.h"
#include "data/parser/ParserClient.h"
@@ -13,7 +14,7 @@ CxxDiagnosticConsumer::CxxDiagnosticConsumer(
clang::DiagnosticOptions *diags,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
bool useLogging
)
: clang::TextDiagnosticPrinter(os, diags)
@@ -68,7 +69,7 @@ void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level lev
return;
}
std::string filePath;
FilePath filePath;
uint line = 0;
uint column = 0;
@@ -81,14 +82,14 @@ void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level lev
column = presumedLocation.getColumn();
}
const clang::FileEntry *fileEntry = sourceManager.getFileEntryForID(sourceManager.getFileID(info.getLocation()));
if (fileEntry)
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(sourceManager.getFileID(info.getLocation()));
if (fileEntry != nullptr && fileEntry->isValid())
{
filePath = m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry)).str();
filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
}
}
ParseLocation location(m_canonicalFilePathCache->getValue(filePath), line, column);
ParseLocation location(filePath, line, column);
m_client->onErrorParsed(
location,
@@ -3,8 +3,7 @@
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "data/parser/cxx/cxxCacheTypes.h"
class CanonicalFilePathCache;
class FileRegister;
class ParserClient;
@@ -17,7 +16,7 @@ public:
clang::DiagnosticOptions *diags,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
bool useLogging = true
);
@@ -31,7 +30,7 @@ public:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_register;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
std::string m_commandline;
+4 -11
View File
@@ -10,6 +10,7 @@
#include "data/indexer/IndexerCommandCxxCdb.h"
#include "data/indexer/IndexerCommandCxxManual.h"
#include "data/parser/cxx/ASTActionFactory.h"
#include "data/parser/cxx/CanonicalFilePathCache.h"
#include "data/parser/cxx/CxxCompilationDatabaseSingle.h"
#include "data/parser/cxx/CxxDiagnosticConsumer.h"
@@ -91,11 +92,7 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxManual> indexerComma
void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent)
{
std::shared_ptr<FilePathCache> canonicalFilePathCache = std::make_shared<FilePathCache>([](std::string fileName) -> FilePath
{
return FilePath(fileName).canonical();
}
);
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache = std::make_shared<CanonicalFilePathCache>();
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, false);
ASTActionFactory actionFactory(m_client, m_fileRegister, canonicalFilePathCache, false);
@@ -115,11 +112,7 @@ void CxxParser::runTool(clang::tooling::CompilationDatabase* compilationDatabase
{
clang::tooling::ClangTool tool(*compilationDatabase, std::vector<std::string>(1, sourceFilePath.str()));
std::shared_ptr<FilePathCache> canonicalFilePathCache = std::make_shared<FilePathCache>([](std::string fileName) -> FilePath
{
return FilePath(fileName).canonical();
}
);
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache = std::make_shared<CanonicalFilePathCache>();
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, true);
@@ -225,7 +218,7 @@ std::shared_ptr<clang::tooling::FixedCompilationDatabase> CxxParser::getCompilat
return compilationDatabase;
}
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(std::shared_ptr<FilePathCache> canonicalFilePathCache, bool logErrors) const
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache, bool logErrors) const
{
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
return std::make_shared<CxxDiagnosticConsumer>(
+2 -2
View File
@@ -1,9 +1,9 @@
#ifndef CXX_PARSER_H
#define CXX_PARSER_H
#include "data/parser/cxx/cxxCacheTypes.h"
#include "data/parser/Parser.h"
class CanonicalFilePathCache;
class CxxDiagnosticConsumer;
class FilePath;
class FileRegister;
@@ -38,7 +38,7 @@ private:
std::vector<std::string> getCommandlineArguments(std::shared_ptr<IndexerCommandCxxManual> indexerCommand) const;
std::shared_ptr<clang::tooling::FixedCompilationDatabase> getCompilationDatabase(std::shared_ptr<IndexerCommandCxxManual> indexerCommand) const;
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(std::shared_ptr<FilePathCache> canonicalFilePathCache, bool logErrors) const;
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache, bool logErrors) const;
friend class TaskParseCxx;
@@ -17,7 +17,7 @@ CxxVerboseAstVisitor::CxxVerboseAstVisitor(
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
)
: base(context, preprocessor, client, fileRegister, canonicalFilePathCache)
, m_currentFilePath("")
@@ -5,6 +5,7 @@
#include "data/parser/cxx/CxxAstVisitor.h"
class CanonicalFilePathCache;
class ParserClient;
class FileRegister;
@@ -16,7 +17,7 @@ public:
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
);
virtual ~CxxVerboseAstVisitor();
@@ -4,18 +4,19 @@
#include "clang/Basic/IdentifierTable.h"
#include "clang/Lex/MacroArgs.h"
#include "utility/file/FileSystem.h"
#include "utility/file/FileRegister.h"
#include "data/parser/cxx/CanonicalFilePathCache.h"
#include "data/parser/cxx/utilityClang.h"
#include "data/parser/ParserClient.h"
#include "data/parser/ParseLocation.h"
#include "utility/file/FileSystem.h"
#include "utility/file/FileRegister.h"
PreprocessorCallbacks::PreprocessorCallbacks(
clang::SourceManager& sourceManager,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
)
: m_sourceManager(sourceManager)
, m_client(client)
@@ -31,10 +32,10 @@ void PreprocessorCallbacks::FileChanged(
FilePath filePath;
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry)
const clang::FileEntry* fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry != nullptr && fileEntry->isValid())
{
filePath = m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry));
filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
}
if (!filePath.empty() && m_fileRegister->hasFilePath(filePath))
@@ -60,7 +61,7 @@ void PreprocessorCallbacks::InclusionDirective(
){
if (!m_currentPath.empty() && fileEntry)
{
FilePath includedFilePath = m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry));
FilePath includedFilePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
if (m_fileRegister->hasFilePath(includedFilePath))
{
const NameHierarchy referencedNameHierarchy(includedFilePath.str(), NAME_DELIMITER_FILE);
@@ -152,11 +153,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());
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry)
const clang::FileEntry* fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry != nullptr && fileEntry->isValid())
{
return ParseLocation(
m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry)),
m_canonicalFilePathCache->getCanonicalFilePath(fileEntry),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
@@ -172,11 +173,11 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::MacroInfo* ma
clang::SourceLocation location = macroInfo->getDefinitionLoc();
clang::SourceLocation endLocation = macroInfo->getDefinitionEndLoc();
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry)
const clang::FileEntry* fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry != nullptr && fileEntry->isValid())
{
return ParseLocation(
m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry)),
m_canonicalFilePathCache->getCanonicalFilePath(fileEntry),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
@@ -195,10 +196,10 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::SourceRange&
const clang::PresumedLoc& presumedEnd = m_sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(sourceRange.getBegin()));
if (fileEntry)
if (fileEntry != nullptr && fileEntry->isValid())
{
return ParseLocation(
m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry)),
m_canonicalFilePathCache->getCanonicalFilePath(fileEntry),
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
@@ -211,16 +212,16 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::SourceRange&
bool PreprocessorCallbacks::isLocatedInProjectFile(const clang::SourceLocation loc)
{
// we need the spelling loc here, since this is the location where the macro comes from
clang::SourceLocation spellingLoc = m_sourceManager.getSpellingLoc(loc);
clang::FileID fileId;
if (spellingLoc.isValid())
{
fileId = m_sourceManager.getFileID(spellingLoc);
}
if (!fileId.isInvalid())
if (fileId.isValid())
{
auto it = m_inProjectFileMap.find(fileId);
if (it != m_inProjectFileMap.end())
@@ -229,10 +230,9 @@ bool PreprocessorCallbacks::isLocatedInProjectFile(const clang::SourceLocation l
}
const clang::FileEntry* fileEntry = m_sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
if (fileEntry != nullptr && fileEntry->isValid())
{
FilePath filePath =
m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry));
const FilePath filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry);
bool ret = m_fileRegister->hasFilePath(filePath);
m_inProjectFileMap[fileId] = ret;
return ret;
@@ -2,15 +2,16 @@
#define PREPROCESSOR_CALLBACKS_H
#include <memory>
#include <unordered_map>
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Token.h"
#include "data/parser/cxx/cxxCacheTypes.h"
#include "utility/file/FilePath.h"
class CanonicalFilePathCache;
class FileRegister;
class ParserClient;
@@ -24,7 +25,7 @@ public:
clang::SourceManager& sourceManager,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache);
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache);
virtual void FileChanged(
clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID) override;
@@ -71,7 +72,7 @@ private:
const clang::SourceManager& m_sourceManager;
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
std::unordered_map<const clang::FileID, bool, FileIdHash> m_inProjectFileMap;
FilePath m_currentPath;
@@ -1,11 +0,0 @@
#ifndef CXX_CACHE_TYPES_H
#define CXX_CACHE_TYPES_H
#include <string>
#include "utility/Cache.h"
class FilePath;
typedef Cache<std::string, FilePath> FilePathCache;
#endif // CXX_CACHE_TYPES_H
@@ -9,18 +9,23 @@
#include "data/parser/cxx/name_resolver/CxxSpecifierNameResolver.h"
#include "data/parser/cxx/name_resolver/CxxTemplateArgumentNameResolver.h"
#include "data/parser/cxx/name_resolver/CxxTypeNameResolver.h"
#include "data/parser/cxx/CanonicalFilePathCache.h"
#include "data/parser/cxx/utilityClang.h"
#include "utility/file/FilePath.h"
#include "utility/ScopedSwitcher.h"
#include "utility/utilityString.h"
CxxDeclNameResolver::CxxDeclNameResolver()
: CxxNameResolver(std::vector<const clang::Decl*>())
CxxDeclNameResolver::CxxDeclNameResolver(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache)
: CxxNameResolver(canonicalFilePathCache, std::vector<const clang::Decl*>())
, m_currentDecl(nullptr)
{
}
CxxDeclNameResolver::CxxDeclNameResolver(std::vector<const clang::Decl*> ignoredContextDecls)
: CxxNameResolver(ignoredContextDecls)
CxxDeclNameResolver::CxxDeclNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
)
: CxxNameResolver(canonicalFilePathCache, ignoredContextDecls)
, m_currentDecl(nullptr)
{
}
@@ -69,7 +74,7 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getName(const clang::NamedDecl
{
if (const clang::UsingDecl* usingDecl = clang::dyn_cast_or_null<clang::UsingDecl>(declaration))
{
CxxSpecifierNameResolver specifierNameResolver(getIgnoredContextDecls());
CxxSpecifierNameResolver specifierNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
declName->setParent(specifierNameResolver.getName(usingDecl->getQualifier()));
}
else
@@ -127,9 +132,6 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
}
else if (declNameString.empty())
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
std::string symbolKindName = "class";
if (recordDecl->isStruct())
{
@@ -140,7 +142,7 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
symbolKindName = "union";
}
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol(symbolKindName, presumedBegin), std::vector<std::string>());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol(symbolKindName, declaration), std::vector<std::string>());
}
else if (const clang::CXXRecordDecl* cxxRecordDecl = clang::dyn_cast_or_null<clang::CXXRecordDecl>(declaration))
{
@@ -244,7 +246,7 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
isStatic = functionDecl->getStorageClass() == clang::SC_Static;
}
CxxTypeNameResolver typenNameResolver(getIgnoredContextDecls());
CxxTypeNameResolver typenNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
typenNameResolver.ignoreContextDecl(functionDecl);
std::shared_ptr<CxxTypeName> returnTypeName = CxxTypeName::makeUnsolvedIfNull(typenNameResolver.getName(functionDecl->getReturnType()));
@@ -261,7 +263,7 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
templateArguments,
returnTypeName,
parameterTypeNames,
getTranslationUnitMainFilePath(declaration).fileName()
getTranslationUnitMainFileName(declaration)
);
}
@@ -287,22 +289,18 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
else if (clang::isa<clang::FieldDecl>(declaration))
{
const clang::FieldDecl* fieldDecl = clang::dyn_cast<clang::FieldDecl>(declaration);
CxxTypeNameResolver typenNameResolver(getIgnoredContextDecls());
CxxTypeNameResolver typenNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
typenNameResolver.ignoreContextDecl(fieldDecl);
std::shared_ptr<CxxTypeName> typeName = CxxTypeName::makeUnsolvedIfNull(typenNameResolver.getName(fieldDecl->getType()));
return std::make_shared<CxxVariableDeclName>(declNameString, std::vector<std::string>(), typeName, false);
}
else if (clang::isa<clang::NamespaceDecl>(declaration) && clang::dyn_cast<clang::NamespaceDecl>(declaration)->isAnonymousNamespace())
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("namespace", presumedBegin), std::vector<std::string>());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("namespace", declaration), std::vector<std::string>());
}
else if (clang::isa<clang::EnumDecl>(declaration) && declNameString.empty())
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("enum", presumedBegin), std::vector<std::string>());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("enum", declaration), std::vector<std::string>());
}
else if (
(
@@ -311,15 +309,11 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
clang::isa<clang::TemplateTemplateParmDecl>(declaration)
) && declNameString.empty())
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("template parameter", presumedBegin), std::vector<std::string>());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("template parameter", declaration), std::vector<std::string>());
}
else if (clang::isa<clang::ParmVarDecl>(declaration) && declNameString.empty())
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("parameter", presumedBegin), std::vector<std::string>());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("parameter", declaration), std::vector<std::string>());
}
else if (clang::isa<clang::VarDecl>(declaration))
{
@@ -337,7 +331,7 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
// nothing todo, varDecl is global (and non-static)
}
CxxTypeNameResolver typenNameResolver(getIgnoredContextDecls());
CxxTypeNameResolver typenNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
typenNameResolver.ignoreContextDecl(varDecl);
std::shared_ptr<CxxTypeName> typeName = CxxTypeName::makeUnsolvedIfNull(typenNameResolver.getName(varDecl->getType()));
@@ -353,11 +347,11 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
{
if (varDecl->getType().isConstQualified())
{
scopeFileName = getDeclarationFilePath(declaration).fileName();
scopeFileName = getDeclarationFileName(declaration);
}
else
{
scopeFileName = getTranslationUnitMainFilePath(declaration).fileName();
scopeFileName = getTranslationUnitMainFileName(declaration);
}
}
if (!scopeFileName.empty())
@@ -376,37 +370,42 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
}
}
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
// LOG_ERROR("could not resolve name of decl at: " + declaration->getLocation().printToString(sourceManager));
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("symbol", presumedBegin), std::vector<std::string>());
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("symbol", declaration), std::vector<std::string>());
}
FilePath CxxDeclNameResolver::getTranslationUnitMainFilePath(const clang::Decl* declaration)
std::string CxxDeclNameResolver::getTranslationUnitMainFileName(const clang::Decl* declaration)
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
clang::FileID fileId = sourceManager.getMainFileID();
if (fileId.isValid())
{
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
return FilePath(utility::getFileNameOfFileEntry(fileEntry));
return getCanonicalFilePathCache()->getCanonicalFilePath(fileEntry).fileName();
}
return FilePath();
return "";
}
FilePath CxxDeclNameResolver::getDeclarationFilePath(const clang::Decl* declaration)
std::string CxxDeclNameResolver::getDeclarationFileName(const clang::Decl* declaration)
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(sourceManager.getFileID(declaration->getLocStart()));
if (fileEntry != nullptr && fileEntry->isValid())
{
return getCanonicalFilePathCache()->getCanonicalFilePath(fileEntry).fileName();
}
return getCanonicalFilePathCache()->getCanonicalFilePath(sourceManager.getPresumedLoc(declaration->getLocStart()).getFilename()).fileName();
}
std::string CxxDeclNameResolver::getNameForAnonymousSymbol(const std::string& symbolKindName, const clang::Decl* declaration)
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
return FilePath(presumedBegin.getFilename());
}
std::string CxxDeclNameResolver::getNameForAnonymousSymbol(const std::string& symbolKindName, const clang::PresumedLoc& presumedBegin)
{
if (presumedBegin.isValid())
{
return "anonymous " + symbolKindName +
" (" + FilePath(presumedBegin.getFilename()).fileName() + "<" + std::to_string(presumedBegin.getLine()) + ":" + std::to_string(presumedBegin.getColumn()) + ">)";
" (" + getDeclarationFileName(declaration) + "<" + std::to_string(presumedBegin.getLine()) + ":" + std::to_string(presumedBegin.getColumn()) + ">)";
}
return "anonymous " + symbolKindName;
}
@@ -445,7 +444,7 @@ std::string CxxDeclNameResolver::getTemplateParameterString(const clang::NamedDe
std::string CxxDeclNameResolver::getTemplateParameterTypeString(const clang::NonTypeTemplateParmDecl* parameter)
{
CxxTypeNameResolver typeNameResolver(getIgnoredContextDecls());
CxxTypeNameResolver typeNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
if (clang::isa<clang::TemplateDecl>(m_currentDecl))
{
@@ -500,6 +499,6 @@ std::string CxxDeclNameResolver::getTemplateParameterTypeString(const clang::Tem
std::string CxxDeclNameResolver::getTemplateArgumentName(const clang::TemplateArgument& argument)
{
CxxTemplateArgumentNameResolver resolver(getIgnoredContextDecls());
CxxTemplateArgumentNameResolver resolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
return resolver.getTemplateArgumentName(argument);
}
@@ -4,13 +4,17 @@
#include "data/parser/cxx/name/CxxDeclName.h"
#include "data/parser/cxx/name_resolver/CxxNameResolver.h"
class CanonicalFilePathCache;
class FilePath;
class CxxDeclNameResolver: public CxxNameResolver
{
public:
CxxDeclNameResolver();
CxxDeclNameResolver(std::vector<const clang::Decl*> ignoredContextDecls);
CxxDeclNameResolver(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache);
CxxDeclNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
);
virtual ~CxxDeclNameResolver();
std::shared_ptr<CxxDeclName> getName(const clang::NamedDecl* declaration);
@@ -18,9 +22,9 @@ public:
private:
std::shared_ptr<CxxName> getContextName(const clang::DeclContext* declaration);
std::shared_ptr<CxxDeclName> getDeclName(const clang::NamedDecl* declaration);
FilePath getTranslationUnitMainFilePath(const clang::Decl* declaration);
FilePath getDeclarationFilePath(const clang::Decl* declaration);
std::string getNameForAnonymousSymbol(const std::string& symbolKindName, const clang::PresumedLoc& presumedBegin);
std::string getTranslationUnitMainFileName(const clang::Decl* declaration);
std::string getDeclarationFileName(const clang::Decl* declaration);
std::string getNameForAnonymousSymbol(const std::string& symbolKindName, const clang::Decl* declaration);
std::string getTemplateParameterString(const clang::NamedDecl* parameter);
std::string getTemplateParameterTypeString(const clang::NonTypeTemplateParmDecl* parameter);
std::string getTemplateParameterTypeString(const clang::TemplateTypeParmDecl* parameter);
@@ -1,7 +1,11 @@
#include "data/parser/cxx/name_resolver/CxxNameResolver.h"
CxxNameResolver::CxxNameResolver(std::vector<const clang::Decl*> ignoredContextDecls)
: m_ignoredContextDecls(ignoredContextDecls)
CxxNameResolver::CxxNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
)
: m_canonicalFilePathCache(canonicalFilePathCache)
, m_ignoredContextDecls(ignoredContextDecls)
{
}
@@ -30,6 +34,11 @@ bool CxxNameResolver::ignoresContext(const clang::DeclContext* declContext)
return false;
}
std::shared_ptr<CanonicalFilePathCache> CxxNameResolver::getCanonicalFilePathCache() const
{
return m_canonicalFilePathCache;
}
std::vector<const clang::Decl*> CxxNameResolver::getIgnoredContextDecls() const
{
return m_ignoredContextDecls;
@@ -3,21 +3,28 @@
#include <vector>
#include "clang/AST/Decl.h"
#include <clang/AST/Decl.h>
class CanonicalFilePathCache;
class CxxNameResolver
{
public:
CxxNameResolver(std::vector<const clang::Decl*> ignoredContextDecls);
CxxNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
);
virtual ~CxxNameResolver();
void ignoreContextDecl(const clang::Decl* decl);
bool ignoresContext(const clang::DeclContext* declContext);
protected:
std::shared_ptr<CanonicalFilePathCache> getCanonicalFilePathCache() const;
std::vector<const clang::Decl*> getIgnoredContextDecls() const;
private:
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
std::vector<const clang::Decl*> m_ignoredContextDecls;
};
@@ -7,13 +7,16 @@
#include "data/parser/cxx/name_resolver/CxxTypeNameResolver.h"
#include "data/parser/cxx/name_resolver/CxxDeclNameResolver.h"
CxxSpecifierNameResolver::CxxSpecifierNameResolver()
: CxxNameResolver(std::vector<const clang::Decl*>())
CxxSpecifierNameResolver::CxxSpecifierNameResolver(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache)
: CxxNameResolver(canonicalFilePathCache, std::vector<const clang::Decl*>())
{
}
CxxSpecifierNameResolver::CxxSpecifierNameResolver(std::vector<const clang::Decl*> ignoredContextDecls)
: CxxNameResolver(ignoredContextDecls)
CxxSpecifierNameResolver::CxxSpecifierNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
)
: CxxNameResolver(canonicalFilePathCache, ignoredContextDecls)
{
}
@@ -48,20 +51,20 @@ std::shared_ptr<CxxName> CxxSpecifierNameResolver::getName(const clang::NestedNa
break;
case clang::NestedNameSpecifier::Namespace:
{
CxxDeclNameResolver declNameResolver(getIgnoredContextDecls());
CxxDeclNameResolver declNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
name = declNameResolver.getName(nestedNameSpecifier->getAsNamespace());
}
break;
case clang::NestedNameSpecifier::NamespaceAlias:
{
CxxDeclNameResolver declNameResolver(getIgnoredContextDecls());
CxxDeclNameResolver declNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
name = declNameResolver.getName(nestedNameSpecifier->getAsNamespaceAlias());
}
break;
case clang::NestedNameSpecifier::TypeSpec:
case clang::NestedNameSpecifier::TypeSpecWithTemplate:
{
CxxTypeNameResolver typeNameResolver(getIgnoredContextDecls());
CxxTypeNameResolver typeNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
name = CxxTypeName::makeUnsolvedIfNull(typeNameResolver.getName(nestedNameSpecifier->getAsType()));
}
break;
@@ -70,7 +73,7 @@ std::shared_ptr<CxxName> CxxSpecifierNameResolver::getName(const clang::NestedNa
break;
case clang::NestedNameSpecifier::Super:
{
CxxDeclNameResolver declNameResolver(getIgnoredContextDecls());
CxxDeclNameResolver declNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
name = declNameResolver.getName(nestedNameSpecifier->getAsRecordDecl());
}
break;
@@ -10,8 +10,11 @@ class CxxName;
class CxxSpecifierNameResolver: public CxxNameResolver
{
public:
CxxSpecifierNameResolver();
CxxSpecifierNameResolver(std::vector<const clang::Decl*> ignoredContextDecls);
CxxSpecifierNameResolver(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache);
CxxSpecifierNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
);
virtual ~CxxSpecifierNameResolver();
std::shared_ptr<CxxName> getName(const clang::NestedNameSpecifier* nestedNameSpecifier);
@@ -5,13 +5,16 @@
#include "data/parser/cxx/name_resolver/CxxTypeNameResolver.h"
CxxTemplateArgumentNameResolver::CxxTemplateArgumentNameResolver()
: CxxNameResolver(std::vector<const clang::Decl*>())
CxxTemplateArgumentNameResolver::CxxTemplateArgumentNameResolver(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache)
: CxxNameResolver(canonicalFilePathCache, std::vector<const clang::Decl*>())
{
}
CxxTemplateArgumentNameResolver::CxxTemplateArgumentNameResolver(std::vector<const clang::Decl*> ignoredContextDecls)
: CxxNameResolver(ignoredContextDecls)
CxxTemplateArgumentNameResolver::CxxTemplateArgumentNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
)
: CxxNameResolver(canonicalFilePathCache, ignoredContextDecls)
{
}
@@ -28,7 +31,7 @@ std::string CxxTemplateArgumentNameResolver::getTemplateArgumentName(const clang
{
case clang::TemplateArgument::Type:
{
CxxTypeNameResolver typeNameResolver(getIgnoredContextDecls());
CxxTypeNameResolver typeNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
std::shared_ptr<CxxTypeName> typeName = CxxTypeName::makeUnsolvedIfNull(typeNameResolver.getName(argument.getAsType()));
return typeName->toString();
}
@@ -10,8 +10,11 @@ class DataType;
class CxxTemplateArgumentNameResolver: public CxxNameResolver
{
public:
CxxTemplateArgumentNameResolver();
CxxTemplateArgumentNameResolver(std::vector<const clang::Decl*> ignoredContextDecls);
CxxTemplateArgumentNameResolver(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache);
CxxTemplateArgumentNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
);
virtual ~CxxTemplateArgumentNameResolver();
std::string getTemplateArgumentName(const clang::TemplateArgument& argument);
@@ -9,13 +9,16 @@
#include "data/parser/cxx/name_resolver/CxxTemplateArgumentNameResolver.h"
#include "utility/logging/logging.h"
CxxTypeNameResolver::CxxTypeNameResolver()
: CxxNameResolver(std::vector<const clang::Decl*>())
CxxTypeNameResolver::CxxTypeNameResolver(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache)
: CxxNameResolver(canonicalFilePathCache, std::vector<const clang::Decl*>())
{
}
CxxTypeNameResolver::CxxTypeNameResolver(std::vector<const clang::Decl*> ignoredContextDecls)
: CxxNameResolver(ignoredContextDecls)
CxxTypeNameResolver::CxxTypeNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
)
: CxxNameResolver(canonicalFilePathCache, ignoredContextDecls)
{
}
@@ -58,7 +61,7 @@ std::shared_ptr<CxxTypeName> CxxTypeNameResolver::getName(const clang::Type* typ
}
case clang::Type::Typedef:
{
CxxDeclNameResolver declNameResolver(getIgnoredContextDecls());
CxxDeclNameResolver declNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
std::shared_ptr<CxxDeclName> declName = declNameResolver.getName(type->getAs<clang::TypedefType>()->getDecl());
if (declName)
{
@@ -118,7 +121,7 @@ std::shared_ptr<CxxTypeName> CxxTypeNameResolver::getName(const clang::Type* typ
case clang::Type::Enum:
case clang::Type::Record:
{
CxxDeclNameResolver declNameResolver(getIgnoredContextDecls());
CxxDeclNameResolver declNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
std::shared_ptr<CxxDeclName> declName = declNameResolver.getName(type->getAs<clang::TagType>()->getDecl());
if (declName)
{
@@ -146,7 +149,7 @@ std::shared_ptr<CxxTypeName> CxxTypeNameResolver::getName(const clang::Type* typ
const clang::TagType* tagType = type->getAs<clang::TagType>(); // remove this case when NameHierarchy is split into namepart and parameter part
if (tagType)
{
CxxDeclNameResolver declNameResolver(getIgnoredContextDecls());
CxxDeclNameResolver declNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
std::shared_ptr<CxxDeclName> declName = declNameResolver.getName(tagType->getDecl());
if (declName)
{
@@ -160,13 +163,13 @@ std::shared_ptr<CxxTypeName> CxxTypeNameResolver::getName(const clang::Type* typ
else // specialization of a template template parameter (no concrete class) important, may help: has no underlying decl!
{
const clang::TemplateSpecializationType* templateSpecializationType = type->getAs<clang::TemplateSpecializationType>();
CxxDeclNameResolver declNameResolver(getIgnoredContextDecls());
CxxDeclNameResolver declNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
const std::shared_ptr<CxxDeclName> declName = declNameResolver.getName(templateSpecializationType->getTemplateName().getAsTemplateDecl());
if (declName)
{
std::vector<std::string> templateArguments;
CxxTemplateArgumentNameResolver resolver(getIgnoredContextDecls());
CxxTemplateArgumentNameResolver resolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
resolver.ignoreContextDecl(templateSpecializationType->getTemplateName().getAsTemplateDecl()->getTemplatedDecl());
for (size_t i = 0; i < templateSpecializationType->getNumArgs(); i++)
{
@@ -188,7 +191,7 @@ std::shared_ptr<CxxTypeName> CxxTypeNameResolver::getName(const clang::Type* typ
}
case clang::Type::TemplateTypeParm:
{
CxxDeclNameResolver declNameResolver(getIgnoredContextDecls());
CxxDeclNameResolver declNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
std::shared_ptr<CxxDeclName> declName = declNameResolver.getName(clang::dyn_cast<clang::TemplateTypeParmType>(type)->getDecl());
if (declName)
{
@@ -209,7 +212,7 @@ std::shared_ptr<CxxTypeName> CxxTypeNameResolver::getName(const clang::Type* typ
{
const clang::DependentNameType* dependentType = clang::dyn_cast<clang::DependentNameType>(type);
CxxSpecifierNameResolver specifierNameResolver(getIgnoredContextDecls());
CxxSpecifierNameResolver specifierNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
std::shared_ptr<CxxName> specifierName = specifierNameResolver.getName(dependentType->getQualifier());
typeName = std::make_shared<CxxTypeName>(
@@ -221,11 +224,11 @@ std::shared_ptr<CxxTypeName> CxxTypeNameResolver::getName(const clang::Type* typ
{
const clang::DependentTemplateSpecializationType* dependentType = clang::dyn_cast<clang::DependentTemplateSpecializationType>(type);
CxxSpecifierNameResolver specifierNameResolver(getIgnoredContextDecls());
CxxSpecifierNameResolver specifierNameResolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
std::shared_ptr<CxxName> specifierName = specifierNameResolver.getName(dependentType->getQualifier());
std::vector<std::string> templateArguments;
CxxTemplateArgumentNameResolver resolver(getIgnoredContextDecls());
CxxTemplateArgumentNameResolver resolver(getCanonicalFilePathCache(), getIgnoredContextDecls());
for (size_t i = 0; i < dependentType->getNumArgs(); i++)
{
templateArguments.push_back(resolver.getTemplateArgumentName(dependentType->getArg(i)));
@@ -7,8 +7,11 @@
class CxxTypeNameResolver: public CxxNameResolver
{
public:
CxxTypeNameResolver();
CxxTypeNameResolver(std::vector<const clang::Decl*> ignoredContextDecls);
CxxTypeNameResolver(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache);
CxxTypeNameResolver(
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::vector<const clang::Decl*> ignoredContextDecls
);
virtual ~CxxTypeNameResolver();
std::shared_ptr<CxxTypeName> getName(const clang::QualType& qualType);
+1 -1
View File
@@ -111,7 +111,7 @@ SymbolKind utility::getSymbolKind(const clang::VarDecl* d)
std::string utility::getFileNameOfFileEntry(const clang::FileEntry* entry)
{
std::string fileName = "";
if (entry)
if (entry != nullptr && entry->isValid())
{
fileName = entry->tryGetRealPathName();
if (fileName.empty())