mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Refactor NodeKind to take advantage of a parse node only having one token kind. (#3486)
This builds on the series of changes to NodeKinds, aiming to simplify the NodeKind implementation a little, also making it clearer that there's a single associated token for each parse node (or, for placeholders/invalid parses, not validated). Note that prior to the relevant changes, there were nodes with multiple tokens. This change is also locking in the approach of one token per parse node, by refactoring macros to stop supporting multiple.
This commit is contained in:
@@ -69,7 +69,7 @@ Context::Context(Tree& tree, Lex::TokenizedBuffer& tokens,
|
||||
|
||||
auto Context::AddLeafNode(NodeKind kind, Lex::TokenIndex token, bool has_error)
|
||||
-> void {
|
||||
CheckNodeMatchesLexerToken(kind, tokens_->GetKind(token), has_error);
|
||||
kind.CheckMatchesTokenKind(tokens_->GetKind(token), has_error);
|
||||
tree_->node_impls_.push_back(
|
||||
Tree::NodeImpl(kind, has_error, token, /*subtree_size=*/1));
|
||||
if (has_error) {
|
||||
@@ -79,7 +79,7 @@ auto Context::AddLeafNode(NodeKind kind, Lex::TokenIndex token, bool has_error)
|
||||
|
||||
auto Context::AddNode(NodeKind kind, Lex::TokenIndex token, int subtree_start,
|
||||
bool has_error) -> void {
|
||||
CheckNodeMatchesLexerToken(kind, tokens_->GetKind(token), has_error);
|
||||
kind.CheckMatchesTokenKind(tokens_->GetKind(token), has_error);
|
||||
int subtree_size = tree_->size() - subtree_start + 1;
|
||||
tree_->node_impls_.push_back(
|
||||
Tree::NodeImpl(kind, has_error, token, subtree_size));
|
||||
|
||||
Reference in New Issue
Block a user