| 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_SCOPES_H_ | 5 #ifndef V8_SCOPES_H_ |
| 6 #define V8_SCOPES_H_ | 6 #define V8_SCOPES_H_ |
| 7 | 7 |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/pending-compilation-error-handler.h" | 9 #include "src/pending-compilation-error-handler.h" |
| 10 #include "src/zone.h" | 10 #include "src/zone.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // block scoped declarations. In that case it is removed from the scope | 94 // block scoped declarations. In that case it is removed from the scope |
| 95 // tree and its children are reparented. | 95 // tree and its children are reparented. |
| 96 Scope* FinalizeBlockScope(); | 96 Scope* FinalizeBlockScope(); |
| 97 | 97 |
| 98 Zone* zone() const { return zone_; } | 98 Zone* zone() const { return zone_; } |
| 99 | 99 |
| 100 // --------------------------------------------------------------------------- | 100 // --------------------------------------------------------------------------- |
| 101 // Declarations | 101 // Declarations |
| 102 | 102 |
| 103 // Lookup a variable in this scope. Returns the variable or NULL if not found. | 103 // Lookup a variable in this scope. Returns the variable or NULL if not found. |
| 104 Variable* LookupLocal(const AstRawString* name); | 104 Variable* LookupLocal(const AstRawString* name, bool parameters_only = false); |
| 105 | 105 |
| 106 // This lookup corresponds to a lookup in the "intermediate" scope sitting | 106 // This lookup corresponds to a lookup in the "intermediate" scope sitting |
| 107 // between this scope and the outer scope. (ECMA-262, 3rd., requires that | 107 // between this scope and the outer scope. (ECMA-262, 3rd., requires that |
| 108 // the name of named function literal is kept in an intermediate scope | 108 // the name of named function literal is kept in an intermediate scope |
| 109 // in between this scope and the next outer scope.) | 109 // in between this scope and the next outer scope.) |
| 110 Variable* LookupFunctionVar(const AstRawString* name, | 110 Variable* LookupFunctionVar(const AstRawString* name, |
| 111 AstNodeFactory* factory); | 111 AstNodeFactory* factory); |
| 112 | 112 |
| 113 // Lookup a variable in this scope or outer scopes. | 113 // Lookup a variable in this scope or outer scopes. |
| 114 // Returns the variable or NULL if not found. | 114 // Returns the variable or NULL if not found. |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; } | 275 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; } |
| 276 bool is_function_scope() const { | 276 bool is_function_scope() const { |
| 277 return scope_type_ == FUNCTION_SCOPE || scope_type_ == ARROW_SCOPE; | 277 return scope_type_ == FUNCTION_SCOPE || scope_type_ == ARROW_SCOPE; |
| 278 } | 278 } |
| 279 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } | 279 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } |
| 280 bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; } | 280 bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; } |
| 281 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } | 281 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } |
| 282 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } | 282 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } |
| 283 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } | 283 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } |
| 284 bool is_arrow_scope() const { return scope_type_ == ARROW_SCOPE; } | 284 bool is_arrow_scope() const { return scope_type_ == ARROW_SCOPE; } |
| 285 bool is_parameter_scope() const { return scope_type_ == PARAMETER_SCOPE; } |
| 285 void tag_as_class_scope() { | 286 void tag_as_class_scope() { |
| 286 DCHECK(is_block_scope()); | 287 DCHECK(is_block_scope()); |
| 287 block_scope_is_class_scope_ = true; | 288 block_scope_is_class_scope_ = true; |
| 288 } | 289 } |
| 289 bool is_class_scope() const { | 290 bool is_class_scope() const { |
| 290 return is_block_scope() && block_scope_is_class_scope_; | 291 return is_block_scope() && block_scope_is_class_scope_; |
| 291 } | 292 } |
| 292 bool is_declaration_scope() const { | 293 bool is_declaration_scope() const { |
| 293 return is_eval_scope() || is_function_scope() || | 294 return is_eval_scope() || is_function_scope() || |
| 294 is_module_scope() || is_script_scope(); | 295 is_module_scope() || is_script_scope(); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 // * The code is being executed as part of a call to 'eval' and the calling | 671 // * The code is being executed as part of a call to 'eval' and the calling |
| 671 // context chain contains either a variable binding for the name or it | 672 // context chain contains either a variable binding for the name or it |
| 672 // contains a 'with' context. | 673 // contains a 'with' context. |
| 673 DYNAMIC_LOOKUP | 674 DYNAMIC_LOOKUP |
| 674 }; | 675 }; |
| 675 | 676 |
| 676 // Lookup a variable reference given by name recursively starting with this | 677 // Lookup a variable reference given by name recursively starting with this |
| 677 // scope. If the code is executed because of a call to 'eval', the context | 678 // scope. If the code is executed because of a call to 'eval', the context |
| 678 // parameter should be set to the calling context of 'eval'. | 679 // parameter should be set to the calling context of 'eval'. |
| 679 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, | 680 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, |
| 680 AstNodeFactory* factory); | 681 AstNodeFactory* factory, |
| 682 bool parameters_only = false); |
| 681 MUST_USE_RESULT | 683 MUST_USE_RESULT |
| 682 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, | 684 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, |
| 683 AstNodeFactory* factory); | 685 AstNodeFactory* factory); |
| 684 MUST_USE_RESULT | 686 MUST_USE_RESULT |
| 685 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); | 687 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); |
| 686 | 688 |
| 687 bool CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var); | 689 bool CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var); |
| 688 | 690 |
| 689 // If this scope is a method scope of a class, return the corresponding | 691 // If this scope is a method scope of a class, return the corresponding |
| 690 // class variable, otherwise nullptr. | 692 // class variable, otherwise nullptr. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 PendingCompilationErrorHandler pending_error_handler_; | 747 PendingCompilationErrorHandler pending_error_handler_; |
| 746 | 748 |
| 747 // For tracking which classes are declared consecutively. Needed for strong | 749 // For tracking which classes are declared consecutively. Needed for strong |
| 748 // mode. | 750 // mode. |
| 749 int class_declaration_group_start_; | 751 int class_declaration_group_start_; |
| 750 }; | 752 }; |
| 751 | 753 |
| 752 } } // namespace v8::internal | 754 } } // namespace v8::internal |
| 753 | 755 |
| 754 #endif // V8_SCOPES_H_ | 756 #endif // V8_SCOPES_H_ |
| OLD | NEW |