| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_AST_SCOPES_H_ | 5 #ifndef V8_AST_SCOPES_H_ |
| 6 #define V8_AST_SCOPES_H_ | 6 #define V8_AST_SCOPES_H_ |
| 7 | 7 |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
| 10 #include "src/globals.h" | 10 #include "src/globals.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 // Inform the scope that the corresponding code contains an eval call. | 224 // Inform the scope that the corresponding code contains an eval call. |
| 225 void RecordEvalCall() { scope_calls_eval_ = true; } | 225 void RecordEvalCall() { scope_calls_eval_ = true; } |
| 226 | 226 |
| 227 // Inform the scope that the corresponding code uses "super". | 227 // Inform the scope that the corresponding code uses "super". |
| 228 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } | 228 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } |
| 229 | 229 |
| 230 // Set the language mode flag (unless disabled by a global flag). | 230 // Set the language mode flag (unless disabled by a global flag). |
| 231 void SetLanguageMode(LanguageMode language_mode) { | 231 void SetLanguageMode(LanguageMode language_mode) { |
| 232 DCHECK(!is_module_scope() || is_strict(language_mode)); | 232 DCHECK(!is_module_scope() || is_strict(language_mode)); |
| 233 language_mode_ = language_mode; | 233 set_language_mode(language_mode); |
| 234 } | 234 } |
| 235 | 235 |
| 236 // Set the ASM module flag. | 236 // Set the ASM module flag. |
| 237 void SetAsmModule() { asm_module_ = true; } | 237 void SetAsmModule() { asm_module_ = true; } |
| 238 | 238 |
| 239 // Inform the scope that the scope may execute declarations nonlinearly. | 239 // Inform the scope that the scope may execute declarations nonlinearly. |
| 240 // Currently, the only nonlinear scope is a switch statement. The name is | 240 // Currently, the only nonlinear scope is a switch statement. The name is |
| 241 // more general in case something else comes up with similar control flow, | 241 // more general in case something else comes up with similar control flow, |
| 242 // for example the ability to break out of something which does not have | 242 // for example the ability to break out of something which does not have |
| 243 // its own lexical scope. | 243 // its own lexical scope. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } | 304 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } |
| 305 bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; } | 305 bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; } |
| 306 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } | 306 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } |
| 307 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } | 307 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } |
| 308 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } | 308 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } |
| 309 bool is_declaration_scope() const { return is_declaration_scope_; } | 309 bool is_declaration_scope() const { return is_declaration_scope_; } |
| 310 | 310 |
| 311 // Information about which scopes calls eval. | 311 // Information about which scopes calls eval. |
| 312 bool calls_eval() const { return scope_calls_eval_; } | 312 bool calls_eval() const { return scope_calls_eval_; } |
| 313 bool calls_sloppy_eval() const { | 313 bool calls_sloppy_eval() const { |
| 314 return scope_calls_eval_ && is_sloppy(language_mode_); | 314 return scope_calls_eval_ && is_sloppy(language_mode()); |
| 315 } | 315 } |
| 316 bool outer_scope_calls_sloppy_eval() const { | 316 bool outer_scope_calls_sloppy_eval() const { |
| 317 return outer_scope_calls_sloppy_eval_; | 317 return outer_scope_calls_sloppy_eval_; |
| 318 } | 318 } |
| 319 bool asm_module() const { return asm_module_; } | 319 bool asm_module() const { return asm_module_; } |
| 320 bool asm_function() const { return asm_function_; } | 320 bool asm_function() const { return asm_function_; } |
| 321 | 321 |
| 322 // Does this scope access "super" property (super.foo). | 322 // Does this scope access "super" property (super.foo). |
| 323 bool uses_super_property() const { return scope_uses_super_property_; } | 323 bool uses_super_property() const { return scope_uses_super_property_; } |
| 324 // Does this scope have the potential to execute declarations non-linearly? | 324 // Does this scope have the potential to execute declarations non-linearly? |
| 325 bool is_nonlinear() const { return scope_nonlinear_; } | 325 bool is_nonlinear() const { return scope_nonlinear_; } |
| 326 | 326 |
| 327 // Whether this needs to be represented by a runtime context. | 327 // Whether this needs to be represented by a runtime context. |
| 328 bool NeedsContext() const { | 328 bool NeedsContext() const { |
| 329 // Catch scopes always have heap slots. | 329 // Catch scopes always have heap slots. |
| 330 DCHECK(!is_catch_scope() || num_heap_slots() > 0); | 330 DCHECK(!is_catch_scope() || num_heap_slots() > 0); |
| 331 return num_heap_slots() > 0; | 331 return num_heap_slots() > 0; |
| 332 } | 332 } |
| 333 | 333 |
| 334 // --------------------------------------------------------------------------- | 334 // --------------------------------------------------------------------------- |
| 335 // Accessors. | 335 // Accessors. |
| 336 | 336 |
| 337 // The type of this scope. | 337 // The type of this scope. |
| 338 ScopeType scope_type() const { return scope_type_; } | 338 ScopeType scope_type() const { return scope_type_; } |
| 339 | 339 |
| 340 // The language mode of this scope. | 340 // The language mode of this scope. |
| 341 LanguageMode language_mode() const { return language_mode_; } | 341 LanguageMode language_mode() const { return is_strict_ ? STRICT : SLOPPY; } |
| 342 | 342 |
| 343 // inner_scope() and sibling() together implement the inner scope list of a | 343 // inner_scope() and sibling() together implement the inner scope list of a |
| 344 // scope. Inner scope points to the an inner scope of the function, and | 344 // scope. Inner scope points to the an inner scope of the function, and |
| 345 // "sibling" points to a next inner scope of the outer scope of this scope. | 345 // "sibling" points to a next inner scope of the outer scope of this scope. |
| 346 Scope* inner_scope() const { return inner_scope_; } | 346 Scope* inner_scope() const { return inner_scope_; } |
| 347 Scope* sibling() const { return sibling_; } | 347 Scope* sibling() const { return sibling_; } |
| 348 | 348 |
| 349 // The scope immediately surrounding this scope, or NULL. | 349 // The scope immediately surrounding this scope, or NULL. |
| 350 Scope* outer_scope() const { return outer_scope_; } | 350 Scope* outer_scope() const { return outer_scope_; } |
| 351 | 351 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 // Check that all Scopes in the scope tree use the same Zone. | 438 // Check that all Scopes in the scope tree use the same Zone. |
| 439 void CheckZones(); | 439 void CheckZones(); |
| 440 #endif | 440 #endif |
| 441 | 441 |
| 442 // Retrieve `IsSimpleParameterList` of current or outer function. | 442 // Retrieve `IsSimpleParameterList` of current or outer function. |
| 443 bool HasSimpleParameters(); | 443 bool HasSimpleParameters(); |
| 444 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } | 444 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } |
| 445 | 445 |
| 446 protected: | 446 protected: |
| 447 void set_language_mode(LanguageMode language_mode) { | 447 void set_language_mode(LanguageMode language_mode) { |
| 448 language_mode_ = language_mode; | 448 is_strict_ = is_strict(language_mode); |
| 449 } | 449 } |
| 450 | 450 |
| 451 private: | 451 private: |
| 452 Zone* zone_; | 452 Zone* zone_; |
| 453 | 453 |
| 454 // Scope tree. | 454 // Scope tree. |
| 455 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 455 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
| 456 Scope* inner_scope_; // an inner scope of this scope | 456 Scope* inner_scope_; // an inner scope of this scope |
| 457 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. | 457 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. |
| 458 | 458 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 489 int num_stack_slots_; | 489 int num_stack_slots_; |
| 490 int num_heap_slots_; | 490 int num_heap_slots_; |
| 491 int num_global_slots_; | 491 int num_global_slots_; |
| 492 | 492 |
| 493 // The scope type. | 493 // The scope type. |
| 494 const ScopeType scope_type_; | 494 const ScopeType scope_type_; |
| 495 | 495 |
| 496 // Scope-specific information computed during parsing. | 496 // Scope-specific information computed during parsing. |
| 497 // | 497 // |
| 498 // The language mode of this scope. | 498 // The language mode of this scope. |
| 499 STATIC_ASSERT(LANGUAGE_END == 3); | 499 STATIC_ASSERT(LANGUAGE_END == 2); |
| 500 LanguageMode language_mode_ : 2; | 500 bool is_strict_ : 1; |
| 501 // This scope is inside a 'with' of some outer scope. | 501 // This scope is inside a 'with' of some outer scope. |
| 502 bool scope_inside_with_ : 1; | 502 bool scope_inside_with_ : 1; |
| 503 // This scope or a nested catch scope or with scope contain an 'eval' call. At | 503 // This scope or a nested catch scope or with scope contain an 'eval' call. At |
| 504 // the 'eval' call site this scope is the declaration scope. | 504 // the 'eval' call site this scope is the declaration scope. |
| 505 bool scope_calls_eval_ : 1; | 505 bool scope_calls_eval_ : 1; |
| 506 // This scope uses "super" property ('super.foo'). | 506 // This scope uses "super" property ('super.foo'). |
| 507 bool scope_uses_super_property_ : 1; | 507 bool scope_uses_super_property_ : 1; |
| 508 // This scope has a parameter called "arguments". | 508 // This scope has a parameter called "arguments". |
| 509 bool has_arguments_parameter_ : 1; | 509 bool has_arguments_parameter_ : 1; |
| 510 // This scope contains an "use asm" annotation. | 510 // This scope contains an "use asm" annotation. |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 void AllocateModuleVariables(); | 891 void AllocateModuleVariables(); |
| 892 | 892 |
| 893 private: | 893 private: |
| 894 ModuleDescriptor* module_descriptor_; | 894 ModuleDescriptor* module_descriptor_; |
| 895 }; | 895 }; |
| 896 | 896 |
| 897 } // namespace internal | 897 } // namespace internal |
| 898 } // namespace v8 | 898 } // namespace v8 |
| 899 | 899 |
| 900 #endif // V8_AST_SCOPES_H_ | 900 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |