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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 Scope(Scope* outer_scope, Type type); | 98 Scope(Scope* outer_scope, Type type); |
99 | 99 |
100 virtual ~Scope() { } | 100 virtual ~Scope() { } |
101 | 101 |
102 // Compute top scope and allocate variables. For lazy compilation the top | 102 // Compute top scope and allocate variables. For lazy compilation the top |
103 // scope only contains the single lazily compiled function, so this | 103 // scope only contains the single lazily compiled function, so this |
104 // doesn't re-allocate variables repeatedly. | 104 // doesn't re-allocate variables repeatedly. |
105 static bool Analyze(CompilationInfo* info); | 105 static bool Analyze(CompilationInfo* info); |
106 | 106 |
| 107 static Scope* DeserializeScopeChain(CompilationInfo* info, |
| 108 Scope* innermost_scope); |
| 109 |
107 // The scope name is only used for printing/debugging. | 110 // The scope name is only used for printing/debugging. |
108 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } | 111 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } |
109 | 112 |
110 virtual void Initialize(bool inside_with); | 113 virtual void Initialize(bool inside_with); |
111 | 114 |
112 // Called just before leaving a scope. | 115 // Called just before leaving a scope. |
113 virtual void Leave() { | 116 virtual void Leave() { |
114 // No cleanup or fixup necessary. | 117 // No cleanup or fixup necessary. |
115 } | 118 } |
116 | 119 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively | 314 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively |
312 #endif | 315 #endif |
313 | 316 |
314 // --------------------------------------------------------------------------- | 317 // --------------------------------------------------------------------------- |
315 // Implementation. | 318 // Implementation. |
316 protected: | 319 protected: |
317 friend class ParserFactory; | 320 friend class ParserFactory; |
318 | 321 |
319 explicit Scope(Type type); | 322 explicit Scope(Type type); |
320 | 323 |
321 void InsertAfterScope(Scope* scope) { | |
322 inner_scopes_.Add(scope); | |
323 outer_scope_ = scope->outer_scope_; | |
324 outer_scope_->inner_scopes_.RemoveElement(scope); | |
325 outer_scope_->inner_scopes_.Add(this); | |
326 scope->outer_scope_ = this; | |
327 } | |
328 | |
329 // Scope tree. | 324 // Scope tree. |
330 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 325 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
331 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes | 326 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes |
332 | 327 |
333 // The scope type. | 328 // The scope type. |
334 Type type_; | 329 Type type_; |
335 | 330 |
336 // Debugging support. | 331 // Debugging support. |
337 Handle<String> scope_name_; | 332 Handle<String> scope_name_; |
338 | 333 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 void AllocateStackSlot(Variable* var); | 407 void AllocateStackSlot(Variable* var); |
413 void AllocateHeapSlot(Variable* var); | 408 void AllocateHeapSlot(Variable* var); |
414 void AllocateParameterLocals(); | 409 void AllocateParameterLocals(); |
415 void AllocateNonParameterLocal(Variable* var); | 410 void AllocateNonParameterLocal(Variable* var); |
416 void AllocateNonParameterLocals(); | 411 void AllocateNonParameterLocals(); |
417 void AllocateVariablesRecursively(); | 412 void AllocateVariablesRecursively(); |
418 | 413 |
419 private: | 414 private: |
420 Scope(Scope* inner_scope, SerializedScopeInfo* scope_info); | 415 Scope(Scope* inner_scope, SerializedScopeInfo* scope_info); |
421 | 416 |
| 417 void AddInnerScope(Scope* inner_scope) { |
| 418 if (inner_scope != NULL) { |
| 419 inner_scopes_.Add(inner_scope); |
| 420 inner_scope->outer_scope_ = this; |
| 421 } |
| 422 } |
| 423 |
422 void SetDefaults(Type type, | 424 void SetDefaults(Type type, |
423 Scope* outer_scope, | 425 Scope* outer_scope, |
424 SerializedScopeInfo* scope_info) { | 426 SerializedScopeInfo* scope_info) { |
425 outer_scope_ = outer_scope; | 427 outer_scope_ = outer_scope; |
426 type_ = type; | 428 type_ = type; |
427 scope_name_ = Factory::empty_symbol(); | 429 scope_name_ = Factory::empty_symbol(); |
428 dynamics_ = NULL; | 430 dynamics_ = NULL; |
429 receiver_ = NULL; | 431 receiver_ = NULL; |
430 function_ = NULL; | 432 function_ = NULL; |
431 arguments_ = NULL; | 433 arguments_ = NULL; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 int nesting_level_; | 495 int nesting_level_; |
494 // Nesting level of outermost scope that is contained in a with statement, | 496 // Nesting level of outermost scope that is contained in a with statement, |
495 // or kNotInsideWith if there are no with's around the current scope. | 497 // or kNotInsideWith if there are no with's around the current scope. |
496 int inside_with_level_; | 498 int inside_with_level_; |
497 }; | 499 }; |
498 | 500 |
499 | 501 |
500 } } // namespace v8::internal | 502 } } // namespace v8::internal |
501 | 503 |
502 #endif // V8_SCOPES_H_ | 504 #endif // V8_SCOPES_H_ |
OLD | NEW |