From f764eeb8abf1ec50794ddb1f31bc57d025e29a3c Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Fri, 18 Dec 2020 21:07:04 +0800 Subject: Unified representation of macro invocation internal data - will be better for processing --- gcc/rust/parse/rust-parse-impl.h | 57 ++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 31 deletions(-) (limited to 'gcc/rust/parse/rust-parse-impl.h') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 187f821..671565c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1514,6 +1514,7 @@ Parser::parse_macro_invocation_semi ( t->get_token_description ()); return nullptr; } + Location tok_tree_locus = t->get_locus (); lexer.skip_token (); // parse actual token trees @@ -1538,6 +1539,9 @@ Parser::parse_macro_invocation_semi ( t = lexer.peek_token (); } + + AST::DelimTokenTree delim_tok_tree (delim_type, std::move (token_trees), tok_tree_locus); + AST::MacroInvocData invoc_data (std::move (path), std::move (delim_tok_tree)); // parse end delimiters t = lexer.peek_token (); @@ -1553,8 +1557,7 @@ Parser::parse_macro_invocation_semi ( { // as this is the end, allow recovery (probably) - may change return std::unique_ptr ( - new AST::MacroInvocationSemi (std::move (path), delim_type, - std::move (token_trees), + new AST::MacroInvocationSemi (std::move (invoc_data), std::move (outer_attrs), macro_locus)); } @@ -1567,8 +1570,7 @@ Parser::parse_macro_invocation_semi ( lexer.peek_token ()->get_token_description ()); return std::unique_ptr ( - new AST::MacroInvocationSemi (std::move (path), delim_type, - std::move (token_trees), + new AST::MacroInvocationSemi (std::move (invoc_data), std::move (outer_attrs), macro_locus)); } else @@ -1616,8 +1618,8 @@ Parser::parse_macro_invocation ( Location macro_locus = macro_path.get_locus (); return std::unique_ptr ( - new AST::MacroInvocation (std::move (macro_path), - std::move (delim_tok_tree), + new AST::MacroInvocation (AST::MacroInvocData (std::move (macro_path), + std::move (delim_tok_tree)), std::move (outer_attrs), macro_locus)); } @@ -8826,10 +8828,8 @@ Parser::parse_type () AST::DelimTokenTree tok_tree = parse_delim_token_tree (); return std::unique_ptr ( - new AST::MacroInvocation (std::move (macro_path), - std::move (tok_tree), - std::vector (), - locus)); + new AST::MacroInvocation (AST::MacroInvocData (std::move (macro_path), + std::move (tok_tree)), {}, locus)); } case PLUS: { // type param bounds @@ -9629,10 +9629,8 @@ Parser::parse_type_no_bounds () AST::DelimTokenTree tok_tree = parse_delim_token_tree (); return std::unique_ptr ( - new AST::MacroInvocation (std::move (macro_path), - std::move (tok_tree), - std::vector (), - locus)); + new AST::MacroInvocation (AST::MacroInvocData (std::move (macro_path), + std::move (tok_tree)), {}, locus)); } case PLUS: { // type param bounds - not allowed, here for error message @@ -11397,25 +11395,24 @@ Parser::parse_path_based_stmt_or_expr ( * fixed up via HACKs in semantic analysis (by checking whether it * is the last elem in the vector). */ + AST::DelimTokenTree delim_tok_tree (type, std::move (token_trees), + tok_tree_loc); + AST::MacroInvocData invoc_data (std::move (macro_path), std::move (delim_tok_tree)); + if (lexer.peek_token ()->get_id () == SEMICOLON) { lexer.skip_token (); std::unique_ptr stmt ( - new AST::MacroInvocationSemi (std::move (macro_path), type, - std::move (token_trees), + new AST::MacroInvocationSemi (std::move (invoc_data), std::move (outer_attrs), stmt_or_expr_loc)); return ExprOrStmt (std::move (stmt)); } // otherwise, create macro invocation - AST::DelimTokenTree delim_tok_tree (type, std::move (token_trees), - tok_tree_loc); - std::unique_ptr expr ( - new AST::MacroInvocation (std::move (macro_path), - std::move (delim_tok_tree), + new AST::MacroInvocation (std::move (invoc_data), std::move (outer_attrs), stmt_or_expr_loc)); return ExprOrStmt (std::move (expr)); @@ -11424,8 +11421,7 @@ Parser::parse_path_based_stmt_or_expr ( { // tokens don't match opening delimiters, so produce error rust_error_at (t2->get_locus (), - "unexpected token %qs - expecting closing " - "delimiter %qs (for a " + "unexpected token %qs - expecting closing delimiter %qs (for a " "macro invocation)", t2->get_token_description (), (type == AST::PARENS @@ -11697,25 +11693,24 @@ Parser::parse_macro_invocation_maybe_semi ( * HACKs in semantic analysis (by checking whether it is the last elem in * the vector). */ + AST::DelimTokenTree delim_tok_tree (type, std::move (token_trees), + tok_tree_loc); + AST::MacroInvocData invoc_data (std::move (macro_path), std::move (delim_tok_tree)); + if (lexer.peek_token ()->get_id () == SEMICOLON) { lexer.skip_token (); std::unique_ptr stmt ( - new AST::MacroInvocationSemi (std::move (macro_path), type, - std::move (token_trees), + new AST::MacroInvocationSemi (std::move (invoc_data), std::move (outer_attrs), macro_locus)); return ExprOrStmt (std::move (stmt)); } // otherwise, create macro invocation - AST::DelimTokenTree delim_tok_tree (type, std::move (token_trees), - tok_tree_loc); - std::unique_ptr expr ( - new AST::MacroInvocation (std::move (macro_path), - std::move (delim_tok_tree), + new AST::MacroInvocation (std::move (invoc_data), std::move (outer_attrs), macro_locus)); return ExprOrStmt (std::move (expr)); } @@ -13926,7 +13921,7 @@ Parser::parse_macro_invocation_partial ( Location macro_locus = converted_path.get_locus (); return std::unique_ptr ( - new AST::MacroInvocation (std::move (converted_path), std::move (tok_tree), + new AST::MacroInvocation (AST::MacroInvocData (std::move (converted_path), std::move (tok_tree)), std::move (outer_attrs), macro_locus)); } -- cgit v1.1 From 3a0c8ca2156038b726e2689e9b46be4d8c40c55f Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Tue, 2 Feb 2021 13:19:26 +0800 Subject: Cleanup of AST - moved outer_attrs to child classes Fixed compile errors Fixed more compile errors --- gcc/rust/parse/rust-parse-impl.h | 79 +++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 41 deletions(-) (limited to 'gcc/rust/parse/rust-parse-impl.h') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 87e02dd..a0d2af9 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -791,7 +791,7 @@ Parser::parse_attr_input () } // create actual LiteralExpr - AST::LiteralExpr lit_expr (t->get_str (), lit_type, t->get_type_hint (), + AST::LiteralExpr lit_expr (t->get_str (), lit_type, t->get_type_hint (), {}, t->get_locus ()); std::unique_ptr attr_input_lit ( @@ -6361,9 +6361,8 @@ Parser::parse_path_in_expression () segments.shrink_to_fit (); - return AST::PathInExpression (std::move (segments), locus, - has_opening_scope_resolution, - std::vector ()); + return AST::PathInExpression (std::move (segments), {}, locus, + has_opening_scope_resolution); } /* Parses a single path in expression path segment (including generic @@ -6476,8 +6475,7 @@ Parser::parse_qualified_path_in_expression ( // FIXME: outer attr parsing return AST::QualifiedPathInExpression (std::move (qual_path_type), - std::move (segments), locus, - std::vector ()); + std::move (segments), {}, locus); } // Parses the type syntactical construction at the start of a qualified path. @@ -7377,8 +7375,7 @@ Parser::parse_literal_expr ( // create literal based on stuff in switch return std::unique_ptr ( new AST::LiteralExpr (std::move (literal_value), std::move (type), - t->get_type_hint (), t->get_locus (), - std::move (outer_attrs))); + t->get_type_hint (), std::move (outer_attrs), t->get_locus ())); } // Parses a return expression (including any expression to return). @@ -7406,8 +7403,8 @@ Parser::parse_return_expr ( // FIXME: ensure this doesn't ruin the middle of any expressions or anything return std::unique_ptr ( - new AST::ReturnExpr (locus, std::move (returned_expr), - std::move (outer_attrs))); + new AST::ReturnExpr (std::move (returned_expr), + std::move (outer_attrs), locus)); } /* Parses a break expression (including any label to break to AND any return @@ -7442,8 +7439,8 @@ Parser::parse_break_expr ( std::unique_ptr return_expr = parse_expr (); return std::unique_ptr ( - new AST::BreakExpr (locus, std::move (label), std::move (return_expr), - std::move (outer_attrs))); + new AST::BreakExpr (std::move (label), std::move (return_expr), + std::move (outer_attrs), locus)); } // Parses a continue expression (including any label to continue from). @@ -7474,7 +7471,7 @@ Parser::parse_continue_expr ( } return std::unique_ptr ( - new AST::ContinueExpr (locus, std::move (label), std::move (outer_attrs))); + new AST::ContinueExpr (std::move (label), std::move (outer_attrs), locus)); } // Parses a loop label used in loop expressions. @@ -11488,7 +11485,7 @@ Parser::parse_path_based_stmt_or_expr ( // lexer.skip_token(); // HACK: add outer attrs to path - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); expr = std::unique_ptr ( new AST::PathInExpression (std::move (path))); } @@ -11539,7 +11536,7 @@ Parser::parse_path_based_stmt_or_expr ( // lexer.skip_token(); // HACK: replace outer attributes in path - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); std::unique_ptr expr ( new AST::PathInExpression (std::move (path))); @@ -12047,11 +12044,11 @@ Parser::null_denotation ( /* HACK: may have to become permanent, but this is my * current identifier expression */ return std::unique_ptr ( - new AST::IdentifierExpr (tok->get_str (), + new AST::IdentifierExpr (tok->get_str (), {}, tok->get_locus ())); } // HACK: add outer attrs to path - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); return std::unique_ptr ( new AST::PathInExpression (std::move (path))); } @@ -12069,11 +12066,11 @@ Parser::null_denotation ( /* HACK: may have to become permanent, but this is my * current identifier expression */ return std::unique_ptr ( - new AST::IdentifierExpr (tok->get_str (), + new AST::IdentifierExpr (tok->get_str (), {}, tok->get_locus ())); } // HACK: add outer attrs to path - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); return std::unique_ptr ( new AST::PathInExpression (std::move (path))); } @@ -12087,10 +12084,10 @@ Parser::null_denotation ( /* HACK: may have to become permanent, but this is my current * identifier expression */ return std::unique_ptr ( - new AST::IdentifierExpr (tok->get_str (), tok->get_locus ())); + new AST::IdentifierExpr (tok->get_str (), {}, tok->get_locus ())); } // HACK: add outer attrs to path - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); return std::unique_ptr ( new AST::PathInExpression (std::move (path))); } @@ -12105,33 +12102,34 @@ Parser::null_denotation ( // HACK: add outer attrs to path AST::QualifiedPathInExpression path = parse_qualified_path_in_expression (true); - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); return std::unique_ptr ( new AST::QualifiedPathInExpression (std::move (path))); } + // FIXME: for literal exprs, should outer attrs be passed in or just ignored? case INT_LITERAL: // we should check the range, but ignore for now // encode as int? return std::unique_ptr ( new AST::LiteralExpr (tok->get_str (), AST::Literal::INT, - tok->get_type_hint (), tok->get_locus ())); + tok->get_type_hint (), {}, tok->get_locus ())); case FLOAT_LITERAL: // encode as float? return std::unique_ptr ( new AST::LiteralExpr (tok->get_str (), AST::Literal::FLOAT, - tok->get_type_hint (), tok->get_locus ())); + tok->get_type_hint (), {}, tok->get_locus ())); case STRING_LITERAL: return std::unique_ptr ( new AST::LiteralExpr (tok->get_str (), AST::Literal::STRING, - tok->get_type_hint (), tok->get_locus ())); + tok->get_type_hint (), {}, tok->get_locus ())); case TRUE_LITERAL: return std::unique_ptr ( new AST::LiteralExpr ("true", AST::Literal::BOOL, tok->get_type_hint (), - tok->get_locus ())); + {}, tok->get_locus ())); case FALSE_LITERAL: return std::unique_ptr ( new AST::LiteralExpr ("false", AST::Literal::BOOL, - tok->get_type_hint (), tok->get_locus ())); + tok->get_type_hint (), {}, tok->get_locus ())); case LEFT_PAREN: { // have to parse whole expression if inside brackets /* recursively invoke parse_expression with lowest priority possible as * it it were a top-level expression. */ @@ -12170,7 +12168,7 @@ Parser::null_denotation ( ParseRestrictions entered_from_unary; entered_from_unary.entered_from_unary = true; std::unique_ptr expr - = parse_expr (LBP_UNARY_MINUS, std::vector (), + = parse_expr (LBP_UNARY_MINUS, {}, entered_from_unary); if (expr == nullptr) @@ -12195,7 +12193,7 @@ Parser::null_denotation ( ParseRestrictions entered_from_unary; entered_from_unary.entered_from_unary = true; std::unique_ptr expr - = parse_expr (LBP_UNARY_EXCLAM, std::vector (), + = parse_expr (LBP_UNARY_EXCLAM, {}, entered_from_unary); if (expr == nullptr) @@ -12222,7 +12220,7 @@ Parser::null_denotation ( entered_from_unary.entered_from_unary = true; entered_from_unary.can_be_struct_expr = false; std::unique_ptr expr - = parse_expr (LBP_UNARY_ASTERISK, std::vector (), + = parse_expr (LBP_UNARY_ASTERISK, {}, entered_from_unary); // FIXME: allow outer attributes on expression return std::unique_ptr ( @@ -12245,13 +12243,13 @@ Parser::null_denotation ( { lexer.skip_token (); expr - = parse_expr (LBP_UNARY_AMP_MUT, std::vector (), + = parse_expr (LBP_UNARY_AMP_MUT, {}, entered_from_unary); is_mut_borrow = true; } else { - expr = parse_expr (LBP_UNARY_AMP, std::vector (), + expr = parse_expr (LBP_UNARY_AMP, {}, entered_from_unary); } @@ -12272,13 +12270,13 @@ Parser::null_denotation ( { lexer.skip_token (); expr - = parse_expr (LBP_UNARY_AMP_MUT, std::vector (), + = parse_expr (LBP_UNARY_AMP_MUT, {}, entered_from_unary); is_mut_borrow = true; } else { - expr = parse_expr (LBP_UNARY_AMP, std::vector (), + expr = parse_expr (LBP_UNARY_AMP, {}, entered_from_unary); } @@ -12317,7 +12315,7 @@ Parser::null_denotation ( if (tok->get_id () == SELF && path.is_single_segment ()) { // HACK: add outer attrs to path - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); return std::unique_ptr ( new AST::PathInExpression (std::move (path))); } @@ -12347,7 +12345,7 @@ Parser::null_denotation ( { // assume path is returned // HACK: add outer attributes to path - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); return std::unique_ptr ( new AST::PathInExpression (std::move (path))); } @@ -12360,7 +12358,7 @@ Parser::null_denotation ( { // assume path is returned // HACK: add outer attributes to path - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); return std::unique_ptr ( new AST::PathInExpression (std::move (path))); } @@ -12369,7 +12367,7 @@ Parser::null_denotation ( default: // assume path is returned // HACK: add outer attributes to path - path.replace_outer_attrs (std::move (outer_attrs)); + path.set_outer_attrs (std::move (outer_attrs)); return std::unique_ptr ( new AST::PathInExpression (std::move (path))); } @@ -14115,9 +14113,8 @@ Parser::parse_struct_expr_tuple_partial ( exprs.push_back (std::move (expr)); if (lexer.peek_token ()->get_id () != COMMA) - { break; - } + lexer.skip_token (); t = lexer.peek_token (); @@ -14243,7 +14240,7 @@ Parser::parse_path_in_expression_pratt (const_TokenPtr tok) "current token (just about to return path to null denotation): '%s'\n", lexer.peek_token ()->get_token_description ()); - return AST::PathInExpression (std::move (segments), tok->get_locus (), false); + return AST::PathInExpression (std::move (segments), {}, tok->get_locus (), false); } // Parses a closure expression with pratt parsing (from null denotation). -- cgit v1.1 From 877e7ac6c72608950fbe2ffde04142bbfb01b29d Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Wed, 3 Feb 2021 18:23:00 +0800 Subject: Readded outer attributes to if and if let exprs --- gcc/rust/parse/rust-parse-impl.h | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'gcc/rust/parse/rust-parse-impl.h') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index ffe4e91..3bea914 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7503,10 +7503,8 @@ Parser::parse_loop_label () template std::unique_ptr Parser::parse_if_expr ( - std::vector outer_attrs ATTRIBUTE_UNUSED) + std::vector outer_attrs) { - // TODO: make having outer attributes an error? - Location locus = lexer.peek_token ()->get_locus (); skip_token (IF); @@ -7525,7 +7523,7 @@ Parser::parse_if_expr ( ParseRestrictions no_struct_expr; no_struct_expr.can_be_struct_expr = false; std::unique_ptr condition - = parse_expr (std::vector (), no_struct_expr); + = parse_expr ({}, no_struct_expr); if (condition == nullptr) { rust_error_at (lexer.peek_token ()->get_locus (), @@ -7550,7 +7548,7 @@ Parser::parse_if_expr ( { // single selection - end of if expression return std::unique_ptr ( - new AST::IfExpr (std::move (condition), std::move (if_body), locus)); + new AST::IfExpr (std::move (condition), std::move (if_body), std::move (outer_attrs), locus)); } else { @@ -7579,7 +7577,7 @@ Parser::parse_if_expr ( return std::unique_ptr ( new AST::IfExprConseqElse (std::move (condition), std::move (if_body), - std::move (else_body), locus)); + std::move (else_body), std::move (outer_attrs), locus)); } case IF: { // multiple selection - else if or else if let @@ -7601,7 +7599,7 @@ Parser::parse_if_expr ( return std::unique_ptr ( new AST::IfExprConseqIfLet (std::move (condition), std::move (if_body), - std::move (if_let_expr), locus)); + std::move (if_let_expr), std::move (outer_attrs), locus)); } else { @@ -7619,7 +7617,7 @@ Parser::parse_if_expr ( return std::unique_ptr ( new AST::IfExprConseqIf (std::move (condition), std::move (if_body), - std::move (if_expr), locus)); + std::move (if_expr), std::move (outer_attrs), locus)); } } default: @@ -7639,10 +7637,8 @@ Parser::parse_if_expr ( template std::unique_ptr Parser::parse_if_let_expr ( - std::vector outer_attrs ATTRIBUTE_UNUSED) + std::vector outer_attrs) { - // TODO: make having outer attributes an error? - Location locus = lexer.peek_token ()->get_locus (); skip_token (IF); @@ -7679,7 +7675,7 @@ Parser::parse_if_let_expr ( ParseRestrictions no_struct_expr; no_struct_expr.can_be_struct_expr = false; std::unique_ptr scrutinee_expr - = parse_expr (std::vector (), no_struct_expr); + = parse_expr ({}, no_struct_expr); if (scrutinee_expr == nullptr) { rust_error_at ( @@ -7709,7 +7705,7 @@ Parser::parse_if_let_expr ( return std::unique_ptr ( new AST::IfLetExpr (std::move (match_arm_patterns), std::move (scrutinee_expr), std::move (if_let_body), - locus)); + std::move (outer_attrs), locus)); } else { @@ -7739,7 +7735,7 @@ Parser::parse_if_let_expr ( new AST::IfLetExprConseqElse (std::move (match_arm_patterns), std::move (scrutinee_expr), std::move (if_let_body), - std::move (else_body), locus)); + std::move (else_body), std::move (outer_attrs), locus)); } case IF: { // multiple selection - else if or else if let @@ -7761,7 +7757,7 @@ Parser::parse_if_let_expr ( return std::unique_ptr ( new AST::IfLetExprConseqIfLet ( std::move (match_arm_patterns), std::move (scrutinee_expr), - std::move (if_let_body), std::move (if_let_expr), locus)); + std::move (if_let_body), std::move (if_let_expr), std::move (outer_attrs), locus)); } else { @@ -7780,7 +7776,7 @@ Parser::parse_if_let_expr ( new AST::IfLetExprConseqIf (std::move (match_arm_patterns), std::move (scrutinee_expr), std::move (if_let_body), - std::move (if_expr), locus)); + std::move (if_expr), std::move (outer_attrs), locus)); } } default: -- cgit v1.1 From 8f97711dce5c48e46a9a64c5517fa6ae10db5e04 Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Sun, 7 Feb 2021 15:03:07 +0800 Subject: General cleanup of AST and macro expansion-related things --- gcc/rust/parse/rust-parse-impl.h | 121 +++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 57 deletions(-) (limited to 'gcc/rust/parse/rust-parse-impl.h') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 3bea914..cc30f1b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -789,8 +789,8 @@ Parser::parse_attr_input () } // create actual LiteralExpr - AST::LiteralExpr lit_expr (t->get_str (), lit_type, t->get_type_hint (), {}, - t->get_locus ()); + AST::LiteralExpr lit_expr (t->get_str (), lit_type, t->get_type_hint (), + {}, t->get_locus ()); std::unique_ptr attr_input_lit ( new AST::AttrInputLiteral (std::move (lit_expr))); @@ -1554,8 +1554,9 @@ Parser::parse_macro_invocation_semi ( t = lexer.peek_token (); } - - AST::DelimTokenTree delim_tok_tree (delim_type, std::move (token_trees), tok_tree_locus); + + AST::DelimTokenTree delim_tok_tree (delim_type, std::move (token_trees), + tok_tree_locus); AST::MacroInvocData invoc_data (std::move (path), std::move (delim_tok_tree)); // parse end delimiters @@ -1572,7 +1573,7 @@ Parser::parse_macro_invocation_semi ( { // as this is the end, allow recovery (probably) - may change return std::unique_ptr ( - new AST::MacroInvocationSemi (std::move (invoc_data), + new AST::MacroInvocationSemi (std::move (invoc_data), std::move (outer_attrs), macro_locus)); } @@ -1585,7 +1586,7 @@ Parser::parse_macro_invocation_semi ( lexer.peek_token ()->get_token_description ()); return std::unique_ptr ( - new AST::MacroInvocationSemi (std::move (invoc_data), + new AST::MacroInvocationSemi (std::move (invoc_data), std::move (outer_attrs), macro_locus)); } else @@ -1634,7 +1635,7 @@ Parser::parse_macro_invocation ( return std::unique_ptr ( new AST::MacroInvocation (AST::MacroInvocData (std::move (macro_path), - std::move (delim_tok_tree)), + std::move (delim_tok_tree)), std::move (outer_attrs), macro_locus)); } @@ -7373,7 +7374,8 @@ Parser::parse_literal_expr ( // create literal based on stuff in switch return std::unique_ptr ( new AST::LiteralExpr (std::move (literal_value), std::move (type), - t->get_type_hint (), std::move (outer_attrs), t->get_locus ())); + t->get_type_hint (), std::move (outer_attrs), + t->get_locus ())); } // Parses a return expression (including any expression to return). @@ -7401,8 +7403,8 @@ Parser::parse_return_expr ( // FIXME: ensure this doesn't ruin the middle of any expressions or anything return std::unique_ptr ( - new AST::ReturnExpr (std::move (returned_expr), - std::move (outer_attrs), locus)); + new AST::ReturnExpr (std::move (returned_expr), std::move (outer_attrs), + locus)); } /* Parses a break expression (including any label to break to AND any return @@ -7522,8 +7524,7 @@ Parser::parse_if_expr ( * parsed */ ParseRestrictions no_struct_expr; no_struct_expr.can_be_struct_expr = false; - std::unique_ptr condition - = parse_expr ({}, no_struct_expr); + std::unique_ptr condition = parse_expr ({}, no_struct_expr); if (condition == nullptr) { rust_error_at (lexer.peek_token ()->get_locus (), @@ -7548,7 +7549,8 @@ Parser::parse_if_expr ( { // single selection - end of if expression return std::unique_ptr ( - new AST::IfExpr (std::move (condition), std::move (if_body), std::move (outer_attrs), locus)); + new AST::IfExpr (std::move (condition), std::move (if_body), + std::move (outer_attrs), locus)); } else { @@ -7577,7 +7579,8 @@ Parser::parse_if_expr ( return std::unique_ptr ( new AST::IfExprConseqElse (std::move (condition), std::move (if_body), - std::move (else_body), std::move (outer_attrs), locus)); + std::move (else_body), + std::move (outer_attrs), locus)); } case IF: { // multiple selection - else if or else if let @@ -7599,7 +7602,8 @@ Parser::parse_if_expr ( return std::unique_ptr ( new AST::IfExprConseqIfLet (std::move (condition), std::move (if_body), - std::move (if_let_expr), std::move (outer_attrs), locus)); + std::move (if_let_expr), + std::move (outer_attrs), locus)); } else { @@ -7617,7 +7621,8 @@ Parser::parse_if_expr ( return std::unique_ptr ( new AST::IfExprConseqIf (std::move (condition), std::move (if_body), - std::move (if_expr), std::move (outer_attrs), locus)); + std::move (if_expr), + std::move (outer_attrs), locus)); } } default: @@ -7674,8 +7679,7 @@ Parser::parse_if_let_expr ( // parse expression (required) - HACK to prevent struct expr being parsed ParseRestrictions no_struct_expr; no_struct_expr.can_be_struct_expr = false; - std::unique_ptr scrutinee_expr - = parse_expr ({}, no_struct_expr); + std::unique_ptr scrutinee_expr = parse_expr ({}, no_struct_expr); if (scrutinee_expr == nullptr) { rust_error_at ( @@ -7735,7 +7739,8 @@ Parser::parse_if_let_expr ( new AST::IfLetExprConseqElse (std::move (match_arm_patterns), std::move (scrutinee_expr), std::move (if_let_body), - std::move (else_body), std::move (outer_attrs), locus)); + std::move (else_body), + std::move (outer_attrs), locus)); } case IF: { // multiple selection - else if or else if let @@ -7757,7 +7762,8 @@ Parser::parse_if_let_expr ( return std::unique_ptr ( new AST::IfLetExprConseqIfLet ( std::move (match_arm_patterns), std::move (scrutinee_expr), - std::move (if_let_body), std::move (if_let_expr), std::move (outer_attrs), locus)); + std::move (if_let_body), std::move (if_let_expr), + std::move (outer_attrs), locus)); } else { @@ -7776,7 +7782,8 @@ Parser::parse_if_let_expr ( new AST::IfLetExprConseqIf (std::move (match_arm_patterns), std::move (scrutinee_expr), std::move (if_let_body), - std::move (if_expr), std::move (outer_attrs), locus)); + std::move (if_expr), + std::move (outer_attrs), locus)); } } default: @@ -8837,8 +8844,10 @@ Parser::parse_type () AST::DelimTokenTree tok_tree = parse_delim_token_tree (); return std::unique_ptr ( - new AST::MacroInvocation (AST::MacroInvocData (std::move (macro_path), - std::move (tok_tree)), {}, locus)); + new AST::MacroInvocation ( + AST::MacroInvocData (std::move (macro_path), + std::move (tok_tree)), + {}, locus)); } case PLUS: { // type param bounds @@ -9638,8 +9647,10 @@ Parser::parse_type_no_bounds () AST::DelimTokenTree tok_tree = parse_delim_token_tree (); return std::unique_ptr ( - new AST::MacroInvocation (AST::MacroInvocData (std::move (macro_path), - std::move (tok_tree)), {}, locus)); + new AST::MacroInvocation ( + AST::MacroInvocData (std::move (macro_path), + std::move (tok_tree)), + {}, locus)); } case PLUS: { // type param bounds - not allowed, here for error message @@ -11411,9 +11422,10 @@ Parser::parse_path_based_stmt_or_expr ( * fixed up via HACKs in semantic analysis (by checking whether it * is the last elem in the vector). */ - AST::DelimTokenTree delim_tok_tree (type, std::move (token_trees), + AST::DelimTokenTree delim_tok_tree (type, std::move (token_trees), tok_tree_loc); - AST::MacroInvocData invoc_data (std::move (macro_path), std::move (delim_tok_tree)); + AST::MacroInvocData invoc_data (std::move (macro_path), + std::move (delim_tok_tree)); if (lexer.peek_token ()->get_id () == SEMICOLON) { @@ -11436,13 +11448,12 @@ Parser::parse_path_based_stmt_or_expr ( else { // tokens don't match opening delimiters, so produce error - rust_error_at (t2->get_locus (), - "unexpected token %qs - expecting closing delimiter %qs (for a " - "macro invocation)", - t2->get_token_description (), - (type == AST::PARENS - ? ")" - : (type == AST::SQUARE ? "]" : "}"))); + rust_error_at ( + t2->get_locus (), + "unexpected token %qs - expecting closing delimiter %qs (for a " + "macro invocation)", + t2->get_token_description (), + (type == AST::PARENS ? ")" : (type == AST::SQUARE ? "]" : "}"))); return ExprOrStmt::create_error (); } } @@ -11711,14 +11722,15 @@ Parser::parse_macro_invocation_maybe_semi ( AST::DelimTokenTree delim_tok_tree (type, std::move (token_trees), tok_tree_loc); - AST::MacroInvocData invoc_data (std::move (macro_path), std::move (delim_tok_tree)); + AST::MacroInvocData invoc_data (std::move (macro_path), + std::move (delim_tok_tree)); if (lexer.peek_token ()->get_id () == SEMICOLON) { lexer.skip_token (); std::unique_ptr stmt ( - new AST::MacroInvocationSemi (std::move (invoc_data), + new AST::MacroInvocationSemi (std::move (invoc_data), std::move (outer_attrs), macro_locus)); return ExprOrStmt (std::move (stmt)); @@ -12078,7 +12090,8 @@ Parser::null_denotation ( /* HACK: may have to become permanent, but this is my current * identifier expression */ return std::unique_ptr ( - new AST::IdentifierExpr (tok->get_str (), {}, tok->get_locus ())); + new AST::IdentifierExpr (tok->get_str (), {}, + tok->get_locus ())); } // HACK: add outer attrs to path path.set_outer_attrs (std::move (outer_attrs)); @@ -12100,7 +12113,8 @@ Parser::null_denotation ( return std::unique_ptr ( new AST::QualifiedPathInExpression (std::move (path))); } - // FIXME: for literal exprs, should outer attrs be passed in or just ignored? + // FIXME: for literal exprs, should outer attrs be passed in or just + // ignored? case INT_LITERAL: // we should check the range, but ignore for now // encode as int? @@ -12162,8 +12176,7 @@ Parser::null_denotation ( ParseRestrictions entered_from_unary; entered_from_unary.entered_from_unary = true; std::unique_ptr expr - = parse_expr (LBP_UNARY_MINUS, {}, - entered_from_unary); + = parse_expr (LBP_UNARY_MINUS, {}, entered_from_unary); if (expr == nullptr) return nullptr; @@ -12187,8 +12200,7 @@ Parser::null_denotation ( ParseRestrictions entered_from_unary; entered_from_unary.entered_from_unary = true; std::unique_ptr expr - = parse_expr (LBP_UNARY_EXCLAM, {}, - entered_from_unary); + = parse_expr (LBP_UNARY_EXCLAM, {}, entered_from_unary); if (expr == nullptr) return nullptr; @@ -12214,8 +12226,7 @@ Parser::null_denotation ( entered_from_unary.entered_from_unary = true; entered_from_unary.can_be_struct_expr = false; std::unique_ptr expr - = parse_expr (LBP_UNARY_ASTERISK, {}, - entered_from_unary); + = parse_expr (LBP_UNARY_ASTERISK, {}, entered_from_unary); // FIXME: allow outer attributes on expression return std::unique_ptr ( new AST::DereferenceExpr (std::move (expr), std::move (outer_attrs), @@ -12235,15 +12246,12 @@ Parser::null_denotation ( if (lexer.peek_token ()->get_id () == MUT) { lexer.skip_token (); - expr - = parse_expr (LBP_UNARY_AMP_MUT, {}, - entered_from_unary); + expr = parse_expr (LBP_UNARY_AMP_MUT, {}, entered_from_unary); is_mut_borrow = true; } else { - expr = parse_expr (LBP_UNARY_AMP, {}, - entered_from_unary); + expr = parse_expr (LBP_UNARY_AMP, {}, entered_from_unary); } // FIXME: allow outer attributes on expression @@ -12262,15 +12270,12 @@ Parser::null_denotation ( if (lexer.peek_token ()->get_id () == MUT) { lexer.skip_token (); - expr - = parse_expr (LBP_UNARY_AMP_MUT, {}, - entered_from_unary); + expr = parse_expr (LBP_UNARY_AMP_MUT, {}, entered_from_unary); is_mut_borrow = true; } else { - expr = parse_expr (LBP_UNARY_AMP, {}, - entered_from_unary); + expr = parse_expr (LBP_UNARY_AMP, {}, entered_from_unary); } // FIXME: allow outer attributes on expression @@ -13939,7 +13944,8 @@ Parser::parse_macro_invocation_partial ( Location macro_locus = converted_path.get_locus (); return std::unique_ptr ( - new AST::MacroInvocation (AST::MacroInvocData (std::move (converted_path), std::move (tok_tree)), + new AST::MacroInvocation (AST::MacroInvocData (std::move (converted_path), + std::move (tok_tree)), std::move (outer_attrs), macro_locus)); } @@ -14106,7 +14112,7 @@ Parser::parse_struct_expr_tuple_partial ( exprs.push_back (std::move (expr)); if (lexer.peek_token ()->get_id () != COMMA) - break; + break; lexer.skip_token (); @@ -14233,7 +14239,8 @@ Parser::parse_path_in_expression_pratt (const_TokenPtr tok) "current token (just about to return path to null denotation): '%s'\n", lexer.peek_token ()->get_token_description ()); - return AST::PathInExpression (std::move (segments), {}, tok->get_locus (), false); + return AST::PathInExpression (std::move (segments), {}, tok->get_locus (), + false); } // Parses a closure expression with pratt parsing (from null denotation). -- cgit v1.1 From cfd1d805ff5921480d9badd7d215e1b1deb33aca Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Tue, 9 Feb 2021 16:40:23 +0800 Subject: Unified Tokens partially in preparation for macro expansion --- gcc/rust/parse/rust-parse-impl.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'gcc/rust/parse/rust-parse-impl.h') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index cc30f1b..4a9f3a3 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -972,8 +972,7 @@ Parser::parse_token_tree () default: // parse token itself as TokenTree lexer.skip_token (); - // TODO: fix that token constructor, possibly with c++11 features - return std::unique_ptr (new AST::Token (t)); + return std::unique_ptr (new AST::Token (std::move (t))); } } @@ -1805,7 +1804,7 @@ Parser::parse_macro_match () default: // just the token lexer.skip_token (); - return std::unique_ptr (new AST::Token (t)); + return std::unique_ptr (new AST::Token (std::move (t))); } } @@ -1913,7 +1912,7 @@ Parser::parse_macro_match_repetition () break; default: // separator does exist - separator = std::unique_ptr (new AST::Token (t)); + separator = std::unique_ptr (new AST::Token (std::move (t))); lexer.skip_token (); break; } @@ -2665,9 +2664,9 @@ Parser::parse_generic_params () } std::unique_ptr param ( - new AST::LifetimeParam (std::move (lifetime), locus, + new AST::LifetimeParam (std::move (lifetime), std::move (lifetime_bounds), - std::move (outer_attr))); + std::move (outer_attr), locus)); generic_params.push_back (std::move (param)); if (lexer.peek_token ()->get_id () != COMMA) @@ -2841,9 +2840,9 @@ Parser::parse_generic_params (EndTokenPred is_end_token) } std::unique_ptr param ( - new AST::LifetimeParam (std::move (lifetime), locus, + new AST::LifetimeParam (std::move (lifetime), std::move (lifetime_bounds), - std::move (outer_attr))); + std::move (outer_attr), locus)); generic_params.push_back (std::move (param)); if (lexer.peek_token ()->get_id () != COMMA) @@ -3166,9 +3165,9 @@ Parser::parse_lifetime_param () // TODO: have end token passed in? } - return AST::LifetimeParam (std::move (lifetime), lifetime_tok->get_locus (), + return AST::LifetimeParam (std::move (lifetime), std::move (lifetime_bounds), - std::move (outer_attr)); + std::move (outer_attr), lifetime_tok->get_locus ()); } // Parses type generic parameters. Will also consume any trailing comma. @@ -3693,13 +3692,11 @@ Parser::parse_trait_bound () lexer.skip_token (); } - // parse for lifetimes, if it exists (although empty for lifetimes is ok to - // handle this) + /* parse for lifetimes, if it exists (although empty for lifetimes is ok to + * handle this) */ std::vector for_lifetimes; if (lexer.peek_token ()->get_id () == FOR) - { for_lifetimes = parse_for_lifetimes (); - } // handle TypePath AST::TypePath type_path = parse_type_path (); -- cgit v1.1