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

Side by Side Diff: src/preparser.h

Issue 194503004: Move ParseArguments to ParserBase and add tests. (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/parser.cc ('k') | src/preparser.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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 bool* is_set, 336 bool* is_set,
337 bool* ok); 337 bool* ok);
338 338
339 typename Traits::Type::Expression ParseRegExpLiteral(bool seen_equal, 339 typename Traits::Type::Expression ParseRegExpLiteral(bool seen_equal,
340 bool* ok); 340 bool* ok);
341 341
342 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok); 342 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok);
343 typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok); 343 typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok);
344 typename Traits::Type::Expression ParseArrayLiteral(bool* ok); 344 typename Traits::Type::Expression ParseArrayLiteral(bool* ok);
345 typename Traits::Type::Expression ParseObjectLiteral(bool* ok); 345 typename Traits::Type::Expression ParseObjectLiteral(bool* ok);
346 typename Traits::Type::ExpressionList ParseArguments(bool* ok);
346 347
347 // Used to detect duplicates in object literals. Each of the values 348 // Used to detect duplicates in object literals. Each of the values
348 // kGetterProperty, kSetterProperty and kValueProperty represents 349 // kGetterProperty, kSetterProperty and kValueProperty represents
349 // a type of object literal property. When parsing a property, its 350 // a type of object literal property. When parsing a property, its
350 // type value is stored in the DuplicateFinder for the property name. 351 // type value is stored in the DuplicateFinder for the property name.
351 // Values are chosen so that having intersection bits means the there is 352 // Values are chosen so that having intersection bits means the there is
352 // an incompatibility. 353 // an incompatibility.
353 // I.e., you can add a getter to a property that already has a setter, since 354 // I.e., you can add a getter to a property that already has a setter, since
354 // kGetterProperty and kSetterProperty doesn't intersect, but not if it 355 // kGetterProperty and kSetterProperty doesn't intersect, but not if it
355 // already has a getter or a value. Adding the getter to an existing 356 // already has a getter or a value. Adding the getter to an existing
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 551
551 int code_; 552 int code_;
552 }; 553 };
553 554
554 555
555 // PreParserExpressionList doesn't actually store the expressions because 556 // PreParserExpressionList doesn't actually store the expressions because
556 // PreParser doesn't need to. 557 // PreParser doesn't need to.
557 class PreParserExpressionList { 558 class PreParserExpressionList {
558 public: 559 public:
559 // These functions make list->Add(some_expression) work (and do nothing). 560 // These functions make list->Add(some_expression) work (and do nothing).
561 PreParserExpressionList() : length_(0) {}
560 PreParserExpressionList* operator->() { return this; } 562 PreParserExpressionList* operator->() { return this; }
561 void Add(PreParserExpression, void*) { } 563 void Add(PreParserExpression, void*) { ++length_; }
564 int length() const { return length_; }
565 private:
566 int length_;
562 }; 567 };
563 568
564 569
565 class PreParserScope { 570 class PreParserScope {
566 public: 571 public:
567 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type) 572 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type)
568 : scope_type_(scope_type) { 573 : scope_type_(scope_type) {
569 if (outer_scope) { 574 if (outer_scope) {
570 scope_inside_with_ = 575 scope_inside_with_ =
571 outer_scope->scope_inside_with_ || is_with_scope(); 576 outer_scope->scope_inside_with_ || is_with_scope();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 // "null" return type creators. 728 // "null" return type creators.
724 static PreParserIdentifier EmptyIdentifier() { 729 static PreParserIdentifier EmptyIdentifier() {
725 return PreParserIdentifier::Default(); 730 return PreParserIdentifier::Default();
726 } 731 }
727 static PreParserExpression EmptyExpression() { 732 static PreParserExpression EmptyExpression() {
728 return PreParserExpression::Default(); 733 return PreParserExpression::Default();
729 } 734 }
730 static PreParserExpression EmptyLiteral() { 735 static PreParserExpression EmptyLiteral() {
731 return PreParserExpression::Default(); 736 return PreParserExpression::Default();
732 } 737 }
738 static PreParserExpressionList NullExpressionList() {
739 return PreParserExpressionList();
740 }
733 741
734 // Odd-ball literal creators. 742 // Odd-ball literal creators.
735 static PreParserExpression GetLiteralTheHole(int position, 743 static PreParserExpression GetLiteralTheHole(int position,
736 PreParserFactory* factory) { 744 PreParserFactory* factory) {
737 return PreParserExpression::Default(); 745 return PreParserExpression::Default();
738 } 746 }
739 747
740 // Producing data during the recursive descent. 748 // Producing data during the recursive descent.
741 PreParserIdentifier GetSymbol(Scanner* scanner); 749 PreParserIdentifier GetSymbol(Scanner* scanner);
742 static PreParserIdentifier NextLiteralString(Scanner* scanner, 750 static PreParserIdentifier NextLiteralString(Scanner* scanner,
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 }; 921 };
914 922
915 explicit Statement(Type code) : code_(code) {} 923 explicit Statement(Type code) : code_(code) {}
916 Type code_; 924 Type code_;
917 }; 925 };
918 926
919 enum SourceElements { 927 enum SourceElements {
920 kUnknownSourceElements 928 kUnknownSourceElements
921 }; 929 };
922 930
923 typedef int Arguments;
924
925 // All ParseXXX functions take as the last argument an *ok parameter 931 // All ParseXXX functions take as the last argument an *ok parameter
926 // which is set to false if parsing failed; it is unchanged otherwise. 932 // which is set to false if parsing failed; it is unchanged otherwise.
927 // By making the 'exception handling' explicit, we are forced to check 933 // By making the 'exception handling' explicit, we are forced to check
928 // for failure at the call sites. 934 // for failure at the call sites.
929 Statement ParseSourceElement(bool* ok); 935 Statement ParseSourceElement(bool* ok);
930 SourceElements ParseSourceElements(int end_token, bool* ok); 936 SourceElements ParseSourceElements(int end_token, bool* ok);
931 Statement ParseStatement(bool* ok); 937 Statement ParseStatement(bool* ok);
932 Statement ParseFunctionDeclaration(bool* ok); 938 Statement ParseFunctionDeclaration(bool* ok);
933 Statement ParseBlock(bool* ok); 939 Statement ParseBlock(bool* ok);
934 Statement ParseVariableStatement(VariableDeclarationContext var_context, 940 Statement ParseVariableStatement(VariableDeclarationContext var_context,
(...skipping 23 matching lines...) Expand all
958 Expression ParseUnaryExpression(bool* ok); 964 Expression ParseUnaryExpression(bool* ok);
959 Expression ParsePostfixExpression(bool* ok); 965 Expression ParsePostfixExpression(bool* ok);
960 Expression ParseLeftHandSideExpression(bool* ok); 966 Expression ParseLeftHandSideExpression(bool* ok);
961 Expression ParseMemberExpression(bool* ok); 967 Expression ParseMemberExpression(bool* ok);
962 Expression ParseMemberExpressionContinuation(PreParserExpression expression, 968 Expression ParseMemberExpressionContinuation(PreParserExpression expression,
963 bool* ok); 969 bool* ok);
964 Expression ParseMemberWithNewPrefixesExpression(bool* ok); 970 Expression ParseMemberWithNewPrefixesExpression(bool* ok);
965 Expression ParseObjectLiteral(bool* ok); 971 Expression ParseObjectLiteral(bool* ok);
966 Expression ParseV8Intrinsic(bool* ok); 972 Expression ParseV8Intrinsic(bool* ok);
967 973
968 Arguments ParseArguments(bool* ok);
969 Expression ParseFunctionLiteral( 974 Expression ParseFunctionLiteral(
970 Identifier name, 975 Identifier name,
971 Scanner::Location function_name_location, 976 Scanner::Location function_name_location,
972 bool name_is_strict_reserved, 977 bool name_is_strict_reserved,
973 bool is_generator, 978 bool is_generator,
974 int function_token_pos, 979 int function_token_pos,
975 FunctionLiteral::FunctionType function_type, 980 FunctionLiteral::FunctionType function_type,
976 bool* ok); 981 bool* ok);
977 void ParseLazyFunctionLiteralBody(bool* ok); 982 void ParseLazyFunctionLiteralBody(bool* ok);
978 983
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); 1161 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos);
1157 } 1162 }
1158 1163
1159 1164
1160 #define CHECK_OK ok); \ 1165 #define CHECK_OK ok); \
1161 if (!*ok) return this->EmptyExpression(); \ 1166 if (!*ok) return this->EmptyExpression(); \
1162 ((void)0 1167 ((void)0
1163 #define DUMMY ) // to make indentation work 1168 #define DUMMY ) // to make indentation work
1164 #undef DUMMY 1169 #undef DUMMY
1165 1170
1171 // Used in functions where the return type is not Traits::Type::Expression.
1172 #define CHECK_OK_CUSTOM(x) ok); \
1173 if (!*ok) return this->x(); \
1174 ((void)0
1175 #define DUMMY ) // to make indentation work
1176 #undef DUMMY
1177
1166 template <class Traits> 1178 template <class Traits>
1167 typename Traits::Type::Expression ParserBase<Traits>::ParsePrimaryExpression( 1179 typename Traits::Type::Expression ParserBase<Traits>::ParsePrimaryExpression(
1168 bool* ok) { 1180 bool* ok) {
1169 // PrimaryExpression :: 1181 // PrimaryExpression ::
1170 // 'this' 1182 // 'this'
1171 // 'null' 1183 // 'null'
1172 // 'true' 1184 // 'true'
1173 // 'false' 1185 // 'false'
1174 // Identifier 1186 // Identifier
1175 // Number 1187 // Number
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 int literal_index = function_state_->NextMaterializedLiteralIndex(); 1472 int literal_index = function_state_->NextMaterializedLiteralIndex();
1461 1473
1462 return factory()->NewObjectLiteral(properties, 1474 return factory()->NewObjectLiteral(properties,
1463 literal_index, 1475 literal_index,
1464 number_of_boilerplate_properties, 1476 number_of_boilerplate_properties,
1465 has_function, 1477 has_function,
1466 pos); 1478 pos);
1467 } 1479 }
1468 1480
1469 1481
1482 template <class Traits>
1483 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments(
1484 bool* ok) {
1485 // Arguments ::
1486 // '(' (AssignmentExpression)*[','] ')'
1487
1488 typename Traits::Type::ExpressionList result =
1489 this->NewExpressionList(4, zone_);
1490 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList));
1491 bool done = (peek() == Token::RPAREN);
1492 while (!done) {
1493 typename Traits::Type::Expression argument =
1494 this->ParseAssignmentExpression(true,
1495 CHECK_OK_CUSTOM(NullExpressionList));
1496 result->Add(argument, zone_);
1497 if (result->length() > Code::kMaxArguments) {
1498 ReportMessageAt(scanner()->location(), "too_many_arguments");
1499 *ok = false;
1500 return this->NullExpressionList();
1501 }
1502 done = (peek() == Token::RPAREN);
1503 if (!done) Expect(Token::COMMA, CHECK_OK_CUSTOM(NullExpressionList));
ulan 2014/03/11 15:39:59 As discussed offline, it is probably worth putting
marja 2014/03/11 15:49:10 Done.
1504 }
1505 Expect(Token::RPAREN, CHECK_OK_CUSTOM(NullExpressionList));
1506 return result;
1507 }
1508
1470 1509
1471 #undef CHECK_OK 1510 #undef CHECK_OK
1511 #undef CHECK_OK_CUSTOM
1472 1512
1473 1513
1474 template <typename Traits> 1514 template <typename Traits>
1475 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( 1515 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty(
1476 Token::Value property, 1516 Token::Value property,
1477 PropertyKind type, 1517 PropertyKind type,
1478 bool* ok) { 1518 bool* ok) {
1479 int old; 1519 int old;
1480 if (property == Token::NUMBER) { 1520 if (property == Token::NUMBER) {
1481 old = finder_.AddNumber(scanner()->literal_ascii_string(), type); 1521 old = finder_.AddNumber(scanner()->literal_ascii_string(), type);
(...skipping 20 matching lines...) Expand all
1502 "accessor_get_set"); 1542 "accessor_get_set");
1503 } 1543 }
1504 *ok = false; 1544 *ok = false;
1505 } 1545 }
1506 } 1546 }
1507 1547
1508 1548
1509 } } // v8::internal 1549 } } // v8::internal
1510 1550
1511 #endif // V8_PREPARSER_H 1551 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698