Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 class Scope: public ZoneObject { | 87 class Scope: public ZoneObject { |
| 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 CATCH_SCOPE, // The scope introduced by catch. | 96 CATCH_SCOPE, // The scope introduced by catch. |
| 97 BLOCK_SCOPE // The scope introduced by a new block. | 97 BLOCK_SCOPE, // The scope introduced by a new block. |
| 98 WITH_SCOPE // The scope introduced by with. | |
| 98 }; | 99 }; |
| 99 | 100 |
| 100 Scope(Scope* outer_scope, Type type); | 101 Scope(Scope* outer_scope, Type type); |
| 101 | 102 |
| 102 // Compute top scope and allocate variables. For lazy compilation the top | 103 // Compute top scope and allocate variables. For lazy compilation the top |
| 103 // scope only contains the single lazily compiled function, so this | 104 // scope only contains the single lazily compiled function, so this |
| 104 // doesn't re-allocate variables repeatedly. | 105 // doesn't re-allocate variables repeatedly. |
| 105 static bool Analyze(CompilationInfo* info); | 106 static bool Analyze(CompilationInfo* info); |
| 106 | 107 |
| 107 static Scope* DeserializeScopeChain(CompilationInfo* info, | 108 static Scope* DeserializeScopeChain(CompilationInfo* info, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 | 204 |
| 204 // Enable strict mode for the scope (unless disabled by a global flag). | 205 // Enable strict mode for the scope (unless disabled by a global flag). |
| 205 void EnableStrictMode() { | 206 void EnableStrictMode() { |
| 206 strict_mode_ = FLAG_strict_mode; | 207 strict_mode_ = FLAG_strict_mode; |
| 207 } | 208 } |
| 208 | 209 |
| 209 // --------------------------------------------------------------------------- | 210 // --------------------------------------------------------------------------- |
| 210 // Predicates. | 211 // Predicates. |
| 211 | 212 |
| 212 // Specific scope types. | 213 // Specific scope types. |
| 214 Type type() const { return type_; } | |
|
Kevin Millikin (Chromium)
2011/09/15 09:38:13
Don't introduce this until you have a caller for i
Steven
2011/09/15 19:54:06
Will remove it for for now. But I will need it lat
| |
| 213 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } | 215 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } |
| 214 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } | 216 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } |
| 215 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } | 217 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } |
| 216 bool is_catch_scope() const { return type_ == CATCH_SCOPE; } | 218 bool is_catch_scope() const { return type_ == CATCH_SCOPE; } |
| 217 bool is_block_scope() const { return type_ == BLOCK_SCOPE; } | 219 bool is_block_scope() const { return type_ == BLOCK_SCOPE; } |
| 220 bool is_with_scope() const { return type_ == WITH_SCOPE; } | |
| 221 bool is_declaration_scope() const { | |
| 222 return is_eval_scope() || is_function_scope() || is_global_scope(); | |
| 223 } | |
| 218 bool is_strict_mode() const { return strict_mode_; } | 224 bool is_strict_mode() const { return strict_mode_; } |
| 219 bool is_strict_mode_eval_scope() const { | 225 bool is_strict_mode_eval_scope() const { |
| 220 return is_eval_scope() && is_strict_mode(); | 226 return is_eval_scope() && is_strict_mode(); |
| 221 } | 227 } |
| 222 | 228 |
| 223 // Information about which scopes calls eval. | 229 // Information about which scopes calls eval. |
| 224 bool calls_eval() const { return scope_calls_eval_; } | 230 bool calls_eval() const { return scope_calls_eval_; } |
| 225 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; } | 231 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; } |
| 226 bool outer_scope_calls_non_strict_eval() const { | 232 bool outer_scope_calls_non_strict_eval() const { |
| 227 return outer_scope_calls_non_strict_eval_; | 233 return outer_scope_calls_non_strict_eval_; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 bool outer_scope_is_eval_scope_; | 395 bool outer_scope_is_eval_scope_; |
| 390 bool force_eager_compilation_; | 396 bool force_eager_compilation_; |
| 391 | 397 |
| 392 // True if it doesn't need scope resolution (e.g., if the scope was | 398 // True if it doesn't need scope resolution (e.g., if the scope was |
| 393 // constructed based on a serialized scope info or a catch context). | 399 // constructed based on a serialized scope info or a catch context). |
| 394 bool already_resolved_; | 400 bool already_resolved_; |
| 395 | 401 |
| 396 // Computed as variables are declared. | 402 // Computed as variables are declared. |
| 397 int num_var_or_const_; | 403 int num_var_or_const_; |
| 398 | 404 |
| 399 // Computed via AllocateVariables; function scopes only. | 405 // Computed via AllocateVariables; function, block and catch scopes only. |
| 400 int num_stack_slots_; | 406 int num_stack_slots_; |
| 401 int num_heap_slots_; | 407 int num_heap_slots_; |
| 402 | 408 |
| 403 // Serialized scopes support. | 409 // Serialized scopes support. |
| 404 Handle<SerializedScopeInfo> scope_info_; | 410 Handle<SerializedScopeInfo> scope_info_; |
| 405 bool already_resolved() { return already_resolved_; } | 411 bool already_resolved() { return already_resolved_; } |
| 406 | 412 |
| 407 // Create a non-local variable with a given name. | 413 // Create a non-local variable with a given name. |
| 408 // These variables are looked up dynamically at runtime. | 414 // These variables are looked up dynamically at runtime. |
| 409 Variable* NonLocal(Handle<String> name, Variable::Mode mode); | 415 Variable* NonLocal(Handle<String> name, Variable::Mode mode); |
| 410 | 416 |
| 411 // Variable resolution. | 417 // Variable resolution. |
| 412 Variable* LookupRecursive(Handle<String> name, | 418 |
| 413 bool from_inner_function, | 419 // Possible results of a variable lookup. |
| 414 Variable** invalidated_local); | 420 enum LookupResult { |
| 421 // The variable could be statically resolved to a non-global outer | |
| 422 // scope. There is no 'with' statement in between and no in between | |
| 423 // scope calls 'eval'. | |
| 424 FOUND, | |
|
Kevin Millikin (Chromium)
2011/09/15 09:38:13
Since GLOBAL can also be found, perhaps it's clear
Steven
2011/09/15 19:54:06
Done.
| |
| 425 | |
| 426 // The variable could be statically resolved to a non-global outer | |
| 427 // scope, but an in between scope calls 'eval' that might possibly | |
| 428 // introduce variables shadowing the found one. Thus the found variable | |
| 429 // is just a guess. | |
| 430 FOUND_EVAL, | |
| 431 | |
| 432 // We may have statically resolved a variable to a non-global outer | |
| 433 // scope, but there is a 'with' statement in between. The 'with' object | |
| 434 // may have a property with the same name, so if a variable has been | |
| 435 // found, it is just a guess. | |
| 436 FOUND_WITH, | |
|
Kevin Millikin (Chromium)
2011/09/15 09:38:13
On the other hand, this case includes the case of
Steven
2011/09/15 19:54:06
Done.
| |
| 437 | |
| 438 // The variable could not be resolved to any local binding and is thus | |
| 439 // a global variable unless it is shadowed by an eval-introduced variable. | |
| 440 GLOBAL | |
|
Kevin Millikin (Chromium)
2011/09/15 09:38:13
This case is also used for when the variable is re
Steven
2011/09/15 19:54:06
Done.
| |
| 441 }; | |
| 442 | |
| 443 // Lookup a variable starting with this scope. | |
| 444 LookupResult LookupRecursive(Handle<String> name, | |
| 445 bool from_inner_scope, | |
| 446 Variable** var); | |
| 415 void ResolveVariable(Scope* global_scope, | 447 void ResolveVariable(Scope* global_scope, |
| 416 Handle<Context> context, | 448 Handle<Context> context, |
| 417 VariableProxy* proxy); | 449 VariableProxy* proxy); |
| 418 void ResolveVariablesRecursively(Scope* global_scope, | 450 void ResolveVariablesRecursively(Scope* global_scope, |
| 419 Handle<Context> context); | 451 Handle<Context> context); |
| 420 | 452 |
| 421 // Scope analysis. | 453 // Scope analysis. |
| 422 bool PropagateScopeInfo(bool outer_scope_calls_eval, | 454 bool PropagateScopeInfo(bool outer_scope_calls_eval, |
| 423 bool outer_scope_calls_non_strict_eval, | 455 bool outer_scope_calls_non_strict_eval, |
| 424 bool outer_scope_is_eval_scope); | 456 bool outer_scope_is_eval_scope); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 452 } | 484 } |
| 453 | 485 |
| 454 void SetDefaults(Type type, | 486 void SetDefaults(Type type, |
| 455 Scope* outer_scope, | 487 Scope* outer_scope, |
| 456 Handle<SerializedScopeInfo> scope_info); | 488 Handle<SerializedScopeInfo> scope_info); |
| 457 }; | 489 }; |
| 458 | 490 |
| 459 } } // namespace v8::internal | 491 } } // namespace v8::internal |
| 460 | 492 |
| 461 #endif // V8_SCOPES_H_ | 493 #endif // V8_SCOPES_H_ |
| OLD | NEW |