You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

scope.cc 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #include "ir/scope.h"
  17. namespace mindspore {
  18. const ScopePtr kDefaultScope = std::make_shared<Scope>("Default");
  19. void ScopeManager::EnterScope(const ScopePtr &scope) {
  20. if (scope != kDefaultScope) {
  21. scope_stack_.push(scope);
  22. }
  23. }
  24. void ScopeManager::LeaveScope(const ScopePtr &scope) noexcept {
  25. if (scope != kDefaultScope) {
  26. scope_stack_.pop();
  27. }
  28. }
  29. ScopePtr ScopeManager::GetCurrentScope() {
  30. // if the scope stack is empty, return the default scope
  31. if (scope_stack_.empty()) {
  32. return kDefaultScope;
  33. }
  34. return scope_stack_.top();
  35. }
  36. void ScopeManager::ClearScope() {
  37. while (!scope_stack_.empty()) {
  38. scope_stack_.pop();
  39. }
  40. }
  41. } // namespace mindspore