diff options
author | Philip Herron <philip.herron@embecosm.com> | 2020-12-30 22:13:41 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-06 10:01:17 +0000 |
commit | 36ebe9a0380694c8517536eb37c7134f1323a30b (patch) | |
tree | 06901ff25aa5ea093184e0713bd0363735408959 /gcc/rust/resolve | |
parent | 467141184aa274126ff7e2a41d08bb621b7a3fdf (diff) | |
download | gcc-36ebe9a0380694c8517536eb37c7134f1323a30b.zip gcc-36ebe9a0380694c8517536eb37c7134f1323a30b.tar.gz gcc-36ebe9a0380694c8517536eb37c7134f1323a30b.tar.bz2 |
This brings structs back in post HIR changes. It supports structs
where no base struct is referenced and the constructor is in order.
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-expr.h | 35 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.h | 8 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h | 53 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-toplevel.h | 6 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve.cc | 8 |
5 files changed, 100 insertions, 10 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h index d86866c..2292d16 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.h +++ b/gcc/rust/resolve/rust-ast-resolve-expr.h @@ -21,6 +21,7 @@ #include "rust-ast-resolve-base.h" #include "rust-ast-full.h" +#include "rust-ast-resolve-struct-expr-field.h" namespace Rust { namespace Resolver { @@ -38,19 +39,22 @@ public: void visit (AST::PathInExpression &expr) { + // name scope first if (!resolver->get_name_scope ().lookup (expr.as_string (), &resolved_node)) { - rust_error_at (expr.get_locus (), "unknown path %s", - expr.as_string ().c_str ()); - return; - } - else - { - resolver->insert_resolved_name (expr.get_node_id (), resolved_node); - resolver->insert_new_definition (expr.get_node_id (), - Definition{expr.get_node_id (), - parent}); + // check the type scope + if (!resolver->get_type_scope ().lookup (expr.as_string (), + &resolved_node)) + { + rust_error_at (expr.get_locus (), "unknown path %s", + expr.as_string ().c_str ()); + return; + } } + + resolver->insert_resolved_name (expr.get_node_id (), resolved_node); + resolver->insert_new_definition (expr.get_node_id (), + Definition{expr.get_node_id (), parent}); } void visit (AST::ReturnExpr &expr) @@ -154,6 +158,17 @@ public: ResolveExpr::go (elems.get_elem_to_copy ().get (), elems.get_node_id ()); } + void visit (AST::StructExprStructFields &struct_expr) + { + ResolveExpr::go (&struct_expr.get_struct_name (), + struct_expr.get_node_id ()); + struct_expr.iterate ( + [&] (AST::StructExprField *struct_field) mutable -> bool { + ResolveStructExprField::go (struct_field, struct_expr.get_node_id ()); + return true; + }); + } + private: ResolveExpr (NodeId parent) : ResolverBase (parent) {} }; diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index eca52dc..523f985 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -39,6 +39,14 @@ public: ~ResolveItem () {} + void visit (AST::StructStruct &struct_decl) + { + struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool { + ResolveType::go (field.get_field_type ().get (), field.get_node_id ()); + return true; + }); + } + void visit (AST::ConstantItem &constant) { ResolveType::go (constant.get_type ().get (), constant.get_node_id ()); diff --git a/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h b/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h new file mode 100644 index 0000000..c705a03 --- /dev/null +++ b/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h @@ -0,0 +1,53 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#ifndef RUST_AST_RESOLVE_STRUCT_EXPR_FIELD +#define RUST_AST_RESOLVE_STRUCT_EXPR_FIELD + +#include "rust-ast-resolve-base.h" +#include "rust-ast-full.h" + +namespace Rust { +namespace Resolver { + +// this resolves values being assigned not that the field actually exists yet. +// We cant resolve the field to struct until type resolution since the HIR +// Mappings don't exist yet. +class ResolveStructExprField : public ResolverBase +{ +public: + static void go (AST::StructExprField *field, NodeId parent) + { + ResolveStructExprField resolver (parent); + field->accept_vis (resolver); + } + + virtual ~ResolveStructExprField () {} + + void visit (AST::StructExprFieldIdentifierValue &field); + + // TODO + +private: + ResolveStructExprField (NodeId parent) : ResolverBase (parent) {} +}; + +} // namespace Resolver +} // namespace Rust + +#endif // RUST_AST_RESOLVE_STRUCT_EXPR_FIELD diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 0b6256e..f770ed7 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -36,6 +36,12 @@ public: ~ResolveTopLevel () {} + void visit (AST::StructStruct &struct_decl) + { + resolver->get_type_scope ().insert (struct_decl.get_identifier (), + struct_decl.get_node_id ()); + } + void visit (AST::ConstantItem &constant) { resolver->get_name_scope ().insert (constant.get_identifier (), diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 8370a5b..dc368aa 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -271,5 +271,13 @@ ResolveExpr::visit (AST::BlockExpr &expr) resolver->get_type_scope ().pop (); } +// rust-ast-resolve-struct-expr-field.h + +void +ResolveStructExprField::visit (AST::StructExprFieldIdentifierValue &field) +{ + ResolveExpr::go (field.get_value ().get (), field.get_node_id ()); +} + } // namespace Resolver } // namespace Rust |