Bounds bounds() const { return 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.
virtual bool IsMonomorphic() {
UNREACHABLE();
int base_id_;
Bounds bounds_;
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_;
// Ends with 16-bit field; deriving classes in turn begin with
// 16-bit fields for optimum packing efficiency.
// need to match the pre-parser's behavior.
if (expr->IsBinaryOperation()) {
BinaryOperation* binop = expr->AsBinaryOperation();
- // TODO(wingo): These checks are now unnecessary, given the classifier.
- if (binop->op() != Token::COMMA) {
- ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list");
- *ok = false;
- return;
- }
+ // The classifier has already run, so we know that the expression is a valid
+ // arrow function formals production.
+ DCHECK_EQ(binop->op(), Token::COMMA);
Expression* left = binop->left();
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);
if (!*ok) return;
// LHS of comma expression should be unparenthesized.
}
// TODO(wingo): Support rest parameters.
- if (!expr->IsVariableProxy()) {
- ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list");
- *ok = false;
- return;
- }
+ DCHECK(expr->IsVariableProxy());
+ DCHECK(!expr->AsVariableProxy()->is_this());
const AstRawString* raw_name = expr->AsVariableProxy()->raw_name();
Scanner::Location param_location(expr->position(),
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
// VariableProxy and recorded as unresolved in the scope. Here we undo that
// parse-time side-effect.
void ParserTraits::ParseArrowFunctionFormalParameters(
Scope* scope, Expression* params, const Scanner::Location& params_loc,
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);
}
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
// and PreParser.
PreParserExpression* operator->() { return this; }
kSpreadExpression
};
- enum Parenthesization {
- kNotParenthesized,
- kParanthesizedExpression,
- kMultiParenthesizedExpression
- };
-
enum ExpressionType {
kThisExpression,
kThisPropertyExpression,
explicit PreParserExpression(uint32_t 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<Parenthesization, TypeField::kNext, 2> ParenthesizationField;
// The rest of the bits are interpreted depending on the value
// of the Type field, so they can share the storage.
- typedef BitField<ExpressionType, ParenthesizationField::kNext, 3>
- ExpressionTypeField;
- typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField;
+ typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField;
+ typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField;
typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField;
- typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10>
+ typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10>
IdentifierTypeField;
uint32_t code_;
// seeing the call parentheses.
parenthesized_function_ = (peek() == Token::FUNCTION);
result = this->ParseExpression(true, classifier, CHECK_OK);
- result->increase_parenthesization_level();
Expect(Token::RPAREN, CHECK_OK);
}
break;