Skip to content

Commit a34f994

Browse files
authored
Correct display for implicit and macro-expanded variables (#646)
* 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.
1 parent 9c4a016 commit a34f994

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

plugins/cpp/parser/src/clangastvisitor.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,10 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
766766

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

769-
astNode->astValue = getSourceText(
770-
_clangSrcMgr,
771-
fd_->getSourceRange().getBegin(),
772-
fd_->getSourceRange().getEnd(),
773-
true);
769+
astNode->astValue = fd_->getType().getAsString();
770+
astNode->astValue.append(" ");
771+
astNode->astValue.append(fd_->getNameAsString());
772+
774773
astNode->location = getFileLoc(fd_->getBeginLoc(), fd_->getEndLoc());
775774
astNode->entityHash = util::fnvHash(getUSR(fd_));
776775
astNode->symbolType
@@ -829,12 +828,11 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
829828

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

832-
astNode->astValue = getSourceText(
833-
_clangSrcMgr,
834-
vd_->getOuterLocStart(),
835-
vd_->getEndLoc(),
836-
true);
837-
astNode->location = getFileLoc(vd_->getLocation(), vd_->getLocation());
831+
astNode->astValue = vd_->getType().getAsString();
832+
astNode->astValue.append(" ");
833+
astNode->astValue.append(vd_->getNameAsString());
834+
835+
astNode->location = getFileLoc(vd_->getBeginLoc(), vd_->getEndLoc());
838836
astNode->entityHash = util::fnvHash(getUSR(vd_));
839837
astNode->symbolType
840838
= isFunctionPointer(vd_)
@@ -881,6 +879,8 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
881879

882880
if (_functionStack.empty())
883881
variable->tags.insert(model::Tag::Global);
882+
if (_isImplicit)
883+
variable->tags.insert(model::Tag::Implicit);
884884

885885
//--- CppMemberType ---//
886886

@@ -1258,9 +1258,14 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
12581258

12591259
clang::SourceLocation realStart = start_;
12601260
clang::SourceLocation realEnd = end_;
1261-
1261+
1262+
if (_clangSrcMgr.isMacroBodyExpansion(start_))
1263+
realStart = _clangSrcMgr.getExpansionLoc(start_);
12621264
if (_clangSrcMgr.isMacroArgExpansion(start_))
12631265
realStart = _clangSrcMgr.getSpellingLoc(start_);
1266+
1267+
if (_clangSrcMgr.isMacroBodyExpansion(end_))
1268+
realEnd = _clangSrcMgr.getExpansionLoc(end_);
12641269
if (_clangSrcMgr.isMacroArgExpansion(end_))
12651270
realEnd = _clangSrcMgr.getSpellingLoc(end_);
12661271

0 commit comments

Comments
 (0)