1 /** 2 * Copyright 2019 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "ir/scope.h" 18 namespace mindspore { 19 const ScopePtr kDefaultScope = std::make_shared<Scope>("Default"); 20 EnterScope(const ScopePtr & scope)21void ScopeManager::EnterScope(const ScopePtr &scope) { 22 if (scope != kDefaultScope) { 23 scope_stack_.push(scope); 24 } 25 } 26 LeaveScope(const ScopePtr & scope)27void ScopeManager::LeaveScope(const ScopePtr &scope) noexcept { 28 if (scope != kDefaultScope && !scope_stack_.empty()) { 29 scope_stack_.pop(); 30 } 31 } GetCurrentScope()32ScopePtr ScopeManager::GetCurrentScope() { 33 // if the scope stack is empty, return the default scope 34 if (scope_stack_.empty()) { 35 return kDefaultScope; 36 } 37 return scope_stack_.top(); 38 } ClearScope()39void ScopeManager::ClearScope() { 40 while (!scope_stack_.empty()) { 41 scope_stack_.pop(); 42 } 43 } 44 } // namespace mindspore 45