diff options
Diffstat (limited to 'deps/v8/src/parser.h')
-rw-r--r-- | deps/v8/src/parser.h | 131 |
1 files changed, 75 insertions, 56 deletions
diff --git a/deps/v8/src/parser.h b/deps/v8/src/parser.h index 94aa28a1f9..a0be1dfe7e 100644 --- a/deps/v8/src/parser.h +++ b/deps/v8/src/parser.h @@ -104,9 +104,6 @@ class ParseInfo { ast_value_factory_ = ast_value_factory; } - FunctionLiteral* function() { // TODO(titzer): temporary name adapter - return literal_; - } FunctionLiteral* literal() { return literal_; } void set_literal(FunctionLiteral* literal) { literal_ = literal; } @@ -539,23 +536,24 @@ class Parser; class SingletonLogger; -struct ParserFormalParameterParsingState - : public PreParserFormalParameterParsingState { +struct ParserFormalParameters : FormalParametersBase { struct Parameter { - Parameter(Variable* var, Expression* pattern) - : var(var), pattern(pattern) {} - Variable* var; + Parameter(const AstRawString* name, Expression* pattern, + Expression* initializer, bool is_rest) + : name(name), pattern(pattern), initializer(initializer), + is_rest(is_rest) {} + const AstRawString* name; Expression* pattern; + Expression* initializer; + bool is_rest; }; - explicit ParserFormalParameterParsingState(Scope* scope) - : PreParserFormalParameterParsingState(scope), params(4, scope->zone()) {} - + explicit ParserFormalParameters(Scope* scope) + : FormalParametersBase(scope), params(4, scope->zone()) {} ZoneList<Parameter> params; - void AddParameter(Variable* var, Expression* pattern) { - params.Add(Parameter(var, pattern), scope->zone()); - } + int Arity() const { return params.length(); } + const Parameter& at(int i) const { return params[i]; } }; @@ -580,8 +578,8 @@ class ParserTraits { typedef ObjectLiteral::Property* ObjectLiteralProperty; typedef ZoneList<v8::internal::Expression*>* ExpressionList; typedef ZoneList<ObjectLiteral::Property*>* PropertyList; - typedef const v8::internal::AstRawString* FormalParameter; - typedef ParserFormalParameterParsingState FormalParameterParsingState; + typedef ParserFormalParameters::Parameter FormalParameter; + typedef ParserFormalParameters FormalParameters; typedef ZoneList<v8::internal::Statement*>* StatementList; // For constructing objects returned by the traversing functions. @@ -774,27 +772,34 @@ class ParserTraits { } V8_INLINE void AddParameterInitializationBlock( - const ParserFormalParameterParsingState& formal_parameters, + const ParserFormalParameters& parameters, ZoneList<v8::internal::Statement*>* body, bool* ok); V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, FunctionKind kind = kNormalFunction); + V8_INLINE void AddFormalParameter( + ParserFormalParameters* parameters, Expression* pattern, + Expression* initializer, bool is_rest); V8_INLINE void DeclareFormalParameter( - ParserFormalParameterParsingState* parsing_state, Expression* name, - ExpressionClassifier* classifier, bool is_rest); + Scope* scope, const ParserFormalParameters::Parameter& parameter, + bool is_simple, ExpressionClassifier* classifier); void ParseArrowFunctionFormalParameters( - ParserFormalParameterParsingState* scope, Expression* params, - const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, - bool* ok); + ParserFormalParameters* parameters, Expression* params, + const Scanner::Location& params_loc, + Scanner::Location* duplicate_loc, bool* ok); + void ParseArrowFunctionFormalParameterList( + ParserFormalParameters* parameters, Expression* params, + const Scanner::Location& params_loc, + Scanner::Location* duplicate_loc, bool* ok); - void ReindexLiterals(const ParserFormalParameterParsingState& parsing_state); + void ReindexLiterals(const ParserFormalParameters& parameters); // Temporary glue; these functions will move to ParserBase. Expression* ParseV8Intrinsic(bool* ok); FunctionLiteral* ParseFunctionLiteral( const AstRawString* name, Scanner::Location function_name_location, - bool name_is_strict_reserved, FunctionKind kind, + FunctionNameValidity function_name_validity, FunctionKind kind, int function_token_position, FunctionLiteral::FunctionType type, FunctionLiteral::ArityRestriction arity_restriction, LanguageMode language_mode, bool* ok); @@ -803,8 +808,8 @@ class ParserTraits { Scanner::BookmarkScope* bookmark = nullptr); V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( const AstRawString* name, int pos, - const ParserFormalParameterParsingState& formal_parameters, - Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); + const ParserFormalParameters& parameters, FunctionKind kind, + FunctionLiteral::FunctionType function_type, bool* ok); ClassLiteral* ParseClassLiteral(const AstRawString* name, Scanner::Location class_name_location, @@ -1097,7 +1102,7 @@ class Parser : public ParserBase<ParserTraits> { FunctionLiteral* ParseFunctionLiteral( const AstRawString* name, Scanner::Location function_name_location, - bool name_is_strict_reserved, FunctionKind kind, + FunctionNameValidity function_name_validity, FunctionKind kind, int function_token_position, FunctionLiteral::FunctionType type, FunctionLiteral::ArityRestriction arity_restriction, LanguageMode language_mode, bool* ok); @@ -1156,13 +1161,13 @@ class Parser : public ParserBase<ParserTraits> { SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr); Block* BuildParameterInitializationBlock( - const ParserFormalParameterParsingState& formal_parameters, bool* ok); + const ParserFormalParameters& parameters, bool* ok); // Consumes the ending }. ZoneList<Statement*>* ParseEagerFunctionBody( const AstRawString* function_name, int pos, - const ParserFormalParameterParsingState& formal_parameters, - Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); + const ParserFormalParameters& parameters, FunctionKind kind, + FunctionLiteral::FunctionType function_type, bool* ok); void ThrowPendingError(Isolate* isolate, Handle<Script> script); @@ -1226,11 +1231,10 @@ void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count, ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody( - 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, formal_parameters, fvar, - fvar_init_op, kind, ok); + const AstRawString* name, int pos, const ParserFormalParameters& parameters, + FunctionKind kind, FunctionLiteral::FunctionType function_type, bool* ok) { + return parser_->ParseEagerFunctionBody(name, pos, parameters, kind, + function_type, ok); } void ParserTraits::CheckConflictingVarDeclarations(v8::internal::Scope* scope, @@ -1309,40 +1313,55 @@ Expression* ParserTraits::SpreadCallNew( } -void ParserTraits::DeclareFormalParameter( - ParserFormalParameterParsingState* parsing_state, Expression* pattern, - ExpressionClassifier* classifier, bool is_rest) { - bool is_duplicate = false; - bool is_simple_name = pattern->IsVariableProxy(); - DCHECK(parser_->allow_harmony_destructuring() || is_simple_name); - - const AstRawString* name = is_simple_name +void ParserTraits::AddFormalParameter( + ParserFormalParameters* parameters, + Expression* pattern, Expression* initializer, bool is_rest) { + bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; + DCHECK(parser_->allow_harmony_destructuring() || + parser_->allow_harmony_rest_parameters() || + parser_->allow_harmony_default_parameters() || is_simple); + const AstRawString* name = is_simple ? pattern->AsVariableProxy()->raw_name() : parser_->ast_value_factory()->empty_string(); + parameters->params.Add( + ParserFormalParameters::Parameter(name, pattern, initializer, is_rest), + parameters->scope->zone()); +} + + +void ParserTraits::DeclareFormalParameter( + Scope* scope, const ParserFormalParameters::Parameter& parameter, + bool is_simple, ExpressionClassifier* classifier) { + bool is_duplicate = false; + // TODO(caitp): Remove special handling for rest once desugaring is in. + auto name = is_simple || parameter.is_rest + ? parameter.name : parser_->ast_value_factory()->empty_string(); + auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; 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())) { + scope->DeclareParameter(name, mode, parameter.is_rest, &is_duplicate); + if (is_duplicate) { + classifier->RecordDuplicateFormalParameterError( + parser_->scanner()->location()); + } + if (is_sloppy(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. var->set_maybe_assigned(); } - if (is_duplicate) { - classifier->RecordDuplicateFormalParameterError( - parser_->scanner()->location()); - } } void ParserTraits::AddParameterInitializationBlock( - const ParserFormalParameterParsingState& formal_parameters, + const ParserFormalParameters& 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()); + if (!parameters.is_simple) { + auto* init_block = + parser_->BuildParameterInitializationBlock(parameters, ok); + if (!*ok) return; + if (init_block != nullptr) { + body->Add(init_block, parser_->zone()); + } } } } } // namespace v8::internal |