| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 void RecordWithStatement() { scope_contains_with_ = true; } | 180 void RecordWithStatement() { scope_contains_with_ = true; } |
| 181 | 181 |
| 182 // Inform the scope that the corresponding code contains an eval call. | 182 // Inform the scope that the corresponding code contains an eval call. |
| 183 void RecordEvalCall() { scope_calls_eval_ = true; } | 183 void RecordEvalCall() { scope_calls_eval_ = true; } |
| 184 | 184 |
| 185 | 185 |
| 186 // --------------------------------------------------------------------------- | 186 // --------------------------------------------------------------------------- |
| 187 // Predicates. | 187 // Predicates. |
| 188 | 188 |
| 189 // Specific scope types. | 189 // Specific scope types. |
| 190 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } | 190 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } |
| 191 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } | 191 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } |
| 192 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } | 192 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } |
| 193 | 193 |
| 194 // Information about which scopes calls eval. | 194 // Information about which scopes calls eval. |
| 195 bool calls_eval() const { return scope_calls_eval_; } | 195 bool calls_eval() const { return scope_calls_eval_; } |
| 196 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; } | 196 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; } |
| 197 | 197 |
| 198 // Is this scope inside a with statement. | 198 // Is this scope inside a with statement. |
| 199 bool inside_with() const { return scope_inside_with_; } | 199 bool inside_with() const { return scope_inside_with_; } |
| 200 // Does this scope contain a with statement. | 200 // Does this scope contain a with statement. |
| 201 bool contains_with() const { return scope_contains_with_; } | 201 bool contains_with() const { return scope_contains_with_; } |
| 202 | 202 |
| 203 // The scope immediately surrounding this scope, or NULL. | 203 // The scope immediately surrounding this scope, or NULL. |
| 204 Scope* outer_scope() const { return outer_scope_; } | 204 Scope* outer_scope() const { return outer_scope_; } |
| 205 | 205 |
| 206 // --------------------------------------------------------------------------- | 206 // --------------------------------------------------------------------------- |
| 207 // Accessors. | 207 // Accessors. |
| 208 | 208 |
| 209 // A new variable proxy corresponding to the (function) receiver. | 209 // A new variable proxy corresponding to the (function) receiver. |
| 210 VariableProxy* receiver() const { | 210 VariableProxy* receiver() const { |
| 211 VariableProxy* proxy = | 211 VariableProxy* proxy = |
| 212 new VariableProxy(Factory::this_symbol(), true, false); | 212 new VariableProxy(Factory::this_symbol(), true, false); |
| 213 proxy->BindTo(receiver_); | 213 proxy->BindTo(receiver_); |
| 214 return proxy; | 214 return proxy; |
| 215 } | 215 } |
| 216 | 216 |
| 217 // The variable holding the function literal for named function | 217 // The variable holding the function literal for named function |
| 218 // literals, or NULL. | 218 // literals, or NULL. |
| 219 // Only valid for function scopes. | 219 // Only valid for function scopes. |
| 220 Variable* function() const { | 220 Variable* function() const { |
| 221 ASSERT(is_function_scope()); | 221 ASSERT(is_function_scope()); |
| 222 return function_; | 222 return function_; |
| 223 } | 223 } |
| 224 | 224 |
| 225 // Parameters. The left-most parameter has index 0. | 225 // Parameters. The left-most parameter has index 0. |
| 226 // Only valid for function scopes. | 226 // Only valid for function scopes. |
| 227 Variable* parameter(int index) const { | 227 Variable* parameter(int index) const { |
| 228 ASSERT(is_function_scope()); | 228 ASSERT(is_function_scope()); |
| 229 return params_[index]; | 229 return params_[index]; |
| 230 } | 230 } |
| 231 | 231 |
| 232 int num_parameters() const { return params_.length(); } | 232 int num_parameters() const { return params_.length(); } |
| 233 | 233 |
| 234 // The local variable 'arguments' if we need to allocate it; NULL otherwise. | 234 // The local variable 'arguments' if we need to allocate it; NULL otherwise. |
| 235 // If arguments() exist, arguments_shadow() exists, too. | 235 // If arguments() exist, arguments_shadow() exists, too. |
| 236 Variable* arguments() const { return arguments_; } | 236 Variable* arguments() const { return arguments_; } |
| 237 | 237 |
| 238 // The '.arguments' shadow variable if we need to allocate it; NULL otherwise. | 238 // The '.arguments' shadow variable if we need to allocate it; NULL otherwise. |
| 239 // If arguments_shadow() exist, arguments() exists, too. | 239 // If arguments_shadow() exist, arguments() exists, too. |
| 240 Variable* arguments_shadow() const { return arguments_shadow_; } | 240 Variable* arguments_shadow() const { return arguments_shadow_; } |
| 241 | 241 |
| 242 // Declarations list. | 242 // Declarations list. |
| 243 ZoneList<Declaration*>* declarations() { return &decls_; } | 243 ZoneList<Declaration*>* declarations() { return &decls_; } |
| 244 | 244 |
| 245 | 245 |
| 246 | 246 |
| 247 // --------------------------------------------------------------------------- | 247 // --------------------------------------------------------------------------- |
| 248 // Variable allocation. | 248 // Variable allocation. |
| 249 | 249 |
| 250 // Collect all used locals in this scope. | 250 // Collect all used locals in this scope. |
| 251 template<class Allocator> | 251 template<class Allocator> |
| 252 void CollectUsedVariables(List<Variable*, Allocator>* locals); | 252 void CollectUsedVariables(List<Variable*, Allocator>* locals); |
| 253 | 253 |
| 254 // Resolve and fill in the allocation information for all variables | 254 // Resolve and fill in the allocation information for all variables |
| 255 // in this scopes. Must be called *after* all scopes have been | 255 // in this scopes. Must be called *after* all scopes have been |
| 256 // processed (parsed) to ensure that unresolved variables can be | 256 // processed (parsed) to ensure that unresolved variables can be |
| 257 // resolved properly. | 257 // resolved properly. |
| 258 // | 258 // |
| 259 // In the case of code compiled and run using 'eval', the context | 259 // In the case of code compiled and run using 'eval', the context |
| 260 // parameter is the context in which eval was called. In all other | 260 // parameter is the context in which eval was called. In all other |
| 261 // cases the context parameter is an empty handle. | 261 // cases the context parameter is an empty handle. |
| 262 void AllocateVariables(Handle<Context> context); | 262 void AllocateVariables(Handle<Context> context); |
| 263 | 263 |
| 264 // Result of variable allocation. | 264 // Result of variable allocation. |
| 265 int num_stack_slots() const { return num_stack_slots_; } | 265 int num_stack_slots() const { return num_stack_slots_; } |
| 266 int num_heap_slots() const { return num_heap_slots_; } | 266 int num_heap_slots() const { return num_heap_slots_; } |
| 267 | 267 |
| 268 // Make sure this scope and all outer scopes are eagerly compiled. | 268 // Make sure this scope and all outer scopes are eagerly compiled. |
| 269 void ForceEagerCompilation() { force_eager_compilation_ = true; } | 269 void ForceEagerCompilation() { force_eager_compilation_ = true; } |
| 270 | 270 |
| 271 // Determine if we can use lazy compilation for this scope. | 271 // Determine if we can use lazy compilation for this scope. |
| 272 bool AllowsLazyCompilation() const; | 272 bool AllowsLazyCompilation() const; |
| 273 | 273 |
| 274 // True if the outer context of this scope is always the global context. | 274 // True if the outer context of this scope is always the global context. |
| 275 bool HasTrivialOuterContext() const; | 275 bool HasTrivialOuterContext() const; |
| 276 | 276 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) { | 391 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) { |
| 392 return NULL; | 392 return NULL; |
| 393 } | 393 } |
| 394 virtual VariableProxy* NewTemporary(Handle<String> name) { return NULL; } | 394 virtual VariableProxy* NewTemporary(Handle<String> name) { return NULL; } |
| 395 }; | 395 }; |
| 396 | 396 |
| 397 | 397 |
| 398 } } // namespace v8::internal | 398 } } // namespace v8::internal |
| 399 | 399 |
| 400 #endif // V8_SCOPES_H_ | 400 #endif // V8_SCOPES_H_ |
| OLD | NEW |