/** * Copyright 2019-2020 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MINDSPORE_CCSRC_PIPELINE_JIT_PARSE_RESOLVE_H_ #define MINDSPORE_CCSRC_PIPELINE_JIT_PARSE_RESOLVE_H_ #include #include #include "ir/anf.h" #include "ir/manager.h" #include "pipeline/jit/parse/python_adapter.h" #include "pipeline/jit/parse/parse_base.h" #include "abstract/abstract_value.h" #include "utils/log_adapter.h" // forward declaration of ResourceBase namespace mindspore { namespace pipeline { class ResourceBase; using ResourceBasePtr = std::shared_ptr; } // namespace pipeline } // namespace mindspore namespace mindspore { namespace parse { // NameSpace class for resolving python code. class NameSpace : public Named { public: NameSpace(const std::string &module, const py::object &obj, const py::object &module_obj = py::object()) : Named(module), module_(module), obj_(obj), module_obj_(module_obj) {} ~NameSpace() override = default; MS_DECLARE_PARENT(NameSpace, Named); py::object obj() { return obj_; } py::object module_obj() { return module_obj_; } std::string module() { return module_; } abstract::AbstractBasePtr ToAbstract() override { return std::make_shared(shared_from_base(), std::make_shared()); } private: // namespace of the module std::string module_; // namespace object py::object obj_; // module object py::object module_obj_; }; using NameSpacePtr = std::shared_ptr; // Symbol in NameSpace or Class which shall be resolved. class Symbol : public Named { public: explicit Symbol(const std::string &symbol) : Named(symbol), symbol_(symbol) {} Symbol(const std::string &symbol, const std::string &name) : Named(name), symbol_(symbol) {} ~Symbol() override = default; MS_DECLARE_PARENT(Symbol, Named); std::string symbol() { return symbol_; } abstract::AbstractBasePtr ToAbstract() override { return std::make_shared(shared_from_base(), std::make_shared()); } private: std::string symbol_; }; using SymbolPtr = std::shared_ptr; class Script : public Named { public: explicit Script(const std::string &script) : Named(script), script_(script) {} Script(const std::string &script, const std::string &name) : Named(name), script_(script) {} ~Script() override = default; MS_DECLARE_PARENT(Script, Named); std::string script() { return script_; } abstract::AbstractBasePtr ToAbstract() override { return std::make_shared(shared_from_base