diff --git a/clang/include/clang/Tooling/Syntax/Tree.h b/clang/include/clang/Tooling/Syntax/Tree.h --- a/clang/include/clang/Tooling/Syntax/Tree.h +++ b/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 diff --git a/clang/lib/Tooling/Syntax/Tree.cpp b/clang/lib/Tooling/Syntax/Tree.cpp --- a/clang/lib/Tooling/Syntax/Tree.cpp +++ b/clang/lib/Tooling/Syntax/Tree.cpp @@ -232,6 +232,19 @@ assert(!C->isDetached()); assert(C->getParent() == T); } + + auto *L = dyn_cast(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(C)); + assert(cast(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;