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

Unified Diff: src/ast/ast.h

Issue 1565183002: [regexp] move regexp parser into own files. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix test compile Created 4 years, 11 months 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 | « BUILD.gn ('k') | src/ast/ast.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/ast.h
diff --git a/src/ast/ast.h b/src/ast/ast.h
index 8c9ef323ad29b422fb735a92c0ba154e905cac9e..a6a6afda5d49003dd6d6c997eb453bec57bd9d0d 100644
--- a/src/ast/ast.h
+++ b/src/ast/ast.h
@@ -16,7 +16,6 @@
#include "src/isolate.h"
#include "src/list.h"
#include "src/parsing/token.h"
-#include "src/regexp/jsregexp.h"
#include "src/runtime/runtime.h"
#include "src/small-pointer-list.h"
#include "src/types.h"
@@ -111,19 +110,6 @@ class MaterializedLiteral;
class Statement;
class TypeFeedbackOracle;
-class RegExpAlternative;
-class RegExpAssertion;
-class RegExpAtom;
-class RegExpBackReference;
-class RegExpCapture;
-class RegExpCharacterClass;
-class RegExpCompiler;
-class RegExpDisjunction;
-class RegExpEmpty;
-class RegExpLookaround;
-class RegExpQuantifier;
-class RegExpText;
-
#define DEF_FORWARD_DECLARATION(type) class type;
AST_NODE_LIST(DEF_FORWARD_DECLARATION)
#undef DEF_FORWARD_DECLARATION
@@ -2917,357 +2903,6 @@ class EmptyParentheses final : public Expression {
// ----------------------------------------------------------------------------
-// Regular expressions
-
-
-class RegExpVisitor BASE_EMBEDDED {
- public:
- virtual ~RegExpVisitor() { }
-#define MAKE_CASE(Name) \
- virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
- FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
-#undef MAKE_CASE
-};
-
-
-class RegExpTree : public ZoneObject {
- public:
- static const int kInfinity = kMaxInt;
- virtual ~RegExpTree() {}
- virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
- virtual RegExpNode* ToNode(RegExpCompiler* compiler,
- RegExpNode* on_success) = 0;
- virtual bool IsTextElement() { return false; }
- virtual bool IsAnchoredAtStart() { return false; }
- virtual bool IsAnchoredAtEnd() { return false; }
- virtual int min_match() = 0;
- virtual int max_match() = 0;
- // Returns the interval of registers used for captures within this
- // expression.
- virtual Interval CaptureRegisters() { return Interval::Empty(); }
- virtual void AppendToText(RegExpText* text, Zone* zone);
- std::ostream& Print(std::ostream& os, Zone* zone); // NOLINT
-#define MAKE_ASTYPE(Name) \
- virtual RegExp##Name* As##Name(); \
- virtual bool Is##Name();
- FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
-#undef MAKE_ASTYPE
-};
-
-
-class RegExpDisjunction final : public RegExpTree {
- public:
- explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- RegExpDisjunction* AsDisjunction() override;
- Interval CaptureRegisters() override;
- bool IsDisjunction() override;
- bool IsAnchoredAtStart() override;
- bool IsAnchoredAtEnd() override;
- int min_match() override { return min_match_; }
- int max_match() override { return max_match_; }
- ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
- private:
- bool SortConsecutiveAtoms(RegExpCompiler* compiler);
- void RationalizeConsecutiveAtoms(RegExpCompiler* compiler);
- void FixSingleCharacterDisjunctions(RegExpCompiler* compiler);
- ZoneList<RegExpTree*>* alternatives_;
- int min_match_;
- int max_match_;
-};
-
-
-class RegExpAlternative final : public RegExpTree {
- public:
- explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- RegExpAlternative* AsAlternative() override;
- Interval CaptureRegisters() override;
- bool IsAlternative() override;
- bool IsAnchoredAtStart() override;
- bool IsAnchoredAtEnd() override;
- int min_match() override { return min_match_; }
- int max_match() override { return max_match_; }
- ZoneList<RegExpTree*>* nodes() { return nodes_; }
- private:
- ZoneList<RegExpTree*>* nodes_;
- int min_match_;
- int max_match_;
-};
-
-
-class RegExpAssertion final : public RegExpTree {
- public:
- enum AssertionType {
- START_OF_LINE,
- START_OF_INPUT,
- END_OF_LINE,
- END_OF_INPUT,
- BOUNDARY,
- NON_BOUNDARY
- };
- explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { }
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- RegExpAssertion* AsAssertion() override;
- bool IsAssertion() override;
- bool IsAnchoredAtStart() override;
- bool IsAnchoredAtEnd() override;
- int min_match() override { return 0; }
- int max_match() override { return 0; }
- AssertionType assertion_type() { return assertion_type_; }
- private:
- AssertionType assertion_type_;
-};
-
-
-class CharacterSet final BASE_EMBEDDED {
- public:
- explicit CharacterSet(uc16 standard_set_type)
- : ranges_(NULL),
- standard_set_type_(standard_set_type) {}
- explicit CharacterSet(ZoneList<CharacterRange>* ranges)
- : ranges_(ranges),
- standard_set_type_(0) {}
- ZoneList<CharacterRange>* ranges(Zone* zone);
- uc16 standard_set_type() { return standard_set_type_; }
- void set_standard_set_type(uc16 special_set_type) {
- standard_set_type_ = special_set_type;
- }
- bool is_standard() { return standard_set_type_ != 0; }
- void Canonicalize();
- private:
- ZoneList<CharacterRange>* ranges_;
- // If non-zero, the value represents a standard set (e.g., all whitespace
- // characters) without having to expand the ranges.
- uc16 standard_set_type_;
-};
-
-
-class RegExpCharacterClass final : public RegExpTree {
- public:
- RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
- : set_(ranges),
- is_negated_(is_negated) { }
- explicit RegExpCharacterClass(uc16 type)
- : set_(type),
- is_negated_(false) { }
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- RegExpCharacterClass* AsCharacterClass() override;
- bool IsCharacterClass() override;
- bool IsTextElement() override { return true; }
- int min_match() override { return 1; }
- int max_match() override { return 1; }
- void AppendToText(RegExpText* text, Zone* zone) override;
- CharacterSet character_set() { return set_; }
- // TODO(lrn): Remove need for complex version if is_standard that
- // recognizes a mangled standard set and just do { return set_.is_special(); }
- bool is_standard(Zone* zone);
- // Returns a value representing the standard character set if is_standard()
- // returns true.
- // Currently used values are:
- // s : unicode whitespace
- // S : unicode non-whitespace
- // w : ASCII word character (digit, letter, underscore)
- // W : non-ASCII word character
- // d : ASCII digit
- // D : non-ASCII digit
- // . : non-unicode non-newline
- // * : All characters
- uc16 standard_type() { return set_.standard_set_type(); }
- ZoneList<CharacterRange>* ranges(Zone* zone) { return set_.ranges(zone); }
- bool is_negated() { return is_negated_; }
-
- private:
- CharacterSet set_;
- bool is_negated_;
-};
-
-
-class RegExpAtom final : public RegExpTree {
- public:
- explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- RegExpAtom* AsAtom() override;
- bool IsAtom() override;
- bool IsTextElement() override { return true; }
- int min_match() override { return data_.length(); }
- int max_match() override { return data_.length(); }
- void AppendToText(RegExpText* text, Zone* zone) override;
- Vector<const uc16> data() { return data_; }
- int length() { return data_.length(); }
- private:
- Vector<const uc16> data_;
-};
-
-
-class RegExpText final : public RegExpTree {
- public:
- explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- RegExpText* AsText() override;
- bool IsText() override;
- bool IsTextElement() override { return true; }
- int min_match() override { return length_; }
- int max_match() override { return length_; }
- void AppendToText(RegExpText* text, Zone* zone) override;
- void AddElement(TextElement elm, Zone* zone) {
- elements_.Add(elm, zone);
- length_ += elm.length();
- }
- ZoneList<TextElement>* elements() { return &elements_; }
- private:
- ZoneList<TextElement> elements_;
- int length_;
-};
-
-
-class RegExpQuantifier final : public RegExpTree {
- public:
- enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE };
- RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body)
- : body_(body),
- min_(min),
- max_(max),
- min_match_(min * body->min_match()),
- quantifier_type_(type) {
- if (max > 0 && body->max_match() > kInfinity / max) {
- max_match_ = kInfinity;
- } else {
- max_match_ = max * body->max_match();
- }
- }
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- static RegExpNode* ToNode(int min,
- int max,
- bool is_greedy,
- RegExpTree* body,
- RegExpCompiler* compiler,
- RegExpNode* on_success,
- bool not_at_start = false);
- RegExpQuantifier* AsQuantifier() override;
- Interval CaptureRegisters() override;
- bool IsQuantifier() override;
- int min_match() override { return min_match_; }
- int max_match() override { return max_match_; }
- int min() { return min_; }
- int max() { return max_; }
- bool is_possessive() { return quantifier_type_ == POSSESSIVE; }
- bool is_non_greedy() { return quantifier_type_ == NON_GREEDY; }
- bool is_greedy() { return quantifier_type_ == GREEDY; }
- RegExpTree* body() { return body_; }
-
- private:
- RegExpTree* body_;
- int min_;
- int max_;
- int min_match_;
- int max_match_;
- QuantifierType quantifier_type_;
-};
-
-
-class RegExpCapture final : public RegExpTree {
- public:
- explicit RegExpCapture(int index) : body_(NULL), index_(index) {}
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- static RegExpNode* ToNode(RegExpTree* body,
- int index,
- RegExpCompiler* compiler,
- RegExpNode* on_success);
- RegExpCapture* AsCapture() override;
- bool IsAnchoredAtStart() override;
- bool IsAnchoredAtEnd() override;
- Interval CaptureRegisters() override;
- bool IsCapture() override;
- int min_match() override { return body_->min_match(); }
- int max_match() override { return body_->max_match(); }
- RegExpTree* body() { return body_; }
- void set_body(RegExpTree* body) { body_ = body; }
- int index() { return index_; }
- static int StartRegister(int index) { return index * 2; }
- static int EndRegister(int index) { return index * 2 + 1; }
-
- private:
- RegExpTree* body_;
- int index_;
-};
-
-
-class RegExpLookaround final : public RegExpTree {
- public:
- enum Type { LOOKAHEAD, LOOKBEHIND };
-
- RegExpLookaround(RegExpTree* body, bool is_positive, int capture_count,
- int capture_from, Type type)
- : body_(body),
- is_positive_(is_positive),
- capture_count_(capture_count),
- capture_from_(capture_from),
- type_(type) {}
-
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- RegExpLookaround* AsLookaround() override;
- Interval CaptureRegisters() override;
- bool IsLookaround() override;
- bool IsAnchoredAtStart() override;
- int min_match() override { return 0; }
- int max_match() override { return 0; }
- RegExpTree* body() { return body_; }
- bool is_positive() { return is_positive_; }
- int capture_count() { return capture_count_; }
- int capture_from() { return capture_from_; }
- Type type() { return type_; }
-
- private:
- RegExpTree* body_;
- bool is_positive_;
- int capture_count_;
- int capture_from_;
- Type type_;
-};
-
-
-class RegExpBackReference final : public RegExpTree {
- public:
- explicit RegExpBackReference(RegExpCapture* capture)
- : capture_(capture) { }
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- RegExpBackReference* AsBackReference() override;
- bool IsBackReference() override;
- int min_match() override { return 0; }
- // The back reference may be recursive, e.g. /(\2)(\1)/. To avoid infinite
- // recursion, we give up. Ignorance is bliss.
- int max_match() override { return kInfinity; }
- int index() { return capture_->index(); }
- RegExpCapture* capture() { return capture_; }
- private:
- RegExpCapture* capture_;
-};
-
-
-class RegExpEmpty final : public RegExpTree {
- public:
- RegExpEmpty() { }
- void* Accept(RegExpVisitor* visitor, void* data) override;
- RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
- RegExpEmpty* AsEmpty() override;
- bool IsEmpty() override;
- int min_match() override { return 0; }
- int max_match() override { return 0; }
-};
-
-
-// ----------------------------------------------------------------------------
// Basic visitor
// - leaf node visitors are abstract.
« no previous file with comments | « BUILD.gn ('k') | src/ast/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698