source: icGREP/icgrep-devel/icgrep/re/re_compiler.h @ 4532

Last change on this file since 4532 was 4520, checked in by cameron, 5 years ago

Favor FinaPostPositionByte? positioning; fix for lookahead assertion

File size: 4.0 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef RE_TO_PABLO_COMPILER_H
8#define RE_TO_PABLO_COMPILER_H
9
10#include <re/re_re.h>
11#include <re/re_seq.h>
12#include <cc/cc_compiler.h>
13
14#include <string>
15#include <list>
16#include <map>
17
18namespace cc {
19class CC_NameMap;
20}
21
22namespace pablo {
23class PabloBlock;
24class PabloAST;
25class Assign;
26class Var;
27}
28
29/*   Marker streams represent the results of matching steps.
30     Three types of marker streams are used internally.
31     FinalMatchByte markers are used for character classes and
32     other strings identified by a one bit at their final position.
33     InitialPostPositionByte markers are used to mark matches with
34     a 1 bit immediately after a match.   InitialPostPositionByte markers
35     are generally required whenever a regular expression element
36     can match the empty string (e.g., * and ? repeated items).
37     FinalPostPositionByte markers are used for single code unit
38     lookahead assertions. 
39*/
40
41namespace re {
42
43enum MarkerPosition {FinalMatchByte, InitialPostPositionByte, FinalPostPositionByte};
44
45struct MarkerType { 
46    MarkerPosition pos;
47    pablo::PabloAST * stream;
48};
49
50inline MarkerPosition markerPos(MarkerType m) {return m.pos;}
51
52inline pablo::PabloAST * markerVar(MarkerType m) {return m.stream;}
53   
54inline MarkerType makeMarker(MarkerPosition newpos, pablo::PabloAST * strm) {return {newpos, strm};}
55
56
57class RE_Compiler {
58public:
59
60    RE_Compiler(pablo::PabloBlock & baseCG);
61    void initializeRequiredStreams(cc::CC_Compiler & ccc);
62    void finalizeMatchResult(MarkerType match_result);
63    MarkerType compile(RE * re) {
64        return compile(re, mPB);
65    }
66
67private:
68
69    MarkerType compile(RE * re, pablo::PabloBlock & cg);
70    MarkerType AdvanceMarker(MarkerType m, MarkerPosition newpos, pablo::PabloBlock & pb);
71   
72    void AlignMarkers(MarkerType & m1, MarkerType & m2, pablo::PabloBlock & pb);
73   
74    pablo::PabloAST * getNamedCharacterClassStream(Name * name);
75    pablo::PabloAST * nextUnicodePosition(MarkerType m, pablo::PabloBlock & pb);
76    MarkerType process(RE * re, MarkerType marker, pablo::PabloBlock & pb);
77    MarkerType process(Name * name, MarkerType marker, pablo::PabloBlock & pb);
78    MarkerType process(Seq * seq, MarkerType marker, pablo::PabloBlock & pb);
79    MarkerType processSeqTail(Seq::iterator current, Seq::iterator end, int matchLenSoFar, MarkerType marker, pablo::PabloBlock & pb);
80    MarkerType process(Alt * alt, MarkerType marker, pablo::PabloBlock & pb);
81    MarkerType process(Assertion * a, MarkerType marker, pablo::PabloBlock & pb);
82    MarkerType process(Rep * rep, MarkerType marker, pablo::PabloBlock & pb);
83    MarkerType process(Diff * diff, MarkerType marker, pablo::PabloBlock & cg);
84    MarkerType process(Intersect * x, MarkerType marker, pablo::PabloBlock & cg);
85    pablo::PabloAST *consecutive1(pablo::PabloAST *repeated,  int repeated_lgth, int repeat_count, pablo::PabloBlock & pb);
86    pablo::PabloAST * reachable(pablo::PabloAST * repeated,  int repeated_lgth, int repeat_count, pablo::PabloBlock & pb);
87    static bool isFixedLength(RE * regexp);
88    MarkerType processLowerBound(RE * repeated,  int lb, MarkerType marker, pablo::PabloBlock & pb);
89    MarkerType processUnboundedRep(RE * repeated, MarkerType marker, pablo::PabloBlock & pb);
90    MarkerType processBoundedRep(RE * repeated, int ub, MarkerType marker, pablo::PabloBlock & pb);
91
92    pablo::PabloBlock &                             mPB;
93    pablo::Assign *                                 mLineFeed;
94    pablo::PabloAST *                               mCRLF;
95    pablo::PabloAST *                               mUnicodeLineBreak;
96    pablo::PabloAST *                               mInitial;
97    pablo::Assign *                                 mNonFinal;
98    pablo::PabloAST *                               mFinal;
99    int                                             mStarDepth;
100};
101
102}
103
104#endif // COMPILER_H
Note: See TracBrowser for help on using the repository browser.