Skip to content

Commit

Permalink
Fix non-existent files resolving as working directory
Browse files Browse the repository at this point in the history
This commit should fix non-existent files and directories
being shown in the infotree
  • Loading branch information
ervin7mk committed Feb 16, 2023
1 parent 203f59b commit 9e4f9b9
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 83 deletions.
5 changes: 4 additions & 1 deletion parser/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ void incrementalCleanup(cc::parser::ParserContext& ctx_)
cc::model::FilePtr delFile = ctx_.srcMgr.getFile(item.first);

// Delete File and FileContent (only when no other File references it)
ctx_.srcMgr.removeFile(*delFile);
if (delFile)
{
ctx_.srcMgr.removeFile(*delFile);
}
break;
}
case cc::parser::IncrementalStatus::ADDED:
Expand Down
27 changes: 16 additions & 11 deletions plugins/cpp/parser/src/clangastvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -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;
}

bool isFunctionPointer(const clang::ValueDecl* vd_) const
Expand Down
105 changes: 58 additions & 47 deletions plugins/cpp/parser/src/cppparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
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);
}
}
}
});
Expand Down Expand Up @@ -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;
}

Expand Down
45 changes: 27 additions & 18 deletions plugins/cpp/parser/src/ppincludecallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,48 @@ void PPIncludeCallback::InclusionDirective(

std::string includedPath = searchPath_.str() + '/' + fileName_.str();
model::FilePtr included = _ctx.srcMgr.getFile(includedPath);
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
Expand Down
15 changes: 9 additions & 6 deletions plugins/cpp/parser/src/ppmacrocallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,17 @@ void PPMacroCallback::addFileLoc(
_fileLocUtil.setRange(start_, end_, fileLoc.range);
fileLoc.file = _ctx.srcMgr.getFile(_fileLocUtil.getFilePath(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);
}

astNode_->location = fileLoc;
astNode_->location = fileLoc;
}
}

bool PPMacroCallback::isBuiltInMacro(const clang::MacroInfo* mi_) const
Expand Down

0 comments on commit 9e4f9b9

Please sign in to comment.