| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 Scope(Scope* outer_scope, Type type); | 98 Scope(Scope* outer_scope, Type type); |
| 99 | 99 |
| 100 virtual ~Scope() { } | 100 virtual ~Scope() { } |
| 101 | 101 |
| 102 // Compute top scope and allocate variables. For lazy compilation the top | 102 // Compute top scope and allocate variables. For lazy compilation the top |
| 103 // scope only contains the single lazily compiled function, so this | 103 // scope only contains the single lazily compiled function, so this |
| 104 // doesn't re-allocate variables repeatedly. | 104 // doesn't re-allocate variables repeatedly. |
| 105 static bool Analyze(CompilationInfo* info); | 105 static bool Analyze(CompilationInfo* info); |
| 106 | 106 |
| 107 static Scope* DeserializeScopeChain(CompilationInfo* info, |
| 108 Scope* innermost_scope); |
| 109 |
| 107 // The scope name is only used for printing/debugging. | 110 // The scope name is only used for printing/debugging. |
| 108 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } | 111 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } |
| 109 | 112 |
| 110 virtual void Initialize(bool inside_with); | 113 virtual void Initialize(bool inside_with); |
| 111 | 114 |
| 112 // Called just before leaving a scope. | 115 // Called just before leaving a scope. |
| 113 virtual void Leave() { | 116 virtual void Leave() { |
| 114 // No cleanup or fixup necessary. | 117 // No cleanup or fixup necessary. |
| 115 } | 118 } |
| 116 | 119 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 189 |
| 187 // --------------------------------------------------------------------------- | 190 // --------------------------------------------------------------------------- |
| 188 // Scope-specific info. | 191 // Scope-specific info. |
| 189 | 192 |
| 190 // Inform the scope that the corresponding code contains a with statement. | 193 // Inform the scope that the corresponding code contains a with statement. |
| 191 void RecordWithStatement() { scope_contains_with_ = true; } | 194 void RecordWithStatement() { scope_contains_with_ = true; } |
| 192 | 195 |
| 193 // Inform the scope that the corresponding code contains an eval call. | 196 // Inform the scope that the corresponding code contains an eval call. |
| 194 void RecordEvalCall() { scope_calls_eval_ = true; } | 197 void RecordEvalCall() { scope_calls_eval_ = true; } |
| 195 | 198 |
| 199 // Enable strict mode for the scope (unless disabled by a global flag). |
| 200 void EnableStrictMode() { |
| 201 strict_mode_ = FLAG_strict_mode; |
| 202 } |
| 196 | 203 |
| 197 // --------------------------------------------------------------------------- | 204 // --------------------------------------------------------------------------- |
| 198 // Predicates. | 205 // Predicates. |
| 199 | 206 |
| 200 // Specific scope types. | 207 // Specific scope types. |
| 201 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } | 208 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } |
| 202 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } | 209 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } |
| 203 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } | 210 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } |
| 211 bool is_strict_mode() const { return strict_mode_; } |
| 204 | 212 |
| 205 // Information about which scopes calls eval. | 213 // Information about which scopes calls eval. |
| 206 bool calls_eval() const { return scope_calls_eval_; } | 214 bool calls_eval() const { return scope_calls_eval_; } |
| 207 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; } | 215 bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; } |
| 208 | 216 |
| 209 // Is this scope inside a with statement. | 217 // Is this scope inside a with statement. |
| 210 bool inside_with() const { return scope_inside_with_; } | 218 bool inside_with() const { return scope_inside_with_; } |
| 211 // Does this scope contain a with statement. | 219 // Does this scope contain a with statement. |
| 212 bool contains_with() const { return scope_contains_with_; } | 220 bool contains_with() const { return scope_contains_with_; } |
| 213 | 221 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively | 314 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively |
| 307 #endif | 315 #endif |
| 308 | 316 |
| 309 // --------------------------------------------------------------------------- | 317 // --------------------------------------------------------------------------- |
| 310 // Implementation. | 318 // Implementation. |
| 311 protected: | 319 protected: |
| 312 friend class ParserFactory; | 320 friend class ParserFactory; |
| 313 | 321 |
| 314 explicit Scope(Type type); | 322 explicit Scope(Type type); |
| 315 | 323 |
| 316 void InsertAfterScope(Scope* scope) { | |
| 317 inner_scopes_.Add(scope); | |
| 318 outer_scope_ = scope->outer_scope_; | |
| 319 outer_scope_->inner_scopes_.RemoveElement(scope); | |
| 320 outer_scope_->inner_scopes_.Add(this); | |
| 321 scope->outer_scope_ = this; | |
| 322 } | |
| 323 | |
| 324 // Scope tree. | 324 // Scope tree. |
| 325 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 325 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
| 326 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes | 326 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes |
| 327 | 327 |
| 328 // The scope type. | 328 // The scope type. |
| 329 Type type_; | 329 Type type_; |
| 330 | 330 |
| 331 // Debugging support. | 331 // Debugging support. |
| 332 Handle<String> scope_name_; | 332 Handle<String> scope_name_; |
| 333 | 333 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 356 // Convenience variable; function scopes only. | 356 // Convenience variable; function scopes only. |
| 357 Variable* arguments_shadow_; | 357 Variable* arguments_shadow_; |
| 358 | 358 |
| 359 // Illegal redeclaration. | 359 // Illegal redeclaration. |
| 360 Expression* illegal_redecl_; | 360 Expression* illegal_redecl_; |
| 361 | 361 |
| 362 // Scope-specific information. | 362 // Scope-specific information. |
| 363 bool scope_inside_with_; // this scope is inside a 'with' of some outer scope | 363 bool scope_inside_with_; // this scope is inside a 'with' of some outer scope |
| 364 bool scope_contains_with_; // this scope contains a 'with' statement | 364 bool scope_contains_with_; // this scope contains a 'with' statement |
| 365 bool scope_calls_eval_; // this scope contains an 'eval' call | 365 bool scope_calls_eval_; // this scope contains an 'eval' call |
| 366 bool strict_mode_; // this scope is a strict mode scope |
| 366 | 367 |
| 367 // Computed via PropagateScopeInfo. | 368 // Computed via PropagateScopeInfo. |
| 368 bool outer_scope_calls_eval_; | 369 bool outer_scope_calls_eval_; |
| 369 bool inner_scope_calls_eval_; | 370 bool inner_scope_calls_eval_; |
| 370 bool outer_scope_is_eval_scope_; | 371 bool outer_scope_is_eval_scope_; |
| 371 bool force_eager_compilation_; | 372 bool force_eager_compilation_; |
| 372 | 373 |
| 373 // Computed via AllocateVariables; function scopes only. | 374 // Computed via AllocateVariables; function scopes only. |
| 374 int num_stack_slots_; | 375 int num_stack_slots_; |
| 375 int num_heap_slots_; | 376 int num_heap_slots_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 406 void AllocateStackSlot(Variable* var); | 407 void AllocateStackSlot(Variable* var); |
| 407 void AllocateHeapSlot(Variable* var); | 408 void AllocateHeapSlot(Variable* var); |
| 408 void AllocateParameterLocals(); | 409 void AllocateParameterLocals(); |
| 409 void AllocateNonParameterLocal(Variable* var); | 410 void AllocateNonParameterLocal(Variable* var); |
| 410 void AllocateNonParameterLocals(); | 411 void AllocateNonParameterLocals(); |
| 411 void AllocateVariablesRecursively(); | 412 void AllocateVariablesRecursively(); |
| 412 | 413 |
| 413 private: | 414 private: |
| 414 Scope(Scope* inner_scope, SerializedScopeInfo* scope_info); | 415 Scope(Scope* inner_scope, SerializedScopeInfo* scope_info); |
| 415 | 416 |
| 417 void AddInnerScope(Scope* inner_scope) { |
| 418 if (inner_scope != NULL) { |
| 419 inner_scopes_.Add(inner_scope); |
| 420 inner_scope->outer_scope_ = this; |
| 421 } |
| 422 } |
| 423 |
| 416 void SetDefaults(Type type, | 424 void SetDefaults(Type type, |
| 417 Scope* outer_scope, | 425 Scope* outer_scope, |
| 418 SerializedScopeInfo* scope_info) { | 426 SerializedScopeInfo* scope_info) { |
| 419 outer_scope_ = outer_scope; | 427 outer_scope_ = outer_scope; |
| 420 type_ = type; | 428 type_ = type; |
| 421 scope_name_ = Factory::empty_symbol(); | 429 scope_name_ = Factory::empty_symbol(); |
| 422 dynamics_ = NULL; | 430 dynamics_ = NULL; |
| 423 receiver_ = NULL; | 431 receiver_ = NULL; |
| 424 function_ = NULL; | 432 function_ = NULL; |
| 425 arguments_ = NULL; | 433 arguments_ = NULL; |
| 426 arguments_shadow_ = NULL; | 434 arguments_shadow_ = NULL; |
| 427 illegal_redecl_ = NULL; | 435 illegal_redecl_ = NULL; |
| 428 scope_inside_with_ = false; | 436 scope_inside_with_ = false; |
| 429 scope_contains_with_ = false; | 437 scope_contains_with_ = false; |
| 430 scope_calls_eval_ = false; | 438 scope_calls_eval_ = false; |
| 439 // Inherit the strict mode from the parent scope. |
| 440 strict_mode_ = (outer_scope != NULL) && outer_scope->strict_mode_; |
| 431 outer_scope_calls_eval_ = false; | 441 outer_scope_calls_eval_ = false; |
| 432 inner_scope_calls_eval_ = false; | 442 inner_scope_calls_eval_ = false; |
| 433 outer_scope_is_eval_scope_ = false; | 443 outer_scope_is_eval_scope_ = false; |
| 434 force_eager_compilation_ = false; | 444 force_eager_compilation_ = false; |
| 435 num_stack_slots_ = 0; | 445 num_stack_slots_ = 0; |
| 436 num_heap_slots_ = 0; | 446 num_heap_slots_ = 0; |
| 437 scope_info_ = scope_info; | 447 scope_info_ = scope_info; |
| 438 } | 448 } |
| 439 }; | 449 }; |
| 440 | 450 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 int nesting_level_; | 495 int nesting_level_; |
| 486 // Nesting level of outermost scope that is contained in a with statement, | 496 // Nesting level of outermost scope that is contained in a with statement, |
| 487 // or kNotInsideWith if there are no with's around the current scope. | 497 // or kNotInsideWith if there are no with's around the current scope. |
| 488 int inside_with_level_; | 498 int inside_with_level_; |
| 489 }; | 499 }; |
| 490 | 500 |
| 491 | 501 |
| 492 } } // namespace v8::internal | 502 } } // namespace v8::internal |
| 493 | 503 |
| 494 #endif // V8_SCOPES_H_ | 504 #endif // V8_SCOPES_H_ |
| OLD | NEW |