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

Side by Side Diff: src/parser.cc

Issue 153743006: Merge Parser::ReportUnexpectedToken and PreParser::ReportUnexpectedToken. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 3451 matching lines...) Expand 10 before | Expand all | Expand 10 after
3462 // DebuggerStatement :: 3462 // DebuggerStatement ::
3463 // 'debugger' ';' 3463 // 'debugger' ';'
3464 3464
3465 int pos = peek_position(); 3465 int pos = peek_position();
3466 Expect(Token::DEBUGGER, CHECK_OK); 3466 Expect(Token::DEBUGGER, CHECK_OK);
3467 ExpectSemicolon(CHECK_OK); 3467 ExpectSemicolon(CHECK_OK);
3468 return factory()->NewDebuggerStatement(pos); 3468 return factory()->NewDebuggerStatement(pos);
3469 } 3469 }
3470 3470
3471 3471
3472 void Parser::ReportUnexpectedToken(Token::Value token) {
3473 // We don't report stack overflows here, to avoid increasing the
3474 // stack depth even further. Instead we report it after parsing is
3475 // over, in ParseProgram/ParseJson.
3476 if (token == Token::ILLEGAL && stack_overflow()) return;
3477 // Four of the tokens are treated specially
3478 switch (token) {
3479 case Token::EOS:
3480 return ReportMessage("unexpected_eos", Vector<const char*>::empty());
3481 case Token::NUMBER:
3482 return ReportMessage("unexpected_token_number",
3483 Vector<const char*>::empty());
3484 case Token::STRING:
3485 return ReportMessage("unexpected_token_string",
3486 Vector<const char*>::empty());
3487 case Token::IDENTIFIER:
3488 return ReportMessage("unexpected_token_identifier",
3489 Vector<const char*>::empty());
3490 case Token::FUTURE_RESERVED_WORD:
3491 return ReportMessage("unexpected_reserved",
3492 Vector<const char*>::empty());
3493 case Token::YIELD:
3494 case Token::FUTURE_STRICT_RESERVED_WORD:
3495 return ReportMessage(top_scope_->is_classic_mode() ?
3496 "unexpected_token_identifier" :
3497 "unexpected_strict_reserved",
3498 Vector<const char*>::empty());
3499 default:
3500 const char* name = Token::String(token);
3501 ASSERT(name != NULL);
3502 ReportMessage("unexpected_token", Vector<const char*>(&name, 1));
3503 }
3504 }
3505
3506
3507 void Parser::ReportInvalidPreparseData(Handle<String> name, bool* ok) { 3472 void Parser::ReportInvalidPreparseData(Handle<String> name, bool* ok) {
3508 SmartArrayPointer<char> name_string = name->ToCString(DISALLOW_NULLS); 3473 SmartArrayPointer<char> name_string = name->ToCString(DISALLOW_NULLS);
3509 const char* element[1] = { name_string.get() }; 3474 const char* element[1] = { name_string.get() };
3510 ReportMessage("invalid_preparser_data", 3475 ReportMessage("invalid_preparser_data",
3511 Vector<const char*>(element, 1)); 3476 Vector<const char*>(element, 1));
3512 *ok = false; 3477 *ok = false;
3513 } 3478 }
3514 3479
3515 3480
3516 Expression* Parser::ParsePrimaryExpression(bool* ok) { 3481 Expression* Parser::ParsePrimaryExpression(bool* ok) {
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
4478 void ParserBase::ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { 4443 void ParserBase::ExpectContextualKeyword(Vector<const char> keyword, bool* ok) {
4479 Expect(Token::IDENTIFIER, ok); 4444 Expect(Token::IDENTIFIER, ok);
4480 if (!*ok) return; 4445 if (!*ok) return;
4481 if (!scanner()->is_literal_contextual_keyword(keyword)) { 4446 if (!scanner()->is_literal_contextual_keyword(keyword)) {
4482 ReportUnexpectedToken(scanner()->current_token()); 4447 ReportUnexpectedToken(scanner()->current_token());
4483 *ok = false; 4448 *ok = false;
4484 } 4449 }
4485 } 4450 }
4486 4451
4487 4452
4453 void ParserBase::ReportUnexpectedToken(Token::Value token) {
4454 // We don't report stack overflows here, to avoid increasing the
4455 // stack depth even further. Instead we report it after parsing is
4456 // over, in ParseProgram.
4457 if (token == Token::ILLEGAL && stack_overflow()) {
4458 return;
4459 }
4460 Scanner::Location source_location = scanner()->location();
4461
4462 // Four of the tokens are treated specially
4463 switch (token) {
4464 case Token::EOS:
4465 return ReportMessageAt(source_location, "unexpected_eos");
4466 case Token::NUMBER:
4467 return ReportMessageAt(source_location, "unexpected_token_number");
4468 case Token::STRING:
4469 return ReportMessageAt(source_location, "unexpected_token_string");
4470 case Token::IDENTIFIER:
4471 return ReportMessageAt(source_location,
4472 "unexpected_token_identifier");
4473 case Token::FUTURE_RESERVED_WORD:
4474 return ReportMessageAt(source_location, "unexpected_reserved");
4475 case Token::YIELD:
4476 case Token::FUTURE_STRICT_RESERVED_WORD:
4477 return ReportMessageAt(source_location,
4478 is_classic_mode() ? "unexpected_token_identifier"
4479 : "unexpected_strict_reserved");
4480 default:
4481 const char* name = Token::String(token);
4482 ASSERT(name != NULL);
4483 ReportMessageAt(
4484 source_location, "unexpected_token", Vector<const char*>(&name, 1));
4485 }
4486 }
4487
4488
4488 Literal* Parser::GetLiteralUndefined(int position) { 4489 Literal* Parser::GetLiteralUndefined(int position) {
4489 return factory()->NewLiteral( 4490 return factory()->NewLiteral(
4490 isolate()->factory()->undefined_value(), position); 4491 isolate()->factory()->undefined_value(), position);
4491 } 4492 }
4492 4493
4493 4494
4494 Literal* Parser::GetLiteralTheHole(int position) { 4495 Literal* Parser::GetLiteralTheHole(int position) {
4495 return factory()->NewLiteral( 4496 return factory()->NewLiteral(
4496 isolate()->factory()->the_hole_value(), RelocInfo::kNoPosition); 4497 isolate()->factory()->the_hole_value(), RelocInfo::kNoPosition);
4497 } 4498 }
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
5688 ASSERT(info()->isolate()->has_pending_exception()); 5689 ASSERT(info()->isolate()->has_pending_exception());
5689 } else { 5690 } else {
5690 result = ParseProgram(); 5691 result = ParseProgram();
5691 } 5692 }
5692 } 5693 }
5693 info()->SetFunction(result); 5694 info()->SetFunction(result);
5694 return (result != NULL); 5695 return (result != NULL);
5695 } 5696 }
5696 5697
5697 } } // namespace v8::internal 5698 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698