Author: Eduardo Caldas Date: 2020-08-20T14:57:35Z New Revision: a4ef9e8643e2f3f8972e19c5b25f4dd81ba03508
URL: https://github.com/llvm/llvm-project/commit/a4ef9e8643e2f3f8972e19c5b25f4dd81ba03508 DIFF: https://github.com/llvm/llvm-project/commit/a4ef9e8643e2f3f8972e19c5b25f4dd81ba03508.diff LOG: [SyntaxTree] Unify logic for generating `id-expression` Added: Modified: clang/lib/Tooling/Syntax/BuildTree.cpp Removed: ################################################################################ diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp index a77149d66207..37d29a270463 100644 --- a/clang/lib/Tooling/Syntax/BuildTree.cpp +++ b/clang/lib/Tooling/Syntax/BuildTree.cpp @@ -881,35 +881,46 @@ class BuildTreeVisitor : public RecursiveASTVisitor<BuildTreeVisitor> { 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 @@ class BuildTreeVisitor : public RecursiveASTVisitor<BuildTreeVisitor> { } 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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits