// 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" 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::Function &function) { if (function.has_return_type ()) ResolveType::go (function.get_return_type ().get (), function.get_node_id ()); 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 ()); } // setup parent scoping for names NodeId scope_node_id = function.get_definition ()->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 ()); function.get_definition ()->iterate_stmts ( [&] (AST::Stmt *s) mutable -> bool { ResolveStmt::go (s, s->get_node_id ()); return true; }); 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