[PATCH] D87600: [SyntaxTree][List] `assertInvariants` for `List`s
Eduardo Caldas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 14 01:23:32 PDT 2020
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87600.291507.patch
Type: text/x-patch
Size: 2299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200914/78e48d54/attachment.bin>
More information about the cfe-commits
mailing list