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

Side by Side Diff: src/scopes.h

Issue 7060010: Merge bleeding edge into the GC branch up to 7948. The asserts (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 7 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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 public: 88 public:
89 // --------------------------------------------------------------------------- 89 // ---------------------------------------------------------------------------
90 // Construction 90 // Construction
91 91
92 enum Type { 92 enum Type {
93 EVAL_SCOPE, // the top-level scope for an 'eval' source 93 EVAL_SCOPE, // the top-level scope for an 'eval' source
94 FUNCTION_SCOPE, // the top-level scope for a function 94 FUNCTION_SCOPE, // the top-level scope for a function
95 GLOBAL_SCOPE // the top-level scope for a program or a top-level eval 95 GLOBAL_SCOPE // the top-level scope for a program or a top-level eval
96 }; 96 };
97 97
98 enum LocalType {
99 PARAMETER,
100 VAR_OR_CONST
101 };
102
98 Scope(Scope* outer_scope, Type type); 103 Scope(Scope* outer_scope, Type type);
99 104
100 virtual ~Scope() { } 105 virtual ~Scope() { }
101 106
102 // Compute top scope and allocate variables. For lazy compilation the top 107 // Compute top scope and allocate variables. For lazy compilation the top
103 // scope only contains the single lazily compiled function, so this 108 // scope only contains the single lazily compiled function, so this
104 // doesn't re-allocate variables repeatedly. 109 // doesn't re-allocate variables repeatedly.
105 static bool Analyze(CompilationInfo* info); 110 static bool Analyze(CompilationInfo* info);
106 111
107 static Scope* DeserializeScopeChain(CompilationInfo* info, 112 static Scope* DeserializeScopeChain(CompilationInfo* info,
(...skipping 19 matching lines...) Expand all
127 // Returns the variable or NULL if not found. 132 // Returns the variable or NULL if not found.
128 virtual Variable* Lookup(Handle<String> name); 133 virtual Variable* Lookup(Handle<String> name);
129 134
130 // Declare the function variable for a function literal. This variable 135 // Declare the function variable for a function literal. This variable
131 // is in an intermediate scope between this function scope and the the 136 // is in an intermediate scope between this function scope and the the
132 // outer scope. Only possible for function scopes; at most one variable. 137 // outer scope. Only possible for function scopes; at most one variable.
133 Variable* DeclareFunctionVar(Handle<String> name); 138 Variable* DeclareFunctionVar(Handle<String> name);
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 virtual Variable* DeclareLocal(Handle<String> name, Variable::Mode mode); 142 virtual Variable* DeclareLocal(Handle<String> name,
143 Variable::Mode mode,
144 LocalType type);
138 145
139 // Declare an implicit global variable in this scope which must be a 146 // Declare an implicit global variable in this scope which must be a
140 // global scope. The variable was introduced (possibly from an inner 147 // global scope. The variable was introduced (possibly from an inner
141 // scope) by a reference to an unresolved variable with no intervening 148 // scope) by a reference to an unresolved variable with no intervening
142 // with statements or eval calls. 149 // with statements or eval calls.
143 Variable* DeclareGlobal(Handle<String> name); 150 Variable* DeclareGlobal(Handle<String> name);
144 151
145 // Add a parameter to the parameter list. The parameter must have been 152 // Add a parameter to the parameter list. The parameter must have been
146 // declared via Declare. The same parameter may occur more than once in 153 // declared via Declare. The same parameter may occur more than once in
147 // the parameter list; they must be added in source order, from left to 154 // the parameter list; they must be added in source order, from left to
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } 218 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; }
212 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } 219 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; }
213 bool is_strict_mode() const { return strict_mode_; } 220 bool is_strict_mode() const { return strict_mode_; }
214 bool is_strict_mode_eval_scope() const { 221 bool is_strict_mode_eval_scope() const {
215 return is_eval_scope() && is_strict_mode(); 222 return is_eval_scope() && is_strict_mode();
216 } 223 }
217 224
218 // Information about which scopes calls eval. 225 // Information about which scopes calls eval.
219 bool calls_eval() const { return scope_calls_eval_; } 226 bool calls_eval() const { return scope_calls_eval_; }
220 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; } 227 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; }
228 bool outer_scope_calls_non_strict_eval() const {
229 return outer_scope_calls_non_strict_eval_;
230 }
221 231
222 // Is this scope inside a with statement. 232 // Is this scope inside a with statement.
223 bool inside_with() const { return scope_inside_with_; } 233 bool inside_with() const { return scope_inside_with_; }
224 // Does this scope contain a with statement. 234 // Does this scope contain a with statement.
225 bool contains_with() const { return scope_contains_with_; } 235 bool contains_with() const { return scope_contains_with_; }
226 236
227 // The scope immediately surrounding this scope, or NULL. 237 // The scope immediately surrounding this scope, or NULL.
228 Scope* outer_scope() const { return outer_scope_; } 238 Scope* outer_scope() const { return outer_scope_; }
229 239
230 // --------------------------------------------------------------------------- 240 // ---------------------------------------------------------------------------
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // Resolve and fill in the allocation information for all variables 288 // Resolve and fill in the allocation information for all variables
279 // in this scopes. Must be called *after* all scopes have been 289 // in this scopes. Must be called *after* all scopes have been
280 // processed (parsed) to ensure that unresolved variables can be 290 // processed (parsed) to ensure that unresolved variables can be
281 // resolved properly. 291 // resolved properly.
282 // 292 //
283 // In the case of code compiled and run using 'eval', the context 293 // In the case of code compiled and run using 'eval', the context
284 // parameter is the context in which eval was called. In all other 294 // parameter is the context in which eval was called. In all other
285 // cases the context parameter is an empty handle. 295 // cases the context parameter is an empty handle.
286 void AllocateVariables(Handle<Context> context); 296 void AllocateVariables(Handle<Context> context);
287 297
298 // Current number of var or const locals.
299 int num_var_or_const() { return num_var_or_const_; }
300
288 // Result of variable allocation. 301 // Result of variable allocation.
289 int num_stack_slots() const { return num_stack_slots_; } 302 int num_stack_slots() const { return num_stack_slots_; }
290 int num_heap_slots() const { return num_heap_slots_; } 303 int num_heap_slots() const { return num_heap_slots_; }
291 304
292 // Make sure this scope and all outer scopes are eagerly compiled. 305 // Make sure this scope and all outer scopes are eagerly compiled.
293 void ForceEagerCompilation() { force_eager_compilation_ = true; } 306 void ForceEagerCompilation() { force_eager_compilation_ = true; }
294 307
295 // Determine if we can use lazy compilation for this scope. 308 // Determine if we can use lazy compilation for this scope.
296 bool AllowsLazyCompilation() const; 309 bool AllowsLazyCompilation() const;
297 310
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 Expression* illegal_redecl_; 378 Expression* illegal_redecl_;
366 379
367 // Scope-specific information. 380 // Scope-specific information.
368 bool scope_inside_with_; // this scope is inside a 'with' of some outer scope 381 bool scope_inside_with_; // this scope is inside a 'with' of some outer scope
369 bool scope_contains_with_; // this scope contains a 'with' statement 382 bool scope_contains_with_; // this scope contains a 'with' statement
370 bool scope_calls_eval_; // this scope contains an 'eval' call 383 bool scope_calls_eval_; // this scope contains an 'eval' call
371 bool strict_mode_; // this scope is a strict mode scope 384 bool strict_mode_; // this scope is a strict mode scope
372 385
373 // Computed via PropagateScopeInfo. 386 // Computed via PropagateScopeInfo.
374 bool outer_scope_calls_eval_; 387 bool outer_scope_calls_eval_;
388 bool outer_scope_calls_non_strict_eval_;
375 bool inner_scope_calls_eval_; 389 bool inner_scope_calls_eval_;
376 bool outer_scope_is_eval_scope_; 390 bool outer_scope_is_eval_scope_;
377 bool force_eager_compilation_; 391 bool force_eager_compilation_;
378 392
393 // Computed as variables are declared.
394 int num_var_or_const_;
395
379 // Computed via AllocateVariables; function scopes only. 396 // Computed via AllocateVariables; function scopes only.
380 int num_stack_slots_; 397 int num_stack_slots_;
381 int num_heap_slots_; 398 int num_heap_slots_;
382 399
383 // Serialized scopes support. 400 // Serialized scopes support.
384 Handle<SerializedScopeInfo> scope_info_; 401 Handle<SerializedScopeInfo> scope_info_;
385 bool resolved() { return !scope_info_.is_null(); } 402 bool resolved() { return !scope_info_.is_null(); }
386 403
387 // Create a non-local variable with a given name. 404 // Create a non-local variable with a given name.
388 // These variables are looked up dynamically at runtime. 405 // These variables are looked up dynamically at runtime.
389 Variable* NonLocal(Handle<String> name, Variable::Mode mode); 406 Variable* NonLocal(Handle<String> name, Variable::Mode mode);
390 407
391 // Variable resolution. 408 // Variable resolution.
392 Variable* LookupRecursive(Handle<String> name, 409 Variable* LookupRecursive(Handle<String> name,
393 bool inner_lookup, 410 bool inner_lookup,
394 Variable** invalidated_local); 411 Variable** invalidated_local);
395 void ResolveVariable(Scope* global_scope, 412 void ResolveVariable(Scope* global_scope,
396 Handle<Context> context, 413 Handle<Context> context,
397 VariableProxy* proxy); 414 VariableProxy* proxy);
398 void ResolveVariablesRecursively(Scope* global_scope, 415 void ResolveVariablesRecursively(Scope* global_scope,
399 Handle<Context> context); 416 Handle<Context> context);
400 417
401 // Scope analysis. 418 // Scope analysis.
402 bool PropagateScopeInfo(bool outer_scope_calls_eval, 419 bool PropagateScopeInfo(bool outer_scope_calls_eval,
420 bool outer_scope_calls_non_strict_eval,
403 bool outer_scope_is_eval_scope); 421 bool outer_scope_is_eval_scope);
404 bool HasTrivialContext() const; 422 bool HasTrivialContext() const;
405 423
406 // Predicates. 424 // Predicates.
407 bool MustAllocate(Variable* var); 425 bool MustAllocate(Variable* var);
408 bool MustAllocateInContext(Variable* var); 426 bool MustAllocateInContext(Variable* var);
409 bool HasArgumentsParameter(); 427 bool HasArgumentsParameter();
410 428
411 // Variable allocation. 429 // Variable allocation.
412 void AllocateStackSlot(Variable* var); 430 void AllocateStackSlot(Variable* var);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 int nesting_level_; 498 int nesting_level_;
481 // Nesting level of outermost scope that is contained in a with statement, 499 // Nesting level of outermost scope that is contained in a with statement,
482 // or kNotInsideWith if there are no with's around the current scope. 500 // or kNotInsideWith if there are no with's around the current scope.
483 int inside_with_level_; 501 int inside_with_level_;
484 }; 502 };
485 503
486 504
487 } } // namespace v8::internal 505 } } // namespace v8::internal
488 506
489 #endif // V8_SCOPES_H_ 507 #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