Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb_re2::SimplifyWalker Class Reference
Inheritance diagram for duckdb_re2::SimplifyWalker:
Collaboration diagram for duckdb_re2::SimplifyWalker:

Public Member Functions

virtual Regexp * PreVisit (Regexp *re, Regexp *parent_arg, bool *stop)
virtual Regexp * PostVisit (Regexp *re, Regexp *parent_arg, Regexp *pre_arg, Regexp **child_args, int nchild_args)
virtual Regexp * Copy (Regexp *re)
virtual Regexp * ShortVisit (Regexp *re, Regexp *parent_arg)
Public Member Functions inherited from duckdb_re2::Regexp::Walker< Regexp * >
virtual Regexp * PreVisit (Regexp *re, Regexp *parent_arg, bool *stop)
virtual Regexp * PostVisit (Regexp *re, Regexp *parent_arg, Regexp *pre_arg, Regexp **child_args, int nchild_args)
virtual Regexp * Copy (Regexp *arg)
Regexp * Walk (Regexp *re, Regexp *top_arg)
Regexp * WalkExponential (Regexp *re, Regexp *top_arg, int max_visits)
void Reset ()
bool stopped_early ()

Private Member Functions

 SimplifyWalker (const SimplifyWalker &)=delete
SimplifyWalker & operator= (const SimplifyWalker &)=delete

Static Private Member Functions

static Regexp * Concat2 (Regexp *re1, Regexp *re2, Regexp::ParseFlags flags)
static Regexp * SimplifyRepeat (Regexp *re, int min, int max, Regexp::ParseFlags parse_flags)
static Regexp * SimplifyCharClass (Regexp *re)

Constructor & Destructor Documentation

◆ SimplifyWalker()

duckdb_re2::SimplifyWalker::SimplifyWalker ( )
inline
474371{}

Member Function Documentation

◆ PreVisit()

Regexp * duckdb_re2::SimplifyWalker::PreVisit ( Regexp * re,
Regexp * parent_arg,
bool * stop )
virtual
474689 {
474690 if (re->simple()) {
474691 *stop = true;
474692 return re->Incref();
474693 }
474694 return NULL;
474695}

◆ PostVisit()

Regexp * duckdb_re2::SimplifyWalker::PostVisit ( Regexp * re,
Regexp * parent_arg,
Regexp * pre_arg,
Regexp ** child_args,
int nchild_args )
virtual
474701 {
474702 switch (re->op()) {
474703 case kRegexpNoMatch:
474704 case kRegexpEmptyMatch:
474705 case kRegexpLiteral:
474706 case kRegexpLiteralString:
474707 case kRegexpBeginLine:
474708 case kRegexpEndLine:
474709 case kRegexpBeginText:
474710 case kRegexpWordBoundary:
474711 case kRegexpNoWordBoundary:
474712 case kRegexpEndText:
474713 case kRegexpAnyChar:
474714 case kRegexpAnyByte:
474715 case kRegexpHaveMatch:
474716 // All these are always simple.
474717 re->simple_ = true;
474718 return re->Incref();
474719
474720 case kRegexpConcat:
474721 case kRegexpAlternate: {
474722 // These are simple as long as the subpieces are simple.
474723 if (!ChildArgsChanged(re, child_args)) {
474724 re->simple_ = true;
474725 return re->Incref();
474726 }
474727 Regexp* nre = new Regexp(re->op(), re->parse_flags());
474728 nre->AllocSub(re->nsub());
474729 Regexp** nre_subs = nre->sub();
474730 for (int i = 0; i < re->nsub(); i++)
474731 nre_subs[i] = child_args[i];
474732 nre->simple_ = true;
474733 return nre;
474734 }
474735
474736 case kRegexpCapture: {
474737 Regexp* newsub = child_args[0];
474738 if (newsub == re->sub()[0]) {
474739 newsub->Decref();
474740 re->simple_ = true;
474741 return re->Incref();
474742 }
474743 Regexp* nre = new Regexp(kRegexpCapture, re->parse_flags());
474744 nre->AllocSub(1);
474745 nre->sub()[0] = newsub;
474746 nre->arguments.capture.cap_ = re->cap();
474747 nre->simple_ = true;
474748 return nre;
474749 }
474750
474751 case kRegexpStar:
474752 case kRegexpPlus:
474753 case kRegexpQuest: {
474754 Regexp* newsub = child_args[0];
474755 // Special case: repeat the empty string as much as
474756 // you want, but it's still the empty string.
474757 if (newsub->op() == kRegexpEmptyMatch)
474758 return newsub;
474759
474760 // These are simple as long as the subpiece is simple.
474761 if (newsub == re->sub()[0]) {
474762 newsub->Decref();
474763 re->simple_ = true;
474764 return re->Incref();
474765 }
474766
474767 // These are also idempotent if flags are constant.
474768 if (re->op() == newsub->op() &&
474769 re->parse_flags() == newsub->parse_flags())
474770 return newsub;
474771
474772 Regexp* nre = new Regexp(re->op(), re->parse_flags());
474773 nre->AllocSub(1);
474774 nre->sub()[0] = newsub;
474775 nre->simple_ = true;
474776 return nre;
474777 }
474778
474779 case kRegexpRepeat: {
474780 Regexp* newsub = child_args[0];
474781 // Special case: repeat the empty string as much as
474782 // you want, but it's still the empty string.
474783 if (newsub->op() == kRegexpEmptyMatch)
474784 return newsub;
474785
474786 Regexp* nre = SimplifyRepeat(newsub, re->arguments.repeat.min_, re->arguments.repeat.max_,
474787 re->parse_flags());
474788 newsub->Decref();
474789 nre->simple_ = true;
474790 return nre;
474791 }
474792
474793 case kRegexpCharClass: {
474794 Regexp* nre = SimplifyCharClass(re);
474795 nre->simple_ = true;
474796 return nre;
474797 }
474798 }
474799
474800 LOG(ERROR) << "Simplify case not handled: " << re->op();
474801 return re->Incref();
474802}

