Simplify preparsing of "new"-expressions.

Review URL: http://codereview.chromium.org/4331003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5764 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
lrn@chromium.org 2010-11-04 07:19:06 +00:00
parent 926bf7bc6b
commit 3c1c4ffb29
2 changed files with 13 additions and 27 deletions

View File

@ -186,8 +186,7 @@ class PreParser {
Expression ParseLeftHandSideExpression(bool* ok);
Expression ParseNewExpression(bool* ok);
Expression ParseMemberExpression(bool* ok);
Expression ParseNewPrefix(int* new_count, bool* ok);
Expression ParseMemberWithNewPrefixesExpression(int* new_count, bool* ok);
Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok);
Expression ParsePrimaryExpression(bool* ok);
Expression ParseArrayLiteral(bool* ok);
Expression ParseObjectLiteral(bool* ok);
@ -965,9 +964,8 @@ Expression PreParser<Scanner, Log>::ParseLeftHandSideExpression(bool* ok) {
}
template <typename Scanner, typename Log>
Expression PreParser<Scanner, Log>::ParseNewPrefix(int* new_count, bool* ok) {
Expression PreParser<Scanner, Log>::ParseNewExpression(bool* ok) {
// NewExpression ::
// ('new')+ MemberExpression
@ -979,38 +977,25 @@ Expression PreParser<Scanner, Log>::ParseNewPrefix(int* new_count, bool* ok) {
// many we have parsed. This information is then passed on to the
// member expression parser, which is only allowed to match argument
// lists as long as it has 'new' prefixes left
Expect(Token::NEW, CHECK_OK);
*new_count++;
unsigned new_count = 0;
do {
Consume(Token::NEW);
new_count++;
} while (peek() == Token::NEW);
if (peek() == Token::NEW) {
ParseNewPrefix(new_count, CHECK_OK);
} else {
ParseMemberWithNewPrefixesExpression(new_count, CHECK_OK);
}
if (*new_count > 0) {
*new_count--;
}
return kUnknownExpression;
}
template <typename Scanner, typename Log>
Expression PreParser<Scanner, Log>::ParseNewExpression(bool* ok) {
int new_count = 0;
return ParseNewPrefix(&new_count, ok);
return ParseMemberWithNewPrefixesExpression(new_count, ok);
}
template <typename Scanner, typename Log>
Expression PreParser<Scanner, Log>::ParseMemberExpression(bool* ok) {
return ParseMemberWithNewPrefixesExpression(NULL, ok);
return ParseMemberWithNewPrefixesExpression(0, ok);
}
template <typename Scanner, typename Log>
Expression PreParser<Scanner, Log>::ParseMemberWithNewPrefixesExpression(
int* new_count, bool* ok) {
unsigned new_count, bool* ok) {
// MemberExpression ::
// (PrimaryExpression | FunctionLiteral)
// ('[' Expression ']' | '.' Identifier | Arguments)*
@ -1051,10 +1036,10 @@ Expression PreParser<Scanner, Log>::ParseMemberWithNewPrefixesExpression(
break;
}
case Token::LPAREN: {
if ((new_count == NULL) || *new_count == 0) return result;
if (new_count == 0) return result;
// Consume one of the new prefixes (already parsed).
ParseArguments(CHECK_OK);
*new_count--;
new_count--;
result = kUnknownExpression;
break;
}

View File

@ -253,6 +253,7 @@ TEST(StandAlonePreParser) {
"var x = 42;",
"function foo(x, y) { return x + y; }",
"native function foo(); return %ArgleBargle(glop);",
"var x = new new Function('this.x = 42');",
NULL
};