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

Side by Side Diff: src/scopes.h

Issue 196133017: Experimental parser: merge r19949 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // --------------------------------------------------------------------------- 227 // ---------------------------------------------------------------------------
228 // Scope-specific info. 228 // Scope-specific info.
229 229
230 // Inform the scope that the corresponding code contains a with statement. 230 // Inform the scope that the corresponding code contains a with statement.
231 void RecordWithStatement() { scope_contains_with_ = true; } 231 void RecordWithStatement() { scope_contains_with_ = true; }
232 232
233 // Inform the scope that the corresponding code contains an eval call. 233 // Inform the scope that the corresponding code contains an eval call.
234 void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ = true; } 234 void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ = true; }
235 235
236 // Set the strict mode flag (unless disabled by a global flag). 236 // Set the strict mode flag (unless disabled by a global flag).
237 void SetLanguageMode(LanguageMode language_mode) { 237 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; }
238 language_mode_ = language_mode;
239 }
240 238
241 // Position in the source where this scope begins and ends. 239 // Position in the source where this scope begins and ends.
242 // 240 //
243 // * For the scope of a with statement 241 // * For the scope of a with statement
244 // with (obj) stmt 242 // with (obj) stmt
245 // start position: start position of first token of 'stmt' 243 // start position: start position of first token of 'stmt'
246 // end position: end position of last token of 'stmt' 244 // end position: end position of last token of 'stmt'
247 // * For the scope of a block 245 // * For the scope of a block
248 // { stmts } 246 // { stmts }
249 // start position: start position of '{' 247 // start position: start position of '{'
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 bool is_function_scope() const { return scope_type_ == FUNCTION_SCOPE; } 284 bool is_function_scope() const { return scope_type_ == FUNCTION_SCOPE; }
287 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } 285 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; }
288 bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; } 286 bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; }
289 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } 287 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; }
290 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } 288 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; }
291 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } 289 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; }
292 bool is_declaration_scope() const { 290 bool is_declaration_scope() const {
293 return is_eval_scope() || is_function_scope() || 291 return is_eval_scope() || is_function_scope() ||
294 is_module_scope() || is_global_scope(); 292 is_module_scope() || is_global_scope();
295 } 293 }
296 bool is_classic_mode() const { 294 bool is_strict_eval_scope() const {
297 return language_mode() == CLASSIC_MODE; 295 return is_eval_scope() && strict_mode_ == STRICT;
298 }
299 bool is_extended_mode() const {
300 return language_mode() == EXTENDED_MODE;
301 }
302 bool is_strict_or_extended_eval_scope() const {
303 return is_eval_scope() && !is_classic_mode();
304 } 296 }
305 297
306 // Information about which scopes calls eval. 298 // Information about which scopes calls eval.
307 bool calls_eval() const { return scope_calls_eval_; } 299 bool calls_eval() const { return scope_calls_eval_; }
308 bool calls_non_strict_eval() { 300 bool calls_sloppy_eval() {
309 return scope_calls_eval_ && is_classic_mode(); 301 return scope_calls_eval_ && strict_mode_ == SLOPPY;
310 } 302 }
311 bool outer_scope_calls_non_strict_eval() const { 303 bool outer_scope_calls_sloppy_eval() const {
312 return outer_scope_calls_non_strict_eval_; 304 return outer_scope_calls_sloppy_eval_;
313 } 305 }
314 306
315 // Is this scope inside a with statement. 307 // Is this scope inside a with statement.
316 bool inside_with() const { return scope_inside_with_; } 308 bool inside_with() const { return scope_inside_with_; }
317 // Does this scope contain a with statement. 309 // Does this scope contain a with statement.
318 bool contains_with() const { return scope_contains_with_; } 310 bool contains_with() const { return scope_contains_with_; }
319 311
320 // --------------------------------------------------------------------------- 312 // ---------------------------------------------------------------------------
321 // Accessors. 313 // Accessors.
322 314
323 // The type of this scope. 315 // The type of this scope.
324 ScopeType scope_type() const { return scope_type_; } 316 ScopeType scope_type() const { return scope_type_; }
325 317
326 // The language mode of this scope. 318 // The language mode of this scope.
327 LanguageMode language_mode() const { return language_mode_; } 319 StrictMode strict_mode() const { return strict_mode_; }
328 320
329 // The variable corresponding the 'this' value. 321 // The variable corresponding the 'this' value.
330 Variable* receiver() { return receiver_; } 322 Variable* receiver() { return receiver_; }
331 323
332 // The variable holding the function literal for named function 324 // The variable holding the function literal for named function
333 // literals, or NULL. Only valid for function scopes. 325 // literals, or NULL. Only valid for function scopes.
334 VariableDeclaration* function() const { 326 VariableDeclaration* function() const {
335 ASSERT(is_function_scope()); 327 ASSERT(is_function_scope());
336 return function_; 328 return function_;
337 } 329 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 478
487 // Scope-specific information computed during parsing. 479 // Scope-specific information computed during parsing.
488 // 480 //
489 // This scope is inside a 'with' of some outer scope. 481 // This scope is inside a 'with' of some outer scope.
490 bool scope_inside_with_; 482 bool scope_inside_with_;
491 // This scope contains a 'with' statement. 483 // This scope contains a 'with' statement.
492 bool scope_contains_with_; 484 bool scope_contains_with_;
493 // This scope or a nested catch scope or with scope contain an 'eval' call. At 485 // This scope or a nested catch scope or with scope contain an 'eval' call. At
494 // the 'eval' call site this scope is the declaration scope. 486 // the 'eval' call site this scope is the declaration scope.
495 bool scope_calls_eval_; 487 bool scope_calls_eval_;
496 // The language mode of this scope. 488 // The strict mode of this scope.
497 LanguageMode language_mode_; 489 StrictMode strict_mode_;
498 // Source positions. 490 // Source positions.
499 int start_position_; 491 int start_position_;
500 int end_position_; 492 int end_position_;
501 493
502 // Computed via PropagateScopeInfo. 494 // Computed via PropagateScopeInfo.
503 bool outer_scope_calls_non_strict_eval_; 495 bool outer_scope_calls_sloppy_eval_;
504 bool inner_scope_calls_eval_; 496 bool inner_scope_calls_eval_;
505 bool force_eager_compilation_; 497 bool force_eager_compilation_;
506 bool force_context_allocation_; 498 bool force_context_allocation_;
507 499
508 // True if it doesn't need scope resolution (e.g., if the scope was 500 // True if it doesn't need scope resolution (e.g., if the scope was
509 // constructed based on a serialized scope info or a catch context). 501 // constructed based on a serialized scope info or a catch context).
510 bool already_resolved_; 502 bool already_resolved_;
511 503
512 // Computed as variables are declared. 504 // Computed as variables are declared.
513 int num_var_or_const_; 505 int num_var_or_const_;
(...skipping 17 matching lines...) Expand all
531 Variable* NonLocal(Handle<String> name, VariableMode mode); 523 Variable* NonLocal(Handle<String> name, VariableMode mode);
532 524
533 // Variable resolution. 525 // Variable resolution.
534 // Possible results of a recursive variable lookup telling if and how a 526 // Possible results of a recursive variable lookup telling if and how a
535 // variable is bound. These are returned in the output parameter *binding_kind 527 // variable is bound. These are returned in the output parameter *binding_kind
536 // of the LookupRecursive function. 528 // of the LookupRecursive function.
537 enum BindingKind { 529 enum BindingKind {
538 // The variable reference could be statically resolved to a variable binding 530 // The variable reference could be statically resolved to a variable binding
539 // which is returned. There is no 'with' statement between the reference and 531 // which is returned. There is no 'with' statement between the reference and
540 // the binding and no scope between the reference scope (inclusive) and 532 // the binding and no scope between the reference scope (inclusive) and
541 // binding scope (exclusive) makes a non-strict 'eval' call. 533 // binding scope (exclusive) makes a sloppy 'eval' call.
542 BOUND, 534 BOUND,
543 535
544 // The variable reference could be statically resolved to a variable binding 536 // The variable reference could be statically resolved to a variable binding
545 // which is returned. There is no 'with' statement between the reference and 537 // which is returned. There is no 'with' statement between the reference and
546 // the binding, but some scope between the reference scope (inclusive) and 538 // the binding, but some scope between the reference scope (inclusive) and
547 // binding scope (exclusive) makes a non-strict 'eval' call, that might 539 // binding scope (exclusive) makes a sloppy 'eval' call, that might
548 // possibly introduce variable bindings shadowing the found one. Thus the 540 // possibly introduce variable bindings shadowing the found one. Thus the
549 // found variable binding is just a guess. 541 // found variable binding is just a guess.
550 BOUND_EVAL_SHADOWED, 542 BOUND_EVAL_SHADOWED,
551 543
552 // The variable reference could not be statically resolved to any binding 544 // The variable reference could not be statically resolved to any binding
553 // and thus should be considered referencing a global variable. NULL is 545 // and thus should be considered referencing a global variable. NULL is
554 // returned. The variable reference is not inside any 'with' statement and 546 // returned. The variable reference is not inside any 'with' statement and
555 // no scope between the reference scope (inclusive) and global scope 547 // no scope between the reference scope (inclusive) and global scope
556 // (exclusive) makes a non-strict 'eval' call. 548 // (exclusive) makes a sloppy 'eval' call.
557 UNBOUND, 549 UNBOUND,
558 550
559 // The variable reference could not be statically resolved to any binding 551 // The variable reference could not be statically resolved to any binding
560 // NULL is returned. The variable reference is not inside any 'with' 552 // NULL is returned. The variable reference is not inside any 'with'
561 // statement, but some scope between the reference scope (inclusive) and 553 // statement, but some scope between the reference scope (inclusive) and
562 // global scope (exclusive) makes a non-strict 'eval' call, that might 554 // global scope (exclusive) makes a sloppy 'eval' call, that might
563 // possibly introduce a variable binding. Thus the reference should be 555 // possibly introduce a variable binding. Thus the reference should be
564 // considered referencing a global variable unless it is shadowed by an 556 // considered referencing a global variable unless it is shadowed by an
565 // 'eval' introduced binding. 557 // 'eval' introduced binding.
566 UNBOUND_EVAL_SHADOWED, 558 UNBOUND_EVAL_SHADOWED,
567 559
568 // The variable could not be statically resolved and needs to be looked up 560 // The variable could not be statically resolved and needs to be looked up
569 // dynamically. NULL is returned. There are two possible reasons: 561 // dynamically. NULL is returned. There are two possible reasons:
570 // * A 'with' statement has been encountered and there is no variable 562 // * A 'with' statement has been encountered and there is no variable
571 // binding for the name between the variable reference and the 'with'. 563 // binding for the name between the variable reference and the 'with'.
572 // The variable potentially references a property of the 'with' object. 564 // The variable potentially references a property of the 'with' object.
(...skipping 11 matching lines...) Expand all
584 AstNodeFactory<AstNullVisitor>* factory); 576 AstNodeFactory<AstNullVisitor>* factory);
585 MUST_USE_RESULT 577 MUST_USE_RESULT
586 bool ResolveVariable(CompilationInfo* info, 578 bool ResolveVariable(CompilationInfo* info,
587 VariableProxy* proxy, 579 VariableProxy* proxy,
588 AstNodeFactory<AstNullVisitor>* factory); 580 AstNodeFactory<AstNullVisitor>* factory);
589 MUST_USE_RESULT 581 MUST_USE_RESULT
590 bool ResolveVariablesRecursively(CompilationInfo* info, 582 bool ResolveVariablesRecursively(CompilationInfo* info,
591 AstNodeFactory<AstNullVisitor>* factory); 583 AstNodeFactory<AstNullVisitor>* factory);
592 584
593 // Scope analysis. 585 // Scope analysis.
594 bool PropagateScopeInfo(bool outer_scope_calls_non_strict_eval); 586 bool PropagateScopeInfo(bool outer_scope_calls_sloppy_eval);
595 bool HasTrivialContext() const; 587 bool HasTrivialContext() const;
596 588
597 // Predicates. 589 // Predicates.
598 bool MustAllocate(Variable* var); 590 bool MustAllocate(Variable* var);
599 bool MustAllocateInContext(Variable* var); 591 bool MustAllocateInContext(Variable* var);
600 bool HasArgumentsParameter(); 592 bool HasArgumentsParameter();
601 593
602 // Variable allocation. 594 // Variable allocation.
603 void AllocateStackSlot(Variable* var); 595 void AllocateStackSlot(Variable* var);
604 void AllocateHeapSlot(Variable* var); 596 void AllocateHeapSlot(Variable* var);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 void SetDefaults(ScopeType type, 630 void SetDefaults(ScopeType type,
639 Scope* outer_scope, 631 Scope* outer_scope,
640 Handle<ScopeInfo> scope_info); 632 Handle<ScopeInfo> scope_info);
641 633
642 Zone* zone_; 634 Zone* zone_;
643 }; 635 };
644 636
645 } } // namespace v8::internal 637 } } // namespace v8::internal
646 638
647 #endif // V8_SCOPES_H_ 639 #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