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

Side by Side Diff: src/scopes.h

Issue 7280012: Introduce scopes to keep track of catch blocks at compile time. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update to HEAD. Created 9 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
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // allocation binds each unresolved VariableProxy to one Variable and assigns 83 // allocation binds each unresolved VariableProxy to one Variable and assigns
84 // a location. Note that many VariableProxy nodes may refer to the same Java- 84 // a location. Note that many VariableProxy nodes may refer to the same Java-
85 // Script variable. 85 // Script variable.
86 86
87 class Scope: public ZoneObject { 87 class Scope: public ZoneObject {
88 public: 88 public:
89 // --------------------------------------------------------------------------- 89 // ---------------------------------------------------------------------------
90 // Construction 90 // Construction
91 91
92 enum Type { 92 enum Type {
93 EVAL_SCOPE, // the top-level scope for an 'eval' source 93 EVAL_SCOPE, // The top-level scope for an eval source.
94 FUNCTION_SCOPE, // the top-level scope for a function 94 FUNCTION_SCOPE, // The top-level scope for a function.
95 GLOBAL_SCOPE // the top-level scope for a program or a top-level eval 95 GLOBAL_SCOPE, // The top-level scope for a program or a top-level eval.
96 CATCH_SCOPE // The scope introduced by catch.
96 }; 97 };
97 98
98 Scope(Scope* outer_scope, Type type); 99 Scope(Scope* outer_scope, Type type);
99 100
100 // Compute top scope and allocate variables. For lazy compilation the top 101 // Compute top scope and allocate variables. For lazy compilation the top
101 // scope only contains the single lazily compiled function, so this 102 // scope only contains the single lazily compiled function, so this
102 // doesn't re-allocate variables repeatedly. 103 // doesn't re-allocate variables repeatedly.
103 static bool Analyze(CompilationInfo* info); 104 static bool Analyze(CompilationInfo* info);
104 105
105 static Scope* DeserializeScopeChain(CompilationInfo* info, 106 static Scope* DeserializeScopeChain(CompilationInfo* info,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 strict_mode_ = FLAG_strict_mode; 196 strict_mode_ = FLAG_strict_mode;
196 } 197 }
197 198
198 // --------------------------------------------------------------------------- 199 // ---------------------------------------------------------------------------
199 // Predicates. 200 // Predicates.
200 201
201 // Specific scope types. 202 // Specific scope types.
202 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } 203 bool is_eval_scope() const { return type_ == EVAL_SCOPE; }
203 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } 204 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; }
204 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } 205 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; }
206 bool is_catch_scope() const { return type_ == CATCH_SCOPE; }
205 bool is_strict_mode() const { return strict_mode_; } 207 bool is_strict_mode() const { return strict_mode_; }
206 bool is_strict_mode_eval_scope() const { 208 bool is_strict_mode_eval_scope() const {
207 return is_eval_scope() && is_strict_mode(); 209 return is_eval_scope() && is_strict_mode();
208 } 210 }
209 211
210 // Information about which scopes calls eval. 212 // Information about which scopes calls eval.
211 bool calls_eval() const { return scope_calls_eval_; } 213 bool calls_eval() const { return scope_calls_eval_; }
212 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; } 214 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; }
213 bool outer_scope_calls_non_strict_eval() const { 215 bool outer_scope_calls_non_strict_eval() const {
214 return outer_scope_calls_non_strict_eval_; 216 return outer_scope_calls_non_strict_eval_;
215 } 217 }
216 218
217 // Is this scope inside a with statement. 219 // Is this scope inside a with statement.
218 bool inside_with() const { return scope_inside_with_; } 220 bool inside_with() const { return scope_inside_with_; }
219 // Does this scope contain a with statement. 221 // Does this scope contain a with statement.
220 bool contains_with() const { return scope_contains_with_; } 222 bool contains_with() const { return scope_contains_with_; }
221 223
222 // The scope immediately surrounding this scope, or NULL. 224 // The scope immediately surrounding this scope, or NULL.
223 Scope* outer_scope() const { return outer_scope_; } 225 Scope* outer_scope() const { return outer_scope_; }
224 226
225 // --------------------------------------------------------------------------- 227 // ---------------------------------------------------------------------------
226 // Accessors. 228 // Accessors.
227 229
228 // A new variable proxy corresponding to the (function) receiver. 230 // The variable corresponding the 'this' value.
229 VariableProxy* receiver() const { 231 Variable* receiver() { return receiver_; }
230 VariableProxy* proxy =
231 new VariableProxy(FACTORY->this_symbol(), true, false);
232 proxy->BindTo(receiver_);
233 return proxy;
234 }
235 232
236 // The variable holding the function literal for named function 233 // The variable holding the function literal for named function
237 // literals, or NULL. 234 // literals, or NULL.
238 // Only valid for function scopes. 235 // Only valid for function scopes.
239 Variable* function() const { 236 Variable* function() const {
240 ASSERT(is_function_scope()); 237 ASSERT(is_function_scope());
241 return function_; 238 return function_;
242 } 239 }
243 240
244 // Parameters. The left-most parameter has index 0. 241 // Parameters. The left-most parameter has index 0.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 419 }
423 420
424 void SetDefaults(Type type, 421 void SetDefaults(Type type,
425 Scope* outer_scope, 422 Scope* outer_scope,
426 Handle<SerializedScopeInfo> scope_info); 423 Handle<SerializedScopeInfo> scope_info);
427 }; 424 };
428 425
429 } } // namespace v8::internal 426 } } // namespace v8::internal
430 427
431 #endif // V8_SCOPES_H_ 428 #endif // V8_SCOPES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698