[PATCH] D87600: [SyntaxTree][List] `assertInvariants` for `List`s
Eduardo Caldas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 14 02:53:42 PDT 2020
eduucaldas updated this revision to Diff 291522.
eduucaldas marked 2 inline comments as done.
eduucaldas added a comment.
Fix build error and clang-tidy lint error
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87600/new/
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
@@ -223,7 +223,7 @@
else
assert(getParent() != nullptr);
- auto *T = dyn_cast<Tree>(this);
+ const auto *T = dyn_cast<Tree>(this);
if (!T)
return;
for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
@@ -232,6 +232,19 @@
assert(!C->isDetached());
assert(C->getParent() == T);
}
+
+ const 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
}
@@ -273,7 +286,7 @@
return nullptr;
}
-bool classof(const syntax::Node *N) {
+bool syntax::List::classof(const syntax::Node *N) {
switch (N->getKind()) {
case syntax::NodeKind::NestedNameSpecifier:
case syntax::NodeKind::CallArguments:
@@ -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.291522.patch
Type: text/x-patch
Size: 2797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200914/bf9f54ab/attachment.bin>
More information about the cfe-commits
mailing list