Chromium Code Reviews| Index: src/parser.h |
| diff --git a/src/parser.h b/src/parser.h |
| index 39d0d9278b132fd4dfc5a9ebd104661f1f846205..69e305802c27d121c3c37370272f289a6ca664e6 100644 |
| --- a/src/parser.h |
| +++ b/src/parser.h |
| @@ -538,6 +538,28 @@ class RegExpParser BASE_EMBEDDED { |
| class Parser; |
| class SingletonLogger; |
| + |
| +struct ParserFormalParameterParsingState |
| + : public PreParserFormalParameterParsingState { |
| + struct Parameter { |
| + Parameter(Variable* var, Expression* pattern) |
| + : var(var), pattern(pattern) {} |
| + Variable* var; |
| + Expression* pattern; |
| + }; |
| + |
| + explicit ParserFormalParameterParsingState(Scope* scope) |
| + : PreParserFormalParameterParsingState(scope), params(4, scope->zone()) {} |
| + |
| + |
|
arv (Not doing code reviews)
2015/06/19 19:25:26
-1 newline
Dmitry Lomov (no reviews)
2015/06/22 10:14:10
Done.
|
| + ZoneList<Parameter> params; |
| + |
| + void AddParameter(Variable* var, Expression* pattern) { |
| + params.Add(Parameter(var, pattern), scope->zone()); |
| + } |
| +}; |
| + |
| + |
| class ParserTraits { |
| public: |
| struct Type { |
| @@ -560,7 +582,7 @@ class ParserTraits { |
| typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
| typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
| typedef const v8::internal::AstRawString* FormalParameter; |
| - typedef Scope FormalParameterScope; |
| + typedef ParserFormalParameterParsingState FormalParameterParsingState; |
| typedef ZoneList<v8::internal::Statement*>* StatementList; |
| // For constructing objects returned by the traversing functions. |
| @@ -751,17 +773,21 @@ class ParserTraits { |
| ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { |
| return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
| } |
| + |
| + V8_INLINE void AddParameterInitializationBlock( |
| + const ParserFormalParameterParsingState& formal_parameters, |
| + ZoneList<v8::internal::Statement*>* body, bool* ok); |
| + |
| V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, |
| FunctionKind kind = kNormalFunction); |
| - V8_INLINE void DeclareFormalParameter(Scope* scope, Expression* name, |
| - ExpressionClassifier* classifier, |
| - bool is_rest); |
| - void ParseArrowFunctionFormalParameters(Scope* scope, Expression* params, |
| - const Scanner::Location& params_loc, |
| - bool* has_rest, |
| - Scanner::Location* duplicate_loc, |
| - bool* ok); |
| + V8_INLINE void DeclareFormalParameter( |
| + ParserFormalParameterParsingState* parsing_state, Expression* name, |
| + ExpressionClassifier* classifier, bool is_rest); |
| + void ParseArrowFunctionFormalParameters( |
| + ParserFormalParameterParsingState* scope, Expression* params, |
| + const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
| + bool* ok); |
| // Temporary glue; these functions will move to ParserBase. |
| Expression* ParseV8Intrinsic(bool* ok); |
| @@ -774,8 +800,9 @@ class ParserTraits { |
| int* materialized_literal_count, int* expected_property_count, bool* ok, |
| Scanner::BookmarkScope* bookmark = nullptr); |
| V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( |
| - const AstRawString* name, int pos, Variable* fvar, |
| - Token::Value fvar_init_op, FunctionKind kind, bool* ok); |
| + const AstRawString* name, int pos, |
| + const ParserFormalParameterParsingState& formal_parameters, |
| + Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); |
| ClassLiteral* ParseClassLiteral(const AstRawString* name, |
| Scanner::Location class_name_location, |
| @@ -936,6 +963,7 @@ class Parser : public ParserBase<ParserTraits> { |
| bool* ok); |
| struct DeclarationDescriptor { |
| + enum Kind { NORMAL, PARAMETER }; |
| Parser* parser; |
| Scope* declaration_scope; |
| Scope* scope; |
| @@ -945,6 +973,7 @@ class Parser : public ParserBase<ParserTraits> { |
| int declaration_pos; |
| int initialization_pos; |
| Token::Value init_op; |
| + Kind declaration_kind; |
| }; |
| struct DeclarationParsingResult { |
| @@ -1095,7 +1124,9 @@ class Parser : public ParserBase<ParserTraits> { |
| // Parser support |
| VariableProxy* NewUnresolved(const AstRawString* name, VariableMode mode); |
| - Variable* Declare(Declaration* declaration, bool resolve, bool* ok); |
| + Variable* Declare(Declaration* declaration, |
| + DeclarationDescriptor::Kind declaration_kind, bool resolve, |
| + bool* ok); |
| bool TargetStackContainsLabel(const AstRawString* label); |
| BreakableStatement* LookupBreakTarget(const AstRawString* label, bool* ok); |
| @@ -1121,10 +1152,14 @@ class Parser : public ParserBase<ParserTraits> { |
| PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser( |
| SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr); |
| + Block* BuildParameterInitializationBlock( |
| + const ParserFormalParameterParsingState& formal_parameters, bool* ok); |
| + |
| // Consumes the ending }. |
| ZoneList<Statement*>* ParseEagerFunctionBody( |
| - const AstRawString* function_name, int pos, Variable* fvar, |
| - Token::Value fvar_init_op, FunctionKind kind, bool* ok); |
| + const AstRawString* function_name, int pos, |
| + const ParserFormalParameterParsingState& formal_parameters, |
| + Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); |
| void ThrowPendingError(Isolate* isolate, Handle<Script> script); |
| @@ -1188,10 +1223,11 @@ void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count, |
| ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody( |
| - const AstRawString* name, int pos, Variable* fvar, |
| + const AstRawString* name, int pos, |
| + const ParserFormalParameterParsingState& formal_parameters, Variable* fvar, |
| Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
| - return parser_->ParseEagerFunctionBody(name, pos, fvar, fvar_init_op, kind, |
| - ok); |
| + return parser_->ParseEagerFunctionBody(name, pos, formal_parameters, fvar, |
| + fvar_init_op, kind, ok); |
| } |
| void ParserTraits::CheckConflictingVarDeclarations(v8::internal::Scope* scope, |
| @@ -1270,18 +1306,20 @@ Expression* ParserTraits::SpreadCallNew( |
| } |
| -void ParserTraits::DeclareFormalParameter(Scope* scope, Expression* pattern, |
| - ExpressionClassifier* classifier, |
| - bool is_rest) { |
| +void ParserTraits::DeclareFormalParameter( |
| + ParserFormalParameterParsingState* parsing_state, Expression* pattern, |
| + ExpressionClassifier* classifier, bool is_rest) { |
| bool is_duplicate = false; |
| - if (!pattern->IsVariableProxy()) { |
| - // TODO(dslomov): implement. |
| - DCHECK(parser_->allow_harmony_destructuring()); |
| - return; |
| - } |
| - auto name = pattern->AsVariableProxy()->raw_name(); |
| - Variable* var = scope->DeclareParameter(name, VAR, is_rest, &is_duplicate); |
| - if (is_sloppy(scope->language_mode())) { |
| + bool is_simple_name = pattern->IsVariableProxy(); |
| + DCHECK(parser_->allow_harmony_destructuring() || is_simple_name); |
| + |
| + const AstRawString* name = is_simple_name |
| + ? pattern->AsVariableProxy()->raw_name() |
| + : parser_->ast_value_factory()->empty_string(); |
| + Variable* var = |
| + parsing_state->scope->DeclareParameter(name, VAR, is_rest, &is_duplicate); |
| + parsing_state->AddParameter(var, is_simple_name ? nullptr : pattern); |
| + if (is_sloppy(parsing_state->scope->language_mode())) { |
| // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
| // conservative approximation necessary to account for parameters |
| // that are assigned via the arguments array. |
| @@ -1292,6 +1330,18 @@ void ParserTraits::DeclareFormalParameter(Scope* scope, Expression* pattern, |
| parser_->scanner()->location()); |
| } |
| } |
| + |
| + |
| +void ParserTraits::AddParameterInitializationBlock( |
| + const ParserFormalParameterParsingState& formal_parameters, |
| + ZoneList<v8::internal::Statement*>* body, bool* ok) { |
| + auto* init_block = |
| + parser_->BuildParameterInitializationBlock(formal_parameters, ok); |
| + if (!*ok) return; |
| + if (init_block != nullptr) { |
| + body->Add(init_block, parser_->zone()); |
| + } |
| +} |
| } } // namespace v8::internal |
| #endif // V8_PARSER_H_ |