Revision: 19161
Author: [email protected]
Date: Thu Feb 6 15:10:21 2014 UTC
Log: Merge Parser::ReportUnexpectedToken and
PreParser::ReportUnexpectedToken.
(I.e., move ReportUnexpectedToken to ParserBase.)
Because of the recent unifications, they now do the same thing.
BUG=
[email protected]
Review URL: https://codereview.chromium.org/153743006
http://code.google.com/p/v8/source/detail?r=19161
Modified:
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/src/parser.h
/branches/bleeding_edge/src/preparser.cc
/branches/bleeding_edge/src/preparser.h
=======================================
--- /branches/bleeding_edge/src/parser.cc Thu Feb 6 11:59:16 2014 UTC
+++ /branches/bleeding_edge/src/parser.cc Thu Feb 6 15:10:21 2014 UTC
@@ -3467,41 +3467,6 @@
ExpectSemicolon(CHECK_OK);
return factory()->NewDebuggerStatement(pos);
}
-
-
-void Parser::ReportUnexpectedToken(Token::Value token) {
- // We don't report stack overflows here, to avoid increasing the
- // stack depth even further. Instead we report it after parsing is
- // over, in ParseProgram/ParseJson.
- if (token == Token::ILLEGAL && stack_overflow()) return;
- // Four of the tokens are treated specially
- switch (token) {
- case Token::EOS:
- return ReportMessage("unexpected_eos", Vector<const char*>::empty());
- case Token::NUMBER:
- return ReportMessage("unexpected_token_number",
- Vector<const char*>::empty());
- case Token::STRING:
- return ReportMessage("unexpected_token_string",
- Vector<const char*>::empty());
- case Token::IDENTIFIER:
- return ReportMessage("unexpected_token_identifier",
- Vector<const char*>::empty());
- case Token::FUTURE_RESERVED_WORD:
- return ReportMessage("unexpected_reserved",
- Vector<const char*>::empty());
- case Token::YIELD:
- case Token::FUTURE_STRICT_RESERVED_WORD:
- return ReportMessage(top_scope_->is_classic_mode() ?
- "unexpected_token_identifier" :
- "unexpected_strict_reserved",
- Vector<const char*>::empty());
- default:
- const char* name = Token::String(token);
- ASSERT(name != NULL);
- ReportMessage("unexpected_token", Vector<const char*>(&name, 1));
- }
-}
void Parser::ReportInvalidPreparseData(Handle<String> name, bool* ok) {
@@ -4483,6 +4448,42 @@
*ok = false;
}
}
+
+
+void ParserBase::ReportUnexpectedToken(Token::Value token) {
+ // We don't report stack overflows here, to avoid increasing the
+ // stack depth even further. Instead we report it after parsing is
+ // over, in ParseProgram.
+ if (token == Token::ILLEGAL && stack_overflow()) {
+ return;
+ }
+ Scanner::Location source_location = scanner()->location();
+
+ // Four of the tokens are treated specially
+ switch (token) {
+ case Token::EOS:
+ return ReportMessageAt(source_location, "unexpected_eos");
+ case Token::NUMBER:
+ return ReportMessageAt(source_location, "unexpected_token_number");
+ case Token::STRING:
+ return ReportMessageAt(source_location, "unexpected_token_string");
+ case Token::IDENTIFIER:
+ return ReportMessageAt(source_location,
+ "unexpected_token_identifier");
+ case Token::FUTURE_RESERVED_WORD:
+ return ReportMessageAt(source_location, "unexpected_reserved");
+ case Token::YIELD:
+ case Token::FUTURE_STRICT_RESERVED_WORD:
+ return ReportMessageAt(source_location,
+
is_classic_mode() ? "unexpected_token_identifier"
+ : "unexpected_strict_reserved");
+ default:
+ const char* name = Token::String(token);
+ ASSERT(name != NULL);
+ ReportMessageAt(
+ source_location, "unexpected_token", Vector<const char*>(&name,
1));
+ }
+}
Literal* Parser::GetLiteralUndefined(int position) {
=======================================
--- /branches/bleeding_edge/src/parser.h Wed Feb 5 16:26:48 2014 UTC
+++ /branches/bleeding_edge/src/parser.h Thu Feb 6 15:10:21 2014 UTC
@@ -521,6 +521,10 @@
Mode old_mode_;
};
+ virtual bool is_classic_mode() {
+ return top_scope_->is_classic_mode();
+ }
+
// Returns NULL if parsing failed.
FunctionLiteral* ParseProgram();
@@ -536,7 +540,6 @@
Handle<String> source);
// Report syntax error
- void ReportUnexpectedToken(Token::Value token);
void ReportInvalidPreparseData(Handle<String> name, bool* ok);
void ReportMessage(const char* message, Vector<const char*> args);
void ReportMessage(const char* message, Vector<Handle<String> > args);
=======================================
--- /branches/bleeding_edge/src/preparser.cc Thu Feb 6 13:12:10 2014 UTC
+++ /branches/bleeding_edge/src/preparser.cc Thu Feb 6 15:10:21 2014 UTC
@@ -72,7 +72,7 @@
ReportUnexpectedToken(scanner()->current_token());
} else {
ASSERT_EQ(Token::RBRACE, scanner()->peek());
- if (!is_classic_mode()) {
+ if (!scope_->is_classic_mode()) {
int end_pos = scanner()->location().end_pos;
CheckOctalLiteral(start_position, end_pos, &ok);
if (ok) {
@@ -97,40 +97,6 @@
// That means that contextual checks (like a label being declared where
// it is used) are generally omitted.
-void PreParser::ReportUnexpectedToken(Token::Value token) {
- // We don't report stack overflows here, to avoid increasing the
- // stack depth even further. Instead we report it after parsing is
- // over, in ParseProgram.
- if (token == Token::ILLEGAL && stack_overflow()) {
- return;
- }
- Scanner::Location source_location = scanner()->location();
-
- // Four of the tokens are treated specially
- switch (token) {
- case Token::EOS:
- return ReportMessageAt(source_location, "unexpected_eos", NULL);
- case Token::NUMBER:
- return ReportMessageAt(source_location, "unexpected_token_number",
NULL);
- case Token::STRING:
- return ReportMessageAt(source_location, "unexpected_token_string",
NULL);
- case Token::IDENTIFIER:
- return ReportMessageAt(source_location,
- "unexpected_token_identifier", NULL);
- case Token::FUTURE_RESERVED_WORD:
- return ReportMessageAt(source_location, "unexpected_reserved", NULL);
- case Token::YIELD:
- case Token::FUTURE_STRICT_RESERVED_WORD:
- return ReportMessageAt(source_location,
-
is_classic_mode() ? "unexpected_token_identifier"
- : "unexpected_strict_reserved",
- NULL);
- default:
- const char* name = Token::String(token);
- ReportMessageAt(source_location, "unexpected_token", name);
- }
-}
-
#define CHECK_OK ok); \
if (!*ok) return kUnknownSourceElements; \
@@ -271,7 +237,7 @@
Scanner::Location start_location = scanner()->peek_location();
Statement statement = ParseFunctionDeclaration(CHECK_OK);
Scanner::Location end_location = scanner()->location();
- if (!is_classic_mode()) {
+ if (!scope_->is_classic_mode()) {
ReportMessageAt(start_location.beg_pos, end_location.end_pos,
"strict_function", NULL);
*ok = false;
@@ -480,7 +446,7 @@
// Expression is a single identifier, and not, e.g., a parenthesized
// identifier.
ASSERT(!expr.AsIdentifier().IsFutureReserved());
- ASSERT(is_classic_mode() ||
+ ASSERT(scope_->is_classic_mode() ||
(!expr.AsIdentifier().IsFutureStrictReserved() &&
!expr.AsIdentifier().IsYield()));
Consume(Token::COLON);
@@ -578,7 +544,7 @@
// WithStatement ::
// 'with' '(' Expression ')' Statement
Expect(Token::WITH, CHECK_OK);
- if (!is_classic_mode()) {
+ if (!scope_->is_classic_mode()) {
Scanner::Location location = scanner()->location();
ReportMessageAt(location, "strict_mode_with", NULL);
*ok = false;
@@ -834,7 +800,7 @@
return expression;
}
- if (!is_classic_mode() &&
+ if (!scope_->is_classic_mode() &&
expression.IsIdentifier() &&
expression.AsIdentifier().IsEvalOrArguments()) {
Scanner::Location after = scanner()->location();
@@ -928,7 +894,7 @@
op = Next();
Scanner::Location before = scanner()->peek_location();
Expression expression = ParseUnaryExpression(CHECK_OK);
- if (!is_classic_mode() &&
+ if (!scope_->is_classic_mode() &&
expression.IsIdentifier() &&
expression.AsIdentifier().IsEvalOrArguments()) {
Scanner::Location after = scanner()->location();
@@ -951,7 +917,7 @@
Expression expression = ParseLeftHandSideExpression(CHECK_OK);
if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
Token::IsCountOp(peek())) {
- if (!is_classic_mode() &&
+ if (!scope_->is_classic_mode() &&
expression.IsIdentifier() &&
expression.AsIdentifier().IsEvalOrArguments()) {
Scanner::Location after = scanner()->location();
@@ -1392,7 +1358,7 @@
}
Expect(Token::RBRACE, CHECK_OK);
- if (!is_classic_mode()) {
+ if (!scope_->is_classic_mode()) {
int end_position = scanner()->location().end_pos;
CheckOctalLiteral(start_position, end_position, CHECK_OK);
CheckDelayedStrictModeViolation(start_position, end_position,
CHECK_OK);
@@ -1500,11 +1466,11 @@
if (next == Token::IDENTIFIER) {
PreParser::Identifier name = GetIdentifierSymbol();
if (allow_eval_or_arguments == kDontAllowEvalOrArguments &&
- !is_classic_mode() && name.IsEvalOrArguments()) {
+ !scope_->is_classic_mode() && name.IsEvalOrArguments()) {
StrictModeIdentifierViolation(scanner()->location(), name, ok);
}
return name;
- } else if (is_classic_mode() &&
+ } else if (scope_->is_classic_mode() &&
(next == Token::FUTURE_STRICT_RESERVED_WORD ||
(next == Token::YIELD && !scope_->is_generator()))) {
return GetIdentifierSymbol();
@@ -1519,7 +1485,7 @@
void PreParser::SetStrictModeViolation(Scanner::Location location,
const char* type,
bool* ok) {
- if (!is_classic_mode()) {
+ if (!scope_->is_classic_mode()) {
ReportMessageAt(location, type, NULL);
*ok = false;
return;
@@ -1558,7 +1524,7 @@
} else if (identifier.IsFutureStrictReserved() || identifier.IsYield()) {
type = "unexpected_strict_reserved";
}
- if (!is_classic_mode()) {
+ if (!scope_->is_classic_mode()) {
ReportMessageAt(location, type, NULL);
*ok = false;
return;
=======================================
--- /branches/bleeding_edge/src/preparser.h Thu Feb 6 13:12:10 2014 UTC
+++ /branches/bleeding_edge/src/preparser.h Thu Feb 6 15:10:21 2014 UTC
@@ -86,6 +86,8 @@
int peek_position() { return scanner_->peek_location().beg_pos; }
bool stack_overflow() const { return stack_overflow_; }
void set_stack_overflow() { stack_overflow_ = true; }
+
+ virtual bool is_classic_mode() = 0;
INLINE(Token::Value peek()) {
if (stack_overflow_) return Token::ILLEGAL;
@@ -142,8 +144,13 @@
static int Precedence(Token::Value token, bool accept_IN);
// Report syntax errors.
- virtual void ReportUnexpectedToken(Token::Value token) = 0;
- virtual void ReportMessageAt(Scanner::Location loc, const char* type) =
0;
+ void ReportUnexpectedToken(Token::Value token);
+ void ReportMessageAt(Scanner::Location location, const char* type) {
+ ReportMessageAt(location, type, Vector<const char*>::empty());
+ }
+ virtual void ReportMessageAt(Scanner::Location source_location,
+ const char* message,
+ Vector<const char*> args) = 0;
// Used to detect duplicates in object literals. Each of the values
// kGetterProperty, kSetterProperty and kValueProperty represents
@@ -542,9 +549,13 @@
};
// Report syntax error
- void ReportUnexpectedToken(Token::Value token);
- void ReportMessageAt(Scanner::Location location, const char* type) {
- ReportMessageAt(location, type, NULL);
+ void ReportMessageAt(Scanner::Location location,
+ const char* message,
+ Vector<const char*> args) {
+ ReportMessageAt(location.beg_pos,
+ location.end_pos,
+ message,
+ args.length() > 0 ? args[0] : NULL);
}
void ReportMessageAt(Scanner::Location location,
const char* type,
@@ -625,7 +636,7 @@
scope_->set_language_mode(language_mode);
}
- bool is_classic_mode() {
+ virtual bool is_classic_mode() {
return scope_->language_mode() == CLASSIC_MODE;
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.