OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 public: | 86 public: |
87 // --------------------------------------------------------------------------- | 87 // --------------------------------------------------------------------------- |
88 // Construction | 88 // Construction |
89 | 89 |
90 enum Type { | 90 enum Type { |
91 EVAL_SCOPE, // the top-level scope for an 'eval' source | 91 EVAL_SCOPE, // the top-level scope for an 'eval' source |
92 FUNCTION_SCOPE, // the top-level scope for a function | 92 FUNCTION_SCOPE, // the top-level scope for a function |
93 GLOBAL_SCOPE // the top-level scope for a program or a top-level eval | 93 GLOBAL_SCOPE // the top-level scope for a program or a top-level eval |
94 }; | 94 }; |
95 | 95 |
96 Scope(); | |
97 Scope(Scope* outer_scope, Type type); | 96 Scope(Scope* outer_scope, Type type); |
98 | 97 |
99 virtual ~Scope() { } | 98 virtual ~Scope() { } |
100 | 99 |
101 // The scope name is only used for printing/debugging. | 100 // The scope name is only used for printing/debugging. |
102 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } | 101 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } |
103 | 102 |
104 void Initialize(bool inside_with); | 103 void Initialize(bool inside_with); |
105 | 104 |
106 | 105 |
(...skipping 16 matching lines...) Expand all Loading... |
123 // declared before, the previously declared variable is returned. | 122 // declared before, the previously declared variable is returned. |
124 virtual Variable* DeclareLocal(Handle<String> name, Variable::Mode mode); | 123 virtual Variable* DeclareLocal(Handle<String> name, Variable::Mode mode); |
125 | 124 |
126 // Declare an implicit global variable in this scope which must be a | 125 // Declare an implicit global variable in this scope which must be a |
127 // global scope. The variable was introduced (possibly from an inner | 126 // global scope. The variable was introduced (possibly from an inner |
128 // scope) by a reference to an unresolved variable with no intervening | 127 // scope) by a reference to an unresolved variable with no intervening |
129 // with statements or eval calls. | 128 // with statements or eval calls. |
130 Variable* DeclareGlobal(Handle<String> name); | 129 Variable* DeclareGlobal(Handle<String> name); |
131 | 130 |
132 // Add a parameter to the parameter list. The parameter must have been | 131 // Add a parameter to the parameter list. The parameter must have been |
133 // declared via Declare. The same parameter may occur more then once in | 132 // declared via Declare. The same parameter may occur more than once in |
134 // the parameter list; they must be added in source order, from left to | 133 // the parameter list; they must be added in source order, from left to |
135 // right. | 134 // right. |
136 void AddParameter(Variable* var); | 135 void AddParameter(Variable* var); |
137 | 136 |
138 // Create a new unresolved variable. | 137 // Create a new unresolved variable. |
139 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with); | 138 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with); |
140 | 139 |
141 // Remove a unresolved variable. During parsing, an unresolved variable | 140 // Remove a unresolved variable. During parsing, an unresolved variable |
142 // may have been added optimistically, but then only the variable name | 141 // may have been added optimistically, but then only the variable name |
143 // was used (typically for labels). If the variable was not declared, the | 142 // was used (typically for labels). If the variable was not declared, the |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 278 |
280 #ifdef DEBUG | 279 #ifdef DEBUG |
281 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively | 280 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively |
282 #endif | 281 #endif |
283 | 282 |
284 // --------------------------------------------------------------------------- | 283 // --------------------------------------------------------------------------- |
285 // Implementation. | 284 // Implementation. |
286 protected: | 285 protected: |
287 friend class ParserFactory; | 286 friend class ParserFactory; |
288 | 287 |
| 288 explicit Scope(Type type); |
| 289 |
289 // Scope tree. | 290 // Scope tree. |
290 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 291 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
291 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes | 292 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes |
292 | 293 |
293 // The scope type. | 294 // The scope type. |
294 Type type_; | 295 Type type_; |
295 | 296 |
296 // Debugging support. | 297 // Debugging support. |
297 Handle<String> scope_name_; | 298 Handle<String> scope_name_; |
298 | 299 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 void AllocateHeapSlot(Variable* var); | 369 void AllocateHeapSlot(Variable* var); |
369 void AllocateParameterLocals(); | 370 void AllocateParameterLocals(); |
370 void AllocateNonParameterLocal(Variable* var); | 371 void AllocateNonParameterLocal(Variable* var); |
371 void AllocateNonParameterLocals(); | 372 void AllocateNonParameterLocals(); |
372 void AllocateVariablesRecursively(); | 373 void AllocateVariablesRecursively(); |
373 }; | 374 }; |
374 | 375 |
375 | 376 |
376 class DummyScope : public Scope { | 377 class DummyScope : public Scope { |
377 public: | 378 public: |
378 DummyScope() { | 379 DummyScope() : Scope(GLOBAL_SCOPE) { |
379 outer_scope_ = this; | 380 outer_scope_ = this; |
380 } | 381 } |
381 | 382 |
382 virtual Variable* Lookup(Handle<String> name) { return NULL; } | 383 virtual Variable* Lookup(Handle<String> name) { return NULL; } |
383 virtual Variable* Declare(Handle<String> name, Variable::Mode mode) { | 384 virtual Variable* Declare(Handle<String> name, Variable::Mode mode) { |
384 return NULL; | 385 return NULL; |
385 } | 386 } |
386 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) { | 387 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) { |
387 return NULL; | 388 return NULL; |
388 } | 389 } |
389 virtual VariableProxy* NewTemporary(Handle<String> name) { return NULL; } | 390 virtual VariableProxy* NewTemporary(Handle<String> name) { return NULL; } |
390 }; | 391 }; |
391 | 392 |
392 | 393 |
393 } } // namespace v8::internal | 394 } } // namespace v8::internal |
394 | 395 |
395 #endif // V8_SCOPES_H_ | 396 #endif // V8_SCOPES_H_ |
OLD | NEW |