Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: src/scopes.cc

Issue 16549002: Add type field to AST expression nodes (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/scopes.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 ASSERT(p->value != NULL); 97 ASSERT(p->value != NULL);
98 return reinterpret_cast<Variable*>(p->value); 98 return reinterpret_cast<Variable*>(p->value);
99 } 99 }
100 return NULL; 100 return NULL;
101 } 101 }
102 102
103 103
104 // ---------------------------------------------------------------------------- 104 // ----------------------------------------------------------------------------
105 // Implementation of Scope 105 // Implementation of Scope
106 106
107 Scope::Scope(Scope* outer_scope, ScopeType type, Zone* zone) 107 Scope::Scope(Scope* outer_scope, ScopeType scope_type, Zone* zone)
108 : isolate_(zone->isolate()), 108 : isolate_(zone->isolate()),
109 inner_scopes_(4, zone), 109 inner_scopes_(4, zone),
110 variables_(zone), 110 variables_(zone),
111 internals_(4, zone), 111 internals_(4, zone),
112 temps_(4, zone), 112 temps_(4, zone),
113 params_(4, zone), 113 params_(4, zone),
114 unresolved_(16, zone), 114 unresolved_(16, zone),
115 decls_(4, zone), 115 decls_(4, zone),
116 interface_(FLAG_harmony_modules && 116 interface_(FLAG_harmony_modules &&
117 (type == MODULE_SCOPE || type == GLOBAL_SCOPE) 117 (scope_type == MODULE_SCOPE || scope_type == GLOBAL_SCOPE)
118 ? Interface::NewModule(zone) : NULL), 118 ? Interface::NewModule(zone) : NULL),
119 already_resolved_(false), 119 already_resolved_(false),
120 zone_(zone) { 120 zone_(zone) {
121 SetDefaults(type, outer_scope, Handle<ScopeInfo>::null()); 121 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null());
122 // The outermost scope must be a global scope. 122 // The outermost scope must be a global scope.
123 ASSERT(type == GLOBAL_SCOPE || outer_scope != NULL); 123 ASSERT(scope_type == GLOBAL_SCOPE || outer_scope != NULL);
124 ASSERT(!HasIllegalRedeclaration()); 124 ASSERT(!HasIllegalRedeclaration());
125 } 125 }
126 126
127 127
128 Scope::Scope(Scope* inner_scope, 128 Scope::Scope(Scope* inner_scope,
129 ScopeType type, 129 ScopeType scope_type,
130 Handle<ScopeInfo> scope_info, 130 Handle<ScopeInfo> scope_info,
131 Zone* zone) 131 Zone* zone)
132 : isolate_(Isolate::Current()), 132 : isolate_(Isolate::Current()),
133 inner_scopes_(4, zone), 133 inner_scopes_(4, zone),
134 variables_(zone), 134 variables_(zone),
135 internals_(4, zone), 135 internals_(4, zone),
136 temps_(4, zone), 136 temps_(4, zone),
137 params_(4, zone), 137 params_(4, zone),
138 unresolved_(16, zone), 138 unresolved_(16, zone),
139 decls_(4, zone), 139 decls_(4, zone),
140 interface_(NULL), 140 interface_(NULL),
141 already_resolved_(true), 141 already_resolved_(true),
142 zone_(zone) { 142 zone_(zone) {
143 SetDefaults(type, NULL, scope_info); 143 SetDefaults(scope_type, NULL, scope_info);
144 if (!scope_info.is_null()) { 144 if (!scope_info.is_null()) {
145 num_heap_slots_ = scope_info_->ContextLength(); 145 num_heap_slots_ = scope_info_->ContextLength();
146 } 146 }
147 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. 147 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
148 num_heap_slots_ = Max(num_heap_slots_, 148 num_heap_slots_ = Max(num_heap_slots_,
149 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); 149 static_cast<int>(Context::MIN_CONTEXT_SLOTS));
150 AddInnerScope(inner_scope); 150 AddInnerScope(inner_scope);
151 } 151 }
152 152
153 153
(...skipping 16 matching lines...) Expand all
170 Variable* variable = variables_.Declare(this, 170 Variable* variable = variables_.Declare(this,
171 catch_variable_name, 171 catch_variable_name,
172 VAR, 172 VAR,
173 true, // Valid left-hand side. 173 true, // Valid left-hand side.
174 Variable::NORMAL, 174 Variable::NORMAL,
175 kCreatedInitialized); 175 kCreatedInitialized);
176 AllocateHeapSlot(variable); 176 AllocateHeapSlot(variable);
177 } 177 }
178 178
179 179
180 void Scope::SetDefaults(ScopeType type, 180 void Scope::SetDefaults(ScopeType scope_type,
181 Scope* outer_scope, 181 Scope* outer_scope,
182 Handle<ScopeInfo> scope_info) { 182 Handle<ScopeInfo> scope_info) {
183 outer_scope_ = outer_scope; 183 outer_scope_ = outer_scope;
184 type_ = type; 184 scope_type_ = scope_type;
185 scope_name_ = isolate_->factory()->empty_string(); 185 scope_name_ = isolate_->factory()->empty_string();
186 dynamics_ = NULL; 186 dynamics_ = NULL;
187 receiver_ = NULL; 187 receiver_ = NULL;
188 function_ = NULL; 188 function_ = NULL;
189 arguments_ = NULL; 189 arguments_ = NULL;
190 illegal_redecl_ = NULL; 190 illegal_redecl_ = NULL;
191 scope_inside_with_ = false; 191 scope_inside_with_ = false;
192 scope_contains_with_ = false; 192 scope_contains_with_ = false;
193 scope_calls_eval_ = false; 193 scope_calls_eval_ = false;
194 // Inherit the strict mode from the parent scope. 194 // Inherit the strict mode from the parent scope.
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 ASSERT(beg_pos >= 0 && end_pos >= 0); 773 ASSERT(beg_pos >= 0 && end_pos >= 0);
774 if (beg_pos <= position && position < end_pos) { 774 if (beg_pos <= position && position < end_pos) {
775 scope->GetNestedScopeChain(chain, position); 775 scope->GetNestedScopeChain(chain, position);
776 return; 776 return;
777 } 777 }
778 } 778 }
779 } 779 }
780 780
781 781
782 #ifdef DEBUG 782 #ifdef DEBUG
783 static const char* Header(ScopeType type) { 783 static const char* Header(ScopeType scope_type) {
784 switch (type) { 784 switch (scope_type) {
785 case EVAL_SCOPE: return "eval"; 785 case EVAL_SCOPE: return "eval";
786 case FUNCTION_SCOPE: return "function"; 786 case FUNCTION_SCOPE: return "function";
787 case MODULE_SCOPE: return "module"; 787 case MODULE_SCOPE: return "module";
788 case GLOBAL_SCOPE: return "global"; 788 case GLOBAL_SCOPE: return "global";
789 case CATCH_SCOPE: return "catch"; 789 case CATCH_SCOPE: return "catch";
790 case BLOCK_SCOPE: return "block"; 790 case BLOCK_SCOPE: return "block";
791 case WITH_SCOPE: return "with"; 791 case WITH_SCOPE: return "with";
792 } 792 }
793 UNREACHABLE(); 793 UNREACHABLE();
794 return NULL; 794 return NULL;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 PrintVar(indent, var); 848 PrintVar(indent, var);
849 } 849 }
850 } 850 }
851 851
852 852
853 void Scope::Print(int n) { 853 void Scope::Print(int n) {
854 int n0 = (n > 0 ? n : 0); 854 int n0 = (n > 0 ? n : 0);
855 int n1 = n0 + 2; // indentation 855 int n1 = n0 + 2; // indentation
856 856
857 // Print header. 857 // Print header.
858 Indent(n0, Header(type_)); 858 Indent(n0, Header(scope_type_));
859 if (scope_name_->length() > 0) { 859 if (scope_name_->length() > 0) {
860 PrintF(" "); 860 PrintF(" ");
861 PrintName(scope_name_); 861 PrintName(scope_name_);
862 } 862 }
863 863
864 // Print parameters, if any. 864 // Print parameters, if any.
865 if (is_function_scope()) { 865 if (is_function_scope()) {
866 PrintF(" ("); 866 PrintF(" (");
867 for (int i = 0; i < params_.length(); i++) { 867 for (int i = 0; i < params_.length(); i++) {
868 if (i > 0) PrintF(", "); 868 if (i > 0) PrintF(", ");
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 } 1393 }
1394 1394
1395 1395
1396 int Scope::ContextLocalCount() const { 1396 int Scope::ContextLocalCount() const {
1397 if (num_heap_slots() == 0) return 0; 1397 if (num_heap_slots() == 0) return 0;
1398 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1398 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1399 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1399 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1400 } 1400 }
1401 1401
1402 } } // namespace v8::internal 1402 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698