Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: src/scopes.h

Issue 149245: Allow variable proxies for the same global variable to share the same... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.cc ('k') | src/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 #ifndef V8_SCOPES_H_ 28 #ifndef V8_SCOPES_H_
29 #define V8_SCOPES_H_ 29 #define V8_SCOPES_H_
30 30
31 #include "ast.h" 31 #include "ast.h"
32 #include "hashmap.h" 32 #include "hashmap.h"
33 33
34 namespace v8 { 34 namespace v8 {
35 namespace internal { 35 namespace internal {
36 36
37 37
38 // A hash map to support fast local variable declaration and lookup. 38 // A hash map to support fast variable declaration and lookup.
39 class LocalsMap: public HashMap { 39 class VariableMap: public HashMap {
40 public: 40 public:
41 LocalsMap(); 41 VariableMap();
42 42
43 // Dummy constructor. This constructor doesn't set up the map 43 // Dummy constructor. This constructor doesn't set up the map
44 // properly so don't use it unless you have a good reason. 44 // properly so don't use it unless you have a good reason.
45 explicit LocalsMap(bool gotta_love_static_overloading); 45 explicit VariableMap(bool gotta_love_static_overloading);
46 46
47 virtual ~LocalsMap(); 47 virtual ~VariableMap();
48 48
49 Variable* Declare(Scope* scope, Handle<String> name, Variable::Mode mode, 49 Variable* Declare(Scope* scope,
50 bool is_valid_LHS, Variable::Kind kind); 50 Handle<String> name,
51 Variable::Mode mode,
52 bool is_valid_lhs,
53 Variable::Kind kind);
51 54
52 Variable* Lookup(Handle<String> name); 55 Variable* Lookup(Handle<String> name);
53 }; 56 };
54 57
55 58
56 // The dynamic scope part holds hash maps for the variables that will 59 // The dynamic scope part holds hash maps for the variables that will
57 // be looked up dynamically from within eval and with scopes. The objects 60 // be looked up dynamically from within eval and with scopes. The objects
58 // are allocated on-demand from Scope::NonLocal to avoid wasting memory 61 // are allocated on-demand from Scope::NonLocal to avoid wasting memory
59 // and setup time for scopes that don't need them. 62 // and setup time for scopes that don't need them.
60 class DynamicScopePart : public ZoneObject { 63 class DynamicScopePart : public ZoneObject {
61 public: 64 public:
62 LocalsMap* GetMap(Variable::Mode mode) { 65 VariableMap* GetMap(Variable::Mode mode) {
63 int index = mode - Variable::DYNAMIC; 66 int index = mode - Variable::DYNAMIC;
64 ASSERT(index >= 0 && index < 3); 67 ASSERT(index >= 0 && index < 3);
65 return &maps_[index]; 68 return &maps_[index];
66 } 69 }
67 70
68 private: 71 private:
69 LocalsMap maps_[3]; 72 VariableMap maps_[3];
70 }; 73 };
71 74
72 75
73 // Global invariants after AST construction: Each reference (i.e. identifier) 76 // Global invariants after AST construction: Each reference (i.e. identifier)
74 // to a JavaScript variable (including global properties) is represented by a 77 // to a JavaScript variable (including global properties) is represented by a
75 // VariableProxy node. Immediately after AST construction and before variable 78 // VariableProxy node. Immediately after AST construction and before variable
76 // allocation, most VariableProxy nodes are "unresolved", i.e. not bound to a 79 // allocation, most VariableProxy nodes are "unresolved", i.e. not bound to a
77 // corresponding variable (though some are bound during parse time). Variable 80 // corresponding variable (though some are bound during parse time). Variable
78 // allocation binds each unresolved VariableProxy to one Variable and assigns 81 // allocation binds each unresolved VariableProxy to one Variable and assigns
79 // a location. Note that many VariableProxy nodes may refer to the same Java- 82 // a location. Note that many VariableProxy nodes may refer to the same Java-
(...skipping 18 matching lines...) Expand all
98 // The scope name is only used for printing/debugging. 101 // The scope name is only used for printing/debugging.
99 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } 102 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; }
100 103
101 void Initialize(bool inside_with); 104 void Initialize(bool inside_with);
102 105
103 106
104 // --------------------------------------------------------------------------- 107 // ---------------------------------------------------------------------------
105 // Declarations 108 // Declarations
106 109
107 // Lookup a variable in this scope. Returns the variable or NULL if not found. 110 // Lookup a variable in this scope. Returns the variable or NULL if not found.
108 virtual Variable* LookupLocal(Handle<String> name); 111 virtual Variable* LocalLookup(Handle<String> name);
109 112
110 // Lookup a variable in this scope or outer scopes. 113 // Lookup a variable in this scope or outer scopes.
111 // Returns the variable or NULL if not found. 114 // Returns the variable or NULL if not found.
112 virtual Variable* Lookup(Handle<String> name); 115 virtual Variable* Lookup(Handle<String> name);
113 116
114 // Declare the function variable for a function literal. This variable 117 // Declare the function variable for a function literal. This variable
115 // is in an intermediate scope between this function scope and the the 118 // is in an intermediate scope between this function scope and the the
116 // outer scope. Only possible for function scopes; at most one variable. 119 // outer scope. Only possible for function scopes; at most one variable.
117 Variable* DeclareFunctionVar(Handle<String> name); 120 Variable* DeclareFunctionVar(Handle<String> name);
118 121
119 // Declare a variable in this scope. If the variable has been 122 // Declare a local variable in this scope. If the variable has been
120 // declared before, the previously declared variable is returned. 123 // declared before, the previously declared variable is returned.
121 virtual Variable* Declare(Handle<String> name, Variable::Mode mode); 124 virtual Variable* DeclareLocal(Handle<String> name, Variable::Mode mode);
125
126 // Declare an implicit global variable in this scope which must be a
127 // global scope. The variable was introduced (possibly from an inner
128 // scope) by a reference to an unresolved variable with no intervening
129 // with statements or eval calls.
130 Variable* DeclareGlobal(Handle<String> name);
122 131
123 // Add a parameter to the parameter list. The parameter must have been 132 // Add a parameter to the parameter list. The parameter must have been
124 // declared via Declare. The same parameter may occur more then once in 133 // declared via Declare. The same parameter may occur more then once in
125 // the parameter list; they must be added in source order, from left to 134 // the parameter list; they must be added in source order, from left to
126 // right. 135 // right.
127 void AddParameter(Variable* var); 136 void AddParameter(Variable* var);
128 137
129 // Create a new unresolved variable. 138 // Create a new unresolved variable.
130 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with); 139 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with);
131 140
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL 290 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL
282 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes 291 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes
283 292
284 // The scope type. 293 // The scope type.
285 Type type_; 294 Type type_;
286 295
287 // Debugging support. 296 // Debugging support.
288 Handle<String> scope_name_; 297 Handle<String> scope_name_;
289 298
290 // The variables declared in this scope: 299 // The variables declared in this scope:
291 // all user-declared variables (incl. parameters) 300 //
292 LocalsMap locals_; 301 // All user-declared variables (incl. parameters). For global scopes
293 // compiler-allocated (user-invisible) temporaries 302 // variables may be implicitly 'declared' by being used (possibly in
303 // an inner scope) with no intervening with statements or eval calls.
304 VariableMap variables_;
305 // Compiler-allocated (user-invisible) temporaries.
294 ZoneList<Variable*> temps_; 306 ZoneList<Variable*> temps_;
295 // parameter list in source order 307 // Parameter list in source order.
296 ZoneList<Variable*> params_; 308 ZoneList<Variable*> params_;
297 // variables that must be looked up dynamically 309 // Variables that must be looked up dynamically.
298 DynamicScopePart* dynamics_; 310 DynamicScopePart* dynamics_;
299 // unresolved variables referred to from this scope 311 // Unresolved variables referred to from this scope.
300 ZoneList<VariableProxy*> unresolved_; 312 ZoneList<VariableProxy*> unresolved_;
301 // declarations 313 // Declarations.
302 ZoneList<Declaration*> decls_; 314 ZoneList<Declaration*> decls_;
303 // convenience variable 315 // Convenience variable.
304 VariableProxy* receiver_; 316 VariableProxy* receiver_;
305 // function variable, if any; function scopes only 317 // Function variable, if any; function scopes only.
306 Variable* function_; 318 Variable* function_;
307 // convenience variable; function scopes only 319 // Convenience variable; function scopes only.
308 VariableProxy* arguments_; 320 VariableProxy* arguments_;
309 // convenience variable; function scopes only 321 // Convenience variable; function scopes only.
310 VariableProxy* arguments_shadow_; 322 VariableProxy* arguments_shadow_;
311 323
312 // Illegal redeclaration. 324 // Illegal redeclaration.
313 Expression* illegal_redecl_; 325 Expression* illegal_redecl_;
314 326
315 // Scope-specific information. 327 // Scope-specific information.
316 bool scope_inside_with_; // this scope is inside a 'with' of some outer scope 328 bool scope_inside_with_; // this scope is inside a 'with' of some outer scope
317 bool scope_contains_with_; // this scope contains a 'with' statement 329 bool scope_contains_with_; // this scope contains a 'with' statement
318 bool scope_calls_eval_; // this scope contains an 'eval' call 330 bool scope_calls_eval_; // this scope contains an 'eval' call
319 331
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) { 386 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) {
375 return NULL; 387 return NULL;
376 } 388 }
377 virtual VariableProxy* NewTemporary(Handle<String> name) { return NULL; } 389 virtual VariableProxy* NewTemporary(Handle<String> name) { return NULL; }
378 }; 390 };
379 391
380 392
381 } } // namespace v8::internal 393 } } // namespace v8::internal
382 394
383 #endif // V8_SCOPES_H_ 395 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698