| OLD | NEW |
| 1 // Copyright 2012 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 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Remove a unresolved variable. During parsing, an unresolved variable | 181 // Remove a unresolved variable. During parsing, an unresolved variable |
| 182 // may have been added optimistically, but then only the variable name | 182 // may have been added optimistically, but then only the variable name |
| 183 // was used (typically for labels). If the variable was not declared, the | 183 // was used (typically for labels). If the variable was not declared, the |
| 184 // addition introduced a new unresolved variable which may end up being | 184 // addition introduced a new unresolved variable which may end up being |
| 185 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 185 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
| 186 // such a variable again if it was added; otherwise this is a no-op. | 186 // such a variable again if it was added; otherwise this is a no-op. |
| 187 void RemoveUnresolved(VariableProxy* var); | 187 void RemoveUnresolved(VariableProxy* var); |
| 188 | 188 |
| 189 // Creates a new internal variable in this scope. The name is only used |
| 190 // for printing and cannot be used to find the variable. In particular, |
| 191 // the only way to get hold of the temporary is by keeping the Variable* |
| 192 // around. |
| 193 Variable* NewInternal(Handle<String> name); |
| 194 |
| 189 // Creates a new temporary variable in this scope. The name is only used | 195 // Creates a new temporary variable in this scope. The name is only used |
| 190 // for printing and cannot be used to find the variable. In particular, | 196 // for printing and cannot be used to find the variable. In particular, |
| 191 // the only way to get hold of the temporary is by keeping the Variable* | 197 // the only way to get hold of the temporary is by keeping the Variable* |
| 192 // around. The name should not clash with a legitimate variable names. | 198 // around. The name should not clash with a legitimate variable names. |
| 193 Variable* NewTemporary(Handle<String> name); | 199 Variable* NewTemporary(Handle<String> name); |
| 194 | 200 |
| 195 // Adds the specific declaration node to the list of declarations in | 201 // Adds the specific declaration node to the list of declarations in |
| 196 // this scope. The declarations are processed as part of entering | 202 // this scope. The declarations are processed as part of entering |
| 197 // the scope; see codegen.cc:ProcessDeclarations. | 203 // the scope; see codegen.cc:ProcessDeclarations. |
| 198 void AddDeclaration(Declaration* declaration); | 204 void AddDeclaration(Declaration* declaration); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // Current number of var or const locals. | 368 // Current number of var or const locals. |
| 363 int num_var_or_const() { return num_var_or_const_; } | 369 int num_var_or_const() { return num_var_or_const_; } |
| 364 | 370 |
| 365 // Result of variable allocation. | 371 // Result of variable allocation. |
| 366 int num_stack_slots() const { return num_stack_slots_; } | 372 int num_stack_slots() const { return num_stack_slots_; } |
| 367 int num_heap_slots() const { return num_heap_slots_; } | 373 int num_heap_slots() const { return num_heap_slots_; } |
| 368 | 374 |
| 369 int StackLocalCount() const; | 375 int StackLocalCount() const; |
| 370 int ContextLocalCount() const; | 376 int ContextLocalCount() const; |
| 371 | 377 |
| 378 // For global scopes, the number of module literals (including nested ones). |
| 379 int num_modules() const { return num_modules_; } |
| 380 |
| 381 // For module scopes, the host scope's internal variable binding this module. |
| 382 Variable* module_var() const { return module_var_; } |
| 383 |
| 372 // Make sure this scope and all outer scopes are eagerly compiled. | 384 // Make sure this scope and all outer scopes are eagerly compiled. |
| 373 void ForceEagerCompilation() { force_eager_compilation_ = true; } | 385 void ForceEagerCompilation() { force_eager_compilation_ = true; } |
| 374 | 386 |
| 375 // Determine if we can use lazy compilation for this scope. | 387 // Determine if we can use lazy compilation for this scope. |
| 376 bool AllowsLazyCompilation() const; | 388 bool AllowsLazyCompilation() const; |
| 377 | 389 |
| 378 // Determine if we can use lazy compilation for this scope without a context. | 390 // Determine if we can use lazy compilation for this scope without a context. |
| 379 bool AllowsLazyCompilationWithoutContext() const; | 391 bool AllowsLazyCompilationWithoutContext() const; |
| 380 | 392 |
| 381 // True if the outer context of this scope is always the native context. | 393 // True if the outer context of this scope is always the native context. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 446 |
| 435 // Debugging support. | 447 // Debugging support. |
| 436 Handle<String> scope_name_; | 448 Handle<String> scope_name_; |
| 437 | 449 |
| 438 // The variables declared in this scope: | 450 // The variables declared in this scope: |
| 439 // | 451 // |
| 440 // All user-declared variables (incl. parameters). For global scopes | 452 // All user-declared variables (incl. parameters). For global scopes |
| 441 // variables may be implicitly 'declared' by being used (possibly in | 453 // variables may be implicitly 'declared' by being used (possibly in |
| 442 // an inner scope) with no intervening with statements or eval calls. | 454 // an inner scope) with no intervening with statements or eval calls. |
| 443 VariableMap variables_; | 455 VariableMap variables_; |
| 456 // Compiler-allocated (user-invisible) internals. |
| 457 ZoneList<Variable*> internals_; |
| 444 // Compiler-allocated (user-invisible) temporaries. | 458 // Compiler-allocated (user-invisible) temporaries. |
| 445 ZoneList<Variable*> temps_; | 459 ZoneList<Variable*> temps_; |
| 446 // Parameter list in source order. | 460 // Parameter list in source order. |
| 447 ZoneList<Variable*> params_; | 461 ZoneList<Variable*> params_; |
| 448 // Variables that must be looked up dynamically. | 462 // Variables that must be looked up dynamically. |
| 449 DynamicScopePart* dynamics_; | 463 DynamicScopePart* dynamics_; |
| 450 // Unresolved variables referred to from this scope. | 464 // Unresolved variables referred to from this scope. |
| 451 ZoneList<VariableProxy*> unresolved_; | 465 ZoneList<VariableProxy*> unresolved_; |
| 452 // Declarations. | 466 // Declarations. |
| 453 ZoneList<Declaration*> decls_; | 467 ZoneList<Declaration*> decls_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 // constructed based on a serialized scope info or a catch context). | 501 // constructed based on a serialized scope info or a catch context). |
| 488 bool already_resolved_; | 502 bool already_resolved_; |
| 489 | 503 |
| 490 // Computed as variables are declared. | 504 // Computed as variables are declared. |
| 491 int num_var_or_const_; | 505 int num_var_or_const_; |
| 492 | 506 |
| 493 // Computed via AllocateVariables; function, block and catch scopes only. | 507 // Computed via AllocateVariables; function, block and catch scopes only. |
| 494 int num_stack_slots_; | 508 int num_stack_slots_; |
| 495 int num_heap_slots_; | 509 int num_heap_slots_; |
| 496 | 510 |
| 511 // The number of modules (including nested ones). |
| 512 int num_modules_; |
| 513 |
| 514 // For module scopes, the host scope's internal variable binding this module. |
| 515 Variable* module_var_; |
| 516 |
| 497 // Serialized scope info support. | 517 // Serialized scope info support. |
| 498 Handle<ScopeInfo> scope_info_; | 518 Handle<ScopeInfo> scope_info_; |
| 499 bool already_resolved() { return already_resolved_; } | 519 bool already_resolved() { return already_resolved_; } |
| 500 | 520 |
| 501 // Create a non-local variable with a given name. | 521 // Create a non-local variable with a given name. |
| 502 // These variables are looked up dynamically at runtime. | 522 // These variables are looked up dynamically at runtime. |
| 503 Variable* NonLocal(Handle<String> name, VariableMode mode); | 523 Variable* NonLocal(Handle<String> name, VariableMode mode); |
| 504 | 524 |
| 505 // Variable resolution. | 525 // Variable resolution. |
| 506 // Possible results of a recursive variable lookup telling if and how a | 526 // Possible results of a recursive variable lookup telling if and how a |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 bool MustAllocateInContext(Variable* var); | 591 bool MustAllocateInContext(Variable* var); |
| 572 bool HasArgumentsParameter(); | 592 bool HasArgumentsParameter(); |
| 573 | 593 |
| 574 // Variable allocation. | 594 // Variable allocation. |
| 575 void AllocateStackSlot(Variable* var); | 595 void AllocateStackSlot(Variable* var); |
| 576 void AllocateHeapSlot(Variable* var); | 596 void AllocateHeapSlot(Variable* var); |
| 577 void AllocateParameterLocals(); | 597 void AllocateParameterLocals(); |
| 578 void AllocateNonParameterLocal(Variable* var); | 598 void AllocateNonParameterLocal(Variable* var); |
| 579 void AllocateNonParameterLocals(); | 599 void AllocateNonParameterLocals(); |
| 580 void AllocateVariablesRecursively(); | 600 void AllocateVariablesRecursively(); |
| 601 void AllocateModulesRecursively(Scope* host_scope); |
| 581 | 602 |
| 582 // Resolve and fill in the allocation information for all variables | 603 // Resolve and fill in the allocation information for all variables |
| 583 // in this scopes. Must be called *after* all scopes have been | 604 // in this scopes. Must be called *after* all scopes have been |
| 584 // processed (parsed) to ensure that unresolved variables can be | 605 // processed (parsed) to ensure that unresolved variables can be |
| 585 // resolved properly. | 606 // resolved properly. |
| 586 // | 607 // |
| 587 // In the case of code compiled and run using 'eval', the context | 608 // In the case of code compiled and run using 'eval', the context |
| 588 // parameter is the context in which eval was called. In all other | 609 // parameter is the context in which eval was called. In all other |
| 589 // cases the context parameter is an empty handle. | 610 // cases the context parameter is an empty handle. |
| 590 MUST_USE_RESULT | 611 MUST_USE_RESULT |
| 591 bool AllocateVariables(CompilationInfo* info, | 612 bool AllocateVariables(CompilationInfo* info, |
| 592 AstNodeFactory<AstNullVisitor>* factory); | 613 AstNodeFactory<AstNullVisitor>* factory); |
| 593 | 614 |
| 594 // Instance objects have to be created ahead of time (before code generation) | |
| 595 // because of potentially cyclic references between them. | |
| 596 // Linking also has to be a separate stage, since populating one object may | |
| 597 // potentially require (forward) references to others. | |
| 598 void AllocateModules(CompilationInfo* info); | |
| 599 void LinkModules(CompilationInfo* info); | |
| 600 | |
| 601 private: | 615 private: |
| 602 // Construct a scope based on the scope info. | 616 // Construct a scope based on the scope info. |
| 603 Scope(Scope* inner_scope, ScopeType type, Handle<ScopeInfo> scope_info, | 617 Scope(Scope* inner_scope, ScopeType type, Handle<ScopeInfo> scope_info, |
| 604 Zone* zone); | 618 Zone* zone); |
| 605 | 619 |
| 606 // Construct a catch scope with a binding for the name. | 620 // Construct a catch scope with a binding for the name. |
| 607 Scope(Scope* inner_scope, Handle<String> catch_variable_name, Zone* zone); | 621 Scope(Scope* inner_scope, Handle<String> catch_variable_name, Zone* zone); |
| 608 | 622 |
| 609 void AddInnerScope(Scope* inner_scope) { | 623 void AddInnerScope(Scope* inner_scope) { |
| 610 if (inner_scope != NULL) { | 624 if (inner_scope != NULL) { |
| 611 inner_scopes_.Add(inner_scope, zone_); | 625 inner_scopes_.Add(inner_scope, zone_); |
| 612 inner_scope->outer_scope_ = this; | 626 inner_scope->outer_scope_ = this; |
| 613 } | 627 } |
| 614 } | 628 } |
| 615 | 629 |
| 616 void SetDefaults(ScopeType type, | 630 void SetDefaults(ScopeType type, |
| 617 Scope* outer_scope, | 631 Scope* outer_scope, |
| 618 Handle<ScopeInfo> scope_info); | 632 Handle<ScopeInfo> scope_info); |
| 619 | 633 |
| 620 Zone* zone_; | 634 Zone* zone_; |
| 621 }; | 635 }; |
| 622 | 636 |
| 623 } } // namespace v8::internal | 637 } } // namespace v8::internal |
| 624 | 638 |
| 625 #endif // V8_SCOPES_H_ | 639 #endif // V8_SCOPES_H_ |
| OLD | NEW |