diff options
author | 0xn4utilus <gyanendrabanjare8@gmail.com> | 2024-02-26 04:39:43 +0530 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2024-03-05 15:08:36 +0000 |
commit | 87f797f0e827e50eb75945593d9107431f9be2ce (patch) | |
tree | 5ac287a4a12e3d8661b3ddd03244a2d391329fad | |
parent | 0177e3cb1382d4eeefce0038b4791e7fb25bc2b9 (diff) | |
download | gcc-87f797f0e827e50eb75945593d9107431f9be2ce.zip gcc-87f797f0e827e50eb75945593d9107431f9be2ce.tar.gz gcc-87f797f0e827e50eb75945593d9107431f9be2ce.tar.bz2 |
Update resolver to use `AST::Function` instead of `AST::ExternalFunctionItem`
gcc/rust/ChangeLog:
* checks/errors/rust-feature-gate.cc (FeatureGate::visit):
Check if function is_external or not.
* hir/rust-ast-lower-extern.h: Use AST::Function
instead of AST::ExternalFunctionItem.
* parse/rust-parse-impl.h (Parser::parse_external_item):
Likewise.
(Parser::parse_pattern): Fix clang format.
* resolve/rust-ast-resolve-implitem.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveExternItem::visit):
Likewise.
* resolve/rust-ast-resolve-item.h: Likewise.
* resolve/rust-default-resolver.cc (DefaultResolver::visit):
Check if param has_pattern before using get_pattern.
Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
-rw-r--r-- | gcc/rust/checks/errors/rust-feature-gate.cc | 3 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-extern.h | 23 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 7 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-implitem.h | 4 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 16 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.h | 2 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-default-resolver.cc | 3 |
7 files changed, 39 insertions, 19 deletions
diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc index 3c94302..33bbfa1 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -131,7 +131,8 @@ FeatureGate::visit (AST::MacroRulesDefinition &rules_def) void FeatureGate::visit (AST::Function &function) { - check_rustc_attri (function.get_outer_attrs ()); + if (!function.is_external ()) + check_rustc_attri (function.get_outer_attrs ()); } void diff --git a/gcc/rust/hir/rust-ast-lower-extern.h b/gcc/rust/hir/rust-ast-lower-extern.h index f9e067c..ad7d754 100644 --- a/gcc/rust/hir/rust-ast-lower-extern.h +++ b/gcc/rust/hir/rust-ast-lower-extern.h @@ -65,7 +65,7 @@ public: item.get_outer_attrs (), item.get_locus ()); } - void visit (AST::ExternalFunctionItem &function) override + void visit (AST::Function &function) override { std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items; HIR::WhereClause where_clause (std::move (where_clause_items)); @@ -88,12 +88,25 @@ public: std::vector<HIR::NamedFunctionParam> function_params; for (auto it = begin; it != end; it++) { + auto param = static_cast<AST::FunctionParam *> (it->get ()); + + if (param->is_variadic () || param->is_self ()) + continue; + auto param_kind = param->get_pattern ()->get_pattern_kind (); + + rust_assert (param_kind == AST::Pattern::Kind::Identifier + || param_kind == AST::Pattern::Kind::Wildcard); + auto param_ident = static_cast<AST::IdentifierPattern *> ( + param->get_pattern ().get ()); + Identifier param_name = param_kind == AST::Pattern::Kind::Identifier + ? param_ident->get_ident () + : std::string ("_"); + HIR::Type *param_type - = ASTLoweringType::translate (it->get_type ().get ()); - Identifier param_name = it->get_name (); + = ASTLoweringType::translate (param->get_type ().get ()); auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, it->get_node_id (), + Analysis::NodeMapping mapping (crate_num, param->get_node_id (), mappings->get_next_hir_id (crate_num), mappings->get_next_localdef_id ( crate_num)); @@ -109,7 +122,7 @@ public: mappings->get_next_localdef_id (crate_num)); translated = new HIR::ExternalFunctionItem ( - mapping, function.get_identifier (), std::move (generic_params), + mapping, function.get_function_name (), std::move (generic_params), std::unique_ptr<HIR::Type> (return_type), std::move (where_clause), std::move (function_params), is_variadic, std::move (vis), function.get_outer_attrs (), function.get_locus ()); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index c8a87a1..26b2415 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6165,8 +6165,7 @@ Parser<ManagedTokenSource>::parse_external_item () std::move (outer_attrs), locus)); } case FN_KW: - return parse_external_function_item (std::move (vis), - std::move (outer_attrs)); + return parse_function (std::move (vis), std::move (outer_attrs), true); case TYPE: return parse_external_type_item (std::move (vis), @@ -10476,7 +10475,9 @@ Parser<ManagedTokenSource>::parse_pattern () { lexer.skip_token (); alts.push_back (parse_pattern_no_alt ()); - } while (lexer.peek_token ()->get_id () == PIPE); + } + + while (lexer.peek_token ()->get_id () == PIPE); /* alternates */ return std::unique_ptr<AST::Pattern> ( diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h index 4f4d2893..fa344ef 100644 --- a/gcc/rust/resolve/rust-ast-resolve-implitem.h +++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h @@ -189,11 +189,11 @@ public: item->accept_vis (resolver); }; - void visit (AST::ExternalFunctionItem &function) override + void visit (AST::Function &function) override { auto decl = CanonicalPath::new_seg (function.get_node_id (), - function.get_identifier ().as_string ()); + function.get_function_name ().as_string ()); auto path = prefix.append (decl); resolver->get_name_scope ().insert ( diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 743657b..a3f27b3 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -1009,11 +1009,12 @@ ResolveExternItem::go (AST::ExternalItem *item, const CanonicalPath &prefix, } void -ResolveExternItem::visit (AST::ExternalFunctionItem &function) +ResolveExternItem::visit (AST::Function &function) { NodeId scope_node_id = function.get_node_id (); - auto decl = CanonicalPath::new_seg (function.get_node_id (), - function.get_identifier ().as_string ()); + auto decl + = CanonicalPath::new_seg (function.get_node_id (), + function.get_function_name ().as_string ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); @@ -1038,9 +1039,12 @@ ResolveExternItem::visit (AST::ExternalFunctionItem &function) // we make a new scope so the names of parameters are resolved and shadowed // correctly - for (auto ¶m : function.get_function_params ()) - if (!param.is_variadic ()) - ResolveType::go (param.get_type ().get ()); + for (auto &it : function.get_function_params ()) + if (!it->is_variadic ()) + { + auto param = static_cast<AST::FunctionParam *> (it.get ()); + ResolveType::go (param->get_type ().get ()); + } // done resolver->get_name_scope ().pop (); diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index e397ffd..0133d2c 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -111,7 +111,7 @@ public: static void go (AST::ExternalItem *item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix); - void visit (AST::ExternalFunctionItem &function) override; + void visit (AST::Function &function) override; void visit (AST::ExternalStaticItem &item) override; private: diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc index 28f04a1..c99f2f6 100644 --- a/gcc/rust/resolve/rust-default-resolver.cc +++ b/gcc/rust/resolve/rust-default-resolver.cc @@ -62,7 +62,8 @@ DefaultResolver::visit (AST::Function &function) if (p->is_variadic ()) { auto param = static_cast<AST::VariadicParam *> (p.get ()); - param->get_pattern ()->accept_vis (*this); + if (param->has_pattern ()) + param->get_pattern ()->accept_vis (*this); } else if (p->is_self ()) { |