mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-30 16:55:00 +01:00
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:
co-authored by
Chandler Carruth
parent
97ed697386
commit
5cd05efc62
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "toolchain/parser/parse_node_kind.h"
|
||||
|
||||
#include "common/check.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
namespace Carbon {
|
||||
@@ -16,4 +17,39 @@ auto ParseNodeKind::name() const -> llvm::StringRef {
|
||||
return Names[static_cast<int>(kind_)];
|
||||
}
|
||||
|
||||
auto ParseNodeKind::has_bracket() const -> bool {
|
||||
static constexpr bool HasBracket[] = {
|
||||
#define CARBON_PARSE_NODE_KIND_BRACKET(...) true,
|
||||
#define CARBON_PARSE_NODE_KIND_CHILD_COUNT(...) false,
|
||||
#include "toolchain/parser/parse_node_kind.def"
|
||||
};
|
||||
return HasBracket[static_cast<int>(kind_)];
|
||||
}
|
||||
|
||||
auto ParseNodeKind::bracket() const -> ParseNodeKind {
|
||||
// Nodes are never self-bracketed, so we use that for nodes that instead set
|
||||
// child_count.
|
||||
static constexpr ParseNodeKind Bracket[] = {
|
||||
#define CARBON_PARSE_NODE_KIND_BRACKET(Name, BracketName) \
|
||||
ParseNodeKind::BracketName(),
|
||||
#define CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ...) ParseNodeKind::Name(),
|
||||
#include "toolchain/parser/parse_node_kind.def"
|
||||
};
|
||||
auto bracket = Bracket[static_cast<int>(kind_)];
|
||||
CARBON_CHECK(bracket != kind_);
|
||||
return bracket;
|
||||
}
|
||||
|
||||
auto ParseNodeKind::child_count() const -> int32_t {
|
||||
static constexpr int32_t ChildCount[] = {
|
||||
#define CARBON_PARSE_NODE_KIND_BRACKET(...) -1,
|
||||
#define CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, Size) Size,
|
||||
#include "toolchain/parser/parse_node_kind.def"
|
||||
};
|
||||
auto child_count = ChildCount[static_cast<int>(kind_)];
|
||||
// TODO: Allows TodoFixParseNode; see parse_node_kind.def.
|
||||
CARBON_CHECK(child_count != -1);
|
||||
return child_count;
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user