[PATCH] D80540: Add support for binary operators in Syntax Trees

2020-05-26 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a reviewer: gribozavr2.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80540

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -564,7 +564,8 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-test
+| | |-UnknownExpression
+| | | `-test
 | | |-(
 | | `-)
 | `-;
@@ -576,14 +577,16 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-test
+| | | |-UnknownExpression
+| | | | `-test
 | | | |-(
 | | | `-)
 | | `-;
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-test
+|   | |-UnknownExpression
+|   | | `-test
 |   | |-(
 |   | `-)
 |   `-;
@@ -591,6 +594,237 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, BinaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a) {
+  1 - 2;
+  1 == 2;
+  a = 1;
+  a <<= 1;
+
+  true || false;
+  true or false;
+
+  1 & 2;
+  1 bitand 2;
+
+  a ^= 3;
+  a xor_eq 3;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |--
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-==
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-=
+| | `-UnknownExpression
+| |   `-1
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-<<=
+| | `-UnknownExpression
+| |   `-1
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-true
+| | |-||
+| | `-UnknownExpression
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-true
+| | |-or
+| | `-UnknownExpression
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-&
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-bitand
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-^=
+| | `-UnknownExpression
+| |   `-3
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-xor_eq
+| | `-UnknownExpression
+| |   `-3
+| `-;
+`-}
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, NestedBinaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a, int b) {
+  (1 + 2) * (4 / 2);
+  a + b + 42;
+  a = b = 42;
+  a + b * 4 + 2;
+  a % 2 + b * 42;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | |-(
+| | | |-BinaryOperatorExpression
+| | | | |-UnknownExpression
+| | | | | `-1
+| | | | |-+
+| | | | `-UnknownExpression
+| | | |   `-2
+| | | `-)
+| | |-*
+| | `-UnknownExpression
+| |   |-(
+| |   |-BinaryOperatorExpression
+| |   | |-UnknownExpression
+| |   | | `-4
+| |   | |-/
+| |   | `-UnknownExpression
+| |   |   `-2
+| |   `-)
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-BinaryOperatorExpression
+| | | |-UnknownExpression
+| | | | `-a
+| | | |-+
+| | | `-UnknownExpression
+| | |   `-b
+| | |-+
+| | `-UnknownExpression
+| |   `-42
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | 

[PATCH] D80624: Add support for UnaryOperator in SyntaxTree

2020-05-27 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a reviewer: gribozavr2.
gribozavr2 accepted this revision.
This revision is now accepted and ready to land.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80624

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -594,6 +594,161 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, PostfixUnaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a) {
+  a++;
+  a--;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PostfixUnaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | `-++
+| `-;
+|-ExpressionStatement
+| |-PostfixUnaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | `---
+| `-;
+`-}
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, PrefixUnaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a, int *ap, bool b) {
+  --a; ++a;
+  ~a; compl a;
+  -a;
+  +a;
+  &a;
+  *ap;
+  !b; not b;
+  __real a; __imag a;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   |-*
+  |   |   `-ap
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-bool
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |---
+| | `-UnknownExpression
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-++
+| | `-UnknownExpression
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-~
+| | `-UnknownExpression
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-compl
+| | `-UnknownExpression
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |--
+| | `-UnknownExpression
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-+
+| | `-UnknownExpression
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-&
+| | `-UnknownExpression
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-*
+| | `-UnknownExpression
+| |   `-ap
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-!
+| | `-UnknownExpression
+| |   `-b
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-not
+| | `-UnknownExpression
+| |   `-b
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-__real
+| | `-UnknownExpression
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-__imag
+| | `-UnknownExpression
+| |   `-a
+| `-;
+`-}
+)txt");
+}
+
 TEST_F(SyntaxTreeTest, BinaryOperator) {
   expectTreeDumpEqual(
   R"cpp(
@@ -1866,7 +2021,7 @@
 | |-SimpleDeclarator
 | | |-west
 | | |-=
-| | `-UnknownExpression
+| | `-PrefixUnaryOperatorExpression
 | |   |--
 | |   `-UnknownExpression
 | | `-1
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,10 @@
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::PrefixUnaryOperatorExpression:
+return OS << "PrefixUnaryOperatorExpression";
+  case NodeKind::PostfixUnaryOperatorExpression:
+return OS << "PostfixUnaryOperatorExpression";
   case NodeKind::BinaryOperatorExpression:
 return OS << "BinaryOperatorExpression";
   case NodeKind::UnknownStatement:
@@ -112,6 +116,10 @@
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
+  case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
+return OS << "UnaryOperatorExpression_operatorToken";
+  case syn

[PATCH] D80731: Improve test infrastructure in SyntaxTree

2020-05-28 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a reviewer: gribozavr2.

- Test if the code sourcing the SyntaxTree compiles
- Output compiler errors and warnings to err
- Fix tests with code that did not compile


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80731

Files:
  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
@@ -15,6 +15,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
@@ -97,8 +98,12 @@
 
 constexpr const char *FileName = "./input.cpp";
 FS->addFile(FileName, time_t(), llvm::MemoryBuffer::getMemBufferCopy(""));
+
 if (!Diags->getClient())
-  Diags->setClient(new IgnoringDiagConsumer);
+  Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), DiagOpts.get()));
+Diags->setSeverityForGroup(diag::Flavor::WarningOrError, "unused-value",
+   diag::Severity::Ignored, SourceLocation());
+
 // Prepare to run a compiler.
 std::vector Args = {
 "syntax-test", "-target",   Target.c_str(),
@@ -117,7 +122,11 @@
 
 syntax::TranslationUnit *Root = nullptr;
 BuildSyntaxTreeAction Recorder(Root, this->Arena);
-if (!Compiler.ExecuteAction(Recorder)) {
+
+// Action could not be executed but the frontend didn't identify any errors
+// in the code ==> problem in setting up the action
+if (!Compiler.ExecuteAction(Recorder) &&
+Diags->getClient()->getNumErrors() == 0) {
   ADD_FAILURE() << "failed to run the frontend";
   std::abort();
 }
@@ -143,6 +152,8 @@
 continue;
   }
   auto *Root = buildTree(Code, Target);
+  EXPECT_EQ(Diags->getClient()->getNumErrors(), 0u)
+  << "Source file has syntax errors, they were printed to the test log";
   std::string Actual = std::string(StringRef(Root->dump(*Arena)).trim());
   EXPECT_EQ(Expected, Actual)
   << "for target " << Target << " the resulting dump is:\n"
@@ -180,8 +191,10 @@
   }
 
   // Data fields.
+  llvm::IntrusiveRefCntPtr DiagOpts =
+  new DiagnosticOptions();
   llvm::IntrusiveRefCntPtr Diags =
-  new DiagnosticsEngine(new DiagnosticIDs, new DiagnosticOptions);
+  new DiagnosticsEngine(new DiagnosticIDs, DiagOpts.get());
   IntrusiveRefCntPtr FS =
   new llvm::vfs::InMemoryFileSystem;
   llvm::IntrusiveRefCntPtr FileMgr =
@@ -517,11 +530,11 @@
   // Unhandled statements should end up as 'unknown statement'.
   // This example uses a 'label statement', which does not yet have a syntax
   // counterpart.
-  expectTreeDumpEqual("void main() { foo: return 100; }",
+  expectTreeDumpEqual("int main() { foo: return 100; }",
   R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
-  |-void
+  |-int
   |-SimpleDeclarator
   | |-main
   | `-ParametersAndQualifiers
@@ -1166,7 +1179,7 @@
   // Free-standing classes, must live inside a SimpleDeclaration.
   expectTreeDumpEqual(
   R"cpp(
-sturct X;
+struct X;
 struct X {};
 
 struct Y *y1;
@@ -1177,7 +1190,7 @@
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
-| |-sturct
+| |-struct
 | |-X
 | `-;
 |-SimpleDeclaration
@@ -1660,7 +1673,7 @@
 int a[10];
 int b[1][2][3];
 int c[] = {1,2,3};
-void f(int xs[static 10]);
+// void f(int xs[static 10]);
 )cpp",
   R"txt(
 *: TranslationUnit
@@ -1694,163 +1707,146 @@
 | |   | `-3
 | |   `-]
 | `-;
-|-SimpleDeclaration
-| |-int
-| |-SimpleDeclarator
-| | |-c
-| | |-ArraySubscript
-| | | |-[
-| | | `-]
-| | |-=
-| | `-UnknownExpression
-| |   `-UnknownExpression
-| | |-{
-| | |-UnknownExpression
-| | | `-1
-| | |-,
-| | |-UnknownExpression
-| | | `-2
-| | |-,
-| | |-UnknownExpression
-| | | `-3
-| | `-}
-| `-;
 `-SimpleDeclaration
-  |-void
+  |-int
   |-SimpleDeclarator
-  | |-f
-  | `-ParametersAndQualifiers
-  |   |-(
-  |   |-SimpleDeclaration
-  |   | |-int
-  |   | `-SimpleDeclarator
-  |   |   |-xs
-  |   |   `-ArraySubscript
-  |   | |-[
-  |   | |-static
-  |   | |-UnknownExpression
-  |   | | `-10
-  |   | `-]
-  |   `-)
-  `-;
-   )txt");
+  | |-c
+  | |-ArraySubscript
+  | | |-[
+  | | `-]
+  | |-=
+  | `-UnknownExpression
+  |   `-UnknownExpression
+  | |-{
+  | |-UnknownExpression
+  | | `-1
+  | |-,
+  | |-UnknownExpression
+  | | `-2
+  | |-,
+  | |-UnknownExpression
+  | | `-3
+  | `-}
+  `-;   )txt");
 }
 
 TEST_F(SyntaxTreeTest, ParameterListsInDeclarators) {
   expectTreeDumpEqu

[PATCH] D80812: Add support for Overloaded Binary Operators in SyntaxTree

2020-05-29 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a reviewer: gribozavr2.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80812

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
@@ -993,6 +993,134 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, UserDefinedBinaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+struct X {
+  X& operator=(const X&);
+  friend X operator+(X, const X&);
+  friend bool operator<(const X&, const X&);
+};
+void test(X x, X y) {
+  x = y;
+  x + y;
+  x < y;
+}
+  )cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-&
+| | | |-operator
+| | | |-=
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-const
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-+
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | `-X
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-bool
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-y
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-x
+| | |-UnknownExpression
+| | | `-=
+| | `-UnknownExpression
+| |   `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-UnknownExpression
+| | |   `-x
+| | |-UnknownExpression
+| | | `-+
+| | `-UnknownExpression
+| |   `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-x
+| | |-UnknownExpression
+| | | `-<
+| | `-UnknownExpression
+| |   `-y
+| `-;
+`-}
+)txt");
+}
+
 TEST_F(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   expectTreeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -640,6 +640,24 @@
 return true;
   }
 
+  bool WalkUpFromCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
+if (S->isInfixBinaryOp()) {
+  Builder.markExprChild(
+  S->getArg(0),
+  syntax::NodeRole::BinaryOperatorExpression_leftHandSide);
+  Builder.markChildToken(
+  S->getOperatorLoc(),
+  syntax::NodeRole::BinaryOperatorExpression_operatorToken);
+  Builder.markExprChild(
+  S->getArg(1),
+  syntax::NodeRole::BinaryOperatorExpression_rightHandSide);
+  Builder.foldNode(Builder.getExprRange(S),
+   new (allocator()) syntax::BinaryOperatorExpression, S);
+  return true;
+}
+return RecursiveASTVisitor::WalkUpFromCXXOperatorCallExpr(S);
+  }
+
   bool WalkUpFromNamespaceDecl(NamespaceDecl *S) {
 auto Tokens = Builder.getDeclarationRange(S);
 if (Tokens.front().kind() == tok::coloncolon) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80822: Run syntax tree tests in many language modes

2020-06-02 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:54-63
+  bool isCXX() const {
+return Language == Lang_CXX || Language == Lang_CXX11 ||
+   Language == Lang_CXX14 || Language == Lang_CXX17 ||
+   Language == Lang_CXX2a;
+  }
+
+  bool isCXX11OrLater() const {

These could be on the clang/Testing



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:181
+
+Invocation = createInvocationFromCommandLine(ArgsCStr, Diags, FS);
 assert(Invocation);

Note: This already adds -fsyntax-only as a flag



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:206
   void expectTreeDumpEqual(StringRef Code, StringRef Tree,
bool RunWithDelayedTemplateParsing = true) {
+SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " "));

is RunWithDelayedTemplateParsing being used?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80822/new/

https://reviews.llvm.org/D80822



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81019: Syntax tree: ignore implicit expressions at the top level of statements

2020-06-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas accepted this revision.
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:1048
+  syntax::Tree *ChildNode;
+  if (Expr *ChildExpr = dyn_cast(Child)) {
+// This is an expression in a statement position, consume the trailing

I thought this treatement of derived class should be done by 
RecursiveASTVisitor 
This is kinda the task of WalkUpFrom*, unfortunately WalkUpFromThis follows the 
order:
WalkUpFromBase;
VisitThis;

And we would've wanted the opposite order:
VisitThis
WalkUpFromBase



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81019/new/

https://reviews.llvm.org/D81019



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81092: Add support for `nullptr` in SyntaxTrees

2020-06-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a reviewer: gribozavr2.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81092

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -670,6 +670,35 @@
 )txt");
 }
 
+TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  nullptr;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-CxxNullPtrExpression
+| | `-nullptr
+| `-;
+`-}
+)txt");
+}
+
 TEST_P(SyntaxTreeTest, PostfixUnaryOperator) {
   expectTreeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,8 @@
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::CxxNullPtrExpression:
+return OS << "CxxNullPtrExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -116,6 +118,8 @@
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
+  case syntax::NodeRole::CxxNullPtrExpression_keyword:
+return OS << "CxxNullPtrExpression_keyword";
   case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
 return OS << "UnaryOperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
@@ -158,6 +162,11 @@
   llvm_unreachable("invalid role");
 }
 
+syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+}
+
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::BinaryOperatorExpression_leftHandSide));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -608,6 +608,14 @@
 return true;
   }
 
+  bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
+Builder.markChildToken(S->getLocation(),
+   syntax::NodeRole::CxxNullPtrExpression_keyword);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::CxxNullPtrExpression, S);
+return true;
+  }
+
   bool WalkUpFromUnaryOperator(UnaryOperator *S) {
 Builder.markChildToken(
 S->getOperatorLoc(),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -43,6 +43,7 @@
   PrefixUnaryOperatorExpression,
   PostfixUnaryOperatorExpression,
   BinaryOperatorExpression,
+  CxxNullPtrExpression,
 
   // Statements.
   UnknownStatement,
@@ -112,6 +113,7 @@
   BinaryOperatorExpression_leftHandSide,
   BinaryOperatorExpression_operatorToken,
   BinaryOperatorExpression_rightHandSide,
+  CxxNullPtrExpression_keyword,
   CaseStatement_value,
   IfStatement_thenStatement,
   IfStatement_elseKeyword,
@@ -166,6 +168,16 @@
   }
 };
 
+/// C++11 'nullptr' expression.
+class CxxNullPtrExpression final : public Expression {
+public:
+  CxxNullPtrExpression() : Expression(NodeKind::CxxNullPtrExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::CxxNullPtrExpression;
+  }
+  syntax::Leaf *nullPtrKeyword();
+};
+
 /// An abstract class for prefix and postfix unary operators.
 class UnaryOperatorExpression : public Expression {
 public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84348: WIP: Add complete id-expression support to syntax trees

2020-07-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84348

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -867,24 +867,47 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
-namespace a {
+namespace n {
   struct S {
 template
-static T f(){}
+struct TS {
+  static void f();
+};
   };
 }
+template
+struct TS {
+  struct S {
+template
+static U f();
+  };
+};
 void test() {
-  ::  // global-namespace-specifier
-  a:: // namespace-specifier
-  S:: // type-name-specifier
+  :: // global-namespace-specifier
+  n::// namespace-specifier
+  S::// type-name-specifier
+  template TS:: // type-template-instantiation-specifier
+  f();
+
+  n::// namespace-specifier
+  S::// type-name-specifier
+  TS::  // type-template-instantiation-specifier
+  f();
+
+  TS:: // type-name-specifier
+  S::   // type-name-specifier
   f();
+
+  TS:: // type-name-specifier
+  S::   // type-name-specifier
+  template f();
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-NamespaceDefinition
 | |-namespace
-| |-a
+| |-n
 | |-{
 | |-SimpleDeclaration
 | | |-struct
@@ -898,19 +921,58 @@
 | | | | `-T
 | | | |->
 | | | `-SimpleDeclaration
-| | |   |-static
-| | |   |-T
-| | |   |-SimpleDeclarator
-| | |   | |-f
-| | |   | `-ParametersAndQualifiers
-| | |   |   |-(
-| | |   |   `-)
-| | |   `-CompoundStatement
-| | | |-{
-| | | `-}
+| | |   |-struct
+| | |   |-TS
+| | |   |-{
+| | |   |-SimpleDeclaration
+| | |   | |-static
+| | |   | |-void
+| | |   | |-SimpleDeclarator
+| | |   | | |-f
+| | |   | | `-ParametersAndQualifiers
+| | |   | |   |-(
+| | |   | |   `-)
+| | |   | `-;
+| | |   |-}
+| | |   `-;
 | | |-}
 | | `-;
 | `-}
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-TS
+|   |-{
+|   |-SimpleDeclaration
+|   | |-struct
+|   | |-S
+|   | |-{
+|   | |-TemplateDeclaration
+|   | | |-template
+|   | | |-<
+|   | | |-UnknownDeclaration
+|   | | | |-typename
+|   | | | `-U
+|   | | |->
+|   | | `-SimpleDeclaration
+|   | |   |-static
+|   | |   |-U
+|   | |   |-SimpleDeclarator
+|   | |   | |-f
+|   | |   | `-ParametersAndQualifiers
+|   | |   |   |-(
+|   | |   |   `-)
+|   | |   `-;
+|   | |-}
+|   | `-;
+|   |-}
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -924,14 +986,82 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-NameSpecifier
+| | | | |-GlobalNameSpecifier
+| | | | | `-::
+| | | | |-NamespaceNameSpecifier
+| | | | | |-n
+| | | | | `-::
+| | | | |-TypeNameSpecifier
+| | | | | |-S
+| | | | | `-::
+| | | | `-TypeWithTemplateNameSpecifier
+| | | |   |-template
+| | | |   |-TS
+| | | |   |-<
+| | | |   |-int
+| | | |   |->
+| | | |   `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-NamespaceNameSpecifier
+| | | | | |-n
+| | | | | `-::
+| | | | |-TypeNameSpecifier
+| | | | | |-S
+| | | | | `-::
+| | | | `-TypeNameSpecifier
+| | | |   |-TS
+| | | |   |-<
+| | | |   |-int
+| | | |   |->
+| | | |   `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-TypeNameSpecifier
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | |->
 | | | | | `-::
-| | | | |-NameSpecifier
-| | | | | |-a
+| | | | `-TypeNameSpecifier
+| | | |   |-S
+| | | |   `-::
+| | | `-UnqualifiedId
+| | |   |-f
+| | |   |-<
+| | |   |-int
+| | |   `->
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-TypeNameSpecifier
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | |->
 | | | | | `-::
-| | | | `-NameSpecifier
+| | | | `-TypeNameSpecifier
 | | | |   |-S
 | | | |   `-::
+| | | |-template
 | | | `-UnqualifiedId
 | | |   |-f
 | | |   |-<
@@ -944,7 +1074,7 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, Qualified

[PATCH] D84348: WIP: Add complete id-expression support to syntax trees

2020-07-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a reviewer: gribozavr2.
eduucaldas marked 6 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:101-106
+  UnknownNameSpecifier,
+  GlobalNameSpecifier,
+  NamespaceNameSpecifier,
+  TypeNameSpecifier,
+  IdentifierNameSpecifier,
+  TypeWithTemplateNameSpecifier

All of this is ephemeral, we are gonna have just one Name Specifier with a 
PointerUnion.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:206-276
+class NameSpecifier : public Tree {
 public:
-  NameSpecifier() : Tree(NodeKind::NameSpecifier) {}
+  NameSpecifier(NodeKind K) : Tree(K) {}
   static bool classof(const Node *N) {
-return N->kind() == NodeKind::NameSpecifier;
+return N->kind() == NodeKind::GlobalNameSpecifier ||
+   N->kind() == NodeKind::TypeNameSpecifier ||
+   N->kind() == NodeKind::NamespaceNameSpecifier ||

(bis) All of this is temporary, we are gonna have just one Name Specifier with 
a PointerUnion.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:768-769
-// Get `UnqualifiedId` from `DeclRefExpr`.
-// FIXME: Extract this logic so that it can be used by `MemberExpr`,
-// and other semantic constructs, now it is tied to `DeclRefExpr`.
-if (!S->hasExplicitTemplateArgs()) {

We extracted the logic into `getUnqualifiedSourceRange`



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:831-850
+  // FIXME: Same logic as DeclRefExpr. How to DRY?
+  SourceRange getUnqualifiedIdSourceRange(DependentScopeDeclRefExpr *S) {
+if (S->hasExplicitTemplateArgs())
+  return SourceRange(S->getNameInfo().getBeginLoc(), S->getRAngleLoc());
+return S->getNameInfo().getSourceRange();
+  }
+

This is the same logic as `DeclRefExpr`! Exacly the same code!
`DependentScopeDeclRefExpr` is important because it enables `T::template S::`



Comment at: clang/lib/Tooling/Syntax/Nodes.cpp:119-130
+  case NodeKind::GlobalNameSpecifier:
+return OS << "GlobalNameSpecifier";
+  case NodeKind::NamespaceNameSpecifier:
+return OS << "NamespaceNameSpecifier";
+  case NodeKind::TypeNameSpecifier:
+return OS << "TypeNameSpecifier";
+  case NodeKind::UnknownNameSpecifier:

(bis) All of this is temporary, we are gonna have just one Name Specifier with 
a PointerUnion.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:958-964
-struct X {
-  template static void f();
-  template
-  struct Y {
-static void f();
-  };
-};

I noticed that we don't need that as everything is dependent on the template 
anyways


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84348/new/

https://reviews.llvm.org/D84348



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84348: WIP: Add complete id-expression support to syntax trees

2020-07-23 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 280216.
eduucaldas added a comment.

Update API to new nested-name-specifier grammar rule


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84348/new/

https://reviews.llvm.org/D84348

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -988,13 +988,13 @@
 | | | |-NestedNameSpecifier
 | | | | |-GlobalNameSpecifier
 | | | | | `-::
-| | | | |-NamespaceNameSpecifier
+| | | | |-IdentifierNameSpecifier
 | | | | | |-n
 | | | | | `-::
-| | | | |-TypeNameSpecifier
+| | | | |-IdentifierNameSpecifier
 | | | | | |-S
 | | | | | `-::
-| | | | `-TypeWithTemplateNameSpecifier
+| | | | `-SimpleTemplateNameSpecifier
 | | | |   |-template
 | | | |   |-TS
 | | | |   |-<
@@ -1010,13 +1010,13 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-NamespaceNameSpecifier
+| | | | |-IdentifierNameSpecifier
 | | | | | |-n
 | | | | | `-::
-| | | | |-TypeNameSpecifier
+| | | | |-IdentifierNameSpecifier
 | | | | | |-S
 | | | | | `-::
-| | | | `-TypeNameSpecifier
+| | | | `-SimpleTemplateNameSpecifier
 | | | |   |-TS
 | | | |   |-<
 | | | |   |-int
@@ -1031,13 +1031,13 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-TypeNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
 | | | | | |-TS
 | | | | | |-<
 | | | | | |-int
 | | | | | |->
 | | | | | `-::
-| | | | `-TypeNameSpecifier
+| | | | `-IdentifierNameSpecifier
 | | | |   |-S
 | | | |   `-::
 | | | `-UnqualifiedId
@@ -1052,13 +1052,13 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-TypeNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
 | | | | | |-TS
 | | | | | |-<
 | | | | | |-int
 | | | | | |->
 | | | | | `-::
-| | | | `-TypeNameSpecifier
+| | | | `-IdentifierNameSpecifier
 | | | |   |-S
 | | | |   `-::
 | | | |-template
@@ -1116,10 +1116,10 @@
   | |-UnknownExpression
   | | |-IdExpression
   | | | |-NestedNameSpecifier
-  | | | | |-TypeNameSpecifier
+  | | | | |-IdentifierNameSpecifier
   | | | | | |-T
   | | | | | `-::
-  | | | | `-TypeWithTemplateNameSpecifier
+  | | | | `-SimpleTemplateNameSpecifier
   | | | |   |-template
   | | | |   |-U
   | | | |   |-<
@@ -1135,7 +1135,7 @@
   | |-UnknownExpression
   | | |-IdExpression
   | | | |-NestedNameSpecifier
-  | | | | |-TypeNameSpecifier
+  | | | | |-IdentifierNameSpecifier
   | | | | | |-T
   | | | | | `-::
   | | | | `-IdentifierNameSpecifier
@@ -1150,7 +1150,7 @@
   | |-UnknownExpression
   | | |-IdExpression
   | | | |-NestedNameSpecifier
