5#ifndef V8_REGEXP_REGEXP_AST_H_
6#define V8_REGEXP_REGEXP_AST_H_
17#include "unicode/uniset.h"
22#define FOR_EACH_REG_EXP_TREE_TYPE(VISIT) \
27 VISIT(ClassSetOperand) \
28 VISIT(ClassSetExpression) \
34 VISIT(BackReference) \
38#define FORWARD_DECLARE(Name) class RegExp##Name;
49#define MAKE_CASE(Name) \
50 virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
61 if (that.from_ ==
kNone)
return *
this;
74 static constexpr int kNone = -1;
107 DCHECK(
static_cast<uint32_t
>(from) <=
static_cast<uint32_t
>(to));
118 list->
Add(range, zone);
181 return lhs.
from() == rhs.
from() && lhs.
to() == rhs.
to();
187#define DECL_BOILERPLATE(Name) \
188 void* Accept(RegExpVisitor* visitor, void* data) override; \
189 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) \
191 RegExp##Name* As##Name() override; \
192 bool Is##Name() override
211#define MAKE_ASTYPE(Name) \
212 virtual RegExp##Name* As##Name(); \
213 virtual bool Is##Name();
324 if (ranges->is_empty()) {
325 ranges->Add(CharacterRange::Everything(), zone);
326 class_ranges_flags_ ^= NEGATED;
377 if (lhs[
i] != rhs[
i]) {
378 return lhs[
i] < rhs[
i];
556 min_match_ = kInfinity;
558 min_match_ = min * body->min_match();
561 max_match_ = kInfinity;
563 max_match_ = max * body->max_match();
571 bool not_at_start =
false);
686 int stack_pointer_register,
int position_register,
687 int capture_register_count = 0,
int capture_register_start = 0);
743#undef DECL_BOILERPLATE
#define FORWARD_DECLARE(Name, Argc)
static bool Equals(const ZoneList< CharacterRange > *lhs, const ZoneList< CharacterRange > *rhs)
static void Canonicalize(ZoneList< CharacterRange > *ranges)
static void AddUnicodeCaseEquivalents(ZoneList< CharacterRange > *ranges, Zone *zone)
CharacterRange(void *null)
static void Subtract(const ZoneList< CharacterRange > *src, const ZoneList< CharacterRange > *to_remove, ZoneList< CharacterRange > *dst, Zone *zone)
bool IsEverything(base::uc32 max) const
static void Negate(const ZoneList< CharacterRange > *src, ZoneList< CharacterRange > *dst, Zone *zone)
CharacterRange(base::uc32 from, base::uc32 to)
static V8_EXPORT_PRIVATE void AddCaseEquivalents(Isolate *isolate, Zone *zone, ZoneList< CharacterRange > *ranges, bool is_one_byte)
static constexpr int kMaxCodePoint
static void ClampToOneByte(ZoneList< CharacterRange > *ranges)
bool Contains(base::uc32 i) const
static CharacterRange Singleton(base::uc32 value)
static V8_EXPORT_PRIVATE bool IsCanonical(const ZoneList< CharacterRange > *ranges)
static ZoneList< CharacterRange > * List(Zone *zone, CharacterRange range)
static void Intersect(const ZoneList< CharacterRange > *lhs, const ZoneList< CharacterRange > *rhs, ZoneList< CharacterRange > *dst, Zone *zone)
static CharacterRange Range(base::uc32 from, base::uc32 to)
static CharacterRange Everything()
static V8_EXPORT_PRIVATE void AddClassEscape(StandardCharacterSet standard_character_set, ZoneList< CharacterRange > *ranges, bool add_unicode_case_equivalents, Zone *zone)
CharacterSet(StandardCharacterSet standard_set_type)
void set_standard_set_type(StandardCharacterSet standard_set_type)
V8_EXPORT_PRIVATE void Canonicalize()
CharacterSet(ZoneList< CharacterRange > *ranges)
std::optional< StandardCharacterSet > standard_set_type_
StandardCharacterSet standard_set_type() const
ZoneList< CharacterRange > * ranges_
ZoneList< CharacterRange > * ranges(Zone *zone)
Interval(int from, int to)
Interval Union(Interval that)
static constexpr int kNone
bool Contains(int value) const
DECL_BOILERPLATE(Alternative)
bool IsAnchoredAtStart() override
Interval CaptureRegisters() override
ZoneList< RegExpTree * > * nodes_
bool IsAnchoredAtEnd() override
RegExpAlternative(ZoneList< RegExpTree * > *nodes)
ZoneList< RegExpTree * > * nodes() const
const Type assertion_type_
bool IsAnchoredAtEnd() override
DECL_BOILERPLATE(Assertion)
bool IsAnchoredAtStart() override
Type assertion_type() const
RegExpAssertion(Type type)
RegExpAtom(base::Vector< const base::uc16 > data)
base::Vector< const base::uc16 > data_
base::Vector< const base::uc16 > data() const
void AppendToText(RegExpText *text, Zone *zone) override
bool IsTextElement() override
RegExpBackReference(RegExpCapture *capture, Zone *zone)
const ZoneVector< base::uc16 > * name() const
const ZoneVector< base::uc16 > * name_
void add_capture(RegExpCapture *capture, Zone *zone)
void set_name(const ZoneVector< base::uc16 > *name)
DECL_BOILERPLATE(BackReference)
const ZoneList< RegExpCapture * > * captures() const
ZoneList< RegExpCapture * > captures_
RegExpBackReference(Zone *zone)
static int StartRegister(int index)
const ZoneVector< base::uc16 > * name_
static RegExpNode * ToNode(RegExpTree *body, int index, RegExpCompiler *compiler, RegExpNode *on_success)
void set_name(const ZoneVector< base::uc16 > *name)
static int EndRegister(int index)
DECL_BOILERPLATE(Capture)
bool IsAnchoredAtStart() override
Interval CaptureRegisters() override
void set_body(RegExpTree *body)
bool IsAnchoredAtEnd() override
const ZoneVector< base::uc16 > * name() const
bool contains_split_surrogate() const
RegExpClassRanges(StandardCharacterSet standard_set_type)
StandardCharacterSet standard_type() const
bool IsTextElement() override
DECL_BOILERPLATE(ClassRanges)
base::Flags< Flag > ClassRangesFlags
bool is_standard(Zone *zone)
void AppendToText(RegExpText *text, Zone *zone) override
@ CONTAINS_SPLIT_SURROGATE
ZoneList< CharacterRange > * ranges(Zone *zone)
bool is_case_folded() const
ClassRangesFlags class_ranges_flags_
CharacterSet character_set() const
RegExpClassRanges(Zone *zone, ZoneList< CharacterRange > *ranges, ClassRangesFlags class_ranges_flags=ClassRangesFlags())
const bool may_contain_strings_
bool IsTextElement() override
OperationType operation() const
static RegExpClassSetOperand * ComputeExpression(RegExpTree *root, ZoneList< CharacterRange > *temp_ranges, Zone *zone)
ZoneList< RegExpTree * > * operands()
const ZoneList< RegExpTree * > * operands() const
static RegExpClassSetExpression * Empty(Zone *zone, bool is_negated)
bool may_contain_strings() const
const OperationType operation_
RegExpClassSetExpression(OperationType op, bool is_negated, bool may_contain_strings, ZoneList< RegExpTree * > *operands)
DECL_BOILERPLATE(ClassSetExpression)
ZoneList< RegExpTree * > * operands_
ZoneList< CharacterRange > * ranges_
DECL_BOILERPLATE(ClassSetOperand)
CharacterClassStrings * strings_
ZoneList< CharacterRange > * ranges()
bool IsTextElement() override
void Intersect(RegExpClassSetOperand *other, ZoneList< CharacterRange > *temp_ranges, Zone *zone)
RegExpClassSetOperand(ZoneList< CharacterRange > *ranges, CharacterClassStrings *strings)
CharacterClassStrings * strings()
void Union(RegExpClassSetOperand *other, Zone *zone)
void Subtract(RegExpClassSetOperand *other, ZoneList< CharacterRange > *temp_ranges, Zone *zone)
DECL_BOILERPLATE(Disjunction)
bool IsAnchoredAtStart() override
RegExpDisjunction(ZoneList< RegExpTree * > *alternatives)
ZoneList< RegExpTree * > * alternatives() const
ZoneList< RegExpTree * > * alternatives_
Interval CaptureRegisters() override
void RationalizeConsecutiveAtoms(RegExpCompiler *compiler)
bool IsAnchoredAtEnd() override
void FixSingleCharacterDisjunctions(RegExpCompiler *compiler)
bool SortConsecutiveAtoms(RegExpCompiler *compiler)
RegExpTree * body() const
bool IsAnchoredAtStart() override
Interval CaptureRegisters() override
RegExpFlags flags() const
bool IsAnchoredAtEnd() override
RegExpGroup(RegExpTree *body, RegExpFlags flags)
RegExpNode * on_match_success() const
RegExpNode * on_match_success_
RegExpNode * ForMatch(RegExpNode *match)
int stack_pointer_register_
Builder(bool is_positive, RegExpNode *on_success, int stack_pointer_register, int position_register, int capture_register_count=0, int capture_register_start=0)
bool IsAnchoredAtStart() override
RegExpTree * body() const
RegExpLookaround(RegExpTree *body, bool is_positive, int capture_count, int capture_from, Type type, int index)
Interval CaptureRegisters() override
DECL_BOILERPLATE(Lookaround)
int capture_count() const
QuantifierType quantifier_type_
QuantifierType quantifier_type() const
bool is_non_greedy() const
bool is_possessive() const
Interval CaptureRegisters() override
DECL_BOILERPLATE(Quantifier)
RegExpQuantifier(int min, int max, QuantifierType type, int index, RegExpTree *body)
RegExpTree * body() const
static RegExpNode * ToNode(int min, int max, bool is_greedy, RegExpTree *body, RegExpCompiler *compiler, RegExpNode *on_success, bool not_at_start=false)
void AppendToText(RegExpText *text, Zone *zone) override
ZoneList< TextElement > elements_
ZoneList< TextElement > * elements()
void AddElement(TextElement elm, Zone *zone)
bool IsTextElement() override
virtual RegExpNode * ToNode(RegExpCompiler *compiler, RegExpNode *on_success)=0
virtual bool IsAnchoredAtStart()
virtual bool IsAnchoredAtEnd()
virtual int min_match()=0
virtual void AppendToText(RegExpText *text, Zone *zone)
static const int kInfinity
virtual ~RegExpTree()=default
virtual Interval CaptureRegisters()
virtual int max_match()=0
virtual bool IsTextElement()
virtual void * Accept(RegExpVisitor *visitor, void *data)=0
V8_EXPORT_PRIVATE std::ostream & Print(std::ostream &os, Zone *zone)
virtual ~RegExpVisitor()=default
RegExpTree * tree() const
TextType text_type() const
TextElement(TextType text_type, RegExpTree *tree)
RegExpClassRanges * class_ranges() const
static TextElement ClassRanges(RegExpClassRanges *class_ranges)
void set_cp_offset(int cp_offset)
static TextElement Atom(RegExpAtom *atom)
RegExpAtom * atom() const
void Add(const T &element, Zone *zone)
#define MAKE_CASE(TYPE, Name, name)
bool operator!=(ExternalReference lhs, ExternalReference rhs)
bool operator==(ExternalReference lhs, ExternalReference rhs)
#define FOR_EACH_REG_EXP_TREE_TYPE(VISIT)
#define MAKE_ASTYPE(Name)
#define DCHECK_NOT_NULL(val)
#define DCHECK(condition)
#define V8_EXPORT_PRIVATE
bool operator()(base::Vector< const base::uc32 > lhs, base::Vector< const base::uc32 > rhs) const