1 | /* |
2 | * Copyright (c) 2015-2017, Intel Corporation |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions are met: |
6 | * |
7 | * * Redistributions of source code must retain the above copyright notice, |
8 | * this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of Intel Corporation nor the names of its contributors |
13 | * may be used to endorse or promote products derived from this software |
14 | * without specific prior written permission. |
15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | |
29 | /** \file |
30 | * \brief: NFA Graph Builder: used by Glushkov construction to construct an |
31 | * NGHolder from a parsed expression. |
32 | */ |
33 | |
34 | #ifndef NG_BUILDER_H |
35 | #define NG_BUILDER_H |
36 | |
37 | #include "ue2common.h" |
38 | |
39 | #include "parser/position.h" |
40 | #include "util/noncopyable.h" |
41 | |
42 | #include <memory> |
43 | |
44 | namespace ue2 { |
45 | |
46 | class CharReach; |
47 | class ReportManager; |
48 | struct BuiltExpression; |
49 | struct CompileContext; |
50 | |
51 | class ParsedExpression; |
52 | |
53 | /** \brief Abstract builder interface. Use \ref makeNFABuilder to construct |
54 | * one. Used by GlushkovBuildState. */ |
55 | class NFABuilder : noncopyable { |
56 | public: |
57 | virtual ~NFABuilder(); |
58 | |
59 | virtual Position makePositions(size_t nPositions) = 0; |
60 | virtual Position getStart() const = 0; |
61 | virtual Position getStartDotStar() const = 0; |
62 | virtual Position getAccept() const = 0; |
63 | virtual Position getAcceptEOD() const = 0; |
64 | |
65 | virtual bool isSpecialState(Position p) const = 0; |
66 | |
67 | virtual void setNodeReportID(Position position, int offsetAdjust) = 0; |
68 | virtual void addCharReach(Position position, const CharReach &cr) = 0; |
69 | |
70 | /* or-in vertex assertions */ |
71 | virtual void setAssertFlag(Position position, u32 flag) = 0; |
72 | virtual u32 getAssertFlag(Position position) = 0; |
73 | |
74 | virtual void addVertex(Position p) = 0; |
75 | |
76 | virtual void addEdge(Position start, Position end) = 0; |
77 | |
78 | virtual bool hasEdge(Position start, Position end) const = 0; |
79 | |
80 | virtual u32 numVertices() const = 0; |
81 | |
82 | virtual void cloneRegion(Position first, Position last, |
83 | unsigned posOffset) = 0; |
84 | |
85 | /** |
86 | * \brief Returns the built NGHolder graph and ExpressionInfo. |
87 | * Note that this builder cannot be used after this call. |
88 | */ |
89 | virtual BuiltExpression getGraph() = 0; |
90 | }; |
91 | |
92 | /** Construct a usable NFABuilder. */ |
93 | std::unique_ptr<NFABuilder> makeNFABuilder(ReportManager &rm, |
94 | const CompileContext &cc, |
95 | const ParsedExpression &expr); |
96 | |
97 | } // namespace ue2 |
98 | |
99 | #endif |
100 | |