| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PARSING_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
| 6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 typedef PreParserFactory Factory; | 617 typedef PreParserFactory Factory; |
| 618 }; | 618 }; |
| 619 | 619 |
| 620 // TODO(nikolaos): The traits methods should not need to call methods | 620 // TODO(nikolaos): The traits methods should not need to call methods |
| 621 // of the implementation object. | 621 // of the implementation object. |
| 622 PreParser* delegate() { return reinterpret_cast<PreParser*>(this); } | 622 PreParser* delegate() { return reinterpret_cast<PreParser*>(this); } |
| 623 const PreParser* delegate() const { | 623 const PreParser* delegate() const { |
| 624 return reinterpret_cast<const PreParser*>(this); | 624 return reinterpret_cast<const PreParser*>(this); |
| 625 } | 625 } |
| 626 | 626 |
| 627 // Helper functions for recursive descent. | |
| 628 bool IsEval(PreParserIdentifier identifier) const { | |
| 629 return identifier.IsEval(); | |
| 630 } | |
| 631 | |
| 632 bool IsArguments(PreParserIdentifier identifier) const { | |
| 633 return identifier.IsArguments(); | |
| 634 } | |
| 635 | |
| 636 bool IsEvalOrArguments(PreParserIdentifier identifier) const { | |
| 637 return identifier.IsEvalOrArguments(); | |
| 638 } | |
| 639 | |
| 640 bool IsUndefined(PreParserIdentifier identifier) const { | |
| 641 return identifier.IsUndefined(); | |
| 642 } | |
| 643 | |
| 644 bool IsAwait(PreParserIdentifier identifier) const { | |
| 645 return identifier.IsAwait(); | |
| 646 } | |
| 647 | |
| 648 bool IsFutureStrictReserved(PreParserIdentifier identifier) const { | |
| 649 return identifier.IsFutureStrictReserved(); | |
| 650 } | |
| 651 | |
| 652 // Returns true if the expression is of type "this.foo". | |
| 653 static bool IsThisProperty(PreParserExpression expression) { | |
| 654 return expression.IsThisProperty(); | |
| 655 } | |
| 656 | |
| 657 static bool IsIdentifier(PreParserExpression expression) { | |
| 658 return expression.IsIdentifier(); | |
| 659 } | |
| 660 | |
| 661 static PreParserIdentifier AsIdentifier(PreParserExpression expression) { | |
| 662 return expression.AsIdentifier(); | |
| 663 } | |
| 664 | |
| 665 bool IsPrototype(PreParserIdentifier identifier) const { | |
| 666 return identifier.IsPrototype(); | |
| 667 } | |
| 668 | |
| 669 bool IsConstructor(PreParserIdentifier identifier) const { | |
| 670 return identifier.IsConstructor(); | |
| 671 } | |
| 672 | |
| 673 bool IsDirectEvalCall(PreParserExpression expression) const { | |
| 674 return expression.IsDirectEvalCall(); | |
| 675 } | |
| 676 | |
| 677 static bool IsBoilerplateProperty(PreParserExpression property) { | |
| 678 // PreParser doesn't count boilerplate properties. | |
| 679 return false; | |
| 680 } | |
| 681 | |
| 682 static bool IsArrayIndex(PreParserIdentifier string, uint32_t* index) { | |
| 683 return false; | |
| 684 } | |
| 685 | |
| 686 static PreParserExpression GetPropertyValue(PreParserExpression property) { | |
| 687 return PreParserExpression::Default(); | |
| 688 } | |
| 689 | |
| 690 // Functions for encapsulating the differences between parsing and preparsing; | |
| 691 // operations interleaved with the recursive descent. | |
| 692 static void PushLiteralName(FuncNameInferrer* fni, PreParserIdentifier id) { | |
| 693 // PreParser should not use FuncNameInferrer. | |
| 694 UNREACHABLE(); | |
| 695 } | |
| 696 | |
| 697 void PushPropertyName(FuncNameInferrer* fni, PreParserExpression expression) { | |
| 698 // PreParser should not use FuncNameInferrer. | |
| 699 UNREACHABLE(); | |
| 700 } | |
| 701 | |
| 702 static void InferFunctionName(FuncNameInferrer* fni, | |
| 703 PreParserExpression expression) { | |
| 704 // PreParser should not use FuncNameInferrer. | |
| 705 UNREACHABLE(); | |
| 706 } | |
| 707 | |
| 708 static void CheckAssigningFunctionLiteralToProperty( | |
| 709 PreParserExpression left, PreParserExpression right) {} | |
| 710 | |
| 711 static PreParserExpression MarkExpressionAsAssigned( | |
| 712 PreParserExpression expression) { | |
| 713 // TODO(marja): To be able to produce the same errors, the preparser needs | |
| 714 // to start tracking which expressions are variables and which are assigned. | |
| 715 return expression; | |
| 716 } | |
| 717 | |
| 718 bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, | |
| 719 PreParserExpression y, | |
| 720 Token::Value op, int pos, | |
| 721 PreParserFactory* factory) { | |
| 722 return false; | |
| 723 } | |
| 724 | |
| 725 PreParserExpression BuildUnaryExpression(PreParserExpression expression, | 627 PreParserExpression BuildUnaryExpression(PreParserExpression expression, |
| 726 Token::Value op, int pos, | 628 Token::Value op, int pos, |
| 727 PreParserFactory* factory) { | 629 PreParserFactory* factory) { |
| 728 return PreParserExpression::Default(); | 630 return PreParserExpression::Default(); |
| 729 } | 631 } |
| 730 | 632 |
| 731 PreParserExpression BuildIteratorResult(PreParserExpression value, | 633 PreParserExpression BuildIteratorResult(PreParserExpression value, |
| 732 bool done) { | 634 bool done) { |
| 733 return PreParserExpression::Default(); | 635 return PreParserExpression::Default(); |
| 734 } | 636 } |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier, | 1031 V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier, |
| 1130 bool* ok) { | 1032 bool* ok) { |
| 1131 ValidateExpression(classifier, ok); | 1033 ValidateExpression(classifier, ok); |
| 1132 } | 1034 } |
| 1133 | 1035 |
| 1134 V8_INLINE void QueueDestructuringAssignmentForRewriting( | 1036 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
| 1135 PreParserExpression assignment) {} | 1037 PreParserExpression assignment) {} |
| 1136 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, | 1038 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, |
| 1137 bool* ok) {} | 1039 bool* ok) {} |
| 1138 | 1040 |
| 1041 // Helper functions for recursive descent. |
| 1042 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { |
| 1043 return identifier.IsEval(); |
| 1044 } |
| 1045 |
| 1046 V8_INLINE bool IsArguments(PreParserIdentifier identifier) const { |
| 1047 return identifier.IsArguments(); |
| 1048 } |
| 1049 |
| 1050 V8_INLINE bool IsEvalOrArguments(PreParserIdentifier identifier) const { |
| 1051 return identifier.IsEvalOrArguments(); |
| 1052 } |
| 1053 |
| 1054 V8_INLINE bool IsUndefined(PreParserIdentifier identifier) const { |
| 1055 return identifier.IsUndefined(); |
| 1056 } |
| 1057 |
| 1058 V8_INLINE bool IsAwait(PreParserIdentifier identifier) const { |
| 1059 return identifier.IsAwait(); |
| 1060 } |
| 1061 |
| 1062 V8_INLINE bool IsFutureStrictReserved(PreParserIdentifier identifier) const { |
| 1063 return identifier.IsFutureStrictReserved(); |
| 1064 } |
| 1065 |
| 1066 // Returns true if the expression is of type "this.foo". |
| 1067 V8_INLINE static bool IsThisProperty(PreParserExpression expression) { |
| 1068 return expression.IsThisProperty(); |
| 1069 } |
| 1070 |
| 1071 V8_INLINE static bool IsIdentifier(PreParserExpression expression) { |
| 1072 return expression.IsIdentifier(); |
| 1073 } |
| 1074 |
| 1075 V8_INLINE static PreParserIdentifier AsIdentifier( |
| 1076 PreParserExpression expression) { |
| 1077 return expression.AsIdentifier(); |
| 1078 } |
| 1079 |
| 1080 V8_INLINE bool IsPrototype(PreParserIdentifier identifier) const { |
| 1081 return identifier.IsPrototype(); |
| 1082 } |
| 1083 |
| 1084 V8_INLINE bool IsConstructor(PreParserIdentifier identifier) const { |
| 1085 return identifier.IsConstructor(); |
| 1086 } |
| 1087 |
| 1088 V8_INLINE bool IsDirectEvalCall(PreParserExpression expression) const { |
| 1089 return expression.IsDirectEvalCall(); |
| 1090 } |
| 1091 |
| 1092 V8_INLINE static bool IsBoilerplateProperty(PreParserExpression property) { |
| 1093 // PreParser doesn't count boilerplate properties. |
| 1094 return false; |
| 1095 } |
| 1096 |
| 1097 V8_INLINE static bool IsArrayIndex(PreParserIdentifier string, |
| 1098 uint32_t* index) { |
| 1099 return false; |
| 1100 } |
| 1101 |
| 1102 V8_INLINE static PreParserExpression GetPropertyValue( |
| 1103 PreParserExpression property) { |
| 1104 return PreParserExpression::Default(); |
| 1105 } |
| 1106 |
| 1107 // Functions for encapsulating the differences between parsing and preparsing; |
| 1108 // operations interleaved with the recursive descent. |
| 1109 V8_INLINE static void PushLiteralName(FuncNameInferrer* fni, |
| 1110 PreParserIdentifier id) { |
| 1111 // PreParser should not use FuncNameInferrer. |
| 1112 UNREACHABLE(); |
| 1113 } |
| 1114 |
| 1115 V8_INLINE void PushPropertyName(FuncNameInferrer* fni, |
| 1116 PreParserExpression expression) { |
| 1117 // PreParser should not use FuncNameInferrer. |
| 1118 UNREACHABLE(); |
| 1119 } |
| 1120 |
| 1121 V8_INLINE static void InferFunctionName(FuncNameInferrer* fni, |
| 1122 PreParserExpression expression) { |
| 1123 // PreParser should not use FuncNameInferrer. |
| 1124 UNREACHABLE(); |
| 1125 } |
| 1126 |
| 1127 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( |
| 1128 PreParserExpression left, PreParserExpression right) {} |
| 1129 |
| 1130 V8_INLINE static PreParserExpression MarkExpressionAsAssigned( |
| 1131 PreParserExpression expression) { |
| 1132 // TODO(marja): To be able to produce the same errors, the preparser needs |
| 1133 // to start tracking which expressions are variables and which are assigned. |
| 1134 return expression; |
| 1135 } |
| 1136 |
| 1137 V8_INLINE bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, |
| 1138 PreParserExpression y, |
| 1139 Token::Value op, |
| 1140 int pos) { |
| 1141 return false; |
| 1142 } |
| 1143 |
| 1144 // Preparser's private field members. |
| 1145 |
| 1139 int* use_counts_; | 1146 int* use_counts_; |
| 1140 }; | 1147 }; |
| 1141 | 1148 |
| 1142 void ParserBaseTraits<PreParser>::MaterializeUnspreadArgumentsLiterals( | 1149 void ParserBaseTraits<PreParser>::MaterializeUnspreadArgumentsLiterals( |
| 1143 int count) { | 1150 int count) { |
| 1144 for (int i = 0; i < count; ++i) { | 1151 for (int i = 0; i < count; ++i) { |
| 1145 delegate()->function_state_->NextMaterializedLiteralIndex(); | 1152 delegate()->function_state_->NextMaterializedLiteralIndex(); |
| 1146 } | 1153 } |
| 1147 } | 1154 } |
| 1148 | 1155 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 function_state_->NextMaterializedLiteralIndex(); | 1216 function_state_->NextMaterializedLiteralIndex(); |
| 1210 function_state_->NextMaterializedLiteralIndex(); | 1217 function_state_->NextMaterializedLiteralIndex(); |
| 1211 } | 1218 } |
| 1212 return EmptyExpression(); | 1219 return EmptyExpression(); |
| 1213 } | 1220 } |
| 1214 | 1221 |
| 1215 } // namespace internal | 1222 } // namespace internal |
| 1216 } // namespace v8 | 1223 } // namespace v8 |
| 1217 | 1224 |
| 1218 #endif // V8_PARSING_PREPARSER_H | 1225 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |