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

Unified Diff: src/preparser.h

Issue 4331003: Simplify preparsing of "new"-expressions. (Closed)
Patch Set: Created 10 years, 1 month 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/cctest/test-parsing.cc » ('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 697ef6ecc8123850fd8470e881a0e5c914bdf0d7..4b236c9dacac235be191e53d7217b12a3c18b64d 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -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++;
-
- if (peek() == Token::NEW) {
- ParseNewPrefix(new_count, CHECK_OK);
- } else {
- ParseMemberWithNewPrefixesExpression(new_count, CHECK_OK);
- }
-
- if (*new_count > 0) {
- *new_count--;
- }
- return kUnknownExpression;
-}
-
+ unsigned new_count = 0;
+ do {
+ Consume(Token::NEW);
+ new_count++;
+ } while (peek() == Token::NEW);
-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;
}
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698