V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
builtins-regexp-gen.h
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_REGEXP_GEN_H_
6 #define V8_BUILTINS_BUILTINS_REGEXP_GEN_H_
7 
8 #include "src/base/optional.h"
9 #include "src/code-stub-assembler.h"
10 #include "src/message-template.h"
11 
12 namespace v8 {
13 namespace internal {
14 
16  public:
18  : CodeStubAssembler(state) {}
19 
20  void BranchIfFastRegExp(
21  Node* const context, Node* const object, Node* const map,
22  base::Optional<DescriptorIndexAndName> additional_property_to_check,
23  Label* const if_isunmodified, Label* const if_ismodified);
24 
25  // Create and initialize a RegExp object.
26  TNode<Object> RegExpCreate(TNode<Context> context,
27  TNode<Context> native_context,
28  TNode<Object> regexp_string, TNode<String> flags);
29 
30  TNode<Object> RegExpCreate(TNode<Context> context, TNode<Map> initial_map,
31  TNode<Object> regexp_string, TNode<String> flags);
32 
33  protected:
34  TNode<Smi> SmiZero();
35  TNode<IntPtrT> IntPtrZero();
36 
37  // Allocate a RegExpResult with the given length (the number of captures,
38  // including the match itself), index (the index where the match starts),
39  // and input string.
40  TNode<JSRegExpResult> AllocateRegExpResult(TNode<Context> context,
41  TNode<Smi> length,
42  TNode<Smi> index,
43  TNode<String> input);
44 
45  TNode<Object> FastLoadLastIndex(TNode<JSRegExp> regexp);
46  TNode<Object> SlowLoadLastIndex(TNode<Context> context, TNode<Object> regexp);
47  TNode<Object> LoadLastIndex(TNode<Context> context, TNode<Object> regexp,
48  bool is_fastpath);
49 
50  void FastStoreLastIndex(Node* regexp, Node* value);
51  void SlowStoreLastIndex(Node* context, Node* regexp, Node* value);
52  void StoreLastIndex(Node* context, Node* regexp, Node* value,
53  bool is_fastpath);
54 
55  // Loads {var_string_start} and {var_string_end} with the corresponding
56  // offsets into the given {string_data}.
57  void GetStringPointers(Node* const string_data, Node* const offset,
58  Node* const last_index, Node* const string_length,
59  String::Encoding encoding, Variable* var_string_start,
60  Variable* var_string_end);
61 
62  // Low level logic around the actual call into pattern matching code.
63  TNode<HeapObject> RegExpExecInternal(TNode<Context> context,
64  TNode<JSRegExp> regexp,
65  TNode<String> string,
66  TNode<Number> last_index,
67  TNode<RegExpMatchInfo> match_info);
68 
69  TNode<JSRegExpResult> ConstructNewResultFromMatchInfo(
70  TNode<Context> context, TNode<JSReceiver> maybe_regexp,
71  TNode<RegExpMatchInfo> match_info, TNode<String> string);
72 
73  TNode<RegExpMatchInfo> RegExpPrototypeExecBodyWithoutResult(
74  TNode<Context> context, TNode<JSReceiver> maybe_regexp,
75  TNode<String> string, Label* if_didnotmatch, const bool is_fastpath);
76  TNode<HeapObject> RegExpPrototypeExecBody(TNode<Context> context,
77  TNode<JSReceiver> maybe_regexp,
78  TNode<String> string,
79  const bool is_fastpath);
80 
81  Node* ThrowIfNotJSReceiver(Node* context, Node* maybe_receiver,
82  MessageTemplate msg_template,
83  char const* method_name);
84 
85  // Analogous to BranchIfFastRegExp, for use in asserts.
86  TNode<BoolT> IsFastRegExp(SloppyTNode<Context> context,
87  SloppyTNode<Object> object);
88 
89  void BranchIfFastRegExp(Node* const context, Node* const object,
90  Label* const if_isunmodified,
91  Label* const if_ismodified);
92 
93  // Performs fast path checks on the given object itself, but omits prototype
94  // checks.
95  Node* IsFastRegExpNoPrototype(Node* const context, Node* const object);
96  TNode<BoolT> IsFastRegExpWithOriginalExec(TNode<Context> context,
97  TNode<JSRegExp> object);
98  Node* IsFastRegExpNoPrototype(Node* const context, Node* const object,
99  Node* const map);
100 
101  void BranchIfFastRegExpResult(Node* const context, Node* const object,
102  Label* if_isunmodified, Label* if_ismodified);
103 
104  Node* FlagsGetter(Node* const context, Node* const regexp, bool is_fastpath);
105 
106  TNode<Int32T> FastFlagGetter(TNode<JSRegExp> regexp, JSRegExp::Flag flag);
107  TNode<Int32T> SlowFlagGetter(TNode<Context> context, TNode<Object> regexp,
108  JSRegExp::Flag flag);
109  TNode<Int32T> FlagGetter(TNode<Context> context, TNode<Object> regexp,
110  JSRegExp::Flag flag, bool is_fastpath);
111 
112  void FlagGetter(Node* context, Node* receiver, JSRegExp::Flag flag,
113  int counter, const char* method_name);
114 
115  Node* IsRegExp(Node* const context, Node* const maybe_receiver);
116 
117  Node* RegExpInitialize(Node* const context, Node* const regexp,
118  Node* const maybe_pattern, Node* const maybe_flags);
119 
120  Node* RegExpExec(Node* context, Node* regexp, Node* string);
121 
122  Node* AdvanceStringIndex(Node* const string, Node* const index,
123  Node* const is_unicode, bool is_fastpath);
124 
125  void RegExpPrototypeMatchBody(Node* const context, Node* const regexp,
126  TNode<String> const string,
127  const bool is_fastpath);
128 
129  void RegExpPrototypeSearchBodyFast(Node* const context, Node* const regexp,
130  Node* const string);
131  void RegExpPrototypeSearchBodySlow(Node* const context, Node* const regexp,
132  Node* const string);
133 
134  void RegExpPrototypeSplitBody(Node* const context, Node* const regexp,
135  TNode<String> const string,
136  TNode<Smi> const limit);
137 
138  Node* ReplaceGlobalCallableFastPath(Node* context, Node* regexp, Node* string,
139  Node* replace_callable);
140  Node* ReplaceSimpleStringFastPath(Node* context, Node* regexp,
141  TNode<String> string,
142  TNode<String> replace_string);
143 };
144 
146  public:
148  : RegExpBuiltinsAssembler(state) {}
149 
150  TNode<Object> CreateRegExpStringIterator(TNode<Context> native_context,
151  TNode<Object> regexp,
152  TNode<String> string,
153  TNode<Int32T> global,
154  TNode<Int32T> full_unicode);
155  void Generate(TNode<Context> context, TNode<Context> native_context,
156  TNode<Object> receiver, TNode<Object> maybe_string);
157 };
158 
159 } // namespace internal
160 } // namespace v8
161 
162 #endif // V8_BUILTINS_BUILTINS_REGEXP_GEN_H_
Definition: libplatform.h:13