// 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 // . #ifndef RUST_AST_RESOLVE_ITEM_H #define RUST_AST_RESOLVE_ITEM_H #include "rust-ast-resolve-base.h" #include "rust-ast-full.h" #include "rust-ast-resolve-type.h" #include "rust-ast-resolve-pattern.h" #include "rust-ast-resolve-stmt.h" #include "rust-ast-resolve-unused.h" namespace Rust { namespace Resolver { class ResolveItem : public ResolverBase { public: static void go (AST::Item *item) { ResolveItem resolver; item->accept_vis (resolver); }; ~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::StaticItem &var) { ResolveType::go (var.get_type ().get (), var.get_node_id ()); ResolveExpr::go (var.get_expr ().get (), var.get_node_id ()); } void visit (AST::ConstantItem &constant) { ResolveType::go (constant.get_type ().get (), constant.get_node_id ()); ResolveExpr::go (constant.get_expr ().get (), constant.get_node_id ()); } void visit (AST::Function &function) { if (function.has_return_type ()) ResolveType::go (function.get_return_type ().get (), function.get_node_id ()); NodeId scope_node_id = function.get_node_id (); resolver->get_name_scope ().push (scope_node_id); resolver->get_type_scope ().push (scope_node_id); resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); resolver->push_new_type_rib (resolver->get_type_scope ().peek ()); // we make a new scope so the names of parameters are resolved and shadowed // correctly for (auto ¶m : function.get_function_params ()) { ResolveType::go (param.get_type ().get (), param.get_node_id ()); PatternDeclaration::go (param.get_pattern ().get (), param.get_node_id ()); } // resolve the function body ResolveExpr::go (function.get_definition ().get (), function.get_node_id ()); ScanUnused::Scan (resolver->get_name_scope ().peek ()); ScanUnused::Scan (resolver->get_type_scope ().peek ()); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); } private: ResolveItem () : ResolverBase (UNKNOWN_NODEID) {} }; } // namespace Resolver } // namespace Rust #endif // RUST_AST_RESOLVE_ITEM_H