diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-02 16:30:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-02 16:30:47 +0000 |
commit | 59b417323b25072aff2662f1f54f417f7b7ded61 (patch) | |
tree | ab05c3728ec828ed65b037dcfd3f067bdf917030 | |
parent | 325ef69b132819b824ae757695d9724e503f7256 (diff) | |
parent | 2840815dc44a46ecaf1d7a9acd6634b92233433b (diff) | |
download | gcc-59b417323b25072aff2662f1f54f417f7b7ded61.zip gcc-59b417323b25072aff2662f1f54f417f7b7ded61.tar.gz gcc-59b417323b25072aff2662f1f54f417f7b7ded61.tar.bz2 |
Merge #469
469: lowering attribute by copying attribute from AST to HIR directly r=philberty a=thomasyonug
lowering attribute by copying attribute from AST to HIR directly.
Addresses #459
Co-authored-by: Thomas Young <wenzhang5800@gmail.com>
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 1 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-block.h | 3 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-expr.h | 72 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-implitem.h | 10 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-item.h | 31 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-stmt.h | 3 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower.cc | 13 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir.h | 3 |
8 files changed, 46 insertions, 90 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 08f29d1..3b768a6 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1611,6 +1611,7 @@ public: } NodeId get_node_id () const { return node_id; } + const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; } }; // Base path expression AST node - abstract diff --git a/gcc/rust/hir/rust-ast-lower-block.h b/gcc/rust/hir/rust-ast-lower-block.h index 77ca50d..b29bd14 100644 --- a/gcc/rust/hir/rust-ast-lower-block.h +++ b/gcc/rust/hir/rust-ast-lower-block.h @@ -142,7 +142,6 @@ public: void visit (AST::LoopExpr &expr) override { - AST::AttrVec outer_attribs; HIR::BlockExpr *loop_block = ASTLoweringBlock::translate (expr.get_loop_block ().get (), &terminated); @@ -158,7 +157,7 @@ public: = new HIR::LoopExpr (mapping, std::unique_ptr<HIR::BlockExpr> (loop_block), expr.get_locus (), std::move (loop_label), - std::move (outer_attribs)); + expr.get_outer_attrs ()); } void visit (AST::WhileLoopExpr &expr) override; diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index 0aeaf09..82d13d0 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.h +++ b/gcc/rust/hir/rust-ast-lower-expr.h @@ -80,8 +80,6 @@ public: void visit (AST::TupleIndexExpr &expr) override { - AST::AttrVec outer_attribs; - HIR::Expr *tuple_expr = ASTLoweringExpr::translate (expr.get_tuple_expr ().get (), &terminated); @@ -94,13 +92,11 @@ public: = new HIR::TupleIndexExpr (mapping, std::unique_ptr<HIR::Expr> (tuple_expr), expr.get_tuple_index (), - std::move (outer_attribs), expr.get_locus ()); + expr.get_outer_attrs (), expr.get_locus ()); } void visit (AST::TupleExpr &expr) override { - AST::AttrVec inner_attribs; - AST::AttrVec outer_attribs; std::vector<std::unique_ptr<HIR::Expr> > tuple_elements; for (auto &e : expr.get_tuple_elems ()) { @@ -115,8 +111,8 @@ public: translated = new HIR::TupleExpr (std::move (mapping), std::move (tuple_elements), - std::move (inner_attribs), - std::move (outer_attribs), expr.get_locus ()); + expr.get_inner_attrs (), expr.get_outer_attrs (), + expr.get_locus ()); } void visit (AST::IfExpr &expr) override @@ -163,7 +159,6 @@ public: void visit (AST::CallExpr &expr) override { - AST::AttrVec outer_attribs; HIR::Expr *func = ASTLoweringExpr::translate (expr.get_function_expr ().get ()); std::vector<std::unique_ptr<HIR::Expr> > params; @@ -178,16 +173,13 @@ public: crate_num, UNKNOWN_NODEID /* this can map back to the AST*/, mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - translated - = new HIR::CallExpr (mapping, std::unique_ptr<HIR::Expr> (func), - std::move (params), std::move (outer_attribs), - expr.get_locus ()); + translated = new HIR::CallExpr (mapping, std::unique_ptr<HIR::Expr> (func), + std::move (params), expr.get_outer_attrs (), + expr.get_locus ()); } void visit (AST::MethodCallExpr &expr) override { - AST::AttrVec outer_attribs; - HIR::PathExprSegment method_path = lower_path_expr_seg (expr.get_method_name ()); @@ -209,7 +201,7 @@ public: translated = new HIR::MethodCallExpr (mapping, std::unique_ptr<HIR::Expr> (receiver), method_path, std::move (params), - std::move (outer_attribs), expr.get_locus ()); + expr.get_outer_attrs (), expr.get_locus ()); } void visit (AST::AssignmentExpr &expr) override @@ -240,9 +232,6 @@ public: void visit (AST::ArrayExpr &expr) override { - AST::AttrVec outer_attribs; - AST::AttrVec inner_attribs; - expr.get_array_elems ()->accept_vis (*this); rust_assert (translated_array_elems != nullptr); HIR::ArrayElems *elems = translated_array_elems; @@ -254,12 +243,12 @@ public: translated = new HIR::ArrayExpr (mapping, std::unique_ptr<HIR::ArrayElems> (elems), - inner_attribs, outer_attribs, expr.get_locus ()); + expr.get_inner_attrs (), expr.get_outer_attrs (), + expr.get_locus ()); } void visit (AST::ArrayIndexExpr &expr) override { - AST::AttrVec outer_attribs; HIR::Expr *array_expr = ASTLoweringExpr::translate (expr.get_array_expr ().get ()); HIR::Expr *array_index_expr @@ -274,7 +263,7 @@ public: = new HIR::ArrayIndexExpr (mapping, std::unique_ptr<HIR::Expr> (array_expr), std::unique_ptr<HIR::Expr> (array_index_expr), - outer_attribs, expr.get_locus ()); + expr.get_outer_attrs (), expr.get_locus ()); } void visit (AST::ArrayElemsValues &elems) override @@ -402,8 +391,6 @@ public: void visit (AST::NegationExpr &expr) override { - AST::AttrVec outer_attribs; - HIR::Expr *negated_value = ASTLoweringExpr::translate (expr.get_negated_expr ().get ()); @@ -414,7 +401,7 @@ public: translated = new HIR::NegationExpr (mapping, std::unique_ptr<HIR::Expr> (negated_value), - expr.get_expr_type (), std::move (outer_attribs), + expr.get_expr_type (), expr.get_outer_attrs (), expr.get_locus ()); } @@ -482,9 +469,6 @@ public: void visit (AST::StructExprStructFields &struct_expr) override { - AST::AttrVec inner_attribs; - AST::AttrVec outer_attribs; - // bit of a hack for now HIR::PathInExpression *path = ASTLowerPathInExpression::translate (&struct_expr.get_struct_name ()); @@ -513,18 +497,13 @@ public: mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - translated - = new HIR::StructExprStructFields (mapping, copied_path, - std::move (fields), - struct_expr.get_locus (), base, - inner_attribs, outer_attribs); + translated = new HIR::StructExprStructFields ( + mapping, copied_path, std::move (fields), struct_expr.get_locus (), base, + struct_expr.get_inner_attrs (), struct_expr.get_outer_attrs ()); } void visit (AST::GroupedExpr &expr) override { - AST::AttrVec inner_attribs; - AST::AttrVec outer_attribs; - HIR::Expr *paren_expr = ASTLoweringExpr::translate (expr.get_expr_in_parens ().get ()); @@ -535,15 +514,12 @@ public: translated = new HIR::GroupedExpr (mapping, std::unique_ptr<HIR::Expr> (paren_expr), - std::move (inner_attribs), - std::move (outer_attribs), expr.get_locus ()); + expr.get_inner_attrs (), expr.get_outer_attrs (), + expr.get_locus ()); } void visit (AST::FieldAccessExpr &expr) override { - AST::AttrVec inner_attribs; - AST::AttrVec outer_attribs; - HIR::Expr *receiver = ASTLoweringExpr::translate (expr.get_receiver_expr ().get ()); @@ -555,7 +531,7 @@ public: = new HIR::FieldAccessExpr (mapping, std::unique_ptr<HIR::Expr> (receiver), expr.get_field_name (), - std::move (outer_attribs), expr.get_locus ()); + expr.get_outer_attrs (), expr.get_locus ()); } void visit (AST::LoopExpr &expr) override @@ -570,7 +546,6 @@ public: void visit (AST::BreakExpr &expr) override { - AST::AttrVec outer_attribs; HIR::Lifetime break_label = lower_lifetime (expr.get_label ()); HIR::Expr *break_expr = expr.has_break_expr () @@ -585,12 +560,11 @@ public: translated = new HIR::BreakExpr (mapping, expr.get_locus (), std ::move (break_label), std::unique_ptr<HIR::Expr> (break_expr), - std::move (outer_attribs)); + expr.get_outer_attrs ()); } void visit (AST::ContinueExpr &expr) override { - AST::AttrVec outer_attribs; HIR::Lifetime break_label = lower_lifetime (expr.get_label ()); auto crate_num = mappings->get_current_crate (); @@ -600,13 +574,11 @@ public: translated = new HIR::ContinueExpr (mapping, expr.get_locus (), std ::move (break_label), - std::move (outer_attribs)); + expr.get_outer_attrs ()); } void visit (AST::BorrowExpr &expr) override { - AST::AttrVec outer_attribs; - HIR::Expr *borrow_lvalue = ASTLoweringExpr::translate (expr.get_borrowed_expr ().get ()); @@ -619,13 +591,11 @@ public: = new HIR::BorrowExpr (mapping, std::unique_ptr<HIR::Expr> (borrow_lvalue), expr.get_is_mut (), expr.get_is_double_borrow (), - std::move (outer_attribs), expr.get_locus ()); + expr.get_outer_attrs (), expr.get_locus ()); } void visit (AST::DereferenceExpr &expr) override { - AST::AttrVec outer_attribs; - HIR::Expr *dref_lvalue = ASTLoweringExpr::translate (expr.get_dereferenced_expr ().get ()); @@ -637,7 +607,7 @@ public: translated = new HIR::DereferenceExpr (mapping, std::unique_ptr<HIR::Expr> (dref_lvalue), - std::move (outer_attribs), expr.get_locus ()); + expr.get_outer_attrs (), expr.get_locus ()); } private: diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index 43cc256..7b88408 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -60,7 +60,6 @@ public: void visit (AST::ConstantItem &constant) override { - AST::AttrVec outer_attrs; HIR::Visibility vis = HIR::Visibility::create_public (); HIR::Type *type = ASTLoweringType::translate (constant.get_type ().get ()); @@ -74,7 +73,8 @@ public: translated = new HIR::ConstantItem (mapping, constant.get_identifier (), vis, std::unique_ptr<HIR::Type> (type), std::unique_ptr<HIR::Expr> (expr), - outer_attrs, constant.get_locus ()); + constant.get_outer_attrs (), + constant.get_locus ()); mappings->insert_hir_implitem (mapping.get_crate_num (), mapping.get_hirid (), parent_impl_id, @@ -86,7 +86,6 @@ public: void visit (AST::Function &function) override { // ignore for now and leave empty - AST::AttrVec outer_attrs; std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items; HIR::WhereClause where_clause (std::move (where_clause_items)); HIR::FunctionQualifiers qualifiers ( @@ -147,7 +146,7 @@ public: std::move (qualifiers), std::move (generic_params), std::move (function_params), std::move (return_type), std::move (where_clause), std::move (function_body), - std::move (vis), std::move (outer_attrs), locus); + std::move (vis), function.get_outer_attrs (), locus); mappings->insert_hir_implitem (mapping.get_crate_num (), mapping.get_hirid (), parent_impl_id, fn); @@ -169,7 +168,6 @@ public: void visit (AST::Method &method) override { // ignore for now and leave empty - AST::AttrVec outer_attrs; std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items; HIR::WhereClause where_clause (std::move (where_clause_items)); HIR::FunctionQualifiers qualifiers ( @@ -228,7 +226,7 @@ public: std::move (self_param), std::move (function_params), std::move (return_type), std::move (where_clause), std::move (method_body), std::move (vis), - std::move (outer_attrs), locus); + method.get_outer_attrs (), locus); mappings->insert_hir_implitem (mapping.get_crate_num (), mapping.get_hirid (), parent_impl_id, mth); diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h index 10ec203..936aebb 100644 --- a/gcc/rust/hir/rust-ast-lower-item.h +++ b/gcc/rust/hir/rust-ast-lower-item.h @@ -58,7 +58,6 @@ public: std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items; HIR::WhereClause where_clause (std::move (where_clause_items)); HIR::Visibility vis = HIR::Visibility::create_public (); - AST::AttrVec outer_attrs; std::vector<std::unique_ptr<HIR::GenericParam> > generic_params; if (alias.has_generics ()) @@ -76,7 +75,7 @@ public: std::move (generic_params), std::move (where_clause), std::unique_ptr<HIR::Type> (existing_type), - std::move (vis), std::move (outer_attrs), + std::move (vis), alias.get_outer_attrs (), alias.get_locus ()); mappings->insert_defid_mapping (mapping.get_defid (), translated); @@ -98,11 +97,9 @@ public: std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items; HIR::WhereClause where_clause (std::move (where_clause_items)); HIR::Visibility vis = HIR::Visibility::create_public (); - AST::AttrVec outer_attrs; std::vector<HIR::TupleField> fields; struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool { - AST::AttrVec outer_attrs; HIR::Visibility vis = HIR::Visibility::create_public (); HIR::Type *type = ASTLoweringType::translate (field.get_field_type ().get ()); @@ -118,7 +115,7 @@ public: Location field_locus; HIR::TupleField translated_field (mapping, std::unique_ptr<HIR::Type> (type), vis, - field_locus, outer_attrs); + field_locus, field.get_outer_attrs ()); fields.push_back (std::move (translated_field)); return true; }); @@ -132,7 +129,7 @@ public: struct_decl.get_identifier (), std::move (generic_params), std::move (where_clause), vis, - std::move (outer_attrs), + struct_decl.get_outer_attrs (), struct_decl.get_locus ()); mappings->insert_defid_mapping (mapping.get_defid (), translated); @@ -154,12 +151,10 @@ public: std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items; HIR::WhereClause where_clause (std::move (where_clause_items)); HIR::Visibility vis = HIR::Visibility::create_public (); - AST::AttrVec outer_attrs; bool is_unit = struct_decl.is_unit_struct (); std::vector<HIR::StructField> fields; struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool { - AST::AttrVec outer_attrs; HIR::Visibility vis = HIR::Visibility::create_public (); HIR::Type *type = ASTLoweringType::translate (field.get_field_type ().get ()); @@ -175,7 +170,7 @@ public: Location field_locus; HIR::StructField translated_field (mapping, field.get_field_name (), std::unique_ptr<HIR::Type> (type), vis, - field_locus, outer_attrs); + field_locus, field.get_outer_attrs ()); fields.push_back (std::move (translated_field)); return true; }); @@ -189,7 +184,7 @@ public: struct_decl.get_identifier (), std::move (generic_params), std::move (where_clause), is_unit, vis, - std::move (outer_attrs), + struct_decl.get_outer_attrs (), struct_decl.get_locus ()); mappings->insert_defid_mapping (mapping.get_defid (), translated); @@ -201,7 +196,6 @@ public: void visit (AST::StaticItem &var) override { - AST::AttrVec outer_attrs; HIR::Visibility vis = HIR::Visibility::create_public (); HIR::Type *type = ASTLoweringType::translate (var.get_type ().get ()); @@ -216,7 +210,7 @@ public: = new HIR::StaticItem (mapping, var.get_identifier (), var.is_mutable (), std::unique_ptr<HIR::Type> (type), std::unique_ptr<HIR::Expr> (expr), vis, - outer_attrs, var.get_locus ()); + var.get_outer_attrs (), var.get_locus ()); mappings->insert_defid_mapping (mapping.get_defid (), translated); mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (), @@ -227,7 +221,6 @@ public: void visit (AST::ConstantItem &constant) override { - AST::AttrVec outer_attrs; HIR::Visibility vis = HIR::Visibility::create_public (); HIR::Type *type = ASTLoweringType::translate (constant.get_type ().get ()); @@ -241,7 +234,8 @@ public: translated = new HIR::ConstantItem (mapping, constant.get_identifier (), vis, std::unique_ptr<HIR::Type> (type), std::unique_ptr<HIR::Expr> (expr), - outer_attrs, constant.get_locus ()); + constant.get_outer_attrs (), + constant.get_locus ()); mappings->insert_defid_mapping (mapping.get_defid (), translated); mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (), @@ -253,7 +247,6 @@ public: void visit (AST::Function &function) override { // ignore for now and leave empty - AST::AttrVec outer_attrs; std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items; HIR::WhereClause where_clause (std::move (where_clause_items)); HIR::FunctionQualifiers qualifiers ( @@ -315,7 +308,7 @@ public: std::move (qualifiers), std::move (generic_params), std::move (function_params), std::move (return_type), std::move (where_clause), std::move (function_body), - std::move (vis), std::move (outer_attrs), locus); + std::move (vis), function.get_outer_attrs (), locus); mappings->insert_defid_mapping (mapping.get_defid (), translated); mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (), @@ -337,8 +330,6 @@ public: void visit (AST::InherentImpl &impl_block) override { - AST::AttrVec inner_attrs; - AST::AttrVec outer_attrs; std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items; HIR::WhereClause where_clause (std::move (where_clause_items)); @@ -397,8 +388,8 @@ public: = new HIR::InherentImpl (mapping, std::move (impl_items), std::move (generic_params), std::unique_ptr<HIR::Type> (trait_type), - where_clause, vis, std::move (inner_attrs), - std::move (outer_attrs), + where_clause, vis, impl_block.get_inner_attrs (), + impl_block.get_outer_attrs (), impl_block.get_locus ()); mappings->insert_defid_mapping (mapping.get_defid (), translated); diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h index 0534749..b0763e6 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.h +++ b/gcc/rust/hir/rust-ast-lower-stmt.h @@ -86,7 +86,6 @@ public: void visit (AST::LetStmt &stmt) override { - AST::AttrVec outer_attrs; HIR::Pattern *variables = ASTLoweringPattern::translate (stmt.get_pattern ().get ()); HIR::Type *type = stmt.has_type () @@ -105,7 +104,7 @@ public: = new HIR::LetStmt (mapping, std::unique_ptr<HIR::Pattern> (variables), std::unique_ptr<HIR::Expr> (init_expression), std::unique_ptr<HIR::Type> (type), - std::move (outer_attrs), stmt.get_locus ()); + stmt.get_outer_attrs (), stmt.get_locus ()); mappings->insert_location (crate_num, mapping.get_hirid (), stmt.get_locus ()); mappings->insert_hir_stmt (crate_num, mapping.get_hirid (), translated); diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index b436089..c8c506c 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -40,7 +40,6 @@ HIR::Crate ASTLowering::go () { std::vector<std::unique_ptr<HIR::Item> > items; - AST::AttrVec inner_attrs; bool has_utf8bom = false; bool has_shebang = false; @@ -57,7 +56,7 @@ ASTLowering::go () mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - return HIR::Crate (std::move (items), std::move (inner_attrs), mapping, + return HIR::Crate (std::move (items), astCrate.get_inner_attrs (), mapping, has_utf8bom, has_shebang); } @@ -65,9 +64,6 @@ ASTLowering::go () void ASTLoweringBlock::visit (AST::BlockExpr &expr) { - AST::AttrVec inner_attribs; - AST::AttrVec outer_attribs; - std::vector<std::unique_ptr<HIR::Stmt> > block_stmts; bool block_did_terminate = false; expr.iterate_stmts ([&] (AST::Stmt *s) mutable -> bool { @@ -105,8 +101,8 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr) translated = new HIR::BlockExpr (mapping, std::move (block_stmts), std::unique_ptr<HIR::ExprWithoutBlock> (tail_expr), - tail_reachable, std::move (inner_attribs), - std::move (outer_attribs), expr.get_locus ()); + tail_reachable, expr.get_inner_attrs (), + expr.get_outer_attrs (), expr.get_locus ()); terminated = block_did_terminate; } @@ -240,7 +236,6 @@ ASTLowerStructExprField::visit (AST::StructExprFieldIdentifier &field) void ASTLoweringExprWithBlock::visit (AST::WhileLoopExpr &expr) { - AST::AttrVec outer_attribs; HIR::BlockExpr *loop_block = ASTLoweringBlock::translate (expr.get_loop_block ().get (), &terminated); @@ -259,7 +254,7 @@ ASTLoweringExprWithBlock::visit (AST::WhileLoopExpr &expr) std::unique_ptr<HIR::Expr> (loop_condition), std::unique_ptr<HIR::BlockExpr> (loop_block), expr.get_locus (), std::move (loop_label), - std::move (outer_attribs)); + expr.get_outer_attrs ()); } // rust-ast-lower-expr.h diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index decf0c9..0bc8a54 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -290,6 +290,9 @@ public: virtual void accept_vis (HIRVisitor &vis ATTRIBUTE_UNUSED) {} + AST::AttrVec &get_outer_attrs () { return outer_attrs; } + const AST::AttrVec &get_outer_attrs () const { return outer_attrs; } + protected: // Constructor Item (Analysis::NodeMapping mappings, |