Commit 63f7fbfe authored by vogelheim's avatar vogelheim Committed by Commit bot

Lolcode candidate: Both Expression and FunctionLiteral define an accessor...

Lolcode candidate: Both Expression and FunctionLiteral define an accessor is_parenthesized(), which access different flags. FunctionLiteral derives from Expression.

Given
      FunctionLiteral* a; a->is_parenthesized()
const FunctionLiteral* b; b->is_parenthesized()

the first accesses FunctionLiteral::IsParenthesized, the second accesses Expression::IsParenthesizedField.

Since these are distinct uses, we could rename them based on their use:
- Expression::is_parenthesized -> is_single_parenthesized
  Count # of parenthesis, for parsing & error handling:
  no parenthesis -> single parenthesis -> multi parenthesis
- FunctionLiteral::eager_compile_hint()
  Hint from parser to compiler about whether the parser suggests this function for eager compilation.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#28042}
parent 4f9bc2d1
...@@ -372,16 +372,16 @@ class Expression : public AstNode { ...@@ -372,16 +372,16 @@ class Expression : public AstNode {
void set_bounds(Bounds bounds) { bounds_ = bounds; } void set_bounds(Bounds bounds) { bounds_ = bounds; }
// Whether the expression is parenthesized // Whether the expression is parenthesized
bool is_parenthesized() const { bool is_single_parenthesized() const {
return IsParenthesizedField::decode(bit_field_); return IsSingleParenthesizedField::decode(bit_field_);
} }
bool is_multi_parenthesized() const { bool is_multi_parenthesized() const {
return IsMultiParenthesizedField::decode(bit_field_); return IsMultiParenthesizedField::decode(bit_field_);
} }
void increase_parenthesization_level() { void increase_parenthesization_level() {
bit_field_ = bit_field_ = IsMultiParenthesizedField::update(bit_field_,
IsMultiParenthesizedField::update(bit_field_, is_parenthesized()); is_single_parenthesized());
bit_field_ = IsParenthesizedField::update(bit_field_, true); bit_field_ = IsSingleParenthesizedField::update(bit_field_, true);
} }
// Type feedback information for assignments and properties. // Type feedback information for assignments and properties.
...@@ -435,7 +435,7 @@ class Expression : public AstNode { ...@@ -435,7 +435,7 @@ 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 IsParenthesizedField : public BitField16<bool, 8, 1> {}; class IsSingleParenthesizedField : public BitField16<bool, 8, 1> {};
class IsMultiParenthesizedField : public BitField16<bool, 9, 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
...@@ -2504,10 +2504,7 @@ class FunctionLiteral final : public Expression { ...@@ -2504,10 +2504,7 @@ class FunctionLiteral final : public Expression {
kIsFunction kIsFunction
}; };
enum IsParenthesizedFlag { enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile };
kIsParenthesized,
kNotParenthesized
};
enum ArityRestriction { enum ArityRestriction {
NORMAL_ARITY, NORMAL_ARITY,
...@@ -2597,11 +2594,11 @@ class FunctionLiteral final : public Expression { ...@@ -2597,11 +2594,11 @@ class FunctionLiteral final : public Expression {
// function will be called immediately: // function will be called immediately:
// - (function() { ... })(); // - (function() { ... })();
// - var x = function() { ... }(); // - var x = function() { ... }();
bool is_parenthesized() { bool should_eager_compile() const {
return IsParenthesized::decode(bitfield_) == kIsParenthesized; return EagerCompileHintBit::decode(bitfield_) == kShouldEagerCompile;
} }
void set_parenthesized() { void set_should_eager_compile() {
bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); bitfield_ = EagerCompileHintBit::update(bitfield_, kShouldEagerCompile);
} }
FunctionKind kind() { return FunctionKindBits::decode(bitfield_); } FunctionKind kind() { return FunctionKindBits::decode(bitfield_); }
...@@ -2628,7 +2625,7 @@ class FunctionLiteral final : public Expression { ...@@ -2628,7 +2625,7 @@ class FunctionLiteral final : public Expression {
int parameter_count, FunctionType function_type, int parameter_count, FunctionType function_type,
ParameterFlag has_duplicate_parameters, ParameterFlag has_duplicate_parameters,
IsFunctionFlag is_function, IsFunctionFlag is_function,
IsParenthesizedFlag is_parenthesized, FunctionKind kind, EagerCompileHint eager_compile_hint, FunctionKind kind,
int position) int position)
: Expression(zone, position), : Expression(zone, position),
raw_name_(name), raw_name_(name),
...@@ -2647,7 +2644,7 @@ class FunctionLiteral final : public Expression { ...@@ -2647,7 +2644,7 @@ class FunctionLiteral final : public Expression {
Pretenure::encode(false) | Pretenure::encode(false) |
HasDuplicateParameters::encode(has_duplicate_parameters) | HasDuplicateParameters::encode(has_duplicate_parameters) |
IsFunction::encode(is_function) | IsFunction::encode(is_function) |
IsParenthesized::encode(is_parenthesized) | EagerCompileHintBit::encode(eager_compile_hint) |
FunctionKindBits::encode(kind); FunctionKindBits::encode(kind);
DCHECK(IsValidFunctionKind(kind)); DCHECK(IsValidFunctionKind(kind));
} }
...@@ -2675,7 +2672,7 @@ class FunctionLiteral final : public Expression { ...@@ -2675,7 +2672,7 @@ class FunctionLiteral final : public Expression {
class Pretenure : public BitField<bool, 2, 1> {}; class Pretenure : public BitField<bool, 2, 1> {};
class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {}; class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
class IsFunction : public BitField<IsFunctionFlag, 4, 1> {}; class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {}; class EagerCompileHintBit : public BitField<EagerCompileHint, 5, 1> {};
class FunctionKindBits : public BitField<FunctionKind, 6, 8> {}; class FunctionKindBits : public BitField<FunctionKind, 6, 8> {};
}; };
...@@ -3559,12 +3556,12 @@ class AstNodeFactory final BASE_EMBEDDED { ...@@ -3559,12 +3556,12 @@ class AstNodeFactory final BASE_EMBEDDED {
FunctionLiteral::ParameterFlag has_duplicate_parameters, FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type, FunctionLiteral::FunctionType function_type,
FunctionLiteral::IsFunctionFlag is_function, FunctionLiteral::IsFunctionFlag is_function,
FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
int position) { int position) {
return new (zone_) FunctionLiteral( return new (zone_) FunctionLiteral(
zone_, name, ast_value_factory, scope, body, materialized_literal_count, zone_, name, ast_value_factory, scope, body, materialized_literal_count,
expected_property_count, handler_count, parameter_count, function_type, expected_property_count, handler_count, parameter_count, function_type,
has_duplicate_parameters, is_function, is_parenthesized, kind, has_duplicate_parameters, is_function, eager_compile_hint, kind,
position); position);
} }
......
...@@ -1348,7 +1348,7 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( ...@@ -1348,7 +1348,7 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(
// Generate code // Generate code
Handle<ScopeInfo> scope_info; Handle<ScopeInfo> scope_info;
if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { if (FLAG_lazy && allow_lazy && !literal->should_eager_compile()) {
Handle<Code> code = isolate->builtins()->CompileLazy(); Handle<Code> code = isolate->builtins()->CompileLazy();
info.SetCode(code); info.SetCode(code);
// There's no need in theory for a lazy-compiled function to have a type // There's no need in theory for a lazy-compiled function to have a type
......
...@@ -378,7 +378,7 @@ FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, ...@@ -378,7 +378,7 @@ FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
materialized_literal_count, expected_property_count, handler_count, materialized_literal_count, expected_property_count, handler_count,
parameter_count, FunctionLiteral::kNoDuplicateParameters, parameter_count, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
FunctionLiteral::kNotParenthesized, kind, pos); FunctionLiteral::kShouldLazyCompile, kind, pos);
return function_literal; return function_literal;
} }
...@@ -1039,7 +1039,8 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -1039,7 +1039,8 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
function_state.handler_count(), 0, function_state.handler_count(), 0,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval, FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval,
FunctionLiteral::kNotParenthesized, FunctionKind::kNormalFunction, 0); FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction,
0);
} }
} }
...@@ -3833,7 +3834,7 @@ void ParserTraits::DeclareArrowFunctionParameters( ...@@ -3833,7 +3834,7 @@ void ParserTraits::DeclareArrowFunctionParameters(
} }
Expression* left = binop->left(); Expression* left = binop->left();
Expression* right = binop->right(); Expression* right = binop->right();
if (left->is_parenthesized() || right->is_parenthesized()) { if (left->is_single_parenthesized() || right->is_single_parenthesized()) {
ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list"); ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list");
*ok = false; *ok = false;
return; return;
...@@ -3975,9 +3976,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3975,9 +3976,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
int expected_property_count = -1; int expected_property_count = -1;
int handler_count = 0; int handler_count = 0;
FormalParameterErrorLocations error_locs; FormalParameterErrorLocations error_locs;
FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ FunctionLiteral::EagerCompileHint eager_compile_hint =
? FunctionLiteral::kIsParenthesized parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile
: FunctionLiteral::kNotParenthesized; : FunctionLiteral::kShouldLazyCompile;
// Parse function body. // Parse function body.
{ {
AstNodeFactory function_factory(ast_value_factory()); AstNodeFactory function_factory(ast_value_factory());
...@@ -4123,7 +4124,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4123,7 +4124,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
function_name, ast_value_factory(), scope, body, function_name, ast_value_factory(), scope, body,
materialized_literal_count, expected_property_count, handler_count, materialized_literal_count, expected_property_count, handler_count,
num_parameters, duplicate_parameters, function_type, num_parameters, duplicate_parameters, function_type,
FunctionLiteral::kIsFunction, parenthesized, kind, pos); FunctionLiteral::kIsFunction, eager_compile_hint, kind, pos);
function_literal->set_function_token_position(function_token_pos); function_literal->set_function_token_position(function_token_pos);
if (scope->has_rest_parameter()) { if (scope->has_rest_parameter()) {
......
...@@ -903,10 +903,10 @@ class PreParserExpression { ...@@ -903,10 +903,10 @@ class PreParserExpression {
Token::Value op, Token::Value op,
PreParserExpression right) { PreParserExpression right) {
ValidArrowParam valid_arrow_param_list = ValidArrowParam valid_arrow_param_list =
(op == Token::COMMA && !left.is_parenthesized() && (op == Token::COMMA && !left.is_single_parenthesized() &&
!right.is_parenthesized()) ? !right.is_single_parenthesized())
std::min(left.ValidateArrowParams(), right.ValidateArrowParams()) ? std::min(left.ValidateArrowParams(), right.ValidateArrowParams())
: kInvalidArrowParam; : kInvalidArrowParam;
return PreParserExpression( return PreParserExpression(
TypeField::encode(kBinaryOperationExpression) | TypeField::encode(kBinaryOperationExpression) |
IsValidArrowParamListField::encode(valid_arrow_param_list)); IsValidArrowParamListField::encode(valid_arrow_param_list));
...@@ -1045,14 +1045,14 @@ class PreParserExpression { ...@@ -1045,14 +1045,14 @@ class PreParserExpression {
return TypeField::decode(code_) == kBinaryOperationExpression; return TypeField::decode(code_) == kBinaryOperationExpression;
} }
bool is_parenthesized() const { bool is_single_parenthesized() const {
return ParenthesizationField::decode(code_) != kNotParenthesized; return ParenthesizationField::decode(code_) != kNotParenthesized;
} }
void increase_parenthesization_level() { void increase_parenthesization_level() {
code_ = ParenthesizationField::update( code_ = ParenthesizationField::update(
code_, is_parenthesized() ? kMultiParenthesizedExpression code_, is_single_parenthesized() ? kMultiParenthesizedExpression
: kParanthesizedExpression); : kParanthesizedExpression);
} }
// Dummy implementation for making expression->somefunc() work in both Parser // Dummy implementation for making expression->somefunc() work in both Parser
...@@ -1061,7 +1061,7 @@ class PreParserExpression { ...@@ -1061,7 +1061,7 @@ class PreParserExpression {
// More dummy implementations of things PreParser doesn't need to track: // More dummy implementations of things PreParser doesn't need to track:
void set_index(int index) {} // For YieldExpressions void set_index(int index) {} // For YieldExpressions
void set_parenthesized() {} void set_should_eager_compile() {}
int position() const { return RelocInfo::kNoPosition; } int position() const { return RelocInfo::kNoPosition; }
void set_function_token_position(int position) {} void set_function_token_position(int position) {}
...@@ -1349,7 +1349,7 @@ class PreParserFactory { ...@@ -1349,7 +1349,7 @@ class PreParserFactory {
FunctionLiteral::ParameterFlag has_duplicate_parameters, FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type, FunctionLiteral::FunctionType function_type,
FunctionLiteral::IsFunctionFlag is_function, FunctionLiteral::IsFunctionFlag is_function,
FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
int position) { int position) {
return PreParserExpression::Default(); return PreParserExpression::Default();
} }
...@@ -2963,7 +2963,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression( ...@@ -2963,7 +2963,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
// be called immediately. If we happen to have parsed a preceding // be called immediately. If we happen to have parsed a preceding
// function literal eagerly, we can also compile it eagerly. // function literal eagerly, we can also compile it eagerly.
if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
result->AsFunctionLiteral()->set_parenthesized(); result->AsFunctionLiteral()->set_should_eager_compile();
} }
} }
Scanner::Location spread_pos; Scanner::Location spread_pos;
...@@ -3325,7 +3325,7 @@ ParserBase<Traits>::ParseMemberExpressionContinuation( ...@@ -3325,7 +3325,7 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
// If the tag function looks like an IIFE, set_parenthesized() to // If the tag function looks like an IIFE, set_parenthesized() to
// force eager compilation. // force eager compilation.
expression->AsFunctionLiteral()->set_parenthesized(); expression->AsFunctionLiteral()->set_should_eager_compile();
} }
} }
expression = expression =
...@@ -3520,7 +3520,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral( ...@@ -3520,7 +3520,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
materialized_literal_count, expected_property_count, handler_count, materialized_literal_count, expected_property_count, handler_count,
num_parameters, FunctionLiteral::kNoDuplicateParameters, num_parameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
FunctionLiteral::kNotParenthesized, FunctionKind::kArrowFunction, FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction,
scope->start_position()); scope->start_position());
function_literal->set_function_token_position(scope->start_position()); function_literal->set_function_token_position(scope->start_position());
......
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