LCOV - code coverage report
Current view: top level - src/builtins - builtins-string-gen.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2017-10-20 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             : class StringBuiltinsAssembler : public CodeStubAssembler {
      14             :  public:
      15             :   explicit StringBuiltinsAssembler(compiler::CodeAssemblerState* state)
      16        1215 :       : 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* lhs_length, Node* rhs, Node* rhs_instance_type,
      24             :                         Label* if_equal, Label* if_not_equal,
      25             :                         Label* if_notbothdirectonebyte);
      26             : 
      27             :  protected:
      28             :   Node* DirectStringData(Node* string, Node* string_instance_type);
      29             : 
      30             :   void DispatchOnStringEncodings(Node* const lhs_instance_type,
      31             :                                  Node* const rhs_instance_type,
      32             :                                  Label* if_one_one, Label* if_one_two,
      33             :                                  Label* if_two_one, Label* if_two_two);
      34             : 
      35             :   template <typename SubjectChar, typename PatternChar>
      36             :   Node* CallSearchStringRaw(Node* const subject_ptr, Node* const subject_length,
      37             :                             Node* const search_ptr, Node* const search_length,
      38             :                             Node* const start_position);
      39             : 
      40             :   Node* PointerToStringDataAtIndex(Node* const string_data, Node* const index,
      41             :                                    String::Encoding encoding);
      42             : 
      43             :   // substr and slice have a common way of handling the {start} argument.
      44             :   void ConvertAndBoundsCheckStartArgument(Node* context, Variable* var_start,
      45             :                                           Node* start, Node* string_length);
      46             : 
      47             :   void GenerateStringEqual(Node* context, Node* left, Node* right);
      48             :   void GenerateStringRelationalComparison(Node* context, Node* left,
      49             :                                           Node* right,
      50             :                                           RelationalComparisonMode mode);
      51             : 
      52             :   TNode<Smi> ToSmiBetweenZeroAnd(SloppyTNode<Context> context,
      53             :                                  SloppyTNode<Object> value,
      54             :                                  SloppyTNode<Smi> limit);
      55             : 
      56             :   TNode<Uint32T> LoadSurrogatePairAt(SloppyTNode<String> string,
      57             :                                      SloppyTNode<Smi> length,
      58             :                                      SloppyTNode<Smi> index,
      59             :                                      UnicodeEncoding encoding);
      60             : 
      61             :   void StringIndexOf(Node* const subject_string, Node* const search_string,
      62             :                      Node* const position, std::function<void(Node*)> f_return);
      63             : 
      64             :   Node* IndexOfDollarChar(Node* const context, Node* const string);
      65             : 
      66             :   Node* IsNullOrUndefined(Node* const value);
      67             :   void RequireObjectCoercible(Node* const context, Node* const value,
      68             :                               const char* method_name);
      69             : 
      70          62 :   Node* SmiIsNegative(Node* const value) {
      71         124 :     return SmiLessThan(value, SmiConstant(0));
      72             :   }
      73             : 
      74             :   // Implements boilerplate logic for {match, split, replace, search} of the
      75             :   // form:
      76             :   //
      77             :   //  if (!IS_NULL_OR_UNDEFINED(object)) {
      78             :   //    var maybe_function = object[symbol];
      79             :   //    if (!IS_UNDEFINED(maybe_function)) {
      80             :   //      return %_Call(maybe_function, ...);
      81             :   //    }
      82             :   //  }
      83             :   //
      84             :   // Contains fast paths for Smi and RegExp objects.
      85             :   typedef std::function<Node*()> NodeFunction0;
      86             :   typedef std::function<Node*(Node* fn)> NodeFunction1;
      87             :   void MaybeCallFunctionAtSymbol(Node* const context, Node* const object,
      88             :                                  Handle<Symbol> symbol,
      89             :                                  const NodeFunction0& regexp_call,
      90             :                                  const NodeFunction1& generic_call,
      91             :                                  CodeStubArguments* args = nullptr);
      92             : };
      93             : 
      94             : class StringIncludesIndexOfAssembler : public StringBuiltinsAssembler {
      95             :  public:
      96             :   explicit StringIncludesIndexOfAssembler(compiler::CodeAssemblerState* state)
      97             :       : StringBuiltinsAssembler(state) {}
      98             : 
      99             :  protected:
     100             :   enum SearchVariant { kIncludes, kIndexOf };
     101             : 
     102             :   void Generate(SearchVariant variant);
     103             : };
     104             : 
     105             : class StringTrimAssembler : public StringBuiltinsAssembler {
     106             :  public:
     107             :   explicit StringTrimAssembler(compiler::CodeAssemblerState* state)
     108             :       : StringBuiltinsAssembler(state) {}
     109             : 
     110             :   void GotoIfNotWhiteSpaceOrLineTerminator(Node* const char_code,
     111             :                                            Label* const if_not_whitespace);
     112             : 
     113             :  protected:
     114             :   void Generate(String::TrimMode mode, const char* method);
     115             : 
     116             :   void ScanForNonWhiteSpaceOrLineTerminator(Node* const string_data,
     117             :                                             Node* const string_data_offset,
     118             :                                             Node* const is_stringonebyte,
     119             :                                             Variable* const var_index,
     120             :                                             Node* const end, int increment,
     121             :                                             Label* const if_none_found);
     122             : 
     123             :   void BuildLoop(Variable* const var_index, Node* const end, int increment,
     124             :                  Label* const if_none_found, Label* const out,
     125             :                  std::function<Node*(Node*)> get_character);
     126             : };
     127             : 
     128             : }  // namespace internal
     129             : }  // namespace v8
     130             : 
     131             : #endif  // V8_BUILTINS_BUILTINS_STRING_GEN_H_

Generated by: LCOV version 1.10