Commit a9f45ce9 authored by wingo's avatar wingo Committed by Commit bot

Rely on ExpressionClassifier to match valid arrow function formals

R=dslomov@chromium.org
LOG=N
BUG=

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

Cr-Commit-Position: refs/heads/master@{#28397}
parent 9be59492
...@@ -363,19 +363,6 @@ class Expression : public AstNode { ...@@ -363,19 +363,6 @@ class Expression : public AstNode {
Bounds bounds() const { return bounds_; } Bounds bounds() const { return bounds_; }
void set_bounds(Bounds bounds) { bounds_ = bounds; } void set_bounds(Bounds bounds) { bounds_ = bounds; }
// Whether the expression is parenthesized
bool is_single_parenthesized() const {
return IsSingleParenthesizedField::decode(bit_field_);
}
bool is_multi_parenthesized() const {
return IsMultiParenthesizedField::decode(bit_field_);
}
void increase_parenthesization_level() {
bit_field_ = IsMultiParenthesizedField::update(bit_field_,
is_single_parenthesized());
bit_field_ = IsSingleParenthesizedField::update(bit_field_, true);
}
// Type feedback information for assignments and properties. // Type feedback information for assignments and properties.
virtual bool IsMonomorphic() { virtual bool IsMonomorphic() {
UNREACHABLE(); UNREACHABLE();
...@@ -427,8 +414,6 @@ class Expression : public AstNode { ...@@ -427,8 +414,6 @@ class Expression : public AstNode {
int base_id_; int base_id_;
Bounds bounds_; Bounds bounds_;
class ToBooleanTypesField : public BitField16<byte, 0, 8> {}; class ToBooleanTypesField : public BitField16<byte, 0, 8> {};
class IsSingleParenthesizedField : public BitField16<bool, 8, 1> {};
class IsMultiParenthesizedField : public BitField16<bool, 9, 1> {};
uint16_t bit_field_; uint16_t bit_field_;
// Ends with 16-bit field; deriving classes in turn begin with // Ends with 16-bit field; deriving classes in turn begin with
// 16-bit fields for optimum packing efficiency. // 16-bit fields for optimum packing efficiency.
......
...@@ -3732,19 +3732,11 @@ void ParserTraits::DeclareArrowFunctionParameters( ...@@ -3732,19 +3732,11 @@ void ParserTraits::DeclareArrowFunctionParameters(
// need to match the pre-parser's behavior. // need to match the pre-parser's behavior.
if (expr->IsBinaryOperation()) { if (expr->IsBinaryOperation()) {
BinaryOperation* binop = expr->AsBinaryOperation(); BinaryOperation* binop = expr->AsBinaryOperation();
// TODO(wingo): These checks are now unnecessary, given the classifier. // The classifier has already run, so we know that the expression is a valid
if (binop->op() != Token::COMMA) { // arrow function formals production.
ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list"); DCHECK_EQ(binop->op(), Token::COMMA);
*ok = false;
return;
}
Expression* left = binop->left(); Expression* left = binop->left();
Expression* right = binop->right(); Expression* right = binop->right();
if (left->is_single_parenthesized() || right->is_single_parenthesized()) {
ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list");
*ok = false;
return;
}
DeclareArrowFunctionParameters(scope, left, params_loc, duplicate_loc, ok); DeclareArrowFunctionParameters(scope, left, params_loc, duplicate_loc, ok);
if (!*ok) return; if (!*ok) return;
// LHS of comma expression should be unparenthesized. // LHS of comma expression should be unparenthesized.
...@@ -3752,22 +3744,13 @@ void ParserTraits::DeclareArrowFunctionParameters( ...@@ -3752,22 +3744,13 @@ void ParserTraits::DeclareArrowFunctionParameters(
} }
// TODO(wingo): Support rest parameters. // TODO(wingo): Support rest parameters.
if (!expr->IsVariableProxy()) { DCHECK(expr->IsVariableProxy());
ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list"); DCHECK(!expr->AsVariableProxy()->is_this());
*ok = false;
return;
}
const AstRawString* raw_name = expr->AsVariableProxy()->raw_name(); const AstRawString* raw_name = expr->AsVariableProxy()->raw_name();
Scanner::Location param_location(expr->position(), Scanner::Location param_location(expr->position(),
expr->position() + raw_name->length()); expr->position() + raw_name->length());
if (expr->AsVariableProxy()->is_this()) {
ReportMessageAt(param_location, "this_formal_parameter");
*ok = false;
return;
}
// When the formal parameter was originally seen, it was parsed as a // When the formal parameter was originally seen, it was parsed as a
// VariableProxy and recorded as unresolved in the scope. Here we undo that // VariableProxy and recorded as unresolved in the scope. Here we undo that
// parse-time side-effect. // parse-time side-effect.
...@@ -3785,15 +3768,6 @@ void ParserTraits::DeclareArrowFunctionParameters( ...@@ -3785,15 +3768,6 @@ void ParserTraits::DeclareArrowFunctionParameters(
void ParserTraits::ParseArrowFunctionFormalParameters( void ParserTraits::ParseArrowFunctionFormalParameters(
Scope* scope, Expression* params, const Scanner::Location& params_loc, Scope* scope, Expression* params, const Scanner::Location& params_loc,
bool* is_rest, Scanner::Location* duplicate_loc, bool* ok) { bool* is_rest, Scanner::Location* duplicate_loc, bool* ok) {
// Too many parentheses around expression:
// (( ... )) => ...
if (params->is_multi_parenthesized()) {
// TODO(wingo): Make a better message.
ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list");
*ok = false;
return;
}
DeclareArrowFunctionParameters(scope, params, params_loc, duplicate_loc, ok); DeclareArrowFunctionParameters(scope, params, params_loc, duplicate_loc, ok);
} }
......
...@@ -1195,16 +1195,6 @@ class PreParserExpression { ...@@ -1195,16 +1195,6 @@ class PreParserExpression {
return TypeField::decode(code_) == kBinaryOperationExpression; return TypeField::decode(code_) == kBinaryOperationExpression;
} }
bool is_single_parenthesized() const {
return ParenthesizationField::decode(code_) != kNotParenthesized;
}
void increase_parenthesization_level() {
code_ = ParenthesizationField::update(
code_, is_single_parenthesized() ? kMultiParenthesizedExpression
: kParanthesizedExpression);
}
// Dummy implementation for making expression->somefunc() work in both Parser // Dummy implementation for making expression->somefunc() work in both Parser
// and PreParser. // and PreParser.
PreParserExpression* operator->() { return this; } PreParserExpression* operator->() { return this; }
...@@ -1225,12 +1215,6 @@ class PreParserExpression { ...@@ -1225,12 +1215,6 @@ class PreParserExpression {
kSpreadExpression kSpreadExpression
}; };
enum Parenthesization {
kNotParenthesized,
kParanthesizedExpression,
kMultiParenthesizedExpression
};
enum ExpressionType { enum ExpressionType {
kThisExpression, kThisExpression,
kThisPropertyExpression, kThisPropertyExpression,
...@@ -1242,17 +1226,15 @@ class PreParserExpression { ...@@ -1242,17 +1226,15 @@ class PreParserExpression {
explicit PreParserExpression(uint32_t expression_code) explicit PreParserExpression(uint32_t expression_code)
: code_(expression_code) {} : code_(expression_code) {}
// The first five bits are for the Type and Parenthesization. // The first three bits are for the Type.
typedef BitField<Type, 0, 3> TypeField; typedef BitField<Type, 0, 3> TypeField;
typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField;
// The rest of the bits are interpreted depending on the value // The rest of the bits are interpreted depending on the value
// of the Type field, so they can share the storage. // of the Type field, so they can share the storage.
typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField;
ExpressionTypeField; typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField;
typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField;
typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField;
typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10> typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10>
IdentifierTypeField; IdentifierTypeField;
uint32_t code_; uint32_t code_;
...@@ -2373,7 +2355,6 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, ...@@ -2373,7 +2355,6 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
// seeing the call parentheses. // seeing the call parentheses.
parenthesized_function_ = (peek() == Token::FUNCTION); parenthesized_function_ = (peek() == Token::FUNCTION);
result = this->ParseExpression(true, classifier, CHECK_OK); result = this->ParseExpression(true, classifier, CHECK_OK);
result->increase_parenthesization_level();
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
} }
break; break;
......
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