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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // corresponding variable (though some are bound during parse time). Variable | 90 // corresponding variable (though some are bound during parse time). Variable |
91 // allocation binds each unresolved VariableProxy to one Variable and assigns | 91 // allocation binds each unresolved VariableProxy to one Variable and assigns |
92 // a location. Note that many VariableProxy nodes may refer to the same Java- | 92 // a location. Note that many VariableProxy nodes may refer to the same Java- |
93 // Script variable. | 93 // Script variable. |
94 | 94 |
95 class Scope: public ZoneObject { | 95 class Scope: public ZoneObject { |
96 public: | 96 public: |
97 // --------------------------------------------------------------------------- | 97 // --------------------------------------------------------------------------- |
98 // Construction | 98 // Construction |
99 | 99 |
100 Scope(Scope* outer_scope, ScopeType type, Zone* zone); | 100 Scope(Scope* outer_scope, ScopeType scope_type, Zone* zone); |
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(Context* context, Scope* global_scope, | 107 static Scope* DeserializeScopeChain(Context* context, Scope* global_scope, |
108 Zone* zone); | 108 Zone* zone); |
109 | 109 |
110 // The scope name is only used for printing/debugging. | 110 // The scope name is only used for printing/debugging. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 force_context_allocation_ = true; | 275 force_context_allocation_ = true; |
276 } | 276 } |
277 bool has_forced_context_allocation() const { | 277 bool has_forced_context_allocation() const { |
278 return force_context_allocation_; | 278 return force_context_allocation_; |
279 } | 279 } |
280 | 280 |
281 // --------------------------------------------------------------------------- | 281 // --------------------------------------------------------------------------- |
282 // Predicates. | 282 // Predicates. |
283 | 283 |
284 // Specific scope types. | 284 // Specific scope types. |
285 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } | 285 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; } |
286 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } | 286 bool is_function_scope() const { return scope_type_ == FUNCTION_SCOPE; } |
287 bool is_module_scope() const { return type_ == MODULE_SCOPE; } | 287 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } |
288 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } | 288 bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; } |
289 bool is_catch_scope() const { return type_ == CATCH_SCOPE; } | 289 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } |
290 bool is_block_scope() const { return type_ == BLOCK_SCOPE; } | 290 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } |
291 bool is_with_scope() const { return type_ == WITH_SCOPE; } | 291 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } |
292 bool is_declaration_scope() const { | 292 bool is_declaration_scope() const { |
293 return is_eval_scope() || is_function_scope() || | 293 return is_eval_scope() || is_function_scope() || |
294 is_module_scope() || is_global_scope(); | 294 is_module_scope() || is_global_scope(); |
295 } | 295 } |
296 bool is_classic_mode() const { | 296 bool is_classic_mode() const { |
297 return language_mode() == CLASSIC_MODE; | 297 return language_mode() == CLASSIC_MODE; |
298 } | 298 } |
299 bool is_extended_mode() const { | 299 bool is_extended_mode() const { |
300 return language_mode() == EXTENDED_MODE; | 300 return language_mode() == EXTENDED_MODE; |
301 } | 301 } |
(...skipping 12 matching lines...) Expand all Loading... |
314 | 314 |
315 // Is this scope inside a with statement. | 315 // Is this scope inside a with statement. |
316 bool inside_with() const { return scope_inside_with_; } | 316 bool inside_with() const { return scope_inside_with_; } |
317 // Does this scope contain a with statement. | 317 // Does this scope contain a with statement. |
318 bool contains_with() const { return scope_contains_with_; } | 318 bool contains_with() const { return scope_contains_with_; } |
319 | 319 |
320 // --------------------------------------------------------------------------- | 320 // --------------------------------------------------------------------------- |
321 // Accessors. | 321 // Accessors. |
322 | 322 |
323 // The type of this scope. | 323 // The type of this scope. |
324 ScopeType type() const { return type_; } | 324 ScopeType scope_type() const { return scope_type_; } |
325 | 325 |
326 // The language mode of this scope. | 326 // The language mode of this scope. |
327 LanguageMode language_mode() const { return language_mode_; } | 327 LanguageMode language_mode() const { return language_mode_; } |
328 | 328 |
329 // The variable corresponding the 'this' value. | 329 // The variable corresponding the 'this' value. |
330 Variable* receiver() { return receiver_; } | 330 Variable* receiver() { return receiver_; } |
331 | 331 |
332 // The variable holding the function literal for named function | 332 // The variable holding the function literal for named function |
333 // literals, or NULL. Only valid for function scopes. | 333 // literals, or NULL. Only valid for function scopes. |
334 VariableDeclaration* function() const { | 334 VariableDeclaration* function() const { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 protected: | 442 protected: |
443 friend class ParserFactory; | 443 friend class ParserFactory; |
444 | 444 |
445 Isolate* const isolate_; | 445 Isolate* const isolate_; |
446 | 446 |
447 // Scope tree. | 447 // Scope tree. |
448 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 448 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
449 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes | 449 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes |
450 | 450 |
451 // The scope type. | 451 // The scope type. |
452 ScopeType type_; | 452 ScopeType scope_type_; |
453 | 453 |
454 // Debugging support. | 454 // Debugging support. |
455 Handle<String> scope_name_; | 455 Handle<String> scope_name_; |
456 | 456 |
457 // The variables declared in this scope: | 457 // The variables declared in this scope: |
458 // | 458 // |
459 // All user-declared variables (incl. parameters). For global scopes | 459 // All user-declared variables (incl. parameters). For global scopes |
460 // variables may be implicitly 'declared' by being used (possibly in | 460 // variables may be implicitly 'declared' by being used (possibly in |
461 // an inner scope) with no intervening with statements or eval calls. | 461 // an inner scope) with no intervening with statements or eval calls. |
462 VariableMap variables_; | 462 VariableMap variables_; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 void SetDefaults(ScopeType type, | 638 void SetDefaults(ScopeType type, |
639 Scope* outer_scope, | 639 Scope* outer_scope, |
640 Handle<ScopeInfo> scope_info); | 640 Handle<ScopeInfo> scope_info); |
641 | 641 |
642 Zone* zone_; | 642 Zone* zone_; |
643 }; | 643 }; |
644 | 644 |
645 } } // namespace v8::internal | 645 } } // namespace v8::internal |
646 | 646 |
647 #endif // V8_SCOPES_H_ | 647 #endif // V8_SCOPES_H_ |
OLD | NEW |