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

Side by Side Diff: src/scopes.h

Issue 7618040: Version 3.5.5. (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 4 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/scopeinfo.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 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 CATCH_SCOPE, // The scope introduced by catch.
97 BLOCK_SCOPE // The scope introduced by a new block.
97 }; 98 };
98 99
99 Scope(Scope* outer_scope, Type type); 100 Scope(Scope* outer_scope, Type type);
100 101
101 // Compute top scope and allocate variables. For lazy compilation the top 102 // Compute top scope and allocate variables. For lazy compilation the top
102 // scope only contains the single lazily compiled function, so this 103 // scope only contains the single lazily compiled function, so this
103 // doesn't re-allocate variables repeatedly. 104 // doesn't re-allocate variables repeatedly.
104 static bool Analyze(CompilationInfo* info); 105 static bool Analyze(CompilationInfo* info);
105 106
106 static Scope* DeserializeScopeChain(CompilationInfo* info, 107 static Scope* DeserializeScopeChain(CompilationInfo* info,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 198 }
198 199
199 // --------------------------------------------------------------------------- 200 // ---------------------------------------------------------------------------
200 // Predicates. 201 // Predicates.
201 202
202 // Specific scope types. 203 // Specific scope types.
203 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } 204 bool is_eval_scope() const { return type_ == EVAL_SCOPE; }
204 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } 205 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; }
205 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } 206 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; }
206 bool is_catch_scope() const { return type_ == CATCH_SCOPE; } 207 bool is_catch_scope() const { return type_ == CATCH_SCOPE; }
208 bool is_block_scope() const { return type_ == BLOCK_SCOPE; }
207 bool is_strict_mode() const { return strict_mode_; } 209 bool is_strict_mode() const { return strict_mode_; }
208 bool is_strict_mode_eval_scope() const { 210 bool is_strict_mode_eval_scope() const {
209 return is_eval_scope() && is_strict_mode(); 211 return is_eval_scope() && is_strict_mode();
210 } 212 }
211 213
212 // Information about which scopes calls eval. 214 // Information about which scopes calls eval.
213 bool calls_eval() const { return scope_calls_eval_; } 215 bool calls_eval() const { return scope_calls_eval_; }
214 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; } 216 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; }
215 bool outer_scope_calls_non_strict_eval() const { 217 bool outer_scope_calls_non_strict_eval() const {
216 return outer_scope_calls_non_strict_eval_; 218 return outer_scope_calls_non_strict_eval_;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // True if the outer context of this scope is always the global context. 289 // True if the outer context of this scope is always the global context.
288 bool HasTrivialOuterContext() const; 290 bool HasTrivialOuterContext() const;
289 291
290 // The number of contexts between this and scope; zero if this == scope. 292 // The number of contexts between this and scope; zero if this == scope.
291 int ContextChainLength(Scope* scope); 293 int ContextChainLength(Scope* scope);
292 294
293 // Find the first function, global, or eval scope. This is the scope 295 // Find the first function, global, or eval scope. This is the scope
294 // where var declarations will be hoisted to in the implementation. 296 // where var declarations will be hoisted to in the implementation.
295 Scope* DeclarationScope(); 297 Scope* DeclarationScope();
296 298
299 Handle<SerializedScopeInfo> GetSerializedScopeInfo();
300
297 // --------------------------------------------------------------------------- 301 // ---------------------------------------------------------------------------
298 // Strict mode support. 302 // Strict mode support.
299 bool IsDeclared(Handle<String> name) { 303 bool IsDeclared(Handle<String> name) {
300 // During formal parameter list parsing the scope only contains 304 // During formal parameter list parsing the scope only contains
301 // two variables inserted at initialization: "this" and "arguments". 305 // two variables inserted at initialization: "this" and "arguments".
302 // "this" is an invalid parameter name and "arguments" is invalid parameter 306 // "this" is an invalid parameter name and "arguments" is invalid parameter
303 // name in strict mode. Therefore looking up with the map which includes 307 // name in strict mode. Therefore looking up with the map which includes
304 // "this" and "arguments" in addition to all formal parameters is safe. 308 // "this" and "arguments" in addition to all formal parameters is safe.
305 return variables_.Lookup(name) != NULL; 309 return variables_.Lookup(name) != NULL;
306 } 310 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // Serialized scopes support. 394 // Serialized scopes support.
391 Handle<SerializedScopeInfo> scope_info_; 395 Handle<SerializedScopeInfo> scope_info_;
392 bool already_resolved() { return already_resolved_; } 396 bool already_resolved() { return already_resolved_; }
393 397
394 // Create a non-local variable with a given name. 398 // Create a non-local variable with a given name.
395 // These variables are looked up dynamically at runtime. 399 // These variables are looked up dynamically at runtime.
396 Variable* NonLocal(Handle<String> name, Variable::Mode mode); 400 Variable* NonLocal(Handle<String> name, Variable::Mode mode);
397 401
398 // Variable resolution. 402 // Variable resolution.
399 Variable* LookupRecursive(Handle<String> name, 403 Variable* LookupRecursive(Handle<String> name,
400 bool inner_lookup, 404 bool from_inner_function,
401 Variable** invalidated_local); 405 Variable** invalidated_local);
402 void ResolveVariable(Scope* global_scope, 406 void ResolveVariable(Scope* global_scope,
403 Handle<Context> context, 407 Handle<Context> context,
404 VariableProxy* proxy); 408 VariableProxy* proxy);
405 void ResolveVariablesRecursively(Scope* global_scope, 409 void ResolveVariablesRecursively(Scope* global_scope,
406 Handle<Context> context); 410 Handle<Context> context);
407 411
408 // Scope analysis. 412 // Scope analysis.
409 bool PropagateScopeInfo(bool outer_scope_calls_eval, 413 bool PropagateScopeInfo(bool outer_scope_calls_eval,
410 bool outer_scope_calls_non_strict_eval, 414 bool outer_scope_calls_non_strict_eval,
411 bool outer_scope_is_eval_scope); 415 bool outer_scope_is_eval_scope);
412 bool HasTrivialContext() const; 416 bool HasTrivialContext() const;
413 417
414 // Predicates. 418 // Predicates.
415 bool MustAllocate(Variable* var); 419 bool MustAllocate(Variable* var);
416 bool MustAllocateInContext(Variable* var); 420 bool MustAllocateInContext(Variable* var);
417 bool HasArgumentsParameter(); 421 bool HasArgumentsParameter();
418 422
419 // Variable allocation. 423 // Variable allocation.
420 void AllocateStackSlot(Variable* var); 424 void AllocateStackSlot(Variable* var);
421 void AllocateHeapSlot(Variable* var); 425 void AllocateHeapSlot(Variable* var);
422 void AllocateParameterLocals(); 426 void AllocateParameterLocals();
423 void AllocateNonParameterLocal(Variable* var); 427 void AllocateNonParameterLocal(Variable* var);
424 void AllocateNonParameterLocals(); 428 void AllocateNonParameterLocals();
425 void AllocateVariablesRecursively(); 429 void AllocateVariablesRecursively();
426 430
427 private: 431 private:
428 // Construct a function scope based on the scope info. 432 // Construct a function or block scope based on the scope info.
429 Scope(Scope* inner_scope, Handle<SerializedScopeInfo> scope_info); 433 Scope(Scope* inner_scope, Type type, Handle<SerializedScopeInfo> scope_info);
430 434
431 // Construct a catch scope with a binding for the name. 435 // Construct a catch scope with a binding for the name.
432 Scope(Scope* inner_scope, Handle<String> catch_variable_name); 436 Scope(Scope* inner_scope, Handle<String> catch_variable_name);
433 437
434 inline Slot* NewSlot(Variable* var, Slot::Type type, int index) { 438 inline Slot* NewSlot(Variable* var, Slot::Type type, int index) {
435 return new(isolate_->zone()) Slot(isolate_, var, type, index); 439 return new(isolate_->zone()) Slot(isolate_, var, type, index);
436 } 440 }
437 441
438 void AddInnerScope(Scope* inner_scope) { 442 void AddInnerScope(Scope* inner_scope) {
439 if (inner_scope != NULL) { 443 if (inner_scope != NULL) {
440 inner_scopes_.Add(inner_scope); 444 inner_scopes_.Add(inner_scope);
441 inner_scope->outer_scope_ = this; 445 inner_scope->outer_scope_ = this;
442 } 446 }
443 } 447 }
444 448
445 void SetDefaults(Type type, 449 void SetDefaults(Type type,
446 Scope* outer_scope, 450 Scope* outer_scope,
447 Handle<SerializedScopeInfo> scope_info); 451 Handle<SerializedScopeInfo> scope_info);
448 }; 452 };
449 453
450 } } // namespace v8::internal 454 } } // namespace v8::internal
451 455
452 #endif // V8_SCOPES_H_ 456 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698