Introduce verification checks on subtree_size (#2414)

This switches the Verify method to walk postorder so that we can see how much subtree_size is really used, and shift towards removing it. It also starts calling Verify.

Also, I think I'd lost the reserve/size check during Parser refactoring, so I'm putting that back in as part of Verify.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
Jon Ross-Perkins
2022-11-18 16:45:59 -08:00
committed by GitHub
co-authored by Chandler Carruth
parent 97ed697386
commit 5cd05efc62
6 changed files with 230 additions and 129 deletions
+14
View File
@@ -33,6 +33,9 @@ class ParseNodeKind {
};
public:
// TODO: See parse_node_kind.def.
static constexpr int32_t TodoFixParseNode = -2;
// `clang-format` has a bug with spacing around `->` returns in macros. See
// https://bugs.llvm.org/show_bug.cgi?id=48320 for details.
#define CARBON_PARSE_NODE_KIND(Name) \
@@ -64,6 +67,17 @@ class ParseNodeKind {
void Print(llvm::raw_ostream& out) const { out << name(); }
// Returns true if the node is bracketed; otherwise, child_count is used.
auto has_bracket() const -> bool;
// Returns the bracketing node kind for the current node kind. Requires that
// has_bracket is true.
auto bracket() const -> ParseNodeKind;
// Returns the number of children that the node must have, often 0. Requires
// that has_bracket is false.
auto child_count() const -> int32_t;
private:
constexpr explicit ParseNodeKind(KindEnum k) : kind_(k) {}