OLD | NEW |
1 // Copyright 2011 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // --------------------------------------------------------------------------- | 108 // --------------------------------------------------------------------------- |
109 // Declarations | 109 // Declarations |
110 | 110 |
111 // Lookup a variable in this scope. Returns the variable or NULL if not found. | 111 // Lookup a variable in this scope. Returns the variable or NULL if not found. |
112 Variable* LocalLookup(Handle<String> name); | 112 Variable* LocalLookup(Handle<String> name); |
113 | 113 |
114 // This lookup corresponds to a lookup in the "intermediate" scope sitting | 114 // This lookup corresponds to a lookup in the "intermediate" scope sitting |
115 // between this scope and the outer scope. (ECMA-262, 3rd., requires that | 115 // between this scope and the outer scope. (ECMA-262, 3rd., requires that |
116 // the name of named function literal is kept in an intermediate scope | 116 // the name of named function literal is kept in an intermediate scope |
117 // in between this scope and the next outer scope.) | 117 // in between this scope and the next outer scope.) |
118 Variable* LookupFunctionVar(Handle<String> name); | 118 Variable* LookupFunctionVar(Handle<String> name, |
| 119 AstNodeFactory<AstNullVisitor>* factory); |
119 | 120 |
120 // Lookup a variable in this scope or outer scopes. | 121 // Lookup a variable in this scope or outer scopes. |
121 // Returns the variable or NULL if not found. | 122 // Returns the variable or NULL if not found. |
122 Variable* Lookup(Handle<String> name); | 123 Variable* Lookup(Handle<String> name); |
123 | 124 |
124 // Declare the function variable for a function literal. This variable | 125 // Declare the function variable for a function literal. This variable |
125 // is in an intermediate scope between this function scope and the the | 126 // is in an intermediate scope between this function scope and the the |
126 // outer scope. Only possible for function scopes; at most one variable. | 127 // outer scope. Only possible for function scopes; at most one variable. |
127 Variable* DeclareFunctionVar(Handle<String> name, VariableMode mode); | 128 template<class Visitor> |
| 129 Variable* DeclareFunctionVar(Handle<String> name, |
| 130 VariableMode mode, |
| 131 AstNodeFactory<Visitor>* factory) { |
| 132 ASSERT(is_function_scope() && function_ == NULL); |
| 133 Variable* function_var = new Variable( |
| 134 this, name, mode, true, Variable::NORMAL, kCreatedInitialized); |
| 135 function_ = factory->NewVariableProxy(function_var); |
| 136 return function_var; |
| 137 } |
128 | 138 |
129 // Declare a parameter in this scope. When there are duplicated | 139 // Declare a parameter in this scope. When there are duplicated |
130 // parameters the rightmost one 'wins'. However, the implementation | 140 // parameters the rightmost one 'wins'. However, the implementation |
131 // expects all parameters to be declared and from left to right. | 141 // expects all parameters to be declared and from left to right. |
132 void DeclareParameter(Handle<String> name, VariableMode mode); | 142 void DeclareParameter(Handle<String> name, VariableMode mode); |
133 | 143 |
134 // Declare a local variable in this scope. If the variable has been | 144 // Declare a local variable in this scope. If the variable has been |
135 // declared before, the previously declared variable is returned. | 145 // declared before, the previously declared variable is returned. |
136 Variable* DeclareLocal(Handle<String> name, | 146 Variable* DeclareLocal(Handle<String> name, |
137 VariableMode mode, | 147 VariableMode mode, |
138 InitializationFlag init_flag); | 148 InitializationFlag init_flag); |
139 | 149 |
140 // Declare an implicit global variable in this scope which must be a | 150 // Declare an implicit global variable in this scope which must be a |
141 // global scope. The variable was introduced (possibly from an inner | 151 // global scope. The variable was introduced (possibly from an inner |
142 // scope) by a reference to an unresolved variable with no intervening | 152 // scope) by a reference to an unresolved variable with no intervening |
143 // with statements or eval calls. | 153 // with statements or eval calls. |
144 Variable* DeclareGlobal(Handle<String> name); | 154 Variable* DeclareGlobal(Handle<String> name); |
145 | 155 |
146 // Create a new unresolved variable. | 156 // Create a new unresolved variable. |
147 VariableProxy* NewUnresolved(Handle<String> name, | 157 template<class Visitor> |
148 int position = RelocInfo::kNoPosition); | 158 VariableProxy* NewUnresolved(AstNodeFactory<Visitor>* factory, |
| 159 Handle<String> name, |
| 160 int position = RelocInfo::kNoPosition) { |
| 161 // Note that we must not share the unresolved variables with |
| 162 // the same name because they may be removed selectively via |
| 163 // RemoveUnresolved(). |
| 164 ASSERT(!already_resolved()); |
| 165 VariableProxy* proxy = factory->NewVariableProxy(name, false, position); |
| 166 unresolved_.Add(proxy); |
| 167 return proxy; |
| 168 } |
149 | 169 |
150 // Remove a unresolved variable. During parsing, an unresolved variable | 170 // Remove a unresolved variable. During parsing, an unresolved variable |
151 // may have been added optimistically, but then only the variable name | 171 // may have been added optimistically, but then only the variable name |
152 // was used (typically for labels). If the variable was not declared, the | 172 // was used (typically for labels). If the variable was not declared, the |
153 // addition introduced a new unresolved variable which may end up being | 173 // addition introduced a new unresolved variable which may end up being |
154 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 174 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
155 // such a variable again if it was added; otherwise this is a no-op. | 175 // such a variable again if it was added; otherwise this is a no-op. |
156 void RemoveUnresolved(VariableProxy* var); | 176 void RemoveUnresolved(VariableProxy* var); |
157 | 177 |
158 // Creates a new temporary variable in this scope. The name is only used | 178 // Creates a new temporary variable in this scope. The name is only used |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 ZoneList<Variable*>* context_locals); | 345 ZoneList<Variable*>* context_locals); |
326 | 346 |
327 // Resolve and fill in the allocation information for all variables | 347 // Resolve and fill in the allocation information for all variables |
328 // in this scopes. Must be called *after* all scopes have been | 348 // in this scopes. Must be called *after* all scopes have been |
329 // processed (parsed) to ensure that unresolved variables can be | 349 // processed (parsed) to ensure that unresolved variables can be |
330 // resolved properly. | 350 // resolved properly. |
331 // | 351 // |
332 // In the case of code compiled and run using 'eval', the context | 352 // In the case of code compiled and run using 'eval', the context |
333 // parameter is the context in which eval was called. In all other | 353 // parameter is the context in which eval was called. In all other |
334 // cases the context parameter is an empty handle. | 354 // cases the context parameter is an empty handle. |
335 void AllocateVariables(Scope* global_scope); | 355 void AllocateVariables(Scope* global_scope, |
| 356 AstNodeFactory<AstNullVisitor>* factory); |
336 | 357 |
337 // Current number of var or const locals. | 358 // Current number of var or const locals. |
338 int num_var_or_const() { return num_var_or_const_; } | 359 int num_var_or_const() { return num_var_or_const_; } |
339 | 360 |
340 // Result of variable allocation. | 361 // Result of variable allocation. |
341 int num_stack_slots() const { return num_stack_slots_; } | 362 int num_stack_slots() const { return num_stack_slots_; } |
342 int num_heap_slots() const { return num_heap_slots_; } | 363 int num_heap_slots() const { return num_heap_slots_; } |
343 | 364 |
344 int StackLocalCount() const; | 365 int StackLocalCount() const; |
345 int ContextLocalCount() const; | 366 int ContextLocalCount() const; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // * The code is being executed as part of a call to 'eval' and the calling | 533 // * The code is being executed as part of a call to 'eval' and the calling |
513 // context chain contains either a variable binding for the name or it | 534 // context chain contains either a variable binding for the name or it |
514 // contains a 'with' context. | 535 // contains a 'with' context. |
515 DYNAMIC_LOOKUP | 536 DYNAMIC_LOOKUP |
516 }; | 537 }; |
517 | 538 |
518 // Lookup a variable reference given by name recursively starting with this | 539 // Lookup a variable reference given by name recursively starting with this |
519 // scope. If the code is executed because of a call to 'eval', the context | 540 // scope. If the code is executed because of a call to 'eval', the context |
520 // parameter should be set to the calling context of 'eval'. | 541 // parameter should be set to the calling context of 'eval'. |
521 Variable* LookupRecursive(Handle<String> name, | 542 Variable* LookupRecursive(Handle<String> name, |
522 BindingKind* binding_kind); | 543 BindingKind* binding_kind, |
| 544 AstNodeFactory<AstNullVisitor>* factory); |
523 void ResolveVariable(Scope* global_scope, | 545 void ResolveVariable(Scope* global_scope, |
524 VariableProxy* proxy); | 546 VariableProxy* proxy, |
525 void ResolveVariablesRecursively(Scope* global_scope); | 547 AstNodeFactory<AstNullVisitor>* factory); |
| 548 void ResolveVariablesRecursively(Scope* global_scope, |
| 549 AstNodeFactory<AstNullVisitor>* factory); |
526 | 550 |
527 // Scope analysis. | 551 // Scope analysis. |
528 bool PropagateScopeInfo(bool outer_scope_calls_non_strict_eval); | 552 bool PropagateScopeInfo(bool outer_scope_calls_non_strict_eval); |
529 bool HasTrivialContext() const; | 553 bool HasTrivialContext() const; |
530 | 554 |
531 // Predicates. | 555 // Predicates. |
532 bool MustAllocate(Variable* var); | 556 bool MustAllocate(Variable* var); |
533 bool MustAllocateInContext(Variable* var); | 557 bool MustAllocateInContext(Variable* var); |
534 bool HasArgumentsParameter(); | 558 bool HasArgumentsParameter(); |
535 | 559 |
(...skipping 20 matching lines...) Expand all Loading... |
556 } | 580 } |
557 | 581 |
558 void SetDefaults(ScopeType type, | 582 void SetDefaults(ScopeType type, |
559 Scope* outer_scope, | 583 Scope* outer_scope, |
560 Handle<ScopeInfo> scope_info); | 584 Handle<ScopeInfo> scope_info); |
561 }; | 585 }; |
562 | 586 |
563 } } // namespace v8::internal | 587 } } // namespace v8::internal |
564 | 588 |
565 #endif // V8_SCOPES_H_ | 589 #endif // V8_SCOPES_H_ |
OLD | NEW |