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

Side by Side Diff: src/scopes.h

Issue 7860035: Merge bleeding edge up to 9192 into the GC branch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Created 9 years, 3 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/scopeinfo.cc ('k') | src/scopes.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 static bool Analyze(CompilationInfo* info); 105 static bool Analyze(CompilationInfo* info);
106 106
107 static Scope* DeserializeScopeChain(CompilationInfo* info, 107 static Scope* DeserializeScopeChain(CompilationInfo* info,
108 Scope* innermost_scope); 108 Scope* innermost_scope);
109 109
110 // The scope name is only used for printing/debugging. 110 // The scope name is only used for printing/debugging.
111 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } 111 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; }
112 112
113 void Initialize(bool inside_with); 113 void Initialize(bool inside_with);
114 114
115 // Checks if the block scope is redundant, i.e. it does not contain any
116 // block scoped declarations. In that case it is removed from the scope
117 // tree and its children are reparented.
118 Scope* FinalizeBlockScope();
119
115 // --------------------------------------------------------------------------- 120 // ---------------------------------------------------------------------------
116 // Declarations 121 // Declarations
117 122
118 // Lookup a variable in this scope. Returns the variable or NULL if not found. 123 // Lookup a variable in this scope. Returns the variable or NULL if not found.
119 Variable* LocalLookup(Handle<String> name); 124 Variable* LocalLookup(Handle<String> name);
120 125
121 // Lookup a variable in this scope or outer scopes. 126 // Lookup a variable in this scope or outer scopes.
122 // Returns the variable or NULL if not found. 127 // Returns the variable or NULL if not found.
123 Variable* Lookup(Handle<String> name); 128 Variable* Lookup(Handle<String> name);
124 129
125 // Declare the function variable for a function literal. This variable 130 // Declare the function variable for a function literal. This variable
126 // is in an intermediate scope between this function scope and the the 131 // is in an intermediate scope between this function scope and the the
127 // outer scope. Only possible for function scopes; at most one variable. 132 // outer scope. Only possible for function scopes; at most one variable.
128 Variable* DeclareFunctionVar(Handle<String> name); 133 Variable* DeclareFunctionVar(Handle<String> name);
129 134
130 // Declare a parameter in this scope. When there are duplicated 135 // Declare a parameter in this scope. When there are duplicated
131 // parameters the rightmost one 'wins'. However, the implementation 136 // parameters the rightmost one 'wins'. However, the implementation
132 // expects all parameters to be declared and from left to right. 137 // expects all parameters to be declared and from left to right.
133 void DeclareParameter(Handle<String> name); 138 void DeclareParameter(Handle<String> name, Variable::Mode mode);
134 139
135 // Declare a local variable in this scope. If the variable has been 140 // Declare a local variable in this scope. If the variable has been
136 // declared before, the previously declared variable is returned. 141 // declared before, the previously declared variable is returned.
137 Variable* DeclareLocal(Handle<String> name, Variable::Mode mode); 142 Variable* DeclareLocal(Handle<String> name, Variable::Mode mode);
138 143
139 // Declare an implicit global variable in this scope which must be a 144 // Declare an implicit global variable in this scope which must be a
140 // global scope. The variable was introduced (possibly from an inner 145 // global scope. The variable was introduced (possibly from an inner
141 // scope) by a reference to an unresolved variable with no intervening 146 // scope) by a reference to an unresolved variable with no intervening
142 // with statements or eval calls. 147 // with statements or eval calls.
143 Variable* DeclareGlobal(Handle<String> name); 148 Variable* DeclareGlobal(Handle<String> name);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // the additional requests will be silently ignored. 180 // the additional requests will be silently ignored.
176 void SetIllegalRedeclaration(Expression* expression); 181 void SetIllegalRedeclaration(Expression* expression);
177 182
178 // Visit the illegal redeclaration expression. Do not call if the 183 // Visit the illegal redeclaration expression. Do not call if the
179 // scope doesn't have an illegal redeclaration node. 184 // scope doesn't have an illegal redeclaration node.
180 void VisitIllegalRedeclaration(AstVisitor* visitor); 185 void VisitIllegalRedeclaration(AstVisitor* visitor);
181 186
182 // Check if the scope has (at least) one illegal redeclaration. 187 // Check if the scope has (at least) one illegal redeclaration.
183 bool HasIllegalRedeclaration() const { return illegal_redecl_ != NULL; } 188 bool HasIllegalRedeclaration() const { return illegal_redecl_ != NULL; }
184 189
190 // For harmony block scoping mode: Check if the scope has conflicting var
191 // declarations, i.e. a var declaration that has been hoisted from a nested
192 // scope over a let binding of the same name.
193 Declaration* CheckConflictingVarDeclarations();
185 194
186 // --------------------------------------------------------------------------- 195 // ---------------------------------------------------------------------------
187 // Scope-specific info. 196 // Scope-specific info.
188 197
189 // Inform the scope that the corresponding code contains a with statement. 198 // Inform the scope that the corresponding code contains a with statement.
190 void RecordWithStatement() { scope_contains_with_ = true; } 199 void RecordWithStatement() { scope_contains_with_ = true; }
191 200
192 // Inform the scope that the corresponding code contains an eval call. 201 // Inform the scope that the corresponding code contains an eval call.
193 void RecordEvalCall() { scope_calls_eval_ = true; } 202 void RecordEvalCall() { scope_calls_eval_ = true; }
194 203
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 237
229 // --------------------------------------------------------------------------- 238 // ---------------------------------------------------------------------------
230 // Accessors. 239 // Accessors.
231 240
232 // The variable corresponding the 'this' value. 241 // The variable corresponding the 'this' value.
233 Variable* receiver() { return receiver_; } 242 Variable* receiver() { return receiver_; }
234 243
235 // The variable holding the function literal for named function 244 // The variable holding the function literal for named function
236 // literals, or NULL. 245 // literals, or NULL.
237 // Only valid for function scopes. 246 // Only valid for function scopes.
238 Variable* function() const { 247 VariableProxy* function() const {
239 ASSERT(is_function_scope()); 248 ASSERT(is_function_scope());
240 return function_; 249 return function_;
241 } 250 }
242 251
243 // Parameters. The left-most parameter has index 0. 252 // Parameters. The left-most parameter has index 0.
244 // Only valid for function scopes. 253 // Only valid for function scopes.
245 Variable* parameter(int index) const { 254 Variable* parameter(int index) const {
246 ASSERT(is_function_scope()); 255 ASSERT(is_function_scope());
247 return params_[index]; 256 return params_[index];
248 } 257 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 ZoneList<Variable*> params_; 356 ZoneList<Variable*> params_;
348 // Variables that must be looked up dynamically. 357 // Variables that must be looked up dynamically.
349 DynamicScopePart* dynamics_; 358 DynamicScopePart* dynamics_;
350 // Unresolved variables referred to from this scope. 359 // Unresolved variables referred to from this scope.
351 ZoneList<VariableProxy*> unresolved_; 360 ZoneList<VariableProxy*> unresolved_;
352 // Declarations. 361 // Declarations.
353 ZoneList<Declaration*> decls_; 362 ZoneList<Declaration*> decls_;
354 // Convenience variable. 363 // Convenience variable.
355 Variable* receiver_; 364 Variable* receiver_;
356 // Function variable, if any; function scopes only. 365 // Function variable, if any; function scopes only.
357 Variable* function_; 366 VariableProxy* function_;
358 // Convenience variable; function scopes only. 367 // Convenience variable; function scopes only.
359 Variable* arguments_; 368 Variable* arguments_;
360 369
361 // Illegal redeclaration. 370 // Illegal redeclaration.
362 Expression* illegal_redecl_; 371 Expression* illegal_redecl_;
363 372
364 // Scope-specific information computed during parsing. 373 // Scope-specific information computed during parsing.
365 // 374 //
366 // This scope is inside a 'with' of some outer scope. 375 // This scope is inside a 'with' of some outer scope.
367 bool scope_inside_with_; 376 bool scope_inside_with_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 void AllocateNonParameterLocals(); 437 void AllocateNonParameterLocals();
429 void AllocateVariablesRecursively(); 438 void AllocateVariablesRecursively();
430 439
431 private: 440 private:
432 // Construct a function or block scope based on the scope info. 441 // Construct a function or block scope based on the scope info.
433 Scope(Scope* inner_scope, Type type, Handle<SerializedScopeInfo> scope_info); 442 Scope(Scope* inner_scope, Type type, Handle<SerializedScopeInfo> scope_info);
434 443
435 // Construct a catch scope with a binding for the name. 444 // Construct a catch scope with a binding for the name.
436 Scope(Scope* inner_scope, Handle<String> catch_variable_name); 445 Scope(Scope* inner_scope, Handle<String> catch_variable_name);
437 446
438 inline Slot* NewSlot(Variable* var, Slot::Type type, int index) {
439 return new(isolate_->zone()) Slot(isolate_, var, type, index);
440 }
441
442 void AddInnerScope(Scope* inner_scope) { 447 void AddInnerScope(Scope* inner_scope) {
443 if (inner_scope != NULL) { 448 if (inner_scope != NULL) {
444 inner_scopes_.Add(inner_scope); 449 inner_scopes_.Add(inner_scope);
445 inner_scope->outer_scope_ = this; 450 inner_scope->outer_scope_ = this;
446 } 451 }
447 } 452 }
448 453
449 void SetDefaults(Type type, 454 void SetDefaults(Type type,
450 Scope* outer_scope, 455 Scope* outer_scope,
451 Handle<SerializedScopeInfo> scope_info); 456 Handle<SerializedScopeInfo> scope_info);
452 }; 457 };
453 458
454 } } // namespace v8::internal 459 } } // namespace v8::internal
455 460
456 #endif // V8_SCOPES_H_ 461 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698