| Index: src/parser.h
|
| diff --git a/src/parser.h b/src/parser.h
|
| index 2b0a4d92211a4e119f15e36164ad1aaf3cdd7432..d7830f630a58aca5bc996d2a7e4a0a20136537b0 100644
|
| --- a/src/parser.h
|
| +++ b/src/parser.h
|
| @@ -869,7 +869,6 @@ class Parser : public ParserBase<ParserTraits> {
|
|
|
| private:
|
| friend class ParserTraits;
|
| - class PatternRewriter;
|
|
|
| // Limit the allowed number of local variables in a function. The hard limit
|
| // is that offsets computed by FullCodeGenerator::StackOperand and similar
|
| @@ -938,12 +937,109 @@ class Parser : public ParserBase<ParserTraits> {
|
| Block* ParseVariableStatement(VariableDeclarationContext var_context,
|
| ZoneList<const AstRawString*>* names,
|
| bool* ok);
|
| - Block* ParseVariableDeclarations(VariableDeclarationContext var_context,
|
| - int* num_decl,
|
| - ZoneList<const AstRawString*>* names,
|
| - const AstRawString** out,
|
| - Scanner::Location* first_initializer_loc,
|
| - Scanner::Location* bindings_loc, bool* ok);
|
| +
|
| + struct DeclarationDescriptor {
|
| + Parser* parser;
|
| + Scope* declaration_scope;
|
| + Scope* scope;
|
| + VariableMode mode;
|
| + bool is_const;
|
| + bool needs_init;
|
| + int pos;
|
| + Token::Value init_op;
|
| + };
|
| +
|
| +
|
| + class PatternRewriter : private AstVisitor {
|
| + public:
|
| + explicit PatternRewriter(Expression* pattern)
|
| + : pattern_(pattern),
|
| + initializer_position_(RelocInfo::kNoPosition),
|
| + state_(nullptr) {}
|
| +
|
| + PatternRewriter()
|
| + : pattern_(nullptr),
|
| + initializer_position_(RelocInfo::kNoPosition),
|
| + state_(nullptr) {}
|
| +
|
| + PatternRewriter(const PatternRewriter& other)
|
| + : AstVisitor(other),
|
| + pattern_(other.pattern_),
|
| + initializer_position_(other.initializer_position_),
|
| + state_(nullptr) {}
|
| +
|
| + bool IsSingleVariableBinding() const;
|
| + const AstRawString* SingleName() const;
|
| +
|
| + void DeclareAndInitializeVariables(Block* block,
|
| + const DeclarationDescriptor* decl,
|
| + Expression* value,
|
| + ZoneList<const AstRawString*>* names,
|
| + bool* ok);
|
| +
|
| + void set_initializer_position(int pos) { initializer_position_ = pos; }
|
| +
|
| + private:
|
| + // Group all state local to visting AST.
|
| + struct VisitorState {
|
| + Block* block;
|
| + const DeclarationDescriptor* decl;
|
| + ZoneList<const AstRawString*>* names;
|
| + Expression* current_value;
|
| + bool* ok;
|
| + };
|
| +
|
| +#define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override;
|
| + // Visiting functions for AST nodes make this an AstVisitor.
|
| + AST_NODE_LIST(DECLARE_VISIT)
|
| +#undef DECLARE_VISIT
|
| + virtual void Visit(AstNode* node) override;
|
| +
|
| + void RecurseIntoSubpattern(AstNode* pattern, Expression* value) {
|
| + Expression* old_value = state_->current_value;
|
| + state_->current_value = value;
|
| + pattern->Accept(this);
|
| + state_->current_value = old_value;
|
| + }
|
| +
|
| + AstNodeFactory* factory() const { return state_->decl->parser->factory(); }
|
| + AstValueFactory* ast_value_factory() const {
|
| + return state_->decl->parser->ast_value_factory();
|
| + }
|
| + bool inside_with() const { return state_->decl->parser->inside_with(); }
|
| + Zone* zone() const { return state_->decl->parser->zone(); }
|
| +
|
| + Expression* pattern_;
|
| + int initializer_position_;
|
| +
|
| + VisitorState* state_;
|
| + };
|
| +
|
| + struct DeclarationParsingResult {
|
| + struct Declaration {
|
| + Declaration(const PatternRewriter& p, Expression* initializer)
|
| + : pattern(p), initializer(initializer) {}
|
| +
|
| + PatternRewriter pattern;
|
| + Expression* initializer;
|
| + };
|
| +
|
| + DeclarationParsingResult()
|
| + : declarations(4),
|
| + out(nullptr),
|
| + first_initializer_loc(Scanner::Location::invalid()),
|
| + bindings_loc(Scanner::Location::invalid()) {}
|
| +
|
| + DeclarationDescriptor decl;
|
| + List<Declaration> declarations;
|
| + const AstRawString* out;
|
| + Scanner::Location first_initializer_loc;
|
| + Scanner::Location bindings_loc;
|
| + };
|
| +
|
| + void ParseVariableDeclarations(VariableDeclarationContext var_context,
|
| + DeclarationParsingResult* parsing_result,
|
| + bool* ok);
|
| Statement* ParseExpressionOrLabelledStatement(
|
| ZoneList<const AstRawString*>* labels, bool* ok);
|
| IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels,
|
|
|