OLD | NEW |
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 bool is_function_scope() const { return scope_type_ == FUNCTION_SCOPE; } | 286 bool is_function_scope() const { return scope_type_ == FUNCTION_SCOPE; } |
287 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } | 287 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } |
288 bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; } | 288 bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; } |
289 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } | 289 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } |
290 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } | 290 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } |
291 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } | 291 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } |
292 bool is_declaration_scope() const { | 292 bool is_declaration_scope() const { |
293 return is_eval_scope() || is_function_scope() || | 293 return is_eval_scope() || is_function_scope() || |
294 is_module_scope() || is_global_scope(); | 294 is_module_scope() || is_global_scope(); |
295 } | 295 } |
296 bool is_classic_mode() const { | 296 bool is_sloppy_mode() const { |
297 return language_mode() == CLASSIC_MODE; | 297 return language_mode() == SLOPPY_MODE; |
298 } | 298 } |
299 bool is_extended_mode() const { | 299 bool is_extended_mode() const { |
300 return language_mode() == EXTENDED_MODE; | 300 return language_mode() == EXTENDED_MODE; |
301 } | 301 } |
302 bool is_strict_or_extended_eval_scope() const { | 302 bool is_strict_or_extended_eval_scope() const { |
303 return is_eval_scope() && !is_classic_mode(); | 303 return is_eval_scope() && !is_sloppy_mode(); |
304 } | 304 } |
305 | 305 |
306 // Information about which scopes calls eval. | 306 // Information about which scopes calls eval. |
307 bool calls_eval() const { return scope_calls_eval_; } | 307 bool calls_eval() const { return scope_calls_eval_; } |
308 bool calls_non_strict_eval() { | 308 bool calls_sloppy_eval() { return scope_calls_eval_ && is_sloppy_mode(); } |
309 return scope_calls_eval_ && is_classic_mode(); | 309 bool outer_scope_calls_sloppy_eval() const { |
310 } | 310 return outer_scope_calls_sloppy_eval_; |
311 bool outer_scope_calls_non_strict_eval() const { | |
312 return outer_scope_calls_non_strict_eval_; | |
313 } | 311 } |
314 | 312 |
315 // Is this scope inside a with statement. | 313 // Is this scope inside a with statement. |
316 bool inside_with() const { return scope_inside_with_; } | 314 bool inside_with() const { return scope_inside_with_; } |
317 // Does this scope contain a with statement. | 315 // Does this scope contain a with statement. |
318 bool contains_with() const { return scope_contains_with_; } | 316 bool contains_with() const { return scope_contains_with_; } |
319 | 317 |
320 // --------------------------------------------------------------------------- | 318 // --------------------------------------------------------------------------- |
321 // Accessors. | 319 // Accessors. |
322 | 320 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 // This scope or a nested catch scope or with scope contain an 'eval' call. At | 491 // This scope or a nested catch scope or with scope contain an 'eval' call. At |
494 // the 'eval' call site this scope is the declaration scope. | 492 // the 'eval' call site this scope is the declaration scope. |
495 bool scope_calls_eval_; | 493 bool scope_calls_eval_; |
496 // The language mode of this scope. | 494 // The language mode of this scope. |
497 LanguageMode language_mode_; | 495 LanguageMode language_mode_; |
498 // Source positions. | 496 // Source positions. |
499 int start_position_; | 497 int start_position_; |
500 int end_position_; | 498 int end_position_; |
501 | 499 |
502 // Computed via PropagateScopeInfo. | 500 // Computed via PropagateScopeInfo. |
503 bool outer_scope_calls_non_strict_eval_; | 501 bool outer_scope_calls_sloppy_eval_; |
504 bool inner_scope_calls_eval_; | 502 bool inner_scope_calls_eval_; |
505 bool force_eager_compilation_; | 503 bool force_eager_compilation_; |
506 bool force_context_allocation_; | 504 bool force_context_allocation_; |
507 | 505 |
508 // True if it doesn't need scope resolution (e.g., if the scope was | 506 // True if it doesn't need scope resolution (e.g., if the scope was |
509 // constructed based on a serialized scope info or a catch context). | 507 // constructed based on a serialized scope info or a catch context). |
510 bool already_resolved_; | 508 bool already_resolved_; |
511 | 509 |
512 // Computed as variables are declared. | 510 // Computed as variables are declared. |
513 int num_var_or_const_; | 511 int num_var_or_const_; |
(...skipping 17 matching lines...) Expand all Loading... |
531 Variable* NonLocal(Handle<String> name, VariableMode mode); | 529 Variable* NonLocal(Handle<String> name, VariableMode mode); |
532 | 530 |
533 // Variable resolution. | 531 // Variable resolution. |
534 // Possible results of a recursive variable lookup telling if and how a | 532 // Possible results of a recursive variable lookup telling if and how a |
535 // variable is bound. These are returned in the output parameter *binding_kind | 533 // variable is bound. These are returned in the output parameter *binding_kind |
536 // of the LookupRecursive function. | 534 // of the LookupRecursive function. |
537 enum BindingKind { | 535 enum BindingKind { |
538 // The variable reference could be statically resolved to a variable binding | 536 // The variable reference could be statically resolved to a variable binding |
539 // which is returned. There is no 'with' statement between the reference and | 537 // which is returned. There is no 'with' statement between the reference and |
540 // the binding and no scope between the reference scope (inclusive) and | 538 // the binding and no scope between the reference scope (inclusive) and |
541 // binding scope (exclusive) makes a non-strict 'eval' call. | 539 // binding scope (exclusive) makes a sloppy 'eval' call. |
542 BOUND, | 540 BOUND, |
543 | 541 |
544 // The variable reference could be statically resolved to a variable binding | 542 // The variable reference could be statically resolved to a variable binding |
545 // which is returned. There is no 'with' statement between the reference and | 543 // which is returned. There is no 'with' statement between the reference and |
546 // the binding, but some scope between the reference scope (inclusive) and | 544 // the binding, but some scope between the reference scope (inclusive) and |
547 // binding scope (exclusive) makes a non-strict 'eval' call, that might | 545 // binding scope (exclusive) makes a sloppy 'eval' call, that might |
548 // possibly introduce variable bindings shadowing the found one. Thus the | 546 // possibly introduce variable bindings shadowing the found one. Thus the |
549 // found variable binding is just a guess. | 547 // found variable binding is just a guess. |
550 BOUND_EVAL_SHADOWED, | 548 BOUND_EVAL_SHADOWED, |
551 | 549 |
552 // The variable reference could not be statically resolved to any binding | 550 // The variable reference could not be statically resolved to any binding |
553 // and thus should be considered referencing a global variable. NULL is | 551 // and thus should be considered referencing a global variable. NULL is |
554 // returned. The variable reference is not inside any 'with' statement and | 552 // returned. The variable reference is not inside any 'with' statement and |
555 // no scope between the reference scope (inclusive) and global scope | 553 // no scope between the reference scope (inclusive) and global scope |
556 // (exclusive) makes a non-strict 'eval' call. | 554 // (exclusive) makes a sloppy 'eval' call. |
557 UNBOUND, | 555 UNBOUND, |
558 | 556 |
559 // The variable reference could not be statically resolved to any binding | 557 // The variable reference could not be statically resolved to any binding |
560 // NULL is returned. The variable reference is not inside any 'with' | 558 // NULL is returned. The variable reference is not inside any 'with' |
561 // statement, but some scope between the reference scope (inclusive) and | 559 // statement, but some scope between the reference scope (inclusive) and |
562 // global scope (exclusive) makes a non-strict 'eval' call, that might | 560 // global scope (exclusive) makes a sloppy 'eval' call, that might |
563 // possibly introduce a variable binding. Thus the reference should be | 561 // possibly introduce a variable binding. Thus the reference should be |
564 // considered referencing a global variable unless it is shadowed by an | 562 // considered referencing a global variable unless it is shadowed by an |
565 // 'eval' introduced binding. | 563 // 'eval' introduced binding. |
566 UNBOUND_EVAL_SHADOWED, | 564 UNBOUND_EVAL_SHADOWED, |
567 | 565 |
568 // The variable could not be statically resolved and needs to be looked up | 566 // The variable could not be statically resolved and needs to be looked up |
569 // dynamically. NULL is returned. There are two possible reasons: | 567 // dynamically. NULL is returned. There are two possible reasons: |
570 // * A 'with' statement has been encountered and there is no variable | 568 // * A 'with' statement has been encountered and there is no variable |
571 // binding for the name between the variable reference and the 'with'. | 569 // binding for the name between the variable reference and the 'with'. |
572 // The variable potentially references a property of the 'with' object. | 570 // The variable potentially references a property of the 'with' object. |
(...skipping 11 matching lines...) Expand all Loading... |
584 AstNodeFactory<AstNullVisitor>* factory); | 582 AstNodeFactory<AstNullVisitor>* factory); |
585 MUST_USE_RESULT | 583 MUST_USE_RESULT |
586 bool ResolveVariable(CompilationInfo* info, | 584 bool ResolveVariable(CompilationInfo* info, |
587 VariableProxy* proxy, | 585 VariableProxy* proxy, |
588 AstNodeFactory<AstNullVisitor>* factory); | 586 AstNodeFactory<AstNullVisitor>* factory); |
589 MUST_USE_RESULT | 587 MUST_USE_RESULT |
590 bool ResolveVariablesRecursively(CompilationInfo* info, | 588 bool ResolveVariablesRecursively(CompilationInfo* info, |
591 AstNodeFactory<AstNullVisitor>* factory); | 589 AstNodeFactory<AstNullVisitor>* factory); |
592 | 590 |
593 // Scope analysis. | 591 // Scope analysis. |
594 bool PropagateScopeInfo(bool outer_scope_calls_non_strict_eval); | 592 bool PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); |
595 bool HasTrivialContext() const; | 593 bool HasTrivialContext() const; |
596 | 594 |
597 // Predicates. | 595 // Predicates. |
598 bool MustAllocate(Variable* var); | 596 bool MustAllocate(Variable* var); |
599 bool MustAllocateInContext(Variable* var); | 597 bool MustAllocateInContext(Variable* var); |
600 bool HasArgumentsParameter(); | 598 bool HasArgumentsParameter(); |
601 | 599 |
602 // Variable allocation. | 600 // Variable allocation. |
603 void AllocateStackSlot(Variable* var); | 601 void AllocateStackSlot(Variable* var); |
604 void AllocateHeapSlot(Variable* var); | 602 void AllocateHeapSlot(Variable* var); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 void SetDefaults(ScopeType type, | 636 void SetDefaults(ScopeType type, |
639 Scope* outer_scope, | 637 Scope* outer_scope, |
640 Handle<ScopeInfo> scope_info); | 638 Handle<ScopeInfo> scope_info); |
641 | 639 |
642 Zone* zone_; | 640 Zone* zone_; |
643 }; | 641 }; |
644 | 642 |
645 } } // namespace v8::internal | 643 } } // namespace v8::internal |
646 | 644 |
647 #endif // V8_SCOPES_H_ | 645 #endif // V8_SCOPES_H_ |
OLD | NEW |