• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <fstream>
6 #include <iostream>
7 #include <string>
8 
9 #include "src/torque/global-context.h"
10 
11 #include "src/torque/scope.h"
12 
13 namespace v8 {
14 namespace internal {
15 namespace torque {
16 
Scope(ScopeChain & scope_chain)17 Scope::Scope(ScopeChain& scope_chain)
18     : scope_chain_(scope_chain),
19       scope_number_(scope_chain_.GetNextScopeNumber()),
20       private_label_number_(0) {}
21 
NewScope()22 Scope* ScopeChain::NewScope() {
23   Scope* new_scope = new Scope(*this);
24   scopes_.emplace_back(std::unique_ptr<Scope>(new_scope));
25   return new_scope;
26 }
27 
AddLiveVariables(std::set<const Variable * > & set)28 void Scope::AddLiveVariables(std::set<const Variable*>& set) {
29   for (auto& current : lookup_) {
30     if (current.second->IsVariable()) {
31       set.insert(Variable::cast(current.second));
32     }
33   }
34 }
35 
Print()36 void Scope::Print() {
37   std::cout << "scope #" << std::to_string(scope_number_) << "\n";
38   for (auto& i : lookup_) {
39     std::cout << i.first << ": " << i.second << "\n";
40   }
41 }
42 
Activator(Scope * scope)43 Scope::Activator::Activator(Scope* scope) : scope_(scope) {
44   scope->GetScopeChain().PushScope(scope);
45 }
46 
~Activator()47 Scope::Activator::~Activator() { scope_->GetScopeChain().PopScope(); }
48 
49 }  // namespace torque
50 }  // namespace internal
51 }  // namespace v8
52