logic: cxx indexer fixes

* fixed comment locations have been saved to wrong database table
* fixed usage of tryGetRealPathName on windows
* used real filename in PreprocessorCallbacks, DiagnosticsConsumer and CommentHandler
* fixed crash in IncludeValidation when only one source file was checked
This commit is contained in:
malte_langkabel
2017-08-09 10:59:47 +02:00
parent 42fc52b8f7
commit 1ac63f0158
7 changed files with 85 additions and 46 deletions
@@ -1027,7 +1027,7 @@ void SqliteIndexStorage::setupPrecompiledStatements()
"LIMIT 1;"
);
m_insertCommentLocationStmt = m_database.compileStatement(
"INSERT INTO source_location(id, file_node_id, start_line, start_column, end_line, end_column) VALUES(NULL, ?, ?, ?, ?, ?);"
"INSERT INTO comment_location(id, file_node_id, start_line, start_column, end_line, end_column) VALUES(NULL, ?, ?, ?, ?, ?);"
);
m_checkErrorExistsStmt = m_database.compileStatement(
"SELECT id FROM error WHERE "
+20 -9
View File
@@ -1,5 +1,6 @@
#include "data/parser/cxx/CommentHandler.h"
#include "data/parser/cxx/utilityCxxAstVisitor.h"
#include "data/parser/ParseLocation.h"
#include "data/parser/ParserClient.h"
#include "utility/file/FileRegister.h"
@@ -25,16 +26,26 @@ bool CommentHandler::HandleComment(clang::Preprocessor& preprocessor, clang::Sou
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(sourceRange.getBegin(), false);
const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
FilePath filePath = m_canonicalFilePathCache->getValue(presumedBegin.getFilename());
if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsIndexed(filePath))
clang::FileID fileId = sourceManager.getFileID(sourceRange.getBegin());
// find the location file
if (!fileId.isInvalid())
{
m_client->onCommentParsed(ParseLocation(
filePath,
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
presumedEnd.getColumn()
));
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
{
FilePath filePath = m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry));
if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsIndexed(filePath))
{
m_client->onCommentParsed(ParseLocation(
filePath,
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
presumedEnd.getColumn()
));
}
}
}
return false;
@@ -3,6 +3,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Tooling/Tooling.h"
#include "data/parser/cxx/utilityCxxAstVisitor.h"
#include "data/parser/ParseLocation.h"
#include "data/parser/ParserClient.h"
#include "utility/file/FileRegister.h"
@@ -74,11 +75,17 @@ void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level lev
if (info.getLocation().isValid() && info.hasSourceManager())
{
const clang::SourceManager& sourceManager = info.getSourceManager();
clang::PresumedLoc presumedLocation = sourceManager.getPresumedLoc(info.getLocation());
{
const clang::PresumedLoc presumedLocation = sourceManager.getPresumedLoc(info.getLocation());
line = presumedLocation.getLine();
column = presumedLocation.getColumn();
}
filePath = clang::tooling::getAbsolutePath(presumedLocation.getFilename());
line = presumedLocation.getLine();
column = presumedLocation.getColumn();
const clang::FileEntry *fileEntry = sourceManager.getFileEntryForID(sourceManager.getFileID(info.getLocation()));
if (fileEntry)
{
filePath = m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry)).str();
}
}
ParseLocation location(m_canonicalFilePathCache->getValue(filePath), line, column);
@@ -152,13 +152,19 @@ 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());
return ParseLocation(
m_canonicalFilePathCache->getValue(m_sourceManager.getFilename(location).str()),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
m_sourceManager.getSpellingColumnNumber(endLocation) - 1
);
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry)
{
return ParseLocation(
m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry)),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
m_sourceManager.getSpellingColumnNumber(endLocation) - 1
);
}
return ParseLocation();
}
ParseLocation PreprocessorCallbacks::getParseLocation(const clang::MacroInfo* macroInfo) const
@@ -166,30 +172,39 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::MacroInfo* ma
clang::SourceLocation location = macroInfo->getDefinitionLoc();
clang::SourceLocation endLocation = macroInfo->getDefinitionEndLoc();
return ParseLocation(
m_canonicalFilePathCache->getValue(m_sourceManager.getFilename(location).str()),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
m_sourceManager.getSpellingColumnNumber(endLocation) - 1
);
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry)
{
return ParseLocation(
m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry)),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
m_sourceManager.getSpellingColumnNumber(endLocation) - 1
);
}
return ParseLocation();
}
ParseLocation PreprocessorCallbacks::getParseLocation(const clang::SourceRange& sourceRange) const
{
if (sourceRange.isInvalid())
if (sourceRange.isValid())
{
return ParseLocation();
const clang::PresumedLoc& presumedBegin = m_sourceManager.getPresumedLoc(sourceRange.getBegin(), false);
const clang::PresumedLoc& presumedEnd = m_sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(sourceRange.getBegin()));
if (fileEntry)
{
return ParseLocation(
m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry)),
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
presumedEnd.getColumn() - 1
);
}
}
const clang::PresumedLoc& presumedBegin = m_sourceManager.getPresumedLoc(sourceRange.getBegin(), false);
const clang::PresumedLoc& presumedEnd = m_sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
return ParseLocation(
m_canonicalFilePathCache->getValue(presumedBegin.getFilename()),
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
presumedEnd.getColumn() - 1
);
return ParseLocation();
}
@@ -3,6 +3,7 @@
#include <clang/AST/DeclCXX.h>
#include <clang/AST/DeclTemplate.h>
#include "utility/file/FilePath.h"
bool utility::isImplicit(const clang::Decl* d)
{
@@ -72,12 +73,17 @@ SymbolKind utility::convertTagKind(clang::TagTypeKind tagKind)
}
}
clang::StringRef utility::getFileNameOfFileEntry(const clang::FileEntry* entry)
std::string utility::getFileNameOfFileEntry(const clang::FileEntry* entry)
{
clang::StringRef fileName = entry->tryGetRealPathName();
if (!fileName.size())
std::string fileName = entry->tryGetRealPathName();
if (fileName.empty())
{
fileName = entry->getName();
}
else
{
fileName = FilePath(entry->getName().str()).parentDirectory().concat(FilePath(FilePath(fileName).fileName())).str();
}
return fileName;
}
@@ -11,7 +11,7 @@ namespace utility
bool isImplicit(const clang::Decl* d);
AccessKind convertAccessSpecifier(clang::AccessSpecifier access);
SymbolKind convertTagKind(clang::TagTypeKind tagKind);
clang::StringRef getFileNameOfFileEntry(const clang::FileEntry* entry);
std::string getFileNameOfFileEntry(const clang::FileEntry* entry);
}
#endif // UTILITY_CXX_AST_VISITOR_H
+1 -1
View File
@@ -24,7 +24,7 @@ std::vector<IncludeDirective> IncludeValidation::getUnresolvedIncludeDirectives(
std::set<std::string> processedFilePaths;
std::set<IncludeDirective, IncludeDirectiveComparator> unresolvedIncludeDirectives;
quantileCount = std::min(quantileCount, sourceFilePaths.size());
quantileCount = std::max<size_t>(1, std::min(quantileCount, sourceFilePaths.size()));
std::vector<std::vector<FilePath>> quantiles;
for (size_t i = 0; i < quantileCount; i++)