-  | | | | `-TypeNameSpecifier
+  | | | | `-IdentifierNameSpecifier
   | | | |   |-T
   | | | |   `-::
   | | | |-template
@@ -1217,7 +1217,7 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | `-TypeNameSpecifier
+| | | | `-DecltypeNameSpecifier
 | | | |   |-decltype
 | | | |   |-(
 | | | |   |-IdExpression
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -118,16 +118,12 @@
 return OS << "MemberPointer";
   case NodeKind::GlobalNameSpecifier:
 return OS << "GlobalNameSpecifier";
-  case NodeKind::NamespaceNameSpecifier:
-return OS << "NamespaceNameSpecifier";
-  case NodeKind::TypeNameSpecifier:
-return OS << "TypeNameSpecifier";
-  case NodeKind::UnknownNameSpecifier:
-return OS << "UnknownNameSpecifier";
+  case NodeKind::DecltypeNameSpecifier:
+return OS << "DecltypeNameSpecifier";
   case NodeKind::IdentifierNameSpecifier:
 return OS << "IdentifierNameSpecifier";
-  case NodeKind::TypeWithTemplateNameSpecifier:
-return OS << "TypeWithTemplateNameSpecifier";
+  case NodeKind::SimpleTemplateNameSpecifier:
+return OS << "SimpleTemplateNameSpecifier";
   case NodeKind::NestedNameSpecifier:
 return OS << "NestedNameSpecifier";
   }
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -744,23 +744,37 @@
 return true;
   }
 
-  syntax::NameSpecifier *
-  BuildNameSpecifier(NestedNameSpecifier::SpecifierKind K) {
-sw

[PATCH] D84348: WIP: Add complete id-expression support to syntax trees

2020-07-24 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 280497.
eduucaldas added a comment.

- Improve getLocalSourceRange
- nested-name-specifier is now a ::-separated list of name-specifiers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84348/new/

https://reviews.llvm.org/D84348

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -867,24 +867,47 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
-namespace a {
+namespace n {
   struct S {
 template
-static T f(){}
+struct TS {
+  static void f();
+};
   };
 }
+template
+struct TS {
+  struct S {
+template
+static U f();
+  };
+};
 void test() {
-  ::  // global-namespace-specifier
-  a:: // namespace-specifier
-  S:: // type-name-specifier
+  :: // global-namespace-specifier
+  n::// namespace-specifier
+  S::// type-name-specifier
+  template TS:: // type-template-instantiation-specifier
+  f();
+
+  n::// namespace-specifier
+  S::// type-name-specifier
+  TS::  // type-template-instantiation-specifier
+  f();
+
+  TS:: // type-name-specifier
+  S::   // type-name-specifier
   f();
+
+  TS:: // type-name-specifier
+  S::   // type-name-specifier
+  template f();
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-NamespaceDefinition
 | |-namespace
-| |-a
+| |-n
 | |-{
 | |-SimpleDeclaration
 | | |-struct
@@ -898,19 +921,58 @@
 | | | | `-T
 | | | |->
 | | | `-SimpleDeclaration
-| | |   |-static
-| | |   |-T
-| | |   |-SimpleDeclarator
-| | |   | |-f
-| | |   | `-ParametersAndQualifiers
-| | |   |   |-(
-| | |   |   `-)
-| | |   `-CompoundStatement
-| | | |-{
-| | | `-}
+| | |   |-struct
+| | |   |-TS
+| | |   |-{
+| | |   |-SimpleDeclaration
+| | |   | |-static
+| | |   | |-void
+| | |   | |-SimpleDeclarator
+| | |   | | |-f
+| | |   | | `-ParametersAndQualifiers
+| | |   | |   |-(
+| | |   | |   `-)
+| | |   | `-;
+| | |   |-}
+| | |   `-;
 | | |-}
 | | `-;
 | `-}
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-TS
+|   |-{
+|   |-SimpleDeclaration
+|   | |-struct
+|   | |-S
+|   | |-{
+|   | |-TemplateDeclaration
+|   | | |-template
+|   | | |-<
+|   | | |-UnknownDeclaration
+|   | | | |-typename
+|   | | | `-U
+|   | | |->
+|   | | `-SimpleDeclaration
+|   | |   |-static
+|   | |   |-U
+|   | |   |-SimpleDeclarator
+|   | |   | |-f
+|   | |   | `-ParametersAndQualifiers
+|   | |   |   |-(
+|   | |   |   `-)
+|   | |   `-;
+|   | |-}
+|   | `-;
+|   |-}
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -924,14 +986,81 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-NameSpecifier
-| | | | | `-::
-| | | | |-NameSpecifier
-| | | | | |-a
-| | | | | `-::
-| | | | `-NameSpecifier
-| | | |   |-S
-| | | |   `-::
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-n
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | |-::
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-template
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-IdentifierNameSpecifier
+| | | | | `-n
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | |-::
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   |-f
+| | |   |-<
+| | |   |-int
+| | |   `->
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | |-::
+| | | |

[PATCH] D84348: WIP: Add complete id-expression support to syntax trees

2020-07-24 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 280511.
eduucaldas added a comment.

- Remove UnknownNameSpecifier, answer to comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84348/new/

https://reviews.llvm.org/D84348

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -867,24 +867,47 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
-namespace a {
+namespace n {
   struct S {
 template
-static T f(){}
+struct TS {
+  static void f();
+};
   };
 }
+template
+struct TS {
+  struct S {
+template
+static U f();
+  };
+};
 void test() {
-  ::  // global-namespace-specifier
-  a:: // namespace-specifier
-  S:: // type-name-specifier
+  :: // global-namespace-specifier
+  n::// namespace-specifier
+  S::// type-name-specifier
+  template TS:: // type-template-instantiation-specifier
+  f();
+
+  n::// namespace-specifier
+  S::// type-name-specifier
+  TS::  // type-template-instantiation-specifier
+  f();
+
+  TS:: // type-name-specifier
+  S::   // type-name-specifier
   f();
+
+  TS:: // type-name-specifier
+  S::   // type-name-specifier
+  template f();
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-NamespaceDefinition
 | |-namespace
-| |-a
+| |-n
 | |-{
 | |-SimpleDeclaration
 | | |-struct
@@ -898,19 +921,58 @@
 | | | | `-T
 | | | |->
 | | | `-SimpleDeclaration
-| | |   |-static
-| | |   |-T
-| | |   |-SimpleDeclarator
-| | |   | |-f
-| | |   | `-ParametersAndQualifiers
-| | |   |   |-(
-| | |   |   `-)
-| | |   `-CompoundStatement
-| | | |-{
-| | | `-}
+| | |   |-struct
+| | |   |-TS
+| | |   |-{
+| | |   |-SimpleDeclaration
+| | |   | |-static
+| | |   | |-void
+| | |   | |-SimpleDeclarator
+| | |   | | |-f
+| | |   | | `-ParametersAndQualifiers
+| | |   | |   |-(
+| | |   | |   `-)
+| | |   | `-;
+| | |   |-}
+| | |   `-;
 | | |-}
 | | `-;
 | `-}
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-TS
+|   |-{
+|   |-SimpleDeclaration
+|   | |-struct
+|   | |-S
+|   | |-{
+|   | |-TemplateDeclaration
+|   | | |-template
+|   | | |-<
+|   | | |-UnknownDeclaration
+|   | | | |-typename
+|   | | | `-U
+|   | | |->
+|   | | `-SimpleDeclaration
+|   | |   |-static
+|   | |   |-U
+|   | |   |-SimpleDeclarator
+|   | |   | |-f
+|   | |   | `-ParametersAndQualifiers
+|   | |   |   |-(
+|   | |   |   `-)
+|   | |   `-;
+|   | |-}
+|   | `-;
+|   |-}
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -924,14 +986,81 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-NameSpecifier
-| | | | | `-::
-| | | | |-NameSpecifier
-| | | | | |-a
-| | | | | `-::
-| | | | `-NameSpecifier
-| | | |   |-S
-| | | |   `-::
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-n
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | |-::
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-template
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-IdentifierNameSpecifier
+| | | | | `-n
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | |-::
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   |-f
+| | |   |-<
+| | |   |-int
+| | |   `->
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-TS
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+   

[PATCH] D84348: WIP: Add complete id-expression support to syntax trees

2020-07-27 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 280899.
eduucaldas marked 9 inline comments as done.
eduucaldas added a comment.

- Answer code review
- Simpler logic for `getUnqualifiedIdSourceRange` and inline it
- Remove ambiguously named variable NNS


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84348/new/

https://reviews.llvm.org/D84348

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -867,24 +867,47 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
-namespace a {
+namespace n {
   struct S {
 template
-static T f(){}
+struct ST {
+  static void f();
+};
   };
 }
+template
+struct ST {
+  struct S {
+template
+static U f();
+  };
+};
 void test() {
-  ::  // global-namespace-specifier
-  a:: // namespace-specifier
-  S:: // type-name-specifier
+  :: // global-namespace-specifier
+  n::// namespace-specifier
+  S::// type-name-specifier
+  template ST:: // type-template-instantiation-specifier
+  f();
+
+  n::// namespace-specifier
+  S::// type-name-specifier
+  ST::  // type-template-instantiation-specifier
+  f();
+
+  ST:: // type-name-specifier
+  S::   // type-name-specifier
   f();
+
+  ST:: // type-name-specifier
+  S::   // type-name-specifier
+  template f();
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-NamespaceDefinition
 | |-namespace
-| |-a
+| |-n
 | |-{
 | |-SimpleDeclaration
 | | |-struct
@@ -898,19 +921,58 @@
 | | | | `-T
 | | | |->
 | | | `-SimpleDeclaration
-| | |   |-static
-| | |   |-T
-| | |   |-SimpleDeclarator
-| | |   | |-f
-| | |   | `-ParametersAndQualifiers
-| | |   |   |-(
-| | |   |   `-)
-| | |   `-CompoundStatement
-| | | |-{
-| | | `-}
+| | |   |-struct
+| | |   |-ST
+| | |   |-{
+| | |   |-SimpleDeclaration
+| | |   | |-static
+| | |   | |-void
+| | |   | |-SimpleDeclarator
+| | |   | | |-f
+| | |   | | `-ParametersAndQualifiers
+| | |   | |   |-(
+| | |   | |   `-)
+| | |   | `-;
+| | |   |-}
+| | |   `-;
 | | |-}
 | | `-;
 | `-}
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-ST
+|   |-{
+|   |-SimpleDeclaration
+|   | |-struct
+|   | |-S
+|   | |-{
+|   | |-TemplateDeclaration
+|   | | |-template
+|   | | |-<
+|   | | |-UnknownDeclaration
+|   | | | |-typename
+|   | | | `-U
+|   | | |->
+|   | | `-SimpleDeclaration
+|   | |   |-static
+|   | |   |-U
+|   | |   |-SimpleDeclarator
+|   | |   | |-f
+|   | |   | `-ParametersAndQualifiers
+|   | |   |   |-(
+|   | |   |   `-)
+|   | |   `-;
+|   | |-}
+|   | `-;
+|   |-}
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -924,14 +986,81 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-NameSpecifier
-| | | | | `-::
-| | | | |-NameSpecifier
-| | | | | |-a
-| | | | | `-::
-| | | | `-NameSpecifier
-| | | |   |-S
-| | | |   `-::
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-n
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | |-::
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-template
+| | | | | |-ST
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-IdentifierNameSpecifier
+| | | | | `-n
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | |-::
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-ST
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-ST
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   |-f
+| | |   |-<
+| | |   |-int
+| | |   `->
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-ST
+| | | | | |-<

[PATCH] D84348: WIP: Add complete id-expression support to syntax trees

2020-07-27 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 2 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:834
+  // FIXME: I feel like this could be upstreamed.
+  SourceRange getUnqualifiedIdSourceRange(DeclRefExpr *S) {
+if (S->hasExplicitTemplateArgs())

gribozavr2 wrote:
> WDYM by "upstream"?
I meant to put that logic under the DeclRefExpr node, instead of here. But I 
found a way of writing this logic in a simpler way :). So I just inlined it!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84348/new/

https://reviews.llvm.org/D84348



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84781: Use PointerUnion instead of inheritance for alternative clauses in NNS

2020-07-28 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84781

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.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
@@ -987,18 +987,19 @@
 | | |-IdExpression
 | | | |-NestedNameSpecifier
 | | | | |-::
-| | | | |-IdentifierNameSpecifier
+| | | | |-NameSpecifier
 | | | | | `-n
 | | | | |-::
-| | | | |-IdentifierNameSpecifier
+| | | | |-NameSpecifier
 | | | | | `-S
 | | | | |-::
-| | | | |-SimpleTemplateNameSpecifier
-| | | | | |-template
-| | | | | |-ST
-| | | | | |-<
-| | | | | |-int
-| | | | | `->
+| | | | |-NameSpecifier
+| | | | | `-SimpleTemplateSpecifier
+| | | | |   |-template
+| | | | |   |-ST
+| | | | |   |-<
+| | | | |   |-int
+| | | | |   `->
 | | | | `-::
 | | | `-UnqualifiedId
 | | |   `-f
@@ -1009,17 +1010,18 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-IdentifierNameSpecifier
+| | | | |-NameSpecifier
 | | | | | `-n
 | | | | |-::
-| | | | |-IdentifierNameSpecifier
+| | | | |-NameSpecifier
 | | | | | `-S
 | | | | |-::
-| | | | |-SimpleTemplateNameSpecifier
-| | | | | |-ST
-| | | | | |-<
-| | | | | |-int
-| | | | | `->
+| | | | |-NameSpecifier
+| | | | | `-SimpleTemplateSpecifier
+| | | | |   |-ST
+| | | | |   |-<
+| | | | |   |-int
+| | | | |   `->
 | | | | `-::
 | | | `-UnqualifiedId
 | | |   `-f
@@ -1030,13 +1032,14 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-SimpleTemplateNameSpecifier
-| | | | | |-ST
-| | | | | |-<
-| | | | | |-int
-| | | | | `->
+| | | | |-NameSpecifier
+| | | | | `-SimpleTemplateSpecifier
+| | | | |   |-ST
+| | | | |   |-<
+| | | | |   |-int
+| | | | |   `->
 | | | | |-::
-| | | | |-IdentifierNameSpecifier
+| | | | |-NameSpecifier
 | | | | | `-S
 | | | | `-::
 | | | `-UnqualifiedId
@@ -1051,13 +1054,14 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-SimpleTemplateNameSpecifier
-| | | | | |-ST
-| | | | | |-<
-| | | | | |-int
-| | | | | `->
+| | | | |-NameSpecifier
+| | | | | `-SimpleTemplateSpecifier
+| | | | |   |-ST
+| | | | |   |-<
+| | | | |   |-int
+| | | | |   `->
 | | | | |-::
-| | | | |-IdentifierNameSpecifier
+| | | | |-NameSpecifier
 | | | | | `-S
 | | | | `-::
 | | | |-template
@@ -1115,15 +1119,16 @@
   | |-UnknownExpression
   | | |-IdExpression
   | | | |-NestedNameSpecifier
-  | | | | |-IdentifierNameSpecifier
+  | | | | |-NameSpecifier
   | | | | | `-T
   | | | | |-::
-  | | | | |-SimpleTemplateNameSpecifier
-  | | | | | |-template
-  | | | | | |-U
-  | | | | | |-<
-  | | | | | |-int
-  | | | | | `->
+  | | | | |-NameSpecifier
+  | | | | | `-SimpleTemplateSpecifier
+  | | | | |   |-template
+  | | | | |   |-U
+  | | | | |   |-<
+  | | | | |   |-int
+  | | | | |   `->
   | | | | `-::
   | | | `-UnqualifiedId
   | | |   `-f
@@ -1134,10 +1139,10 @@
   | |-UnknownExpression
   | | |-IdExpression
   | | | |-NestedNameSpecifier
-  | | | | |-IdentifierNameSpecifier
+  | | | | |-NameSpecifier
   | | | | | `-T
   | | | | |-::
-  | | | | |-IdentifierNameSpecifier
+  | | | | |-NameSpecifier
   | | | | | `-U
   | | | | `-::
   | | | `-UnqualifiedId
@@ -1149,7 +1154,7 @@
   | |-UnknownExpression
   | | |-IdExpression
   | | | |-NestedNameSpecifier
-  | | | | |-IdentifierNameSpecifier
+  | | | | |-NameSpecifier
   | | | | | `-T
   | | | | `-::
   | | | |-template
@@ -1216,13 +1221,14 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-DecltypeNameSpecifier
-| | | | | |-decltype
-| | | | | |-(
-| | | | | |-IdExpression
-| | | | | | `-UnqualifiedId
-| | | | | |   `-s
-| | | | | `-)
+| | | | |-NameSpecifier
+| | | | | `-DecltypeSpecifier
+| | | | |   |-decltype
+| | | | |   |-(
+| | | | |   |-IdExpression
+| | | | |   | `-UnqualifiedId
+| | | | |   |   `-s
+| | | | |   `-)
 | | | | `-::
 | | | `-UnqualifiedId
 | | |   `-f
Index: clang/lib/Too

[PATCH] D81135: Add support for IntegerLiteral in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81135

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -314,7 +314,7 @@
   |-SimpleDeclarator
   | |-b
   | |-=
-  | `-UnknownExpression
+  | `-IntegerLiteralExpression
   |   `-42
   `-;
 )txt");
@@ -371,7 +371,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -380,7 +380,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-CompoundStatement
@@ -390,7 +390,7 @@
 | `-IfStatement
 |   |-if
 |   |-(
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-0
 |   |-)
 |   `-CompoundStatement
@@ -461,7 +461,7 @@
 | |   |-a
 | |   `-ArraySubscript
 | | |-[
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-3
 | | `-]
 | `-;
@@ -501,7 +501,7 @@
 | | `-SimpleDeclarator
 | |   |-a
 | |   |-=
-| |   `-UnknownExpression
+| |   `-IntegerLiteralExpression
 | | `-10
 | `-;
 `-}
@@ -532,14 +532,14 @@
 |-SwitchStatement
 | |-switch
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
 |   |-{
 |   |-CaseStatement
 |   | |-case
-|   | |-UnknownExpression
+|   | |-IntegerLiteralExpression
 |   | | `-0
 |   | |-:
 |   | `-DefaultStatement
@@ -573,7 +573,7 @@
 |-WhileStatement
 | |-while
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -610,7 +610,7 @@
 | |-:
 | `-ReturnStatement
 |   |-return
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-100
 |   `-;
 `-}
@@ -648,7 +648,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-ExpressionStatement
@@ -699,6 +699,32 @@
 )txt");
 }
 
+TEST_P(SyntaxTreeTest, IntegerLiteralExpression) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  42;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-42
+| `-;
+`-}
+)txt");
+}
+
 TEST_P(SyntaxTreeTest, PostfixUnaryOperator) {
   expectTreeDumpEqual(
   R"cpp(
@@ -914,18 +940,18 @@
 |-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |--
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-==
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionStatement
@@ -933,7 +959,7 @@
 | | |-UnknownExpression
 | | | `-a
 | | |-=
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-1
 | `-;
 |-ExpressionStatement
@@ -941,23 +967,23 @@
 | | |-UnknownExpression
 | | | `-a
 | | |-<<=
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-1
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-||
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-0
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-&
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionStatement
@@ -965,7 +991,7 @@
 | | |-UnknownExpression
 | | | `-a
 | | |-^=
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-3
 | `-;
 `-}
@@ -1018,10 +1044,10 @@
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-bitand
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionS

[PATCH] D81135: Add support for IntegerLiteral in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 268382.
eduucaldas added a comment.

Add support for IntegerLiteral in SyntaxTree


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81135/new/

https://reviews.llvm.org/D81135

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -314,7 +314,7 @@
   |-SimpleDeclarator
   | |-b
   | |-=
-  | `-UnknownExpression
+  | `-IntegerLiteralExpression
   |   `-42
   `-;
 )txt");
@@ -371,7 +371,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -380,7 +380,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-CompoundStatement
@@ -390,7 +390,7 @@
 | `-IfStatement
 |   |-if
 |   |-(
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-0
 |   |-)
 |   `-CompoundStatement
@@ -461,7 +461,7 @@
 | |   |-a
 | |   `-ArraySubscript
 | | |-[
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-3
 | | `-]
 | `-;
@@ -501,7 +501,7 @@
 | | `-SimpleDeclarator
 | |   |-a
 | |   |-=
-| |   `-UnknownExpression
+| |   `-IntegerLiteralExpression
 | | `-10
 | `-;
 `-}
@@ -532,14 +532,14 @@
 |-SwitchStatement
 | |-switch
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
 |   |-{
 |   |-CaseStatement
 |   | |-case
-|   | |-UnknownExpression
+|   | |-IntegerLiteralExpression
 |   | | `-0
 |   | |-:
 |   | `-DefaultStatement
@@ -573,7 +573,7 @@
 |-WhileStatement
 | |-while
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -610,7 +610,7 @@
 | |-:
 | `-ReturnStatement
 |   |-return
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-100
 |   `-;
 `-}
@@ -648,7 +648,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-ExpressionStatement
@@ -699,6 +699,32 @@
 )txt");
 }
 
+TEST_P(SyntaxTreeTest, IntegerLiteralExpression) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  42;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-42
+| `-;
+`-}
+)txt");
+}
+
 TEST_P(SyntaxTreeTest, PostfixUnaryOperator) {
   expectTreeDumpEqual(
   R"cpp(
@@ -914,18 +940,18 @@
 |-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |--
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-==
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionStatement
@@ -933,7 +959,7 @@
 | | |-UnknownExpression
 | | | `-a
 | | |-=
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-1
 | `-;
 |-ExpressionStatement
@@ -941,23 +967,23 @@
 | | |-UnknownExpression
 | | | `-a
 | | |-<<=
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-1
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-||
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-0
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-&
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionStatement
@@ -965,7 +991,7 @@
 | | |-UnknownExpression
 | | | `-a
 | | |-^=
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-3
 | `-;
 `-}
@@ -1018,10 +1044,10 @@
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-bitand
-| | `-UnknownExpres

[PATCH] D81136: Define rules for naming NodeRole and apply them.

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81136

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp

Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -120,18 +120,14 @@
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
-  case syntax::NodeRole::IntegerLiteralExpression_literalToken:
+  case syntax::NodeRole::LiteralToken:
 return OS << "IntegerLiteralExpression_literalToken";
-  case syntax::NodeRole::CxxNullPtrExpression_keyword:
-return OS << "CxxNullPtrExpression_keyword";
-  case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
-return OS << "UnaryOperatorExpression_operatorToken";
+  case syntax::NodeRole::OperatorExpression_operatorToken:
+return OS << "OperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
 return OS << "UnaryOperatorExpression_operand";
   case syntax::NodeRole::BinaryOperatorExpression_leftHandSide:
 return OS << "BinaryOperatorExpression_leftHandSide";
-  case syntax::NodeRole::BinaryOperatorExpression_operatorToken:
-return OS << "BinaryOperatorExpression_operatorToken";
   case syntax::NodeRole::BinaryOperatorExpression_rightHandSide:
 return OS << "BinaryOperatorExpression_rightHandSide";
   case syntax::NodeRole::ReturnStatement_value:
@@ -154,8 +150,8 @@
 return OS << "ExplicitTemplateInstantiation_declaration";
   case syntax::NodeRole::ArraySubscript_sizeExpression:
 return OS << "ArraySubscript_sizeExpression";
-  case syntax::NodeRole::TrailingReturnType_arrow:
-return OS << "TrailingReturnType_arrow";
+  case syntax::NodeRole::TrailingReturnType_arrowToken:
+return OS << "TrailingReturnType_arrowToken";
   case syntax::NodeRole::TrailingReturnType_declarator:
 return OS << "TrailingReturnType_declarator";
   case syntax::NodeRole::ParametersAndQualifiers_parameter:
@@ -168,12 +164,12 @@
 
 syntax::Leaf *syntax::IntegerLiteralExpression::literal() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::IntegerLiteralExpression_literalToken));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
@@ -183,7 +179,7 @@
 
 syntax::Leaf *syntax::UnaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::UnaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::UnaryOperatorExpression::operand() {
@@ -193,7 +189,7 @@
 
 syntax::Leaf *syntax::BinaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::BinaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::rhs() {
@@ -402,7 +398,7 @@
 
 syntax::Leaf *syntax::TrailingReturnType::arrow() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::TrailingReturnType_arrow));
+  findChild(syntax::NodeRole::TrailingReturnType_arrowToken));
 }
 
 syntax::SimpleDeclarator *syntax::TrailingReturnType::declarator() {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -609,26 +609,22 @@
   }
 
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
-Builder.markChildToken(
-S->getLocation(),
-syntax::NodeRole::IntegerLiteralExpression_literalToken);
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::IntegerLiteralExpression, S);
 return true;
   }
 
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
-Builder.markChildToken(S->getLocation(),
-   syntax::NodeRole::CxxNullPtrExpression_keyword);
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::CxxNullPtrExpression, S);
 return true;
   }
 
   bool WalkUpFromUnaryOperator(UnaryOperator *S) {
-Builder.markChildToken(
-S->getOperatorLoc(),
-syntax::NodeRole::UnaryOperatorExpression_op

[PATCH] D81135: Add support for IntegerLiteral in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 268397.
eduucaldas added a comment.

answer comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81135/new/

https://reviews.llvm.org/D81135

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp

Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -120,18 +120,14 @@
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
-  case syntax::NodeRole::IntegerLiteralExpression_literalToken:
+  case syntax::NodeRole::LiteralToken:
 return OS << "IntegerLiteralExpression_literalToken";
-  case syntax::NodeRole::CxxNullPtrExpression_keyword:
-return OS << "CxxNullPtrExpression_keyword";
-  case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
-return OS << "UnaryOperatorExpression_operatorToken";
+  case syntax::NodeRole::OperatorExpression_operatorToken:
+return OS << "OperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
 return OS << "UnaryOperatorExpression_operand";
   case syntax::NodeRole::BinaryOperatorExpression_leftHandSide:
 return OS << "BinaryOperatorExpression_leftHandSide";
-  case syntax::NodeRole::BinaryOperatorExpression_operatorToken:
-return OS << "BinaryOperatorExpression_operatorToken";
   case syntax::NodeRole::BinaryOperatorExpression_rightHandSide:
 return OS << "BinaryOperatorExpression_rightHandSide";
   case syntax::NodeRole::ReturnStatement_value:
@@ -154,8 +150,8 @@
 return OS << "ExplicitTemplateInstantiation_declaration";
   case syntax::NodeRole::ArraySubscript_sizeExpression:
 return OS << "ArraySubscript_sizeExpression";
-  case syntax::NodeRole::TrailingReturnType_arrow:
-return OS << "TrailingReturnType_arrow";
+  case syntax::NodeRole::TrailingReturnType_arrowToken:
+return OS << "TrailingReturnType_arrowToken";
   case syntax::NodeRole::TrailingReturnType_declarator:
 return OS << "TrailingReturnType_declarator";
   case syntax::NodeRole::ParametersAndQualifiers_parameter:
@@ -168,12 +164,12 @@
 
 syntax::Leaf *syntax::IntegerLiteralExpression::literal() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::IntegerLiteralExpression_literalToken));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
@@ -183,7 +179,7 @@
 
 syntax::Leaf *syntax::UnaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::UnaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::UnaryOperatorExpression::operand() {
@@ -193,7 +189,7 @@
 
 syntax::Leaf *syntax::BinaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::BinaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::rhs() {
@@ -402,7 +398,7 @@
 
 syntax::Leaf *syntax::TrailingReturnType::arrow() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::TrailingReturnType_arrow));
