Commit 5bb6b47b authored by machenbach's avatar machenbach Committed by Commit bot

Revert of Non-pattern rewriting revisited (patchset #3 id:40001 of...

Revert of Non-pattern rewriting revisited (patchset #3 id:40001 of https://codereview.chromium.org/1702063002/ )

Reason for revert:
[Sheriff] This makes jsfunfuzz unhappy:
https://build.chromium.org/p/client.v8/builders/V8%20Fuzzer/builds/7681

Original issue's description:
> 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
>
> Committed: https://crrev.com/7f5c864a6faf2b957b7273891e143b9bde35487c
> Cr-Commit-Position: refs/heads/master@{#34154}

TBR=rossberg@chromium.org,bmeurer@chromium.org,titzer@chromium.org,nikolaos@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=chromium:579913

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

Cr-Commit-Position: refs/heads/master@{#34158}
parent 915ae08d
......@@ -398,10 +398,10 @@ void AstExpressionRewriter::VisitDoExpression(DoExpression* node) {
}
void AstExpressionRewriter::VisitRewritableExpression(
RewritableExpression* node) {
void AstExpressionRewriter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
REWRITE_THIS(node);
AST_REWRITE(Expression, node->expression(), node->Rewrite(replacement));
AST_REWRITE_PROPERTY(Expression, node, expression);
}
......
......@@ -400,8 +400,8 @@ void AstExpressionVisitor::VisitSuperCallReference(SuperCallReference* expr) {
}
void AstExpressionVisitor::VisitRewritableExpression(
RewritableExpression* expr) {
void AstExpressionVisitor::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
VisitExpression(expr);
RECURSE(Visit(expr->expression()));
}
......
......@@ -77,8 +77,8 @@ void AstLiteralReindexer::VisitSuperCallReference(SuperCallReference* node) {
}
void AstLiteralReindexer::VisitRewritableExpression(
RewritableExpression* node) {
void AstLiteralReindexer::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
Visit(node->expression());
}
......
......@@ -554,10 +554,10 @@ void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) {
}
void AstNumberingVisitor::VisitRewritableExpression(
RewritableExpression* node) {
void AstNumberingVisitor::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
IncrementNodeCount();
node->set_base_id(ReserveIdRange(RewritableExpression::num_ids()));
node->set_base_id(ReserveIdRange(RewritableAssignmentExpression::num_ids()));
Visit(node->expression());
}
......
......@@ -91,7 +91,7 @@ namespace internal {
V(CaseClause) \
V(EmptyParentheses) \
V(DoExpression) \
V(RewritableExpression)
V(RewritableAssignmentExpression)
#define AST_NODE_LIST(V) \
DECLARATION_NODE_LIST(V) \
......@@ -205,9 +205,13 @@ class AstNode: public ZoneObject {
// Type testing & conversion functions overridden by concrete subclasses.
#define DECLARE_NODE_FUNCTIONS(type) \
V8_INLINE bool Is##type() const; \
V8_INLINE type* As##type(); \
V8_INLINE const type* As##type() const;
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; \
}
AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
#undef DECLARE_NODE_FUNCTIONS
......@@ -2482,32 +2486,18 @@ class Assignment final : 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 {
class RewritableAssignmentExpression : public Expression {
public:
DECLARE_NODE_TYPE(RewritableExpression)
DECLARE_NODE_TYPE(RewritableAssignmentExpression)
Expression* expression() const { return expr_; }
Expression* expression() { 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;
}
......@@ -2515,12 +2505,10 @@ class RewritableExpression : public Expression {
static int num_ids() { return parent_num_ids(); }
protected:
RewritableExpression(Zone* zone, Expression* expression)
RewritableAssignmentExpression(Zone* zone, Expression* expression)
: Expression(zone, expression->position()),
is_rewritten_(false),
expr_(expression) {
DCHECK(!expression->IsRewritableExpression());
}
expr_(expression) {}
private:
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
......@@ -3377,9 +3365,12 @@ class AstNodeFactory final BASE_EMBEDDED {
local_zone_, condition, then_expression, else_expression, position);
}
RewritableExpression* NewRewritableExpression(Expression* expression) {
RewritableAssignmentExpression* NewRewritableAssignmentExpression(
Expression* expression) {
DCHECK_NOT_NULL(expression);
return new (local_zone_) RewritableExpression(local_zone_, expression);
DCHECK(expression->IsAssignment());
return new (local_zone_)
RewritableAssignmentExpression(local_zone_, expression);
}
Assignment* NewAssignment(Token::Value op,
......@@ -3517,46 +3508,6 @@ 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,7 +412,8 @@ void CallPrinter::VisitSuperCallReference(SuperCallReference* node) {
}
void CallPrinter::VisitRewritableExpression(RewritableExpression* node) {
void CallPrinter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
Find(node->expression());
}
......@@ -928,7 +929,8 @@ void PrettyPrinter::VisitSuperCallReference(SuperCallReference* node) {
}
void PrettyPrinter::VisitRewritableExpression(RewritableExpression* node) {
void PrettyPrinter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
Visit(node->expression());
}
......@@ -1703,7 +1705,8 @@ void AstPrinter::VisitSuperCallReference(SuperCallReference* node) {
}
void AstPrinter::VisitRewritableExpression(RewritableExpression* node) {
void AstPrinter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
Visit(node->expression());
}
......
......@@ -3062,7 +3062,8 @@ VectorSlotPair AstGraphBuilder::CreateVectorSlotPair(
}
void AstGraphBuilder::VisitRewritableExpression(RewritableExpression* node) {
void AstGraphBuilder::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
Visit(node->expression());
}
......
......@@ -287,7 +287,8 @@ void ALAA::VisitCountOperation(CountOperation* e) {
}
void ALAA::VisitRewritableExpression(RewritableExpression* expr) {
void ALAA::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
Visit(expr->expression());
}
......
......@@ -12194,8 +12194,8 @@ void HOptimizedGraphBuilder::VisitExportDeclaration(
}
void HOptimizedGraphBuilder::VisitRewritableExpression(
RewritableExpression* node) {
void HOptimizedGraphBuilder::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
CHECK_ALIVE(Visit(node->expression()));
}
......
......@@ -770,7 +770,8 @@ void AstTyper::VisitSuperPropertyReference(SuperPropertyReference* expr) {}
void AstTyper::VisitSuperCallReference(SuperCallReference* expr) {}
void AstTyper::VisitRewritableExpression(RewritableExpression* expr) {
void AstTyper::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
Visit(expr->expression());
}
......
......@@ -1507,7 +1507,8 @@ void FullCodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) {
}
void FullCodeGenerator::VisitRewritableExpression(RewritableExpression* expr) {
void FullCodeGenerator::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
Visit(expr->expression());
}
......
......@@ -2860,7 +2860,8 @@ void BytecodeGenerator::VisitLogicalAndExpression(BinaryOperation* binop) {
}
void BytecodeGenerator::VisitRewritableExpression(RewritableExpression* expr) {
void BytecodeGenerator::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
Visit(expr->expression());
}
......
......@@ -13,7 +13,6 @@ namespace v8 {
namespace internal {
template <typename Traits>
class ExpressionClassifier {
public:
struct Error {
......@@ -56,25 +55,15 @@ class ExpressionClassifier {
enum FunctionProperties { NonSimpleParameter = 1 << 0 };
explicit ExpressionClassifier(const Traits* t)
: zone_(t->zone()),
non_patterns_to_rewrite_(t->GetNonPatternList()),
invalid_productions_(0),
ExpressionClassifier()
: invalid_productions_(0),
function_properties_(0),
duplicate_finder_(nullptr) {
non_pattern_begin_ = non_patterns_to_rewrite_->length();
}
duplicate_finder_(nullptr) {}
ExpressionClassifier(const Traits* t, DuplicateFinder* duplicate_finder)
: zone_(t->zone()),
non_patterns_to_rewrite_(t->GetNonPatternList()),
invalid_productions_(0),
explicit ExpressionClassifier(DuplicateFinder* duplicate_finder)
: invalid_productions_(0),
function_properties_(0),
duplicate_finder_(duplicate_finder) {
non_pattern_begin_ = non_patterns_to_rewrite_->length();
}
~ExpressionClassifier() { Discard(); }
duplicate_finder_(duplicate_finder) {}
bool is_valid(unsigned productions) const {
return (invalid_productions_ & productions) == 0;
......@@ -292,14 +281,12 @@ class ExpressionClassifier {
assignment_pattern_error_ = Error();
}
void Accumulate(ExpressionClassifier* inner,
unsigned productions = StandardProductions,
bool merge_non_patterns = true) {
if (merge_non_patterns) MergeNonPatterns(inner);
void Accumulate(const ExpressionClassifier& inner,
unsigned productions = StandardProductions) {
// 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;
......@@ -309,27 +296,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
......@@ -338,31 +325,16 @@ 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_;
......@@ -378,7 +350,6 @@ class ExpressionClassifier {
DuplicateFinder* duplicate_finder_;
};
} // namespace internal
} // namespace v8
......
This diff is collapsed.
This diff is collapsed.
......@@ -335,9 +335,6 @@ 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;
......@@ -552,7 +549,7 @@ class ParserTraits {
int initializer_end_position, bool is_rest);
V8_INLINE void DeclareFormalParameter(
Scope* scope, const ParserFormalParameters::Parameter& parameter,
Type::ExpressionClassifier* classifier);
ExpressionClassifier* classifier);
void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters,
Expression* params,
const Scanner::Location& params_loc,
......@@ -646,7 +643,6 @@ class ParserTraits {
V8_INLINE void QueueDestructuringAssignmentForRewriting(
Expression* assignment);
V8_INLINE void QueueNonPatternForRewriting(Expression* expr);
void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
const AstRawString* name);
......@@ -655,12 +651,11 @@ class ParserTraits {
Expression* identifier);
// Rewrite expressions that are not used as patterns
V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok);
V8_INLINE Zone* zone() const;
V8_INLINE ZoneList<Expression*>* GetNonPatternList() const;
V8_INLINE Expression* RewriteNonPattern(
Expression* expr, const ExpressionClassifier* classifier, bool* ok);
V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty(
ObjectLiteralProperty* property, const ExpressionClassifier* classifier,
bool* ok);
Expression* RewriteYieldStar(
Expression* generator, Expression* expression, int pos);
......@@ -817,9 +812,8 @@ class Parser : public ParserBase<ParserTraits> {
const DeclarationParsingResult::Declaration* declaration,
ZoneList<const AstRawString*>* names, bool* ok);
static void RewriteDestructuringAssignment(Parser* parser,
RewritableExpression* expr,
Scope* Scope);
static void RewriteDestructuringAssignment(
Parser* parser, RewritableAssignmentExpression* expr, Scope* Scope);
static Expression* RewriteDestructuringAssignment(Parser* parser,
Assignment* assignment,
......@@ -1035,7 +1029,11 @@ class Parser : public ParserBase<ParserTraits> {
friend class NonPatternRewriter;
V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok);
V8_INLINE Expression* RewriteNonPattern(
Expression* expr, const ExpressionClassifier* classifier, bool* ok);
V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty(
ObjectLiteralProperty* property, const ExpressionClassifier* classifier,
bool* ok);
friend class InitializerRewriter;
void RewriteParameterInitializer(Expression* expr, Scope* scope);
......@@ -1186,7 +1184,7 @@ void ParserTraits::AddFormalParameter(ParserFormalParameters* parameters,
void ParserTraits::DeclareFormalParameter(
Scope* scope, const ParserFormalParameters::Parameter& parameter,
Type::ExpressionClassifier* classifier) {
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, RewritableExpression* to_rewrite, Scope* scope) {
Parser* parser, RewritableAssignmentExpression* to_rewrite, Scope* scope) {
PatternRewriter rewriter;
DCHECK(!to_rewrite->is_rewritten());
......@@ -58,7 +58,8 @@ 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()->NewRewritableExpression(assignment);
auto to_rewrite =
parser->factory()->NewRewritableAssignmentExpression(assignment);
RewriteDestructuringAssignment(parser, to_rewrite, scope);
return to_rewrite->expression();
}
......@@ -90,8 +91,8 @@ Parser::PatternRewriter::SetInitializerContextIfNeeded(Expression* node) {
// AssignmentElement nodes
PatternContext old_context = context();
bool is_destructuring_assignment =
node->IsRewritableExpression() &&
!node->AsRewritableExpression()->is_rewritten();
node->IsRewritableAssignmentExpression() &&
!node->AsRewritableAssignmentExpression()->is_rewritten();
bool is_assignment =
node->IsAssignment() && node->AsAssignment()->op() == Token::ASSIGN;
if (is_destructuring_assignment || is_assignment) {
......@@ -323,11 +324,10 @@ Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) {
}
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
void Parser::PatternRewriter::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* node) {
if (!IsAssignmentContext()) {
// Mark the assignment 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(this);
ExpressionClassifier pattern_classifier;
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(this);
ExpressionClassifier classifier;
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(this);
ExpressionClassifier classifier;
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(this);
ExpressionClassifier classifier;
Expression expr = ParseExpression(true, &classifier, CHECK_OK);
ValidateExpression(&classifier, CHECK_OK);
......@@ -937,9 +937,10 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
if (mode == ForEachStatement::ITERATE) {
ExpressionClassifier classifier(this);
ParseAssignmentExpression(true, &classifier, CHECK_OK);
RewriteNonPattern(&classifier, CHECK_OK);
ExpressionClassifier classifier;
Expression enumerable =
ParseAssignmentExpression(true, &classifier, CHECK_OK);
PreParserTraits::RewriteNonPattern(enumerable, &classifier, CHECK_OK);
} else {
ParseExpression(true, CHECK_OK);
}
......@@ -950,7 +951,7 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
} else {
int lhs_beg_pos = peek_position();
ExpressionClassifier classifier(this);
ExpressionClassifier classifier;
Expression lhs = ParseExpression(false, &classifier, CHECK_OK);
int lhs_end_pos = scanner()->location().end_pos;
is_let_identifier_expression =
......@@ -975,9 +976,10 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
if (mode == ForEachStatement::ITERATE) {
ExpressionClassifier classifier(this);
ParseAssignmentExpression(true, &classifier, CHECK_OK);
RewriteNonPattern(&classifier, CHECK_OK);
ExpressionClassifier classifier;
Expression enumerable =
ParseAssignmentExpression(true, &classifier, CHECK_OK);
PreParserTraits::RewriteNonPattern(enumerable, &classifier, CHECK_OK);
} else {
ParseExpression(true, CHECK_OK);
}
......@@ -1055,7 +1057,7 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
if (tok == Token::CATCH) {
Consume(Token::CATCH);
Expect(Token::LPAREN, CHECK_OK);
ExpressionClassifier pattern_classifier(this);
ExpressionClassifier pattern_classifier;
ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
ValidateBindingPattern(&pattern_classifier, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
......@@ -1112,7 +1114,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
FunctionState function_state(&function_state_, &scope_, function_scope, kind,
&factory);
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
ExpressionClassifier formals_classifier(this, &duplicate_finder);
ExpressionClassifier formals_classifier(&duplicate_finder);
Expect(Token::LPAREN, CHECK_OK);
int start_position = scanner()->location().beg_pos;
......@@ -1218,7 +1220,7 @@ PreParserExpression PreParser::ParseClassLiteral(
bool has_extends = Check(Token::EXTENDS);
if (has_extends) {
ExpressionClassifier classifier(this);
ExpressionClassifier classifier;
ParseLeftHandSideExpression(&classifier, CHECK_OK);
ValidateExpression(&classifier, CHECK_OK);
}
......@@ -1234,7 +1236,7 @@ PreParserExpression PreParser::ParseClassLiteral(
bool is_computed_name = false; // Classes do not care about computed
// property names here.
Identifier name;
ExpressionClassifier classifier(this);
ExpressionClassifier classifier;
ParsePropertyDefinition(&checker, in_class, has_extends, is_static,
&is_computed_name, &has_seen_constructor,
&classifier, &name, CHECK_OK);
......@@ -1258,7 +1260,7 @@ PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) {
// Allow "eval" or "arguments" for backward compatibility.
ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
Scanner::Location spread_pos;
ExpressionClassifier classifier(this);
ExpressionClassifier classifier;
ParseArguments(&spread_pos, &classifier, ok);
ValidateExpression(&classifier, CHECK_OK);
......
......@@ -197,6 +197,8 @@ class PreParserExpression {
ExpressionTypeField::decode(code_) == kAssignment;
}
bool IsRewritableAssignmentExpression() const { return IsAssignment(); }
bool IsObjectLiteral() const {
return TypeField::decode(code_) == kObjectLiteralExpression;
}
......@@ -485,7 +487,8 @@ class PreParserFactory {
PreParserExpression right, int pos) {
return PreParserExpression::Default();
}
PreParserExpression NewRewritableExpression(PreParserExpression expression) {
PreParserExpression NewRewritableAssignmentExpression(
PreParserExpression expression) {
return expression;
}
PreParserExpression NewAssignment(Token::Value op,
......@@ -586,9 +589,6 @@ 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,
Type::ExpressionClassifier* classifier) {
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 void RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok);
V8_INLINE Zone* zone() const;
V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const;
inline PreParserExpression RewriteNonPattern(
PreParserExpression expr, const ExpressionClassifier* classifier,
bool* ok);
inline PreParserExpression RewriteNonPatternObjectLiteralProperty(
PreParserExpression property, const ExpressionClassifier* classifier,
bool* ok);
inline PreParserExpression RewriteYieldStar(
PreParserExpression generator, PreParserExpression expr, int pos);
......@@ -1119,19 +1119,19 @@ PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) {
}
void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok) {
PreParserExpression PreParserTraits::RewriteNonPattern(
PreParserExpression expr, const ExpressionClassifier* classifier,
bool* ok) {
pre_parser_->ValidateExpression(classifier, ok);
return expr;
}
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();
PreParserExpression PreParserTraits::RewriteNonPatternObjectLiteralProperty(
PreParserExpression property, const ExpressionClassifier* classifier,
bool* ok) {
pre_parser_->ValidateExpression(classifier, ok);
return property;
}
......
......@@ -1551,7 +1551,8 @@ void AsmTyper::VisitWithExpectation(Expression* expr, Type* expected_type,
}
void AsmTyper::VisitRewritableExpression(RewritableExpression* expr) {
void AsmTyper::VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* expr) {
RECURSE(Visit(expr->expression()));
}
......
......@@ -1177,7 +1177,10 @@ class AsmWasmBuilderImpl : public AstVisitor {
void VisitDoExpression(DoExpression* expr) { UNREACHABLE(); }
void VisitRewritableExpression(RewritableExpression* expr) { UNREACHABLE(); }
void VisitRewritableAssignmentExpression(
RewritableAssignmentExpression* 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