| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // Determine if we can use lazy compilation for this scope. | 282 // Determine if we can use lazy compilation for this scope. |
| 283 bool AllowsLazyCompilation() const; | 283 bool AllowsLazyCompilation() const; |
| 284 | 284 |
| 285 // True if the outer context of this scope is always the global context. | 285 // True if the outer context of this scope is always the global context. |
| 286 virtual bool HasTrivialOuterContext() const; | 286 virtual bool HasTrivialOuterContext() const; |
| 287 | 287 |
| 288 // The number of contexts between this and scope; zero if this == scope. | 288 // The number of contexts between this and scope; zero if this == scope. |
| 289 int ContextChainLength(Scope* scope); | 289 int ContextChainLength(Scope* scope); |
| 290 | 290 |
| 291 // --------------------------------------------------------------------------- | 291 // --------------------------------------------------------------------------- |
| 292 // Strict mode support. |
| 293 bool IsDeclared(Handle<String> name) { |
| 294 // During formal parameter list parsing the scope only contains |
| 295 // two variables inserted at initialization: "this" and "arguments". |
| 296 // "this" is an invalid parameter name and "arguments" is invalid parameter |
| 297 // name in strict mode. Therefore looking up with the map which includes |
| 298 // "this" and "arguments" in addition to all formal parameters is safe. |
| 299 return variables_.Lookup(name) != NULL; |
| 300 } |
| 301 |
| 302 // --------------------------------------------------------------------------- |
| 292 // Debugging. | 303 // Debugging. |
| 293 | 304 |
| 294 #ifdef DEBUG | 305 #ifdef DEBUG |
| 295 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively | 306 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively |
| 296 #endif | 307 #endif |
| 297 | 308 |
| 298 // --------------------------------------------------------------------------- | 309 // --------------------------------------------------------------------------- |
| 299 // Implementation. | 310 // Implementation. |
| 300 protected: | 311 protected: |
| 301 friend class ParserFactory; | 312 friend class ParserFactory; |
| 302 | 313 |
| 303 explicit Scope(Type type); | 314 explicit Scope(Type type); |
| 304 | 315 |
| 316 void InsertAfterScope(Scope* scope) { |
| 317 inner_scopes_.Add(scope); |
| 318 outer_scope_ = scope->outer_scope_; |
| 319 outer_scope_->inner_scopes_.RemoveElement(scope); |
| 320 outer_scope_->inner_scopes_.Add(this); |
| 321 scope->outer_scope_ = this; |
| 322 } |
| 323 |
| 305 // Scope tree. | 324 // Scope tree. |
| 306 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 325 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
| 307 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes | 326 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes |
| 308 | 327 |
| 309 // The scope type. | 328 // The scope type. |
| 310 Type type_; | 329 Type type_; |
| 311 | 330 |
| 312 // Debugging support. | 331 // Debugging support. |
| 313 Handle<String> scope_name_; | 332 Handle<String> scope_name_; |
| 314 | 333 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 // Computed via PropagateScopeInfo. | 367 // Computed via PropagateScopeInfo. |
| 349 bool outer_scope_calls_eval_; | 368 bool outer_scope_calls_eval_; |
| 350 bool inner_scope_calls_eval_; | 369 bool inner_scope_calls_eval_; |
| 351 bool outer_scope_is_eval_scope_; | 370 bool outer_scope_is_eval_scope_; |
| 352 bool force_eager_compilation_; | 371 bool force_eager_compilation_; |
| 353 | 372 |
| 354 // Computed via AllocateVariables; function scopes only. | 373 // Computed via AllocateVariables; function scopes only. |
| 355 int num_stack_slots_; | 374 int num_stack_slots_; |
| 356 int num_heap_slots_; | 375 int num_heap_slots_; |
| 357 | 376 |
| 377 // Serialized scopes support. |
| 378 SerializedScopeInfo* scope_info_; |
| 379 bool resolved() { return scope_info_ != NULL; } |
| 380 |
| 358 // Create a non-local variable with a given name. | 381 // Create a non-local variable with a given name. |
| 359 // These variables are looked up dynamically at runtime. | 382 // These variables are looked up dynamically at runtime. |
| 360 Variable* NonLocal(Handle<String> name, Variable::Mode mode); | 383 Variable* NonLocal(Handle<String> name, Variable::Mode mode); |
| 361 | 384 |
| 362 // Variable resolution. | 385 // Variable resolution. |
| 363 Variable* LookupRecursive(Handle<String> name, | 386 Variable* LookupRecursive(Handle<String> name, |
| 364 bool inner_lookup, | 387 bool inner_lookup, |
| 365 Variable** invalidated_local); | 388 Variable** invalidated_local); |
| 366 void ResolveVariable(Scope* global_scope, | 389 void ResolveVariable(Scope* global_scope, |
| 367 Handle<Context> context, | 390 Handle<Context> context, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 379 bool MustAllocateInContext(Variable* var); | 402 bool MustAllocateInContext(Variable* var); |
| 380 bool HasArgumentsParameter(); | 403 bool HasArgumentsParameter(); |
| 381 | 404 |
| 382 // Variable allocation. | 405 // Variable allocation. |
| 383 void AllocateStackSlot(Variable* var); | 406 void AllocateStackSlot(Variable* var); |
| 384 void AllocateHeapSlot(Variable* var); | 407 void AllocateHeapSlot(Variable* var); |
| 385 void AllocateParameterLocals(); | 408 void AllocateParameterLocals(); |
| 386 void AllocateNonParameterLocal(Variable* var); | 409 void AllocateNonParameterLocal(Variable* var); |
| 387 void AllocateNonParameterLocals(); | 410 void AllocateNonParameterLocals(); |
| 388 void AllocateVariablesRecursively(); | 411 void AllocateVariablesRecursively(); |
| 412 |
| 413 private: |
| 414 Scope(Scope* inner_scope, SerializedScopeInfo* scope_info); |
| 415 |
| 416 void SetDefaults(Type type, |
| 417 Scope* outer_scope, |
| 418 SerializedScopeInfo* scope_info) { |
| 419 outer_scope_ = outer_scope; |
| 420 type_ = type; |
| 421 scope_name_ = Factory::empty_symbol(); |
| 422 dynamics_ = NULL; |
| 423 receiver_ = NULL; |
| 424 function_ = NULL; |
| 425 arguments_ = NULL; |
| 426 arguments_shadow_ = NULL; |
| 427 illegal_redecl_ = NULL; |
| 428 scope_inside_with_ = false; |
| 429 scope_contains_with_ = false; |
| 430 scope_calls_eval_ = false; |
| 431 outer_scope_calls_eval_ = false; |
| 432 inner_scope_calls_eval_ = false; |
| 433 outer_scope_is_eval_scope_ = false; |
| 434 force_eager_compilation_ = false; |
| 435 num_stack_slots_ = 0; |
| 436 num_heap_slots_ = 0; |
| 437 scope_info_ = scope_info; |
| 438 } |
| 389 }; | 439 }; |
| 390 | 440 |
| 391 | 441 |
| 392 // Scope used during pre-parsing. | 442 // Scope used during pre-parsing. |
| 393 class DummyScope : public Scope { | 443 class DummyScope : public Scope { |
| 394 public: | 444 public: |
| 395 DummyScope() | 445 DummyScope() |
| 396 : Scope(GLOBAL_SCOPE), | 446 : Scope(GLOBAL_SCOPE), |
| 397 nesting_level_(1), // Allows us to Leave the initial scope. | 447 nesting_level_(1), // Allows us to Leave the initial scope. |
| 398 inside_with_level_(kNotInsideWith) { | 448 inside_with_level_(kNotInsideWith) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 int nesting_level_; | 485 int nesting_level_; |
| 436 // Nesting level of outermost scope that is contained in a with statement, | 486 // Nesting level of outermost scope that is contained in a with statement, |
| 437 // or kNotInsideWith if there are no with's around the current scope. | 487 // or kNotInsideWith if there are no with's around the current scope. |
| 438 int inside_with_level_; | 488 int inside_with_level_; |
| 439 }; | 489 }; |
| 440 | 490 |
| 441 | 491 |
| 442 } } // namespace v8::internal | 492 } } // namespace v8::internal |
| 443 | 493 |
| 444 #endif // V8_SCOPES_H_ | 494 #endif // V8_SCOPES_H_ |
| OLD | NEW |