[flang] Replace scope stack with current scope
authorTim Keith <tkeith@nvidia.com>
Fri, 10 Aug 2018 00:12:31 +0000 (17:12 -0700)
committerTim Keith <tkeith@nvidia.com>
Fri, 10 Aug 2018 00:12:31 +0000 (17:12 -0700)
We don't need to manage a stack of scopes: each scope has a reference to
its parent, so popping the scope stack is equivalent to setting the
new current scope to the parent of the old current scope.

Original-commit: flang-compiler/f18@022aa7a7f9d09ee96db6ec9a025afb6bcf99cc55
Reviewed-on: https://github.com/flang-compiler/f18/pull/167
Tree-same-pre-rewrite: false

flang/lib/semantics/resolve-names.cc

index 530dcd8..a10e5a8 100644 (file)
@@ -293,7 +293,7 @@ private:
 class ScopeHandler : public virtual ImplicitRulesVisitor {
 public:
   void set_rootScope(Scope &scope) { PushScope(scope); }
-  Scope &CurrScope() { return *scopes_.top(); }
+  Scope &CurrScope() { return *currScope_; }
   // Return the enclosing scope not corresponding to a derived type:
   Scope &CurrNonTypeScope();
 
@@ -375,8 +375,7 @@ protected:
   std::optional<const DeclTypeSpec> GetImplicitType(Symbol &);
 
 private:
-  // Stack of containing scopes; memory referenced is owned by parent scopes
-  std::stack<Scope *, std::list<Scope *>> scopes_;
+  Scope *currScope_{nullptr};
 };
 
 class ModuleVisitor : public virtual ScopeHandler {
@@ -1154,11 +1153,11 @@ Scope &ScopeHandler::PushScope(Scope::Kind kind, Symbol *symbol) {
   return scope;
 }
 void ScopeHandler::PushScope(Scope &scope) {
-  scopes_.push(&scope);
+  currScope_ = &scope;
   ImplicitRulesVisitor::PushScope();
 }
 void ScopeHandler::PopScope() {
-  scopes_.pop();
+  currScope_ = &currScope_->parent();
   ImplicitRulesVisitor::PopScope();
 }