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

Unified Diff: src/parser.cc

Issue 207633003: Move new expression parsing funcs to ParserBase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: code review Created 6 years, 9 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 | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index c0d33604cb7a29f840ad0c2ce9992b5b767dcf05..9724ec74c59f008b65b99ab1fcca5bc0adeb28a4 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -439,6 +439,17 @@ bool ParserTraits::IsIdentifier(Expression* expression) {
}
+void ParserTraits::PushPropertyName(FuncNameInferrer* fni,
+ Expression* expression) {
+ if (expression->IsPropertyName()) {
+ fni->PushLiteralName(expression->AsLiteral()->AsPropertyName());
+ } else {
+ fni->PushLiteralName(
+ parser_->isolate()->factory()->anonymous_function_string());
+ }
+}
+
+
void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left,
Expression* right) {
ASSERT(left != NULL);
@@ -750,11 +761,6 @@ FunctionLiteral* ParserTraits::ParseFunctionLiteral(
}
-Expression* ParserTraits::ParseMemberWithNewPrefixesExpression(bool* ok) {
- return parser_->ParseMemberWithNewPrefixesExpression(ok);
-}
-
-
Parser::Parser(CompilationInfo* info)
: ParserBase<ParserTraits>(&scanner_,
info->isolate()->stack_guard()->real_climit(),
@@ -3053,127 +3059,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
}
-Expression* Parser::ParseMemberWithNewPrefixesExpression(bool* ok) {
- // NewExpression ::
- // ('new')+ MemberExpression
-
- // The grammar for new expressions is pretty warped. We can have several 'new'
- // keywords following each other, and then a MemberExpression. When we see '('
- // after the MemberExpression, it's associated with the rightmost unassociated
- // 'new' to create a NewExpression with arguments. However, a NewExpression
- // can also occur without arguments.
-
- // Examples of new expression:
- // new foo.bar().baz means (new (foo.bar)()).baz
- // new foo()() means (new foo())()
- // new new foo()() means (new (new foo())())
- // new new foo means new (new foo)
- // new new foo() means new (new foo())
- // new new foo().bar().baz means (new (new foo()).bar()).baz
-
- if (peek() == Token::NEW) {
- Consume(Token::NEW);
- int new_pos = position();
- Expression* result = ParseMemberWithNewPrefixesExpression(CHECK_OK);
- if (peek() == Token::LPAREN) {
- // NewExpression with arguments.
- ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
- result = factory()->NewCallNew(result, args, new_pos);
- // The expression can still continue with . or [ after the arguments.
- result = ParseMemberExpressionContinuation(result, CHECK_OK);
- return result;
- }
- // NewExpression without arguments.
- return factory()->NewCallNew(
- result, new(zone()) ZoneList<Expression*>(0, zone()), new_pos);
- }
- // No 'new' keyword.
- return ParseMemberExpression(ok);
-}
-
-
-Expression* Parser::ParseMemberExpression(bool* ok) {
- // MemberExpression ::
- // (PrimaryExpression | FunctionLiteral)
- // ('[' Expression ']' | '.' Identifier | Arguments)*
-
- // The '[' Expression ']' and '.' Identifier parts are parsed by
- // ParseMemberExpressionContinuation, and the Arguments part is parsed by the
- // caller.
-
- // Parse the initial primary or function expression.
- Expression* result = NULL;
- if (peek() == Token::FUNCTION) {
- Consume(Token::FUNCTION);
- int function_token_position = position();
- bool is_generator = allow_generators() && Check(Token::MUL);
- Handle<String> name;
- bool is_strict_reserved_name = false;
- Scanner::Location function_name_location = Scanner::Location::invalid();
- FunctionLiteral::FunctionType function_type =
- FunctionLiteral::ANONYMOUS_EXPRESSION;
- if (peek_any_identifier()) {
- name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
- CHECK_OK);
- function_name_location = scanner()->location();
- function_type = FunctionLiteral::NAMED_EXPRESSION;
- }
- result = ParseFunctionLiteral(name,
- function_name_location,
- is_strict_reserved_name,
- is_generator,
- function_token_position,
- function_type,
- CHECK_OK);
- } else {
- result = ParsePrimaryExpression(CHECK_OK);
- }
-
- result = ParseMemberExpressionContinuation(result, CHECK_OK);
- return result;
-}
-
-
-Expression* Parser::ParseMemberExpressionContinuation(Expression* expression,
- bool* ok) {
- // Parses this part of MemberExpression:
- // ('[' Expression ']' | '.' Identifier)*
- while (true) {
- switch (peek()) {
- case Token::LBRACK: {
- Consume(Token::LBRACK);
- int pos = position();
- Expression* index = ParseExpression(true, CHECK_OK);
- expression = factory()->NewProperty(expression, index, pos);
- if (fni_ != NULL) {
- if (index->IsPropertyName()) {
- fni_->PushLiteralName(index->AsLiteral()->AsPropertyName());
- } else {
- fni_->PushLiteralName(
- isolate()->factory()->anonymous_function_string());
- }
- }
- Expect(Token::RBRACK, CHECK_OK);
- break;
- }
- case Token::PERIOD: {
- Consume(Token::PERIOD);
- int pos = position();
- Handle<String> name = ParseIdentifierName(CHECK_OK);
- expression = factory()->NewProperty(
- expression, factory()->NewLiteral(name, pos), pos);
- if (fni_ != NULL) fni_->PushLiteralName(name);
- break;
- }
- default:
- return expression;
- }
- }
- ASSERT(false);
- return NULL;
-}
-
-
DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) {
// In ECMA-262 'debugger' is defined as a reserved keyword. In some browser
// contexts this is used as a statement which invokes the debugger as i a
« 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