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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 VariableMap(); | 43 VariableMap(); |
44 | 44 |
45 // Dummy constructor. This constructor doesn't set up the map | 45 // Dummy constructor. This constructor doesn't set up the map |
46 // properly so don't use it unless you have a good reason. | 46 // properly so don't use it unless you have a good reason. |
47 explicit VariableMap(bool gotta_love_static_overloading); | 47 explicit VariableMap(bool gotta_love_static_overloading); |
48 | 48 |
49 virtual ~VariableMap(); | 49 virtual ~VariableMap(); |
50 | 50 |
51 Variable* Declare(Scope* scope, | 51 Variable* Declare(Scope* scope, |
52 Handle<String> name, | 52 Handle<String> name, |
53 Variable::Mode mode, | 53 VariableMode mode, |
54 bool is_valid_lhs, | 54 bool is_valid_lhs, |
55 Variable::Kind kind); | 55 Variable::Kind kind); |
56 | 56 |
57 Variable* Lookup(Handle<String> name); | 57 Variable* Lookup(Handle<String> name); |
58 }; | 58 }; |
59 | 59 |
60 | 60 |
61 // The dynamic scope part holds hash maps for the variables that will | 61 // The dynamic scope part holds hash maps for the variables that will |
62 // be looked up dynamically from within eval and with scopes. The objects | 62 // be looked up dynamically from within eval and with scopes. The objects |
63 // are allocated on-demand from Scope::NonLocal to avoid wasting memory | 63 // are allocated on-demand from Scope::NonLocal to avoid wasting memory |
64 // and setup time for scopes that don't need them. | 64 // and setup time for scopes that don't need them. |
65 class DynamicScopePart : public ZoneObject { | 65 class DynamicScopePart : public ZoneObject { |
66 public: | 66 public: |
67 VariableMap* GetMap(Variable::Mode mode) { | 67 VariableMap* GetMap(VariableMode mode) { |
68 int index = mode - Variable::DYNAMIC; | 68 int index = mode - DYNAMIC; |
69 ASSERT(index >= 0 && index < 3); | 69 ASSERT(index >= 0 && index < 3); |
70 return &maps_[index]; | 70 return &maps_[index]; |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 VariableMap maps_[3]; | 74 VariableMap maps_[3]; |
75 }; | 75 }; |
76 | 76 |
77 | 77 |
78 // Global invariants after AST construction: Each reference (i.e. identifier) | 78 // Global invariants after AST construction: Each reference (i.e. identifier) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 Variable* Lookup(Handle<String> name); | 128 Variable* Lookup(Handle<String> name); |
129 | 129 |
130 // Declare the function variable for a function literal. This variable | 130 // Declare the function variable for a function literal. This variable |
131 // is in an intermediate scope between this function scope and the the | 131 // is in an intermediate scope between this function scope and the the |
132 // outer scope. Only possible for function scopes; at most one variable. | 132 // outer scope. Only possible for function scopes; at most one variable. |
133 Variable* DeclareFunctionVar(Handle<String> name); | 133 Variable* DeclareFunctionVar(Handle<String> name); |
134 | 134 |
135 // Declare a parameter in this scope. When there are duplicated | 135 // Declare a parameter in this scope. When there are duplicated |
136 // parameters the rightmost one 'wins'. However, the implementation | 136 // parameters the rightmost one 'wins'. However, the implementation |
137 // expects all parameters to be declared and from left to right. | 137 // expects all parameters to be declared and from left to right. |
138 void DeclareParameter(Handle<String> name, Variable::Mode mode); | 138 void DeclareParameter(Handle<String> name, VariableMode mode); |
139 | 139 |
140 // Declare a local variable in this scope. If the variable has been | 140 // Declare a local variable in this scope. If the variable has been |
141 // declared before, the previously declared variable is returned. | 141 // declared before, the previously declared variable is returned. |
142 Variable* DeclareLocal(Handle<String> name, Variable::Mode mode); | 142 Variable* DeclareLocal(Handle<String> name, VariableMode mode); |
143 | 143 |
144 // Declare an implicit global variable in this scope which must be a | 144 // Declare an implicit global variable in this scope which must be a |
145 // global scope. The variable was introduced (possibly from an inner | 145 // global scope. The variable was introduced (possibly from an inner |
146 // scope) by a reference to an unresolved variable with no intervening | 146 // scope) by a reference to an unresolved variable with no intervening |
147 // with statements or eval calls. | 147 // with statements or eval calls. |
148 Variable* DeclareGlobal(Handle<String> name); | 148 Variable* DeclareGlobal(Handle<String> name); |
149 | 149 |
150 // Create a new unresolved variable. | 150 // Create a new unresolved variable. |
151 VariableProxy* NewUnresolved(Handle<String> name, | 151 VariableProxy* NewUnresolved(Handle<String> name, |
152 bool inside_with, | 152 bool inside_with, |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 // Computed via AllocateVariables; function scopes only. | 399 // Computed via AllocateVariables; function scopes only. |
400 int num_stack_slots_; | 400 int num_stack_slots_; |
401 int num_heap_slots_; | 401 int num_heap_slots_; |
402 | 402 |
403 // Serialized scopes support. | 403 // Serialized scopes support. |
404 Handle<SerializedScopeInfo> scope_info_; | 404 Handle<SerializedScopeInfo> scope_info_; |
405 bool already_resolved() { return already_resolved_; } | 405 bool already_resolved() { return already_resolved_; } |
406 | 406 |
407 // Create a non-local variable with a given name. | 407 // Create a non-local variable with a given name. |
408 // These variables are looked up dynamically at runtime. | 408 // These variables are looked up dynamically at runtime. |
409 Variable* NonLocal(Handle<String> name, Variable::Mode mode); | 409 Variable* NonLocal(Handle<String> name, VariableMode mode); |
410 | 410 |
411 // Variable resolution. | 411 // Variable resolution. |
412 Variable* LookupRecursive(Handle<String> name, | 412 Variable* LookupRecursive(Handle<String> name, |
413 bool from_inner_function, | 413 bool from_inner_function, |
414 Variable** invalidated_local); | 414 Variable** invalidated_local); |
415 void ResolveVariable(Scope* global_scope, | 415 void ResolveVariable(Scope* global_scope, |
416 Handle<Context> context, | 416 Handle<Context> context, |
417 VariableProxy* proxy); | 417 VariableProxy* proxy); |
418 void ResolveVariablesRecursively(Scope* global_scope, | 418 void ResolveVariablesRecursively(Scope* global_scope, |
419 Handle<Context> context); | 419 Handle<Context> context); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 } | 452 } |
453 | 453 |
454 void SetDefaults(Type type, | 454 void SetDefaults(Type type, |
455 Scope* outer_scope, | 455 Scope* outer_scope, |
456 Handle<SerializedScopeInfo> scope_info); | 456 Handle<SerializedScopeInfo> scope_info); |
457 }; | 457 }; |
458 | 458 |
459 } } // namespace v8::internal | 459 } } // namespace v8::internal |
460 | 460 |
461 #endif // V8_SCOPES_H_ | 461 #endif // V8_SCOPES_H_ |
OLD | NEW |