OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // --------------------------------------------------------------------------- | 86 // --------------------------------------------------------------------------- |
87 // Construction | 87 // Construction |
88 | 88 |
89 Scope(Scope* outer_scope, ScopeType type); | 89 Scope(Scope* outer_scope, ScopeType type); |
90 | 90 |
91 // Compute top scope and allocate variables. For lazy compilation the top | 91 // Compute top scope and allocate variables. For lazy compilation the top |
92 // scope only contains the single lazily compiled function, so this | 92 // scope only contains the single lazily compiled function, so this |
93 // doesn't re-allocate variables repeatedly. | 93 // doesn't re-allocate variables repeatedly. |
94 static bool Analyze(CompilationInfo* info); | 94 static bool Analyze(CompilationInfo* info); |
95 | 95 |
96 static Scope* DeserializeScopeChain(CompilationInfo* info, | 96 static Scope* DeserializeScopeChain(Context* context, Scope* global_scope); |
97 Scope* innermost_scope); | |
98 | 97 |
99 // The scope name is only used for printing/debugging. | 98 // The scope name is only used for printing/debugging. |
100 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } | 99 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } |
101 | 100 |
102 void Initialize(); | 101 void Initialize(); |
103 | 102 |
104 // Checks if the block scope is redundant, i.e. it does not contain any | 103 // Checks if the block scope is redundant, i.e. it does not contain any |
105 // block scoped declarations. In that case it is removed from the scope | 104 // block scoped declarations. In that case it is removed from the scope |
106 // tree and its children are reparented. | 105 // tree and its children are reparented. |
107 Scope* FinalizeBlockScope(); | 106 Scope* FinalizeBlockScope(); |
108 | 107 |
109 // --------------------------------------------------------------------------- | 108 // --------------------------------------------------------------------------- |
110 // Declarations | 109 // Declarations |
111 | 110 |
112 // 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. |
113 Variable* LocalLookup(Handle<String> name); | 112 Variable* LocalLookup(Handle<String> name); |
114 | 113 |
| 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 |
| 116 // the name of named function literal is kept in an intermediate scope |
| 117 // in between this scope and the next outer scope.) |
| 118 Variable* LookupFunctionVar(Handle<String> name); |
| 119 |
115 // Lookup a variable in this scope or outer scopes. | 120 // Lookup a variable in this scope or outer scopes. |
116 // Returns the variable or NULL if not found. | 121 // Returns the variable or NULL if not found. |
117 Variable* Lookup(Handle<String> name); | 122 Variable* Lookup(Handle<String> name); |
118 | 123 |
119 // Declare the function variable for a function literal. This variable | 124 // Declare the function variable for a function literal. This variable |
120 // is in an intermediate scope between this function scope and the the | 125 // is in an intermediate scope between this function scope and the the |
121 // outer scope. Only possible for function scopes; at most one variable. | 126 // outer scope. Only possible for function scopes; at most one variable. |
122 Variable* DeclareFunctionVar(Handle<String> name, VariableMode mode); | 127 Variable* DeclareFunctionVar(Handle<String> name, VariableMode mode); |
123 | 128 |
124 // Declare a parameter in this scope. When there are duplicated | 129 // Declare a parameter in this scope. When there are duplicated |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 ZoneList<Variable*>* context_locals); | 315 ZoneList<Variable*>* context_locals); |
311 | 316 |
312 // Resolve and fill in the allocation information for all variables | 317 // Resolve and fill in the allocation information for all variables |
313 // in this scopes. Must be called *after* all scopes have been | 318 // in this scopes. Must be called *after* all scopes have been |
314 // processed (parsed) to ensure that unresolved variables can be | 319 // processed (parsed) to ensure that unresolved variables can be |
315 // resolved properly. | 320 // resolved properly. |
316 // | 321 // |
317 // In the case of code compiled and run using 'eval', the context | 322 // In the case of code compiled and run using 'eval', the context |
318 // parameter is the context in which eval was called. In all other | 323 // parameter is the context in which eval was called. In all other |
319 // cases the context parameter is an empty handle. | 324 // cases the context parameter is an empty handle. |
320 void AllocateVariables(Handle<Context> context); | 325 void AllocateVariables(Scope* global_scope); |
321 | 326 |
322 // Current number of var or const locals. | 327 // Current number of var or const locals. |
323 int num_var_or_const() { return num_var_or_const_; } | 328 int num_var_or_const() { return num_var_or_const_; } |
324 | 329 |
325 // Result of variable allocation. | 330 // Result of variable allocation. |
326 int num_stack_slots() const { return num_stack_slots_; } | 331 int num_stack_slots() const { return num_stack_slots_; } |
327 int num_heap_slots() const { return num_heap_slots_; } | 332 int num_heap_slots() const { return num_heap_slots_; } |
328 | 333 |
329 int StackLocalCount() const; | 334 int StackLocalCount() const; |
330 int ContextLocalCount() const; | 335 int ContextLocalCount() const; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 // * The code is being executed as part of a call to 'eval' and the calling | 502 // * The code is being executed as part of a call to 'eval' and the calling |
498 // context chain contains either a variable binding for the name or it | 503 // context chain contains either a variable binding for the name or it |
499 // contains a 'with' context. | 504 // contains a 'with' context. |
500 DYNAMIC_LOOKUP | 505 DYNAMIC_LOOKUP |
501 }; | 506 }; |
502 | 507 |
503 // Lookup a variable reference given by name recursively starting with this | 508 // Lookup a variable reference given by name recursively starting with this |
504 // scope. If the code is executed because of a call to 'eval', the context | 509 // scope. If the code is executed because of a call to 'eval', the context |
505 // parameter should be set to the calling context of 'eval'. | 510 // parameter should be set to the calling context of 'eval'. |
506 Variable* LookupRecursive(Handle<String> name, | 511 Variable* LookupRecursive(Handle<String> name, |
507 Handle<Context> context, | |
508 BindingKind* binding_kind); | 512 BindingKind* binding_kind); |
509 void ResolveVariable(Scope* global_scope, | 513 void ResolveVariable(Scope* global_scope, |
510 Handle<Context> context, | |
511 VariableProxy* proxy); | 514 VariableProxy* proxy); |
512 void ResolveVariablesRecursively(Scope* global_scope, | 515 void ResolveVariablesRecursively(Scope* global_scope); |
513 Handle<Context> context); | |
514 | 516 |
515 // Scope analysis. | 517 // Scope analysis. |
516 bool PropagateScopeInfo(bool outer_scope_calls_non_strict_eval); | 518 bool PropagateScopeInfo(bool outer_scope_calls_non_strict_eval); |
517 bool HasTrivialContext() const; | 519 bool HasTrivialContext() const; |
518 | 520 |
519 // Predicates. | 521 // Predicates. |
520 bool MustAllocate(Variable* var); | 522 bool MustAllocate(Variable* var); |
521 bool MustAllocateInContext(Variable* var); | 523 bool MustAllocateInContext(Variable* var); |
522 bool HasArgumentsParameter(); | 524 bool HasArgumentsParameter(); |
523 | 525 |
(...skipping 20 matching lines...) Expand all Loading... |
544 } | 546 } |
545 | 547 |
546 void SetDefaults(ScopeType type, | 548 void SetDefaults(ScopeType type, |
547 Scope* outer_scope, | 549 Scope* outer_scope, |
548 Handle<ScopeInfo> scope_info); | 550 Handle<ScopeInfo> scope_info); |
549 }; | 551 }; |
550 | 552 |
551 } } // namespace v8::internal | 553 } } // namespace v8::internal |
552 | 554 |
553 #endif // V8_SCOPES_H_ | 555 #endif // V8_SCOPES_H_ |
OLD | NEW |