1// Copyright 2020 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_REGEXP_EXPERIMENTAL_EXPERIMENTAL_H_ 6#define V8_REGEXP_EXPERIMENTAL_EXPERIMENTAL_H_ 7 8#include "src/regexp/regexp-flags.h" 9#include "src/regexp/regexp.h" 10 11namespace v8 { 12namespace internal { 13 14class ExperimentalRegExp final : public AllStatic { 15 public: 16 // Initialization & Compilation 17 // ------------------------------------------------------------------------- 18 // Check whether a parsed regexp pattern can be compiled and executed by the 19 // EXPERIMENTAL engine. 20 // TODO(mbid, v8:10765): This walks the RegExpTree, but it could also be 21 // checked on the fly in the parser. Not done currently because walking the 22 // AST again is more flexible and less error prone (but less performant). 23 static bool CanBeHandled(RegExpTree* tree, RegExpFlags flags, 24 int capture_count); 25 static void Initialize(Isolate* isolate, Handle<JSRegExp> re, 26 Handle<String> pattern, RegExpFlags flags, 27 int capture_count); 28 static bool IsCompiled(Handle<JSRegExp> re, Isolate* isolate); 29 V8_WARN_UNUSED_RESULT 30 static bool Compile(Isolate* isolate, Handle<JSRegExp> re); 31 32 // Execution: 33 static int32_t MatchForCallFromJs(Address subject, int32_t start_position, 34 Address input_start, Address input_end, 35 int* output_registers, 36 int32_t output_register_count, 37 RegExp::CallOrigin call_origin, 38 Isolate* isolate, Address regexp); 39 static MaybeHandle<Object> Exec( 40 Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject, 41 int index, Handle<RegExpMatchInfo> last_match_info, 42 RegExp::ExecQuirks exec_quirks = RegExp::ExecQuirks::kNone); 43 static int32_t ExecRaw(Isolate* isolate, RegExp::CallOrigin call_origin, 44 JSRegExp regexp, String subject, 45 int32_t* output_registers, 46 int32_t output_register_count, int32_t subject_index); 47 48 // Compile and execute a regexp with the experimental engine, regardless of 49 // its type tag. The regexp itself is not changed (apart from lastIndex). 50 static MaybeHandle<Object> OneshotExec( 51 Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject, 52 int index, Handle<RegExpMatchInfo> last_match_info, 53 RegExp::ExecQuirks exec_quirks = RegExp::ExecQuirks::kNone); 54 static int32_t OneshotExecRaw(Isolate* isolate, Handle<JSRegExp> regexp, 55 Handle<String> subject, 56 int32_t* output_registers, 57 int32_t output_register_count, 58 int32_t subject_index); 59 60 static constexpr bool kSupportsUnicode = false; 61}; 62 63} // namespace internal 64} // namespace v8 65 66#endif // V8_REGEXP_EXPERIMENTAL_EXPERIMENTAL_H_ 67