Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index 501ed71ae6000ccdd49f4c9d82b0cc2f0b3ff059..a4a7e3bdf3250dce0ed344626a9f96e7444d920a 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -343,6 +343,7 @@ class ParserBase : public Traits { |
| typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok); |
| typename Traits::Type::Expression ParseArrayLiteral(bool* ok); |
| typename Traits::Type::Expression ParseObjectLiteral(bool* ok); |
| + typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
| // Used to detect duplicates in object literals. Each of the values |
| // kGetterProperty, kSetterProperty and kValueProperty represents |
| @@ -557,8 +558,12 @@ class PreParserExpression { |
| class PreParserExpressionList { |
| public: |
| // These functions make list->Add(some_expression) work (and do nothing). |
| + PreParserExpressionList() : length_(0) {} |
| PreParserExpressionList* operator->() { return this; } |
| - void Add(PreParserExpression, void*) { } |
| + void Add(PreParserExpression, void*) { ++length_; } |
| + int length() const { return length_; } |
| + private: |
| + int length_; |
| }; |
| @@ -730,6 +735,9 @@ class PreParserTraits { |
| static PreParserExpression EmptyLiteral() { |
| return PreParserExpression::Default(); |
| } |
| + static PreParserExpressionList NullExpressionList() { |
| + return PreParserExpressionList(); |
| + } |
| // Odd-ball literal creators. |
| static PreParserExpression GetLiteralTheHole(int position, |
| @@ -920,8 +928,6 @@ class PreParser : public ParserBase<PreParserTraits> { |
| kUnknownSourceElements |
| }; |
| - typedef int Arguments; |
| - |
| // All ParseXXX functions take as the last argument an *ok parameter |
| // which is set to false if parsing failed; it is unchanged otherwise. |
| // By making the 'exception handling' explicit, we are forced to check |
| @@ -965,7 +971,6 @@ class PreParser : public ParserBase<PreParserTraits> { |
| Expression ParseObjectLiteral(bool* ok); |
| Expression ParseV8Intrinsic(bool* ok); |
| - Arguments ParseArguments(bool* ok); |
| Expression ParseFunctionLiteral( |
| Identifier name, |
| Scanner::Location function_name_location, |
| @@ -1163,6 +1168,13 @@ ParserBase<Traits>::ParseRegExpLiteral(bool seen_equal, bool* ok) { |
| #define DUMMY ) // to make indentation work |
| #undef DUMMY |
| +// Used in functions where the return type is not Traits::Type::Expression. |
| +#define CHECK_OK_CUSTOM(x) ok); \ |
| + if (!*ok) return this->x(); \ |
| + ((void)0 |
| +#define DUMMY ) // to make indentation work |
| +#undef DUMMY |
| + |
| template <class Traits> |
| typename Traits::Type::Expression ParserBase<Traits>::ParsePrimaryExpression( |
| bool* ok) { |
| @@ -1467,8 +1479,36 @@ typename Traits::Type::Expression ParserBase<Traits>::ParseObjectLiteral( |
| } |
| +template <class Traits> |
| +typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( |
| + bool* ok) { |
| + // Arguments :: |
| + // '(' (AssignmentExpression)*[','] ')' |
| + |
| + typename Traits::Type::ExpressionList result = |
| + this->NewExpressionList(4, zone_); |
| + Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
| + bool done = (peek() == Token::RPAREN); |
| + while (!done) { |
| + typename Traits::Type::Expression argument = |
| + this->ParseAssignmentExpression(true, |
| + CHECK_OK_CUSTOM(NullExpressionList)); |
| + result->Add(argument, zone_); |
| + if (result->length() > Code::kMaxArguments) { |
| + ReportMessageAt(scanner()->location(), "too_many_arguments"); |
| + *ok = false; |
| + return this->NullExpressionList(); |
| + } |
| + done = (peek() == Token::RPAREN); |
| + if (!done) Expect(Token::COMMA, CHECK_OK_CUSTOM(NullExpressionList)); |
|
ulan
2014/03/11 15:39:59
As discussed offline, it is probably worth putting
marja
2014/03/11 15:49:10
Done.
|
| + } |
| + Expect(Token::RPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
| + return result; |
| +} |
| + |
| #undef CHECK_OK |
| +#undef CHECK_OK_CUSTOM |
| template <typename Traits> |