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

Side by Side Diff: src/preparser.cc

Issue 199233003: Revert "Move ParseAssignmentExpression to ParserBase." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
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/preparser.h ('k') | no next file » | 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // Usually defined in math.h, but not in MSVC until VS2013+. 48 // Usually defined in math.h, but not in MSVC until VS2013+.
49 // Abstracted to work 49 // Abstracted to work
50 int isfinite(double value); 50 int isfinite(double value);
51 51
52 } // namespace std 52 } // namespace std
53 #endif 53 #endif
54 54
55 namespace v8 { 55 namespace v8 {
56 namespace internal { 56 namespace internal {
57 57
58
59 void PreParserTraits::CheckStrictModeLValue(PreParserExpression expression,
60 bool* ok) {
61 if (expression.IsIdentifier() &&
62 expression.AsIdentifier().IsEvalOrArguments()) {
63 pre_parser_->ReportMessage("strict_eval_arguments",
64 Vector<const char*>::empty());
65 *ok = false;
66 }
67 }
68
69
70 void PreParserTraits::ReportMessageAt(Scanner::Location location, 58 void PreParserTraits::ReportMessageAt(Scanner::Location location,
71 const char* message, 59 const char* message,
72 Vector<const char*> args) { 60 Vector<const char*> args) {
73 ReportMessageAt(location.beg_pos, 61 ReportMessageAt(location.beg_pos,
74 location.end_pos, 62 location.end_pos,
75 message, 63 message,
76 args.length() > 0 ? args[0] : NULL); 64 args.length() > 0 ? args[0] : NULL);
77 } 65 }
78 66
79 67
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 PreParserExpression PreParserTraits::ExpressionFromString( 104 PreParserExpression PreParserTraits::ExpressionFromString(
117 int pos, Scanner* scanner, PreParserFactory* factory) { 105 int pos, Scanner* scanner, PreParserFactory* factory) {
118 pre_parser_->LogSymbol(); 106 pre_parser_->LogSymbol();
119 if (scanner->UnescapedLiteralMatches("use strict", 10)) { 107 if (scanner->UnescapedLiteralMatches("use strict", 10)) {
120 return PreParserExpression::UseStrictStringLiteral(); 108 return PreParserExpression::UseStrictStringLiteral();
121 } 109 }
122 return PreParserExpression::StringLiteral(); 110 return PreParserExpression::StringLiteral();
123 } 111 }
124 112
125 113
114 PreParserExpression PreParserTraits::ParseAssignmentExpression(bool accept_IN,
115 bool* ok) {
116 return pre_parser_->ParseAssignmentExpression(accept_IN, ok);
117 }
118
119
126 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { 120 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) {
127 return pre_parser_->ParseV8Intrinsic(ok); 121 return pre_parser_->ParseV8Intrinsic(ok);
128 } 122 }
129 123
130 124
131 PreParserExpression PreParserTraits::ParseFunctionLiteral( 125 PreParserExpression PreParserTraits::ParseFunctionLiteral(
132 PreParserIdentifier name, 126 PreParserIdentifier name,
133 Scanner::Location function_name_location, 127 Scanner::Location function_name_location,
134 bool name_is_strict_reserved, 128 bool name_is_strict_reserved,
135 bool is_generator, 129 bool is_generator,
136 int function_token_position, 130 int function_token_position,
137 FunctionLiteral::FunctionType type, 131 FunctionLiteral::FunctionType type,
138 bool* ok) { 132 bool* ok) {
139 return pre_parser_->ParseFunctionLiteral( 133 return pre_parser_->ParseFunctionLiteral(
140 name, function_name_location, name_is_strict_reserved, is_generator, 134 name, function_name_location, name_is_strict_reserved, is_generator,
141 function_token_position, type, ok); 135 function_token_position, type, ok);
142 } 136 }
143 137
144 138
145 PreParserExpression PreParserTraits::ParseYieldExpression(bool* ok) {
146 return pre_parser_->ParseYieldExpression(ok);
147 }
148
149
150 PreParserExpression PreParserTraits::ParseConditionalExpression(bool accept_IN,
151 bool* ok) {
152 return pre_parser_->ParseConditionalExpression(accept_IN, ok);
153 }
154
155
156 PreParser::PreParseResult PreParser::PreParseLazyFunction( 139 PreParser::PreParseResult PreParser::PreParseLazyFunction(
157 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { 140 StrictMode strict_mode, bool is_generator, ParserRecorder* log) {
158 log_ = log; 141 log_ = log;
159 // Lazy functions always have trivial outer scopes (no with/catch scopes). 142 // Lazy functions always have trivial outer scopes (no with/catch scopes).
160 PreParserScope top_scope(scope_, GLOBAL_SCOPE); 143 PreParserScope top_scope(scope_, GLOBAL_SCOPE);
161 FunctionState top_state(&function_state_, &scope_, &top_scope); 144 FunctionState top_state(&function_state_, &scope_, &top_scope);
162 scope_->SetStrictMode(strict_mode); 145 scope_->SetStrictMode(strict_mode);
163 PreParserScope function_scope(scope_, FUNCTION_SCOPE); 146 PreParserScope function_scope(scope_, FUNCTION_SCOPE);
164 FunctionState function_state(&function_state_, &scope_, &function_scope); 147 FunctionState function_state(&function_state_, &scope_, &function_scope);
165 function_state.set_is_generator(is_generator); 148 function_state.set_is_generator(is_generator);
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 820
838 821
839 #undef CHECK_OK 822 #undef CHECK_OK
840 #define CHECK_OK ok); \ 823 #define CHECK_OK ok); \
841 if (!*ok) return Expression::Default(); \ 824 if (!*ok) return Expression::Default(); \
842 ((void)0 825 ((void)0
843 #define DUMMY ) // to make indentation work 826 #define DUMMY ) // to make indentation work
844 #undef DUMMY 827 #undef DUMMY
845 828
846 829
830 // Precedence = 2
831 PreParser::Expression PreParser::ParseAssignmentExpression(bool accept_IN,
832 bool* ok) {
833 // AssignmentExpression ::
834 // ConditionalExpression
835 // YieldExpression
836 // LeftHandSideExpression AssignmentOperator AssignmentExpression
837
838 if (function_state_->is_generator() && peek() == Token::YIELD) {
839 return ParseYieldExpression(ok);
840 }
841
842 Scanner::Location before = scanner()->peek_location();
843 Expression expression = ParseConditionalExpression(accept_IN, CHECK_OK);
844
845 if (!Token::IsAssignmentOp(peek())) {
846 // Parsed conditional expression only (no assignment).
847 return expression;
848 }
849
850 if (strict_mode() == STRICT &&
851 expression.IsIdentifier() &&
852 expression.AsIdentifier().IsEvalOrArguments()) {
853 Scanner::Location after = scanner()->location();
854 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos,
855 "strict_eval_arguments", NULL);
856 *ok = false;
857 return Expression::Default();
858 }
859
860 Token::Value op = Next(); // Get assignment operator.
861 ParseAssignmentExpression(accept_IN, CHECK_OK);
862
863 if ((op == Token::ASSIGN) && expression.IsThisProperty()) {
864 function_state_->AddProperty();
865 }
866
867 return Expression::Default();
868 }
869
870
847 // Precedence = 3 871 // Precedence = 3
848 PreParser::Expression PreParser::ParseYieldExpression(bool* ok) { 872 PreParser::Expression PreParser::ParseYieldExpression(bool* ok) {
849 // YieldExpression :: 873 // YieldExpression ::
850 // 'yield' '*'? AssignmentExpression 874 // 'yield' '*'? AssignmentExpression
851 Consume(Token::YIELD); 875 Consume(Token::YIELD);
852 Check(Token::MUL); 876 Check(Token::MUL);
853 877
854 ParseAssignmentExpression(false, CHECK_OK); 878 ParseAssignmentExpression(false, CHECK_OK);
855 879
856 return Expression::Default(); 880 return Expression::Default();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 // '~' UnaryExpression 932 // '~' UnaryExpression
909 // '!' UnaryExpression 933 // '!' UnaryExpression
910 934
911 Token::Value op = peek(); 935 Token::Value op = peek();
912 if (Token::IsUnaryOp(op)) { 936 if (Token::IsUnaryOp(op)) {
913 op = Next(); 937 op = Next();
914 ParseUnaryExpression(ok); 938 ParseUnaryExpression(ok);
915 return Expression::Default(); 939 return Expression::Default();
916 } else if (Token::IsCountOp(op)) { 940 } else if (Token::IsCountOp(op)) {
917 op = Next(); 941 op = Next();
942 Scanner::Location before = scanner()->peek_location();
918 Expression expression = ParseUnaryExpression(CHECK_OK); 943 Expression expression = ParseUnaryExpression(CHECK_OK);
919 if (strict_mode() == STRICT) { 944 if (strict_mode() == STRICT &&
920 CheckStrictModeLValue(expression, CHECK_OK); 945 expression.IsIdentifier() &&
946 expression.AsIdentifier().IsEvalOrArguments()) {
947 Scanner::Location after = scanner()->location();
948 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos,
949 "strict_eval_arguments", NULL);
950 *ok = false;
921 } 951 }
922 return Expression::Default(); 952 return Expression::Default();
923 } else { 953 } else {
924 return ParsePostfixExpression(ok); 954 return ParsePostfixExpression(ok);
925 } 955 }
926 } 956 }
927 957
928 958
929 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { 959 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) {
930 // PostfixExpression :: 960 // PostfixExpression ::
931 // LeftHandSideExpression ('++' | '--')? 961 // LeftHandSideExpression ('++' | '--')?
932 962
963 Scanner::Location before = scanner()->peek_location();
933 Expression expression = ParseLeftHandSideExpression(CHECK_OK); 964 Expression expression = ParseLeftHandSideExpression(CHECK_OK);
934 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 965 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
935 Token::IsCountOp(peek())) { 966 Token::IsCountOp(peek())) {
936 if (strict_mode() == STRICT) { 967 if (strict_mode() == STRICT &&
937 CheckStrictModeLValue(expression, CHECK_OK); 968 expression.IsIdentifier() &&
969 expression.AsIdentifier().IsEvalOrArguments()) {
970 Scanner::Location after = scanner()->location();
971 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos,
972 "strict_eval_arguments", NULL);
973 *ok = false;
974 return Expression::Default();
938 } 975 }
939 Next(); 976 Next();
940 return Expression::Default(); 977 return Expression::Default();
941 } 978 }
942 return expression; 979 return expression;
943 } 980 }
944 981
945 982
946 PreParser::Expression PreParser::ParseLeftHandSideExpression(bool* ok) { 983 PreParser::Expression PreParser::ParseLeftHandSideExpression(bool* ok) {
947 // LeftHandSideExpression :: 984 // LeftHandSideExpression ::
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 1267
1231 1268
1232 void PreParser::LogSymbol() { 1269 void PreParser::LogSymbol() {
1233 if (log_->ShouldLogSymbols()) { 1270 if (log_->ShouldLogSymbols()) {
1234 scanner()->LogSymbol(log_, position()); 1271 scanner()->LogSymbol(log_, position());
1235 } 1272 }
1236 } 1273 }
1237 1274
1238 1275
1239 } } // v8::internal 1276 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698