Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Unified Diff: runtime/vm/regexp_parser.h

Issue 683433003: Integrate the Irregexp Regular Expression Engine. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: more comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/regexp_ast.cc ('k') | runtime/vm/regexp_parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/regexp_parser.h
diff --git a/runtime/vm/regexp_parser.h b/runtime/vm/regexp_parser.h
index 42cedd4d3469e01eba9ceee433280c6d063d7e91..3030782b881a24db920be4002b351f0e58a7aee9 100644
--- a/runtime/vm/regexp_parser.h
+++ b/runtime/vm/regexp_parser.h
@@ -5,17 +5,18 @@
#ifndef VM_REGEXP_PARSER_H_
#define VM_REGEXP_PARSER_H_
-// SNIP
+#include "vm/allocation.h"
+#include "vm/growable_array.h"
+#include "vm/regexp_ast.h"
namespace dart {
-// SNIP
-
// Accumulates RegExp atoms and assertions into lists of terms and alternatives.
-class RegExpBuilder: public ZoneObject {
+class RegExpBuilder: public ZoneAllocated {
public:
- explicit RegExpBuilder(Zone* zone);
- void AddCharacter(uc16 character);
+ RegExpBuilder();
+
+ void AddCharacter(uint16_t character);
// "Adds" an empty expression. Does nothing except consume a
// following quantifier
void AddEmpty();
@@ -23,21 +24,22 @@ class RegExpBuilder: public ZoneObject {
void AddAssertion(RegExpTree* tree);
void NewAlternative(); // '|'
void AddQuantifierToAtom(
- int min, int max, RegExpQuantifier::QuantifierType type);
+ intptr_t min, intptr_t max, RegExpQuantifier::QuantifierType type);
RegExpTree* ToRegExp();
private:
void FlushCharacters();
void FlushText();
void FlushTerms();
- Zone* zone() const { return zone_; }
- Zone* zone_;
+ Isolate* isolate() const { return isolate_; }
+
+ Isolate* isolate_;
bool pending_empty_;
- ZoneList<uc16>* characters_;
- BufferedZoneList<RegExpTree, 2> terms_;
- BufferedZoneList<RegExpTree, 2> text_;
- BufferedZoneList<RegExpTree, 2> alternatives_;
+ ZoneGrowableArray<uint16_t>* characters_;
+ GrowableArray<RegExpTree*> terms_;
+ GrowableArray<RegExpTree*> text_;
+ GrowableArray<RegExpTree*> alternatives_;
#ifdef DEBUG
enum {ADD_NONE, ADD_CHAR, ADD_TERM, ADD_ASSERT, ADD_ATOM} last_added_;
#define LAST(x) last_added_ = x;
@@ -46,18 +48,17 @@ class RegExpBuilder: public ZoneObject {
#endif
};
-
-class RegExpParser BASE_EMBEDDED {
+class RegExpParser : public ValueObject {
public:
- RegExpParser(FlatStringReader* in,
- Handle<String>* error,
- bool multiline_mode,
- Zone* zone);
+ RegExpParser(const String& in,
+ String* error,
+ bool multiline_mode);
+
+ static bool ParseFunction(ParsedFunction* parsed_function);
- static bool ParseRegExp(FlatStringReader* input,
+ static bool ParseRegExp(const String& input,
bool multiline,
- RegExpCompileData* result,
- Zone* zone);
+ RegExpCompileData* result);
RegExpTree* ParsePattern();
RegExpTree* ParseDisjunction();
@@ -66,41 +67,42 @@ class RegExpParser BASE_EMBEDDED {
// Parses a {...,...} quantifier and stores the range in the given
// out parameters.
- bool ParseIntervalQuantifier(int* min_out, int* max_out);
+ bool ParseIntervalQuantifier(intptr_t* min_out, intptr_t* max_out);
// Parses and returns a single escaped character. The character
// must not be 'b' or 'B' since they are usually handle specially.
- uc32 ParseClassCharacterEscape();
+ uint32_t ParseClassCharacterEscape();
// Checks whether the following is a length-digit hexadecimal number,
// and sets the value if it is.
- bool ParseHexEscape(int length, uc32* value);
+ bool ParseHexEscape(intptr_t length, uint32_t* value);
- uc32 ParseOctalLiteral();
+ uint32_t ParseOctalLiteral();
// Tries to parse the input as a back reference. If successful it
// stores the result in the output parameter and returns true. If
// it fails it will push back the characters read so the same characters
// can be reparsed.
- bool ParseBackReferenceIndex(int* index_out);
+ bool ParseBackReferenceIndex(intptr_t* index_out);
- CharacterRange ParseClassAtom(uc16* char_class);
- RegExpTree* ReportError(Vector<const char> message);
+ CharacterRange ParseClassAtom(uint16_t* char_class);
+ void ReportError(const char* message);
void Advance();
- void Advance(int dist);
- void Reset(int pos);
+ void Advance(intptr_t dist);
+ void Reset(intptr_t pos);
// Reports whether the pattern might be used as a literal search string.
// Only use if the result of the parse is a single atom node.
bool simple();
bool contains_anchor() { return contains_anchor_; }
void set_contains_anchor() { contains_anchor_ = true; }
- int captures_started() { return captures_ == NULL ? 0 : captures_->length(); }
- int position() { return next_pos_ - 1; }
+ intptr_t captures_started() { return captures_ == NULL ?
+ 0 : captures_->length(); }
+ intptr_t position() { return next_pos_ - 1; }
bool failed() { return failed_; }
- static const int kMaxCaptures = 1 << 16;
- static const uc32 kEndMarker = (1 << 21);
+ static const intptr_t kMaxCaptures = 1 << 16;
+ static const uint32_t kEndMarker = (1 << 21);
private:
enum SubexpressionType {
@@ -111,14 +113,14 @@ class RegExpParser BASE_EMBEDDED {
GROUPING
};
- class RegExpParserState : public ZoneObject {
+ class RegExpParserState : public ZoneAllocated {
public:
RegExpParserState(RegExpParserState* previous_state,
SubexpressionType group_type,
- int disjunction_capture_index,
- Zone* zone)
+ intptr_t disjunction_capture_index,
+ Isolate *isolate)
: previous_state_(previous_state),
- builder_(new(zone) RegExpBuilder(zone)),
+ builder_(new(isolate) RegExpBuilder()),
group_type_(group_type),
disjunction_capture_index_(disjunction_capture_index) {}
// Parser state of containing expression, if any.
@@ -131,7 +133,7 @@ class RegExpParser BASE_EMBEDDED {
// Index in captures array of first capture in this sub-expression, if any.
// Also the capture index of this sub-expression itself, if group_type
// is CAPTURE.
- int capture_index() { return disjunction_capture_index_; }
+ intptr_t capture_index() { return disjunction_capture_index_; }
private:
// Linked list implementation of stack of states.
@@ -141,28 +143,26 @@ class RegExpParser BASE_EMBEDDED {
// Stored disjunction type (capture, look-ahead or grouping), if any.
SubexpressionType group_type_;
// Stored disjunction's capture index (if any).
- int disjunction_capture_index_;
+ intptr_t disjunction_capture_index_;
};
Isolate* isolate() { return isolate_; }
- Zone* zone() const { return zone_; }
- uc32 current() { return current_; }
+ uint32_t current() { return current_; }
bool has_more() { return has_more_; }
- bool has_next() { return next_pos_ < in()->length(); }
- uc32 Next();
- FlatStringReader* in() { return in_; }
+ bool has_next() { return next_pos_ < in().Length(); }
+ uint32_t Next();
+ const String& in() { return in_; }
void ScanForCaptures();
Isolate* isolate_;
- Zone* zone_;
- Handle<String>* error_;
- ZoneList<RegExpCapture*>* captures_;
- FlatStringReader* in_;
- uc32 current_;
- int next_pos_;
+ String* error_;
+ ZoneGrowableArray<RegExpCapture*>* captures_;
+ const String& in_;
+ uint32_t current_;
+ intptr_t next_pos_;
// The capture count is only valid after we have scanned for captures.
- int capture_count_;
+ intptr_t capture_count_;
bool has_more_;
bool multiline_;
bool simple_;
@@ -171,8 +171,6 @@ class RegExpParser BASE_EMBEDDED {
bool failed_;
};
-// SNIP
-
} // namespace dart
#endif // VM_REGEXP_PARSER_H_
« no previous file with comments | « runtime/vm/regexp_ast.cc ('k') | runtime/vm/regexp_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698