-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix non-existent files resolving as working directory #594
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1246,13 +1246,16 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor> | |
if (start_.isInvalid() || end_.isInvalid()) | ||
{ | ||
fileLoc.file = getFile(start_); | ||
const std::string& type = fileLoc.file.load()->type; | ||
if (type != model::File::DIRECTORY_TYPE && type != _cppSourceType) | ||
if (fileLoc.file) | ||
{ | ||
fileLoc.file->type = _cppSourceType; | ||
_ctx.srcMgr.updateFile(*fileLoc.file); | ||
const std::string& type = fileLoc.file.load()->type; | ||
if (type != model::File::DIRECTORY_TYPE && type != _cppSourceType) | ||
{ | ||
fileLoc.file->type = _cppSourceType; | ||
_ctx.srcMgr.updateFile(*fileLoc.file); | ||
} | ||
} | ||
return fileLoc; | ||
return fileLoc; | ||
} | ||
|
||
clang::SourceLocation realStart = start_; | ||
|
@@ -1268,14 +1271,16 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor> | |
|
||
fileLoc.file = getFile(realStart); | ||
|
||
const std::string& type = fileLoc.file.load()->type; | ||
if (type != model::File::DIRECTORY_TYPE && type != _cppSourceType) | ||
if (fileLoc.file) | ||
{ | ||
fileLoc.file->type = _cppSourceType; | ||
_ctx.srcMgr.updateFile(*fileLoc.file); | ||
const std::string& type = fileLoc.file.load()->type; | ||
if (type != model::File::DIRECTORY_TYPE && type != _cppSourceType) | ||
{ | ||
fileLoc.file->type = _cppSourceType; | ||
_ctx.srcMgr.updateFile(*fileLoc.file); | ||
} | ||
} | ||
|
||
return fileLoc; | ||
return fileLoc; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary indentation. |
||
} | ||
|
||
bool isFunctionPointer(const clang::ValueDecl* vd_) const | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,23 +259,28 @@ void CppParser::addCompileCommand( | |
{ | ||
model::BuildSource buildSource; | ||
buildSource.file = _ctx.srcMgr.getFile(srcTarget.first); | ||
buildSource.file->parseStatus = error_ | ||
? model::File::PSPartiallyParsed | ||
: model::File::PSFullyParsed; | ||
_ctx.srcMgr.updateFile(*buildSource.file); | ||
buildSource.action = buildAction_; | ||
sources.push_back(std::move(buildSource)); | ||
if (buildSource.file) | ||
{ | ||
buildSource.file->parseStatus = error_ | ||
? model::File::PSPartiallyParsed | ||
: model::File::PSFullyParsed; | ||
_ctx.srcMgr.updateFile(*buildSource.file); | ||
buildSource.action = buildAction_; | ||
sources.push_back(std::move(buildSource)); | ||
} | ||
|
||
model::BuildTarget buildTarget; | ||
buildTarget.file = _ctx.srcMgr.getFile(srcTarget.second); | ||
buildTarget.action = buildAction_; | ||
if (buildTarget.file->type != model::File::BINARY_TYPE) | ||
if (buildTarget.file) | ||
{ | ||
buildTarget.file->type = model::File::BINARY_TYPE; | ||
_ctx.srcMgr.updateFile(*buildTarget.file); | ||
buildTarget.action = buildAction_; | ||
if (buildTarget.file->type != model::File::BINARY_TYPE) | ||
{ | ||
buildTarget.file->type = model::File::BINARY_TYPE; | ||
_ctx.srcMgr.updateFile(*buildTarget.file); | ||
} | ||
targets.push_back(std::move(buildTarget)); | ||
} | ||
|
||
targets.push_back(std::move(buildTarget)); | ||
} | ||
|
||
_ctx.srcMgr.persistFiles(); | ||
|
@@ -374,17 +379,20 @@ std::vector<std::vector<std::string>> CppParser::createCleanupOrder() | |
{ | ||
auto file = _ctx.srcMgr.getFile(item.first); | ||
|
||
auto inclusions = _ctx.db->query<model::CppHeaderInclusion>( | ||
odb::query<model::CppHeaderInclusion>::included == file->id); | ||
|
||
for (const auto& inclusion : inclusions) | ||
if (file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using the early return technique if the nesting is too deep. |
||
{ | ||
bool inserted; | ||
model::FilePtr includer = inclusion.includer.load(); | ||
boost::graph_traits<Graph>::edge_descriptor e; | ||
boost::tie(e, inserted) = boost::add_edge( | ||
fileNameToVertex.at(includer->path), | ||
fileNameToVertex.at(file->path), g); | ||
auto inclusions = _ctx.db->query<model::CppHeaderInclusion>( | ||
odb::query<model::CppHeaderInclusion>::included == file->id); | ||
|
||
for (const auto& inclusion : inclusions) | ||
{ | ||
bool inserted; | ||
model::FilePtr includer = inclusion.includer.load(); | ||
boost::graph_traits<Graph>::edge_descriptor e; | ||
boost::tie(e, inserted) = boost::add_edge( | ||
fileNameToVertex.at(includer->path), | ||
fileNameToVertex.at(file->path), g); | ||
} | ||
} | ||
} | ||
}); | ||
|
@@ -622,38 +630,41 @@ bool CppParser::cleanupWorker(const std::string& path_) | |
// Fetch file from SourceManager by path | ||
model::FilePtr delFile = _ctx.srcMgr.getFile(path_); | ||
|
||
// Query CppAstNode | ||
auto defCppAstNodes = _ctx.db->query<model::CppAstNode>( | ||
odb::query<model::CppAstNode>::location.file == delFile->id); | ||
|
||
for (const model::CppAstNode& astNode : defCppAstNodes) | ||
if (delFile) | ||
{ | ||
// Delete CppEntity | ||
_ctx.db->erase_query<model::CppEntity>(odb::query<model::CppEntity>::astNodeId == astNode.id); | ||
// Query CppAstNode | ||
auto defCppAstNodes = _ctx.db->query<model::CppAstNode>( | ||
odb::query<model::CppAstNode>::location.file == delFile->id); | ||
|
||
if (astNode.astType == model::CppAstNode::AstType::Definition) | ||
for (const model::CppAstNode& astNode : defCppAstNodes) | ||
{ | ||
// Delete CppInheritance | ||
_ctx.db->erase_query<model::CppInheritance>( | ||
odb::query<model::CppInheritance>::derived == astNode.entityHash); | ||
|
||
// Delete CppFriendship | ||
_ctx.db->erase_query<model::CppFriendship>( | ||
odb::query<model::CppFriendship>::target == astNode.entityHash); | ||
// Delete CppEntity | ||
_ctx.db->erase_query<model::CppEntity>(odb::query<model::CppEntity>::astNodeId == astNode.id); | ||
|
||
if (astNode.astType == model::CppAstNode::AstType::Definition) | ||
{ | ||
// Delete CppInheritance | ||
_ctx.db->erase_query<model::CppInheritance>( | ||
odb::query<model::CppInheritance>::derived == astNode.entityHash); | ||
|
||
// Delete CppFriendship | ||
_ctx.db->erase_query<model::CppFriendship>( | ||
odb::query<model::CppFriendship>::target == astNode.entityHash); | ||
} | ||
} | ||
} | ||
|
||
// Delete BuildAction | ||
auto delSources = _ctx.db->query<model::BuildSource>( | ||
odb::query<model::BuildSource>::file == delFile->id); | ||
for (const model::BuildSource& source : delSources) | ||
{ | ||
_ctx.db->erase<model::BuildAction>(source.action->id); | ||
} | ||
// Delete BuildAction | ||
auto delSources = _ctx.db->query<model::BuildSource>( | ||
odb::query<model::BuildSource>::file == delFile->id); | ||
for (const model::BuildSource& source : delSources) | ||
{ | ||
_ctx.db->erase<model::BuildAction>(source.action->id); | ||
} | ||
|
||
// Delete CppEdge (connected to File) | ||
_ctx.db->erase_query<model::CppEdge>(odb::query<model::CppEdge>::from == delFile->id); | ||
// Delete CppEdge (connected to File) | ||
_ctx.db->erase_query<model::CppEdge>(odb::query<model::CppEdge>::from == delFile->id); | ||
|
||
} | ||
break; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,39 +77,48 @@ void PPIncludeCallback::InclusionDirective( | |
|
||
std::string includedPath = searchPath_.str() + '/' + fileName_.str(); | ||
model::FilePtr included = _ctx.srcMgr.getFile(includedPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding extra indentation everywhere, maybe it was simpler to bring the |
||
included->parseStatus = model::File::PSFullyParsed; | ||
if (included->type != model::File::DIRECTORY_TYPE && | ||
included->type != _cppSourceType) | ||
if (included) | ||
{ | ||
included->type = _cppSourceType; | ||
_ctx.srcMgr.updateFile(*included); | ||
included->parseStatus = model::File::PSFullyParsed; | ||
if (included->type != model::File::DIRECTORY_TYPE && | ||
included->type != _cppSourceType) | ||
{ | ||
included->type = _cppSourceType; | ||
_ctx.srcMgr.updateFile(*included); | ||
} | ||
} | ||
|
||
//--- Includer file ---// | ||
|
||
std::string includerPath = presLoc.getFilename(); | ||
model::FilePtr includer = _ctx.srcMgr.getFile(includerPath); | ||
includer->parseStatus = model::File::PSFullyParsed; | ||
if (includer->type != model::File::DIRECTORY_TYPE && | ||
includer->type != _cppSourceType) | ||
if (includer) | ||
{ | ||
includer->type = _cppSourceType; | ||
_ctx.srcMgr.updateFile(*includer); | ||
includer->parseStatus = model::File::PSFullyParsed; | ||
if (includer->type != model::File::DIRECTORY_TYPE && | ||
includer->type != _cppSourceType) | ||
{ | ||
includer->type = _cppSourceType; | ||
_ctx.srcMgr.updateFile(*includer); | ||
} | ||
} | ||
|
||
//--- CppAstNode ---// | ||
|
||
model::CppAstNodePtr fileNode = | ||
createFileAstNode(included, filenameRange_.getAsRange()); | ||
if (included && includer) | ||
{ | ||
model::CppAstNodePtr fileNode = | ||
createFileAstNode(included, filenameRange_.getAsRange()); | ||
|
||
if (_entityCache.insert(*fileNode)) | ||
_astNodes.push_back(fileNode); | ||
if (_entityCache.insert(*fileNode)) | ||
_astNodes.push_back(fileNode); | ||
|
||
model::CppHeaderInclusionPtr inclusion(new model::CppHeaderInclusion); | ||
inclusion->includer = includer; | ||
inclusion->included = included; | ||
model::CppHeaderInclusionPtr inclusion(new model::CppHeaderInclusion); | ||
inclusion->includer = includer; | ||
inclusion->included = included; | ||
|
||
_headerIncs.push_back(inclusion); | ||
_headerIncs.push_back(inclusion); | ||
} | ||
} | ||
|
||
} // parser | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary indentation.