◆ Copy()

Regexp * duckdb_re2::SimplifyWalker::Copy ( Regexp * re)
virtual
474677 {
474678 return re->Incref();
474679}

◆ ShortVisit()

Regexp * duckdb_re2::SimplifyWalker::ShortVisit ( Regexp * re,
Regexp * parent_arg )
virtual

Implements duckdb_re2::Regexp::Walker< Regexp * >.

474681 {
474682 // Should never be called: we use Walk(), not WalkExponential().
474683#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
474684 LOG(DFATAL) << "SimplifyWalker::ShortVisit called";
474685#endif
474686 return re->Incref();
474687}

◆ Concat2()

Regexp * duckdb_re2::SimplifyWalker::Concat2 ( Regexp * re1,
Regexp * re2,
Regexp::ParseFlags flags )
staticprivate
474807 {
474808 Regexp* re = new Regexp(kRegexpConcat, parse_flags);
474809 re->AllocSub(2);
474810 Regexp** subs = re->sub();
474811 subs[0] = re1;
474812 subs[1] = re2;
474813 return re;
474814}

◆ SimplifyRepeat()

Regexp * duckdb_re2::SimplifyWalker::SimplifyRepeat ( Regexp * re,
int min,
int max,
Regexp::ParseFlags parse_flags )
staticprivate
474823 {
474824 // x{n,} means at least n matches of x.
474825 if (max == -1) {
474826 // Special case: x{0,} is x*
474827 if (min == 0)
474828 return Regexp::Star(re->Incref(), f);
474829
474830 // Special case: x{1,} is x+
474831 if (min == 1)
474832 return Regexp::Plus(re->Incref(), f);
474833
474834 // General case: x{4,} is xxxx+
474835 PODArray<Regexp*> nre_subs(min);
474836 for (int i = 0; i < min-1; i++)
474837 nre_subs[i] = re->Incref();
474838 nre_subs[min-1] = Regexp::Plus(re->Incref(), f);
474839 return Regexp::Concat(nre_subs.data(), min, f);
474840 }
474841
474842 // Special case: (x){0} matches only empty string.
474843 if (min == 0 && max == 0)
474844 return new Regexp(kRegexpEmptyMatch, f);
474845
474846 // Special case: x{1} is just x.
474847 if (min == 1 && max == 1)
474848 return re->Incref();
474849
474850 // General case: x{n,m} means n copies of x and m copies of x?.
474851 // The machine will do less work if we nest the final m copies,
474852 // so that x{2,5} = xx(x(x(x)?)?)?
474853
474854 // Build leading prefix: xx. Capturing only on the last one.
474855 Regexp* nre = NULL;
474856 if (min > 0) {
474857 PODArray<Regexp*> nre_subs(min);
474858 for (int i = 0; i < min; i++)
474859 nre_subs[i] = re->Incref();
474860 nre = Regexp::Concat(nre_subs.data(), min, f);
474861 }
474862
474863 // Build and attach suffix: (x(x(x)?)?)?
474864 if (max > min) {
474865 Regexp* suf = Regexp::Quest(re->Incref(), f);
474866 for (int i = min+1; i < max; i++)
474867 suf = Regexp::Quest(Concat2(re->Incref(), suf, f), f);
474868 if (nre == NULL)
474869 nre = suf;
474870 else
474871 nre = Concat2(nre, suf, f);
474872 }
474873
474874 if (nre == NULL) {
474875 // Some degenerate case, like min > max, or min < max < 0.
474876 // This shouldn't happen, because the parser rejects such regexps.
474877 LOG(DFATAL) << "Malformed repeat " << re->ToString() << " " << min << " " << max;
474878 return new Regexp(kRegexpNoMatch, f);
474879 }
474880
474881 return nre;
474882}
static softfloat min()
static softfloat max()

◆ SimplifyCharClass()

Regexp * duckdb_re2::SimplifyWalker::SimplifyCharClass ( Regexp * re)
staticprivate
474886 {
474887 CharClass* cc = re->cc();
474888
474889 // Special cases
474890 if (cc->empty())
474891 return new Regexp(kRegexpNoMatch, re->parse_flags());
474892 if (cc->full())
474893 return new Regexp(kRegexpAnyChar, re->parse_flags());
474894
474895 return re->Incref();
474896}

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