+  findChild(syntax::NodeRole::TrailingReturnType_arrowToken));
 }
 
 syntax::SimpleDeclarator *syntax::TrailingReturnType::declarator() {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -609,26 +609,22 @@
   }
 
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
-Builder.markChildToken(
-S->getLocation(),
-syntax::NodeRole::IntegerLiteralExpression_literalToken);
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::IntegerLiteralExpression, S);
 return true;
   }
 
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
-Builder.markChildToken(S->getLocation(),
-   syntax::NodeRole::CxxNullPtrExpression_keyword);
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::CxxNullPtrExpression, S);
 return true;
   }
 
   bool WalkUpFromUnaryOperator(UnaryOperator *S) {
-Builder.markChildToken(
-S->getOperatorLoc(

[PATCH] D81135: Add support for IntegerLiteral in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 268403.
eduucaldas added a comment.

fix


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81135/new/

https://reviews.llvm.org/D81135

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -314,7 +314,7 @@
   |-SimpleDeclarator
   | |-b
   | |-=
-  | `-UnknownExpression
+  | `-IntegerLiteralExpression
   |   `-42
   `-;
 )txt");
@@ -371,7 +371,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -380,7 +380,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-CompoundStatement
@@ -390,7 +390,7 @@
 | `-IfStatement
 |   |-if
 |   |-(
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-0
 |   |-)
 |   `-CompoundStatement
@@ -461,7 +461,7 @@
 | |   |-a
 | |   `-ArraySubscript
 | | |-[
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-3
 | | `-]
 | `-;
@@ -501,7 +501,7 @@
 | | `-SimpleDeclarator
 | |   |-a
 | |   |-=
-| |   `-UnknownExpression
+| |   `-IntegerLiteralExpression
 | | `-10
 | `-;
 `-}
@@ -532,14 +532,14 @@
 |-SwitchStatement
 | |-switch
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
 |   |-{
 |   |-CaseStatement
 |   | |-case
-|   | |-UnknownExpression
+|   | |-IntegerLiteralExpression
 |   | | `-0
 |   | |-:
 |   | `-DefaultStatement
@@ -573,7 +573,7 @@
 |-WhileStatement
 | |-while
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -610,7 +610,7 @@
 | |-:
 | `-ReturnStatement
 |   |-return
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-100
 |   `-;
 `-}
@@ -648,7 +648,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-ExpressionStatement
@@ -699,6 +699,32 @@
 )txt");
 }
 
+TEST_P(SyntaxTreeTest, IntegerLiteralExpression) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  42;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-42
+| `-;
+`-}
+)txt");
+}
+
 TEST_P(SyntaxTreeTest, PostfixUnaryOperator) {
   expectTreeDumpEqual(
   R"cpp(
@@ -914,18 +940,18 @@
 |-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |--
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-==
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionStatement
@@ -933,7 +959,7 @@
 | | |-UnknownExpression
 | | | `-a
 | | |-=
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-1
 | `-;
 |-ExpressionStatement
@@ -941,23 +967,23 @@
 | | |-UnknownExpression
 | | | `-a
 | | |-<<=
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-1
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-||
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-0
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-&
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-2
 | `-;
 |-ExpressionStatement
@@ -965,7 +991,7 @@
 | | |-UnknownExpression
 | | | `-a
 | | |-^=
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression
 | |   `-3
 | `-;
 `-}
@@ -1018,10 +1044,10 @@
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-1
 | | |-bitand
-| | `-UnknownExpression
+| | `-IntegerLiteralExpression

[PATCH] D81135: Add support for IntegerLiteral in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 268420.
eduucaldas added a comment.

answering comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81135/new/

https://reviews.llvm.org/D81135

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -64,6 +64,11 @@
Language == Lang_CXX17 || Language == Lang_CXX20;
   }
 
+  bool isCXX14OrLater() const {
+return Language == Lang_CXX14 || Language == Lang_CXX17 ||
+   Language == Lang_CXX20;
+  }
+
   bool supportsCXXDynamicExceptionSpecification() const {
 return Language == Lang_CXX03 || Language == Lang_CXX11 ||
Language == Lang_CXX14;
@@ -314,7 +319,7 @@
   |-SimpleDeclarator
   | |-b
   | |-=
-  | `-UnknownExpression
+  | `-IntegerLiteralExpression
   |   `-42
   `-;
 )txt");
@@ -371,7 +376,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -380,7 +385,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-CompoundStatement
@@ -390,7 +395,7 @@
 | `-IfStatement
 |   |-if
 |   |-(
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-0
 |   |-)
 |   `-CompoundStatement
@@ -461,7 +466,7 @@
 | |   |-a
 | |   `-ArraySubscript
 | | |-[
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-3
 | | `-]
 | `-;
@@ -501,7 +506,7 @@
 | | `-SimpleDeclarator
 | |   |-a
 | |   |-=
-| |   `-UnknownExpression
+| |   `-IntegerLiteralExpression
 | | `-10
 | `-;
 `-}
@@ -532,14 +537,14 @@
 |-SwitchStatement
 | |-switch
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
 |   |-{
 |   |-CaseStatement
 |   | |-case
-|   | |-UnknownExpression
+|   | |-IntegerLiteralExpression
 |   | | `-0
 |   | |-:
 |   | `-DefaultStatement
@@ -573,7 +578,7 @@
 |-WhileStatement
 | |-while
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -610,7 +615,7 @@
 | |-:
 | `-ReturnStatement
 |   |-return
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-100
 |   `-;
 `-}
@@ -648,7 +653,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-ExpressionStatement
@@ -699,6 +704,149 @@
 )txt");
 }
 
+TEST_P(SyntaxTreeTest, IntegerLiteral) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  12;
+  12u;
+  12l;
+  12ul;
+  014;
+  0XC;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12u
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12l
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12ul
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-014
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-0XC
+| `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, LongLongLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  12ll;
+  12ull;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12ll
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12ull
+| `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, BinaryLiteral) {
+  if (!GetParam().isCXX14OrLater()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  0b1100;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-0b1100
+| `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, QuotedIntegerLiter

[PATCH] D81135: Add support for IntegerLiteral in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 268428.
eduucaldas marked 4 inline comments as done.
eduucaldas added a comment.

Fix nits


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81135/new/

https://reviews.llvm.org/D81135

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -64,6 +64,11 @@
Language == Lang_CXX17 || Language == Lang_CXX20;
   }
 
+  bool isCXX14OrLater() const {
+return Language == Lang_CXX14 || Language == Lang_CXX17 ||
+   Language == Lang_CXX20;
+  }
+
   bool supportsCXXDynamicExceptionSpecification() const {
 return Language == Lang_CXX03 || Language == Lang_CXX11 ||
Language == Lang_CXX14;
@@ -314,7 +319,7 @@
   |-SimpleDeclarator
   | |-b
   | |-=
-  | `-UnknownExpression
+  | `-IntegerLiteralExpression
   |   `-42
   `-;
 )txt");
@@ -371,7 +376,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -380,7 +385,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-CompoundStatement
@@ -390,7 +395,7 @@
 | `-IfStatement
 |   |-if
 |   |-(
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-0
 |   |-)
 |   `-CompoundStatement
@@ -461,7 +466,7 @@
 | |   |-a
 | |   `-ArraySubscript
 | | |-[
-| | |-UnknownExpression
+| | |-IntegerLiteralExpression
 | | | `-3
 | | `-]
 | `-;
@@ -501,7 +506,7 @@
 | | `-SimpleDeclarator
 | |   |-a
 | |   |-=
-| |   `-UnknownExpression
+| |   `-IntegerLiteralExpression
 | | `-10
 | `-;
 `-}
@@ -532,14 +537,14 @@
 |-SwitchStatement
 | |-switch
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
 |   |-{
 |   |-CaseStatement
 |   | |-case
-|   | |-UnknownExpression
+|   | |-IntegerLiteralExpression
 |   | | `-0
 |   | |-:
 |   | `-DefaultStatement
@@ -573,7 +578,7 @@
 |-WhileStatement
 | |-while
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | `-CompoundStatement
@@ -610,7 +615,7 @@
 | |-:
 | `-ReturnStatement
 |   |-return
-|   |-UnknownExpression
+|   |-IntegerLiteralExpression
 |   | `-100
 |   `-;
 `-}
@@ -648,7 +653,7 @@
 |-IfStatement
 | |-if
 | |-(
-| |-UnknownExpression
+| |-IntegerLiteralExpression
 | | `-1
 | |-)
 | |-ExpressionStatement
@@ -699,6 +704,149 @@
 )txt");
 }
 
+TEST_P(SyntaxTreeTest, IntegerLiteral) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  12;
+  12u;
+  12l;
+  12ul;
+  014;
+  0XC;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12u
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12l
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12ul
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-014
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-0XC
+| `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, IntegerLiteralLongLong) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  12ll;
+  12ull;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12ll
+| `-;
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-12ull
+| `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, IntegerLiteralBinary) {
+  if (!GetParam().isCXX14OrLater()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  0b1100;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IntegerLiteralExpression
+| | `-0b1100
+| `-;
+`-}
+)txt")

[PATCH] D81155: Rename arrow -> arrowToken for unified naming

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a reviewer: gribozavr2.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81155

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/Nodes.cpp


Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -400,7 +400,7 @@
   findChild(syntax::NodeRole::CloseParen));
 }
 
-syntax::Leaf *syntax::TrailingReturnType::arrow() {
+syntax::Leaf *syntax::TrailingReturnType::arrowToken() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::TrailingReturnType_arrow));
 }
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -639,7 +639,7 @@
 return N->kind() == NodeKind::TrailingReturnType;
   }
   // TODO: add accessors for specifiers.
-  syntax::Leaf *arrow();
+  syntax::Leaf *arrowToken();
   syntax::SimpleDeclarator *declarator();
 };
 


Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -400,7 +400,7 @@
   findChild(syntax::NodeRole::CloseParen));
 }
 
-syntax::Leaf *syntax::TrailingReturnType::arrow() {
+syntax::Leaf *syntax::TrailingReturnType::arrowToken() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::TrailingReturnType_arrow));
 }
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -639,7 +639,7 @@
 return N->kind() == NodeKind::TrailingReturnType;
   }
   // TODO: add accessors for specifiers.
-  syntax::Leaf *arrow();
+  syntax::Leaf *arrowToken();
   syntax::SimpleDeclarator *declarator();
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81157: Propose naming principle for NodeRole and apply it

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp

Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -120,18 +120,14 @@
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
-  case syntax::NodeRole::IntegerLiteralExpression_literalToken:
+  case syntax::NodeRole::LiteralToken:
 return OS << "IntegerLiteralExpression_literalToken";
-  case syntax::NodeRole::CxxNullPtrExpression_keyword:
-return OS << "CxxNullPtrExpression_keyword";
-  case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
-return OS << "UnaryOperatorExpression_operatorToken";
+  case syntax::NodeRole::OperatorExpression_operatorToken:
+return OS << "OperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
 return OS << "UnaryOperatorExpression_operand";
   case syntax::NodeRole::BinaryOperatorExpression_leftHandSide:
 return OS << "BinaryOperatorExpression_leftHandSide";
-  case syntax::NodeRole::BinaryOperatorExpression_operatorToken:
-return OS << "BinaryOperatorExpression_operatorToken";
   case syntax::NodeRole::BinaryOperatorExpression_rightHandSide:
 return OS << "BinaryOperatorExpression_rightHandSide";
   case syntax::NodeRole::ReturnStatement_value:
@@ -154,8 +150,8 @@
 return OS << "ExplicitTemplateInstantiation_declaration";
   case syntax::NodeRole::ArraySubscript_sizeExpression:
 return OS << "ArraySubscript_sizeExpression";
-  case syntax::NodeRole::TrailingReturnType_arrow:
-return OS << "TrailingReturnType_arrow";
+  case syntax::NodeRole::TrailingReturnType_arrowToken:
+return OS << "TrailingReturnType_arrowToken";
   case syntax::NodeRole::TrailingReturnType_declarator:
 return OS << "TrailingReturnType_declarator";
   case syntax::NodeRole::ParametersAndQualifiers_parameter:
@@ -168,12 +164,12 @@
 
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::IntegerLiteralExpression_literalToken));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
@@ -183,7 +179,7 @@
 
 syntax::Leaf *syntax::UnaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::UnaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::UnaryOperatorExpression::operand() {
@@ -193,7 +189,7 @@
 
 syntax::Leaf *syntax::BinaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::BinaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::rhs() {
@@ -402,7 +398,7 @@
 
 syntax::Leaf *syntax::TrailingReturnType::arrow() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::TrailingReturnType_arrow));
+  findChild(syntax::NodeRole::TrailingReturnType_arrowToken));
 }
 
 syntax::SimpleDeclarator *syntax::TrailingReturnType::declarator() {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -609,26 +609,22 @@
   }
 
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
-Builder.markChildToken(
-S->getLocation(),
-syntax::NodeRole::IntegerLiteralExpression_literalToken);
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::IntegerLiteralExpression, S);
 return true;
   }
 
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
-Builder.markChildToken(S->getLocation(),
-   syntax::NodeRole::CxxNullPtrExpression_keyword);
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::CxxNullPtrExpression, S);
 return true;
   }
 
   bool WalkUpFromUnaryOperator(UnaryOperator *S) {
-Builder.markChildToken(
-S->getOperatorLoc(),
-syntax::NodeRole::UnaryOperatorExpressi

[PATCH] D81168: Add support for id-expression in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a subscriber: gribozavr2.
eduucaldas marked an inline comment as done.
eduucaldas added inline comments.
eduucaldas marked an inline comment as not done.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:829
+| | | | | `-::
+| | | | `-TypeSpecifier
+| | | |   |-S

Perhaps we shouldn't differ between specifiers as that is semantical information


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81168

Files:
  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
@@ -692,6 +692,152 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UnqualifiedId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test(int b) {
+  int a;
+  a = b;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-int
+| | `-SimpleDeclarator
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-a
+| | |-=
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-b
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, QualifiedId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+namespace a {
+  namespace b {
+struct S {
+  int i;
+  static void f(){}
+};
+  }
+}
+void test(int b) {
+  ::a::b::S::f();
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-NamespaceDefinition
+| |-namespace
+| |-a
+| |-{
+| |-NamespaceDefinition
+| | |-namespace
+| | |-b
+| | |-{
+| | |-SimpleDeclaration
+| | | |-struct
+| | | |-S
+| | | |-{
+| | | |-SimpleDeclaration
+| | | | |-int
+| | | | |-SimpleDeclarator
+| | | | | `-i
+| | | | `-;
+| | | |-SimpleDeclaration
+| | | | |-static
+| | | | |-void
+| | | | |-SimpleDeclarator
+| | | | | |-f
+| | | | | `-ParametersAndQualifiers
+| | | | |   |-(
+| | | | |   `-)
+| | | | `-CompoundStatement
+| | | |   |-{
+| | | |   `-}
+| | | |-}
+| | | `-;
+| | `-}
+| `-}
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-a
+| | |-::
+| | |-b
+| | |-::
+| | |-S
+| | `-SimpleDeclarator
+| |   `-UnknownExpression
+| | `-s
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NameSpecifiers
+| | | | |-GlobalNamespaceSpecifier
+| | | | | `::
+| | | | |-NamespaceSpecifier
+| | | | | |-a
+| | | | | `-::
+| | | | |-NamespaceSpecifier
+| | | | | |-b
+| | | | | `-::
+| | | | `-TypeSpecifier
+| | | |   |-S
+| | | |   `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
   if (!GetParam().isCXX11OrLater()) {
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81168: Add support for id-expression in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a subscriber: gribozavr2.
eduucaldas marked an inline comment as done.
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:829
+| | | | | `-::
+| | | | `-TypeSpecifier
+| | | |   |-S

Perhaps we shouldn't differ between specifiers as that is semantical information


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81168: Add support for id-expression in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 268503.
eduucaldas marked an inline comment as done.
eduucaldas added a comment.

.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168

Files:
  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
@@ -692,6 +692,152 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UnqualifiedId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test(int b) {
+  int a;
+  a = b;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-int
+| | `-SimpleDeclarator
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-a
+| | |-=
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-b
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, QualifiedId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+namespace a {
+  namespace b {
+struct S {
+  int i;
+  static void f(){}
+};
+  }
+}
+void test(int b) {
+  ::a::b::S::f();
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-NamespaceDefinition
+| |-namespace
+| |-a
+| |-{
+| |-NamespaceDefinition
+| | |-namespace
+| | |-b
+| | |-{
+| | |-SimpleDeclaration
+| | | |-struct
+| | | |-S
+| | | |-{
+| | | |-SimpleDeclaration
+| | | | |-int
+| | | | |-SimpleDeclarator
+| | | | | `-i
+| | | | `-;
+| | | |-SimpleDeclaration
+| | | | |-static
+| | | | |-void
+| | | | |-SimpleDeclarator
+| | | | | |-f
+| | | | | `-ParametersAndQualifiers
+| | | | |   |-(
+| | | | |   `-)
+| | | | `-CompoundStatement
+| | | |   |-{
+| | | |   `-}
+| | | |-}
+| | | `-;
+| | `-}
+| `-}
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-a
+| | |-::
+| | |-b
+| | |-::
+| | |-S
+| | `-SimpleDeclarator
+| |   `-UnknownExpression
+| | `-s
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-GlobalNamespaceSpecifier
+| | | | | `::
+| | | | |-NamespaceNameSpecifier
+| | | | | |-a
+| | | | | `-::
+| | | | |-NamespaceNameSpecifier
+| | | | | |-b
+| | | | | `-::
+| | | | `-TypeNameSpecifier
+| | | |   |-S
+| | | |   `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
   if (!GetParam().isCXX11OrLater()) {
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81157: Propose naming principle for NodeRole and apply it

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:94
 /// a binary expression'. Used for implementing accessors.
+// How to name NodeRole:
+// If the child node is a token/keyword, end its name with 'Token'/'Keyword'

gribozavr2 wrote:
> I'd suggest to make this into a doc comment, but phrase it in a way that is 
> useful for users, so that they can understand the pattern too. For example:
> 
> Some roles describe parent/child relations that occur multiple times in 
> language grammar. We define only one role to describe all instances of such 
> recurring relations. For example, grammar for both "if" and "while" 
> statements requires an opening paren and a closing paren. The opening paren 
> token is assigned the `OpenParen` role regardless of whether it appears as a 
> child of `IfStatement` or `WhileStatement` node. More generally, when grammar 
> requires a certain fixed token (like a specific keyword, or an opening 
> paren), we define a role for this token and use it across all grammar rules 
> with the same requirement. Names of such reusable roles end with a `~Token` 
> or a `~Keyword` suffix.
> 
> Some roles are assigned only to child nodes of one specific parent syntax 
> node type. Names of such roles start with the name of the parent syntax tree 
> node type. For example, a syntax node with a role 
> `BinaryOperatorExpression_leftHandSide` can only appear as a child of a 
> `BinaryOperatorExpression` node.
> 
> 
Thank you a lot. This is really well explained



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:124
   IfStatement_thenStatement,
   IfStatement_elseKeyword,
   IfStatement_elseStatement,

gribozavr2 wrote:
> Shouldn't `elseKeyword` have no prefix?
When a keyword can only be used by IfStatement, then I think it actually helps 
readability to have it prepended with the ParentKind. Here everything is nicely 
grouped, and if someone needs to change IfStatement, it is clear to see where 
to make the change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81157/new/

https://reviews.llvm.org/D81157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81168: Add support for id-expression in SyntaxTree

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:829
+| | | | | `-::
+| | | | `-TypeSpecifier
+| | | |   |-S

eduucaldas wrote:
> Perhaps we shouldn't differ between specifiers as that is semantical 
> information
Followed the [[ https://eel.is/c++draft/expr.prim.id.qual | grammar ]], but 
added specifier in the end as we also hold the `::` and not only the names


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81157: Propose naming principle for NodeRole and apply it

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 268502.
eduucaldas marked 2 inline comments as done.
eduucaldas added a comment.

Fix cout, add explanation


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81157/new/

https://reviews.llvm.org/D81157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp

Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -110,6 +110,8 @@
 return OS << "CloseParen";
   case syntax::NodeRole::IntroducerKeyword:
 return OS << "IntroducerKeyword";
+  case syntax::NodeRole::LiteralToken:
+return OS << "LiteralToken";
   case syntax::NodeRole::BodyStatement:
 return OS << "BodyStatement";
   case syntax::NodeRole::CaseStatement_value:
@@ -120,18 +122,12 @@
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
-  case syntax::NodeRole::IntegerLiteralExpression_literalToken:
-return OS << "IntegerLiteralExpression_literalToken";
-  case syntax::NodeRole::CxxNullPtrExpression_keyword:
-return OS << "CxxNullPtrExpression_keyword";
-  case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
-return OS << "UnaryOperatorExpression_operatorToken";
+  case syntax::NodeRole::OperatorExpression_operatorToken:
+return OS << "OperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
 return OS << "UnaryOperatorExpression_operand";
   case syntax::NodeRole::BinaryOperatorExpression_leftHandSide:
 return OS << "BinaryOperatorExpression_leftHandSide";
-  case syntax::NodeRole::BinaryOperatorExpression_operatorToken:
-return OS << "BinaryOperatorExpression_operatorToken";
   case syntax::NodeRole::BinaryOperatorExpression_rightHandSide:
 return OS << "BinaryOperatorExpression_rightHandSide";
   case syntax::NodeRole::ReturnStatement_value:
@@ -154,8 +150,8 @@
 return OS << "ExplicitTemplateInstantiation_declaration";
   case syntax::NodeRole::ArraySubscript_sizeExpression:
 return OS << "ArraySubscript_sizeExpression";
-  case syntax::NodeRole::TrailingReturnType_arrow:
-return OS << "TrailingReturnType_arrow";
+  case syntax::NodeRole::TrailingReturnType_arrowToken:
+return OS << "TrailingReturnType_arrowToken";
   case syntax::NodeRole::TrailingReturnType_declarator:
 return OS << "TrailingReturnType_declarator";
   case syntax::NodeRole::ParametersAndQualifiers_parameter:
@@ -168,12 +164,12 @@
 
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::IntegerLiteralExpression_literalToken));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
@@ -183,7 +179,7 @@
 
 syntax::Leaf *syntax::UnaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::UnaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::UnaryOperatorExpression::operand() {
@@ -193,7 +189,7 @@
 
 syntax::Leaf *syntax::BinaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::BinaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::rhs() {
@@ -402,7 +398,7 @@
 
 syntax::Leaf *syntax::TrailingReturnType::arrow() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::TrailingReturnType_arrow));
+  findChild(syntax::NodeRole::TrailingReturnType_arrowToken));
 }
 
 syntax::SimpleDeclarator *syntax::TrailingReturnType::declarator() {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -609,26 +609,22 @@
   }
 
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
-Builder.markChildToken(
-S->getLocation(),
-syntax::NodeRole::IntegerLiteralExpression_literalToken);
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::IntegerLiteralExpression, S);
 return true;
   }
 
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
-Builder.markChildToken(S->getLocation(),
-   syntax::NodeRole::CxxNullPtrE

[PATCH] D81157: Propose naming principle for NodeRole and apply it

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 268519.
eduucaldas added a comment.

fixed


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81157/new/

https://reviews.llvm.org/D81157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp

Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -110,6 +110,12 @@
 return OS << "CloseParen";
   case syntax::NodeRole::IntroducerKeyword:
 return OS << "IntroducerKeyword";
+  case syntax::NodeRole::LiteralToken:
+return OS << "LiteralToken";
+  case syntax::NodeRole::ArrowToken:
+return OS << "ArrowToken";
+  case syntax::NodeRole::ExternKeyword:
+return OS << "ExternKeyword";
   case syntax::NodeRole::BodyStatement:
 return OS << "BodyStatement";
   case syntax::NodeRole::CaseStatement_value:
@@ -120,18 +126,12 @@
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
-  case syntax::NodeRole::IntegerLiteralExpression_literalToken:
-return OS << "IntegerLiteralExpression_literalToken";
-  case syntax::NodeRole::CxxNullPtrExpression_keyword:
-return OS << "CxxNullPtrExpression_keyword";
-  case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
-return OS << "UnaryOperatorExpression_operatorToken";
+  case syntax::NodeRole::OperatorExpression_operatorToken:
+return OS << "OperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
 return OS << "UnaryOperatorExpression_operand";
   case syntax::NodeRole::BinaryOperatorExpression_leftHandSide:
 return OS << "BinaryOperatorExpression_leftHandSide";
-  case syntax::NodeRole::BinaryOperatorExpression_operatorToken:
-return OS << "BinaryOperatorExpression_operatorToken";
   case syntax::NodeRole::BinaryOperatorExpression_rightHandSide:
 return OS << "BinaryOperatorExpression_rightHandSide";
   case syntax::NodeRole::ReturnStatement_value:
@@ -148,14 +148,10 @@
 return OS << "SimpleDeclaration_declarator";
   case syntax::NodeRole::TemplateDeclaration_declaration:
 return OS << "TemplateDeclaration_declaration";
-  case syntax::NodeRole::ExplicitTemplateInstantiation_externKeyword:
-return OS << "ExplicitTemplateInstantiation_externKeyword";
   case syntax::NodeRole::ExplicitTemplateInstantiation_declaration:
 return OS << "ExplicitTemplateInstantiation_declaration";
   case syntax::NodeRole::ArraySubscript_sizeExpression:
 return OS << "ArraySubscript_sizeExpression";
-  case syntax::NodeRole::TrailingReturnType_arrow:
-return OS << "TrailingReturnType_arrow";
   case syntax::NodeRole::TrailingReturnType_declarator:
 return OS << "TrailingReturnType_declarator";
   case syntax::NodeRole::ParametersAndQualifiers_parameter:
@@ -168,12 +164,12 @@
 
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::IntegerLiteralExpression_literalToken));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
@@ -183,7 +179,7 @@
 
 syntax::Leaf *syntax::UnaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::UnaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::UnaryOperatorExpression::operand() {
@@ -193,7 +189,7 @@
 
 syntax::Leaf *syntax::BinaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::BinaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::rhs() {
@@ -367,7 +363,7 @@
 
 syntax::Leaf *syntax::ExplicitTemplateInstantiation::externKeyword() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::ExplicitTemplateInstantiation_externKeyword));
+  findChild(syntax::NodeRole::ExternKeyword));
 }
 
 syntax::Declaration *syntax::ExplicitTemplateInstantiation::declaration() {
@@ -402,7 +398,7 @@
 
 syntax::Leaf *syntax::TrailingReturnType::arrow() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::TrailingReturnType_arrow));
+  findChild(syntax::NodeRole::ArrowToken));
 }
 
 syntax::SimpleDeclarator *syntax::TrailingReturnType::declarator() {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax

[PATCH] D81157: Propose naming principle for NodeRole and apply it

2020-06-04 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 268517.
eduucaldas added a comment.

`ArrowToken`, `ExternKeyword`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81157/new/

https://reviews.llvm.org/D81157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp

Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -110,6 +110,8 @@
 return OS << "CloseParen";
   case syntax::NodeRole::IntroducerKeyword:
 return OS << "IntroducerKeyword";
+  case syntax::NodeRole::LiteralToken:
+return OS << "LiteralToken";
   case syntax::NodeRole::BodyStatement:
 return OS << "BodyStatement";
   case syntax::NodeRole::CaseStatement_value:
@@ -120,18 +122,12 @@
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
-  case syntax::NodeRole::IntegerLiteralExpression_literalToken:
-return OS << "IntegerLiteralExpression_literalToken";
-  case syntax::NodeRole::CxxNullPtrExpression_keyword:
-return OS << "CxxNullPtrExpression_keyword";
-  case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
-return OS << "UnaryOperatorExpression_operatorToken";
+  case syntax::NodeRole::OperatorExpression_operatorToken:
+return OS << "OperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
 return OS << "UnaryOperatorExpression_operand";
   case syntax::NodeRole::BinaryOperatorExpression_leftHandSide:
 return OS << "BinaryOperatorExpression_leftHandSide";
-  case syntax::NodeRole::BinaryOperatorExpression_operatorToken:
-return OS << "BinaryOperatorExpression_operatorToken";
   case syntax::NodeRole::BinaryOperatorExpression_rightHandSide:
 return OS << "BinaryOperatorExpression_rightHandSide";
   case syntax::NodeRole::ReturnStatement_value:
@@ -148,14 +144,14 @@
 return OS << "SimpleDeclaration_declarator";
   case syntax::NodeRole::TemplateDeclaration_declaration:
 return OS << "TemplateDeclaration_declaration";
-  case syntax::NodeRole::ExplicitTemplateInstantiation_externKeyword:
-return OS << "ExplicitTemplateInstantiation_externKeyword";
+  case syntax::NodeRole::ExternKeyword:
+return OS << "ExternKeyword";
   case syntax::NodeRole::ExplicitTemplateInstantiation_declaration:
 return OS << "ExplicitTemplateInstantiation_declaration";
   case syntax::NodeRole::ArraySubscript_sizeExpression:
 return OS << "ArraySubscript_sizeExpression";
-  case syntax::NodeRole::TrailingReturnType_arrow:
-return OS << "TrailingReturnType_arrow";
+  case syntax::NodeRole::ArrowToken:
+return OS << "ArrowToken";
   case syntax::NodeRole::TrailingReturnType_declarator:
 return OS << "TrailingReturnType_declarator";
   case syntax::NodeRole::ParametersAndQualifiers_parameter:
@@ -168,12 +164,12 @@
 
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::IntegerLiteralExpression_literalToken));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+  findChild(syntax::NodeRole::LiteralToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
@@ -183,7 +179,7 @@
 
 syntax::Leaf *syntax::UnaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::UnaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::UnaryOperatorExpression::operand() {
@@ -193,7 +189,7 @@
 
 syntax::Leaf *syntax::BinaryOperatorExpression::operatorToken() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::BinaryOperatorExpression_operatorToken));
+  findChild(syntax::NodeRole::OperatorExpression_operatorToken));
 }
 
 syntax::Expression *syntax::BinaryOperatorExpression::rhs() {
@@ -367,7 +363,7 @@
 
 syntax::Leaf *syntax::ExplicitTemplateInstantiation::externKeyword() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::ExplicitTemplateInstantiation_externKeyword));
+  findChild(syntax::NodeRole::ExternKeyword));
 }
 
 syntax::Declaration *syntax::ExplicitTemplateInstantiation::declaration() {
@@ -402,7 +398,7 @@
 
 syntax::Leaf *syntax::TrailingReturnType::arrow() {
   return llvm::cast_or_null(
-  findChild(syntax::NodeRole::TrailingReturnType_arrow));
+  findChild(syntax::NodeRole::ArrowToken));
 }
 
 syntax::SimpleDeclarator *syntax::TrailingReturnType::declarator() {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- c

[PATCH] D81280: (Incomplete)Add support for id-expression

2020-06-05 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- TODO: Differ between NameQualifiers
- TODO: Box all operators
- Done: Treat NestedNameSpecifiers
- Done: [Try] Unbox all operators


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81280

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -485,7 +485,7 @@
 | | |-SimpleDeclarator
 | | | `-x
 | | `-:
-| |-UnknownExpression
+| |-IdExpression
 | | `-a
 | |-)
 | `-EmptyStatement
@@ -662,7 +662,7 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-test
 | | |-(
 | | `-)
@@ -675,7 +675,7 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-UnknownExpression
+| | | |-IdExpression
 | | | | `-test
 | | | |-(
 | | | `-)
@@ -683,7 +683,7 @@
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-UnknownExpression
+|   | |-IdExpression
 |   | | `-test
 |   | |-(
 |   | `-)
@@ -724,12 +724,10 @@
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-a
+| | | `-a
 | | |-=
 | | `-IdExpression
-| |   `-UnqualifiedId
-| | `-b
+| |   `-b
 | `-;
 `-}
 )txt"));
@@ -800,38 +798,22 @@
   |   `-)
   `-CompoundStatement
 |-{
-|-DeclarationStatement
-| |-SimpleDeclaration
-| | |-a
-| | |-::
-| | |-b
-| | |-::
-| | |-S
-| | `-SimpleDeclarator
-| |   `-UnknownExpression
-| | `-s
-| `-;
 |-ExpressionStatement
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
 | | | | |-NameQualifier
-| | | | | |-GlobalNamespace
-| | | | | `::
+| | | | | `-::
 | | | | |-NameQualifier
-| | | | | |-NamespaceName
-| | | | | | `-a
+| | | | | |-a
 | | | | | `-::
 | | | | |-NameQualifier
-| | | | | |-NamespaceName
-| | | | | | `-b
+| | | | | |-b
 | | | | | `-::
 | | | | `-NameQualifier
-| | | |   |-TypeName
-| | | |   | `-S
+| | | |   |-S
 | | | |   `-::
-| | | `-UnqualifiedId
-| | |   `-f
+| | | `-f
 | | |-(
 | | `-)
 | `-;
@@ -1036,13 +1018,13 @@
 |-{
 |-ExpressionStatement
 | |-PostfixUnaryOperatorExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-a
 | | `-++
 | `-;
 |-ExpressionStatement
 | |-PostfixUnaryOperatorExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-a
 | | `---
 | `-;
@@ -1088,61 +1070,61 @@
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |---
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-++
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-~
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |--
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-+
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-&
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-*
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-ap
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-!
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-__real
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-__imag
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 `-}
@@ -1183,13 +1165,13 @@
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-compl
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-not
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-b
   

[PATCH] D81280: (Incomplete)Add support for id-expression

2020-06-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 269127.
eduucaldas added a comment.

Add support for DeclRefExpr in SyntaxTree, by generating IdExpression


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81280/new/

https://reviews.llvm.org/D81280

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -485,7 +485,7 @@
 | | |-SimpleDeclarator
 | | | `-x
 | | `-:
-| |-UnknownExpression
+| |-IdExpression
 | | `-a
 | |-)
 | `-EmptyStatement
@@ -662,7 +662,7 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-test
 | | |-(
 | | `-)
@@ -675,7 +675,7 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-UnknownExpression
+| | | |-IdExpression
 | | | | `-test
 | | | |-(
 | | | `-)
@@ -683,7 +683,7 @@
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-UnknownExpression
+|   | |-IdExpression
 |   | | `-test
 |   | |-(
 |   | `-)
@@ -724,12 +724,10 @@
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-a
+| | | `-a
 | | |-=
 | | `-IdExpression
-| |   `-UnqualifiedId
-| | `-b
+| |   `-b
 | `-;
 `-}
 )txt"));
@@ -800,38 +798,22 @@
   |   `-)
   `-CompoundStatement
 |-{
-|-DeclarationStatement
-| |-SimpleDeclaration
-| | |-a
-| | |-::
-| | |-b
-| | |-::
-| | |-S
-| | `-SimpleDeclarator
-| |   `-UnknownExpression
-| | `-s
-| `-;
 |-ExpressionStatement
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-NameQualifier
-| | | | | |-GlobalNamespace
-| | | | | `::
-| | | | |-NameQualifier
-| | | | | |-NamespaceName
-| | | | | | `-a
+| | | | |-NameSpecifier
+| | | | | `-::
+| | | | |-NameSpecifier
+| | | | | |-a
 | | | | | `-::
-| | | | |-NameQualifier
-| | | | | |-NamespaceName
-| | | | | | `-b
+| | | | |-NameSpecifier
+| | | | | |-b
 | | | | | `-::
-| | | | `-NameQualifier
-| | | |   |-TypeName
-| | | |   | `-S
+| | | | `-NameSpecifier
+| | | |   |-S
 | | | |   `-::
-| | | `-UnqualifiedId
-| | |   `-f
+| | | `-f
 | | |-(
 | | `-)
 | `-;
@@ -1036,13 +1018,13 @@
 |-{
 |-ExpressionStatement
 | |-PostfixUnaryOperatorExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-a
 | | `-++
 | `-;
 |-ExpressionStatement
 | |-PostfixUnaryOperatorExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-a
 | | `---
 | `-;
@@ -1088,61 +1070,61 @@
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |---
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-++
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-~
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |--
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-+
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-&
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-*
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-ap
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-!
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-__real
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-__imag
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 `-}
@@ -1183,13 +1165,13 @@
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-compl
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpres

[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 269129.
eduucaldas added a comment.

cleanup for upstreaming


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -485,7 +485,7 @@
 | | |-SimpleDeclarator
 | | | `-x
 | | `-:
-| |-UnknownExpression
+| |-IdExpression
 | | `-a
 | |-)
 | `-EmptyStatement
@@ -662,7 +662,7 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-test
 | | |-(
 | | `-)
@@ -675,7 +675,7 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-UnknownExpression
+| | | |-IdExpression
 | | | | `-test
 | | | |-(
 | | | `-)
@@ -683,7 +683,7 @@
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-UnknownExpression
+|   | |-IdExpression
 |   | | `-test
 |   | |-(
 |   | `-)
@@ -692,6 +692,135 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UnqualifiedId) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test(int b) {
+  int a;
+  a = b;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-int
+| | `-SimpleDeclarator
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-a
+| | |-=
+| | `-IdExpression
+| |   `-b
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, QualifiedId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+namespace a {
+  namespace b {
+struct S {
+  int i;
+  static void f(){}
+};
+  }
+}
+void test(int b) {
+  ::a::b::S::f();
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-NamespaceDefinition
+| |-namespace
+| |-a
+| |-{
+| |-NamespaceDefinition
+| | |-namespace
+| | |-b
+| | |-{
+| | |-SimpleDeclaration
+| | | |-struct
+| | | |-S
+| | | |-{
+| | | |-SimpleDeclaration
+| | | | |-int
+| | | | |-SimpleDeclarator
+| | | | | `-i
+| | | | `-;
+| | | |-SimpleDeclaration
+| | | | |-static
+| | | | |-void
+| | | | |-SimpleDeclarator
+| | | | | |-f
+| | | | | `-ParametersAndQualifiers
+| | | | |   |-(
+| | | | |   `-)
+| | | | `-CompoundStatement
+| | | |   |-{
+| | | |   `-}
+| | | |-}
+| | | `-;
+| | `-}
+| `-}
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-NameSpecifier
+| | | | | `-::
+| | | | |-NameSpecifier
+| | | | | |-a
+| | | | | `-::
+| | | | |-NameSpecifier
+| | | | | |-b
+| | | | | `-::
+| | | | `-NameSpecifier
+| | | |   |-S
+| | | |   `-::
+| | | `-f
+| | |-(
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
   if (!GetParam().isCXX11OrLater()) {
 return;
@@ -889,13 +1018,13 @@
 |-{
 |-ExpressionStatement
 | |-PostfixUnaryOperatorExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-a
 | | `-++
 | `-;
 |-ExpressionStatement
 | |-PostfixUnaryOperatorExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-a
 | | `---
 | `-;
@@ -941,61 +1070,61 @@
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |---
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-++
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-~
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |--
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-+
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpress

[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 6 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:618
+  Builder.foldNode(Builder.getRange(it.getLocalSourceRange()), NS, 
nullptr);
+  Builder.markChild(NS, syntax::NodeRole::Unknown);
+}

gribozavr2 wrote:
> Do we need to mark the role if it is unknown?
> 
Thanks, that had slipped through, sorry for that


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 269422.
eduucaldas edited the summary of this revision.
eduucaldas added a comment.

Answering simple comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -802,15 +802,15 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-NameQualifier
+| | | | |-NameSpecifier
 | | | | | `-::
-| | | | |-NameQualifier
+| | | | |-NameSpecifier
 | | | | | |-a
 | | | | | `-::
-| | | | |-NameQualifier
+| | | | |-NameSpecifier
 | | | | | |-b
 | | | | | `-::
-| | | | `-NameQualifier
+| | | | `-NameSpecifier
 | | | |   |-S
 | | | |   `-::
 | | | `-f
@@ -1546,7 +1546,8 @@
 | |-BinaryOperatorExpression
 | | |-IdExpression
 | | | `-x
-| | |-=
+| | |-IdExpression
+| | | `-=
 | | `-IdExpression
 | |   `-y
 | `-;
@@ -1555,7 +1556,8 @@
 | | |-UnknownExpression
 | | | `-IdExpression
 | | |   `-x
-| | |-+
+| | |-IdExpression
+| | | `-+
 | | `-IdExpression
 | |   `-y
 | `-;
@@ -1563,7 +1565,8 @@
 | |-BinaryOperatorExpression
 | | |-IdExpression
 | | | `-x
-| | |-<
+| | |-IdExpression
+| | | `-<
 | | `-IdExpression
 | |   `-y
 | `-;
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -96,10 +96,8 @@
 return OS << "ParametersAndQualifiers";
   case NodeKind::MemberPointer:
 return OS << "MemberPointer";
-  case NodeKind::Operator:
-return OS << "Operator";
-  case NodeKind::NameQualifier:
-return OS << "NameQualifier";
+  case NodeKind::NameSpecifier:
+return OS << "NameSpecifier";
   case NodeKind::NestedNameSpecifier:
 return OS << "NestedNameSpecifier";
   }
@@ -170,19 +168,23 @@
 return OS << "IdExpression_unqualifiedId";
   case syntax::NodeRole::IdExpression_qualifier:
 return OS << "IdExpression_qualifier";
+  case syntax::NodeRole::NestedNameSpecifier_specifier:
+return OS << "NestedNameSpecifier_specifier";
   }
   llvm_unreachable("invalid role");
 }
 
-std::vector syntax::NestedNameSpecifier::specifiers() {
-  std::vector Children;
+std::vector syntax::NestedNameSpecifier::specifiers() {
+  std::vector Children;
   for (auto *C = firstChild(); C; C = C->nextSibling()) {
-Children.push_back(llvm::cast(C));
+if (C->role() == syntax::NodeRole::NestedNameSpecifier_specifier)
+  Children.push_back(llvm::cast(C));
   }
   return Children;
 }
-syntax::Leaf *syntax::IdExpression::qualifier() {
-  return llvm::cast_or_null(
+
+syntax::NestedNameSpecifier *syntax::IdExpression::qualifier() {
+  return llvm::cast_or_null(
   findChild(syntax::NodeRole::IdExpression_qualifier));
 }
 
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -609,35 +609,28 @@
   }
 
   syntax::NestedNameSpecifier *
-  BuildNestedNameSpecifier(NestedNameSpecifierLoc NNS) {
-if (!NNS)
+  BuildNestedNameSpecifier(NestedNameSpecifierLoc QualifierLoc) {
+if (!QualifierLoc)
   return nullptr;
-NestedNameSpecifierLoc it = NNS;
-while (it) {
-  auto *NS = new (allocator()) syntax::NameQualifier;
+for (auto it = QualifierLoc; it; it = it.getPrefix()) {
+  auto *NS = new (allocator()) syntax::NameSpecifier;
   Builder.foldNode(Builder.getRange(it.getLocalSourceRange()), NS, nullptr);
-  Builder.markChild(NS, syntax::NodeRole::Unknown);
-  it = it.getPrefix();
+  Builder.markChild(NS, syntax::NodeRole::NestedNameSpecifier_specifier);
 }
-syntax::NestedNameSpecifier *sNNS =
-new (allocator()) syntax::NestedNameSpecifier;
-Builder.foldNode(Builder.getRange(NNS.getSourceRange()), sNNS, nullptr);
-return sNNS;
+auto *NNS = new (allocator()) syntax::NestedNameSpecifier;
+Builder.foldNode(Builder.getRange(QualifierLoc.getSourceRange()), NNS,
+ nullptr);
+return NNS;
   }
 
   bool WalkUpFromDeclRefExpr(DeclRefExpr *S) {
-if (S->getNameInfo().getName().getNameKind() ==
-clang::DeclarationName::CXXOperatorName) {
-  return true;
-} else {
-  auto *sNNS = BuildNestedNameSpecifier(S->getQualifierLoc());
-  if (sNNS)
-Builder.markChild(sNNS, syntax::NodeRole::IdExpression_qualif

[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 269423.
eduucaldas added a comment.

nswering simple comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -485,7 +485,7 @@
 | | |-SimpleDeclarator
 | | | `-x
 | | `-:
-| |-UnknownExpression
+| |-IdExpression
 | | `-a
 | |-)
 | `-EmptyStatement
@@ -662,7 +662,7 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-test
 | | |-(
 | | `-)
@@ -675,7 +675,7 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-UnknownExpression
+| | | |-IdExpression
 | | | | `-test
 | | | |-(
 | | | `-)
@@ -683,7 +683,7 @@
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-UnknownExpression
+|   | |-IdExpression
 |   | | `-test
 |   | |-(
 |   | `-)
@@ -692,6 +692,135 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UnqualifiedId) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test(int b) {
+  int a;
+  a = b;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-int
+| | `-SimpleDeclarator
+| |   `-a
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-a
+| | |-=
+| | `-IdExpression
+| |   `-b
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, QualifiedId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+namespace a {
+  namespace b {
+struct S {
+  int i;
+  static void f(){}
+};
+  }
+}
+void test(int b) {
+  ::a::b::S::f();
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-NamespaceDefinition
+| |-namespace
+| |-a
+| |-{
+| |-NamespaceDefinition
+| | |-namespace
+| | |-b
+| | |-{
+| | |-SimpleDeclaration
+| | | |-struct
+| | | |-S
+| | | |-{
+| | | |-SimpleDeclaration
+| | | | |-int
+| | | | |-SimpleDeclarator
+| | | | | `-i
+| | | | `-;
+| | | |-SimpleDeclaration
+| | | | |-static
+| | | | |-void
+| | | | |-SimpleDeclarator
+| | | | | |-f
+| | | | | `-ParametersAndQualifiers
+| | | | |   |-(
+| | | | |   `-)
+| | | | `-CompoundStatement
+| | | |   |-{
+| | | |   `-}
+| | | |-}
+| | | `-;
+| | `-}
+| `-}
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-NameSpecifier
+| | | | | `-::
+| | | | |-NameSpecifier
+| | | | | |-a
+| | | | | `-::
+| | | | |-NameSpecifier
+| | | | | |-b
+| | | | | `-::
+| | | | `-NameSpecifier
+| | | |   |-S
+| | | |   `-::
+| | | `-f
+| | |-(
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
   if (!GetParam().isCXX11OrLater()) {
 return;
@@ -889,13 +1018,13 @@
 |-{
 |-ExpressionStatement
 | |-PostfixUnaryOperatorExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-a
 | | `-++
 | `-;
 |-ExpressionStatement
 | |-PostfixUnaryOperatorExpression
-| | |-UnknownExpression
+| | |-IdExpression
 | | | `-a
 | | `---
 | `-;
@@ -941,61 +1070,61 @@
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |---
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-++
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-~
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |--
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
 | | |-+
-| | `-UnknownExpression
+| | `-IdExpression
 | |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpres

[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-18 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 271620.
eduucaldas marked 7 inline comments as done.
eduucaldas added a comment.

- cleanup for upstreaming
- better coverage for unqualified-id
- Better coverage for qualified-id
- Finish implementing unqualified-id.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -485,8 +485,9 @@
 | | |-SimpleDeclarator
 | | | `-x
 | | `-:
-| |-UnknownExpression
-| | `-a
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-a
 | |-)
 | `-EmptyStatement
 |   `-;
@@ -662,8 +663,9 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-UnknownExpression
-| | | `-test
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-test
 | | |-(
 | | `-)
 | `-;
@@ -675,16 +677,18 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-UnknownExpression
-| | | | `-test
+| | | |-IdExpression
+| | | | `-UnqualifiedId
+| | | |   `-test
 | | | |-(
 | | | `-)
 | | `-;
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-UnknownExpression
-|   | | `-test
+|   | |-IdExpression
+|   | | `-UnqualifiedId
+|   | |   `-test
 |   | |-(
 |   | `-)
 |   `-;
@@ -692,6 +696,464 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UnqualifiedId) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  // TODO: Expose `id-expression` from `Declarator`
+  friend X operator+(const X&, const X&);
+  operator int();
+};
+unsigned operator "" _w(long long unsigned);
+template
+void f(T&);
+void test(X x) {
+  x;  // identifier
+  operator+(x, x);// operator-function-id
+  operator "" _w(1llu);   // literal-operator-id
+
+  f(x);// template-id
+
+  // TODO: Expose `id-expression` from `MemberExpr`
+  x.operator int();   // conversion-funtion-id
+  x.~X(); // ~type-name
+  x.~decltype(x)();   // ~decltype-specifier
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-+
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-int
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | |-long
+| |   | `-unsigned
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-void
+|   |-SimpleDeclarator
+|   | |-f
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   |-SimpleDeclaration
+|   |   | |-T
+|   |   | `-SimpleDeclarator
+|   |   |   `-&
+|   |   `-)
+|   `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-x
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   `-+
+| | |-(
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-,
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   |-""
+| | |   `-_w
+| | |-(
+| | |-IntegerLiteralExpression
+| | | `-1llu
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-f
+| | |   |-<
+| | |   |-X
+| | |   `->
+| | |-(
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| 

[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-18 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked an inline comment as not done.
eduucaldas added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:190
+return N->kind() == NodeKind::NameSpecifier;
+  }
+};

gribozavr2 wrote:
> Should there be getters for various parts of the specifier?
I think not.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:209
+/// qualified-id:
+///   nested-name-specifier template_opt unqualified-id
+class IdExpression final : public Expression {

gribozavr2 wrote:
> Please add a TODO for the accessor for the 'template' keyword (and a test 
> that has that keyword).
I can implement accessor. But I couldn't write a test with this template 
keyword that uses `DeclRefExpr`.  [[ https://godbolt.org/z/XWGuZP | This ]] is 
the test I came up with, note that both expressions are represented as 
`DependentScopeDeclRefExpr`



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:216
+  }
+
+  syntax::NestedNameSpecifier *qualifier();

Just by looking at code it is impossible to know if the accessed thing is 
optional or not. 
IdExpression ALWAYS has a UnqualifiedId
IdExpression MAY have a NestedNameSpecifier
This same issue repeats in other places


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-18 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 271630.
eduucaldas added a comment.

Fix mistake on getting SourceRange for template-id


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -485,8 +485,9 @@
 | | |-SimpleDeclarator
 | | | `-x
 | | `-:
-| |-UnknownExpression
-| | `-a
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-a
 | |-)
 | `-EmptyStatement
 |   `-;
@@ -662,8 +663,9 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-UnknownExpression
-| | | `-test
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-test
 | | |-(
 | | `-)
 | `-;
@@ -675,16 +677,18 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-UnknownExpression
-| | | | `-test
+| | | |-IdExpression
+| | | | `-UnqualifiedId
+| | | |   `-test
 | | | |-(
 | | | `-)
 | | `-;
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-UnknownExpression
-|   | | `-test
+|   | |-IdExpression
+|   | | `-UnqualifiedId
+|   | |   `-test
 |   | |-(
 |   | `-)
 |   `-;
@@ -692,6 +696,475 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UnqualifiedId) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  // TODO: Expose `id-expression` from `Declarator`
+  friend X operator+(const X&, const X&);
+  operator int();
+};
+unsigned operator "" _w(long long unsigned);
+template
+void f(T&);
+void test(X x) {
+  x;  // identifier
+  operator+(x, x);// operator-function-id
+  operator "" _w(1llu);   // literal-operator-id
+
+  f(x);// template-id
+
+  // TODO: Expose `id-expression` from `MemberExpr`
+  x.operator int();   // conversion-funtion-id
+  x.~X(); // ~type-name
+  x.~decltype(x)();   // ~decltype-specifier
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-+
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-int
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | |-long
+| |   | `-unsigned
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-void
+|   |-SimpleDeclarator
+|   | |-f
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   |-SimpleDeclaration
+|   |   | |-T
+|   |   | `-SimpleDeclarator
+|   |   |   `-&
+|   |   `-)
+|   `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-x
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   `-+
+| | |-(
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-,
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   |-""
+| | |   `-_w
+| | |-(
+| | |-IntegerLiteralExpression
+| | | `-1llu
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-f
+| | |   |-<
+| | |   |-X
+| | |   `->
+| | |-(
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-UnknownExpression
+| | | |-IdExpression
+   

[PATCH] D82937: Fix `isInfixBinaryOp` that returned true for postfix ++

2020-07-01 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 274769.
eduucaldas added a comment.

better comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82937/new/

https://reviews.llvm.org/D82937

Files:
  clang/lib/AST/ExprCXX.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/CXXOperatorCallExprTest.cpp

Index: clang/unittests/Tooling/CXXOperatorCallExprTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/CXXOperatorCallExprTest.cpp
@@ -0,0 +1,77 @@
+//===- unittests/Tooling/CXXOperatorCallExprTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Unit tests for the predicates in CXXOperatorCallExpr.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace {
+
+TEST(CXXOperatorPredicatesTest, InfixBinaryOp) {
+  const std::string Code = R"cpp(
+  struct X{
+friend X operator+(X, X);
+  };
+  void test(X x){
+x + x;
+  }
+  )cpp";
+
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_TRUE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+  visitor.runOver(Code);
+}
+
+TEST(CXXOperatorPredicatesTest, CallLikeOp) {
+  const std::string Code = R"cpp(
+  struct X{
+int operator[](int idx);
+  };
+  void test(X x){
+x[1];
+  }
+  )cpp";
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_FALSE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+
+  visitor.runOver(Code);
+}
+
+TEST(CXXOperatorPredicatesTest, PostfixUnaryOp) {
+  const std::string Code = R"cpp(
+  struct X{
+X operator++(int);
+  };
+  void test(X x){
+x++;
+  }
+  )cpp";
+
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_FALSE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+
+  visitor.runOver(Code);
+}
+} // namespace
+} // namespace clang
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -18,6 +18,7 @@
   CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
+  CXXOperatorCallExprTest.cpp
   DependencyScannerTest.cpp
   DiagnosticsYamlTest.cpp
   ExecutionTest.cpp
Index: clang/lib/AST/ExprCXX.cpp
===
--- clang/lib/AST/ExprCXX.cpp
+++ clang/lib/AST/ExprCXX.cpp
@@ -46,15 +46,18 @@
 //===--===//
 
 bool CXXOperatorCallExpr::isInfixBinaryOp() const {
-  // An infix binary operator is any operator with two arguments other than
-  // operator() and operator[]. Note that none of these operators can have
-  // default arguments, so it suffices to check the number of argument
-  // expressions.
   if (getNumArgs() != 2)
 return false;
 
   switch (getOperator()) {
-  case OO_Call: case OO_Subscript:
+  // operator() may have two arguments, but it's not a binary operator
+  case OO_Call:
+  // operator[] takes two arguments but it's not infix
+  case OO_Subscript:
+  // Postfix unary operators (++ and --) take 2 arguments to differ from their
+  // prefix counterparts
+  case OO_PlusPlus:
+  case OO_MinusMinus:
 return false;
   default:
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid sloc

2020-07-01 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82954

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ExprCXX.cpp
  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
@@ -2268,6 +2268,64 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PostfixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-++
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -648,6 +648,8 @@
   }
 
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
+if (S->getLocation().isInvalid())
+  return true;
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::IntegerLiteralExpression, S);
@@ -733,8 +735,23 @@
   Builder.foldNode(Builder.getExprRange(S),
new (allocator()) syntax::BinaryOperatorExpression, S);
   return true;
-}
-return RecursiveASTVisitor::WalkUpFromCXXOperatorCallExpr(S);
+} else if (S->isUnaryOp()) {
+  Builder.markChildToken(
+  S->getOperatorLoc(),
+  syntax::NodeRole::OperatorExpression_operatorToken);
+  Builder.markExprChild(S->getArg(0),
+syntax::NodeRole::UnaryOperatorExpression_operand);
+  if (S->isPostfixUnaryOp())
+Builder.foldNode(
+Builder.getExprRange(S),
+new (allocator()) syntax::PostfixUnaryOperatorExpression, S);
+  else
+Builder.foldNode(
+Builder.getExprRange(S),
+new (allocator()) syntax::PrefixUnaryOperatorExpression, S);
+  return true;
+} else
+  return RecursiveASTVisitor::WalkUpFromCXXOperatorCallExpr(S);
   }
 
   bool WalkUpFromNamespaceDecl(NamespaceDecl *S) {
Index: clang/lib/AST/ExprCXX.cpp
===
--- clang/lib/AST/ExprCXX.cpp
+++ clang/lib/AST/ExprCXX.cpp
@@ -48,7 +48,6 @@
 bool CXXOperatorCallExpr::isInfixBinaryOp() const {
   if (getNumArgs() != 2)
 return false;
-
   switch (getOperator()) {
   // operator() may have two arguments, but it's not a binary operator
   case OO_Call:
@@ -64,6 +63,30 @@
   }
 }
 
+bool CXXOperatorCallExpr::isPostfixUnaryOp() const {
+  switch (getOperator()) {
+  case OO_PlusPlus:
+  case OO_MinusMinus:
+return getNumArgs() == 2;
+  default:
+return false;
+  }
+}
+
+bool CXXOperatorCallExpr::isPrefixUnaryOp() const {
+  switch (getOperator()) {
+  case OO_Call:
+  case OO_Subscript:
+return false;
+  default:
+return getNumArgs() == 1;
+  }
+}
+
+bool CXXOperatorCallExpr::isUnaryOp() const {
+  return isPrefixUnaryOp() || isPostfixUnaryOp();
+}
+
 CXXRewrittenBinaryOperator::DecomposedForm
 CXXRewrittenBinaryOperator::getDecomposedForm() const {
   DecomposedForm Result = {};
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -121,6 +121,7 @@
Opc == OO_GreaterGreaterEqual || Opc == OO_AmpEqual ||
Opc == OO_CaretEqual || Opc == OO_PipeEqual;
   }
+
   bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
 
   static bool isComparisonOp(OverloadedOperatorKind Opc) {
@@ -139,7 +140,12 @@
   }
   bool isComparisonOp() const { return isComparisonOp(getOperator()); }
 
-  /// Is this written as an infix binary operator?
+  bool isPostfixUnaryOp() const;
+
+  bool isPrefixUnaryOp() const;
+
+  bool isUnar

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid sloc

2020-07-01 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a reviewer: gribozavr2.
eduucaldas marked an inline comment as done.
eduucaldas added a comment.

Code that reproduces the crash 
Notice that when using a postfix unary operator ++ one argument is introduced 
to differ it from its prefix counterpart, but that argument is not used. This 
phantom argument shows up in the ClangAST in the form of an `IntegerLiteral` 
with `invalid sloc`. This invalid sloc in a valid AST node was causing the 
SyntaxTree generation to crash.
We can address this problems at two different levels:

1. At the `TraverseCXXOperatorCallExpr`, by overriding it and replacing the 
children iteration to not iterate over this phantom argument.
2. At the `WalkUpFromIntegerLiteral`, by skipping the visitation of the phantom 
node.

We preferred the latter.

1. Cons: We would have to duplicate the implementation of RecursiveASTVisitor 
in BuildTree, to handle this subtle change in traversal. That would add code 
complexity.
2. Cons: We are handling a problem of `CXXOperatorCallExpr` in `IntegerLiteral`.

We chose the latter as, anyways, if an AST node has an invalid sloc, it was 
either a problem with parsing or the node is supposed to be ignored




Comment at: clang/include/clang/AST/ExprCXX.h:143-148
+  bool isPostfixUnaryOp() const;
+
+  bool isPrefixUnaryOp() const;
+
+  bool isUnaryOp() const;
+

Should new additions to CXXOperatorCallExpr go on a different patch?
I'll also add unit tests for those. I'm waiting for review on 
https://reviews.llvm.org/D82937, to do that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82960: Add parenthesized expression to SyntaxTree

2020-07-01 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82960

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1129,6 +1129,61 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, ParenExpr) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+  (1);
+  ((1));
+  (1 + (2));
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-IntegerLiteralExpression
+| | | `-1
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-ParenExpression
+| | | |-(
+| | | |-IntegerLiteralExpression
+| | | | `-1
+| | | `-)
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-BinaryOperatorExpression
+| | | |-IntegerLiteralExpression
+| | | | `-1
+| | | |-+
+| | | `-ParenExpression
+| | |   |-(
+| | |   |-IntegerLiteralExpression
+| | |   | `-2
+| | |   `-)
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
@@ -2040,7 +2095,7 @@
 |-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-ParenExpression
 | | | |-(
 | | | |-BinaryOperatorExpression
 | | | | |-IntegerLiteralExpression
@@ -2050,7 +2105,7 @@
 | | | |   `-2
 | | | `-)
 | | |-*
-| | `-UnknownExpression
+| | `-ParenExpression
 | |   |-(
 | |   |-BinaryOperatorExpression
 | |   | |-IntegerLiteralExpression
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -42,6 +42,8 @@
 return OS << "IdExpression";
   case NodeKind::UnknownStatement:
 return OS << "UnknownStatement";
+  case NodeKind::ParenExpression:
+return OS << "ParenExpression";
   case NodeKind::DeclarationStatement:
 return OS << "DeclarationStatement";
   case NodeKind::EmptyStatement:
@@ -180,6 +182,8 @@
 return OS << "IdExpression_qualifier";
   case syntax::NodeRole::NestedNameSpecifier_specifier:
 return OS << "NestedNameSpecifier_specifier";
+  case syntax::NodeRole::ParenExpression_subExpression:
+return OS << "ParenExpression_subExpression";
   }
   llvm_unreachable("invalid role");
 }
@@ -203,6 +207,21 @@
   findChild(syntax::NodeRole::IdExpression_id));
 }
 
+syntax::Leaf *syntax::ParenExpression::openParen() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::OpenParen));
+}
+
+syntax::Expression *syntax::ParenExpression::subExpression() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::ParenExpression_subExpression));
+}
+
+syntax::Leaf *syntax::ParenExpression::closeParen() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::CloseParen));
+}
+
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::LiteralToken));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -647,6 +647,16 @@
 return true;
   }
 
+  bool WalkUpFromParenExpr(ParenExpr *S) {
+Builder.markChildToken(S->getLParen(), syntax::NodeRole::OpenParen);
+Builder.markExprChild(S->getSubExpr(),
+  syntax::NodeRole::ParenExpression_subExpression);
+Builder.markChildToken(S->getRParen(), syntax::NodeRole::CloseParen);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::ParenExpression, S);
+return true;
+  }
+
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -40,6 +40,7 @@
 
   // Expressions.
   UnknownExpression,
+  ParenExpression,
   PrefixUnaryOperatorExpression,
   PostfixUnaryOperatorExpression,
   BinaryOperatorExpression,
@@ -161,7 +162,8 @@
   ParametersAndQualifiers_trailingReturn,
   IdExpr

[PATCH] D82960: Add parenthesized expression to SyntaxTree

2020-07-01 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 274795.
eduucaldas added a comment.

Ordering nit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82960/new/

https://reviews.llvm.org/D82960

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1129,6 +1129,61 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, ParenExpr) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+  (1);
+  ((1));
+  (1 + (2));
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-IntegerLiteralExpression
+| | | `-1
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-ParenExpression
+| | | |-(
+| | | |-IntegerLiteralExpression
+| | | | `-1
+| | | `-)
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-BinaryOperatorExpression
+| | | |-IntegerLiteralExpression
+| | | | `-1
+| | | |-+
+| | | `-ParenExpression
+| | |   |-(
+| | |   |-IntegerLiteralExpression
+| | |   | `-2
+| | |   `-)
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
@@ -2040,7 +2095,7 @@
 |-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-ParenExpression
 | | | |-(
 | | | |-BinaryOperatorExpression
 | | | | |-IntegerLiteralExpression
@@ -2050,7 +2105,7 @@
 | | | |   `-2
 | | | `-)
 | | |-*
-| | `-UnknownExpression
+| | `-ParenExpression
 | |   |-(
 | |   |-BinaryOperatorExpression
 | |   | |-IntegerLiteralExpression
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,8 @@
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::ParenExpression:
+return OS << "ParenExpression";
   case NodeKind::IntegerLiteralExpression:
 return OS << "IntegerLiteralExpression";
   case NodeKind::CharacterLiteralExpression:
@@ -180,6 +182,8 @@
 return OS << "IdExpression_qualifier";
   case syntax::NodeRole::NestedNameSpecifier_specifier:
 return OS << "NestedNameSpecifier_specifier";
+  case syntax::NodeRole::ParenExpression_subExpression:
+return OS << "ParenExpression_subExpression";
   }
   llvm_unreachable("invalid role");
 }
@@ -203,6 +207,21 @@
   findChild(syntax::NodeRole::IdExpression_id));
 }
 
+syntax::Leaf *syntax::ParenExpression::openParen() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::OpenParen));
+}
+
+syntax::Expression *syntax::ParenExpression::subExpression() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::ParenExpression_subExpression));
+}
+
+syntax::Leaf *syntax::ParenExpression::closeParen() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::CloseParen));
+}
+
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::LiteralToken));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -647,6 +647,16 @@
 return true;
   }
 
+  bool WalkUpFromParenExpr(ParenExpr *S) {
+Builder.markChildToken(S->getLParen(), syntax::NodeRole::OpenParen);
+Builder.markExprChild(S->getSubExpr(),
+  syntax::NodeRole::ParenExpression_subExpression);
+Builder.markChildToken(S->getRParen(), syntax::NodeRole::CloseParen);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::ParenExpression, S);
+return true;
+  }
+
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -43,6 +43,7 @@
   PrefixUnaryOperatorExpression,
   PostfixUnaryOperatorExpression,
   BinaryOperatorExpression,
+  ParenExpression,
   IntegerLiteralExpression,
   Chara

[PATCH] D82960: Add parenthesized expression to SyntaxTree

2020-07-01 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 274796.
eduucaldas added a comment.

nitpick comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82960/new/

https://reviews.llvm.org/D82960

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1129,6 +1129,61 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, ParenExpr) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+  (1);
+  ((1));
+  (1 + (2));
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-IntegerLiteralExpression
+| | | `-1
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-ParenExpression
+| | | |-(
+| | | |-IntegerLiteralExpression
+| | | | `-1
+| | | `-)
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-BinaryOperatorExpression
+| | | |-IntegerLiteralExpression
+| | | | `-1
+| | | |-+
+| | | `-ParenExpression
+| | |   |-(
+| | |   |-IntegerLiteralExpression
+| | |   | `-2
+| | |   `-)
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
@@ -2040,7 +2095,7 @@
 |-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-ParenExpression
 | | | |-(
 | | | |-BinaryOperatorExpression
 | | | | |-IntegerLiteralExpression
@@ -2050,7 +2105,7 @@
 | | | |   `-2
 | | | `-)
 | | |-*
-| | `-UnknownExpression
+| | `-ParenExpression
 | |   |-(
 | |   |-BinaryOperatorExpression
 | |   | |-IntegerLiteralExpression
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,8 @@
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::ParenExpression:
+return OS << "ParenExpression";
   case NodeKind::IntegerLiteralExpression:
 return OS << "IntegerLiteralExpression";
   case NodeKind::CharacterLiteralExpression:
@@ -180,6 +182,8 @@
 return OS << "IdExpression_qualifier";
   case syntax::NodeRole::NestedNameSpecifier_specifier:
 return OS << "NestedNameSpecifier_specifier";
+  case syntax::NodeRole::ParenExpression_subExpression:
+return OS << "ParenExpression_subExpression";
   }
   llvm_unreachable("invalid role");
 }
@@ -203,6 +207,21 @@
   findChild(syntax::NodeRole::IdExpression_id));
 }
 
+syntax::Leaf *syntax::ParenExpression::openParen() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::OpenParen));
+}
+
+syntax::Expression *syntax::ParenExpression::subExpression() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::ParenExpression_subExpression));
+}
+
+syntax::Leaf *syntax::ParenExpression::closeParen() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::CloseParen));
+}
+
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::LiteralToken));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -647,6 +647,16 @@
 return true;
   }
 
+  bool WalkUpFromParenExpr(ParenExpr *S) {
+Builder.markChildToken(S->getLParen(), syntax::NodeRole::OpenParen);
+Builder.markExprChild(S->getSubExpr(),
+  syntax::NodeRole::ParenExpression_subExpression);
+Builder.markChildToken(S->getRParen(), syntax::NodeRole::CloseParen);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::ParenExpression, S);
+return true;
+  }
+
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -43,6 +43,7 @@
   PrefixUnaryOperatorExpression,
   PostfixUnaryOperatorExpression,
   BinaryOperatorExpression,
+  ParenExpression,
   IntegerLiteralExpression,
   Ch

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid sloc

2020-07-01 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked an inline comment as done.
eduucaldas added inline comments.



Comment at: clang/lib/AST/ExprCXX.cpp:82
+  default:
+return getNumArgs() == 1;
+  }

riccibruno wrote:
> This will be true for `operator->`.
Thank you ! I had missed that! I'll propose a more robust solution. I'll 
probably split this patch. But I'll take care to subscribe you to anything 
related


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82960: Add parenthesized expression to SyntaxTree

2020-07-01 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfdbd78333fc6: Add parenthesized expression to SyntaxTree 
(authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82960/new/

https://reviews.llvm.org/D82960

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1129,6 +1129,61 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, ParenExpr) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+  (1);
+  ((1));
+  (1 + (2));
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-IntegerLiteralExpression
+| | | `-1
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-ParenExpression
+| | | |-(
+| | | |-IntegerLiteralExpression
+| | | | `-1
+| | | `-)
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-ParenExpression
+| | |-(
+| | |-BinaryOperatorExpression
+| | | |-IntegerLiteralExpression
+| | | | `-1
+| | | |-+
+| | | `-ParenExpression
+| | |   |-(
+| | |   |-IntegerLiteralExpression
+| | |   | `-2
+| | |   `-)
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
@@ -2040,7 +2095,7 @@
 |-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-ParenExpression
 | | | |-(
 | | | |-BinaryOperatorExpression
 | | | | |-IntegerLiteralExpression
@@ -2050,7 +2105,7 @@
 | | | |   `-2
 | | | `-)
 | | |-*
-| | `-UnknownExpression
+| | `-ParenExpression
 | |   |-(
 | |   |-BinaryOperatorExpression
 | |   | |-IntegerLiteralExpression
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,8 @@
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::ParenExpression:
+return OS << "ParenExpression";
   case NodeKind::IntegerLiteralExpression:
 return OS << "IntegerLiteralExpression";
   case NodeKind::CharacterLiteralExpression:
@@ -180,6 +182,8 @@
 return OS << "IdExpression_qualifier";
   case syntax::NodeRole::NestedNameSpecifier_specifier:
 return OS << "NestedNameSpecifier_specifier";
+  case syntax::NodeRole::ParenExpression_subExpression:
+return OS << "ParenExpression_subExpression";
   }
   llvm_unreachable("invalid role");
 }
@@ -203,6 +207,21 @@
   findChild(syntax::NodeRole::IdExpression_id));
 }
 
+syntax::Leaf *syntax::ParenExpression::openParen() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::OpenParen));
+}
+
+syntax::Expression *syntax::ParenExpression::subExpression() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::ParenExpression_subExpression));
+}
+
+syntax::Leaf *syntax::ParenExpression::closeParen() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::CloseParen));
+}
+
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::LiteralToken));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -647,6 +647,16 @@
 return true;
   }
 
+  bool WalkUpFromParenExpr(ParenExpr *S) {
+Builder.markChildToken(S->getLParen(), syntax::NodeRole::OpenParen);
+Builder.markExprChild(S->getSubExpr(),
+  syntax::NodeRole::ParenExpression_subExpression);
+Builder.markChildToken(S->getRParen(), syntax::NodeRole::CloseParen);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::ParenExpression, S);
+return true;
+  }
+
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -43,6 +43,7 @@
   PrefixUnaryOperatorExpression,
   PostfixUnaryOperatorExpression,
 

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid sloc

2020-07-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275318.
eduucaldas added a comment.

Revert mistake on last update, used `arc diff --update` with the wrong diff


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2323,6 +2323,64 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PostfixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-++
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TypeLoc.h"
@@ -114,6 +115,85 @@
 };
 } // namespace
 
+syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr &E) {
+  switch (E.getOperator()) {
+  // Comparison
+  case OO_EqualEqual:
+  case OO_ExclaimEqual:
+  case OO_Greater:
+  case OO_GreaterEqual:
+  case OO_Less:
+  case OO_LessEqual:
+  case OO_Spaceship:
+  // Assignment
+  case OO_Equal:
+  case OO_SlashEqual:
+  case OO_PercentEqual:
+  case OO_CaretEqual:
+  case OO_PipeEqual:
+  case OO_LessLessEqual:
+  case OO_GreaterGreaterEqual:
+  case OO_PlusEqual:
+  case OO_MinusEqual:
+  case OO_StarEqual:
+  case OO_AmpEqual:
+  // Binary computation
+  case OO_Slash:
+  case OO_Percent:
+  case OO_Caret:
+  case OO_Pipe:
+  case OO_LessLess:
+  case OO_GreaterGreater:
+  case OO_AmpAmp:
+  case OO_PipePipe:
+return syntax::NodeKind::BinaryOperatorExpression;
+  case OO_Tilde:
+  case OO_Exclaim:
+return syntax::NodeKind::PrefixUnaryOperatorExpression;
+  // Prefix/Postfix increment/decrement
+  case OO_PlusPlus:
+  case OO_MinusMinus:
+switch (E.getNumArgs()) {
+case 1:
+  return syntax::NodeKind::PrefixUnaryOperatorExpression;
+case 2:
+  return syntax::NodeKind::PostfixUnaryOperatorExpression;
+default:
+  llvm_unreachable("Invalid number of arguments for operator");
+}
+  // Operators that can be unary or binary
+  case OO_Plus:
+  case OO_Minus:
+  case OO_Star:
+  case OO_Amp:
+switch (E.getNumArgs()) {
+case 1:
+  return syntax::NodeKind::PrefixUnaryOperatorExpression;
+case 2:
+  return syntax::NodeKind::BinaryOperatorExpression;
+default:
+  llvm_unreachable("Invalid number of arguments for operator");
+}
+return syntax::NodeKind::BinaryOperatorExpression;
+  // Not supported by SyntaxTree
+  case OO_New:
+  case OO_Delete:
+  case OO_Array_New:
+  case OO_Array_Delete:
+  case OO_Coawait:
+  case OO_Call:
+  case OO_Subscript:
+  case OO_Arrow:
+  case OO_Comma:
+  case OO_ArrowStar:
+return syntax::NodeKind::UnknownExpression;
+  case OO_Conditional: // not overloadable
+  case NUM_OVERLOADED_OPERATORS:
+  case OO_None:
+llvm_unreachable("Not an overloadable operator");
+  }
+}
+
 /// Gets the range of declarator as defined by the C++ grammar. E.g.
 /// `int a;` -> range of `a`,
 /// `int *a;` -> range of `*a`,
@@ -658,6 +738,8 @@
   }
 
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
+if (S->getLocation().isInvalid())
+  return true;
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::IntegerLiteralExpression, S);
@@ -730,7 +812,8 @@
   }
 
   bool WalkUpFromCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
-if (S->isInfixBinaryOp()) {
+switch (getOperatorNodeKind(

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid sloc

2020-07-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275315.
eduucaldas added a comment.

- Remove predicates in `CXXOperatorCallExpr`.
- Implement getOperatorNodeKind to dispatch from `CXXOperatorCallExpr` to 
syntax constructs  like `BinaryOperatorExpression`, 
`PrefixUnaryOperatorExpression`...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2323,6 +2323,64 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PostfixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-++
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TypeLoc.h"
@@ -114,6 +115,85 @@
 };
 } // namespace
 
+syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr &E) {
+  switch (E.getOperator()) {
+  // Comparison
+  case OO_EqualEqual:
+  case OO_ExclaimEqual:
+  case OO_Greater:
+  case OO_GreaterEqual:
+  case OO_Less:
+  case OO_LessEqual:
+  case OO_Spaceship:
+  // Assignment
+  case OO_Equal:
+  case OO_SlashEqual:
+  case OO_PercentEqual:
+  case OO_CaretEqual:
+  case OO_PipeEqual:
+  case OO_LessLessEqual:
+  case OO_GreaterGreaterEqual:
+  case OO_PlusEqual:
+  case OO_MinusEqual:
+  case OO_StarEqual:
+  case OO_AmpEqual:
+  // Binary computation
+  case OO_Slash:
+  case OO_Percent:
+  case OO_Caret:
+  case OO_Pipe:
+  case OO_LessLess:
+  case OO_GreaterGreater:
+  case OO_AmpAmp:
+  case OO_PipePipe:
+return syntax::NodeKind::BinaryOperatorExpression;
+  case OO_Tilde:
+  case OO_Exclaim:
+return syntax::NodeKind::PrefixUnaryOperatorExpression;
+  // Prefix/Postfix increment/decrement
+  case OO_PlusPlus:
+  case OO_MinusMinus:
+switch (E.getNumArgs()) {
+case 1:
+  return syntax::NodeKind::PrefixUnaryOperatorExpression;
+case 2:
+  return syntax::NodeKind::PostfixUnaryOperatorExpression;
+default:
+  llvm_unreachable("Invalid number of arguments for operator");
+}
+  // Operators that can be unary or binary
+  case OO_Plus:
+  case OO_Minus:
+  case OO_Star:
+  case OO_Amp:
+switch (E.getNumArgs()) {
+case 1:
+  return syntax::NodeKind::PrefixUnaryOperatorExpression;
+case 2:
+  return syntax::NodeKind::BinaryOperatorExpression;
+default:
+  llvm_unreachable("Invalid number of arguments for operator");
+}
+return syntax::NodeKind::BinaryOperatorExpression;
+  // Not supported by SyntaxTree
+  case OO_New:
+  case OO_Delete:
+  case OO_Array_New:
+  case OO_Array_Delete:
+  case OO_Coawait:
+  case OO_Call:
+  case OO_Subscript:
+  case OO_Arrow:
+  case OO_Comma:
+  case OO_ArrowStar:
+return syntax::NodeKind::UnknownExpression;
+  case OO_Conditional: // not overloadable
+  case NUM_OVERLOADED_OPERATORS:
+  case OO_None:
+llvm_unreachable("Not an overloadable operator");
+  }
+}
+
 /// Gets the range of declarator as defined by the C++ grammar. E.g.
 /// `int a;` -> range of `a`,
 /// `int *a;` -> range of `*a`,
@@ -658,6 +738,8 @@
   }
 
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
+if (S->getLocation().isInvalid())
+  return true;
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::IntegerLiteralExpression, S);
@@ -730,7 +812,8 @@
   }

[PATCH] D82937: Fix `isInfixBinaryOp` that returned true for postfix ++

2020-07-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275317.
eduucaldas added a comment.

Nits


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82937/new/

https://reviews.llvm.org/D82937

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ExprCXX.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/CXXOperatorCallExprTest.cpp

Index: clang/unittests/Tooling/CXXOperatorCallExprTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/CXXOperatorCallExprTest.cpp
@@ -0,0 +1,77 @@
+//===- unittests/Tooling/CXXOperatorCallExprTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Unit tests for the predicates in CXXOperatorCallExpr.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace {
+
+TEST(CXXOperatorPredicatesTest, InfixBinaryOp) {
+  const std::string Code = R"cpp(
+  struct X{
+friend X operator+(X, X);
+  };
+  void test(X x){
+x + x;
+  }
+  )cpp";
+
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_TRUE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+  visitor.runOver(Code);
+}
+
+TEST(CXXOperatorPredicatesTest, CallLikeOp) {
+  const std::string Code = R"cpp(
+  struct X{
+int operator[](int idx);
+  };
+  void test(X x){
+x[1];
+  }
+  )cpp";
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_FALSE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+
+  visitor.runOver(Code);
+}
+
+TEST(CXXOperatorPredicatesTest, PostfixUnaryOp) {
+  const std::string Code = R"cpp(
+  struct X{
+X operator++(int);
+  };
+  void test(X x){
+x++;
+  }
+  )cpp";
+
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_FALSE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+
+  visitor.runOver(Code);
+}
+} // namespace
+} // namespace clang
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -18,6 +18,7 @@
   CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
+  CXXOperatorCallExprTest.cpp
   DependencyScannerTest.cpp
   DiagnosticsYamlTest.cpp
   ExecutionTest.cpp
Index: clang/lib/AST/ExprCXX.cpp
===
--- clang/lib/AST/ExprCXX.cpp
+++ clang/lib/AST/ExprCXX.cpp
@@ -46,15 +46,17 @@
 //===--===//
 
 bool CXXOperatorCallExpr::isInfixBinaryOp() const {
-  // An infix binary operator is any operator with two arguments other than
-  // operator() and operator[]. Note that none of these operators can have
-  // default arguments, so it suffices to check the number of argument
-  // expressions.
   if (getNumArgs() != 2)
 return false;
-
   switch (getOperator()) {
-  case OO_Call: case OO_Subscript:
+  // operator() may have two arguments, but it's not a binary operator
+  case OO_Call:
+  // operator[] takes two arguments but it's not infix
+  case OO_Subscript:
+  // Postfix unary operators (++ and --) take 2 arguments to differ from their
+  // prefix counterparts
+  case OO_PlusPlus:
+  case OO_MinusMinus:
 return false;
   default:
 return true;
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -121,6 +121,7 @@
Opc == OO_GreaterGreaterEqual || Opc == OO_AmpEqual ||
Opc == OO_CaretEqual || Opc == OO_PipeEqual;
   }
+
   bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
 
   static bool isComparisonOp(OverloadedOperatorKind Opc) {
@@ -137,9 +138,9 @@
   return false;
 }
   }
+
   bool isComparisonOp() const { return isComparisonOp(getOperator()); }
 
-  /// Is this written as an infix binary operator?
   bool isInfixBinaryOp() const;
 
   /// Returns the location of the operator symbol in the expression.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid sloc

2020-07-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275316.
eduucaldas added a comment.
Herald added a subscriber: mgorny.

Nits


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ExprCXX.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/CXXOperatorCallExprTest.cpp

Index: clang/unittests/Tooling/CXXOperatorCallExprTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/CXXOperatorCallExprTest.cpp
@@ -0,0 +1,77 @@
+//===- unittests/Tooling/CXXOperatorCallExprTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Unit tests for the predicates in CXXOperatorCallExpr.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace {
+
+TEST(CXXOperatorPredicatesTest, InfixBinaryOp) {
+  const std::string Code = R"cpp(
+  struct X{
+friend X operator+(X, X);
+  };
+  void test(X x){
+x + x;
+  }
+  )cpp";
+
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_TRUE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+  visitor.runOver(Code);
+}
+
+TEST(CXXOperatorPredicatesTest, CallLikeOp) {
+  const std::string Code = R"cpp(
+  struct X{
+int operator[](int idx);
+  };
+  void test(X x){
+x[1];
+  }
+  )cpp";
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_FALSE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+
+  visitor.runOver(Code);
+}
+
+TEST(CXXOperatorPredicatesTest, PostfixUnaryOp) {
+  const std::string Code = R"cpp(
+  struct X{
+X operator++(int);
+  };
+  void test(X x){
+x++;
+  }
+  )cpp";
+
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_FALSE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+
+  visitor.runOver(Code);
+}
+} // namespace
+} // namespace clang
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -18,6 +18,7 @@
   CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
+  CXXOperatorCallExprTest.cpp
   DependencyScannerTest.cpp
   DiagnosticsYamlTest.cpp
   ExecutionTest.cpp
Index: clang/lib/AST/ExprCXX.cpp
===
--- clang/lib/AST/ExprCXX.cpp
+++ clang/lib/AST/ExprCXX.cpp
@@ -46,15 +46,17 @@
 //===--===//
 
 bool CXXOperatorCallExpr::isInfixBinaryOp() const {
-  // An infix binary operator is any operator with two arguments other than
-  // operator() and operator[]. Note that none of these operators can have
-  // default arguments, so it suffices to check the number of argument
-  // expressions.
   if (getNumArgs() != 2)
 return false;
-
   switch (getOperator()) {
-  case OO_Call: case OO_Subscript:
+  // operator() may have two arguments, but it's not a binary operator
+  case OO_Call:
+  // operator[] takes two arguments but it's not infix
+  case OO_Subscript:
+  // Postfix unary operators (++ and --) take 2 arguments to differ from their
+  // prefix counterparts
+  case OO_PlusPlus:
+  case OO_MinusMinus:
 return false;
   default:
 return true;
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -121,6 +121,7 @@
Opc == OO_GreaterGreaterEqual || Opc == OO_AmpEqual ||
Opc == OO_CaretEqual || Opc == OO_PipeEqual;
   }
+
   bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
 
   static bool isComparisonOp(OverloadedOperatorKind Opc) {
@@ -137,9 +138,9 @@
   return false;
 }
   }
+
   bool isComparisonOp() const { return isComparisonOp(getOperator()); }
 
-  /// Is this written as an infix binary operator?
   bool isInfixBinaryOp() const;
 
   /// Returns the location of the operator symbol in the expression.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82937: Fix `isInfixBinaryOp` that returned true for postfix ++

2020-07-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275325.
eduucaldas added a comment.

Remove review formatting noise


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82937/new/

https://reviews.llvm.org/D82937

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ExprCXX.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/CXXOperatorCallExprTest.cpp

Index: clang/unittests/Tooling/CXXOperatorCallExprTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/CXXOperatorCallExprTest.cpp
@@ -0,0 +1,77 @@
+//===- unittests/Tooling/CXXOperatorCallExprTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Unit tests for the predicates in CXXOperatorCallExpr.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace {
+
+TEST(CXXOperatorPredicatesTest, InfixBinaryOp) {
+  const std::string Code = R"cpp(
+  struct X{
+friend X operator+(X, X);
+  };
+  void test(X x){
+x + x;
+  }
+  )cpp";
+
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_TRUE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+  visitor.runOver(Code);
+}
+
+TEST(CXXOperatorPredicatesTest, CallLikeOp) {
+  const std::string Code = R"cpp(
+  struct X{
+int operator[](int idx);
+  };
+  void test(X x){
+x[1];
+  }
+  )cpp";
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_FALSE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+
+  visitor.runOver(Code);
+}
+
+TEST(CXXOperatorPredicatesTest, PostfixUnaryOp) {
+  const std::string Code = R"cpp(
+  struct X{
+X operator++(int);
+  };
+  void test(X x){
+x++;
+  }
+  )cpp";
+
+  struct Visitor : TestVisitor {
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  EXPECT_FALSE(E->isInfixBinaryOp());
+  return true;
+}
+  } visitor;
+
+  visitor.runOver(Code);
+}
+} // namespace
+} // namespace clang
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -18,6 +18,7 @@
   CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
+  CXXOperatorCallExprTest.cpp
   DependencyScannerTest.cpp
   DiagnosticsYamlTest.cpp
   ExecutionTest.cpp
Index: clang/lib/AST/ExprCXX.cpp
===
--- clang/lib/AST/ExprCXX.cpp
+++ clang/lib/AST/ExprCXX.cpp
@@ -46,15 +46,18 @@
 //===--===//
 
 bool CXXOperatorCallExpr::isInfixBinaryOp() const {
-  // An infix binary operator is any operator with two arguments other than
-  // operator() and operator[]. Note that none of these operators can have
-  // default arguments, so it suffices to check the number of argument
-  // expressions.
   if (getNumArgs() != 2)
 return false;
 
   switch (getOperator()) {
-  case OO_Call: case OO_Subscript:
+  // operator() may have two arguments, but it's not a binary operator
+  case OO_Call:
+  // operator[] takes two arguments but it's not infix
+  case OO_Subscript:
+  // Postfix unary operators (++ and --) take 2 arguments to differ from their
+  // prefix counterparts
+  case OO_PlusPlus:
+  case OO_MinusMinus:
 return false;
   default:
 return true;
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -139,7 +139,6 @@
   }
   bool isComparisonOp() const { return isComparisonOp(getOperator()); }
 
-  /// Is this written as an infix binary operator?
   bool isInfixBinaryOp() const;
 
   /// Returns the location of the operator symbol in the expression.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid sloc

2020-07-03 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:118
 
+syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr &E) {
+  switch (E.getOperator()) {

# Where to put this logic? 
The pro of having this function inside `BuildTree.cpp` is that it is closer to 
it's *only* usage. And also for now `BuildTree.cpp` agglomerates everything 
that takes a semantic AST as an input, so it would be coherent.

Another option is to put it in `Nodes`, as it might serve as documentation for 
`*OperatorExpression`s. 
For example, it would document that the semantic node `CXXOperatorCallExpr` can 
also generate the syntax node `BinaryOperatorExpression`, which was previously 
only generated by a semantic `BinaryOperator`

Another option is to add put this function as a lambda inside 
`WalkUpFromCXXOperatorCallExpr` as probably it will only be used there. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-05 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:188
+  case OO_Comma:
+  case OO_ArrowStar:
+return syntax::NodeKind::UnknownExpression;

Actually arrow star is treated like a normal binary operator in the [[ 
https://eel.is/c++draft/expr.compound#expr.mptr.oper | grammar ]]


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275930.
eduucaldas added a comment.

`->*` and `,` are binary operators.
Unit tests covering most of the operator kinds


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2189,20 +2189,29 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+class osstream {};
 struct X {
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend osstream operator<<(osstream&, const X&);
 };
-void test(X x, X y) {
+void test(X x, X y, osstream out) {
   x = y;
   x + y;
   x < y;
+  out << x;
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
+| |-class
+| |-osstream
+| |-{
+| |-}
+| `-;
+|-SimpleDeclaration
 | |-struct
 | |-X
 | |-{
@@ -2262,6 +2271,27 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-osstream
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-osstream
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2279,6 +2309,11 @@
   |   | |-X
   |   | `-SimpleDeclarator
   |   |   `-y
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-osstream
+  |   | `-SimpleDeclarator
+  |   |   `-out
   |   `-)
   `-CompoundStatement
 |-{
@@ -2319,6 +2354,242 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-out
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedRareBinaryOperators) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator,(X&);
+};
+void test(X x, X y) {
+  x, y;
+  // TODO: Test for `->*`. That introduced a crash
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-y
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-Id

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275940.
eduucaldas marked 9 inline comments as done.
eduucaldas added a comment.

Answering comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2189,20 +2189,29 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+class osstream {};
 struct X {
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend osstream operator<<(osstream&, const X&);
 };
-void test(X x, X y) {
+void test(X x, X y, osstream out) {
   x = y;
   x + y;
   x < y;
+  out << x;
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
+| |-class
+| |-osstream
+| |-{
+| |-}
+| `-;
+|-SimpleDeclaration
 | |-struct
 | |-X
 | |-{
@@ -2262,6 +2271,27 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-osstream
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-osstream
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2279,6 +2309,11 @@
   |   | |-X
   |   | `-SimpleDeclarator
   |   |   `-y
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-osstream
+  |   | `-SimpleDeclarator
+  |   |   `-out
   |   `-)
   `-CompoundStatement
 |-{
@@ -2319,6 +2354,242 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-out
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedRareBinaryOperators) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator,(X&);
+};
+void test(X x, X y) {
+  x, y;
+  // TODO: Test for `->*`. That introduced a crash
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-y
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a comment.






Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:741
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
+if (S->getLocation().isInvalid())
+  return true;

gribozavr2 wrote:
> WDYT about overriding `TraverseCXXOperatorCallExpr`, so that we don't even 
> visit the synthetic argument of the postfix unary `++`? I would prefer to not 
> introduce blanket "if invalid then ignore" checks in the code.
>>! In D82954#2125300, @eduucaldas wrote:
> [[ https://godbolt.org/z/CWVEJ2 | Code that reproduces the crash ]]
> Notice that when using a postfix unary operator ++ one argument is introduced 
> to differ it from its prefix counterpart, but that argument is not used. This 
> phantom argument shows up in the ClangAST in the form of an `IntegerLiteral` 
> with `invalid sloc`. This invalid sloc in a valid AST node was causing the 
> SyntaxTree generation to crash.
> We can address this problems at two different levels:
> 1. At the `TraverseCXXOperatorCallExpr`, by overriding it and replacing the 
> children iteration to not iterate over this phantom argument.
> 2. At the `WalkUpFromIntegerLiteral`, by skipping the visitation of the 
> phantom node.
> We preferred the latter.
> 1. Cons: We would have to duplicate the implementation of RecursiveASTVisitor 
> in BuildTree, to handle this subtle change in traversal. That would add code 
> complexity.
> 2. Cons: We are handling a problem of `CXXOperatorCallExpr` in 
> `IntegerLiteral`. 
> 
> We chose the latter as, anyways, if an AST node has an invalid sloc, it was 
> either a problem with parsing or the node is supposed to be ignored

I've explained my reasoning in my first comment for this patch. But as it was a 
long time ago, I guess it got lost, even by me.
 
I'll sketch how the Traverse solution would look like, to be able to give more 
concrete arguments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2376
+| | |   `-x
+| | `-IdExpression
+| |   `-UnqualifiedId

gribozavr2 wrote:
> I'm not sure about this part where `++` is wrapped in IdExpression -- 
> shouldn't the syntax tree look identical to a builtin postfix `++` (see 
> another test in this file)?
This comes back to a discussion we had a month ago about operators ( `+`, `!`, 
etc)
**Question**: Should we represent operators (built-in or overloaded) in the 
syntax tree uniformly? If so in which way?
**Context**: The ClangAST stores built-in operators as mere tokens, whereas 
overloaded operators are represented as a `DeclRefExpr`. That makes a lot of 
sense for the ClangAST, as we might refer back to the declaration of the 
overloaded operator, but the declaration of built-in operator doesn't exist.
**Conclusion**: Have the same representation for both types of operators. I 
have implemented the "unboxed" representation of overloaded operators, i.e. 
just storing their token in the syntax tree. I have not committed that, but I 
can do it just after this patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275942.
eduucaldas added a comment.

Unifying user defined binary operator tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2189,20 +2189,32 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+class osstream {};
 struct X {
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend osstream operator<<(osstream&, const X&);
+  X operator,(X&);
+  // TODO: Test for `->*`. Fix crash before
 };
-void test(X x, X y) {
+void test(X x, X y, osstream out) {
   x = y;
   x + y;
   x < y;
+  out << x;
+  x, y;
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
+| |-class
+| |-osstream
+| |-{
+| |-}
+| `-;
+|-SimpleDeclaration
 | |-struct
 | |-X
 | |-{
@@ -2262,6 +2274,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-osstream
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-osstream
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2279,6 +2325,11 @@
   |   | |-X
   |   | `-SimpleDeclarator
   |   |   `-y
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-osstream
+  |   | `-SimpleDeclarator
+  |   |   `-out
   |   `-)
   `-CompoundStatement
 |-{
@@ -2319,6 +2370,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-out
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2192
   R"cpp(
+class osstream {};
 struct X {

gribozavr2 wrote:
> I don't think we need a separate class to show the left shift operator. The 
> declaration below can be:
> 
> ```
>   friend X operator<<(X&, const X&);
> ```
If we don't bother much about "realistic" operator declarations we could drop 
all the `friend` and declare every operator in their most concise form. WDYT


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276344.
eduucaldas marked 4 inline comments as done.
eduucaldas added a comment.

answering minor comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276361.
eduucaldas added a comment.

Reflect fix on RecursiveASTVisitor


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,6 +1184,93 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+long double operator "" _w(long double);
+unsigned operator "" _w(const char*);
+template  unsigned operator "" _x();
+int main() {
+1.2_w; // calls operator "" _w(1.2L)
+12_w;  // calls operator "" _w("12")
+12_x;  // calls operator<'1', '2'> "" _x()
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-long
+| |-double
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_x
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-main
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UserDefinedLiteralExpression
+| | `-1.2_w
+| `-;
+|-ExpressionStatement
+| |-UserDefinedLiteralExpression
+| | `-12_w
+| `-;
+|-ExpressionStatement
+| |-UserDefinedLiteralExpression
+| | `-12_x
+| `-;
+`-}
+)txt"));
+}
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -32,6 +32,8 @@
 return OS << "BoolLiteralExpression";
   case NodeKind::CxxNullPtrExpression:
 return OS << "CxxNullPtrExpression";
+  case NodeKind::UserDefinedLiteralExpression:
+return OS << "UserDefinedLiteralExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -252,6 +254,11 @@
   findChild(syntax::NodeRole::LiteralToken));
 }
 
+syntax::Leaf *syntax::UserDefinedLiteralExpression::literalToken() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::LiteralToken));
+}
+
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::BinaryOperatorExpression_leftHandSide));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -627,6 +627,26 @@
 return NNS;
   }
 
+  bool TraverseUserDefinedLiteral(UserDefinedLiteral *S) {
+// The user-defined literal `1.2_w` corresponds to *one* token. The semantic
+// node for it however may have two children nodes, both with valid
+// `SourceLocation`s. As a result one of these nodes has a valid
+// `SourceLocation` that doesn't point to a token.
+//
+// If we traverse the children of a user-defined literal, we then arrive to
+// a semantic node that doesn't have a token, and that breaks an invariant
+// of the syntax tree. For that reason we skip traversing user-defined
+// literal children.
+
+return WalkUpFromUserDefinedLiteral(S);
+  }
+
+  bool WalkUpFromUserDefinedLiteral(UserDefinedLiteral *S) {
+Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::UserDefinedLiteralExpression, S);
+return true;
+  }
   bool WalkUpFromDeclRefExpr(DeclRefExpr *S) {
 if (auto *NNS = BuildNestedNameSpecifier(S->getQualifierLoc()))
   Builder.markChild(NNS, syntax::NodeRole::IdExpression_qualifier);
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syn

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 2 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2192
   R"cpp(
+class osstream {};
 struct X {

gribozavr2 wrote:
> eduucaldas wrote:
> > gribozavr2 wrote:
> > > I don't think we need a separate class to show the left shift operator. 
> > > The declaration below can be:
> > > 
> > > ```
> > >   friend X operator<<(X&, const X&);
> > > ```
> > If we don't bother much about "realistic" operator declarations we could 
> > drop all the `friend` and declare every operator in their most concise 
> > form. WDYT
> I think we shouldn't try to make tests realistic in terms of function names 
> etc., but we should try to cover as many different AST shapes as possible. In 
> the case of binary operators, we have three cases -- free function, friend 
> function, member function, that all generate slightly different ASTs, so I 
> believe we should try to cover them all.
But those all regard the operators declaration. 
Here we test the operator call expression - `CXXOperatorCallExpr`.

I think we should test friend function declarations when we add support for 
them in the tree, and then we add tests for declaration of friend operators, 
friend member functions and whatnot.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276408.
eduucaldas marked an inline comment as done.
eduucaldas added a comment.

Switch to `TraverseCXXOperatorCallExpr`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276411.
eduucaldas marked 2 inline comments as done.
eduucaldas added a comment.

minor fix comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-Co

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGea8bba7e8d0d: Fix crash on overloaded postfix unary 
operators due to invalid sloc (authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+ 

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 2 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1265
+| |-UserDefinedLiteralExpression
+| | `-12_w
+| `-;

gribozavr2 wrote:
> It looks somewhat weird to me that integer and floating point literals end up 
> with the same syntax tree node type. WDYT about making different nodes for 
> different literals (integer, floating-point, string, character)?
Makes sense. Let's follow the [[ 
https://eel.is/c++draft/lex.ext#nt:user-defined-literal | grammar ]] then.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGea8bba7e8d0d: Fix crash on overloaded postfix unary 
operators due to invalid sloc (authored by eduucaldas).

Changed prior to commit:
  https://reviews.llvm.org/D82954?vs=275318&id=275709#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82954/new/

https://reviews.llvm.org/D82954

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
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | 

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276637.
eduucaldas marked 4 inline comments as done.
eduucaldas added a comment.

Add support for {Integer,Float,Char,String}UserDefinedLiteral


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Testing/TestClangConfig.h
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,20 +1184,106 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+
+unsigned operator "" _r(const char*); // raw-literal operator
+
+template 
+unsigned operator "" _t();// numeric literal operator template
+
 void test() {
-  12;
-  12u;
-  12l;
-  12ul;
-  014;
-  0XC;
+  12_i;  // call: operator "" _i(12uLL)  | kind: integer
+  1.2_f; // call: operator "" _f(1.2L)   | kind: float
+  '2'_c; // call: operator "" _c('2')| kind: char
+
+  // PROBLEM: How to discover the kind of user-defined-literal from the AST?
+  12_r;  // call: operator "" _r("12")   | kind: integer
+  1.2_r; // call: operator "" _i("1.2")  | kind: float
+  12_t;  // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t; // call: operator<'1', '2'> "" _x() | kind: float
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-unsigned
+| |   | |-long
+| |   | `-long
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_t
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -1208,28 +1294,93 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_i
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12u
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_f
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12l
+| |-CharUserDefinedLiteralExpression
+| | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-014
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-0XC
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_t
+| `-;
+|-ExpressionStatement
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_t
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedLiteralString) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+typedef __SIZE_TYPE__ size_t;
+unsigned operator "" _s(const char*, size_t);
+void test() {
+  "12"_s;// call: operator "" _s("12")   | kind: string
+}
+)cpp",
+  std::string(R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-typedef)txt") +
+  (!GetParam().isLinux() ? R"txt(
+| |-I: long)txt"
+ : "") +
+  R"txt(
+| |-I: long
+| |-I: unsigned
+| |-I: int
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276638.
eduucaldas added a comment.

workaround size_t


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Testing/TestClangConfig.h
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,20 +1184,106 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+
+unsigned operator "" _r(const char*); // raw-literal operator
+
+template 
+unsigned operator "" _t();// numeric literal operator template
+
 void test() {
-  12;
-  12u;
-  12l;
-  12ul;
-  014;
-  0XC;
+  12_i;  // call: operator "" _i(12uLL)  | kind: integer
+  1.2_f; // call: operator "" _f(1.2L)   | kind: float
+  '2'_c; // call: operator "" _c('2')| kind: char
+
+  // PROBLEM: How to discover the kind of user-defined-literal from the AST?
+  12_r;  // call: operator "" _r("12")   | kind: integer
+  1.2_r; // call: operator "" _i("1.2")  | kind: float
+  12_t;  // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t; // call: operator<'1', '2'> "" _x() | kind: float
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-unsigned
+| |   | |-long
+| |   | `-long
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_t
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -1208,28 +1294,95 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_i
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12u
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_f
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12l
+| |-CharUserDefinedLiteralExpression
+| | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-014
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-0XC
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_t
+| `-;
+|-ExpressionStatement
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_t
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedLiteralString) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+typedef decltype(sizeof(void *)) size_t;
+unsigned operator "" _s(const char*, size_t);
+void test() {
+  "12"_s;// call: operator "" _s("12")   | kind: string
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-typedef
+| |-decltype
+| |-(
+| |-UnknownExpression
+| | |-sizeof
+| | |-(
+| | |-void
+| | |-*
+| | `-)
+| |-)
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   |-,
+| |   |-SimpleDeclaration
+| |   | `-size_t
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarato

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 4 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:347-357
+/// Expression for an unkonwn user-defined literal. C++ [lex.ext]
+class UnknownUserDefinedLiteralExpression final
+: public UserDefinedLiteralExpression {
+public:
+  UnknownUserDefinedLiteralExpression()
+  : UserDefinedLiteralExpression(
+NodeKind::UnknownUserDefinedLiteralExpression) {}

This is gonna be removed once we are able to distinguish between integer and 
float on raw and template UDL



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:218-219
 auto InitializerEnd = Initializer.getEnd();
-assert(SM.isBeforeInTranslationUnit(End, InitializerEnd) || End == 
InitializerEnd);
+assert(SM.isBeforeInTranslationUnit(End, InitializerEnd) ||
+   End == InitializerEnd);
 End = InitializerEnd;

I know it adds noise, but this is the only place where the formatting doesn't 
obey the llvm clang format.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:732
+case clang::UserDefinedLiteral::LOK_Template:
+  return syntax::NodeKind::UnknownUserDefinedLiteralExpression;
+}

Here we need logic to determine which kind of UDL, if float or integer



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1309-1310
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_r
 | `-;

For raw and template UDL, we don't know yet how to get the information about 
integer of float


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276678.
eduucaldas added a comment.

Polishing patch


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,20 +1184,106 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+
+unsigned operator "" _r(const char*); // raw-literal operator
+
+template 
+unsigned operator "" _t();// numeric literal operator template
+
 void test() {
-  12;
-  12u;
-  12l;
-  12ul;
-  014;
-  0XC;
+  12_i;  // call: operator "" _i(12uLL)  | kind: integer
+  1.2_f; // call: operator "" _f(1.2L)   | kind: float
+  '2'_c; // call: operator "" _c('2')| kind: char
+
+  // PROBLEM: How to discover the kind of user-defined-literal from the AST?
+  12_r;  // call: operator "" _r("12")   | kind: integer
+  1.2_r; // call: operator "" _i("1.2")  | kind: float
+  12_t;  // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t; // call: operator<'1', '2'> "" _x() | kind: float
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-unsigned
+| |   | |-long
+| |   | `-long
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_t
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -1208,28 +1294,95 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_i
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12u
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_f
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12l
+| |-CharUserDefinedLiteralExpression
+| | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-014
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-0XC
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_t
+| `-;
+|-ExpressionStatement
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_t
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedLiteralString) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+typedef decltype(sizeof(void *)) size_t;
+unsigned operator "" _s(const char*, size_t);
+void test() {
+  "12"_s;// call: operator "" _s("12")   | kind: string
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-typedef
+| |-decltype
+| |-(
+| |-UnknownExpression
+| | |-sizeof
+| | |-(
+| | |-void
+| | |-*
+| | `-)
+| |-)
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   |-,
+| |   |-SimpleDeclaration
+| |   | `-size_t
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  | 

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:634
+// `SourceLocation`s. As a result one of these nodes has a valid
+// `SourceLocation` that doesn't point to a token.
+//

gribozavr2 wrote:
> "The semantic AST node for has child nodes that reference two source 
> locations, the location of the beginning of the token (`1`), and the location 
> of the beginning of the UDL suffix (`_`). The UDL suffix location does not 
> point to the beginning of a token, so we can't represent the UDL suffix as a 
> separate syntax tree node."
I changed your comment slightly, WDYT


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276681.
eduucaldas added a comment.

Document proposed solution for treating raw literal operators and numeric 
template operators


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,20 +1184,108 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+
+unsigned operator "" _r(const char*); // raw-literal operator
+
+template 
+unsigned operator "" _t();// numeric literal operator template
+
 void test() {
-  12;
-  12u;
-  12l;
-  12ul;
-  014;
-  0XC;
+  12_i;  // call: operator "" _i(12uLL)  | kind: integer
+  1.2_f; // call: operator "" _f(1.2L)   | kind: float
+  '2'_c; // call: operator "" _c('2')| kind: char
+
+  // TODO: Generate `FloatUserDefinedLiteralExpression` and
+  // `IntegerUserDefinedLiteralExpression` instead of
+  // `UnknownUserDefinedLiteralExpression`. See `getUserDefinedLiteralKind`
+  12_r;  // call: operator "" _r("12")   | kind: integer
+  1.2_r; // call: operator "" _i("1.2")  | kind: float
+  12_t;  // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t; // call: operator<'1', '2'> "" _x() | kind: float
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-unsigned
+| |   | |-long
+| |   | `-long
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_t
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -1208,28 +1296,95 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_i
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12u
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_f
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12l
+| |-CharUserDefinedLiteralExpression
+| | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-014
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-0XC
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_t
+| `-;
+|-ExpressionStatement
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_t
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedLiteralString) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+typedef decltype(sizeof(void *)) size_t;
+unsigned operator "" _s(const char*, size_t);
+void test() {
+  "12"_s;// call: operator "" _s("12")   | kind: string
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-typedef
+| |-decltype
+| |-(
+| |-UnknownExpression
+| | |-sizeof
+| | |-(
+| | |-void
+| | |-*
+| | `-)
+| |-)
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarat

