Commit c374d413 authored by nikolaos's avatar nikolaos Committed by Commit bot

[parser] Clean up (pre)parser traits, part 3

This patch moves the following methods from the traits objects to
the (pre)parser implementation objects:

- BuildIteratorResult
- BuildUnaryExpression
- EmptyExpression
- EmptyFunctionLiteral
- EmptyIdentifier
- EmptyIdentifierString
- EmptyLiteral
- EmptyObjectLiteralProperty
- GetLiteralTheHole
- NewThrowReferenceError
- NewThrowSyntaxError
- NewThrowTypeError
- NullExpressionList
- ReportMessageAt

R=adamk@chromium.org, marja@chromium.org
BUG=
LOG=N

Review-Url: https://codereview.chromium.org/2268413002
Cr-Commit-Position: refs/heads/master@{#38862}
parent 62630927
...@@ -127,7 +127,7 @@ struct FormalParametersBase { ...@@ -127,7 +127,7 @@ struct FormalParametersBase {
// is correct (e.g. an if statement branch w/o braces)! // is correct (e.g. an if statement branch w/o braces)!
#define CHECK_OK_CUSTOM(x) ok); \ #define CHECK_OK_CUSTOM(x) ok); \
if (!*ok) return this->x(); \ if (!*ok) return impl()->x(); \
((void)0 ((void)0
#define DUMMY ) // to make indentation work #define DUMMY ) // to make indentation work
#undef DUMMY #undef DUMMY
...@@ -818,7 +818,7 @@ class ParserBase : public ParserBaseTraits<Impl> { ...@@ -818,7 +818,7 @@ class ParserBase : public ParserBaseTraits<Impl> {
Scanner::Location octal = scanner()->octal_position(); Scanner::Location octal = scanner()->octal_position();
if (octal.IsValid() && beg_pos <= octal.beg_pos && if (octal.IsValid() && beg_pos <= octal.beg_pos &&
octal.end_pos <= end_pos) { octal.end_pos <= end_pos) {
ReportMessageAt(octal, message); impl()->ReportMessageAt(octal, message);
scanner()->clear_octal_position(); scanner()->clear_octal_position();
*ok = false; *ok = false;
} }
...@@ -860,13 +860,13 @@ class ParserBase : public ParserBaseTraits<Impl> { ...@@ -860,13 +860,13 @@ class ParserBase : public ParserBaseTraits<Impl> {
if (is_sloppy(language_mode)) return; if (is_sloppy(language_mode)) return;
if (impl()->IsEvalOrArguments(function_name)) { if (impl()->IsEvalOrArguments(function_name)) {
Traits::ReportMessageAt(function_name_loc, impl()->ReportMessageAt(function_name_loc,
MessageTemplate::kStrictEvalArguments); MessageTemplate::kStrictEvalArguments);
*ok = false; *ok = false;
return; return;
} }
if (function_name_validity == kFunctionNameIsStrictReserved) { if (function_name_validity == kFunctionNameIsStrictReserved) {
Traits::ReportMessageAt(function_name_loc, impl()->ReportMessageAt(function_name_loc,
MessageTemplate::kUnexpectedStrictReserved); MessageTemplate::kUnexpectedStrictReserved);
*ok = false; *ok = false;
return; return;
...@@ -896,34 +896,20 @@ class ParserBase : public ParserBaseTraits<Impl> { ...@@ -896,34 +896,20 @@ class ParserBase : public ParserBaseTraits<Impl> {
void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, void ReportMessage(MessageTemplate::Template message, const char* arg = NULL,
ParseErrorType error_type = kSyntaxError) { ParseErrorType error_type = kSyntaxError) {
Scanner::Location source_location = scanner()->location(); Scanner::Location source_location = scanner()->location();
Traits::ReportMessageAt(source_location, message, arg, error_type); impl()->ReportMessageAt(source_location, message, arg, error_type);
} }
void ReportMessage(MessageTemplate::Template message, const AstRawString* arg, void ReportMessage(MessageTemplate::Template message, const AstRawString* arg,
ParseErrorType error_type = kSyntaxError) { ParseErrorType error_type = kSyntaxError) {
Scanner::Location source_location = scanner()->location(); Scanner::Location source_location = scanner()->location();
Traits::ReportMessageAt(source_location, message, arg, error_type); impl()->ReportMessageAt(source_location, message, arg, error_type);
}
void ReportMessageAt(Scanner::Location location,
MessageTemplate::Template message,
const char* arg = NULL,
ParseErrorType error_type = kSyntaxError) {
Traits::ReportMessageAt(location, message, arg, error_type);
}
void ReportMessageAt(Scanner::Location location,
MessageTemplate::Template message,
const AstRawString* arg,
ParseErrorType error_type = kSyntaxError) {
Traits::ReportMessageAt(location, message, arg, error_type);
} }
void ReportMessageAt(Scanner::Location location, void ReportMessageAt(Scanner::Location location,
MessageTemplate::Template message, MessageTemplate::Template message,
ParseErrorType error_type) { ParseErrorType error_type) {
ReportMessageAt(location, message, static_cast<const char*>(nullptr), impl()->ReportMessageAt(location, message,
error_type); static_cast<const char*>(nullptr), error_type);
} }
void GetUnexpectedTokenMessage( void GetUnexpectedTokenMessage(
...@@ -938,7 +924,7 @@ class ParserBase : public ParserBaseTraits<Impl> { ...@@ -938,7 +924,7 @@ class ParserBase : public ParserBaseTraits<Impl> {
void ReportClassifierError( void ReportClassifierError(
const typename ExpressionClassifier::Error& error) { const typename ExpressionClassifier::Error& error) {
Traits::ReportMessageAt(error.location, error.message, error.arg, impl()->ReportMessageAt(error.location, error.message, error.arg,
error.type); error.type);
} }
...@@ -1006,7 +992,7 @@ class ParserBase : public ParserBaseTraits<Impl> { ...@@ -1006,7 +992,7 @@ class ParserBase : public ParserBaseTraits<Impl> {
if (classifier->is_valid_binding_pattern()) { if (classifier->is_valid_binding_pattern()) {
// A simple arrow formal parameter: IDENTIFIER => BODY. // A simple arrow formal parameter: IDENTIFIER => BODY.
if (!impl()->IsIdentifier(expr)) { if (!impl()->IsIdentifier(expr)) {
Traits::ReportMessageAt(scanner()->location(), impl()->ReportMessageAt(scanner()->location(),
MessageTemplate::kUnexpectedToken, MessageTemplate::kUnexpectedToken,
Token::String(scanner()->current_token())); Token::String(scanner()->current_token()));
*ok = false; *ok = false;
...@@ -1413,7 +1399,7 @@ void ParserBase<Impl>::ReportUnexpectedTokenAt( ...@@ -1413,7 +1399,7 @@ void ParserBase<Impl>::ReportUnexpectedTokenAt(
MessageTemplate::Template message) { MessageTemplate::Template message) {
const char* arg; const char* arg;
GetUnexpectedTokenMessage(token, &message, &source_location, &arg); GetUnexpectedTokenMessage(token, &message, &source_location, &arg);
Traits::ReportMessageAt(source_location, message, arg); impl()->ReportMessageAt(source_location, message, arg);
} }
template <typename Impl> template <typename Impl>
...@@ -1473,7 +1459,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, ...@@ -1473,7 +1459,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
is_strict(language_mode())) { is_strict(language_mode())) {
ReportUnexpectedToken(next); ReportUnexpectedToken(next);
*ok = false; *ok = false;
return Traits::EmptyIdentifier(); return impl()->EmptyIdentifier();
} }
if (next == Token::LET || if (next == Token::LET ||
(next == Token::ESCAPED_STRICT_RESERVED_WORD && (next == Token::ESCAPED_STRICT_RESERVED_WORD &&
...@@ -1485,7 +1471,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, ...@@ -1485,7 +1471,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
} else { } else {
this->ReportUnexpectedToken(next); this->ReportUnexpectedToken(next);
*ok = false; *ok = false;
return Traits::EmptyIdentifier(); return impl()->EmptyIdentifier();
} }
} }
...@@ -1505,7 +1491,7 @@ ParserBase<Impl>::ParseIdentifierOrStrictReservedWord( ...@@ -1505,7 +1491,7 @@ ParserBase<Impl>::ParseIdentifierOrStrictReservedWord(
} else { } else {
ReportUnexpectedToken(next); ReportUnexpectedToken(next);
*ok = false; *ok = false;
return Traits::EmptyIdentifier(); return impl()->EmptyIdentifier();
} }
return this->GetSymbol(scanner()); return this->GetSymbol(scanner());
...@@ -1523,7 +1509,7 @@ typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifierName( ...@@ -1523,7 +1509,7 @@ typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifierName(
next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) {
this->ReportUnexpectedToken(next); this->ReportUnexpectedToken(next);
*ok = false; *ok = false;
return Traits::EmptyIdentifier(); return impl()->EmptyIdentifier();
} }
return this->GetSymbol(scanner()); return this->GetSymbol(scanner());
...@@ -1537,7 +1523,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral( ...@@ -1537,7 +1523,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral(
Next(); Next();
ReportMessage(MessageTemplate::kUnterminatedRegExp); ReportMessage(MessageTemplate::kUnterminatedRegExp);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} }
int literal_index = function_state_->NextMaterializedLiteralIndex(); int literal_index = function_state_->NextMaterializedLiteralIndex();
...@@ -1548,7 +1534,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral( ...@@ -1548,7 +1534,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral(
Next(); Next();
ReportMessage(MessageTemplate::kMalformedRegExpFlags); ReportMessage(MessageTemplate::kMalformedRegExpFlags);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} }
int js_flags = flags.FromJust(); int js_flags = flags.FromJust();
Next(); Next();
...@@ -1671,10 +1657,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( ...@@ -1671,10 +1657,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
MessageTemplate::kInvalidRestParameter); MessageTemplate::kInvalidRestParameter);
} }
if (peek() == Token::COMMA) { if (peek() == Token::COMMA) {
ReportMessageAt(scanner()->peek_location(), impl()->ReportMessageAt(scanner()->peek_location(),
MessageTemplate::kParamAfterRest); MessageTemplate::kParamAfterRest);
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
return factory()->NewSpread(expr, ellipsis_pos, expr_pos); return factory()->NewSpread(expr, ellipsis_pos, expr_pos);
...@@ -1692,7 +1678,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( ...@@ -1692,7 +1678,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
BindingPatternUnexpectedToken(classifier); BindingPatternUnexpectedToken(classifier);
Consume(Token::CLASS); Consume(Token::CLASS);
int class_token_position = position(); int class_token_position = position();
IdentifierT name = this->EmptyIdentifier(); IdentifierT name = impl()->EmptyIdentifier();
bool is_strict_reserved_name = false; bool is_strict_reserved_name = false;
Scanner::Location class_name_location = Scanner::Location::invalid(); Scanner::Location class_name_location = Scanner::Location::invalid();
if (peek_any_identifier()) { if (peek_any_identifier()) {
...@@ -1731,7 +1717,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( ...@@ -1731,7 +1717,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
ReportUnexpectedToken(Next()); ReportUnexpectedToken(Next());
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
template <typename Impl> template <typename Impl>
...@@ -1822,7 +1808,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral( ...@@ -1822,7 +1808,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral(
while (peek() != Token::RBRACK) { while (peek() != Token::RBRACK) {
ExpressionT elem; ExpressionT elem;
if (peek() == Token::COMMA) { if (peek() == Token::COMMA) {
elem = this->GetLiteralTheHole(peek_position(), factory()); elem = impl()->GetLiteralTheHole(peek_position());
} else if (peek() == Token::ELLIPSIS) { } else if (peek() == Token::ELLIPSIS) {
int start_pos = peek_position(); int start_pos = peek_position();
Consume(Token::ELLIPSIS); Consume(Token::ELLIPSIS);
...@@ -1878,7 +1864,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral( ...@@ -1878,7 +1864,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral(
// to change. Also, this error message will never appear while pre- // to change. Also, this error message will never appear while pre-
// parsing (this is OK, as it is an implementation limitation). // parsing (this is OK, as it is an implementation limitation).
ReportMessage(MessageTemplate::kTooManySpreads); ReportMessage(MessageTemplate::kTooManySpreads);
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
} }
return result; return result;
...@@ -2107,7 +2093,7 @@ ParserBase<Impl>::ParsePropertyDefinition( ...@@ -2107,7 +2093,7 @@ ParserBase<Impl>::ParsePropertyDefinition(
if (in_class && name_token == Token::STATIC && IsNormalMethod(method_kind)) { if (in_class && name_token == Token::STATIC && IsNormalMethod(method_kind)) {
// ClassElement (static) // ClassElement (static)
// 'static' MethodDefinition // 'static' MethodDefinition
*name = this->EmptyIdentifier(); *name = impl()->EmptyIdentifier();
ObjectLiteralPropertyT property = ParsePropertyDefinition( ObjectLiteralPropertyT property = ParsePropertyDefinition(
checker, true, has_extends, MethodKind::kStatic, is_computed_name, checker, true, has_extends, MethodKind::kStatic, is_computed_name,
nullptr, classifier, name, ok); nullptr, classifier, name, ok);
...@@ -2119,7 +2105,7 @@ ParserBase<Impl>::ParsePropertyDefinition( ...@@ -2119,7 +2105,7 @@ ParserBase<Impl>::ParsePropertyDefinition(
// MethodDefinition (Accessors) // MethodDefinition (Accessors)
// get PropertyName '(' ')' '{' FunctionBody '}' // get PropertyName '(' ')' '{' FunctionBody '}'
// set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}'
*name = this->EmptyIdentifier(); *name = impl()->EmptyIdentifier();
bool dont_care = false; bool dont_care = false;
name_token = peek(); name_token = peek();
...@@ -2156,7 +2142,7 @@ ParserBase<Impl>::ParsePropertyDefinition( ...@@ -2156,7 +2142,7 @@ ParserBase<Impl>::ParsePropertyDefinition(
Token::Value next = Next(); Token::Value next = Next();
ReportUnexpectedToken(next); ReportUnexpectedToken(next);
*ok = false; *ok = false;
return this->EmptyObjectLiteralProperty(); return impl()->EmptyObjectLiteralProperty();
} }
template <typename Impl> template <typename Impl>
...@@ -2180,7 +2166,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral( ...@@ -2180,7 +2166,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
const bool in_class = false; const bool in_class = false;
const bool has_extends = false; const bool has_extends = false;
bool is_computed_name = false; bool is_computed_name = false;
IdentifierT name = this->EmptyIdentifier(); IdentifierT name = impl()->EmptyIdentifier();
ObjectLiteralPropertyT property = this->ParsePropertyDefinition( ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
&checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name, &checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name,
NULL, classifier, &name, CHECK_OK); NULL, classifier, &name, CHECK_OK);
...@@ -2263,7 +2249,7 @@ ParserBase<Impl>::ParseArguments(Scanner::Location* first_spread_arg_loc, ...@@ -2263,7 +2249,7 @@ ParserBase<Impl>::ParseArguments(Scanner::Location* first_spread_arg_loc,
if (result->length() > Code::kMaxArguments) { if (result->length() > Code::kMaxArguments) {
ReportMessage(MessageTemplate::kTooManyArguments); ReportMessage(MessageTemplate::kTooManyArguments);
*ok = false; *ok = false;
return this->NullExpressionList(); return impl()->NullExpressionList();
} }
done = (peek() != Token::COMMA); done = (peek() != Token::COMMA);
if (!done) { if (!done) {
...@@ -2276,9 +2262,9 @@ ParserBase<Impl>::ParseArguments(Scanner::Location* first_spread_arg_loc, ...@@ -2276,9 +2262,9 @@ ParserBase<Impl>::ParseArguments(Scanner::Location* first_spread_arg_loc,
} }
Scanner::Location location = scanner_->location(); Scanner::Location location = scanner_->location();
if (Token::RPAREN != Next()) { if (Token::RPAREN != Next()) {
ReportMessageAt(location, MessageTemplate::kUnterminatedArgList); impl()->ReportMessageAt(location, MessageTemplate::kUnterminatedArgList);
*ok = false; *ok = false;
return this->NullExpressionList(); return impl()->NullExpressionList();
} }
*first_spread_arg_loc = spread_arg; *first_spread_arg_loc = spread_arg;
...@@ -2533,7 +2519,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression( ...@@ -2533,7 +2519,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression(
ExpressionT generator_object = ExpressionT generator_object =
factory()->NewVariableProxy(function_state_->generator_object_variable()); factory()->NewVariableProxy(function_state_->generator_object_variable());
// The following initialization is necessary. // The following initialization is necessary.
ExpressionT expression = Traits::EmptyExpression(); ExpressionT expression = impl()->EmptyExpression();
bool delegating = false; // yield* bool delegating = false; // yield*
if (!scanner()->HasAnyLineTerminatorBeforeNext()) { if (!scanner()->HasAnyLineTerminatorBeforeNext()) {
if (Check(Token::MUL)) delegating = true; if (Check(Token::MUL)) delegating = true;
...@@ -2562,7 +2548,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression( ...@@ -2562,7 +2548,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression(
return impl()->RewriteYieldStar(generator_object, expression, pos); return impl()->RewriteYieldStar(generator_object, expression, pos);
} }
expression = Traits::BuildIteratorResult(expression, false); expression = impl()->BuildIteratorResult(expression, false);
// Hackily disambiguate o from o.next and o [Symbol.iterator](). // Hackily disambiguate o from o.next and o [Symbol.iterator]().
// TODO(verwaest): Come up with a better solution. // TODO(verwaest): Come up with a better solution.
typename Traits::Type::YieldExpression yield = factory()->NewYield( typename Traits::Type::YieldExpression yield = factory()->NewYield(
...@@ -2589,20 +2575,22 @@ ParserBase<Impl>::ParseTailCallExpression(ExpressionClassifier* classifier, ...@@ -2589,20 +2575,22 @@ ParserBase<Impl>::ParseTailCallExpression(ExpressionClassifier* classifier,
Scanner::Location loc(pos, scanner()->location().end_pos); Scanner::Location loc(pos, scanner()->location().end_pos);
if (!expression->IsCall()) { if (!expression->IsCall()) {
Scanner::Location sub_loc(sub_expression_pos, loc.end_pos); Scanner::Location sub_loc(sub_expression_pos, loc.end_pos);
ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedInsideTailCall); impl()->ReportMessageAt(sub_loc,
MessageTemplate::kUnexpectedInsideTailCall);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} }
if (impl()->IsDirectEvalCall(expression)) { if (impl()->IsDirectEvalCall(expression)) {
Scanner::Location sub_loc(sub_expression_pos, loc.end_pos); Scanner::Location sub_loc(sub_expression_pos, loc.end_pos);
ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedTailCallOfEval); impl()->ReportMessageAt(sub_loc,
MessageTemplate::kUnexpectedTailCallOfEval);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} }
if (!is_strict(language_mode())) { if (!is_strict(language_mode())) {
ReportMessageAt(loc, MessageTemplate::kUnexpectedSloppyTailCall); impl()->ReportMessageAt(loc, MessageTemplate::kUnexpectedSloppyTailCall);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} }
ReturnExprContext return_expr_context = ReturnExprContext return_expr_context =
function_state_->return_expr_context(); function_state_->return_expr_context();
...@@ -2611,7 +2599,7 @@ ParserBase<Impl>::ParseTailCallExpression(ExpressionClassifier* classifier, ...@@ -2611,7 +2599,7 @@ ParserBase<Impl>::ParseTailCallExpression(ExpressionClassifier* classifier,
switch (return_expr_context) { switch (return_expr_context) {
case ReturnExprContext::kInsideValidReturnStatement: case ReturnExprContext::kInsideValidReturnStatement:
UNREACHABLE(); UNREACHABLE();
return Traits::EmptyExpression(); return impl()->EmptyExpression();
case ReturnExprContext::kInsideValidBlock: case ReturnExprContext::kInsideValidBlock:
msg = MessageTemplate::kUnexpectedTailCall; msg = MessageTemplate::kUnexpectedTailCall;
break; break;
...@@ -2622,9 +2610,9 @@ ParserBase<Impl>::ParseTailCallExpression(ExpressionClassifier* classifier, ...@@ -2622,9 +2610,9 @@ ParserBase<Impl>::ParseTailCallExpression(ExpressionClassifier* classifier,
msg = MessageTemplate::kUnexpectedTailCallInForInOf; msg = MessageTemplate::kUnexpectedTailCallInForInOf;
break; break;
} }
ReportMessageAt(loc, msg); impl()->ReportMessageAt(loc, msg);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} }
classifier->RecordTailCallExpressionError( classifier->RecordTailCallExpressionError(
loc, MessageTemplate::kUnexpectedTailCall); loc, MessageTemplate::kUnexpectedTailCall);
...@@ -2753,18 +2741,18 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryExpression( ...@@ -2753,18 +2741,18 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryExpression(
// "delete identifier" is a syntax error in strict mode. // "delete identifier" is a syntax error in strict mode.
ReportMessage(MessageTemplate::kStrictDelete); ReportMessage(MessageTemplate::kStrictDelete);
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
} }
if (peek() == Token::EXP) { if (peek() == Token::EXP) {
ReportUnexpectedToken(Next()); ReportUnexpectedToken(Next());
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
// Allow Traits do rewrite the expression. // Allow Traits do rewrite the expression.
return this->BuildUnaryExpression(expression, op, pos, factory()); return impl()->BuildUnaryExpression(expression, op, pos);
} else if (Token::IsCountOp(op)) { } else if (Token::IsCountOp(op)) {
BindingPatternUnexpectedToken(classifier); BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier); ArrowFormalParametersUnexpectedToken(classifier);
...@@ -2901,7 +2889,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier, ...@@ -2901,7 +2889,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier,
ReportClassifierError( ReportClassifierError(
async_classifier.async_arrow_formal_parameters_error()); async_classifier.async_arrow_formal_parameters_error());
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
if (args->length()) { if (args->length()) {
// async ( Arguments ) => ... // async ( Arguments ) => ...
...@@ -3071,10 +3059,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression( ...@@ -3071,10 +3059,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression(
if (!is_generator()) { if (!is_generator()) {
// TODO(neis): allow escaping into closures? // TODO(neis): allow escaping into closures?
ReportMessageAt(scanner()->location(), impl()->ReportMessageAt(scanner()->location(),
MessageTemplate::kUnexpectedFunctionSent); MessageTemplate::kUnexpectedFunctionSent);
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
return this->FunctionSentExpression(factory(), pos); return this->FunctionSentExpression(factory(), pos);
...@@ -3083,7 +3071,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression( ...@@ -3083,7 +3071,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression(
FunctionKind function_kind = Check(Token::MUL) FunctionKind function_kind = Check(Token::MUL)
? FunctionKind::kGeneratorFunction ? FunctionKind::kGeneratorFunction
: FunctionKind::kNormalFunction; : FunctionKind::kNormalFunction;
IdentifierT name = this->EmptyIdentifier(); IdentifierT name = impl()->EmptyIdentifier();
bool is_strict_reserved_name = false; bool is_strict_reserved_name = false;
Scanner::Location function_name_location = Scanner::Location::invalid(); Scanner::Location function_name_location = Scanner::Location::invalid();
FunctionLiteral::FunctionType function_type = FunctionLiteral::FunctionType function_type =
...@@ -3135,9 +3123,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression( ...@@ -3135,9 +3123,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression(
} }
} }
ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); impl()->ReportMessageAt(scanner()->location(),
MessageTemplate::kUnexpectedSuper);
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
template <typename Impl> template <typename Impl>
...@@ -3147,7 +3136,7 @@ void ParserBase<Impl>::ExpectMetaProperty(Vector<const char> property_name, ...@@ -3147,7 +3136,7 @@ void ParserBase<Impl>::ExpectMetaProperty(Vector<const char> property_name,
Consume(Token::PERIOD); Consume(Token::PERIOD);
ExpectContextualKeyword(property_name, CHECK_OK_CUSTOM(Void)); ExpectContextualKeyword(property_name, CHECK_OK_CUSTOM(Void));
if (scanner()->literal_contains_escapes()) { if (scanner()->literal_contains_escapes()) {
Traits::ReportMessageAt( impl()->ReportMessageAt(
Scanner::Location(pos, scanner()->location().end_pos), Scanner::Location(pos, scanner()->location().end_pos),
MessageTemplate::kInvalidEscapedMetaProperty, full_name); MessageTemplate::kInvalidEscapedMetaProperty, full_name);
*ok = false; *ok = false;
...@@ -3161,10 +3150,10 @@ ParserBase<Impl>::ParseNewTargetExpression(bool* ok) { ...@@ -3161,10 +3150,10 @@ ParserBase<Impl>::ParseNewTargetExpression(bool* ok) {
ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK);
if (!GetReceiverScope()->is_function_scope()) { if (!GetReceiverScope()->is_function_scope()) {
ReportMessageAt(scanner()->location(), impl()->ReportMessageAt(scanner()->location(),
MessageTemplate::kUnexpectedNewTarget); MessageTemplate::kUnexpectedNewTarget);
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
return this->NewTargetExpression(pos); return this->NewTargetExpression(pos);
...@@ -3236,14 +3225,14 @@ ParserBase<Impl>::ParseMemberExpressionContinuation( ...@@ -3236,14 +3225,14 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(
case Token::ILLEGAL: { case Token::ILLEGAL: {
ReportUnexpectedTokenAt(scanner()->peek_location(), Token::ILLEGAL); ReportUnexpectedTokenAt(scanner()->peek_location(), Token::ILLEGAL);
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
default: default:
return expression; return expression;
} }
} }
DCHECK(false); DCHECK(false);
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
template <typename Impl> template <typename Impl>
...@@ -3264,7 +3253,7 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters, ...@@ -3264,7 +3253,7 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters,
classifier->RecordNonSimpleParameter(); classifier->RecordNonSimpleParameter();
} }
ExpressionT initializer = Traits::EmptyExpression(); ExpressionT initializer = impl()->EmptyExpression();
if (!is_rest && Check(Token::ASSIGN)) { if (!is_rest && Check(Token::ASSIGN)) {
ExpressionClassifier init_classifier(this); ExpressionClassifier init_classifier(this);
initializer = ParseAssignmentExpression(true, &init_classifier, initializer = ParseAssignmentExpression(true, &init_classifier,
...@@ -3312,8 +3301,8 @@ void ParserBase<Impl>::ParseFormalParameterList( ...@@ -3312,8 +3301,8 @@ void ParserBase<Impl>::ParseFormalParameterList(
parameters->is_simple = false; parameters->is_simple = false;
classifier->RecordNonSimpleParameter(); classifier->RecordNonSimpleParameter();
if (peek() == Token::COMMA) { if (peek() == Token::COMMA) {
ReportMessageAt(scanner()->peek_location(), impl()->ReportMessageAt(scanner()->peek_location(),
MessageTemplate::kParamAfterRest); MessageTemplate::kParamAfterRest);
*ok = false; *ok = false;
return; return;
} }
...@@ -3341,19 +3330,22 @@ void ParserBase<Impl>::CheckArityRestrictions(int param_count, ...@@ -3341,19 +3330,22 @@ void ParserBase<Impl>::CheckArityRestrictions(int param_count,
int formals_end_pos, bool* ok) { int formals_end_pos, bool* ok) {
if (IsGetterFunction(function_kind)) { if (IsGetterFunction(function_kind)) {
if (param_count != 0) { if (param_count != 0) {
ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), impl()->ReportMessageAt(
MessageTemplate::kBadGetterArity); Scanner::Location(formals_start_pos, formals_end_pos),
MessageTemplate::kBadGetterArity);
*ok = false; *ok = false;
} }
} else if (IsSetterFunction(function_kind)) { } else if (IsSetterFunction(function_kind)) {
if (param_count != 1) { if (param_count != 1) {
ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), impl()->ReportMessageAt(
MessageTemplate::kBadSetterArity); Scanner::Location(formals_start_pos, formals_end_pos),
MessageTemplate::kBadSetterArity);
*ok = false; *ok = false;
} }
if (has_rest) { if (has_rest) {
ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), impl()->ReportMessageAt(
MessageTemplate::kBadSetterRestParameter); Scanner::Location(formals_start_pos, formals_end_pos),
MessageTemplate::kBadSetterRestParameter);
*ok = false; *ok = false;
} }
} }
...@@ -3413,7 +3405,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -3413,7 +3405,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
// If next token is not `=>`, it's a syntax error anyways. // If next token is not `=>`, it's a syntax error anyways.
ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
typename Traits::Type::StatementList body; typename Traits::Type::StatementList body;
...@@ -3449,7 +3441,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -3449,7 +3441,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
} }
} else { } else {
body = impl()->ParseEagerFunctionBody( body = impl()->ParseEagerFunctionBody(
this->EmptyIdentifier(), kNoSourcePosition, formal_parameters, impl()->EmptyIdentifier(), kNoSourcePosition, formal_parameters,
arrow_kind, FunctionLiteral::kAnonymousExpression, CHECK_OK); arrow_kind, FunctionLiteral::kAnonymousExpression, CHECK_OK);
materialized_literal_count = materialized_literal_count =
function_state.materialized_literal_count(); function_state.materialized_literal_count();
...@@ -3506,7 +3498,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -3506,7 +3498,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
} }
FunctionLiteralT function_literal = factory()->NewFunctionLiteral( FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
this->EmptyIdentifierString(), formal_parameters.scope, body, impl()->EmptyIdentifierString(), formal_parameters.scope, body,
materialized_literal_count, expected_property_count, num_parameters, materialized_literal_count, expected_property_count, num_parameters,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, FunctionLiteral::kAnonymousExpression,
...@@ -3562,16 +3554,16 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( ...@@ -3562,16 +3554,16 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK);
next = peek(); next = peek();
if (next == Token::EOS) { if (next == Token::EOS) {
ReportMessageAt(Scanner::Location(start, peek_position()), impl()->ReportMessageAt(Scanner::Location(start, peek_position()),
MessageTemplate::kUnterminatedTemplate); MessageTemplate::kUnterminatedTemplate);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} else if (next == Token::ILLEGAL) { } else if (next == Token::ILLEGAL) {
Traits::ReportMessageAt( impl()->ReportMessageAt(
Scanner::Location(position() + 1, peek_position()), Scanner::Location(position() + 1, peek_position()),
MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} }
int expr_pos = peek_position(); int expr_pos = peek_position();
...@@ -3581,10 +3573,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( ...@@ -3581,10 +3573,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
impl()->AddTemplateExpression(&ts, expression); impl()->AddTemplateExpression(&ts, expression);
if (peek() != Token::RBRACE) { if (peek() != Token::RBRACE) {
ReportMessageAt(Scanner::Location(expr_pos, peek_position()), impl()->ReportMessageAt(Scanner::Location(expr_pos, peek_position()),
MessageTemplate::kUnterminatedTemplateExpr); MessageTemplate::kUnterminatedTemplateExpr);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} }
// If we didn't die parsing that expression, our next token should be a // If we didn't die parsing that expression, our next token should be a
...@@ -3594,16 +3586,16 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( ...@@ -3594,16 +3586,16 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
pos = position(); pos = position();
if (next == Token::EOS) { if (next == Token::EOS) {
ReportMessageAt(Scanner::Location(start, pos), impl()->ReportMessageAt(Scanner::Location(start, pos),
MessageTemplate::kUnterminatedTemplate); MessageTemplate::kUnterminatedTemplate);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} else if (next == Token::ILLEGAL) { } else if (next == Token::ILLEGAL) {
Traits::ReportMessageAt( impl()->ReportMessageAt(
Scanner::Location(position() + 1, peek_position()), Scanner::Location(position() + 1, peek_position()),
MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError);
*ok = false; *ok = false;
return Traits::EmptyExpression(); return impl()->EmptyExpression();
} }
impl()->AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL); impl()->AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL);
...@@ -3634,7 +3626,7 @@ ParserBase<Impl>::CheckAndRewriteReferenceExpression( ...@@ -3634,7 +3626,7 @@ ParserBase<Impl>::CheckAndRewriteReferenceExpression(
ReportMessageAt(Scanner::Location(beg_pos, end_pos), ReportMessageAt(Scanner::Location(beg_pos, end_pos),
MessageTemplate::kStrictEvalArguments, kSyntaxError); MessageTemplate::kStrictEvalArguments, kSyntaxError);
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
if (expression->IsValidReferenceExpression()) { if (expression->IsValidReferenceExpression()) {
return expression; return expression;
...@@ -3642,12 +3634,12 @@ ParserBase<Impl>::CheckAndRewriteReferenceExpression( ...@@ -3642,12 +3634,12 @@ ParserBase<Impl>::CheckAndRewriteReferenceExpression(
if (expression->IsCall()) { if (expression->IsCall()) {
// If it is a call, make it a runtime error for legacy web compatibility. // If it is a call, make it a runtime error for legacy web compatibility.
// Rewrite `expr' to `expr[throw ReferenceError]'. // Rewrite `expr' to `expr[throw ReferenceError]'.
ExpressionT error = this->NewThrowReferenceError(message, beg_pos); ExpressionT error = impl()->NewThrowReferenceError(message, beg_pos);
return factory()->NewProperty(expression, error, beg_pos); return factory()->NewProperty(expression, error, beg_pos);
} }
ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type); ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type);
*ok = false; *ok = false;
return this->EmptyExpression(); return impl()->EmptyExpression();
} }
template <typename Impl> template <typename Impl>
......
...@@ -367,15 +367,15 @@ bool Parser::ShortcutNumericLiteralBinaryExpression(Expression** x, ...@@ -367,15 +367,15 @@ bool Parser::ShortcutNumericLiteralBinaryExpression(Expression** x,
return false; return false;
} }
Expression* ParserBaseTraits<Parser>::BuildUnaryExpression( Expression* Parser::BuildUnaryExpression(Expression* expression,
Expression* expression, Token::Value op, int pos, AstNodeFactory* factory) { Token::Value op, int pos) {
DCHECK(expression != NULL); DCHECK(expression != NULL);
if (expression->IsLiteral()) { if (expression->IsLiteral()) {
const AstValue* literal = expression->AsLiteral()->raw_value(); const AstValue* literal = expression->AsLiteral()->raw_value();
if (op == Token::NOT) { if (op == Token::NOT) {
// Convert the literal to a boolean condition and negate it. // Convert the literal to a boolean condition and negate it.
bool condition = literal->BooleanValue(); bool condition = literal->BooleanValue();
return factory->NewBooleanLiteral(!condition, pos); return factory()->NewBooleanLiteral(!condition, pos);
} else if (literal->IsNumber()) { } else if (literal->IsNumber()) {
// Compute some expressions involving only number literals. // Compute some expressions involving only number literals.
double value = literal->AsNumber(); double value = literal->AsNumber();
...@@ -384,9 +384,10 @@ Expression* ParserBaseTraits<Parser>::BuildUnaryExpression( ...@@ -384,9 +384,10 @@ Expression* ParserBaseTraits<Parser>::BuildUnaryExpression(
case Token::ADD: case Token::ADD:
return expression; return expression;
case Token::SUB: case Token::SUB:
return factory->NewNumberLiteral(-value, pos, has_dot); return factory()->NewNumberLiteral(-value, pos, has_dot);
case Token::BIT_NOT: case Token::BIT_NOT:
return factory->NewNumberLiteral(~DoubleToInt32(value), pos, has_dot); return factory()->NewNumberLiteral(~DoubleToInt32(value), pos,
has_dot);
default: default:
break; break;
} }
...@@ -394,53 +395,33 @@ Expression* ParserBaseTraits<Parser>::BuildUnaryExpression( ...@@ -394,53 +395,33 @@ Expression* ParserBaseTraits<Parser>::BuildUnaryExpression(
} }
// Desugar '+foo' => 'foo*1' // Desugar '+foo' => 'foo*1'
if (op == Token::ADD) { if (op == Token::ADD) {
return factory->NewBinaryOperation( return factory()->NewBinaryOperation(
Token::MUL, expression, factory->NewNumberLiteral(1, pos, true), pos); Token::MUL, expression, factory()->NewNumberLiteral(1, pos, true), pos);
} }
// The same idea for '-foo' => 'foo*(-1)'. // The same idea for '-foo' => 'foo*(-1)'.
if (op == Token::SUB) { if (op == Token::SUB) {
return factory->NewBinaryOperation( return factory()->NewBinaryOperation(
Token::MUL, expression, factory->NewNumberLiteral(-1, pos), pos); Token::MUL, expression, factory()->NewNumberLiteral(-1, pos), pos);
} }
// ...and one more time for '~foo' => 'foo^(~0)'. // ...and one more time for '~foo' => 'foo^(~0)'.
if (op == Token::BIT_NOT) { if (op == Token::BIT_NOT) {
return factory->NewBinaryOperation( return factory()->NewBinaryOperation(
Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos); Token::BIT_XOR, expression, factory()->NewNumberLiteral(~0, pos), pos);
} }
return factory->NewUnaryOperation(op, expression, pos); return factory()->NewUnaryOperation(op, expression, pos);
} }
Expression* ParserBaseTraits<Parser>::BuildIteratorResult(Expression* value, Expression* Parser::BuildIteratorResult(Expression* value, bool done) {
bool done) {
int pos = kNoSourcePosition; int pos = kNoSourcePosition;
AstNodeFactory* factory = delegate()->factory();
Zone* zone = delegate()->zone();
if (value == nullptr) value = factory->NewUndefinedLiteral(pos);
auto args = new (zone) ZoneList<Expression*>(2, zone); if (value == nullptr) value = factory()->NewUndefinedLiteral(pos);
args->Add(value, zone);
args->Add(factory->NewBooleanLiteral(done, pos), zone);
return factory->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args, auto args = new (zone()) ZoneList<Expression*>(2, zone());
pos); args->Add(value, zone());
} args->Add(factory()->NewBooleanLiteral(done, pos), zone());
Expression* ParserBaseTraits<Parser>::NewThrowReferenceError(
MessageTemplate::Template message, int pos) {
return delegate()->NewThrowError(
Runtime::kNewReferenceError, message,
delegate()->ast_value_factory()->empty_string(), pos);
}
Expression* ParserBaseTraits<Parser>::NewThrowSyntaxError(
MessageTemplate::Template message, const AstRawString* arg, int pos) {
return delegate()->NewThrowError(Runtime::kNewSyntaxError, message, arg, pos);
}
Expression* ParserBaseTraits<Parser>::NewThrowTypeError( return factory()->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args,
MessageTemplate::Template message, const AstRawString* arg, int pos) { pos);
return delegate()->NewThrowError(Runtime::kNewTypeError, message, arg, pos);
} }
Expression* Parser::NewThrowError(Runtime::FunctionId id, Expression* Parser::NewThrowError(Runtime::FunctionId id,
...@@ -453,34 +434,6 @@ Expression* Parser::NewThrowError(Runtime::FunctionId id, ...@@ -453,34 +434,6 @@ Expression* Parser::NewThrowError(Runtime::FunctionId id,
return factory()->NewThrow(call_constructor, pos); return factory()->NewThrow(call_constructor, pos);
} }
void ParserBaseTraits<Parser>::ReportMessageAt(
Scanner::Location source_location, MessageTemplate::Template message,
const char* arg, ParseErrorType error_type) {
if (delegate()->stack_overflow()) {
// Suppress the error message (syntax error or such) in the presence of a
// stack overflow. The isolate allows only one pending exception at at time
// and we want to report the stack overflow later.
return;
}
delegate()->pending_error_handler_.ReportMessageAt(source_location.beg_pos,
source_location.end_pos,
message, arg, error_type);
}
void ParserBaseTraits<Parser>::ReportMessageAt(
Scanner::Location source_location, MessageTemplate::Template message,
const AstRawString* arg, ParseErrorType error_type) {
if (delegate()->stack_overflow()) {
// Suppress the error message (syntax error or such) in the presence of a
// stack overflow. The isolate allows only one pending exception at at time
// and we want to report the stack overflow later.
return;
}
delegate()->pending_error_handler_.ReportMessageAt(source_location.beg_pos,
source_location.end_pos,
message, arg, error_type);
}
const AstRawString* ParserBaseTraits<Parser>::GetSymbol( const AstRawString* ParserBaseTraits<Parser>::GetSymbol(
Scanner* scanner) const { Scanner* scanner) const {
const AstRawString* result = const AstRawString* result =
...@@ -606,11 +559,6 @@ Expression* ParserBaseTraits<Parser>::GetIterator(Expression* iterable, ...@@ -606,11 +559,6 @@ Expression* ParserBaseTraits<Parser>::GetIterator(Expression* iterable,
return factory->NewCall(prop, args, pos); return factory->NewCall(prop, args, pos);
} }
Literal* ParserBaseTraits<Parser>::GetLiteralTheHole(
int position, AstNodeFactory* factory) const {
return factory->NewTheHoleLiteral(kNoSourcePosition);
}
void Parser::MarkTailPosition(Expression* expression) { void Parser::MarkTailPosition(Expression* expression) {
expression->MarkTail(); expression->MarkTail();
} }
...@@ -3967,7 +3915,8 @@ void ParserBaseTraits<Parser>::ParseArrowFunctionFormalParameterList( ...@@ -3967,7 +3915,8 @@ void ParserBaseTraits<Parser>::ParseArrowFunctionFormalParameterList(
scope_snapshot.Reparent(parameters->scope); scope_snapshot.Reparent(parameters->scope);
if (parameters->Arity() > Code::kMaxArguments) { if (parameters->Arity() > Code::kMaxArguments) {
ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); delegate()->ReportMessageAt(params_loc,
MessageTemplate::kMalformedArrowFunParamList);
*ok = false; *ok = false;
return; return;
} }
......
...@@ -175,63 +175,6 @@ class ParserBaseTraits<Parser> { ...@@ -175,63 +175,6 @@ class ParserBaseTraits<Parser> {
return reinterpret_cast<const Parser*>(this); return reinterpret_cast<const Parser*>(this);
} }
// Rewrites the following types of unary expressions:
// not <literal> -> true / false
// + <numeric literal> -> <numeric literal>
// - <numeric literal> -> <numeric literal with value negated>
// ! <literal> -> true / false
// The following rewriting rules enable the collection of type feedback
// without any special stub and the multiplication is removed later in
// Crankshaft's canonicalization pass.
// + foo -> foo * 1
// - foo -> foo * (-1)
// ~ foo -> foo ^(~0)
Expression* BuildUnaryExpression(Expression* expression, Token::Value op,
int pos, AstNodeFactory* factory);
Expression* BuildIteratorResult(Expression* value, bool done);
// Generate AST node that throws a ReferenceError with the given type.
Expression* NewThrowReferenceError(MessageTemplate::Template message,
int pos);
// Generate AST node that throws a SyntaxError with the given
// type. The first argument may be null (in the handle sense) in
// which case no arguments are passed to the constructor.
Expression* NewThrowSyntaxError(MessageTemplate::Template message,
const AstRawString* arg, int pos);
// Generate AST node that throws a TypeError with the given
// type. Both arguments must be non-null (in the handle sense).
Expression* NewThrowTypeError(MessageTemplate::Template message,
const AstRawString* arg, int pos);
// Reporting errors.
void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const char* arg = NULL,
ParseErrorType error_type = kSyntaxError);
void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const AstRawString* arg,
ParseErrorType error_type = kSyntaxError);
// "null" return type creators.
static const AstRawString* EmptyIdentifier() { return nullptr; }
static Expression* EmptyExpression() { return nullptr; }
static Literal* EmptyLiteral() { return nullptr; }
static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return nullptr; }
static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; }
// Used in error return values.
static ZoneList<Expression*>* NullExpressionList() { return nullptr; }
// Non-NULL empty string.
V8_INLINE const AstRawString* EmptyIdentifierString() const;
// Odd-ball literal creators.
Literal* GetLiteralTheHole(int position, AstNodeFactory* factory) const;
// Producing data during the recursive descent. // Producing data during the recursive descent.
const AstRawString* GetSymbol(Scanner* scanner) const; const AstRawString* GetSymbol(Scanner* scanner) const;
const AstRawString* GetNextSymbol(Scanner* scanner) const; const AstRawString* GetNextSymbol(Scanner* scanner) const;
...@@ -939,6 +882,101 @@ class Parser : public ParserBase<Parser> { ...@@ -939,6 +882,101 @@ class Parser : public ParserBase<Parser> {
bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y, bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y,
Token::Value op, int pos); Token::Value op, int pos);
// Rewrites the following types of unary expressions:
// not <literal> -> true / false
// + <numeric literal> -> <numeric literal>
// - <numeric literal> -> <numeric literal with value negated>
// ! <literal> -> true / false
// The following rewriting rules enable the collection of type feedback
// without any special stub and the multiplication is removed later in
// Crankshaft's canonicalization pass.
// + foo -> foo * 1
// - foo -> foo * (-1)
// ~ foo -> foo ^(~0)
Expression* BuildUnaryExpression(Expression* expression, Token::Value op,
int pos);
Expression* BuildIteratorResult(Expression* value, bool done);
// Generate AST node that throws a ReferenceError with the given type.
V8_INLINE Expression* NewThrowReferenceError(
MessageTemplate::Template message, int pos) {
return NewThrowError(Runtime::kNewReferenceError, message,
ast_value_factory()->empty_string(), pos);
}
// Generate AST node that throws a SyntaxError with the given
// type. The first argument may be null (in the handle sense) in
// which case no arguments are passed to the constructor.
V8_INLINE Expression* NewThrowSyntaxError(MessageTemplate::Template message,
const AstRawString* arg, int pos) {
return NewThrowError(Runtime::kNewSyntaxError, message, arg, pos);
}
// Generate AST node that throws a TypeError with the given
// type. Both arguments must be non-null (in the handle sense).
V8_INLINE Expression* NewThrowTypeError(MessageTemplate::Template message,
const AstRawString* arg, int pos) {
return NewThrowError(Runtime::kNewTypeError, message, arg, pos);
}
// Reporting errors.
V8_INLINE void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const char* arg = NULL,
ParseErrorType error_type = kSyntaxError) {
if (stack_overflow()) {
// Suppress the error message (syntax error or such) in the presence of a
// stack overflow. The isolate allows only one pending exception at at
// time
// and we want to report the stack overflow later.
return;
}
pending_error_handler_.ReportMessageAt(source_location.beg_pos,
source_location.end_pos, message,
arg, error_type);
}
V8_INLINE void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const AstRawString* arg,
ParseErrorType error_type = kSyntaxError) {
if (stack_overflow()) {
// Suppress the error message (syntax error or such) in the presence of a
// stack overflow. The isolate allows only one pending exception at at
// time
// and we want to report the stack overflow later.
return;
}
pending_error_handler_.ReportMessageAt(source_location.beg_pos,
source_location.end_pos, message,
arg, error_type);
}
// "null" return type creators.
V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; }
V8_INLINE static Expression* EmptyExpression() { return nullptr; }
V8_INLINE static Literal* EmptyLiteral() { return nullptr; }
V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() {
return nullptr;
}
V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; }
// Used in error return values.
V8_INLINE static ZoneList<Expression*>* NullExpressionList() {
return nullptr;
}
// Non-NULL empty string.
V8_INLINE const AstRawString* EmptyIdentifierString() const {
return ast_value_factory()->empty_string();
}
// Odd-ball literal creators.
V8_INLINE Literal* GetLiteralTheHole(int position) {
return factory()->NewTheHoleLiteral(kNoSourcePosition);
}
// Parser's private field members. // Parser's private field members.
Scanner scanner_; Scanner scanner_;
...@@ -963,10 +1001,6 @@ class Parser : public ParserBase<Parser> { ...@@ -963,10 +1001,6 @@ class Parser : public ParserBase<Parser> {
#endif // DEBUG #endif // DEBUG
}; };
const AstRawString* ParserBaseTraits<Parser>::EmptyIdentifierString() const {
return delegate()->ast_value_factory()->empty_string();
}
// Support for handling complex values (array and object literals) that // Support for handling complex values (array and object literals) that
// can be fully handled at compile time. // can be fully handled at compile time.
......
...@@ -41,19 +41,6 @@ namespace internal { ...@@ -41,19 +41,6 @@ namespace internal {
#define DUMMY ) // to make indentation work #define DUMMY ) // to make indentation work
#undef DUMMY #undef DUMMY
void ParserBaseTraits<PreParser>::ReportMessageAt(
Scanner::Location source_location, MessageTemplate::Template message,
const char* arg, ParseErrorType error_type) {
delegate()->log_->LogMessage(source_location.beg_pos, source_location.end_pos,
message, arg, error_type);
}
void ParserBaseTraits<PreParser>::ReportMessageAt(
Scanner::Location source_location, MessageTemplate::Template message,
const AstRawString* arg, ParseErrorType error_type) {
UNREACHABLE();
}
PreParserIdentifier ParserBaseTraits<PreParser>::GetSymbol( PreParserIdentifier ParserBaseTraits<PreParser>::GetSymbol(
Scanner* scanner) const { Scanner* scanner) const {
switch (scanner->current_token()) { switch (scanner->current_token()) {
......
...@@ -624,75 +624,9 @@ class ParserBaseTraits<PreParser> { ...@@ -624,75 +624,9 @@ class ParserBaseTraits<PreParser> {
return reinterpret_cast<const PreParser*>(this); return reinterpret_cast<const PreParser*>(this);
} }
PreParserExpression BuildUnaryExpression(PreParserExpression expression,
Token::Value op, int pos,
PreParserFactory* factory) {
return PreParserExpression::Default();
}
PreParserExpression BuildIteratorResult(PreParserExpression value,
bool done) {
return PreParserExpression::Default();
}
PreParserExpression NewThrowReferenceError(MessageTemplate::Template message,
int pos) {
return PreParserExpression::Default();
}
PreParserExpression NewThrowSyntaxError(MessageTemplate::Template message,
PreParserIdentifier arg, int pos) {
return PreParserExpression::Default();
}
PreParserExpression NewThrowTypeError(MessageTemplate::Template message,
PreParserIdentifier arg, int pos) {
return PreParserExpression::Default();
}
// Reporting errors.
void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const char* arg = NULL,
ParseErrorType error_type = kSyntaxError);
void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const AstRawString* arg,
ParseErrorType error_type = kSyntaxError);
// A dummy function, just useful as an argument to CHECK_OK_CUSTOM. // A dummy function, just useful as an argument to CHECK_OK_CUSTOM.
static void Void() {} static void Void() {}
// "null" return type creators.
static PreParserIdentifier EmptyIdentifier() {
return PreParserIdentifier::Default();
}
static PreParserExpression EmptyExpression() {
return PreParserExpression::Default();
}
static PreParserExpression EmptyLiteral() {
return PreParserExpression::Default();
}
static PreParserExpression EmptyObjectLiteralProperty() {
return PreParserExpression::Default();
}
static PreParserExpression EmptyFunctionLiteral() {
return PreParserExpression::Default();
}
static PreParserExpressionList NullExpressionList() {
return PreParserExpressionList();
}
PreParserIdentifier EmptyIdentifierString() const {
return PreParserIdentifier::Default();
}
// Odd-ball literal creators.
PreParserExpression GetLiteralTheHole(int position,
PreParserFactory* factory) const {
return PreParserExpression::Default();
}
// Producing data during the recursive descent. // Producing data during the recursive descent.
PreParserIdentifier GetSymbol(Scanner* scanner) const; PreParserIdentifier GetSymbol(Scanner* scanner) const;
...@@ -1141,6 +1075,76 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1141,6 +1075,76 @@ class PreParser : public ParserBase<PreParser> {
return false; return false;
} }
V8_INLINE PreParserExpression BuildUnaryExpression(
PreParserExpression expression, Token::Value op, int pos) {
return PreParserExpression::Default();
}
V8_INLINE PreParserExpression BuildIteratorResult(PreParserExpression value,
bool done) {
return PreParserExpression::Default();
}
V8_INLINE PreParserExpression
NewThrowReferenceError(MessageTemplate::Template message, int pos) {
return PreParserExpression::Default();
}
V8_INLINE PreParserExpression NewThrowSyntaxError(
MessageTemplate::Template message, PreParserIdentifier arg, int pos) {
return PreParserExpression::Default();
}
V8_INLINE PreParserExpression NewThrowTypeError(
MessageTemplate::Template message, PreParserIdentifier arg, int pos) {
return PreParserExpression::Default();
}
// Reporting errors.
V8_INLINE void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const char* arg = NULL,
ParseErrorType error_type = kSyntaxError) {
log_->LogMessage(source_location.beg_pos, source_location.end_pos, message,
arg, error_type);
}
V8_INLINE void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const AstRawString* arg,
ParseErrorType error_type = kSyntaxError) {
UNREACHABLE();
}
// "null" return type creators.
V8_INLINE static PreParserIdentifier EmptyIdentifier() {
return PreParserIdentifier::Default();
}
V8_INLINE static PreParserExpression EmptyExpression() {
return PreParserExpression::Default();
}
V8_INLINE static PreParserExpression EmptyLiteral() {
return PreParserExpression::Default();
}
V8_INLINE static PreParserExpression EmptyObjectLiteralProperty() {
return PreParserExpression::Default();
}
V8_INLINE static PreParserExpression EmptyFunctionLiteral() {
return PreParserExpression::Default();
}
V8_INLINE static PreParserExpressionList NullExpressionList() {
return PreParserExpressionList();
}
V8_INLINE PreParserIdentifier EmptyIdentifierString() const {
return PreParserIdentifier::Default();
}
// Odd-ball literal creators.
V8_INLINE PreParserExpression GetLiteralTheHole(int position) {
return PreParserExpression::Default();
}
// Preparser's private field members. // Preparser's private field members.
int* use_counts_; int* use_counts_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment