Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::RegExpBuilder Class Reference

#include <regexp_parser.h>

Inheritance diagram for dart::RegExpBuilder:
dart::ZoneAllocated

Public Member Functions

 RegExpBuilder (RegExpFlags flags)
 
void AddCharacter (uint16_t character)
 
void AddUnicodeCharacter (uint32_t character)
 
void AddEscapedUnicodeCharacter (uint32_t character)
 
void AddEmpty ()
 
void AddCharacterClass (RegExpCharacterClass *cc)
 
void AddCharacterClassForDesugaring (uint32_t c)
 
void AddAtom (RegExpTree *tree)
 
void AddTerm (RegExpTree *tree)
 
void AddAssertion (RegExpTree *tree)
 
void NewAlternative ()
 
bool AddQuantifierToAtom (intptr_t min, intptr_t max, RegExpQuantifier::QuantifierType type)
 
RegExpTreeToRegExp ()
 
RegExpFlags flags () const
 
bool ignore_case () const
 
bool is_multi_line () const
 
bool is_dot_all () const
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Detailed Description

Definition at line 15 of file regexp_parser.h.

Constructor & Destructor Documentation

◆ RegExpBuilder()

dart::RegExpBuilder::RegExpBuilder ( RegExpFlags  flags)
explicit

Definition at line 23 of file regexp_parser.cc.

24 : zone_(Thread::Current()->zone()),
25 pending_empty_(false),
26 flags_(flags),
27 characters_(nullptr),
28 pending_surrogate_(kNoPendingSurrogate),
29 terms_(),
30 text_(),
31 alternatives_()
32#ifdef DEBUG
33 ,
34 last_added_(ADD_NONE)
35#endif
36{
37}
RegExpFlags flags() const
Definition: regexp_parser.h:38
static Thread * Current()
Definition: thread.h:362

Member Function Documentation

◆ AddAssertion()

void dart::RegExpBuilder::AddAssertion ( RegExpTree tree)

Definition at line 182 of file regexp_parser.cc.

182 {
183 FlushText();
184 terms_.Add(assert);
185 LAST(ADD_ASSERT);
186}
#define LAST(x)
Definition: regexp_parser.h:69

◆ AddAtom()

void dart::RegExpBuilder::AddAtom ( RegExpTree tree)

Definition at line 161 of file regexp_parser.cc.

161 {
162 if (term->IsEmpty()) {
163 AddEmpty();
164 return;
165 }
166 if (term->IsTextElement()) {
167 FlushCharacters();
168 text_.Add(term);
169 } else {
170 FlushText();
171 terms_.Add(term);
172 }
173 LAST(ADD_ATOM);
174}

◆ AddCharacter()

void dart::RegExpBuilder::AddCharacter ( uint16_t  character)

Definition at line 104 of file regexp_parser.cc.

104 {
105 FlushPendingSurrogate();
106 pending_empty_ = false;
107 if (NeedsDesugaringForIgnoreCase(c)) {
109 } else {
110 if (characters_ == nullptr) {
111 characters_ = new (Z) ZoneGrowableArray<uint16_t>(4);
112 }
113 characters_->Add(c);
114 LAST(ADD_CHAR);
115 }
116}
void Add(const T &value)
void AddCharacterClassForDesugaring(uint32_t c)
#define Z

◆ AddCharacterClass()

void dart::RegExpBuilder::AddCharacterClass ( RegExpCharacterClass cc)

Definition at line 146 of file regexp_parser.cc.

146 {
147 if (NeedsDesugaringForUnicode(cc)) {
148 // With /u, character class needs to be desugared, so it
149 // must be a standalone term instead of being part of a RegExpText.
150 AddTerm(cc);
151 } else {
152 AddAtom(cc);
153 }
154}
void AddTerm(RegExpTree *tree)
void AddAtom(RegExpTree *tree)

◆ AddCharacterClassForDesugaring()

void dart::RegExpBuilder::AddCharacterClassForDesugaring ( uint32_t  c)

Definition at line 156 of file regexp_parser.cc.

156 {
158 AddTerm(new (Z) RegExpCharacterClass(ranges, flags_));
159}
static CharacterRange Singleton(int32_t value)
Definition: regexp.h:37
static ZoneGrowableArray< CharacterRange > * List(Zone *zone, CharacterRange range)
Definition: regexp.h:47

◆ AddEmpty()

void dart::RegExpBuilder::AddEmpty ( )

Definition at line 142 of file regexp_parser.cc.

142 {
143 pending_empty_ = true;
144}

◆ AddEscapedUnicodeCharacter()

void dart::RegExpBuilder::AddEscapedUnicodeCharacter ( uint32_t  character)

Definition at line 134 of file regexp_parser.cc.

134 {
135 // A lead or trail surrogate parsed via escape sequence will not
136 // pair up with any preceding lead or following trail surrogate.
137 FlushPendingSurrogate();
139 FlushPendingSurrogate();
140}
void AddUnicodeCharacter(uint32_t character)

◆ AddQuantifierToAtom()

bool dart::RegExpBuilder::AddQuantifierToAtom ( intptr_t  min,
intptr_t  max,
RegExpQuantifier::QuantifierType  type 
)

Definition at line 269 of file regexp_parser.cc.