[PATCH] D83480: Refactored NumericLiteralParser to not require a Preprocessor

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas accepted this revision.
eduucaldas added a comment.
This revision is now accepted and ready to land.

Additionally, consider applying a similar change to `CharLiteralParser`, for 
consistency.

All the comments are just suggestions. Feel free to land this without answering 
them.




Comment at: clang/include/clang/Lex/LiteralSupport.h:57-59
-  NumericLiteralParser(StringRef TokSpelling,
-   SourceLocation TokLoc,
-   Preprocessor &PP);

We don't need to remove this constructor, we can keep the same signature and 
make it call the new constructor. The same is done for `StringLiteralParser`.

That would allow some callers that don't care much about the implementation 
details to just use the simpler to write version.



Comment at: clang/lib/Lex/LiteralSupport.cpp:766
+  !isValidUDSuffix(LangOpts, StringRef(s, ThisTokEnd - s))) {
+Diags.Report(AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin),
+ diag::err_invalid_digit)

How about just using `Lexer::AdvanceToTokenCharacter`? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83480/new/

https://reviews.llvm.org/D83480



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276770.
eduucaldas added a comment.

Add support for integer and floating UDL even for raw literal operator and 
numeric literal operator template


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1204,9 +1204,6 @@
   1.2_f; // call: operator "" _f(1.2L)   | kind: float
   '2'_c; // call: operator "" _c('2')| kind: char
 
-  // TODO: Generate `FloatUserDefinedLiteralExpression` and
-  // `IntegerUserDefinedLiteralExpression` instead of
-  // `UnknownUserDefinedLiteralExpression`. See `getUserDefinedLiteralKind`
   12_r;  // call: operator "" _r("12")   | kind: integer
   1.2_r; // call: operator "" _i("1.2")  | kind: float
   12_t;  // call: operator<'1', '2'> "" _x() | kind: integer
@@ -1308,19 +1305,19 @@
 | | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-UnknownUserDefinedLiteralExpression
+| |-IntegerUserDefinedLiteralExpression
 | | `-12_r
 | `-;
 |-ExpressionStatement
-| |-UnknownUserDefinedLiteralExpression
+| |-FloatUserDefinedLiteralExpression
 | | `-1.2_r
 | `-;
 |-ExpressionStatement
-| |-UnknownUserDefinedLiteralExpression
+| |-IntegerUserDefinedLiteralExpression
 | | `-12_t
 | `-;
 |-ExpressionStatement
-| |-UnknownUserDefinedLiteralExpression
+| |-FloatUserDefinedLiteralExpression
 | | `-1.2_t
 | `-;
 `-}
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -32,8 +32,6 @@
 return OS << "BoolLiteralExpression";
   case NodeKind::CxxNullPtrExpression:
 return OS << "CxxNullPtrExpression";
-  case NodeKind::UnknownUserDefinedLiteralExpression:
-return OS << "UnknownUserDefinedLiteralExpression";
   case NodeKind::IntegerUserDefinedLiteralExpression:
 return OS << "IntegerUserDefinedLiteralExpression";
   case NodeKind::FloatUserDefinedLiteralExpression:
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/LiteralSupport.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "clang/Tooling/Syntax/Tree.h"
@@ -552,8 +553,8 @@
 namespace {
 class BuildTreeVisitor : public RecursiveASTVisitor {
 public:
-  explicit BuildTreeVisitor(ASTContext &Ctx, syntax::TreeBuilder &Builder)
-  : Builder(Builder), LangOpts(Ctx.getLangOpts()) {}
+  explicit BuildTreeVisitor(ASTContext &Context, syntax::TreeBuilder &Builder)
+  : Builder(Builder), Context(Context) {}
 
   bool shouldTraversePostOrder() const { return true; }
 
@@ -730,9 +731,19 @@
   return syntax::NodeKind::StringUserDefinedLiteralExpression;
 case clang::UserDefinedLiteral::LOK_Raw:
 case clang::UserDefinedLiteral::LOK_Template:
-  // FIXME: Apply `NumericLiteralParser` to the underlying token to deduce
-  // the right UDL kind. That would require a `Preprocessor` though.
-  return syntax::NodeKind::UnknownUserDefinedLiteralExpression;
+  auto TokLoc = S->getBeginLoc();
+  auto TokSpelling =
+  Builder.findToken(TokLoc)->text(Context.getSourceManager());
+  auto Literal = NumericLiteralParser{TokSpelling,
+  TokLoc,
+  Context.getSourceManager(),
+  Context.getLangOpts(),
+  Context.getTargetInfo(),
+  Context.getDiagnostics()};
+  if (Literal.isIntegerLiteral())
+return syntax::NodeKind::IntegerUserDefinedLiteralExpression;
+  else
+return syntax::NodeKind::FloatUserDefinedLiteralExpression;
 }
   }
 
@@ -1262,7 +1273,7 @@
   llvm::BumpPtrAllocator &allocator() { return Builder.allocator(); }
 
   syntax::TreeBuilder &Builder;
-  const LangOptions &LangOpts;
+  const ASTContext &Context;
 };
 } // namespace
 
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -50,7 +50,6 @@
   St

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276771.
eduucaldas added a comment.

nothing


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1204,9 +1204,6 @@
   1.2_f; // call: operator "" _f(1.2L)   | kind: float
   '2'_c; // call: operator "" _c('2')| kind: char
 
-  // TODO: Generate `FloatUserDefinedLiteralExpression` and
-  // `IntegerUserDefinedLiteralExpression` instead of
-  // `UnknownUserDefinedLiteralExpression`. See `getUserDefinedLiteralKind`
   12_r;  // call: operator "" _r("12")   | kind: integer
   1.2_r; // call: operator "" _i("1.2")  | kind: float
   12_t;  // call: operator<'1', '2'> "" _x() | kind: integer
@@ -1308,19 +1305,19 @@
 | | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-UnknownUserDefinedLiteralExpression
+| |-IntegerUserDefinedLiteralExpression
 | | `-12_r
 | `-;
 |-ExpressionStatement
-| |-UnknownUserDefinedLiteralExpression
+| |-FloatUserDefinedLiteralExpression
 | | `-1.2_r
 | `-;
 |-ExpressionStatement
-| |-UnknownUserDefinedLiteralExpression
+| |-IntegerUserDefinedLiteralExpression
 | | `-12_t
 | `-;
 |-ExpressionStatement
-| |-UnknownUserDefinedLiteralExpression
+| |-FloatUserDefinedLiteralExpression
 | | `-1.2_t
 | `-;
 `-}
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -32,8 +32,6 @@
 return OS << "BoolLiteralExpression";
   case NodeKind::CxxNullPtrExpression:
 return OS << "CxxNullPtrExpression";
-  case NodeKind::UnknownUserDefinedLiteralExpression:
-return OS << "UnknownUserDefinedLiteralExpression";
   case NodeKind::IntegerUserDefinedLiteralExpression:
 return OS << "IntegerUserDefinedLiteralExpression";
   case NodeKind::FloatUserDefinedLiteralExpression:
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/LiteralSupport.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "clang/Tooling/Syntax/Tree.h"
@@ -552,8 +553,8 @@
 namespace {
 class BuildTreeVisitor : public RecursiveASTVisitor {
 public:
-  explicit BuildTreeVisitor(ASTContext &Ctx, syntax::TreeBuilder &Builder)
-  : Builder(Builder), LangOpts(Ctx.getLangOpts()) {}
+  explicit BuildTreeVisitor(ASTContext &Context, syntax::TreeBuilder &Builder)
+  : Builder(Builder), Context(Context) {}
 
   bool shouldTraversePostOrder() const { return true; }
 
@@ -730,9 +731,19 @@
   return syntax::NodeKind::StringUserDefinedLiteralExpression;
 case clang::UserDefinedLiteral::LOK_Raw:
 case clang::UserDefinedLiteral::LOK_Template:
-  // FIXME: Apply `NumericLiteralParser` to the underlying token to deduce
-  // the right UDL kind. That would require a `Preprocessor` though.
-  return syntax::NodeKind::UnknownUserDefinedLiteralExpression;
+  auto TokLoc = S->getBeginLoc();
+  auto TokSpelling =
+  Builder.findToken(TokLoc)->text(Context.getSourceManager());
+  auto Literal = NumericLiteralParser{TokSpelling,
+  TokLoc,
+  Context.getSourceManager(),
+  Context.getLangOpts(),
+  Context.getTargetInfo(),
+  Context.getDiagnostics()};
+  if (Literal.isIntegerLiteral())
+return syntax::NodeKind::IntegerUserDefinedLiteralExpression;
+  else
+return syntax::NodeKind::FloatUserDefinedLiteralExpression;
 }
   }
 
@@ -1262,7 +1273,7 @@
   llvm::BumpPtrAllocator &allocator() { return Builder.allocator(); }
 
   syntax::TreeBuilder &Builder;
-  const LangOptions &LangOpts;
+  const ASTContext &Context;
 };
 } // namespace
 
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -50,7 +50,6 @@
   StringLiteralExpression,
   BoolLiteralExpression,
   CxxNullPtrExpression,
-  UnknownUserDefinedLiteralExpression,
   IntegerUserDefined

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked an inline comment as done.
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:736
+  auto TokSpelling =
+  Builder.findToken(TokLoc)->text(Context.getSourceManager());
+  auto Literal = NumericLiteralParser{TokSpelling,

Not sure if text is the right thing to get a `TokenSpelling` from a 
`syntax::Token`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276772.
eduucaldas added a comment.

Nothing


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,20 +1184,105 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+
+unsigned operator "" _r(const char*); // raw-literal operator
+
+template 
+unsigned operator "" _t();// numeric literal operator template
+
 void test() {
-  12;
-  12u;
-  12l;
-  12ul;
-  014;
-  0XC;
+  12_i;  // call: operator "" _i(12uLL)  | kind: integer
+  1.2_f; // call: operator "" _f(1.2L)   | kind: float
+  '2'_c; // call: operator "" _c('2')| kind: char
+
+  12_r;  // call: operator "" _r("12")   | kind: integer
+  1.2_r; // call: operator "" _i("1.2")  | kind: float
+  12_t;  // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t; // call: operator<'1', '2'> "" _x() | kind: float
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-unsigned
+| |   | |-long
+| |   | `-long
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_t
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -1208,28 +1293,95 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_i
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12u
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_f
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12l
+| |-CharUserDefinedLiteralExpression
+| | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-014
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-0XC
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_t
+| `-;
+|-ExpressionStatement
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_t
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedLiteralString) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+typedef decltype(sizeof(void *)) size_t;
+unsigned operator "" _s(const char*, size_t);
+void test() {
+  "12"_s;// call: operator "" _s("12")   | kind: string
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-typedef
+| |-decltype
+| |-(
+| |-UnknownExpression
+| | |-sizeof
+| | |-(
+| | |-void
+| | |-*
+| | `-)
+| |-)
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   |-,
+| |   |-SimpleDeclaration
+| |   | `-size_t
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-Strin

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276919.
eduucaldas marked 9 inline comments as done.
eduucaldas added a comment.

Use right function to get TokSpelling, answer comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,20 +1184,139 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+typedef decltype(sizeof(void *)) size_t;
+
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+unsigned operator "" _s(const char*, size_t);
+unsigned operator "" _r(const char*);
+template 
+unsigned operator "" _t();
+
 void test() {
-  12;
-  12u;
-  12l;
-  12ul;
-  014;
-  0XC;
+  12_i;   // call: operator "" _i(12uLL)  | kind: integer
+  1.2_f;  // call: operator "" _f(1.2L)   | kind: float
+  '2'_c;  // call: operator "" _c('2')| kind: char
+  "12"_s; // call: operator "" _s("12")   | kind: string
+
+  12_r;   // call: operator "" _r("12")   | kind: integer
+  1.2_r;  // call: operator "" _i("1.2")  | kind: float
+  12_t;   // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t;  // call: operator<'1', '2'> "" _x() | kind: float
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-typedef
+| |-decltype
+| |-(
+| |-UnknownExpression
+| | |-sizeof
+| | |-(
+| | |-void
+| | |-*
+| | `-)
+| |-)
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-unsigned
+| |   | |-long
+| |   | `-long
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   |-,
+| |   |-SimpleDeclaration
+| |   | `-size_t
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_t
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -1208,28 +1327,36 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_i
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12u
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_f
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12l
+| |-CharUserDefinedLiteralExpression
+| | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-StringUserDefinedLiteralExpression
+| | `-"12"_s
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-014
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-0XC
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_r
+| `-;
+|-ExpressionStatement
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_t
+| `-;
+|-ExpressionStatement
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_t
 | `-;
 `-}
 )txt"));
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -32,6 +32,14 @@
 return OS << "BoolLiteralExpression";
   case NodeKind::CxxNullPtrExpressio

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1210
+  12_t;  // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t; // call: operator<'1', '2'> "" _x() | kind: float
 }

gribozavr2 wrote:
> call -> calls? (as in, "this expression calls ...")
it is a noun here, as kind is.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82157: Fix crash on `user defined literals`

2020-07-09 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 2 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:723
+  syntax::UserDefinedLiteralExpression *
+  buildUserDefinedLiteral(UserDefinedLiteral *S) {
+switch (S->getLiteralOperatorKind()) {

b or B? Should I use camelCase or TitleCase?




Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:735-751
+  auto TokLoc = S->getBeginLoc();
+  auto buffer = SmallVector();
+  bool invalidSpelling = false;
+  auto TokSpelling =
+  Lexer::getSpelling(TokLoc, buffer, Context.getSourceManager(),
+ Context.getLangOpts(), &invalidSpelling);
+  assert(!invalidSpelling);

I'll write a comment explaining why this crazyness. Promise not to rant about 
the lexer that doesn't distinguish between float and integer.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:738-740
+  auto TokSpelling =
+  Lexer::getSpelling(TokLoc, buffer, Context.getSourceManager(),
+ Context.getLangOpts(), &invalidSpelling);

This is exactly the function used by the parser to get the `TokSpelling`. see: 
llvm-project/clang/lib/Sema/SemaExpr.cpp:3633


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82157: Fix crash on `user defined literals`

2020-07-10 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276960.
eduucaldas added a comment.

- Add comment explaining complication on LOK_Raw and LOK_Template
- Use FileRange::text instead of Lexer::getSpelling


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,20 +1184,139 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+typedef decltype(sizeof(void *)) size_t;
+
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+unsigned operator "" _s(const char*, size_t);
+unsigned operator "" _r(const char*);
+template 
+unsigned operator "" _t();
+
 void test() {
-  12;
-  12u;
-  12l;
-  12ul;
-  014;
-  0XC;
+  12_i;   // call: operator "" _i(12uLL)  | kind: integer
+  1.2_f;  // call: operator "" _f(1.2L)   | kind: float
+  '2'_c;  // call: operator "" _c('2')| kind: char
+  "12"_s; // call: operator "" _s("12")   | kind: string
+
+  12_r;   // call: operator "" _r("12")   | kind: integer
+  1.2_r;  // call: operator "" _i("1.2")  | kind: float
+  12_t;   // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t;  // call: operator<'1', '2'> "" _x() | kind: float
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-typedef
+| |-decltype
+| |-(
+| |-UnknownExpression
+| | |-sizeof
+| | |-(
+| | |-void
+| | |-*
+| | `-)
+| |-)
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-unsigned
+| |   | |-long
+| |   | `-long
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   |-,
+| |   |-SimpleDeclaration
+| |   | `-size_t
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_t
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -1208,28 +1327,36 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_i
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12u
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_f
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12l
+| |-CharUserDefinedLiteralExpression
+| | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-StringUserDefinedLiteralExpression
+| | `-"12"_s
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-014
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-0XC
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_r
+| `-;
+|-ExpressionStatement
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_t
+| `-;
+|-ExpressionStatement
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_t
 | `-;
 `-}
 )txt"));
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -32,6 +32,14 @@
 return OS << "BoolLiteralExpression";
   case NodeKind::C

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-10 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 277060.
eduucaldas marked an inline comment as done.
eduucaldas added a comment.

Add assert


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,20 +1184,139 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+typedef decltype(sizeof(void *)) size_t;
+
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+unsigned operator "" _s(const char*, size_t);
+unsigned operator "" _r(const char*);
+template 
+unsigned operator "" _t();
+
 void test() {
-  12;
-  12u;
-  12l;
-  12ul;
-  014;
-  0XC;
+  12_i;   // call: operator "" _i(12uLL)  | kind: integer
+  1.2_f;  // call: operator "" _f(1.2L)   | kind: float
+  '2'_c;  // call: operator "" _c('2')| kind: char
+  "12"_s; // call: operator "" _s("12")   | kind: string
+
+  12_r;   // call: operator "" _r("12")   | kind: integer
+  1.2_r;  // call: operator "" _i("1.2")  | kind: float
+  12_t;   // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t;  // call: operator<'1', '2'> "" _x() | kind: float
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-typedef
+| |-decltype
+| |-(
+| |-UnknownExpression
+| | |-sizeof
+| | |-(
+| | |-void
+| | |-*
+| | `-)
+| |-)
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-unsigned
+| |   | |-long
+| |   | `-long
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   |-,
+| |   |-SimpleDeclaration
+| |   | `-size_t
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_t
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -1208,28 +1327,36 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_i
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12u
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_f
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12l
+| |-CharUserDefinedLiteralExpression
+| | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-StringUserDefinedLiteralExpression
+| | `-"12"_s
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-014
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-0XC
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_r
+| `-;
+|-ExpressionStatement
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_t
+| `-;
+|-ExpressionStatement
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_t
 | `-;
 `-}
 )txt"));
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -32,6 +32,14 @@
 return OS << "BoolLiteralExpression";
   case NodeKind::CxxNullPtrExpression:
 return OS << "CxxNullPtrExpression";

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-10 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf33c2c27a8d4: Fix crash on `user defined literals` (authored 
by eduucaldas).

Changed prior to commit:
  https://reviews.llvm.org/D82157?vs=277060&id=277071#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -1184,20 +1184,108 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+
+unsigned operator "" _r(const char*); // raw-literal operator
+
+template 
+unsigned operator "" _t();// numeric literal operator template
+
 void test() {
-  12;
-  12u;
-  12l;
-  12ul;
-  014;
-  0XC;
+  12_i;  // call: operator "" _i(12uLL)  | kind: integer
+  1.2_f; // call: operator "" _f(1.2L)   | kind: float
+  '2'_c; // call: operator "" _c('2')| kind: char
+
+  // TODO: Generate `FloatUserDefinedLiteralExpression` and
+  // `IntegerUserDefinedLiteralExpression` instead of
+  // `UnknownUserDefinedLiteralExpression`. See `getUserDefinedLiteralKind`
+  12_r;  // call: operator "" _r("12")   | kind: integer
+  1.2_r; // call: operator "" _i("1.2")  | kind: float
+  12_t;  // call: operator<'1', '2'> "" _x() | kind: integer
+  1.2_t; // call: operator<'1', '2'> "" _x() | kind: float
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-unsigned
+| |   | |-long
+| |   | `-long
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_t
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -1208,28 +1296,95 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12
+| |-IntegerUserDefinedLiteralExpression
+| | `-12_i
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12u
+| |-FloatUserDefinedLiteralExpression
+| | `-1.2_f
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12l
+| |-CharUserDefinedLiteralExpression
+| | `-'2'_c
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-12ul
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-014
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_r
 | `-;
 |-ExpressionStatement
-| |-IntegerLiteralExpression
-| | `-0XC
+| |-UnknownUserDefinedLiteralExpression
+| | `-12_t
+| `-;
+|-ExpressionStatement
+| |-UnknownUserDefinedLiteralExpression
+| | `-1.2_t
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedLiteralString) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+typedef decltype(sizeof(void *)) size_t;
+unsigned operator "" _s(const char*, size_t);
+void test() {
+  "12"_s;// call: operator "" _s("12")   | kind: string
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-typedef
+| |-decltype
+| |-(
+| |-UnknownExpression
+| | |-sizeof
+| | |-(
+| | |-void
+| | |-*
+| | `-)
+| |-)
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| |   |-(
+| 

[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-18 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 271744.
eduucaldas marked 12 inline comments as done.
eduucaldas added a comment.

Aswering comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -485,8 +485,9 @@
 | | |-SimpleDeclarator
 | | | `-x
 | | `-:
-| |-UnknownExpression
-| | `-a
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-a
 | |-)
 | `-EmptyStatement
 |   `-;
@@ -662,8 +663,9 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-UnknownExpression
-| | | `-test
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-test
 | | |-(
 | | `-)
 | `-;
@@ -675,16 +677,18 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-UnknownExpression
-| | | | `-test
+| | | |-IdExpression
+| | | | `-UnqualifiedId
+| | | |   `-test
 | | | |-(
 | | | `-)
 | | `-;
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-UnknownExpression
-|   | | `-test
+|   | |-IdExpression
+|   | | `-UnqualifiedId
+|   | |   `-test
 |   | |-(
 |   | `-)
 |   `-;
@@ -692,6 +696,509 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UnqualifiedId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  // TODO: Expose `id-expression` from `Declarator`
+  friend X operator+(const X&, const X&);
+  operator int();
+};
+template
+void f(T&);
+void test(X x) {
+  x;  // identifier
+  operator+(x, x);// operator-function-id
+  f(x);// template-id
+  // TODO: Expose `id-expression` from `MemberExpr`
+  x.operator int();   // conversion-funtion-id
+  x.~X(); // ~type-name
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-+
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-int
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-void
+|   |-SimpleDeclarator
+|   | |-f
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   |-SimpleDeclaration
+|   |   | |-T
+|   |   | `-SimpleDeclarator
+|   |   |   `-&
+|   |   `-)
+|   `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-x
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   `-+
+| | |-(
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-,
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-f
+| | |   |-<
+| | |   |-X
+| | |   `->
+| | |-(
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-UnknownExpression
+| | | |-IdExpression
+| | | | `-UnqualifiedId
+| | | |   `-x
+| | | |-.
+| | | |-operator
+| | | `-int
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-UnknownExpression
+| | | |-IdExpression
+| | | | `-UnqualifiedId
+| | | |   `-x
+| | | |-.
+| | | |-~
+| | | `-X
+| | |-(
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdCxx11OrLater) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X { };
+unsigned operator "" _w(long long unsigned);
+void test(X x) {
+  

[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-18 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 2 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:190
+return N->kind() == NodeKind::NameSpecifier;
+  }
+};

eduucaldas wrote:
> gribozavr2 wrote:
> > Should there be getters for various parts of the specifier?
> I think not.
Pospone to interface discussion with Yitzhak



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:214
+return N->kind() == NodeKind::UnqualifiedId;
+  }
+};

gribozavr2 wrote:
> Could you add TODOs about adding accessors?
Pospone to interface discussion with Yitzhak



Comment at: clang/lib/Tooling/Syntax/Nodes.cpp:178
 }
 
+std::vector syntax::NestedNameSpecifier::specifiers() 
{

I was thinking and our problem is bigger than not testing for `NodeRole`s, we 
don't test accessors at all!



Comment at: clang/lib/Tooling/Syntax/Nodes.cpp:182
+  for (auto *C = firstChild(); C; C = C->nextSibling()) {
+if (C->role() == syntax::NodeRole::NestedNameSpecifier_specifier)
+  Children.push_back(llvm::cast(C));

This should be an assert for now, as if that is not true it would be a logic 
problem. Same reasoning applies to `CompoundStatement`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81168: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-18 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 271784.
eduucaldas added a comment.

change if -> asserts


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81168/new/

https://reviews.llvm.org/D81168

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -485,8 +485,9 @@
 | | |-SimpleDeclarator
 | | | `-x
 | | `-:
-| |-UnknownExpression
-| | `-a
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-a
 | |-)
 | `-EmptyStatement
 |   `-;
@@ -662,8 +663,9 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-UnknownExpression
-| | | `-test
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-test
 | | |-(
 | | `-)
 | `-;
@@ -675,16 +677,18 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-UnknownExpression
-| | | | `-test
+| | | |-IdExpression
+| | | | `-UnqualifiedId
+| | | |   `-test
 | | | |-(
 | | | `-)
 | | `-;
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-UnknownExpression
-|   | | `-test
+|   | |-IdExpression
+|   | | `-UnqualifiedId
+|   | |   `-test
 |   | |-(
 |   | `-)
 |   `-;
@@ -692,6 +696,509 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UnqualifiedId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  // TODO: Expose `id-expression` from `Declarator`
+  friend X operator+(const X&, const X&);
+  operator int();
+};
+template
+void f(T&);
+void test(X x) {
+  x;  // identifier
+  operator+(x, x);// operator-function-id
+  f(x);// template-id
+  // TODO: Expose `id-expression` from `MemberExpr`
+  x.operator int();   // conversion-funtion-id
+  x.~X(); // ~type-name
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-+
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-int
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-void
+|   |-SimpleDeclarator
+|   | |-f
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   |-SimpleDeclaration
+|   |   | |-T
+|   |   | `-SimpleDeclarator
+|   |   |   `-&
+|   |   `-)
+|   `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-x
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   `-+
+| | |-(
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-,
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-f
+| | |   |-<
+| | |   |-X
+| | |   `->
+| | |-(
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-UnknownExpression
+| | | |-IdExpression
+| | | | `-UnqualifiedId
+| | | |   `-x
+| | | |-.
+| | | |-operator
+| | | `-int
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-UnknownExpression
+| | | |-IdExpression
+| | | | `-UnqualifiedId
+| | | |   `-x
+| | | |-.
+| | | |-~
+| | | `-X
+| | |-(
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdCxx11OrLater) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X { };
+unsigned operator "" _w(long long unsigned);
+void test(X x) {
+  operator "" _w(1llu);   // literal-operator

[PATCH] D82157: Fix crash on `user defined literals`

2020-06-19 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Given an UserDefinedLiteral `1.2_w`:
Problem: Lexer generates one Token for the literal, but ClangAST
references two source locations
Fix: Ignore the operator and interpret it as the underlying literal.
e.g.: `1.2_w` token generates syntax node IntegerLiteral(1.2_w)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82157

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
@@ -1228,6 +1228,95 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+long double operator "" _w(long double);
+unsigned operator "" _w(const char*);
+template  unsigned operator "" _x();
+int main() {
+1.2_w; // calls operator "" _w(1.2L)
+12_w;  // calls operator "" _w("12")
+12_x;  // calls operator<'1', '2'> "" _x()
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-long
+| |-double
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_x
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-main
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UnknownExpression
+| | `-UnknownExpression
+| |   `-1.2_w
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | `-UnknownExpression
+| |   `-12_w
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | `-12_x
+| `-;
+`-}
+)txt"));
+}
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -624,6 +624,9 @@
   }
 
   bool WalkUpFromDeclRefExpr(DeclRefExpr *S) {
+if (S->getNameInfo().getName().getNameKind() ==
+clang::DeclarationName::CXXLiteralOperatorName)
+  return true;
 if (auto *NNS = BuildNestedNameSpecifier(S->getQualifierLoc()))
   Builder.markChild(NNS, syntax::NodeRole::IdExpression_qualifier);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82157: Fix crash on `user defined literals`

2020-06-19 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 271980.
eduucaldas added a comment.

Why does this work?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82157/new/

https://reviews.llvm.org/D82157

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
@@ -1228,6 +1228,93 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+long double operator "" _w(long double);
+unsigned operator "" _w(const char*);
+template  unsigned operator "" _x();
+int main() {
+1.2_w; // calls operator "" _w(1.2L)
+12_w;  // calls operator "" _w("12")
+12_x;  // calls operator<'1', '2'> "" _x()
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-long
+| |-double
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_x
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-main
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UserDefinedLiteralExpression
+| | `-1.2_w
+| `-;
+|-ExpressionStatement
+| |-UserDefinedLiteralExpression
+| | `-12_w
+| `-;
+|-ExpressionStatement
+| |-UserDefinedLiteralExpression
+| | `-12_x
+| `-;
+`-}
+)txt"));
+}
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -623,6 +623,19 @@
 return NNS;
   }
 
+  bool TraverseUserDefinedLiteral(UserDefinedLiteral *S) { return true; }
+
+  bool WalkUpFromUserDefinedLiteral(UserDefinedLiteral *S) {
+// The user-defined-literal `1.2_w` is not split in the tokens `1.2` and
+// `_w` as we might imagine, its tokens are `1.2_w` only.
+// As a node is built by folding tokens we cannot generate one
+// for `_w`
+Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::IntegerLiteralExpression, S);
+return true;
+  }
+
   bool WalkUpFromDeclRefExpr(DeclRefExpr *S) {
 if (auto *NNS = BuildNestedNameSpecifier(S->getQualifierLoc()))
   Builder.markChild(NNS, syntax::NodeRole::IdExpression_qualifier);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82302: [Discussion] Interface for nodes related to id-expression

2020-06-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82302

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h

Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -45,6 +45,7 @@
   BinaryOperatorExpression,
   CxxNullPtrExpression,
   IntegerLiteralExpression,
+  IdExpression,
 
   // Statements.
   UnknownStatement,
@@ -84,7 +85,12 @@
   ArraySubscript,
   TrailingReturnType,
   ParametersAndQualifiers,
-  MemberPointer
+  MemberPointer,
+  NestedNameSpecifier,
+  NameSpecifier,
+  NamespaceName,
+  UnqualifiedId,
+  OperatorFunctionId,
 };
 /// For debugging purposes.
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NodeKind K);
@@ -187,6 +193,130 @@
   }
 };
 
+/// A sequence of these specifiers make a `nested-name-specifier`.
+/// e.g. the `std::` or `vector::` in `std::vector::size`.
+/// nested-name-specifier:
+///   ::
+///   type-name ::
+///   namespace-name ::
+///   decltype-specifier ::
+///   nested-name-specifier identifier ::
+///   nested-name-specifier template_opt simple-template-id ::
+class NameSpecifier final : public Tree {
+private:
+  // See discussion about implementation in UnqualifiedId
+  enum SpecifierKind {
+Global,
+TypeSpec,
+Namespace,
+DecltypeSpec,
+Identifier,
+TypeSpecWithTemplate
+  };
+
+public:
+  NameSpecifier() : Tree(NodeKind::NameSpecifier) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::NameSpecifier;
+  }
+  SpecifierKind getKind();
+  syntax::Leaf *getIdentifier();
+  syntax::Leaf *getNamespaceName();
+  //(...)
+  syntax::Leaf &doubleCommaToken();
+};
+
+/// Models a `nested-name-specifier`. C++ [expr.prim.id.qual]
+/// e.g. the `std::vector::` in `std::vector::size`.
+class NestedNameSpecifier final : public Tree {
+public:
+  NestedNameSpecifier() : Tree(NodeKind::NestedNameSpecifier) {}
+  static bool classof(const Node *N) {
+return N->kind() <= NodeKind::NestedNameSpecifier;
+  }
+  std::vector specifiers();
+};
+
+/// Models a `operator-function-id`. C++ [over.oper]
+/// operator-function-id:
+///   'operator' operator
+/// operator:
+///   +   -   *   /   =
+/// (...)
+class OperatorFunctionId final : public Tree {
+public:
+  OperatorFunctionId() : Tree(NodeKind::OperatorFunctionId) {}
+  static bool classof(const Node *N) {
+return N->kind() <= NodeKind::OperatorFunctionId;
+  }
+  syntax::Leaf &operatorKeyword();
+  syntax::Leaf &operatorCode();
+};
+
+/// Models an `unqualified-id`.  / e.g. the `size` in `std::vector::size`.
+// C++ [expr.prim.id.unqual]
+// unqualified-id:
+//   identifier
+//   operator-function-id
+//   conversion-function-id
+//   literal-operator-id
+//   ~ type-name
+//   ~ decltype-specifier
+//   template-id
+class UnqualifiedId final : public Tree {
+  // The variants of `unqualified-id` - `identifier`, `operator-function-id`,
+  // ... - appear in other parts of the syntax. As such we want to implement
+  // them detached from `unqualified-id`. How to implement accessors to these
+  // variants?
+  //  * Store an union with the variants and an enum of the kinds of
+  //variants. Access these variants by asking of what kind is
+  //`unqualified-id` and then using the appropriate getter. See:
+  //`UnqualifiedId` in "llvm-project/clang/include/clang/Sema/DeclSpec.h".
+  //  * Similar but using std::variant instead of union.
+  //  * not implement those accessors.
+private:
+  enum class UnqualifiedIdKind {
+IK_Identifier,
+IK_OperatorFunctionId,
+IK_ConversionFunctionId,
+IK_LiteralOperatorId,
+IK_DestructorName,
+IK_TemplateId,
+  };
+
+public:
+  UnqualifiedId() : Tree(NodeKind::UnqualifiedId) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::UnqualifiedId;
+  }
+  UnqualifiedIdKind getKind();
+  syntax::Leaf *getIdentifier();
+  syntax::OperatorFunctionId *getOperatorFunctionId();
+  // (...)
+};
+
+/// Models an `id-expression`, e.g. `std::vector::size`.
+/// C++ [expr.prim.id]
+/// id-expression:
+///   unqualified-id
+///   qualified-id
+/// qualified-id:
+///   nested-name-specifier template_opt unqualified-id
+class IdExpression final : public Expression {
+public:
+  IdExpression() : Expression(NodeKind::IdExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::IdExpression;
+  }
+  // `qualifier` and `templateKeyword` are optional children of
+  // id-expression whereas id is a required child.
+  // How to make this distinction clear both to the reader and to the compiler?
+  syntax::NestedNameSpecifier *qualifier();
+  syntax::Leaf *templateKeyword();
+
+  syntax::UnqualifiedId &id();
+};
+
 /// C++11 'nullptr' expression.
 class CxxNullPtrExpression final : public Expressi

[PATCH] D82302: [Discussion] Interface for nodes related to id-expression

2020-06-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 272445.
eduucaldas added a comment.

update comments, rollback references, and add them as proposition


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82302/new/

https://reviews.llvm.org/D82302

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h

Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -45,6 +45,7 @@
   BinaryOperatorExpression,
   CxxNullPtrExpression,
   IntegerLiteralExpression,
+  IdExpression,
 
   // Statements.
   UnknownStatement,
@@ -84,7 +85,11 @@
   ArraySubscript,
   TrailingReturnType,
   ParametersAndQualifiers,
-  MemberPointer
+  MemberPointer,
+  NestedNameSpecifier,
+  NameSpecifier,
+  UnqualifiedId,
+  OperatorFunctionId,
 };
 /// For debugging purposes.
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NodeKind K);
@@ -187,6 +192,135 @@
   }
 };
 
