Commit 7f5c864a authored by nikolaos's avatar nikolaos Committed by Commit bot

This patch implements an alternative approach to the rewriting

of non-pattern expressions, according to the (internally circulated)
design document.  Details to be provided here.

1.  RewritableAssignmentExpression has been renamed to RewritableExpression.
    It is a wrapper for AST nodes that wait for some potential rewriting
    (that may or may not happen).  Also, Is... and As... macros now see
    through RewritableExpressions.

2.  The function state keeps a list of rewritable expressions that must be
    rewritten only if they are used as non-pattern expressions.

3.  Expression classifiers are now templates, parameterized by parser
    traits.  They keep some additional state: a pointer to the list of
    non-pattern rewritable expressions.  It is important that expression
    classifiers be used strictly in a stack fashion, from now on.

4.  The RewriteNonPattern function has been simplified.

BUG=chromium:579913
LOG=N

Review URL: https://codereview.chromium.org/1702063002

Cr-Commit-Position: refs/heads/master@{#34154}
parent 0fbe943e
......@@ -398,10 +398,10 @@ void AstExpressionRewriter::VisitDoExpression(DoExpression* node) {
}
void AstExpressionRewriter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
void AstExpressionRewriter::VisitRewritableExpression(
RewritableExpression* node) {
REWRITE_THIS(node);
AST_REWRITE_PROPERTY(Expression, node, expression);
AST_REWRITE(Expression, node->expression(), node->Rewrite(replacement));
}
......
......@@ -400,8 +400,8 @@ void AstExpressionVisitor::VisitSuperCallReference(SuperCallReference* expr) {
}
void AstExpressionVisitor::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
void AstExpressionVisitor::VisitRewritableExpression(
RewritableExpression* expr) {
VisitExpression(expr);
RECURSE(Visit(expr->expression()));
}
......
......@@ -77,8 +77,8 @@ void AstLiteralReindexer::VisitSuperCallReference(SuperCallReference* node) {
}
void AstLiteralReindexer::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
void AstLiteralReindexer::VisitRewritableExpression(
RewritableExpression* node) {
Visit(node->expression());
}
......
......@@ -554,10 +554,10 @@ void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) {
}
void AstNumberingVisitor::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
void AstNumberingVisitor::VisitRewritableExpression(
RewritableExpression* node) {
IncrementNodeCount();
node->set_base_id(ReserveIdRange(RewritableAssignmentExpression::num_ids()));
node->set_base_id(ReserveIdRange(RewritableExpression::num_ids()));
Visit(node->expression());
}
......
......@@ -91,7 +91,7 @@ namespace internal {
V(CaseClause) \
V(EmptyParentheses) \
V(DoExpression) \
V(RewritableAssignmentExpression)
V(RewritableExpression)
#define AST_NODE_LIST(V) \
DECLARATION_NODE_LIST(V) \
......@@ -205,13 +205,9 @@ class AstNode: public ZoneObject {
// Type testing & conversion functions overridden by concrete subclasses.
#define DECLARE_NODE_FUNCTIONS(type) \
bool Is##type() const { return node_type() == AstNode::k##type; } \
type* As##type() { \
return Is##type() ? reinterpret_cast<type*>(this) : NULL; \
} \
const type* As##type() const { \
return Is##type() ? reinterpret_cast<const type*>(this) : NULL; \
}
V8_INLINE bool Is##type() const; \
V8_INLINE type* As##type(); \
V8_INLINE const type* As##type() const;
AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
#undef DECLARE_NODE_FUNCTIONS
......@@ -2486,18 +2482,32 @@ class Assignment final : public Expression {
};
class RewritableAssignmentExpression : public Expression {
// The RewritableExpression class is a wrapper for AST nodes that wait
// for some potential rewriting. However, even if such nodes are indeed
// rewritten, the RewritableExpression wrapper nodes will survive in the
// final AST and should be just ignored, i.e., they should be treated as
// equivalent to the wrapped nodes. For this reason and to simplify later
// phases, RewritableExpressions are considered as exceptions of AST nodes
// in the following sense:
//
// 1. IsRewritableExpression and AsRewritableExpression behave as usual.
// 2. All other Is* and As* methods are practically delegated to the
// wrapped node, i.e. IsArrayLiteral() will return true iff the
// wrapped node is an array literal.
//
// Furthermore, an invariant that should be respected is that the wrapped
// node is not a RewritableExpression.
class RewritableExpression : public Expression {
public:
DECLARE_NODE_TYPE(RewritableAssignmentExpression)
DECLARE_NODE_TYPE(RewritableExpression)
Expression* expression() { return expr_; }
Expression* expression() const { return expr_; }
bool is_rewritten() const { return is_rewritten_; }
void set_expression(Expression* e) { expr_ = e; }
void Rewrite(Expression* new_expression) {
DCHECK(!is_rewritten());
DCHECK_NOT_NULL(new_expression);
DCHECK(!new_expression->IsRewritableExpression());
expr_ = new_expression;
is_rewritten_ = true;
}
......@@ -2505,10 +2515,12 @@ class RewritableAssignmentExpression : public Expression {
static int num_ids() { return parent_num_ids(); }
protected:
RewritableAssignmentExpression(Zone* zone, Expression* expression)
RewritableExpression(Zone* zone, Expression* expression)
: Expression(zone, expression->position()),
is_rewritten_(false),
expr_(expression) {}
expr_(expression) {
DCHECK(!expression->IsRewritableExpression());
}
private:
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
......@@ -3365,12 +3377,9 @@ class AstNodeFactory final BASE_EMBEDDED {
local_zone_, condition, then_expression, else_expression, position);
}
RewritableAssignmentExpression* NewRewritableAssignmentExpression(
Expression* expression) {
RewritableExpression* NewRewritableExpression(Expression* expression) {
DCHECK_NOT_NULL(expression);
DCHECK(expression->IsAssignment());
return new (local_zone_)
RewritableAssignmentExpression(local_zone_, expression);
return new (local_zone_) RewritableExpression(local_zone_, expression);
}
Assignment* NewAssignment(Token::Value op,
......@@ -3508,6 +3517,46 @@ class AstNodeFactory final BASE_EMBEDDED {
};
// Type testing & conversion functions overridden by concrete subclasses.
// Inline functions for AstNode.
#define DECLARE_NODE_FUNCTIONS(type) \
bool AstNode::Is##type() const { \
NodeType mine = node_type(); \
if (mine == AstNode::kRewritableExpression && \
AstNode::k##type != AstNode::kRewritableExpression) \
mine = reinterpret_cast<const RewritableExpression*>(this) \
->expression() \
->node_type(); \
return mine == AstNode::k##type; \
} \
type* AstNode::As##type() { \
NodeType mine = node_type(); \
AstNode* result = this; \
if (mine == AstNode::kRewritableExpression && \
AstNode::k##type != AstNode::kRewritableExpression) { \
result = \
reinterpret_cast<const RewritableExpression*>(this)->expression(); \
mine = result->node_type(); \
} \
return mine == AstNode::k##type ? reinterpret_cast<type*>(result) : NULL; \
} \
const type* AstNode::As##type() const { \
NodeType mine = node_type(); \
const AstNode* result = this; \
if (mine == AstNode::kRewritableExpression && \
AstNode::k##type != AstNode::kRewritableExpression) { \
result = \
reinterpret_cast<const RewritableExpression*>(this)->expression(); \
mine = result->node_type(); \
} \
return mine == AstNode::k##type ? reinterpret_cast<const type*>(result) \
: NULL; \
}
AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
#undef DECLARE_NODE_FUNCTIONS
} // namespace internal
} // namespace v8
......
......@@ -412,8 +412,7 @@ void CallPrinter::VisitSuperCallReference(SuperCallReference* node) {
}
void CallPrinter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
void CallPrinter::VisitRewritableExpression(RewritableExpression* node) {
Find(node->expression());
}
......@@ -929,8 +928,7 @@ void PrettyPrinter::VisitSuperCallReference(SuperCallReference* node) {
}
void PrettyPrinter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
void PrettyPrinter::VisitRewritableExpression(RewritableExpression* node) {
Visit(node->expression());
}
......@@ -1705,8 +1703,7 @@ void AstPrinter::VisitSuperCallReference(SuperCallReference* node) {
}
void AstPrinter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
void AstPrinter::VisitRewritableExpression(RewritableExpression* node) {
Visit(node->expression());
}
......
......@@ -3062,8 +3062,7 @@ VectorSlotPair AstGraphBuilder::CreateVectorSlotPair(
}
void AstGraphBuilder::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
void AstGraphBuilder::VisitRewritableExpression(RewritableExpression* node) {
Visit(node->expression());
}
......
......@@ -287,8 +287,7 @@ void ALAA::VisitCountOperation(CountOperation* e) {
}
void ALAA::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
void ALAA::VisitRewritableExpression(RewritableExpression* expr) {
Visit(expr->expression());
}
......
......@@ -12194,8 +12194,8 @@ void HOptimizedGraphBuilder::VisitExportDeclaration(
}
void HOptimizedGraphBuilder::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
void HOptimizedGraphBuilder::VisitRewritableExpression(
RewritableExpression* node) {
CHECK_ALIVE(Visit(node->expression()));
}
......
......@@ -770,8 +770,7 @@ void AstTyper::VisitSuperPropertyReference(SuperPropertyReference* expr) {}
void AstTyper::VisitSuperCallReference(SuperCallReference* expr) {}
void AstTyper::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
void AstTyper::VisitRewritableExpression(RewritableExpression* expr) {
Visit(expr->expression());
}
......
......@@ -1507,8 +1507,7 @@ void FullCodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) {
}
void FullCodeGenerator::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
void FullCodeGenerator::VisitRewritableExpression(RewritableExpression* expr) {
Visit(expr->expression());
}
......
......@@ -2860,8 +2860,7 @@ void BytecodeGenerator::VisitLogicalAndExpression(BinaryOperation* binop) {
}
void BytecodeGenerator::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
void BytecodeGenerator::VisitRewritableExpression(RewritableExpression* expr) {
Visit(expr->expression());
}
......
......@@ -13,6 +13,7 @@ namespace v8 {
namespace internal {
template <typename Traits>
class ExpressionClassifier {
public:
struct Error {
......@@ -55,15 +56,25 @@ class ExpressionClassifier {
enum FunctionProperties { NonSimpleParameter = 1 << 0 };
ExpressionClassifier()
: invalid_productions_(0),
explicit ExpressionClassifier(const Traits* t)
: zone_(t->zone()),
non_patterns_to_rewrite_(t->GetNonPatternList()),
invalid_productions_(0),
function_properties_(0),
duplicate_finder_(nullptr) {}
duplicate_finder_(nullptr) {
non_pattern_begin_ = non_patterns_to_rewrite_->length();
}
explicit ExpressionClassifier(DuplicateFinder* duplicate_finder)
: invalid_productions_(0),
ExpressionClassifier(const Traits* t, DuplicateFinder* duplicate_finder)
: zone_(t->zone()),
non_patterns_to_rewrite_(t->GetNonPatternList()),
invalid_productions_(0),
function_properties_(0),
duplicate_finder_(duplicate_finder) {}
duplicate_finder_(duplicate_finder) {
non_pattern_begin_ = non_patterns_to_rewrite_->length();
}
~ExpressionClassifier() { Discard(); }
bool is_valid(unsigned productions) const {
return (invalid_productions_ & productions) == 0;
......@@ -281,12 +292,14 @@ class ExpressionClassifier {
assignment_pattern_error_ = Error();
}
void Accumulate(const ExpressionClassifier& inner,
unsigned productions = StandardProductions) {
void Accumulate(ExpressionClassifier* inner,
unsigned productions = StandardProductions,
bool merge_non_patterns = true) {
if (merge_non_patterns) MergeNonPatterns(inner);
// Propagate errors from inner, but don't overwrite already recorded
// errors.
unsigned non_arrow_inner_invalid_productions =
inner.invalid_productions_ & ~ArrowFormalParametersProduction;
inner->invalid_productions_ & ~ArrowFormalParametersProduction;
if (non_arrow_inner_invalid_productions == 0) return;
unsigned non_arrow_productions =
productions & ~ArrowFormalParametersProduction;
......@@ -296,27 +309,27 @@ class ExpressionClassifier {
if (errors != 0) {
invalid_productions_ |= errors;
if (errors & ExpressionProduction)
expression_error_ = inner.expression_error_;
expression_error_ = inner->expression_error_;
if (errors & FormalParameterInitializerProduction)
formal_parameter_initializer_error_ =
inner.formal_parameter_initializer_error_;
inner->formal_parameter_initializer_error_;
if (errors & BindingPatternProduction)
binding_pattern_error_ = inner.binding_pattern_error_;
binding_pattern_error_ = inner->binding_pattern_error_;
if (errors & AssignmentPatternProduction)
assignment_pattern_error_ = inner.assignment_pattern_error_;
assignment_pattern_error_ = inner->assignment_pattern_error_;
if (errors & DistinctFormalParametersProduction)
duplicate_formal_parameter_error_ =
inner.duplicate_formal_parameter_error_;
inner->duplicate_formal_parameter_error_;
if (errors & StrictModeFormalParametersProduction)
strict_mode_formal_parameter_error_ =
inner.strict_mode_formal_parameter_error_;
inner->strict_mode_formal_parameter_error_;
if (errors & StrongModeFormalParametersProduction)
strong_mode_formal_parameter_error_ =
inner.strong_mode_formal_parameter_error_;
inner->strong_mode_formal_parameter_error_;
if (errors & LetPatternProduction)
let_pattern_error_ = inner.let_pattern_error_;
let_pattern_error_ = inner->let_pattern_error_;
if (errors & CoverInitializedNameProduction)
cover_initialized_name_error_ = inner.cover_initialized_name_error_;
cover_initialized_name_error_ = inner->cover_initialized_name_error_;
}
// As an exception to the above, the result continues to be a valid arrow
......@@ -325,16 +338,31 @@ class ExpressionClassifier {
is_valid_arrow_formal_parameters()) {
// Also copy function properties if expecting an arrow function
// parameter.
function_properties_ |= inner.function_properties_;
function_properties_ |= inner->function_properties_;
if (!inner.is_valid_binding_pattern()) {
if (!inner->is_valid_binding_pattern()) {
invalid_productions_ |= ArrowFormalParametersProduction;
arrow_formal_parameters_error_ = inner.binding_pattern_error_;
arrow_formal_parameters_error_ = inner->binding_pattern_error_;
}
}
}
V8_INLINE int GetNonPatternBegin() const { return non_pattern_begin_; }
V8_INLINE void Discard() {
DCHECK_LE(non_pattern_begin_, non_patterns_to_rewrite_->length());
non_patterns_to_rewrite_->Rewind(non_pattern_begin_);
}
V8_INLINE void MergeNonPatterns(ExpressionClassifier* inner) {
DCHECK_LE(non_pattern_begin_, inner->non_pattern_begin_);
inner->non_pattern_begin_ = inner->non_patterns_to_rewrite_->length();
}
private:
Zone* zone_;
ZoneList<typename Traits::Type::Expression>* non_patterns_to_rewrite_;
int non_pattern_begin_;
unsigned invalid_productions_;
unsigned function_properties_;
Error expression_error_;
......@@ -350,6 +378,7 @@ class ExpressionClassifier {
DuplicateFinder* duplicate_finder_;
};
} // namespace internal
} // namespace v8
......
This diff is collapsed.
This diff is collapsed.
......@@ -335,6 +335,9 @@ class ParserTraits {
typedef v8::internal::AstProperties AstProperties;
typedef v8::internal::ExpressionClassifier<ParserTraits>
ExpressionClassifier;
// Return types for traversing functions.
typedef const AstRawString* Identifier;
typedef v8::internal::Expression* Expression;
......@@ -549,7 +552,7 @@ class ParserTraits {
int initializer_end_position, bool is_rest);
V8_INLINE void DeclareFormalParameter(
Scope* scope, const ParserFormalParameters::Parameter& parameter,
ExpressionClassifier* classifier);
Type::ExpressionClassifier* classifier);
void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters,
Expression* params,
const Scanner::Location& params_loc,
......@@ -643,6 +646,7 @@ class ParserTraits {
V8_INLINE void QueueDestructuringAssignmentForRewriting(
Expression* assignment);
V8_INLINE void QueueNonPatternForRewriting(Expression* expr);
void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
const AstRawString* name);
......@@ -651,11 +655,12 @@ class ParserTraits {
Expression* identifier);
// Rewrite expressions that are not used as patterns
V8_INLINE Expression* RewriteNonPattern(
Expression* expr, const ExpressionClassifier* classifier, bool* ok);
V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty(
ObjectLiteralProperty* property, const ExpressionClassifier* classifier,
bool* ok);
V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok);
V8_INLINE Zone* zone() const;
V8_INLINE ZoneList<Expression*>* GetNonPatternList() const;
Expression* RewriteYieldStar(
Expression* generator, Expression* expression, int pos);
......@@ -812,8 +817,9 @@ class Parser : public ParserBase<ParserTraits> {
const DeclarationParsingResult::Declaration* declaration,
ZoneList<const AstRawString*>* names, bool* ok);
static void RewriteDestructuringAssignment(
Parser* parser, RewritableAssignmentExpression* expr, Scope* Scope);
static void RewriteDestructuringAssignment(Parser* parser,
RewritableExpression* expr,
Scope* Scope);
static Expression* RewriteDestructuringAssignment(Parser* parser,
Assignment* assignment,
......@@ -1029,11 +1035,7 @@ class Parser : public ParserBase<ParserTraits> {
friend class NonPatternRewriter;
V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
V8_INLINE Expression* RewriteNonPattern(
Expression* expr, const ExpressionClassifier* classifier, bool* ok);
V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty(
ObjectLiteralProperty* property, const ExpressionClassifier* classifier,
bool* ok);
V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok);
friend class InitializerRewriter;
void RewriteParameterInitializer(Expression* expr, Scope* scope);
......@@ -1184,7 +1186,7 @@ void ParserTraits::AddFormalParameter(ParserFormalParameters* parameters,
void ParserTraits::DeclareFormalParameter(
Scope* scope, const ParserFormalParameters::Parameter& parameter,
ExpressionClassifier* classifier) {
Type::ExpressionClassifier* classifier) {
bool is_duplicate = false;
bool is_simple = classifier->is_simple_parameter_list();
auto name = is_simple || parameter.is_rest
......
......@@ -33,7 +33,7 @@ void Parser::PatternRewriter::DeclareAndInitializeVariables(
void Parser::PatternRewriter::RewriteDestructuringAssignment(
Parser* parser, RewritableAssignmentExpression* to_rewrite, Scope* scope) {
Parser* parser, RewritableExpression* to_rewrite, Scope* scope) {
PatternRewriter rewriter;
DCHECK(!to_rewrite->is_rewritten());
......@@ -58,8 +58,7 @@ Expression* Parser::PatternRewriter::RewriteDestructuringAssignment(
Parser* parser, Assignment* assignment, Scope* scope) {
DCHECK_NOT_NULL(assignment);
DCHECK_EQ(Token::ASSIGN, assignment->op());
auto to_rewrite =
parser->factory()->NewRewritableAssignmentExpression(assignment);
auto to_rewrite = parser->factory()->NewRewritableExpression(assignment);
RewriteDestructuringAssignment(parser, to_rewrite, scope);
return to_rewrite->expression();
}
......@@ -91,8 +90,8 @@ Parser::PatternRewriter::SetInitializerContextIfNeeded(Expression* node) {
// AssignmentElement nodes
PatternContext old_context = context();
bool is_destructuring_assignment =
node->IsRewritableAssignmentExpression() &&
!node->AsRewritableAssignmentExpression()->is_rewritten();
node->IsRewritableExpression() &&
!node->AsRewritableExpression()->is_rewritten();
bool is_assignment =
node->IsAssignment() && node->AsAssignment()->op() == Token::ASSIGN;
if (is_destructuring_assignment || is_assignment) {
......@@ -324,10 +323,11 @@ Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) {
}
void Parser::PatternRewriter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
if (!IsAssignmentContext()) {
// Mark the assignment as rewritten to prevent redundant rewriting, and
void Parser::PatternRewriter::VisitRewritableExpression(
RewritableExpression* node) {
// If this is not a destructuring assignment...
if (!IsAssignmentContext() || !node->expression()->IsAssignment()) {
// Mark the node as rewritten to prevent redundant rewriting, and
// perform BindingPattern rewriting
DCHECK(!node->is_rewritten());
node->Rewrite(node->expression());
......
......@@ -573,7 +573,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
int decl_pos = peek_position();
PreParserExpression pattern = PreParserExpression::Default();
{
ExpressionClassifier pattern_classifier;
ExpressionClassifier pattern_classifier(this);
Token::Value next = peek();
pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
......@@ -594,7 +594,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
Scanner::Location variable_loc = scanner()->location();
nvars++;
if (Check(Token::ASSIGN)) {
ExpressionClassifier classifier;
ExpressionClassifier classifier(this);
ParseAssignmentExpression(var_context != kForStatement, &classifier,
CHECK_OK);
ValidateExpression(&classifier, CHECK_OK);
......@@ -648,7 +648,7 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
IsClassConstructor(function_state_->kind())) {
bool is_this = peek() == Token::THIS;
Expression expr = Expression::Default();
ExpressionClassifier classifier;
ExpressionClassifier classifier(this);
if (is_this) {
expr = ParseStrongInitializationExpression(&classifier, CHECK_OK);
} else {
......@@ -684,7 +684,7 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
}
bool starts_with_identifier = peek_any_identifier();
ExpressionClassifier classifier;
ExpressionClassifier classifier(this);
Expression expr = ParseExpression(true, &classifier, CHECK_OK);
ValidateExpression(&classifier, CHECK_OK);
......@@ -937,10 +937,9 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
if (mode == ForEachStatement::ITERATE) {
ExpressionClassifier classifier;
Expression enumerable =
ParseAssignmentExpression(true, &classifier, CHECK_OK);
PreParserTraits::RewriteNonPattern(enumerable, &classifier, CHECK_OK);
ExpressionClassifier classifier(this);
ParseAssignmentExpression(true, &classifier, CHECK_OK);
RewriteNonPattern(&classifier, CHECK_OK);
} else {
ParseExpression(true, CHECK_OK);
}
......@@ -951,7 +950,7 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
} else {
int lhs_beg_pos = peek_position();
ExpressionClassifier classifier;
ExpressionClassifier classifier(this);
Expression lhs = ParseExpression(false, &classifier, CHECK_OK);
int lhs_end_pos = scanner()->location().end_pos;
is_let_identifier_expression =
......@@ -976,10 +975,9 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
if (mode == ForEachStatement::ITERATE) {
ExpressionClassifier classifier;
Expression enumerable =
ParseAssignmentExpression(true, &classifier, CHECK_OK);
PreParserTraits::RewriteNonPattern(enumerable, &classifier, CHECK_OK);
ExpressionClassifier classifier(this);
ParseAssignmentExpression(true, &classifier, CHECK_OK);
RewriteNonPattern(&classifier, CHECK_OK);
} else {
ParseExpression(true, CHECK_OK);
}
......@@ -1057,7 +1055,7 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
if (tok == Token::CATCH) {
Consume(Token::CATCH);
Expect(Token::LPAREN, CHECK_OK);
ExpressionClassifier pattern_classifier;
ExpressionClassifier pattern_classifier(this);
ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
ValidateBindingPattern(&pattern_classifier, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
......@@ -1114,7 +1112,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
FunctionState function_state(&function_state_, &scope_, function_scope, kind,
&factory);
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
ExpressionClassifier formals_classifier(&duplicate_finder);
ExpressionClassifier formals_classifier(this, &duplicate_finder);
Expect(Token::LPAREN, CHECK_OK);
int start_position = scanner()->location().beg_pos;
......@@ -1220,7 +1218,7 @@ PreParserExpression PreParser::ParseClassLiteral(
bool has_extends = Check(Token::EXTENDS);
if (has_extends) {
ExpressionClassifier classifier;
ExpressionClassifier classifier(this);
ParseLeftHandSideExpression(&classifier, CHECK_OK);
ValidateExpression(&classifier, CHECK_OK);
}
......@@ -1236,7 +1234,7 @@ PreParserExpression PreParser::ParseClassLiteral(
bool is_computed_name = false; // Classes do not care about computed
// property names here.
Identifier name;
ExpressionClassifier classifier;
ExpressionClassifier classifier(this);
ParsePropertyDefinition(&checker, in_class, has_extends, is_static,
&is_computed_name, &has_seen_constructor,
&classifier, &name, CHECK_OK);
......@@ -1260,7 +1258,7 @@ PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) {
// Allow "eval" or "arguments" for backward compatibility.
ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
Scanner::Location spread_pos;
ExpressionClassifier classifier;
ExpressionClassifier classifier(this);
ParseArguments(&spread_pos, &classifier, ok);
ValidateExpression(&classifier, CHECK_OK);
......
......@@ -197,8 +197,6 @@ class PreParserExpression {
ExpressionTypeField::decode(code_) == kAssignment;
}
bool IsRewritableAssignmentExpression() const { return IsAssignment(); }
bool IsObjectLiteral() const {
return TypeField::decode(code_) == kObjectLiteralExpression;
}
......@@ -487,8 +485,7 @@ class PreParserFactory {
PreParserExpression right, int pos) {
return PreParserExpression::Default();
}
PreParserExpression NewRewritableAssignmentExpression(
PreParserExpression expression) {
PreParserExpression NewRewritableExpression(PreParserExpression expression) {
return expression;
}
PreParserExpression NewAssignment(Token::Value op,
......@@ -589,6 +586,9 @@ class PreParserTraits {
typedef int AstProperties;
typedef v8::internal::ExpressionClassifier<PreParserTraits>
ExpressionClassifier;
// Return types for traversing functions.
typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression;
......@@ -885,7 +885,7 @@ class PreParserTraits {
++parameters->arity;
}
void DeclareFormalParameter(Scope* scope, PreParserIdentifier parameter,
ExpressionClassifier* classifier) {
Type::ExpressionClassifier* classifier) {
if (!classifier->is_simple_parameter_list()) {
scope->SetHasNonSimpleParameters();
}
......@@ -923,18 +923,18 @@ class PreParserTraits {
inline void RewriteDestructuringAssignments() {}
inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {}
inline void QueueNonPatternForRewriting(PreParserExpression) {}
void SetFunctionNameFromPropertyName(PreParserExpression,
PreParserIdentifier) {}
void SetFunctionNameFromIdentifierRef(PreParserExpression,
PreParserExpression) {}
inline PreParserExpression RewriteNonPattern(
PreParserExpression expr, const ExpressionClassifier* classifier,
bool* ok);
inline PreParserExpression RewriteNonPatternObjectLiteralProperty(
PreParserExpression property, const ExpressionClassifier* classifier,
bool* ok);
inline void RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok);
V8_INLINE Zone* zone() const;
V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const;
inline PreParserExpression RewriteYieldStar(
PreParserExpression generator, PreParserExpression expr, int pos);
......@@ -1119,19 +1119,19 @@ PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) {
}
PreParserExpression PreParserTraits::RewriteNonPattern(
PreParserExpression expr, const ExpressionClassifier* classifier,
bool* ok) {
void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok) {
pre_parser_->ValidateExpression(classifier, ok);
return expr;
}
PreParserExpression PreParserTraits::RewriteNonPatternObjectLiteralProperty(
PreParserExpression property, const ExpressionClassifier* classifier,
bool* ok) {
pre_parser_->ValidateExpression(classifier, ok);
return property;
Zone* PreParserTraits::zone() const {
return pre_parser_->function_state_->scope()->zone();
}
ZoneList<PreParserExpression>* PreParserTraits::GetNonPatternList() const {
return pre_parser_->function_state_->non_patterns_to_rewrite();
}
......
......@@ -1551,8 +1551,7 @@ void AsmTyper::VisitWithExpectation(Expression* expr, Type* expected_type,
}
void AsmTyper::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
void AsmTyper::VisitRewritableExpression(RewritableExpression* expr) {
RECURSE(Visit(expr->expression()));
}
......
......@@ -1177,10 +1177,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
void VisitDoExpression(DoExpression* expr) { UNREACHABLE(); }
void VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
UNREACHABLE();
}
void VisitRewritableExpression(RewritableExpression* expr) { UNREACHABLE(); }
struct IndexContainer : public ZoneObject {
uint16_t index;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment