forked from qt-creator/qt-creator
ClangRefactoring: Improve symbol parsing
Declarations are only indexed if their file has been changed and references has to be indexed if the file or any included file has been changed. Change-Id: I07c6de1379bce2462c1e0fad34d4378a3da4397b Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -75,7 +75,7 @@ private:
|
||||
clang::index::IndexingOptions options;
|
||||
|
||||
options.SystemSymbolFilter = clang::index::IndexingOptions::SystemSymbolFilterKind::None;
|
||||
options.IndexFunctionLocals = false;
|
||||
options.IndexFunctionLocals = true;
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -99,11 +99,29 @@ SymbolKindAndTags symbolKindAndTags(const clang::Decl *declaration)
|
||||
return visitor.Visit(declaration);
|
||||
}
|
||||
|
||||
bool isContextIndependentDeclaration(const clang::Decl *declaration)
|
||||
bool isDeclaration(clang::index::SymbolRoleSet symbolRoles)
|
||||
{
|
||||
return clang::dyn_cast<clang::ValueDecl>(declaration)
|
||||
|| clang::dyn_cast<clang::TypeDecl>(declaration);
|
||||
using namespace clang::index;
|
||||
|
||||
return symbolRoles & (uint(SymbolRole::Declaration) | uint(SymbolRole::Definition));
|
||||
}
|
||||
|
||||
bool isReference(clang::index::SymbolRoleSet symbolRoles)
|
||||
{
|
||||
using namespace clang::index;
|
||||
|
||||
return symbolRoles & (uint(SymbolRole::Reference) | uint(SymbolRole::Call));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool IndexDataConsumer::skipSymbol(clang::FileID fileId, clang::index::SymbolRoleSet symbolRoles)
|
||||
{
|
||||
bool alreadyParsed = isAlreadyParsed(fileId);
|
||||
bool isParsedDeclaration = alreadyParsed && isDeclaration(symbolRoles);
|
||||
bool isParsedReference = alreadyParsed && !dependentFilesAreModified() && isReference(symbolRoles);
|
||||
|
||||
return isParsedDeclaration || isParsedReference;
|
||||
}
|
||||
|
||||
bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration,
|
||||
@@ -118,7 +136,7 @@ bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration,
|
||||
if (!namedDeclaration->getIdentifier())
|
||||
return true;
|
||||
|
||||
if (alreadyParsed(fileId) && isContextIndependentDeclaration(declaration))
|
||||
if (skipSymbol(fileId, symbolRoles))
|
||||
return true;
|
||||
|
||||
SymbolIndex globalId = toSymbolIndex(declaration->getCanonicalDecl());
|
||||
|
||||
@@ -59,6 +59,9 @@ public:
|
||||
unsigned offset,
|
||||
ASTNodeInfo astNodeInfo) override;
|
||||
|
||||
private:
|
||||
bool skipSymbol(clang::FileID fileId, clang::index::SymbolRoleSet symbolRoles);
|
||||
|
||||
private:
|
||||
SymbolEntries &m_symbolEntries;
|
||||
SourceLocationEntries &m_sourceLocationEntries;
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
if (!upToDate)
|
||||
addOrUpdateNewEntry(filePathId, modifiedTime);
|
||||
|
||||
m_dependendFilesModified = m_dependendFilesModified || !upToDate;
|
||||
m_dependentFilesModified = m_dependentFilesModified || !upToDate;
|
||||
|
||||
return upToDate ;
|
||||
}
|
||||
@@ -82,17 +82,17 @@ public:
|
||||
|
||||
m_modifiedTimeStamps = std::move(mergedModifiedTimeStamps);
|
||||
m_newModifiedTimeStamps.clear();
|
||||
m_dependendFilesModified = false;
|
||||
m_dependentFilesModified = false;
|
||||
}
|
||||
|
||||
bool dependendFilesModified() const
|
||||
bool dependentFilesModified() const
|
||||
{
|
||||
return m_dependendFilesModified;
|
||||
return m_dependentFilesModified;
|
||||
}
|
||||
|
||||
bool alreadyParsedAllDependFiles(FilePathId filePathId, std::time_t modifiedTime)
|
||||
bool alreadyParsedAllDependentFiles(FilePathId filePathId, std::time_t modifiedTime)
|
||||
{
|
||||
return alreadyParsed(filePathId, modifiedTime) && !dependendFilesModified();
|
||||
return alreadyParsed(filePathId, modifiedTime) && !dependentFilesModified();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -114,7 +114,7 @@ private:
|
||||
private:
|
||||
std::vector<FilePathIdTime> m_modifiedTimeStamps;
|
||||
std::vector<FilePathIdTime> m_newModifiedTimeStamps;
|
||||
bool m_dependendFilesModified = false;
|
||||
bool m_dependentFilesModified = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ void SymbolsCollector::addUnsavedFiles(const V2::FileContainers &unsavedFiles)
|
||||
|
||||
void SymbolsCollector::clear()
|
||||
{
|
||||
m_indexDataConsumer->clear();
|
||||
m_collectMacrosSourceFileCallbacks.clear();
|
||||
m_symbolEntries.clear();
|
||||
m_sourceLocationEntries.clear();
|
||||
|
||||
@@ -60,7 +60,12 @@ public:
|
||||
return filePathId(fileEntry);
|
||||
}
|
||||
|
||||
bool alreadyParsed(clang::FileID fileId)
|
||||
bool dependentFilesAreModified()
|
||||
{
|
||||
return m_sourcesManager.dependentFilesModified();
|
||||
}
|
||||
|
||||
bool isAlreadyParsed(clang::FileID fileId)
|
||||
{
|
||||
const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID(fileId);
|
||||
|
||||
@@ -70,7 +75,7 @@ public:
|
||||
|
||||
bool alreadyParsed(clang::SourceLocation sourceLocation)
|
||||
{
|
||||
return alreadyParsed(m_sourceManager->getFileID(sourceLocation));
|
||||
return isAlreadyParsed(m_sourceManager->getFileID(sourceLocation));
|
||||
}
|
||||
|
||||
FilePathId filePathId(const clang::FileEntry *fileEntry)
|
||||
@@ -151,6 +156,11 @@ public:
|
||||
m_sourceManager->getSLocEntry(fileId).getFile().getFileCharacteristic());
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_filePathIndices.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<FilePathId> m_filePathIndices;
|
||||
FilePathCachingInterface &m_filePathCache;
|
||||
|
||||
Reference in New Issue
Block a user