///
/// 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
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()) {
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
}
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:
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;
}
}
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
switch (this->getKind()) {
case NodeKind::NestedNameSpecifier:
return TerminationKind::Terminated;
}
}
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
switch (this->getKind()) {
case NodeKind::NestedNameSpecifier:
return false;