data: Faster creation of ParseLocation
This commit is contained in:
@@ -10,11 +10,11 @@ ParseLocation::ParseLocation()
|
||||
}
|
||||
|
||||
ParseLocation::ParseLocation(
|
||||
const FilePath& filePath,
|
||||
FilePath filePath,
|
||||
uint lineNumber,
|
||||
uint columnNumber
|
||||
)
|
||||
: filePath(filePath.getCanonical())
|
||||
: filePath(std::move(filePath.makeCanonical()))
|
||||
, startLineNumber(lineNumber)
|
||||
, startColumnNumber(columnNumber)
|
||||
, endLineNumber(lineNumber)
|
||||
@@ -23,11 +23,11 @@ ParseLocation::ParseLocation(
|
||||
}
|
||||
|
||||
ParseLocation::ParseLocation(
|
||||
const FilePath& filePath,
|
||||
FilePath filePath,
|
||||
uint startLineNumber, uint startColumnNumber,
|
||||
uint endLineNumber, uint endColumnNumber
|
||||
)
|
||||
: filePath(filePath.getCanonical())
|
||||
: filePath(std::move(filePath.makeCanonical()))
|
||||
, startLineNumber(startLineNumber)
|
||||
, startColumnNumber(startColumnNumber)
|
||||
, endLineNumber(endLineNumber)
|
||||
|
||||
@@ -10,12 +10,12 @@ struct ParseLocation
|
||||
{
|
||||
ParseLocation();
|
||||
ParseLocation(
|
||||
const FilePath& filePath,
|
||||
FilePath filePath,
|
||||
uint lineNumber,
|
||||
uint columnNumber
|
||||
);
|
||||
ParseLocation(
|
||||
const FilePath& filePath,
|
||||
FilePath filePath,
|
||||
uint startLineNumber, uint startColumnNumber,
|
||||
uint endLineNumber, uint endColumnNumber
|
||||
);
|
||||
|
||||
@@ -31,7 +31,7 @@ bool CommentHandler::HandleComment(clang::Preprocessor& preprocessor, clang::Sou
|
||||
const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
|
||||
|
||||
m_client->recordComment(ParseLocation(
|
||||
filePath,
|
||||
std::move(filePath),
|
||||
presumedBegin.getLine(),
|
||||
presumedBegin.getColumn(),
|
||||
presumedEnd.getLine(),
|
||||
|
||||
@@ -71,7 +71,8 @@ void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, con
|
||||
return;
|
||||
}
|
||||
|
||||
const NameHierarchy nameHierarchy(utility::decodeFromUtf8(macroNameToken.getIdentifierInfo()->getName().str()), NAME_DELIMITER_CXX);
|
||||
const NameHierarchy nameHierarchy(
|
||||
utility::decodeFromUtf8(macroNameToken.getIdentifierInfo()->getName().str()), NAME_DELIMITER_CXX);
|
||||
|
||||
m_client->recordSymbolWithLocationAndScope(
|
||||
nameHierarchy,
|
||||
@@ -85,7 +86,9 @@ void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, con
|
||||
}
|
||||
|
||||
void PreprocessorCallbacks::MacroUndefined(
|
||||
const clang::Token& macroNameToken, const clang::MacroDefinition& macroDefinition, const clang::MacroDirective* macroUndefinition)
|
||||
const clang::Token& macroNameToken,
|
||||
const clang::MacroDefinition& macroDefinition,
|
||||
const clang::MacroDirective* macroUndefinition)
|
||||
{
|
||||
onMacroUsage(macroNameToken);
|
||||
}
|
||||
@@ -120,7 +123,8 @@ void PreprocessorCallbacks::onMacroUsage(const clang::Token& macroNameToken)
|
||||
{
|
||||
const ParseLocation loc = getParseLocation(macroNameToken);
|
||||
|
||||
const NameHierarchy referencedNameHierarchy(utility::decodeFromUtf8(macroNameToken.getIdentifierInfo()->getName().str()), NAME_DELIMITER_CXX);
|
||||
const NameHierarchy referencedNameHierarchy(
|
||||
utility::decodeFromUtf8(macroNameToken.getIdentifierInfo()->getName().str()), NAME_DELIMITER_CXX);
|
||||
const NameHierarchy contextNameHierarchy(loc.filePath.wstr(), NAME_DELIMITER_FILE);
|
||||
|
||||
m_client->recordReference(
|
||||
@@ -141,7 +145,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::Token& macroN
|
||||
if (!filePath.empty())
|
||||
{
|
||||
return ParseLocation(
|
||||
filePath,
|
||||
std::move(filePath),
|
||||
m_sourceManager.getSpellingLineNumber(location),
|
||||
m_sourceManager.getSpellingColumnNumber(location),
|
||||
m_sourceManager.getSpellingLineNumber(endLocation),
|
||||
@@ -161,7 +165,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::MacroInfo* ma
|
||||
if (!filePath.empty())
|
||||
{
|
||||
return ParseLocation(
|
||||
filePath,
|
||||
std::move(filePath),
|
||||
m_sourceManager.getSpellingLineNumber(location),
|
||||
m_sourceManager.getSpellingColumnNumber(location),
|
||||
m_sourceManager.getSpellingLineNumber(endLocation),
|
||||
@@ -185,7 +189,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::SourceRange&
|
||||
if (!filePath.empty())
|
||||
{
|
||||
return ParseLocation(
|
||||
filePath,
|
||||
std::move(filePath),
|
||||
presumedBegin.getLine(),
|
||||
presumedBegin.getColumn(),
|
||||
presumedEnd.getLine(),
|
||||
|
||||
@@ -136,7 +136,6 @@ ParseLocation utility::getParseLocation(
|
||||
clang::Preprocessor* preprocessor,
|
||||
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache)
|
||||
{
|
||||
ParseLocation parseLocation;
|
||||
if (sourceLocation.isValid())
|
||||
{
|
||||
clang::SourceLocation loc = sourceLocation;
|
||||
@@ -152,32 +151,34 @@ ParseLocation utility::getParseLocation(
|
||||
const clang::SourceLocation startLoc = sourceManager.getSpellingLoc(loc);
|
||||
const clang::FileID fileId = sourceManager.getFileID(startLoc);
|
||||
|
||||
// find the location file
|
||||
parseLocation.filePath = canonicalFilePathCache->getCanonicalFilePath(fileId, sourceManager);
|
||||
|
||||
// find the start location
|
||||
{
|
||||
const unsigned int offset = sourceManager.getFileOffset(startLoc);
|
||||
parseLocation.startLineNumber = sourceManager.getLineNumber(fileId, offset);
|
||||
parseLocation.startColumnNumber = sourceManager.getColumnNumber(fileId, offset);
|
||||
}
|
||||
const unsigned int startOffset = sourceManager.getFileOffset(startLoc);
|
||||
|
||||
// General case -- find the end of the token starting at loc.
|
||||
if (preprocessor != nullptr)
|
||||
{
|
||||
const clang::SourceLocation endSloc = preprocessor->getLocForEndOfToken(startLoc);
|
||||
const unsigned int offset = sourceManager.getFileOffset(endSloc);
|
||||
parseLocation.endLineNumber = sourceManager.getLineNumber(fileId, offset);
|
||||
parseLocation.endColumnNumber = sourceManager.getColumnNumber(fileId, offset) - 1;
|
||||
const unsigned int endOffset = sourceManager.getFileOffset(endSloc);
|
||||
|
||||
return ParseLocation(
|
||||
canonicalFilePathCache->getCanonicalFilePath(fileId, sourceManager),
|
||||
sourceManager.getLineNumber(fileId, startOffset),
|
||||
sourceManager.getColumnNumber(fileId, startOffset),
|
||||
sourceManager.getLineNumber(fileId, endOffset),
|
||||
sourceManager.getColumnNumber(fileId, endOffset) - 1
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
parseLocation.endLineNumber = parseLocation.startLineNumber;
|
||||
parseLocation.endColumnNumber = parseLocation.startColumnNumber;
|
||||
return ParseLocation(
|
||||
canonicalFilePathCache->getCanonicalFilePath(fileId, sourceManager),
|
||||
sourceManager.getLineNumber(fileId, startOffset),
|
||||
sourceManager.getColumnNumber(fileId, startOffset)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return parseLocation;
|
||||
return ParseLocation();
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +188,6 @@ ParseLocation utility::getParseLocation(
|
||||
clang::Preprocessor* preprocessor,
|
||||
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache)
|
||||
{
|
||||
ParseLocation parseLocation;
|
||||
if (sourceRange.isValid())
|
||||
{
|
||||
clang::SourceRange range = sourceRange;
|
||||
@@ -225,13 +225,14 @@ ParseLocation utility::getParseLocation(
|
||||
filePath = canonicalFilePathCache->getCanonicalFilePath(utility::decodeFromUtf8(presumedBegin.getFilename()));
|
||||
}
|
||||
|
||||
parseLocation = ParseLocation(
|
||||
filePath,
|
||||
return ParseLocation(
|
||||
std::move(filePath),
|
||||
presumedBegin.getLine(),
|
||||
presumedBegin.getColumn(),
|
||||
presumedEnd.getLine(),
|
||||
presumedEnd.getColumn() - (endLoc.isValid() ? 1 : 0)
|
||||
);
|
||||
}
|
||||
return parseLocation;
|
||||
|
||||
return ParseLocation();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user