Skip to content

Commit

Permalink
Correct display for implicit and macro-expanded variables (#646)
Browse files Browse the repository at this point in the history
* Implicit variables and variables expanded from macros are now correctly displayed in the info tree (with type+name and the position of expansion).

* Same fix for class members.

* For macro-expanded variables and class members, instead of jumping straight to the physical location of the variable, we jump to the place of the macro's expansion. This is in line with how most IDEs like VS jump to the definition of such variables.
  • Loading branch information
dbukki authored Nov 8, 2023
1 parent 9c4a016 commit a34f994
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions plugins/cpp/parser/src/clangastvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,10 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>

model::CppAstNodePtr astNode = std::make_shared<model::CppAstNode>();

astNode->astValue = getSourceText(
_clangSrcMgr,
fd_->getSourceRange().getBegin(),
fd_->getSourceRange().getEnd(),
true);
astNode->astValue = fd_->getType().getAsString();
astNode->astValue.append(" ");
astNode->astValue.append(fd_->getNameAsString());

astNode->location = getFileLoc(fd_->getBeginLoc(), fd_->getEndLoc());
astNode->entityHash = util::fnvHash(getUSR(fd_));
astNode->symbolType
Expand Down Expand Up @@ -829,12 +828,11 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>

model::CppAstNodePtr astNode = std::make_shared<model::CppAstNode>();

astNode->astValue = getSourceText(
_clangSrcMgr,
vd_->getOuterLocStart(),
vd_->getEndLoc(),
true);
astNode->location = getFileLoc(vd_->getLocation(), vd_->getLocation());
astNode->astValue = vd_->getType().getAsString();
astNode->astValue.append(" ");
astNode->astValue.append(vd_->getNameAsString());

astNode->location = getFileLoc(vd_->getBeginLoc(), vd_->getEndLoc());
astNode->entityHash = util::fnvHash(getUSR(vd_));
astNode->symbolType
= isFunctionPointer(vd_)
Expand Down Expand Up @@ -881,6 +879,8 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>

if (_functionStack.empty())
variable->tags.insert(model::Tag::Global);
if (_isImplicit)
variable->tags.insert(model::Tag::Implicit);

//--- CppMemberType ---//

Expand Down Expand Up @@ -1258,9 +1258,14 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>

clang::SourceLocation realStart = start_;
clang::SourceLocation realEnd = end_;


if (_clangSrcMgr.isMacroBodyExpansion(start_))
realStart = _clangSrcMgr.getExpansionLoc(start_);
if (_clangSrcMgr.isMacroArgExpansion(start_))
realStart = _clangSrcMgr.getSpellingLoc(start_);

if (_clangSrcMgr.isMacroBodyExpansion(end_))
realEnd = _clangSrcMgr.getExpansionLoc(end_);
if (_clangSrcMgr.isMacroArgExpansion(end_))
realEnd = _clangSrcMgr.getSpellingLoc(end_);

Expand Down

0 comments on commit a34f994

Please sign in to comment.