| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // Declarations list. | 294 // Declarations list. |
| 295 ZoneList<Declaration*>* declarations() { return &decls_; } | 295 ZoneList<Declaration*>* declarations() { return &decls_; } |
| 296 | 296 |
| 297 // Inner scope list. | 297 // Inner scope list. |
| 298 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } | 298 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } |
| 299 | 299 |
| 300 // --------------------------------------------------------------------------- | 300 // --------------------------------------------------------------------------- |
| 301 // Variable allocation. | 301 // Variable allocation. |
| 302 | 302 |
| 303 // Collect all used locals in this scope. | 303 // Collect all used locals in this scope. |
| 304 template<class Allocator> | 304 void CollectUsedVariables(ZoneList<Variable*>* locals); |
| 305 void CollectUsedVariables(List<Variable*, Allocator>* locals); | |
| 306 | 305 |
| 307 // Resolve and fill in the allocation information for all variables | 306 // Resolve and fill in the allocation information for all variables |
| 308 // in this scopes. Must be called *after* all scopes have been | 307 // in this scopes. Must be called *after* all scopes have been |
| 309 // processed (parsed) to ensure that unresolved variables can be | 308 // processed (parsed) to ensure that unresolved variables can be |
| 310 // resolved properly. | 309 // resolved properly. |
| 311 // | 310 // |
| 312 // In the case of code compiled and run using 'eval', the context | 311 // In the case of code compiled and run using 'eval', the context |
| 313 // parameter is the context in which eval was called. In all other | 312 // parameter is the context in which eval was called. In all other |
| 314 // cases the context parameter is an empty handle. | 313 // cases the context parameter is an empty handle. |
| 315 void AllocateVariables(Handle<Context> context); | 314 void AllocateVariables(Handle<Context> context); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 330 // True if the outer context of this scope is always the global context. | 329 // True if the outer context of this scope is always the global context. |
| 331 bool HasTrivialOuterContext() const; | 330 bool HasTrivialOuterContext() const; |
| 332 | 331 |
| 333 // The number of contexts between this and scope; zero if this == scope. | 332 // The number of contexts between this and scope; zero if this == scope. |
| 334 int ContextChainLength(Scope* scope); | 333 int ContextChainLength(Scope* scope); |
| 335 | 334 |
| 336 // Find the first function, global, or eval scope. This is the scope | 335 // Find the first function, global, or eval scope. This is the scope |
| 337 // where var declarations will be hoisted to in the implementation. | 336 // where var declarations will be hoisted to in the implementation. |
| 338 Scope* DeclarationScope(); | 337 Scope* DeclarationScope(); |
| 339 | 338 |
| 340 Handle<SerializedScopeInfo> GetSerializedScopeInfo(); | 339 Handle<ScopeInfo> GetScopeInfo(); |
| 341 | 340 |
| 342 // Get the chain of nested scopes within this scope for the source statement | 341 // Get the chain of nested scopes within this scope for the source statement |
| 343 // position. The scopes will be added to the list from the outermost scope to | 342 // position. The scopes will be added to the list from the outermost scope to |
| 344 // the innermost scope. Only nested block, catch or with scopes are tracked | 343 // the innermost scope. Only nested block, catch or with scopes are tracked |
| 345 // and will be returned, but no inner function scopes. | 344 // and will be returned, but no inner function scopes. |
| 346 void GetNestedScopeChain(List<Handle<SerializedScopeInfo> >* chain, | 345 void GetNestedScopeChain(List<Handle<ScopeInfo> >* chain, |
| 347 int statement_position); | 346 int statement_position); |
| 348 | 347 |
| 349 // --------------------------------------------------------------------------- | 348 // --------------------------------------------------------------------------- |
| 350 // Strict mode support. | 349 // Strict mode support. |
| 351 bool IsDeclared(Handle<String> name) { | 350 bool IsDeclared(Handle<String> name) { |
| 352 // During formal parameter list parsing the scope only contains | 351 // During formal parameter list parsing the scope only contains |
| 353 // two variables inserted at initialization: "this" and "arguments". | 352 // two variables inserted at initialization: "this" and "arguments". |
| 354 // "this" is an invalid parameter name and "arguments" is invalid parameter | 353 // "this" is an invalid parameter name and "arguments" is invalid parameter |
| 355 // name in strict mode. Therefore looking up with the map which includes | 354 // name in strict mode. Therefore looking up with the map which includes |
| 356 // "this" and "arguments" in addition to all formal parameters is safe. | 355 // "this" and "arguments" in addition to all formal parameters is safe. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 // constructed based on a serialized scope info or a catch context). | 430 // constructed based on a serialized scope info or a catch context). |
| 432 bool already_resolved_; | 431 bool already_resolved_; |
| 433 | 432 |
| 434 // Computed as variables are declared. | 433 // Computed as variables are declared. |
| 435 int num_var_or_const_; | 434 int num_var_or_const_; |
| 436 | 435 |
| 437 // Computed via AllocateVariables; function, block and catch scopes only. | 436 // Computed via AllocateVariables; function, block and catch scopes only. |
| 438 int num_stack_slots_; | 437 int num_stack_slots_; |
| 439 int num_heap_slots_; | 438 int num_heap_slots_; |
| 440 | 439 |
| 441 // Serialized scopes support. | 440 // Serialized scope info support. |
| 442 Handle<SerializedScopeInfo> scope_info_; | 441 Handle<ScopeInfo> scope_info_; |
| 443 bool already_resolved() { return already_resolved_; } | 442 bool already_resolved() { return already_resolved_; } |
| 444 | 443 |
| 445 // Create a non-local variable with a given name. | 444 // Create a non-local variable with a given name. |
| 446 // These variables are looked up dynamically at runtime. | 445 // These variables are looked up dynamically at runtime. |
| 447 Variable* NonLocal(Handle<String> name, VariableMode mode); | 446 Variable* NonLocal(Handle<String> name, VariableMode mode); |
| 448 | 447 |
| 449 // Variable resolution. | 448 // Variable resolution. |
| 450 // Possible results of a recursive variable lookup telling if and how a | 449 // Possible results of a recursive variable lookup telling if and how a |
| 451 // variable is bound. These are returned in the output parameter *binding_kind | 450 // variable is bound. These are returned in the output parameter *binding_kind |
| 452 // of the LookupRecursive function. | 451 // of the LookupRecursive function. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // Variable allocation. | 515 // Variable allocation. |
| 517 void AllocateStackSlot(Variable* var); | 516 void AllocateStackSlot(Variable* var); |
| 518 void AllocateHeapSlot(Variable* var); | 517 void AllocateHeapSlot(Variable* var); |
| 519 void AllocateParameterLocals(); | 518 void AllocateParameterLocals(); |
| 520 void AllocateNonParameterLocal(Variable* var); | 519 void AllocateNonParameterLocal(Variable* var); |
| 521 void AllocateNonParameterLocals(); | 520 void AllocateNonParameterLocals(); |
| 522 void AllocateVariablesRecursively(); | 521 void AllocateVariablesRecursively(); |
| 523 | 522 |
| 524 private: | 523 private: |
| 525 // Construct a scope based on the scope info. | 524 // Construct a scope based on the scope info. |
| 526 Scope(Scope* inner_scope, | 525 Scope(Scope* inner_scope, ScopeType type, Handle<ScopeInfo> scope_info); |
| 527 ScopeType type, | |
| 528 Handle<SerializedScopeInfo> scope_info); | |
| 529 | 526 |
| 530 // Construct a catch scope with a binding for the name. | 527 // Construct a catch scope with a binding for the name. |
| 531 Scope(Scope* inner_scope, Handle<String> catch_variable_name); | 528 Scope(Scope* inner_scope, Handle<String> catch_variable_name); |
| 532 | 529 |
| 533 void AddInnerScope(Scope* inner_scope) { | 530 void AddInnerScope(Scope* inner_scope) { |
| 534 if (inner_scope != NULL) { | 531 if (inner_scope != NULL) { |
| 535 inner_scopes_.Add(inner_scope); | 532 inner_scopes_.Add(inner_scope); |
| 536 inner_scope->outer_scope_ = this; | 533 inner_scope->outer_scope_ = this; |
| 537 } | 534 } |
| 538 } | 535 } |
| 539 | 536 |
| 540 void SetDefaults(ScopeType type, | 537 void SetDefaults(ScopeType type, |
| 541 Scope* outer_scope, | 538 Scope* outer_scope, |
| 542 Handle<SerializedScopeInfo> scope_info); | 539 Handle<ScopeInfo> scope_info); |
| 543 }; | 540 }; |
| 544 | 541 |
| 545 } } // namespace v8::internal | 542 } } // namespace v8::internal |
| 546 | 543 |
| 547 #endif // V8_SCOPES_H_ | 544 #endif // V8_SCOPES_H_ |
| OLD | NEW |