OLD | NEW |
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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 } | 547 } |
548 | 548 |
549 static PreParserExpression This() { | 549 static PreParserExpression This() { |
550 return PreParserExpression(kThisExpression); | 550 return PreParserExpression(kThisExpression); |
551 } | 551 } |
552 | 552 |
553 static PreParserExpression ThisProperty() { | 553 static PreParserExpression ThisProperty() { |
554 return PreParserExpression(kThisPropertyExpression); | 554 return PreParserExpression(kThisPropertyExpression); |
555 } | 555 } |
556 | 556 |
557 static PreParserExpression StrictFunction() { | 557 static PreParserExpression Property() { |
558 return PreParserExpression(kStrictFunctionExpression); | 558 return PreParserExpression(kPropertyExpression); |
559 } | 559 } |
560 | 560 |
561 bool IsIdentifier() { return (code_ & kIdentifierFlag) != 0; } | 561 bool IsIdentifier() { return (code_ & kIdentifierFlag) != 0; } |
562 | 562 |
563 // Only works corretly if it is actually an identifier expression. | 563 // Only works corretly if it is actually an identifier expression. |
564 PreParserIdentifier AsIdentifier() { | 564 PreParserIdentifier AsIdentifier() { |
565 return PreParserIdentifier( | 565 return PreParserIdentifier( |
566 static_cast<PreParserIdentifier::Type>(code_ >> kIdentifierShift)); | 566 static_cast<PreParserIdentifier::Type>(code_ >> kIdentifierShift)); |
567 } | 567 } |
568 | 568 |
569 bool IsStringLiteral() { return (code_ & kStringLiteralFlag) != 0; } | 569 bool IsStringLiteral() { return (code_ & kStringLiteralFlag) != 0; } |
570 | 570 |
571 bool IsUseStrictLiteral() { | 571 bool IsUseStrictLiteral() { |
572 return (code_ & kStringLiteralMask) == kUseStrictString; | 572 return (code_ & kStringLiteralMask) == kUseStrictString; |
573 } | 573 } |
574 | 574 |
575 bool IsThis() { return code_ == kThisExpression; } | 575 bool IsThis() { return code_ == kThisExpression; } |
576 | 576 |
577 bool IsThisProperty() { return code_ == kThisPropertyExpression; } | 577 bool IsThisProperty() { return code_ == kThisPropertyExpression; } |
578 | 578 |
579 bool IsStrictFunction() { return code_ == kStrictFunctionExpression; } | 579 bool IsProperty() { |
| 580 return code_ == kPropertyExpression || code_ == kThisPropertyExpression; |
| 581 } |
580 | 582 |
581 // Dummy implementation for making expression->AsCall() work (see below). | 583 // Dummy implementation for making expression->AsCall() work (see below). |
582 PreParserExpression* operator->() { return this; } | 584 PreParserExpression* operator->() { return this; } |
583 | 585 |
584 // These are only used when doing function name inferring, and PreParser | 586 // These are only used when doing function name inferring, and PreParser |
585 // doesn't do function name inferring. | 587 // doesn't do function name inferring. |
586 void* AsCall() const { return NULL; } | 588 void* AsCall() const { return NULL; } |
587 void* AsCallNew() const { return NULL; } | 589 void* AsCallNew() const { return NULL; } |
588 | 590 |
589 // More dummy implementations of things PreParser doesn't need to track: | 591 // More dummy implementations of things PreParser doesn't need to track: |
590 void set_index(int index) {} // For YieldExpressions | 592 void set_index(int index) {} // For YieldExpressions |
591 | 593 |
592 private: | 594 private: |
593 // First two/three bits are used as flags. | 595 // Least significant 2 bits are used as flags. Bits 0 and 1 represent |
594 // Bit 0 and 1 represent identifiers or strings literals, and are | 596 // identifiers or strings literals, and are mutually exclusive, but can both |
595 // mutually exclusive, but can both be absent. | 597 // be absent. If the expression is an identifier or a string literal, the |
| 598 // other bits describe the type (see PreParserIdentifier::Type and string |
| 599 // literal constants below). |
596 enum { | 600 enum { |
597 kUnknownExpression = 0, | 601 kUnknownExpression = 0, |
598 // Identifiers | 602 // Identifiers |
599 kIdentifierFlag = 1, // Used to detect labels. | 603 kIdentifierFlag = 1, // Used to detect labels. |
600 kIdentifierShift = 3, | 604 kIdentifierShift = 3, |
601 | 605 |
602 kStringLiteralFlag = 2, // Used to detect directive prologue. | 606 kStringLiteralFlag = 2, // Used to detect directive prologue. |
603 kUnknownStringLiteral = kStringLiteralFlag, | 607 kUnknownStringLiteral = kStringLiteralFlag, |
604 kUseStrictString = kStringLiteralFlag | 8, | 608 kUseStrictString = kStringLiteralFlag | 8, |
605 kStringLiteralMask = kUseStrictString, | 609 kStringLiteralMask = kUseStrictString, |
606 | 610 |
607 // Below here applies if neither identifier nor string literal. | 611 // Below here applies if neither identifier nor string literal. Reserve the |
608 kThisExpression = 4, | 612 // 2 least significant bits for flags. |
609 kThisPropertyExpression = 8, | 613 kThisExpression = 1 << 2, |
610 kStrictFunctionExpression = 12 | 614 kThisPropertyExpression = 2 << 2, |
| 615 kPropertyExpression = 3 << 2 |
611 }; | 616 }; |
612 | 617 |
613 explicit PreParserExpression(int expression_code) : code_(expression_code) {} | 618 explicit PreParserExpression(int expression_code) : code_(expression_code) {} |
614 | 619 |
615 int code_; | 620 int code_; |
616 }; | 621 }; |
617 | 622 |
618 | 623 |
619 // PreParserExpressionList doesn't actually store the expressions because | 624 // PreParserExpressionList doesn't actually store the expressions because |
620 // PreParser doesn't need to. | 625 // PreParser doesn't need to. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 } | 828 } |
824 | 829 |
825 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( | 830 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( |
826 PreParserScope* scope, PreParserExpression value, bool* has_function) {} | 831 PreParserScope* scope, PreParserExpression value, bool* has_function) {} |
827 | 832 |
828 static void CheckAssigningFunctionLiteralToProperty( | 833 static void CheckAssigningFunctionLiteralToProperty( |
829 PreParserExpression left, PreParserExpression right) {} | 834 PreParserExpression left, PreParserExpression right) {} |
830 | 835 |
831 // Determine whether the expression is a valid assignment left-hand side. | 836 // Determine whether the expression is a valid assignment left-hand side. |
832 static bool IsValidLeftHandSide(PreParserExpression expression) { | 837 static bool IsValidLeftHandSide(PreParserExpression expression) { |
833 // TODO(marja): check properly; for now, leave it to parser. | 838 return expression.IsIdentifier() || expression.IsProperty(); |
834 return true; | |
835 } | 839 } |
836 | 840 |
837 static PreParserExpression MarkExpressionAsLValue( | 841 static PreParserExpression MarkExpressionAsLValue( |
838 PreParserExpression expression) { | 842 PreParserExpression expression) { |
839 // TODO(marja): To be able to produce the same errors, the preparser needs | 843 // TODO(marja): To be able to produce the same errors, the preparser needs |
840 // to start tracking which expressions are variables and which are lvalues. | 844 // to start tracking which expressions are variables and which are lvalues. |
841 return expression; | 845 return expression; |
842 } | 846 } |
843 | 847 |
844 // Checks LHS expression for assignment and prefix/postfix increment/decrement | 848 // Checks LHS expression for assignment and prefix/postfix increment/decrement |
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 "accessor_get_set"); | 1890 "accessor_get_set"); |
1887 } | 1891 } |
1888 *ok = false; | 1892 *ok = false; |
1889 } | 1893 } |
1890 } | 1894 } |
1891 | 1895 |
1892 | 1896 |
1893 } } // v8::internal | 1897 } } // v8::internal |
1894 | 1898 |
1895 #endif // V8_PREPARSER_H | 1899 #endif // V8_PREPARSER_H |
OLD | NEW |