272 {
273 if (pending_empty_) {
274 pending_empty_ = false;
275 return true;
276 }
277 RegExpTree* atom;
278 if (characters_ != nullptr) {
279 DEBUG_ASSERT(last_added_ == ADD_CHAR);
280 // Last atom was character.
281
282 ZoneGrowableArray<uint16_t>* char_vector =
283 new (Z) ZoneGrowableArray<uint16_t>();
284 char_vector->AddArray(*characters_);
285 intptr_t num_chars = char_vector->length();
286 if (num_chars > 1) {
287 ZoneGrowableArray<uint16_t>* prefix =
288 new (Z) ZoneGrowableArray<uint16_t>();
289 for (intptr_t i = 0; i < num_chars - 1; i++) {
290 prefix->Add(char_vector->At(i));
291 }
292 text_.Add(new (Z) RegExpAtom(prefix, flags_));
293 ZoneGrowableArray<uint16_t>* tail = new (Z) ZoneGrowableArray<uint16_t>();
294 tail->Add(char_vector->At(num_chars - 1));
295 char_vector = tail;
296 }
297 characters_ = nullptr;
298 atom = new (Z) RegExpAtom(char_vector, flags_);
299 FlushText();
300 } else if (text_.length() > 0) {
301 DEBUG_ASSERT(last_added_ == ADD_ATOM);
302 atom = text_.RemoveLast();
303 FlushText();
304 } else if (terms_.length() > 0) {
305 DEBUG_ASSERT(last_added_ == ADD_ATOM);
306 atom = terms_.RemoveLast();
307 if (auto lookaround = atom->AsLookaround()) {
308 // With /u, lookarounds are not quantifiable.
309 if (is_unicode()) return false;
310 // Lookbehinds are not quantifiable.
311 if (lookaround->type() == RegExpLookaround::LOOKBEHIND) {
312 return false;
313 }
314 }
315 if (atom->max_match() == 0) {
316 // Guaranteed to only match an empty string.
317 LAST(ADD_TERM);
318 if (min == 0) {
319 return true;
320 }
321 terms_.Add(atom);
322 return true;
323 }
324 } else {
325 // Only call immediately after adding an atom or character!
326 UNREACHABLE();
327 }
328 terms_.Add(new (Z) RegExpQuantifier(min, max, quantifier_type, atom));
329 LAST(ADD_TERM);
330 return true;
331}
#define UNREACHABLE()
Definition: assert.h:248
#define DEBUG_ASSERT(cond)
Definition: assert.h:321
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ AddTerm()

void dart::RegExpBuilder::AddTerm ( RegExpTree tree)

Definition at line 176 of file regexp_parser.cc.

176 {
177 FlushText();
178 terms_.Add(term);
179 LAST(ADD_ATOM);
180}

◆ AddUnicodeCharacter()

void dart::RegExpBuilder::AddUnicodeCharacter ( uint32_t  character)

Definition at line 118 of file regexp_parser.cc.

118 {
119 if (c > static_cast<uint32_t>(Utf16::kMaxCodeUnit)) {
120 ASSERT(is_unicode());
121 uint16_t surrogates[2];
122 Utf16::Encode(c, surrogates);
123 AddLeadSurrogate(surrogates[0]);
124 AddTrailSurrogate(surrogates[1]);
125 } else if (is_unicode() && Utf16::IsLeadSurrogate(c)) {
126 AddLeadSurrogate(c);
127 } else if (is_unicode() && Utf16::IsTrailSurrogate(c)) {
128 AddTrailSurrogate(c);
129 } else {
130 AddCharacter(static_cast<uint16_t>(c));
131 }
132}
void AddCharacter(uint16_t character)
static constexpr int32_t kMaxCodeUnit
Definition: unicode.h:158
static void Encode(int32_t codepoint, uint16_t *dst)
Definition: unicode.cc:273
static bool IsLeadSurrogate(uint32_t ch)
Definition: unicode.h:126
static bool IsTrailSurrogate(uint32_t ch)
Definition: unicode.h:131
#define ASSERT(E)

◆ flags()

RegExpFlags dart::RegExpBuilder::flags ( ) const
inline

Definition at line 38 of file regexp_parser.h.

38{ return flags_; }

◆ ignore_case()

bool dart::RegExpBuilder::ignore_case ( ) const
inline

Definition at line 39 of file regexp_parser.h.

39{ return flags_.IgnoreCase(); }
bool IgnoreCase() const
Definition: object.h:12723

◆ is_dot_all()

bool dart::RegExpBuilder::is_dot_all ( ) const
inline

Definition at line 41 of file regexp_parser.h.

41{ return flags_.IsDotAll(); }
bool IsDotAll() const
Definition: object.h:12726

◆ is_multi_line()

bool dart::RegExpBuilder::is_multi_line ( ) const
inline

Definition at line 40 of file regexp_parser.h.

40{ return flags_.IsMultiLine(); }
bool IsMultiLine() const
Definition: object.h:12724

◆ NewAlternative()

void dart::RegExpBuilder::NewAlternative ( )

Definition at line 188 of file regexp_parser.cc.

188 {
189 FlushTerms();
190}

◆ ToRegExp()

RegExpTree * dart::RegExpBuilder::ToRegExp ( )

Definition at line 252 of file regexp_parser.cc.

252 {
253 FlushTerms();
254 intptr_t num_alternatives = alternatives_.length();
255 if (num_alternatives == 0) {
257 }
258 if (num_alternatives == 1) {
259 return alternatives_.Last();
260 }
261 ZoneGrowableArray<RegExpTree*>* alternatives =
262 new (Z) ZoneGrowableArray<RegExpTree*>();
263 for (intptr_t i = 0; i < alternatives_.length(); i++) {
264 alternatives->Add(alternatives_[i]);
265 }
266 return new (Z) RegExpDisjunction(alternatives);
267}
static RegExpEmpty * GetInstance()
Definition: regexp_ast.h:440

The documentation for this class was generated from the following files: