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

Side by Side Diff: src/preparser.h

Issue 792083002: Add materialized literals for tagged templates in preparser (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 6 years 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.h ('k') | test/cctest/test-parsing.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 // 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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 return PreParserExpression( 749 return PreParserExpression(
750 TypeField::encode(kExpression) | 750 TypeField::encode(kExpression) |
751 ExpressionTypeField::encode(kPropertyExpression)); 751 ExpressionTypeField::encode(kPropertyExpression));
752 } 752 }
753 753
754 static PreParserExpression Call() { 754 static PreParserExpression Call() {
755 return PreParserExpression(TypeField::encode(kExpression) | 755 return PreParserExpression(TypeField::encode(kExpression) |
756 ExpressionTypeField::encode(kCallExpression)); 756 ExpressionTypeField::encode(kCallExpression));
757 } 757 }
758 758
759 static PreParserExpression NoTemplateTag() {
760 return PreParserExpression(TypeField::encode(kExpression) |
761 ExpressionTypeField::encode(
762 kNoTemplateTagExpression));
arv (Not doing code reviews) 2014/12/11 15:29:38 Is this the formatting `git cl format` gives you?
caitp (gmail) 2014/12/11 16:14:04 clang-formatter doesn't complain about this becaus
763 }
764
759 bool IsIdentifier() const { 765 bool IsIdentifier() const {
760 return TypeField::decode(code_) == kIdentifierExpression; 766 return TypeField::decode(code_) == kIdentifierExpression;
761 } 767 }
762 768
763 PreParserIdentifier AsIdentifier() const { 769 PreParserIdentifier AsIdentifier() const {
764 DCHECK(IsIdentifier()); 770 DCHECK(IsIdentifier());
765 return PreParserIdentifier(IdentifierTypeField::decode(code_)); 771 return PreParserIdentifier(IdentifierTypeField::decode(code_));
766 } 772 }
767 773
768 bool IsStringLiteral() const { 774 bool IsStringLiteral() const {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 bool IsValidArrowParamList() const { 808 bool IsValidArrowParamList() const {
803 return IsValidArrowParams() && 809 return IsValidArrowParams() &&
804 ParenthesizationField::decode(code_) != 810 ParenthesizationField::decode(code_) !=
805 kMultiParenthesizedExpression; 811 kMultiParenthesizedExpression;
806 } 812 }
807 813
808 // At the moment PreParser doesn't track these expression types. 814 // At the moment PreParser doesn't track these expression types.
809 bool IsFunctionLiteral() const { return false; } 815 bool IsFunctionLiteral() const { return false; }
810 bool IsCallNew() const { return false; } 816 bool IsCallNew() const { return false; }
811 817
818 bool IsNoTemplateTag() const {
819 return TypeField::decode(code_) == kExpression &&
820 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression;
821 }
822
812 PreParserExpression AsFunctionLiteral() { return *this; } 823 PreParserExpression AsFunctionLiteral() { return *this; }
813 824
814 bool IsBinaryOperation() const { 825 bool IsBinaryOperation() const {
815 return TypeField::decode(code_) == kBinaryOperationExpression; 826 return TypeField::decode(code_) == kBinaryOperationExpression;
816 } 827 }
817 828
818 bool is_parenthesized() const { 829 bool is_parenthesized() const {
819 return ParenthesizationField::decode(code_) != kNotParenthesized; 830 return ParenthesizationField::decode(code_) != kNotParenthesized;
820 } 831 }
821 832
(...skipping 26 matching lines...) Expand all
848 kNotParenthesized, 859 kNotParenthesized,
849 kParanthesizedExpression, 860 kParanthesizedExpression,
850 kMultiParenthesizedExpression 861 kMultiParenthesizedExpression
851 }; 862 };
852 863
853 enum ExpressionType { 864 enum ExpressionType {
854 kThisExpression, 865 kThisExpression,
855 kThisPropertyExpression, 866 kThisPropertyExpression,
856 kPropertyExpression, 867 kPropertyExpression,
857 kCallExpression, 868 kCallExpression,
858 kSuperExpression 869 kSuperExpression,
870 kNoTemplateTagExpression
859 }; 871 };
860 872
861 explicit PreParserExpression(uint32_t expression_code) 873 explicit PreParserExpression(uint32_t expression_code)
862 : code_(expression_code) {} 874 : code_(expression_code) {}
863 875
864 V8_INLINE bool IsValidArrowParams() const { 876 V8_INLINE bool IsValidArrowParams() const {
865 return IsBinaryOperation() 877 return IsBinaryOperation()
866 ? IsValidArrowParamListField::decode(code_) 878 ? IsValidArrowParamListField::decode(code_)
867 : (IsIdentifier() && AsIdentifier().IsValidArrowParam()); 879 : (IsIdentifier() && AsIdentifier().IsValidArrowParam());
868 } 880 }
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 } 1403 }
1392 1404
1393 struct TemplateLiteralState {}; 1405 struct TemplateLiteralState {};
1394 1406
1395 TemplateLiteralState OpenTemplateLiteral(int pos) { 1407 TemplateLiteralState OpenTemplateLiteral(int pos) {
1396 return TemplateLiteralState(); 1408 return TemplateLiteralState();
1397 } 1409 }
1398 void AddTemplateSpan(TemplateLiteralState*, bool) {} 1410 void AddTemplateSpan(TemplateLiteralState*, bool) {}
1399 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} 1411 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {}
1400 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, 1412 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int,
1401 PreParserExpression) { 1413 PreParserExpression tag) {
1414 if (IsTaggedTemplate(tag)) {
1415 // Emulate generation of array literals for tag callsite
arv (Not doing code reviews) 2014/12/11 15:29:38 This comment goes better with PreParserTraits::Mat
1416 // 1st is array of cooked strings, second is array of raw strings
1417 MaterializeTemplateCallsiteLiterals();
1418 }
1402 return EmptyExpression(); 1419 return EmptyExpression();
1403 } 1420 }
1404 PreParserExpression NoTemplateTag() { return PreParserExpression::Default(); } 1421 inline void MaterializeTemplateCallsiteLiterals();
1422 PreParserExpression NoTemplateTag() {
1423 return PreParserExpression::NoTemplateTag();
1424 }
1425 static bool IsTaggedTemplate(const PreParserExpression tag) {
1426 return !tag.IsNoTemplateTag();
1427 }
1405 static AstValueFactory* ast_value_factory() { return NULL; } 1428 static AstValueFactory* ast_value_factory() { return NULL; }
1406 1429
1407 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {} 1430 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {}
1408 1431
1409 // Temporary glue; these functions will move to ParserBase. 1432 // Temporary glue; these functions will move to ParserBase.
1410 PreParserExpression ParseV8Intrinsic(bool* ok); 1433 PreParserExpression ParseV8Intrinsic(bool* ok);
1411 PreParserExpression ParseFunctionLiteral( 1434 PreParserExpression ParseFunctionLiteral(
1412 PreParserIdentifier name, Scanner::Location function_name_location, 1435 PreParserIdentifier name, Scanner::Location function_name_location,
1413 bool name_is_strict_reserved, FunctionKind kind, 1436 bool name_is_strict_reserved, FunctionKind kind,
1414 int function_token_position, FunctionLiteral::FunctionType type, 1437 int function_token_position, FunctionLiteral::FunctionType type,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 }; 1471 };
1449 1472
1450 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) 1473 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit)
1451 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, 1474 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL,
1452 this) {} 1475 this) {}
1453 1476
1454 // Pre-parse the program from the character stream; returns true on 1477 // Pre-parse the program from the character stream; returns true on
1455 // success (even if parsing failed, the pre-parse data successfully 1478 // success (even if parsing failed, the pre-parse data successfully
1456 // captured the syntax error), and false if a stack-overflow happened 1479 // captured the syntax error), and false if a stack-overflow happened
1457 // during parsing. 1480 // during parsing.
1458 PreParseResult PreParseProgram() { 1481 PreParseResult PreParseProgram(int* materialized_literals = 0) {
1459 PreParserScope scope(scope_, SCRIPT_SCOPE); 1482 PreParserScope scope(scope_, SCRIPT_SCOPE);
1460 PreParserFactory factory(NULL); 1483 PreParserFactory factory(NULL);
1461 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); 1484 FunctionState top_scope(&function_state_, &scope_, &scope, &factory);
1462 bool ok = true; 1485 bool ok = true;
1463 int start_position = scanner()->peek_location().beg_pos; 1486 int start_position = scanner()->peek_location().beg_pos;
1464 ParseSourceElements(Token::EOS, &ok); 1487 ParseSourceElements(Token::EOS, &ok);
1465 if (stack_overflow()) return kPreParseStackOverflow; 1488 if (stack_overflow()) return kPreParseStackOverflow;
1466 if (!ok) { 1489 if (!ok) {
1467 ReportUnexpectedToken(scanner()->current_token()); 1490 ReportUnexpectedToken(scanner()->current_token());
1468 } else if (scope_->strict_mode() == STRICT) { 1491 } else if (scope_->strict_mode() == STRICT) {
1469 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok); 1492 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok);
1470 } 1493 }
1494 if (materialized_literals) {
1495 *materialized_literals = function_state_->materialized_literal_count();
1496 }
1471 return kPreParseSuccess; 1497 return kPreParseSuccess;
1472 } 1498 }
1473 1499
1474 // Parses a single function literal, from the opening parentheses before 1500 // Parses a single function literal, from the opening parentheses before
1475 // parameters to the closing brace after the body. 1501 // parameters to the closing brace after the body.
1476 // Returns a FunctionEntry describing the body of the function in enough 1502 // Returns a FunctionEntry describing the body of the function in enough
1477 // detail that it can be lazily compiled. 1503 // detail that it can be lazily compiled.
1478 // The scanner is expected to have matched the "function" or "function*" 1504 // The scanner is expected to have matched the "function" or "function*"
1479 // keyword and parameters, and have consumed the initial '{'. 1505 // keyword and parameters, and have consumed the initial '{'.
1480 // At return, unless an error occurred, the scanner is positioned before the 1506 // At return, unless an error occurred, the scanner is positioned before the
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 1584
1559 PreParserExpression ParseClassLiteral(PreParserIdentifier name, 1585 PreParserExpression ParseClassLiteral(PreParserIdentifier name,
1560 Scanner::Location class_name_location, 1586 Scanner::Location class_name_location,
1561 bool name_is_strict_reserved, int pos, 1587 bool name_is_strict_reserved, int pos,
1562 bool* ok); 1588 bool* ok);
1563 1589
1564 bool CheckInOrOf(bool accept_OF); 1590 bool CheckInOrOf(bool accept_OF);
1565 }; 1591 };
1566 1592
1567 1593
1594 void PreParserTraits::MaterializeTemplateCallsiteLiterals() {
1595 pre_parser_->function_state_->NextMaterializedLiteralIndex();
1596 pre_parser_->function_state_->NextMaterializedLiteralIndex();
1597 }
1598
1599
1568 PreParserStatementList PreParser::ParseEagerFunctionBody( 1600 PreParserStatementList PreParser::ParseEagerFunctionBody(
1569 PreParserIdentifier function_name, int pos, Variable* fvar, 1601 PreParserIdentifier function_name, int pos, Variable* fvar,
1570 Token::Value fvar_init_op, bool is_generator, bool* ok) { 1602 Token::Value fvar_init_op, bool is_generator, bool* ok) {
1571 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1603 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1572 1604
1573 ParseSourceElements(Token::RBRACE, ok); 1605 ParseSourceElements(Token::RBRACE, ok);
1574 if (!*ok) return PreParserStatementList(); 1606 if (!*ok) return PreParserStatementList();
1575 1607
1576 Expect(Token::RBRACE, ok); 1608 Expect(Token::RBRACE, ok);
1577 return PreParserStatementList(); 1609 return PreParserStatementList();
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
2922 DCHECK(IsAccessorAccessorConflict(old_type, type)); 2954 DCHECK(IsAccessorAccessorConflict(old_type, type));
2923 // Both accessors of the same type. 2955 // Both accessors of the same type.
2924 parser()->ReportMessage("accessor_get_set"); 2956 parser()->ReportMessage("accessor_get_set");
2925 } 2957 }
2926 *ok = false; 2958 *ok = false;
2927 } 2959 }
2928 } 2960 }
2929 } } // v8::internal 2961 } } // v8::internal
2930 2962
2931 #endif // V8_PREPARSER_H 2963 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698