LCOV - code coverage report
Current view: top level - src/builtins - builtins-string-gen.h (source / functions) Hit Total Coverage
Test: app.info Lines: 6 6 100.0 %
Date: 2019-04-17 Functions: 1 1 100.0 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_BUILTINS_BUILTINS_STRING_GEN_H_
       6             : #define V8_BUILTINS_BUILTINS_STRING_GEN_H_
       7             : 
       8             : #include "src/code-stub-assembler.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : 
      13        2076 : class StringBuiltinsAssembler : public CodeStubAssembler {
      14             :  public:
      15             :   explicit StringBuiltinsAssembler(compiler::CodeAssemblerState* state)
      16        2076 :       : CodeStubAssembler(state) {}
      17             : 
      18             :   // ES#sec-getsubstitution
      19             :   Node* GetSubstitution(Node* context, Node* subject_string,
      20             :                         Node* match_start_index, Node* match_end_index,
      21             :                         Node* replace_string);
      22             :   void StringEqual_Core(Node* context, Node* lhs, Node* lhs_instance_type,
      23             :                         Node* rhs, Node* rhs_instance_type,
      24             :                         TNode<IntPtrT> length, Label* if_equal,
      25             :                         Label* if_not_equal, Label* if_indirect);
      26             :   void BranchIfStringPrimitiveWithNoCustomIteration(TNode<Object> object,
      27             :                                                     TNode<Context> context,
      28             :                                                     Label* if_true,
      29             :                                                     Label* if_false);
      30             : 
      31             :  protected:
      32             :   TNode<JSArray> StringToList(TNode<Context> context, TNode<String> string);
      33             : 
      34             :   void StringEqual_Loop(Node* lhs, Node* lhs_instance_type,
      35             :                         MachineType lhs_type, Node* rhs,
      36             :                         Node* rhs_instance_type, MachineType rhs_type,
      37             :                         TNode<IntPtrT> length, Label* if_equal,
      38             :                         Label* if_not_equal);
      39             :   Node* DirectStringData(Node* string, Node* string_instance_type);
      40             : 
      41             :   void DispatchOnStringEncodings(Node* const lhs_instance_type,
      42             :                                  Node* const rhs_instance_type,
      43             :                                  Label* if_one_one, Label* if_one_two,
      44             :                                  Label* if_two_one, Label* if_two_two);
      45             : 
      46             :   template <typename SubjectChar, typename PatternChar>
      47             :   Node* CallSearchStringRaw(Node* const subject_ptr, Node* const subject_length,
      48             :                             Node* const search_ptr, Node* const search_length,
      49             :                             Node* const start_position);
      50             : 
      51             :   Node* PointerToStringDataAtIndex(Node* const string_data, Node* const index,
      52             :                                    String::Encoding encoding);
      53             : 
      54             :   // substr and slice have a common way of handling the {start} argument.
      55             :   void ConvertAndBoundsCheckStartArgument(Node* context, Variable* var_start,
      56             :                                           Node* start, Node* string_length);
      57             : 
      58             :   void GenerateStringEqual(Node* context, Node* left, Node* right);
      59             :   void GenerateStringRelationalComparison(Node* context, Node* left,
      60             :                                           Node* right, Operation op);
      61             : 
      62             :   TNode<Smi> ToSmiBetweenZeroAnd(SloppyTNode<Context> context,
      63             :                                  SloppyTNode<Object> value,
      64             :                                  SloppyTNode<Smi> limit);
      65             : 
      66             :   typedef std::function<TNode<Object>(
      67             :       TNode<String> receiver, TNode<IntPtrT> length, TNode<IntPtrT> index)>
      68             :       StringAtAccessor;
      69             : 
      70             :   void GenerateStringAt(const char* method_name, TNode<Context> context,
      71             :                         TNode<Object> receiver, TNode<Object> maybe_position,
      72             :                         TNode<Object> default_return,
      73             :                         const StringAtAccessor& accessor);
      74             : 
      75             :   TNode<Int32T> LoadSurrogatePairAt(SloppyTNode<String> string,
      76             :                                     SloppyTNode<IntPtrT> length,
      77             :                                     SloppyTNode<IntPtrT> index,
      78             :                                     UnicodeEncoding encoding);
      79             : 
      80             :   void StringIndexOf(Node* const subject_string, Node* const search_string,
      81             :                      Node* const position,
      82             :                      const std::function<void(Node*)>& f_return);
      83             : 
      84             :   TNode<Smi> IndexOfDollarChar(Node* const context, Node* const string);
      85             : 
      86             :   TNode<JSArray> StringToArray(TNode<Context> context,
      87             :                                TNode<String> subject_string,
      88             :                                TNode<Smi> subject_length,
      89             :                                TNode<Number> limit_number);
      90             : 
      91             :   void RequireObjectCoercible(Node* const context, Node* const value,
      92             :                               const char* method_name);
      93             : 
      94         112 :   TNode<BoolT> SmiIsNegative(TNode<Smi> value) {
      95         112 :     return SmiLessThan(value, SmiConstant(0));
      96             :   }
      97             : 
      98             :   // Implements boilerplate logic for {match, split, replace, search} of the
      99             :   // form:
     100             :   //
     101             :   //  if (!IS_NULL_OR_UNDEFINED(object)) {
     102             :   //    var maybe_function = object[symbol];
     103             :   //    if (!IS_UNDEFINED(maybe_function)) {
     104             :   //      return %_Call(maybe_function, ...);
     105             :   //    }
     106             :   //  }
     107             :   //
     108             :   // Contains fast paths for Smi and RegExp objects.
     109             :   // Important: {regexp_call} may not contain any code that can call into JS.
     110             :   typedef std::function<void()> NodeFunction0;
     111             :   typedef std::function<void(Node* fn)> NodeFunction1;
     112             :   void MaybeCallFunctionAtSymbol(Node* const context, Node* const object,
     113             :                                  Node* const maybe_string,
     114             :                                  Handle<Symbol> symbol,
     115             :                                  DescriptorIndexAndName symbol_index,
     116             :                                  const NodeFunction0& regexp_call,
     117             :                                  const NodeFunction1& generic_call);
     118             : };
     119             : 
     120         112 : class StringIncludesIndexOfAssembler : public StringBuiltinsAssembler {
     121             :  public:
     122             :   explicit StringIncludesIndexOfAssembler(compiler::CodeAssemblerState* state)
     123             :       : StringBuiltinsAssembler(state) {}
     124             : 
     125             :  protected:
     126             :   enum SearchVariant { kIncludes, kIndexOf };
     127             : 
     128             :   void Generate(SearchVariant variant, TNode<IntPtrT> argc,
     129             :                 TNode<Context> context);
     130             : };
     131             : 
     132         172 : class StringTrimAssembler : public StringBuiltinsAssembler {
     133             :  public:
     134             :   explicit StringTrimAssembler(compiler::CodeAssemblerState* state)
     135             :       : StringBuiltinsAssembler(state) {}
     136             : 
     137             :   V8_EXPORT_PRIVATE void GotoIfNotWhiteSpaceOrLineTerminator(
     138             :       Node* const char_code, Label* const if_not_whitespace);
     139             : 
     140             :  protected:
     141             :   void Generate(String::TrimMode mode, const char* method, TNode<IntPtrT> argc,
     142             :                 TNode<Context> context);
     143             : 
     144             :   void ScanForNonWhiteSpaceOrLineTerminator(Node* const string_data,
     145             :                                             Node* const string_data_offset,
     146             :                                             Node* const is_stringonebyte,
     147             :                                             Variable* const var_index,
     148             :                                             Node* const end, int increment,
     149             :                                             Label* const if_none_found);
     150             : 
     151             :   void BuildLoop(Variable* const var_index, Node* const end, int increment,
     152             :                  Label* const if_none_found, Label* const out,
     153             :                  const std::function<Node*(Node*)>& get_character);
     154             : };
     155             : 
     156             : }  // namespace internal
     157             : }  // namespace v8
     158             : 
     159             : #endif  // V8_BUILTINS_BUILTINS_STRING_GEN_H_

Generated by: LCOV version 1.10