From: Pierre-Emmanuel Patry Date: Mon, 31 Jul 2023 13:29:36 +0000 (+0200) Subject: gccrs: Visit function and structure attributes X-Git-Tag: basepoints/gcc-15~2159 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=47886454483eefc4dc2f0e82dd3e19173a7bf357;p=thirdparty%2Fgcc.git gccrs: Visit function and structure attributes Add a simple attribute visit function and override StructStruct & Function visit functions. gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): Add function to handle attributes. (Early::visit): Override visitor functions. * resolve/rust-early-name-resolver-2.0.h: Add prototype. Signed-off-by: Pierre-Emmanuel Patry --- diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc index e6603cf4fbd8..65ec0d659167 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc @@ -19,6 +19,7 @@ #include "rust-early-name-resolver-2.0.h" #include "rust-ast-full.h" #include "rust-toplevel-name-resolver-2.0.h" +#include "rust-attributes.h" namespace Rust { namespace Resolver2_0 { @@ -173,5 +174,56 @@ void Early::visit (AST::UseTreeGlob &use) {} +void +Early::visit_attributes (std::vector attrs) +{ + for (auto &attr : attrs) + { + auto name = attr.get_path ().get_segments ().at (0).get_segment_name (); + + if (attr.is_derive ()) + { + auto traits = attr.get_traits_to_derive (); + for (auto &trait : traits) + { + auto definition = ctx.macros.resolve_path (trait.get ()); + if (!definition.has_value ()) + { + // FIXME: Change to proper error message + rust_error_at (trait.get ().get_locus (), + "could not resolve trait"); + } + } + } + else if (Analysis::BuiltinAttributeMappings::get () + ->lookup_builtin (name) + .is_error ()) // Do not resolve builtins + { + auto definition = ctx.macros.resolve_path (attr.get_path ()); + if (!definition.has_value ()) + { + // FIXME: Change to proper error message + rust_error_at (attr.get_locus (), + "could not resolve attribute macro invocation"); + return; + } + } + } +} + +void +Early::visit (AST::Function &fn) +{ + visit_attributes (fn.get_outer_attrs ()); + DefaultResolver::visit (fn); +} + +void +Early::visit (AST::StructStruct &s) +{ + visit_attributes (s.get_outer_attrs ()); + DefaultResolver::visit (s); +} + } // namespace Resolver2_0 } // namespace Rust diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.h b/gcc/rust/resolve/rust-early-name-resolver-2.0.h index f2b63c9b6967..fe1c1f6b11cb 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.h @@ -54,8 +54,12 @@ public: void visit (AST::UseTreeRebind &) override; void visit (AST::UseTreeList &) override; void visit (AST::UseTreeGlob &) override; + void visit (AST::Function &) override; + void visit (AST::StructStruct &) override; private: + void visit_attributes (std::vector attrs); + /** * Macros can either be resolved through textual scoping or regular path * scoping - which this class represents. Textual scoping works similarly to a