+/// A sequence of these specifiers make a `nested-name-specifier`.
+/// e.g. the `std::` or `vector::` in `std::vector::size`.
+class NameSpecifier final : public Tree {
+private:
+  // See discussion about implementation in UnqualifiedId
+  /// From C++ [expr.prim.id.qual]
+  /// nested-name-specifier:
+  ///   ::
+  ///   type-name ::
+  ///   namespace-name ::
+  ///   decltype-specifier ::
+  ///   nested-name-specifier identifier ::
+  ///   nested-name-specifier template_opt simple-template-id ::
+  enum SpecifierKind {
+Global,
+TypeSpec,
+Namespace,
+DecltypeSpec,
+Identifier,
+TypeSpecWithTemplate
+  };
+
+public:
+  NameSpecifier() : Tree(NodeKind::NameSpecifier) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::NameSpecifier;
+  }
+  SpecifierKind getKind();
+  syntax::Leaf *getIdentifier();
+  syntax::Leaf *getNamespaceName();
+  //(...)
+  syntax::Leaf *doubleCommaToken();
+};
+
+/// Models a `nested-name-specifier`. C++ [expr.prim.id.qual]
+/// e.g. the `std::vector::` in `std::vector::size`.
+class NestedNameSpecifier final : public Tree {
+public:
+  NestedNameSpecifier() : Tree(NodeKind::NestedNameSpecifier) {}
+  static bool classof(const Node *N) {
+return N->kind() <= NodeKind::NestedNameSpecifier;
+  }
+  std::vector specifiers();
+};
+
+/// Models a `operator-function-id`. C++ [over.oper]
+/// operator-function-id:
+///   'operator' operator
+/// operator:
+///   +   -   *   /   =
+/// (...)
+class OperatorFunctionId final : public Tree {
+public:
+  OperatorFunctionId() : Tree(NodeKind::OperatorFunctionId) {}
+  static bool classof(const Node *N) {
+return N->kind() <= NodeKind::OperatorFunctionId;
+  }
+  syntax::Leaf *operatorKeyword();
+  syntax::Leaf *operatorCode();
+};
+
+/// Models an `unqualified-id`, e.g. the `size` in `std::vector::size`.
+// C++ [expr.prim.id.unqual]
+// unqualified-id:
+//   identifier
+//   operator-function-id
+//   conversion-function-id
+//   literal-operator-id
+//   ~ type-name
+//   ~ decltype-specifier
+//   template-id
+class UnqualifiedId final : public Tree {
+  // The variants of `unqualified-id` - `identifier`, `operator-function-id`,
+  // ... - appear in other parts of the syntax. As such we want to implement
+  // them detached from `unqualified-id`. How to implement accessors to these
+  // variants?
+  //  * Store an union with the variants and an enum of the kinds of
+  //variants. Access these variants by asking of what kind is
+  //`unqualified-id` and then using the appropriate getter. See:
+  //`UnqualifiedId` in "llvm-project/clang/include/clang/Sema/DeclSpec.h".
+  //  * Similar but using std::variant instead of union.
+  //  * not implement those accessors.
+private:
+  enum class UnqualifiedIdKind {
+IK_Identifier,
+IK_OperatorFunctionId,
+IK_ConversionFunctionId,
+IK_LiteralOperatorId,
+IK_DestructorName,
+IK_TemplateId,
+  };
+
+public:
+  UnqualifiedId() : Tree(NodeKind::UnqualifiedId) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::UnqualifiedId;
+  }
+  UnqualifiedIdKind getKind();
+  syntax::Leaf *getIdentifier();
+  syntax::OperatorFunctionId *getOperatorFunctionId();
+  // (...)
+};
+
+/// Models an `id-expression`, e.g. `std::vector::size`.
+/// C++ [expr.prim.id]
+/// id-expression:
+///   unqualified-id
+///   qualified-id
+/// qualified-id:
+///   nested-name-specifier template_opt unqualified-id
+class IdExpression final : public Expression {
+public:
+  IdExpression() : Expression(NodeKind::IdExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::IdExpression;
+  }
+  // `qualifier` and `templateKeyword` are optional children of
+  // id-expression whereas id is a required child.
+  // How to make this distinction clear both to the reader and to the compiler?
+  // For children that are:
+  //  * required: use reference; optiona

[PATCH] D82310: Add `BoolLiteralExpression` to SyntaxTree

2020-06-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82310

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -51,6 +51,7 @@
   TestLanguage Language;
   std::string Target;
 
+  bool isC() const { return Language == Lang_C89 || Language == Lang_C99; }
   bool isC99OrLater() const { return Language == Lang_C99; }
 
   bool isCXX() const {
@@ -1228,6 +1229,40 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, BoolLiteral) {
+  if (GetParam().isC()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+  true;
+  false;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BoolLiteralExpression
+| | `-true
+| `-;
+|-ExpressionStatement
+| |-BoolLiteralExpression
+| | `-false
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
@@ -1691,18 +1726,18 @@
 |-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-BoolLiteralExpression
 | | | `-true
 | | |-||
-| | `-UnknownExpression
+| | `-BoolLiteralExpression
 | |   `-false
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
-| | |-UnknownExpression
+| | |-BoolLiteralExpression
 | | | `-true
 | | |-or
-| | `-UnknownExpression
+| | `-BoolLiteralExpression
 | |   `-false
 | `-;
 |-ExpressionStatement
@@ -2556,7 +2591,7 @@
 |-StaticAssertDeclaration
 | |-static_assert
 | |-(
-| |-UnknownExpression
+| |-BoolLiteralExpression
 | | `-true
 | |-,
 | |-UnknownExpression
@@ -2566,7 +2601,7 @@
 `-StaticAssertDeclaration
   |-static_assert
   |-(
-  |-UnknownExpression
+  |-BoolLiteralExpression
   | `-true
   |-)
   `-;
@@ -3186,7 +3221,7 @@
   |   |-)
   |   |-noexcept
   |   |-(
-  |   |-UnknownExpression
+  |   |-BoolLiteralExpression
   |   | `-true
   |   `-)
   `-;
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -22,6 +22,8 @@
 return OS << "CxxNullPtrExpression";
   case NodeKind::IntegerLiteralExpression:
 return OS << "IntegerLiteralExpression";
+  case NodeKind::BoolLiteralExpression:
+return OS << "BoolLiteralExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -200,6 +202,11 @@
   findChild(syntax::NodeRole::LiteralToken));
 }
 
+syntax::Leaf *syntax::BoolLiteralExpression::literalToken() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::LiteralToken));
+}
+
 syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::LiteralToken));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -654,6 +654,13 @@
 return true;
   }
 
+  bool WalkUpFromCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::BoolLiteralExpression, S);
+return true;
+  }
+
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -45,6 +45,7 @@
   BinaryOperatorExpression,
   CxxNullPtrExpression,
   IntegerLiteralExpression,
+  BoolLiteralExpression,
   IdExpression,
 
   // Statements.
@@ -264,6 +265,16 @@
   syntax::Leaf *literalToken();
 };
 
+/// Expression for boolean literals. C++ [lex.bool]
+class BoolLiteralExpression final : public Expression {
+public:
+  BoolLiteralExpression() : Expression(NodeKind::BoolLiteralExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::BoolLiteralExpression;
+  }
+  syntax::Leaf *literalToken();
+};
+
 /// An abstract class for prefix and postfix una

[PATCH] D82310: Add `BoolLiteralExpression` to SyntaxTree

2020-06-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 3 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:268
 
+/// Expression for boolean literals. C++ [lex.bool]
+class BoolLiteralExpression final : public Expression {

Homogenize this comments for other literals, and possibly other expressions. To 
be done in future change



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:269
+/// Expression for boolean literals. C++ [lex.bool]
+class BoolLiteralExpression final : public Expression {
+public:

Unify Literals under a Literal class, following the grammar, [lex.literal]
To be done in a future change



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:54
 
+  bool isC() const { return Language == Lang_C89 || Language == Lang_C99; }
   bool isC99OrLater() const { return Language == Lang_C99; }

We could use this to extend the coverage of our tests from `isCXX` to `!isC`. 
To be done in a future change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82310/new/

https://reviews.llvm.org/D82310



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82312: Add `CharLiteral` to SyntaxTree

2020-06-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a reviewer: gribozavr2.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82312

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -69,6 +69,10 @@
Language == Lang_CXX20;
   }
 
+  bool isCXX17OrLater() const {
+return Language == Lang_CXX17 || Language == Lang_CXX20;
+  }
+
   bool supportsCXXDynamicExceptionSpecification() const {
 return Language == Lang_CXX03 || Language == Lang_CXX11 ||
Language == Lang_CXX14;
@@ -1228,6 +1232,100 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, CharacterLiteral) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+  'a';
+  L'a';
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-CharacterLiteralExpression
+| | `-'a'
+| `-;
+|-ExpressionStatement
+| |-CharacterLiteralExpression
+| | `-L'a'
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, CharacterLiteralCxx11) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+  u'a';
+  U'a';
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-CharacterLiteralExpression
+| | `-u'a'
+| `-;
+|-ExpressionStatement
+| |-CharacterLiteralExpression
+| | `-U'a'
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, CharacterLiteralCxx17) {
+  if (!GetParam().isCXX17OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+  u8'a';
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-CharacterLiteralExpression
+| | `-u8'a'
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -22,6 +22,8 @@
 return OS << "CxxNullPtrExpression";
   case NodeKind::IntegerLiteralExpression:
 return OS << "IntegerLiteralExpression";
+  case NodeKind::CharacterLiteralExpression:
+return OS << "CharacterLiteralExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -200,6 +202,11 @@
   findChild(syntax::NodeRole::LiteralToken));
 }
 
+syntax::Leaf *syntax::CharacterLiteralExpression::literalToken() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::LiteralToken));
+}
+
 syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::LiteralToken));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -654,6 +654,13 @@
 return true;
   }
 
+  bool WalkUpFromCharacterLiteral(CharacterLiteral *S) {
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::CharacterLiteralExpression, S);
+return true;
+  }
+
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -45,6 +45,7 @@
   BinaryOperatorExpression,
   CxxNullPtrExpression,
   IntegerLiteralExpression,
+  CharacterLiteralExpression,
   IdExpression,
 
   // Statements.
@@ -254,6 +255,17 @@
   syntax::Leaf *nullPtrKeyword();
 };
 
+/// Expression for character literals. C++ [lex.ccon]
+class CharacterLiteralExpression final : public Expression {
+public:
+  CharacterLiteralExpression()
+  : Expression(NodeKind::CharacterLiteralExpression) {}
+  sta

[PATCH] D82318: Add `FloatingLiteral` to SyntaxTree

2020-06-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 272492.
eduucaldas added a comment.

removing automatically added include


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82318/new/

https://reviews.llvm.org/D82318

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -69,6 +69,10 @@
Language == Lang_CXX20;
   }
 
+  bool isCXX17OrLater() const {
+return Language == Lang_CXX17 || Language == Lang_CXX20;
+  }
+
   bool supportsCXXDynamicExceptionSpecification() const {
 return Language == Lang_CXX03 || Language == Lang_CXX11 ||
Language == Lang_CXX14;
@@ -1228,6 +1232,91 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, FloatingLiteral) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+1e-2;
+2.;
+.2;
+2.f;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-1e-2
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-2.
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-.2
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-2.f
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, FloatingLiteralHexadecimal) {
+  if (!GetParam().isCXX17OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+0xfp1;
+0xf.p1;
+0x.fp1;
+0xf.fp1f;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-0xfp1
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-0xf.p1
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-0x.fp1
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-0xf.fp1f
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -22,6 +22,8 @@
 return OS << "CxxNullPtrExpression";
   case NodeKind::IntegerLiteralExpression:
 return OS << "IntegerLiteralExpression";
+  case NodeKind::FloatingLiteralExpression:
+return OS << "FloatingLiteralExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -195,6 +197,11 @@
   findChild(syntax::NodeRole::IdExpression_id));
 }
 
+syntax::Leaf *syntax::FloatingLiteralExpression::literalToken() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::LiteralToken));
+}
+
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::LiteralToken));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -654,6 +654,13 @@
 return true;
   }
 
+  bool WalkUpFromFloatingLiteral(FloatingLiteral *S) {
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::FloatingLiteralExpression, S);
+return true;
+  }
+
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -45,6 +45,7 @@
   BinaryOperatorExpression,
   CxxNullPtrExpression,
   IntegerLiteralExpression,
+  FloatingLiteralExpression,
   IdExpression,
 
   // Statements.
@@ -254,6 +255,17 @@
   syntax::Leaf *nullPtrKeyword();
 };
 
+/// Expression for floating-point literals. C++ [lex.fcon]
+class FloatingLiteralExpression final : public Expression {
+public:
+  FloatingLiteralExpression()
+  : Expression(NodeKind::FloatingLiteralExpression) {}
+  static bool classof(const Node *N) 

[PATCH] D82318: Add `FloatingLiteral` to SyntaxTree

2020-06-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas updated this revision to Diff 272492.
eduucaldas added a comment.

removing automatically added include


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82318

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.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
@@ -69,6 +69,10 @@
Language == Lang_CXX20;
   }
 
+  bool isCXX17OrLater() const {
+return Language == Lang_CXX17 || Language == Lang_CXX20;
+  }
+
   bool supportsCXXDynamicExceptionSpecification() const {
 return Language == Lang_CXX03 || Language == Lang_CXX11 ||
Language == Lang_CXX14;
@@ -1228,6 +1232,91 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, FloatingLiteral) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+1e-2;
+2.;
+.2;
+2.f;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-1e-2
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-2.
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-.2
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-2.f
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, FloatingLiteralHexadecimal) {
+  if (!GetParam().isCXX17OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+0xfp1;
+0xf.p1;
+0x.fp1;
+0xf.fp1f;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-0xfp1
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-0xf.p1
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-0x.fp1
+| `-;
+|-ExpressionStatement
+| |-FloatingLiteralExpression
+| | `-0xf.fp1f
+| `-;
+`-}
+)txt"));
+}
+
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -22,6 +22,8 @@
 return OS << "CxxNullPtrExpression";
   case NodeKind::IntegerLiteralExpression:
 return OS << "IntegerLiteralExpression";
+  case NodeKind::FloatingLiteralExpression:
+return OS << "FloatingLiteralExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -195,6 +197,11 @@
   findChild(syntax::NodeRole::IdExpression_id));
 }
 
+syntax::Leaf *syntax::FloatingLiteralExpression::literalToken() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::LiteralToken));
+}
+
 syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::LiteralToken));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -654,6 +654,13 @@
 return true;
   }
 
+  bool WalkUpFromFloatingLiteral(FloatingLiteral *S) {
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::FloatingLiteralExpression, S);
+return true;
+  }
+
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -45,6 +45,7 @@
   BinaryOperatorExpression,
   CxxNullPtrExpression,
   IntegerLiteralExpression,
+  FloatingLiteralExpression,
   IdExpression,
 
   // Statements.
@@ -254,6 +255,17 @@
   syntax::Leaf *nullPtrKeyword();
 };
 
+/// Expression for floating-point literals. C++ [lex.fcon]
+class FloatingLiteralExpression final : public Expression {
+public:
+  FloatingLiteralExpression()
+  : Expression(NodeKind::FloatingLiteralExpression) {}

[PATCH] D82310: Add `BoolLiteralExpression` to SyntaxTree

2020-06-23 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked an inline comment as done.
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1240
+  true;
+  false;
+}

gribozavr2 wrote:
> C99 has bool literals, but the program should include stdbool.h.
> 
> I feel like it is better to make the predicate something like "hasBoolType()" 
> and change the test to include stdbool.h.
[[ https://clang.llvm.org/doxygen/stdbool_8h_source.html | stdbool ]] consists 
on macro definitions, mapping booleans to integers. `true` is preprocessed into 
1 and `false` to 0 .
I don't  think there is a reasonable way of getting the proper SyntaxTree from 
that macro expansion

Additional problem, we don't have the test infrastructure for includes, AFAIK ^^

Finally, regarding the predicates, I prefer if they relate to languages, 
otherwise we might create many predicates that test for exactly the same thing, 
e.g. we would have `hasBoolType()` and `hasNullPtr()` that ultimately do the 
same thing, test if Language is not C 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82310/new/

https://reviews.llvm.org/D82310



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82318: Add `FloatingLiteral` to SyntaxTree

2020-06-23 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a reviewer: gribozavr2.
eduucaldas marked an inline comment as done.
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:72-75
+  bool isCXX17OrLater() const {
+return Language == Lang_CXX17 || Language == Lang_CXX20;
+  }
+

This was already defined in this [[ https://reviews.llvm.org/D82312 | patch ]]. 
But I wanted to make them independent.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82318/new/

https://reviews.llvm.org/D82318



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   >