-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredicate.hpp
95 lines (66 loc) · 2.31 KB
/
predicate.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2010 Roy Sharon <[email protected]>
// See project repositry at <https://github.com/roysharon/Uniclasser>
// Using this file is subject to the MIT License <http://creativecommons.org/licenses/MIT/>
#ifndef PREDICATE_H
#define PREDICATE_H
#include "codevalue.hpp"
struct IPredicate;
struct Predicate;
struct TerminalPredicate;
struct AndPredicate;
struct OrPredicate;
struct TernaryPredicate;
#include "generator.hpp"
struct IPredicate : public IGeneratable
{
virtual bool push(IPredicate *p) = 0;
};
struct Predicate : public IPredicate
{
Predicate() : predicate(0) {}
virtual ~Predicate() { delete predicate; }
virtual bool push(IPredicate *p);
virtual void accept(IGenerator &generator);
IPredicate *predicate;
};
struct TerminalPredicate : public IPredicate
{
TerminalPredicate(bool should_succeed, codevalue tested_bits = 0, codevalue tested_value = 0)
: should_succeed(should_succeed), tested_bits(tested_bits), tested_value(tested_value) {}
virtual bool push(IPredicate *p) { return false; }
virtual void accept(IGenerator &generator);
bool should_succeed;
codevalue tested_bits, tested_value;
};
struct AndPredicate : public IPredicate
{
AndPredicate(IPredicate *lhs) : complete(false), lhs(lhs), rhs(0) {}
virtual ~AndPredicate() { delete lhs; delete rhs; }
virtual bool push(IPredicate *p);
virtual void accept(IGenerator &generator);
bool complete;
IPredicate *lhs, *rhs;
};
struct OrPredicate : public IPredicate
{
OrPredicate(IPredicate *lhs) : complete(false), lhs(lhs), rhs(0) {}
virtual ~OrPredicate() { delete lhs; delete rhs; }
virtual bool push(IPredicate *p);
virtual void accept(IGenerator &generator);
bool complete;
IPredicate *lhs, *rhs;
};
struct TernaryPredicate : public IPredicate
{
TernaryPredicate(codevalue tested_bit)
// since the ascii range is more common in usage, we want to prefer (i.e., avoid
// the compare/jump in) the off branch. So we create a negative test, and switch
// the on and off branch precedence in the push() method
: predicate(new TerminalPredicate(true, tested_bit, 0)), complete(false), off(0), on(0) {}
virtual ~TernaryPredicate() { delete predicate; delete on; delete off; }
virtual bool push(IPredicate *p);
virtual void accept(IGenerator &generator);
bool complete;
IPredicate *predicate, *on, *off;
};
#endif