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

Side by Side Diff: src/preparser.h

Issue 1123383005: Rely on ExpressionClassifier to match valid arrow function formals (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « src/parser.cc ('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 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_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 bool IsSpreadExpression() const { 1188 bool IsSpreadExpression() const {
1189 return TypeField::decode(code_) == kSpreadExpression; 1189 return TypeField::decode(code_) == kSpreadExpression;
1190 } 1190 }
1191 1191
1192 PreParserExpression AsFunctionLiteral() { return *this; } 1192 PreParserExpression AsFunctionLiteral() { return *this; }
1193 1193
1194 bool IsBinaryOperation() const { 1194 bool IsBinaryOperation() const {
1195 return TypeField::decode(code_) == kBinaryOperationExpression; 1195 return TypeField::decode(code_) == kBinaryOperationExpression;
1196 } 1196 }
1197 1197
1198 bool is_single_parenthesized() const {
1199 return ParenthesizationField::decode(code_) != kNotParenthesized;
1200 }
1201
1202 void increase_parenthesization_level() {
1203 code_ = ParenthesizationField::update(
1204 code_, is_single_parenthesized() ? kMultiParenthesizedExpression
1205 : kParanthesizedExpression);
1206 }
1207
1208 // Dummy implementation for making expression->somefunc() work in both Parser 1198 // Dummy implementation for making expression->somefunc() work in both Parser
1209 // and PreParser. 1199 // and PreParser.
1210 PreParserExpression* operator->() { return this; } 1200 PreParserExpression* operator->() { return this; }
1211 1201
1212 // More dummy implementations of things PreParser doesn't need to track: 1202 // More dummy implementations of things PreParser doesn't need to track:
1213 void set_index(int index) {} // For YieldExpressions 1203 void set_index(int index) {} // For YieldExpressions
1214 void set_should_eager_compile() {} 1204 void set_should_eager_compile() {}
1215 1205
1216 int position() const { return RelocInfo::kNoPosition; } 1206 int position() const { return RelocInfo::kNoPosition; }
1217 void set_function_token_position(int position) {} 1207 void set_function_token_position(int position) {}
1218 1208
1219 private: 1209 private:
1220 enum Type { 1210 enum Type {
1221 kExpression, 1211 kExpression,
1222 kIdentifierExpression, 1212 kIdentifierExpression,
1223 kStringLiteralExpression, 1213 kStringLiteralExpression,
1224 kBinaryOperationExpression, 1214 kBinaryOperationExpression,
1225 kSpreadExpression 1215 kSpreadExpression
1226 }; 1216 };
1227 1217
1228 enum Parenthesization {
1229 kNotParenthesized,
1230 kParanthesizedExpression,
1231 kMultiParenthesizedExpression
1232 };
1233
1234 enum ExpressionType { 1218 enum ExpressionType {
1235 kThisExpression, 1219 kThisExpression,
1236 kThisPropertyExpression, 1220 kThisPropertyExpression,
1237 kPropertyExpression, 1221 kPropertyExpression,
1238 kCallExpression, 1222 kCallExpression,
1239 kNoTemplateTagExpression 1223 kNoTemplateTagExpression
1240 }; 1224 };
1241 1225
1242 explicit PreParserExpression(uint32_t expression_code) 1226 explicit PreParserExpression(uint32_t expression_code)
1243 : code_(expression_code) {} 1227 : code_(expression_code) {}
1244 1228
1245 // The first five bits are for the Type and Parenthesization. 1229 // The first three bits are for the Type.
1246 typedef BitField<Type, 0, 3> TypeField; 1230 typedef BitField<Type, 0, 3> TypeField;
1247 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField;
1248 1231
1249 // The rest of the bits are interpreted depending on the value 1232 // The rest of the bits are interpreted depending on the value
1250 // of the Type field, so they can share the storage. 1233 // of the Type field, so they can share the storage.
1251 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> 1234 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField;
1252 ExpressionTypeField; 1235 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField;
1253 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField;
1254 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; 1236 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField;
1255 typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10> 1237 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10>
1256 IdentifierTypeField; 1238 IdentifierTypeField;
1257 1239
1258 uint32_t code_; 1240 uint32_t code_;
1259 }; 1241 };
1260 1242
1261 1243
1262 // The pre-parser doesn't need to build lists of expressions, identifiers, or 1244 // The pre-parser doesn't need to build lists of expressions, identifiers, or
1263 // the like. 1245 // the like.
1264 template <typename T> 1246 template <typename T>
1265 class PreParserList { 1247 class PreParserList {
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 scope->set_start_position(beg_pos); 2347 scope->set_start_position(beg_pos);
2366 ExpressionClassifier args_classifier; 2348 ExpressionClassifier args_classifier;
2367 bool has_rest = false; 2349 bool has_rest = false;
2368 result = this->ParseArrowFunctionLiteral(scope, has_rest, 2350 result = this->ParseArrowFunctionLiteral(scope, has_rest,
2369 args_classifier, CHECK_OK); 2351 args_classifier, CHECK_OK);
2370 } else { 2352 } else {
2371 // Heuristically try to detect immediately called functions before 2353 // Heuristically try to detect immediately called functions before
2372 // seeing the call parentheses. 2354 // seeing the call parentheses.
2373 parenthesized_function_ = (peek() == Token::FUNCTION); 2355 parenthesized_function_ = (peek() == Token::FUNCTION);
2374 result = this->ParseExpression(true, classifier, CHECK_OK); 2356 result = this->ParseExpression(true, classifier, CHECK_OK);
2375 result->increase_parenthesization_level();
2376 Expect(Token::RPAREN, CHECK_OK); 2357 Expect(Token::RPAREN, CHECK_OK);
2377 } 2358 }
2378 break; 2359 break;
2379 2360
2380 case Token::CLASS: { 2361 case Token::CLASS: {
2381 BindingPatternUnexpectedToken(classifier); 2362 BindingPatternUnexpectedToken(classifier);
2382 Consume(Token::CLASS); 2363 Consume(Token::CLASS);
2383 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { 2364 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) {
2384 ReportMessage("sloppy_lexical"); 2365 ReportMessage("sloppy_lexical");
2385 *ok = false; 2366 *ok = false;
(...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after
3940 *ok = false; 3921 *ok = false;
3941 return; 3922 return;
3942 } 3923 }
3943 has_seen_constructor_ = true; 3924 has_seen_constructor_ = true;
3944 return; 3925 return;
3945 } 3926 }
3946 } 3927 }
3947 } } // v8::internal 3928 } } // v8::internal
3948 3929
3949 #endif // V8_PREPARSER_H 3930 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698