public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Update resolver to use `AST::Function` instead of `AST::ExternalFunctionItem`
@ 2024-05-07 16:16 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2024-05-07 16:16 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:87f797f0e827e50eb75945593d9107431f9be2ce
commit 87f797f0e827e50eb75945593d9107431f9be2ce
Author: 0xn4utilus <gyanendrabanjare8@gmail.com>
Date: Mon Feb 26 04:39:43 2024 +0530
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>
Diff:
---
gcc/rust/checks/errors/rust-feature-gate.cc | 3 ++-
gcc/rust/hir/rust-ast-lower-extern.h | 23 ++++++++++++++++++-----
gcc/rust/parse/rust-parse-impl.h | 7 ++++---
gcc/rust/resolve/rust-ast-resolve-implitem.h | 4 ++--
gcc/rust/resolve/rust-ast-resolve-item.cc | 16 ++++++++++------
gcc/rust/resolve/rust-ast-resolve-item.h | 2 +-
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 3c943022f05e..33bbfa1ec51b 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 f9e067c8e95b..ad7d75422d68 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 c8a87a11766f..26b24150f7a1 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 4f4d2893f832..fa344effe674 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 743657bc4219..a3f27b3e4a08 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 e397ffdfe8ba..0133d2ca27f0 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 28f04a108393..c99f2f643315 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 ())
{
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-05-07 16:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-07 16:16 [gcc/devel/rust/master] Update resolver to use `AST::Function` instead of `AST::ExternalFunctionItem` Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).