diff options
author | Eduardo Caldas <ecaldas@google.com> | 2020-08-20 14:18:55 +0000 |
---|---|---|
committer | Eduardo Caldas <ecaldas@google.com> | 2020-08-20 14:57:35 +0000 |
commit | a4ef9e8643e2f3f8972e19c5b25f4dd81ba03508 (patch) | |
tree | e5e798324333aa4c198d83ca9537a070b693aba3 /clang/lib/Tooling/Syntax/BuildTree.cpp | |
parent | ba32915db2ce78256115a9db7b07bb3806e6364a (diff) | |
download | llvm-a4ef9e8643e2f3f8972e19c5b25f4dd81ba03508.zip llvm-a4ef9e8643e2f3f8972e19c5b25f4dd81ba03508.tar.gz llvm-a4ef9e8643e2f3f8972e19c5b25f4dd81ba03508.tar.bz2 |
[SyntaxTree] Unify logic for generating `id-expression`
Diffstat (limited to 'clang/lib/Tooling/Syntax/BuildTree.cpp')
-rw-r--r-- | clang/lib/Tooling/Syntax/BuildTree.cpp | 79 |
1 files changed, 31 insertions, 48 deletions
diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp index a77149d..37d29a2 100644 --- a/clang/lib/Tooling/Syntax/BuildTree.cpp +++ b/clang/lib/Tooling/Syntax/BuildTree.cpp @@ -881,35 +881,46 @@ public: return true; } - bool WalkUpFromMemberExpr(MemberExpr *S) { - if (auto QualifierLoc = S->getQualifierLoc()) + syntax::IdExpression *buildIdExpression(NestedNameSpecifierLoc QualifierLoc, + SourceLocation TemplateKeywordLoc, + SourceRange UnqualifiedIdLoc, + ASTPtr From) { + if (QualifierLoc) { Builder.markChild(QualifierLoc, syntax::NodeRole::IdExpression_qualifier); - - auto TemplateKeywordLoc = S->getTemplateKeywordLoc(); - if (TemplateKeywordLoc.isValid()) - Builder.markChildToken(TemplateKeywordLoc, - syntax::NodeRole::TemplateKeyword); + if (TemplateKeywordLoc.isValid()) + Builder.markChildToken(TemplateKeywordLoc, + syntax::NodeRole::TemplateKeyword); + } auto *TheUnqualifiedId = new (allocator()) syntax::UnqualifiedId; - Builder.foldNode(Builder.getRange(S->getMemberLoc(), S->getEndLoc()), - TheUnqualifiedId, nullptr); - + Builder.foldNode(Builder.getRange(UnqualifiedIdLoc), TheUnqualifiedId, + nullptr); Builder.markChild(TheUnqualifiedId, syntax::NodeRole::IdExpression_id); + auto IdExpressionBeginLoc = + QualifierLoc ? QualifierLoc.getBeginLoc() : UnqualifiedIdLoc.getBegin(); + auto *TheIdExpression = new (allocator()) syntax::IdExpression; - auto MemberRange = - Builder.getRange(S->hasQualifier() ? S->getQualifierLoc().getBeginLoc() - : S->getMemberLoc(), - S->getEndLoc()); + Builder.foldNode( + Builder.getRange(IdExpressionBeginLoc, UnqualifiedIdLoc.getEnd()), + TheIdExpression, From); + return TheIdExpression; + } + + bool WalkUpFromMemberExpr(MemberExpr *S) { // For `MemberExpr` with implicit `this->` we generate a simple // `id-expression` syntax node, beacuse an implicit `member-expression` is // syntactically undistinguishable from an `id-expression` if (S->isImplicitAccess()) { - Builder.foldNode(MemberRange, TheIdExpression, S); + buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(), + SourceRange(S->getMemberLoc(), S->getEndLoc()), S); return true; } - Builder.foldNode(MemberRange, TheIdExpression, nullptr); + + auto *TheIdExpression = buildIdExpression( + S->getQualifierLoc(), S->getTemplateKeywordLoc(), + SourceRange(S->getMemberLoc(), S->getEndLoc()), nullptr); Builder.markChild(TheIdExpression, syntax::NodeRole::MemberExpression_member); @@ -925,45 +936,17 @@ public: } bool WalkUpFromDeclRefExpr(DeclRefExpr *S) { - if (auto QualifierLoc = S->getQualifierLoc()) - Builder.markChild(QualifierLoc, syntax::NodeRole::IdExpression_qualifier); + buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(), + SourceRange(S->getLocation(), S->getEndLoc()), S); - auto TemplateKeywordLoc = S->getTemplateKeywordLoc(); - if (TemplateKeywordLoc.isValid()) - Builder.markChildToken(TemplateKeywordLoc, - syntax::NodeRole::TemplateKeyword); - - auto *unqualifiedId = new (allocator()) syntax::UnqualifiedId; - - Builder.foldNode(Builder.getRange(S->getLocation(), S->getEndLoc()), - unqualifiedId, nullptr); - - Builder.markChild(unqualifiedId, syntax::NodeRole::IdExpression_id); - - Builder.foldNode(Builder.getExprRange(S), - new (allocator()) syntax::IdExpression, S); return true; } // Same logic as DeclRefExpr. bool WalkUpFromDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) { - if (auto QualifierLoc = S->getQualifierLoc()) - Builder.markChild(QualifierLoc, syntax::NodeRole::IdExpression_qualifier); + buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(), + SourceRange(S->getLocation(), S->getEndLoc()), S); - auto TemplateKeywordLoc = S->getTemplateKeywordLoc(); - if (TemplateKeywordLoc.isValid()) - Builder.markChildToken(TemplateKeywordLoc, - syntax::NodeRole::TemplateKeyword); - - auto *unqualifiedId = new (allocator()) syntax::UnqualifiedId; - - Builder.foldNode(Builder.getRange(S->getLocation(), S->getEndLoc()), - unqualifiedId, nullptr); - - Builder.markChild(unqualifiedId, syntax::NodeRole::IdExpression_id); - - Builder.foldNode(Builder.getExprRange(S), - new (allocator()) syntax::IdExpression, S); return true; } |