diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-07-31 15:29:36 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:04:32 +0100 |
commit | 47886454483eefc4dc2f0e82dd3e19173a7bf357 (patch) | |
tree | b7f230c4de23ad3fe762f1b051ab50ef90246860 /gcc | |
parent | 22bce7cbfa02a53f5505971211374cf336e07aa1 (diff) | |
download | gcc-47886454483eefc4dc2f0e82dd3e19173a7bf357.zip gcc-47886454483eefc4dc2f0e82dd3e19173a7bf357.tar.gz gcc-47886454483eefc4dc2f0e82dd3e19173a7bf357.tar.bz2 |
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 <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 52 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-early-name-resolver-2.0.h | 4 |
2 files changed, 56 insertions, 0 deletions
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 e6603cf..65ec0d6 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<AST::Attribute> 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 f2b63c9..fe1c1f6 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<AST::Attribute> attrs); + /** * Macros can either be resolved through textual scoping or regular path * scoping - which this class represents. Textual scoping works similarly to a |