| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 static bool Analyze(ParseInfo* info); | 80 static bool Analyze(ParseInfo* info); |
| 81 | 81 |
| 82 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, | 82 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, |
| 83 Context* context, Scope* script_scope); | 83 Context* context, Scope* script_scope); |
| 84 | 84 |
| 85 // The scope name is only used for printing/debugging. | 85 // The scope name is only used for printing/debugging. |
| 86 void SetScopeName(const AstRawString* scope_name) { | 86 void SetScopeName(const AstRawString* scope_name) { |
| 87 scope_name_ = scope_name; | 87 scope_name_ = scope_name; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Mark the current scope as a scope for evaluating function parameter |
| 91 // expressions (such as initializers for optional parameters) |
| 92 void SetParameterExpressionsScopeFor(Scope* function_scope); |
| 93 |
| 90 void Initialize(); | 94 void Initialize(); |
| 91 | 95 |
| 92 // Checks if the block scope is redundant, i.e. it does not contain any | 96 // Checks if the block scope is redundant, i.e. it does not contain any |
| 93 // block scoped declarations. In that case it is removed from the scope | 97 // block scoped declarations. In that case it is removed from the scope |
| 94 // tree and its children are reparented. | 98 // tree and its children are reparented. |
| 95 Scope* FinalizeBlockScope(); | 99 Scope* FinalizeBlockScope(); |
| 96 | 100 |
| 97 Zone* zone() const { return zone_; } | 101 Zone* zone() const { return zone_; } |
| 98 | 102 |
| 99 // --------------------------------------------------------------------------- | 103 // --------------------------------------------------------------------------- |
| (...skipping 18 matching lines...) Expand all Loading... |
| 118 // outer scope. Only possible for function scopes; at most one variable. | 122 // outer scope. Only possible for function scopes; at most one variable. |
| 119 void DeclareFunctionVar(VariableDeclaration* declaration) { | 123 void DeclareFunctionVar(VariableDeclaration* declaration) { |
| 120 DCHECK(is_function_scope()); | 124 DCHECK(is_function_scope()); |
| 121 function_ = declaration; | 125 function_ = declaration; |
| 122 } | 126 } |
| 123 | 127 |
| 124 // Declare a parameter in this scope. When there are duplicated | 128 // Declare a parameter in this scope. When there are duplicated |
| 125 // parameters the rightmost one 'wins'. However, the implementation | 129 // parameters the rightmost one 'wins'. However, the implementation |
| 126 // expects all parameters to be declared and from left to right. | 130 // expects all parameters to be declared and from left to right. |
| 127 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, | 131 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, |
| 128 bool is_rest = false); | 132 ParameterKind kind = NormalParameter); |
| 129 | 133 |
| 130 // Declare a local variable in this scope. If the variable has been | 134 // Declare a local variable in this scope. If the variable has been |
| 131 // declared before, the previously declared variable is returned. | 135 // declared before, the previously declared variable is returned. |
| 132 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, | 136 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, |
| 133 InitializationFlag init_flag, Variable::Kind kind, | 137 InitializationFlag init_flag, Variable::Kind kind, |
| 134 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 138 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
| 135 | 139 |
| 136 // Declare an implicit global variable in this scope which must be a | 140 // Declare an implicit global variable in this scope which must be a |
| 137 // script scope. The variable was introduced (possibly from an inner | 141 // script scope. The variable was introduced (possibly from an inner |
| 138 // scope) by a reference to an unresolved variable with no intervening | 142 // scope) by a reference to an unresolved variable with no intervening |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively | 506 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively |
| 503 #endif | 507 #endif |
| 504 | 508 |
| 505 // --------------------------------------------------------------------------- | 509 // --------------------------------------------------------------------------- |
| 506 // Implementation. | 510 // Implementation. |
| 507 protected: | 511 protected: |
| 508 friend class ParserFactory; | 512 friend class ParserFactory; |
| 509 | 513 |
| 510 // Scope tree. | 514 // Scope tree. |
| 511 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 515 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
| 516 |
| 517 // function scope to search for parameters. This auxiliary scope enables TDZ |
| 518 // semantics for parameters while evaluating parameter expressions. |
| 519 Scope* parameter_scope_; |
| 520 |
| 512 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes | 521 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes |
| 513 | 522 |
| 514 // The scope type. | 523 // The scope type. |
| 515 ScopeType scope_type_; | 524 ScopeType scope_type_; |
| 516 // Some block scopes are tagged as class scopes. | 525 // Some block scopes are tagged as class scopes. |
| 517 bool block_scope_is_class_scope_; | 526 bool block_scope_is_class_scope_; |
| 518 // If the scope is a function scope, this is the function kind. | 527 // If the scope is a function scope, this is the function kind. |
| 519 FunctionKind function_kind_; | 528 FunctionKind function_kind_; |
| 520 | 529 |
| 521 // Debugging support. | 530 // Debugging support. |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 | 739 |
| 731 AstValueFactory* ast_value_factory_; | 740 AstValueFactory* ast_value_factory_; |
| 732 Zone* zone_; | 741 Zone* zone_; |
| 733 | 742 |
| 734 PendingCompilationErrorHandler pending_error_handler_; | 743 PendingCompilationErrorHandler pending_error_handler_; |
| 735 }; | 744 }; |
| 736 | 745 |
| 737 } } // namespace v8::internal | 746 } } // namespace v8::internal |
| 738 | 747 |
| 739 #endif // V8_SCOPES_H_ | 748 #endif // V8_SCOPES_H_ |
| OLD | NEW |