diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 2d1fe33c..5d3cd1e6 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -1565,6 +1565,14 @@ auto Parser::parse_nested_name_specifier(NestedNameSpecifierAST*& yyast) auto lookat_decltype_nested_name_specifier = [&] { LookaheadParser lookahead{this}; + SourceLocation decltypeLoc; + if (!match(TokenKind::T_DECLTYPE, decltypeLoc)) return false; + if (!lookat(TokenKind::T_LPAREN)) return false; + if (!parse_skip_balanced()) return false; + if (!lookat(TokenKind::T_COLON_COLON)) return false; + + rewind(decltypeLoc); + DecltypeSpecifierAST* decltypeSpecifier = nullptr; if (!parse_decltype_specifier(decltypeSpecifier)) return false; @@ -1642,15 +1650,6 @@ auto Parser::parse_nested_name_specifier(NestedNameSpecifierAST*& yyast) return true; }; - const auto start = currentLocation(); - - if (auto entry = nested_name_specifiers_.get(start)) { - auto [cursor, ast, parsed, hit] = *entry; - rewind(cursor); - yyast = ast; - return parsed; - } - yyast = nullptr; if (SourceLocation scopeLoc; match(TokenKind::T_COLON_COLON, scopeLoc)) { @@ -1672,8 +1671,6 @@ auto Parser::parse_nested_name_specifier(NestedNameSpecifierAST*& yyast) const auto parsed = yyast != nullptr; - nested_name_specifiers_.set(start, currentLocation(), yyast, parsed); - return parsed; } @@ -3237,13 +3234,6 @@ auto Parser::parse_cast_expression(ExpressionAST*& yyast, const ExprContext& ctx) -> bool { const auto start = currentLocation(); - if (auto it = cast_expressions_.get(start)) { - auto [endLoc, ast, parsed, hit] = *it; - rewind(endLoc); - yyast = ast; - return parsed; - } - auto lookat_cast_expression = [&] { LookaheadParser lookahead{this}; if (!parse_cast_expression_helper(yyast, ctx)) return false; @@ -3251,15 +3241,9 @@ auto Parser::parse_cast_expression(ExpressionAST*& yyast, return true; }; - auto parsed = lookat_cast_expression(); + if (lookat_cast_expression()) return true; - if (!parsed) { - parsed = parse_unary_expression(yyast, ctx); - } - - cast_expressions_.set(start, currentLocation(), yyast, parsed); - - return parsed; + return parse_unary_expression(yyast, ctx); } auto Parser::parse_cast_expression_helper(ExpressionAST*& yyast, @@ -4172,9 +4156,7 @@ auto Parser::parse_do_statement(StatementAST*& yyast) -> bool { return true; } -auto Parser::parse_for_range_statement(StatementAST*& yyast) -> bool { - LookaheadParser lookahead{this}; - +auto Parser::parse_for_statement(StatementAST*& yyast) -> bool { SourceLocation forLoc; if (!match(TokenKind::T_FOR, forLoc)) return false; @@ -4182,63 +4164,56 @@ auto Parser::parse_for_range_statement(StatementAST*& yyast) -> bool { auto parentScope = scope_; auto blockSymbol = control_->newBlockSymbol(scope_, forLoc); + parentScope->addSymbol(blockSymbol); + setScope(blockSymbol); SourceLocation lparenLoc; - if (!match(TokenKind::T_LPAREN, lparenLoc)) return false; + expect(TokenKind::T_LPAREN, lparenLoc); StatementAST* initializer = nullptr; parse_init_statement(initializer); DeclarationAST* rangeDeclaration = nullptr; - if (!parse_for_range_declaration(rangeDeclaration)) return false; - SourceLocation colonLoc; - if (!match(TokenKind::T_COLON, colonLoc)) return false; - - lookahead.commit(); - - parentScope->addSymbol(blockSymbol); - auto ast = make_node(pool_); - yyast = ast; + auto lookat_for_range_declaration = [&] { + LookaheadParser lookahead{this}; - ast->forLoc = forLoc; - ast->rangeDeclaration = rangeDeclaration; - ast->lparenLoc = lparenLoc; - ast->initializer = initializer; - ast->colonLoc = colonLoc; + if (!parse_for_range_declaration(rangeDeclaration)) return false; - parse_for_range_initializer(ast->rangeInitializer); + if (!match(TokenKind::T_COLON, colonLoc)) return false; - expect(TokenKind::T_RPAREN, ast->rparenLoc); + lookahead.commit(); - parse_statement(ast->statement); + return true; + }; - return true; -} + if (lookat_for_range_declaration()) { + auto ast = make_node(pool_); + yyast = ast; -auto Parser::parse_for_statement(StatementAST*& yyast) -> bool { - if (parse_for_range_statement(yyast)) return true; + ast->forLoc = forLoc; + ast->rangeDeclaration = rangeDeclaration; + ast->lparenLoc = lparenLoc; + ast->initializer = initializer; + ast->colonLoc = colonLoc; - SourceLocation forLoc; + parse_for_range_initializer(ast->rangeInitializer); - if (!match(TokenKind::T_FOR, forLoc)) return false; + expect(TokenKind::T_RPAREN, ast->rparenLoc); - ScopeGuard scopeGuard{this}; + parse_statement(ast->statement); - auto blockSymbol = control_->newBlockSymbol(scope_, forLoc); - scope_->addSymbol(blockSymbol); - setScope(blockSymbol); + return true; + } auto ast = make_node(pool_); yyast = ast; ast->forLoc = forLoc; - - expect(TokenKind::T_LPAREN, ast->lparenLoc); - - parse_init_statement(ast->initializer); + ast->lparenLoc = lparenLoc; + ast->initializer = initializer; if (!match(TokenKind::T_SEMICOLON, ast->semicolonLoc)) { parse_condition(ast->condition, ExprContext{}); diff --git a/src/parser/cxx/parser.h b/src/parser/cxx/parser.h index 84d66f47..2ae49c58 100644 --- a/src/parser/cxx/parser.h +++ b/src/parser/cxx/parser.h @@ -342,7 +342,6 @@ class Parser final { [[nodiscard]] auto parse_switch_statement(StatementAST*& yyast) -> bool; [[nodiscard]] auto parse_while_statement(StatementAST*& yyast) -> bool; [[nodiscard]] auto parse_do_statement(StatementAST*& yyast) -> bool; - [[nodiscard]] auto parse_for_range_statement(StatementAST*& yyast) -> bool; [[nodiscard]] auto parse_for_statement(StatementAST*& yyast) -> bool; [[nodiscard]] auto parse_for_range_declaration(DeclarationAST*& yyast) -> bool; @@ -973,8 +972,6 @@ class Parser final { std::deque queue_; }; - CachedAST cast_expressions_; - CachedAST nested_name_specifiers_; CachedAST parameter_declaration_clauses_; CachedAST template_arguments_;