Lolcode candidate: Both Expression and FunctionLiteral define an accessor is_parenthe...
authorvogelheim <vogelheim@chromium.org>
Fri, 24 Apr 2015 11:07:50 +0000 (04:07 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 24 Apr 2015 11:07:31 +0000 (11:07 +0000)
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}

src/ast.h
src/compiler.cc
src/parser.cc
src/preparser.h

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