eduucaldas updated this revision to Diff 284794.
eduucaldas added a comment.
Add explanation comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85750/new/
https://reviews.llvm.org/D85750
Files:
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp
Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===================================================================
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2592,9 +2592,7 @@
| | |-IdExpression
| | | `-UnqualifiedId
| | | `-x
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | `-=
+ | | |-=
| | `-IdExpression
| | `-UnqualifiedId
| | `-y
@@ -2605,9 +2603,7 @@
| | | `-IdExpression
| | | `-UnqualifiedId
| | | `-x
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | `-+
+ | | |-+
| | `-IdExpression
| | `-UnqualifiedId
| | `-y
@@ -2617,9 +2613,7 @@
| | |-IdExpression
| | | `-UnqualifiedId
| | | `-x
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | `-<
+ | | |-<
| | `-IdExpression
| | `-UnqualifiedId
| | `-y
@@ -2629,9 +2623,7 @@
| | |-IdExpression
| | | `-UnqualifiedId
| | | `-x
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | `-<<
+ | | |-<<
| | `-IdExpression
| | `-UnqualifiedId
| | `-y
@@ -2641,9 +2633,7 @@
| | |-IdExpression
| | | `-UnqualifiedId
| | | `-x
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | `-,
+ | | |-,
| | `-IdExpression
| | `-UnqualifiedId
| | `-y
@@ -2730,27 +2720,21 @@
|-{
|-ExpressionStatement
| |-PrefixUnaryOperatorExpression
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | `-++
+ | | |-++
| | `-IdExpression
| | `-UnqualifiedId
| | `-x
| `-;
|-ExpressionStatement
| |-PrefixUnaryOperatorExpression
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | `-!
+ | | |-!
| | `-IdExpression
| | `-UnqualifiedId
| | `-x
| `-;
|-ExpressionStatement
| |-PrefixUnaryOperatorExpression
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | `-&
+ | | |-&
| | `-IdExpression
| | `-UnqualifiedId
| | `-x
@@ -2809,9 +2793,7 @@
| | |-IdExpression
| | | `-UnqualifiedId
| | | `-x
- | | `-IdExpression
- | | `-UnqualifiedId
- | | `-++
+ | | `-++
| `-;
`-}
)txt"));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===================================================================
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1007,23 +1007,26 @@
}
bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
- if (getOperatorNodeKind(*S) ==
- syntax::NodeKind::PostfixUnaryOperatorExpression) {
+ for (auto *child : S->children()) {
// A postfix unary operator is declared as taking two operands. The
// second operand is used to distinguish from its prefix counterpart. In
// the semantic AST this "phantom" operand is represented as a
// `IntegerLiteral` with invalid `SourceLocation`. We skip visiting this
// operand because it does not correspond to anything written in source
// code
- for (auto *child : S->children()) {
- if (child->getSourceRange().isInvalid())
- continue;
- if (!TraverseStmt(child))
- return false;
+ if (child->getSourceRange().isInvalid()) {
+ assert(getOperatorNodeKind(*S) ==
+ syntax::NodeKind::PostfixUnaryOperatorExpression);
+ continue;
}
- return WalkUpFromCXXOperatorCallExpr(S);
- } else
- return RecursiveASTVisitor::TraverseCXXOperatorCallExpr(S);
+ // An operator is treated as a simple token. This allows for an uniform
+ // representation of built-in and user-defined operators.
+ if (child->getBeginLoc() == S->getOperatorLoc())
+ continue;
+ if (!TraverseStmt(child))
+ return false;
+ }
+ return WalkUpFromCXXOperatorCallExpr(S);
}
bool WalkUpFromCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits