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_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 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 | 896 |
897 static PreParserExpression FromIdentifier(PreParserIdentifier id) { | 897 static PreParserExpression FromIdentifier(PreParserIdentifier id) { |
898 return PreParserExpression(TypeField::encode(kIdentifierExpression) | | 898 return PreParserExpression(TypeField::encode(kIdentifierExpression) | |
899 IdentifierTypeField::encode(id.type_)); | 899 IdentifierTypeField::encode(id.type_)); |
900 } | 900 } |
901 | 901 |
902 static PreParserExpression BinaryOperation(PreParserExpression left, | 902 static PreParserExpression BinaryOperation(PreParserExpression left, |
903 Token::Value op, | 903 Token::Value op, |
904 PreParserExpression right) { | 904 PreParserExpression right) { |
905 ValidArrowParam valid_arrow_param_list = | 905 ValidArrowParam valid_arrow_param_list = |
906 (op == Token::COMMA && !left.is_parenthesized() && | 906 (op == Token::COMMA && !left.is_single_parenthesized() && |
907 !right.is_parenthesized()) ? | 907 !right.is_single_parenthesized()) |
908 std::min(left.ValidateArrowParams(), right.ValidateArrowParams()) | 908 ? std::min(left.ValidateArrowParams(), right.ValidateArrowParams()) |
909 : kInvalidArrowParam; | 909 : kInvalidArrowParam; |
910 return PreParserExpression( | 910 return PreParserExpression( |
911 TypeField::encode(kBinaryOperationExpression) | | 911 TypeField::encode(kBinaryOperationExpression) | |
912 IsValidArrowParamListField::encode(valid_arrow_param_list)); | 912 IsValidArrowParamListField::encode(valid_arrow_param_list)); |
913 } | 913 } |
914 | 914 |
915 static PreParserExpression StringLiteral() { | 915 static PreParserExpression StringLiteral() { |
916 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); | 916 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); |
917 } | 917 } |
918 | 918 |
919 static PreParserExpression UseStrictStringLiteral() { | 919 static PreParserExpression UseStrictStringLiteral() { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 bool IsSpreadExpression() const { | 1038 bool IsSpreadExpression() const { |
1039 return TypeField::decode(code_) == kSpreadExpression; | 1039 return TypeField::decode(code_) == kSpreadExpression; |
1040 } | 1040 } |
1041 | 1041 |
1042 PreParserExpression AsFunctionLiteral() { return *this; } | 1042 PreParserExpression AsFunctionLiteral() { return *this; } |
1043 | 1043 |
1044 bool IsBinaryOperation() const { | 1044 bool IsBinaryOperation() const { |
1045 return TypeField::decode(code_) == kBinaryOperationExpression; | 1045 return TypeField::decode(code_) == kBinaryOperationExpression; |
1046 } | 1046 } |
1047 | 1047 |
1048 bool is_parenthesized() const { | 1048 bool is_single_parenthesized() const { |
1049 return ParenthesizationField::decode(code_) != kNotParenthesized; | 1049 return ParenthesizationField::decode(code_) != kNotParenthesized; |
1050 } | 1050 } |
1051 | 1051 |
1052 void increase_parenthesization_level() { | 1052 void increase_parenthesization_level() { |
1053 code_ = ParenthesizationField::update( | 1053 code_ = ParenthesizationField::update( |
1054 code_, is_parenthesized() ? kMultiParenthesizedExpression | 1054 code_, is_single_parenthesized() ? kMultiParenthesizedExpression |
1055 : kParanthesizedExpression); | 1055 : kParanthesizedExpression); |
1056 } | 1056 } |
1057 | 1057 |
1058 // Dummy implementation for making expression->somefunc() work in both Parser | 1058 // Dummy implementation for making expression->somefunc() work in both Parser |
1059 // and PreParser. | 1059 // and PreParser. |
1060 PreParserExpression* operator->() { return this; } | 1060 PreParserExpression* operator->() { return this; } |
1061 | 1061 |
1062 // More dummy implementations of things PreParser doesn't need to track: | 1062 // More dummy implementations of things PreParser doesn't need to track: |
1063 void set_index(int index) {} // For YieldExpressions | 1063 void set_index(int index) {} // For YieldExpressions |
1064 void set_parenthesized() {} | 1064 void set_should_eager_compile() {} |
1065 | 1065 |
1066 int position() const { return RelocInfo::kNoPosition; } | 1066 int position() const { return RelocInfo::kNoPosition; } |
1067 void set_function_token_position(int position) {} | 1067 void set_function_token_position(int position) {} |
1068 | 1068 |
1069 private: | 1069 private: |
1070 enum Type { | 1070 enum Type { |
1071 kExpression, | 1071 kExpression, |
1072 kIdentifierExpression, | 1072 kIdentifierExpression, |
1073 kStringLiteralExpression, | 1073 kStringLiteralExpression, |
1074 kBinaryOperationExpression, | 1074 kBinaryOperationExpression, |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 int pos) { | 1342 int pos) { |
1343 return PreParserStatement::Default(); | 1343 return PreParserStatement::Default(); |
1344 } | 1344 } |
1345 PreParserExpression NewFunctionLiteral( | 1345 PreParserExpression NewFunctionLiteral( |
1346 PreParserIdentifier name, AstValueFactory* ast_value_factory, | 1346 PreParserIdentifier name, AstValueFactory* ast_value_factory, |
1347 Scope* scope, PreParserStatementList body, int materialized_literal_count, | 1347 Scope* scope, PreParserStatementList body, int materialized_literal_count, |
1348 int expected_property_count, int handler_count, int parameter_count, | 1348 int expected_property_count, int handler_count, int parameter_count, |
1349 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 1349 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
1350 FunctionLiteral::FunctionType function_type, | 1350 FunctionLiteral::FunctionType function_type, |
1351 FunctionLiteral::IsFunctionFlag is_function, | 1351 FunctionLiteral::IsFunctionFlag is_function, |
1352 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, | 1352 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, |
1353 int position) { | 1353 int position) { |
1354 return PreParserExpression::Default(); | 1354 return PreParserExpression::Default(); |
1355 } | 1355 } |
1356 | 1356 |
1357 PreParserExpression NewSpread(PreParserExpression expression, int pos) { | 1357 PreParserExpression NewSpread(PreParserExpression expression, int pos) { |
1358 return PreParserExpression::Spread(expression); | 1358 return PreParserExpression::Spread(expression); |
1359 } | 1359 } |
1360 | 1360 |
1361 // Return the object itself as AstVisitor and implement the needed | 1361 // Return the object itself as AstVisitor and implement the needed |
1362 // dummy method right in this class. | 1362 // dummy method right in this class. |
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2956 // For other kinds of calls we record position of the parenthesis as | 2956 // For other kinds of calls we record position of the parenthesis as |
2957 // position of the call. Note that this is extremely important for | 2957 // position of the call. Note that this is extremely important for |
2958 // expressions of the form function(){...}() for which call position | 2958 // expressions of the form function(){...}() for which call position |
2959 // should not point to the closing brace otherwise it will intersect | 2959 // should not point to the closing brace otherwise it will intersect |
2960 // with positions recorded for function literal and confuse debugger. | 2960 // with positions recorded for function literal and confuse debugger. |
2961 pos = peek_position(); | 2961 pos = peek_position(); |
2962 // Also the trailing parenthesis are a hint that the function will | 2962 // Also the trailing parenthesis are a hint that the function will |
2963 // be called immediately. If we happen to have parsed a preceding | 2963 // be called immediately. If we happen to have parsed a preceding |
2964 // function literal eagerly, we can also compile it eagerly. | 2964 // function literal eagerly, we can also compile it eagerly. |
2965 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 2965 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
2966 result->AsFunctionLiteral()->set_parenthesized(); | 2966 result->AsFunctionLiteral()->set_should_eager_compile(); |
2967 } | 2967 } |
2968 } | 2968 } |
2969 Scanner::Location spread_pos; | 2969 Scanner::Location spread_pos; |
2970 typename Traits::Type::ExpressionList args = | 2970 typename Traits::Type::ExpressionList args = |
2971 ParseArguments(&spread_pos, classifier, CHECK_OK); | 2971 ParseArguments(&spread_pos, classifier, CHECK_OK); |
2972 | 2972 |
2973 // Keep track of eval() calls since they disable all local variable | 2973 // Keep track of eval() calls since they disable all local variable |
2974 // optimizations. | 2974 // optimizations. |
2975 // The calls that need special treatment are the | 2975 // The calls that need special treatment are the |
2976 // direct eval calls. These calls are all of the form eval(...), with | 2976 // direct eval calls. These calls are all of the form eval(...), with |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3318 case Token::TEMPLATE_SPAN: | 3318 case Token::TEMPLATE_SPAN: |
3319 case Token::TEMPLATE_TAIL: { | 3319 case Token::TEMPLATE_TAIL: { |
3320 int pos; | 3320 int pos; |
3321 if (scanner()->current_token() == Token::IDENTIFIER) { | 3321 if (scanner()->current_token() == Token::IDENTIFIER) { |
3322 pos = position(); | 3322 pos = position(); |
3323 } else { | 3323 } else { |
3324 pos = peek_position(); | 3324 pos = peek_position(); |
3325 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 3325 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
3326 // If the tag function looks like an IIFE, set_parenthesized() to | 3326 // If the tag function looks like an IIFE, set_parenthesized() to |
3327 // force eager compilation. | 3327 // force eager compilation. |
3328 expression->AsFunctionLiteral()->set_parenthesized(); | 3328 expression->AsFunctionLiteral()->set_should_eager_compile(); |
3329 } | 3329 } |
3330 } | 3330 } |
3331 expression = | 3331 expression = |
3332 ParseTemplateLiteral(expression, pos, classifier, CHECK_OK); | 3332 ParseTemplateLiteral(expression, pos, classifier, CHECK_OK); |
3333 break; | 3333 break; |
3334 } | 3334 } |
3335 default: | 3335 default: |
3336 return expression; | 3336 return expression; |
3337 } | 3337 } |
3338 } | 3338 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3513 scanner()->location().end_pos, CHECK_OK); | 3513 scanner()->location().end_pos, CHECK_OK); |
3514 this->CheckConflictingVarDeclarations(scope, CHECK_OK); | 3514 this->CheckConflictingVarDeclarations(scope, CHECK_OK); |
3515 } | 3515 } |
3516 } | 3516 } |
3517 | 3517 |
3518 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 3518 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
3519 this->EmptyIdentifierString(), ast_value_factory(), scope, body, | 3519 this->EmptyIdentifierString(), ast_value_factory(), scope, body, |
3520 materialized_literal_count, expected_property_count, handler_count, | 3520 materialized_literal_count, expected_property_count, handler_count, |
3521 num_parameters, FunctionLiteral::kNoDuplicateParameters, | 3521 num_parameters, FunctionLiteral::kNoDuplicateParameters, |
3522 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 3522 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
3523 FunctionLiteral::kNotParenthesized, FunctionKind::kArrowFunction, | 3523 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, |
3524 scope->start_position()); | 3524 scope->start_position()); |
3525 | 3525 |
3526 function_literal->set_function_token_position(scope->start_position()); | 3526 function_literal->set_function_token_position(scope->start_position()); |
3527 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); | 3527 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); |
3528 | 3528 |
3529 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 3529 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
3530 | 3530 |
3531 return function_literal; | 3531 return function_literal; |
3532 } | 3532 } |
3533 | 3533 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3713 *ok = false; | 3713 *ok = false; |
3714 return; | 3714 return; |
3715 } | 3715 } |
3716 has_seen_constructor_ = true; | 3716 has_seen_constructor_ = true; |
3717 return; | 3717 return; |
3718 } | 3718 } |
3719 } | 3719 } |
3720 } } // v8::internal | 3720 } } // v8::internal |
3721 | 3721 |
3722 #endif // V8_PREPARSER_H | 3722 #endif // V8_PREPARSER_H |
OLD | NEW |