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

Unified Diff: src/preparser.h

Issue 1207743004: Fix unexpected token messages in expression classifier (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Add message test Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/message/arrow-strict-eval-bare-parameter.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index b66053b94697a7d82a59969e1f06a6cd4fd1b3fc..0653ded54a9522bf4a68e146456680ff24b29bf2 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -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,54 +1839,73 @@ 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) {
ExpressionClassifier classifier;
« no previous file with comments | « no previous file | test/message/arrow-strict-eval-bare-parameter.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698