|
|
@@ -75,8 +75,7 @@ class Context {
|
|
|
};
|
|
|
|
|
|
// Used to track state on state_stack_.
|
|
|
- // TODO: Rename to `State`.
|
|
|
- struct StateStackEntry : public Printable<StateStackEntry> {
|
|
|
+ struct State : public Printable<State> {
|
|
|
// Prints state information for verbose output.
|
|
|
auto Print(llvm::raw_ostream& output) const -> void {
|
|
|
output << kind << " @" << token << " subtree_start=" << subtree_start
|
|
|
@@ -111,7 +110,7 @@ class Context {
|
|
|
int32_t subtree_start;
|
|
|
};
|
|
|
|
|
|
- // We expect StateStackEntry to fit into 12 bytes:
|
|
|
+ // We expect State to fit into 12 bytes:
|
|
|
// state = 1 byte
|
|
|
// has_error and in_var_pattern = 1 byte
|
|
|
// ambient_precedence = 1 byte
|
|
|
@@ -120,8 +119,7 @@ class Context {
|
|
|
// subtree_start = 4 bytes
|
|
|
// If it becomes bigger, it'd be worth examining better packing; it should be
|
|
|
// feasible to pack the 1-byte entries more tightly.
|
|
|
- static_assert(sizeof(StateStackEntry) == 12,
|
|
|
- "StateStackEntry has unexpected size!");
|
|
|
+ static_assert(sizeof(State) == 12, "State has unexpected size!");
|
|
|
|
|
|
explicit Context(Tree* tree, Lex::TokenizedBuffer* tokens,
|
|
|
Diagnostics::Consumer* consumer,
|
|
|
@@ -192,9 +190,8 @@ class Context {
|
|
|
// Creates a parse node of the specified close kind. If `expected_open` is not
|
|
|
// an opening symbol, the parse node will be associated with `state.token`,
|
|
|
// no input will be consumed, and no diagnostic will be emitted.
|
|
|
- auto ConsumeAndAddCloseSymbol(Lex::TokenIndex expected_open,
|
|
|
- StateStackEntry state, NodeKind close_kind)
|
|
|
- -> void;
|
|
|
+ auto ConsumeAndAddCloseSymbol(Lex::TokenIndex expected_open, State state,
|
|
|
+ NodeKind close_kind) -> void;
|
|
|
|
|
|
// Composes `ConsumeIf` and `AddLeafNode`, returning false when ConsumeIf
|
|
|
// fails.
|
|
|
@@ -281,7 +278,7 @@ class Context {
|
|
|
}
|
|
|
|
|
|
// Pops the state and keeps the value for inspection.
|
|
|
- auto PopState() -> StateStackEntry {
|
|
|
+ auto PopState() -> State {
|
|
|
auto back = state_stack_.pop_back_val();
|
|
|
CARBON_VLOG("Pop {0}: {1}\n", state_stack_.size(), back);
|
|
|
return back;
|
|
|
@@ -331,7 +328,7 @@ class Context {
|
|
|
}
|
|
|
|
|
|
// Pushes a constructed state onto the stack.
|
|
|
- auto PushState(StateStackEntry state) -> void {
|
|
|
+ auto PushState(State state) -> void {
|
|
|
CARBON_VLOG("Push {0}: {1}\n", state_stack_.size(), state);
|
|
|
state_stack_.push_back(state);
|
|
|
CARBON_CHECK(state_stack_.size() < (1 << 20),
|
|
|
@@ -339,9 +336,9 @@ class Context {
|
|
|
}
|
|
|
|
|
|
// Pushes a constructed state onto the stack, with a different kind.
|
|
|
- auto PushState(StateStackEntry state_entry, StateKind kind) -> void {
|
|
|
- state_entry.kind = kind;
|
|
|
- PushState(state_entry);
|
|
|
+ auto PushState(State state, StateKind kind) -> void {
|
|
|
+ state.kind = kind;
|
|
|
+ PushState(state);
|
|
|
}
|
|
|
|
|
|
// Propagates an error up the state stack, to the parent state.
|
|
|
@@ -350,7 +347,7 @@ class Context {
|
|
|
// Adds a node for a declaration's semicolon. Includes error recovery when the
|
|
|
// token is not a semicolon, using `decl_kind` and `is_def_allowed` to inform
|
|
|
// diagnostics.
|
|
|
- auto AddNodeExpectingDeclSemi(StateStackEntry state, NodeKind node_kind,
|
|
|
+ auto AddNodeExpectingDeclSemi(State state, NodeKind node_kind,
|
|
|
Lex::TokenKind decl_kind, bool is_def_allowed)
|
|
|
-> void;
|
|
|
|
|
|
@@ -365,7 +362,7 @@ class Context {
|
|
|
// definition has started (although one could be present). Recover to a
|
|
|
// semicolon when it makes sense as a possible end, otherwise use the
|
|
|
// introducer token for the error.
|
|
|
- auto RecoverFromDeclError(StateStackEntry state, NodeKind node_kind,
|
|
|
+ auto RecoverFromDeclError(State state, NodeKind node_kind,
|
|
|
bool skip_past_likely_end) -> void;
|
|
|
|
|
|
// Handles parsing of the library name. Returns the name's ID on success,
|
|
|
@@ -414,11 +411,9 @@ class Context {
|
|
|
auto position() -> Lex::TokenIterator& { return position_; }
|
|
|
auto position() const -> Lex::TokenIterator { return position_; }
|
|
|
|
|
|
- auto state_stack() -> llvm::SmallVector<StateStackEntry>& {
|
|
|
- return state_stack_;
|
|
|
- }
|
|
|
+ auto state_stack() -> llvm::SmallVector<State>& { return state_stack_; }
|
|
|
|
|
|
- auto state_stack() const -> const llvm::SmallVector<StateStackEntry>& {
|
|
|
+ auto state_stack() const -> const llvm::SmallVector<State>& {
|
|
|
return state_stack_;
|
|
|
}
|
|
|
|
|
|
@@ -453,7 +448,7 @@ class Context {
|
|
|
// The FileEnd token.
|
|
|
Lex::TokenIterator end_;
|
|
|
|
|
|
- llvm::SmallVector<StateStackEntry> state_stack_;
|
|
|
+ llvm::SmallVector<State> state_stack_;
|
|
|
|
|
|
// The deferred definition indexes of functions whose definitions have begun
|
|
|
// but not yet finished.
|