eduucaldas updated this revision to Diff 291320.
eduucaldas marked an inline comment as done.
eduucaldas added a comment.

Add argument names to function declaration


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87533

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===================================================================
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -12,6 +12,7 @@
 
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
 #include "gtest/gtest.h"
 
 using namespace clang;
@@ -80,6 +81,62 @@
   )txt"));
 }
 
+TEST_P(SynthesisTest, Tree_Empty) {
+  buildTree("", GetParam());
+
+  auto *Tree = createTree(*Arena, {}, NodeKind::UnknownExpression);
+
+  EXPECT_TRUE(treeDumpEqual(Tree, R"txt(
+UnknownExpression Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Tree_Flat) {
+  buildTree("", GetParam());
+
+  auto *LeafLParen = createLeaf(*Arena, tok::l_paren);
+  auto *LeafRParen = createLeaf(*Arena, tok::r_paren);
+  auto *TreeParen = createTree(*Arena,
+                               {{LeafLParen, NodeRole::LeftHandSide},
+                                {LeafRParen, NodeRole::RightHandSide}},
+                               NodeKind::ParenExpression);
+
+  EXPECT_TRUE(treeDumpEqual(TreeParen, R"txt(
+ParenExpression Detached synthesized
+|-'(' LeftHandSide synthesized
+`-')' RightHandSide synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Tree_OfTree) {
+  buildTree("", GetParam());
+
+  auto *Leaf1 = createLeaf(*Arena, tok::numeric_constant, "1");
+  auto *Int1 = createTree(*Arena, {{Leaf1, NodeRole::LiteralToken}},
+                          NodeKind::IntegerLiteralExpression);
+
+  auto *LeafPlus = createLeaf(*Arena, tok::plus);
+
+  auto *Leaf2 = createLeaf(*Arena, tok::numeric_constant, "2");
+  auto *Int2 = createTree(*Arena, {{Leaf2, NodeRole::LiteralToken}},
+                          NodeKind::IntegerLiteralExpression);
+
+  auto *TreeBinaryOperator = createTree(*Arena,
+                                        {{Int1, NodeRole::LeftHandSide},
+                                         {LeafPlus, NodeRole::OperatorToken},
+                                         {Int2, NodeRole::RightHandSide}},
+                                        NodeKind::BinaryOperatorExpression);
+
+  EXPECT_TRUE(treeDumpEqual(TreeBinaryOperator, R"txt(
+BinaryOperatorExpression Detached synthesized
+|-IntegerLiteralExpression LeftHandSide synthesized
+| `-'1' LiteralToken synthesized
+|-'+' OperatorToken synthesized
+`-IntegerLiteralExpression RightHandSide synthesized
+  `-'2' LiteralToken synthesized
+  )txt"));
+}
+
 TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===================================================================
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -52,6 +52,20 @@
   return createLeaf(A, K, Spelling);
 }
 
+syntax::Tree *clang::syntax::createTree(
+    syntax::Arena &A,
+    std::vector<std::pair<syntax::Node *, syntax::NodeRole>> Children,
+    syntax::NodeKind K) {
+  auto *T = new (A.getAllocator()) syntax::Tree(K);
+  FactoryImpl::setCanModify(T);
+  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend();
+       std::advance(ChildIt, 1))
+    FactoryImpl::prependChildLowLevel(T, ChildIt->first, ChildIt->second);
+
+  T->assertInvariants();
+  return T;
+}
+
 syntax::EmptyStatement *clang::syntax::createEmptyStatement(syntax::Arena &A) {
   auto *S = new (A.getAllocator()) syntax::EmptyStatement;
   FactoryImpl::setCanModify(S);
Index: clang/include/clang/Tooling/Syntax/BuildTree.h
===================================================================
--- clang/include/clang/Tooling/Syntax/BuildTree.h
+++ clang/include/clang/Tooling/Syntax/BuildTree.h
@@ -34,6 +34,12 @@
 /// this token
 syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K);
 
+// Synthesis of Trees
+syntax::Tree *
+createTree(Arena &A,
+           std::vector<std::pair<syntax::Node *, syntax::NodeRole>> Children,
+           syntax::NodeKind K);
+
 // Synthesis of Syntax Nodes
 clang::syntax::EmptyStatement *createEmptyStatement(clang::syntax::Arena &A);
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to