Commit edcc242a authored by wingo's avatar wingo Committed by Commit bot

Fix unexpected token messages in expression classifier

Some tokens need special messages because their token corresponds to
many names.

R=arv@chromium.org
BUG=v8:4213
LOG=N

Review URL: https://codereview.chromium.org/1207743004

Cr-Commit-Position: refs/heads/master@{#29262}
parent 627627b3
......@@ -503,6 +503,10 @@ class ParserBase : public Traits {
error_type);
}
void GetUnexpectedTokenMessage(
Token::Value token, MessageTemplate::Template* message, const char** arg,
MessageTemplate::Template default_ = MessageTemplate::kUnexpectedToken);
void ReportUnexpectedToken(Token::Value token);
void ReportUnexpectedTokenAt(
Scanner::Location location, Token::Value token,
......@@ -572,21 +576,26 @@ class ParserBase : public Traits {
}
void ExpressionUnexpectedToken(ExpressionClassifier* classifier) {
classifier->RecordExpressionError(scanner()->peek_location(),
MessageTemplate::kUnexpectedToken,
Token::String(peek()));
MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
const char* arg;
GetUnexpectedTokenMessage(peek(), &message, &arg);
classifier->RecordExpressionError(scanner()->peek_location(), message, arg);
}
void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) {
classifier->RecordBindingPatternError(scanner()->peek_location(),
MessageTemplate::kUnexpectedToken,
Token::String(peek()));
MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
const char* arg;
GetUnexpectedTokenMessage(peek(), &message, &arg);
classifier->RecordBindingPatternError(scanner()->peek_location(), message,
arg);
}
void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) {
classifier->RecordArrowFormalParametersError(
scanner()->peek_location(), MessageTemplate::kUnexpectedToken,
Token::String(peek()));
MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
const char* arg;
GetUnexpectedTokenMessage(peek(), &message, &arg);
classifier->RecordArrowFormalParametersError(scanner()->peek_location(),
message, arg);
}
// Recursive descent functions:
......@@ -1830,53 +1839,72 @@ ParserBase<Traits>::FunctionState::~FunctionState() {
}
template<class Traits>
void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
return ReportUnexpectedTokenAt(scanner_->location(), token);
}
template <class Traits>
void ParserBase<Traits>::ReportUnexpectedTokenAt(
Scanner::Location source_location, Token::Value token,
MessageTemplate::Template message) {
void ParserBase<Traits>::GetUnexpectedTokenMessage(
Token::Value token, MessageTemplate::Template* message, const char** arg,
MessageTemplate::Template default_) {
// Four of the tokens are treated specially
switch (token) {
case Token::EOS:
return ReportMessageAt(source_location, MessageTemplate::kUnexpectedEOS);
*message = MessageTemplate::kUnexpectedEOS;
*arg = nullptr;
break;
case Token::SMI:
case Token::NUMBER:
return ReportMessageAt(source_location,
MessageTemplate::kUnexpectedTokenNumber);
*message = MessageTemplate::kUnexpectedTokenNumber;
*arg = nullptr;
break;
case Token::STRING:
return ReportMessageAt(source_location,
MessageTemplate::kUnexpectedTokenString);
*message = MessageTemplate::kUnexpectedTokenString;
*arg = nullptr;
break;
case Token::IDENTIFIER:
return ReportMessageAt(source_location,
MessageTemplate::kUnexpectedTokenIdentifier);
*message = MessageTemplate::kUnexpectedTokenIdentifier;
*arg = nullptr;
break;
case Token::FUTURE_RESERVED_WORD:
return ReportMessageAt(source_location,
MessageTemplate::kUnexpectedReserved);
*message = MessageTemplate::kUnexpectedReserved;
*arg = nullptr;
break;
case Token::LET:
case Token::STATIC:
case Token::YIELD:
case Token::FUTURE_STRICT_RESERVED_WORD:
return ReportMessageAt(source_location,
is_strict(language_mode())
? MessageTemplate::kUnexpectedStrictReserved
: MessageTemplate::kUnexpectedTokenIdentifier);
*message = is_strict(language_mode())
? MessageTemplate::kUnexpectedStrictReserved
: MessageTemplate::kUnexpectedTokenIdentifier;
*arg = nullptr;
break;
case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL:
return Traits::ReportMessageAt(
source_location, MessageTemplate::kUnexpectedTemplateString);
*message = MessageTemplate::kUnexpectedTemplateString;
*arg = nullptr;
break;
default:
const char* name = Token::String(token);
DCHECK(name != NULL);
Traits::ReportMessageAt(source_location, message, name);
*arg = name;
break;
}
}
template <class Traits>
void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
return ReportUnexpectedTokenAt(scanner_->location(), token);
}
template <class Traits>
void ParserBase<Traits>::ReportUnexpectedTokenAt(
Scanner::Location source_location, Token::Value token,
MessageTemplate::Template message) {
const char* arg;
GetUnexpectedTokenMessage(token, &message, &arg);
Traits::ReportMessageAt(source_location, message, arg);
}
template <class Traits>
typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier(
AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) {
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --harmony-arrow-functions
"use strict";
eval => 42
*%(basename)s:8: SyntaxError: Unexpected identifier
eval => 42
^^^^
SyntaxError: Unexpected identifier
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