eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
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/D87600

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


Index: clang/lib/Tooling/Syntax/Tree.cpp
===================================================================
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -232,6 +232,19 @@
     assert(!C->isDetached());
     assert(C->getParent() == T);
   }
+
+  auto *L = dyn_cast<List>(T);
+  if (!L)
+    return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+    assert(C->getRole() == NodeRole::ListElement ||
+           C->getRole() == NodeRole::ListDelimiter);
+    if (C->getRole() == NodeRole::ListDelimiter) {
+      assert(isa<Leaf>(C));
+      assert(cast<Leaf>(C)->getToken()->kind() == L->getDelimiterTokenKind());
+    }
+  }
+
 #endif
 }
 
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
     return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
     return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
     return false;
Index: clang/include/clang/Tooling/Syntax/Tree.h
===================================================================
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -237,16 +237,16 @@
   ///
   /// Useful for discovering the correct delimiter to use when adding
   /// elements to empty or one-element lists.
-  clang::tok::TokenKind getDelimiterTokenKind();
+  clang::tok::TokenKind getDelimiterTokenKind() const;
 
-  TerminationKind getTerminationKind();
+  TerminationKind getTerminationKind() const;
 
   /// Whether this list can be empty in syntactically and semantically correct
   /// code.
   ///
   /// This list may be empty when the source code has errors even if
   /// canBeEmpty() returns false.
-  bool canBeEmpty();
+  bool canBeEmpty() const;
 };
 
 } // namespace syntax


Index: clang/lib/Tooling/Syntax/Tree.cpp
===================================================================
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -232,6 +232,19 @@
     assert(!C->isDetached());
     assert(C->getParent() == T);
   }
+
+  auto *L = dyn_cast<List>(T);
+  if (!L)
+    return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+    assert(C->getRole() == NodeRole::ListElement ||
+           C->getRole() == NodeRole::ListDelimiter);
+    if (C->getRole() == NodeRole::ListDelimiter) {
+      assert(isa<Leaf>(C));
+      assert(cast<Leaf>(C)->getToken()->kind() == L->getDelimiterTokenKind());
+    }
+  }
+
 #endif
 }
 
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
     return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
     return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
     return false;
Index: clang/include/clang/Tooling/Syntax/Tree.h
===================================================================
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -237,16 +237,16 @@
   ///
   /// Useful for discovering the correct delimiter to use when adding
   /// elements to empty or one-element lists.
-  clang::tok::TokenKind getDelimiterTokenKind();
+  clang::tok::TokenKind getDelimiterTokenKind() const;
 
-  TerminationKind getTerminationKind();
+  TerminationKind getTerminationKind() const;
 
   /// Whether this list can be empty in syntactically and semantically correct
   /// code.
   ///
   /// This list may be empty when the source code has errors even if
   /// canBeEmpty() returns false.
-  bool canBeEmpty();
+  bool canBeEmpty() const;
 };
 
 } // namespace syntax
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to