1 /********************* */
2 /*! \file theory_strings_type_rules.h
4 ** Original author: Tianyi Liang
5 ** Major contributors: none
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2013-2013 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief Typing and cardinality rules for the theory of arrays
14 ** Typing and cardinality rules for the theory of arrays.
17 #include "cvc4_private.h"
19 #ifndef __CVC4__THEORY__STRINGS__THEORY_STRINGS_TYPE_RULES_H
20 #define __CVC4__THEORY__STRINGS__THEORY_STRINGS_TYPE_RULES_H
26 class StringConstantTypeRule
{
28 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
29 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
30 return nodeManager
->stringType();
34 class StringConcatTypeRule
{
36 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
37 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
38 TNode::iterator it
= n
.begin();
39 TNode::iterator it_end
= n
.end();
40 for (; it
!= it_end
; ++ it
) {
41 TypeNode t
= (*it
).getType(check
);
43 throw TypeCheckingExceptionPrivate(n
, "expecting string terms in string concat");
46 return nodeManager
->stringType();
50 class StringLengthTypeRule
{
52 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
53 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
55 TypeNode t
= n
[0].getType(check
);
57 throw TypeCheckingExceptionPrivate(n
, "expecting string terms in string length");
60 return nodeManager
->integerType();
64 class RegExpConstantTypeRule
{
66 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
67 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
68 return nodeManager
->regexpType();
72 class RegExpConcatTypeRule
{
74 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
75 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
76 TNode::iterator it
= n
.begin();
77 TNode::iterator it_end
= n
.end();
78 for (; it
!= it_end
; ++ it
) {
79 TypeNode t
= (*it
).getType(check
);
81 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
84 return nodeManager
->regexpType();
88 class RegExpOrTypeRule
{
90 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
91 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
92 TNode::iterator it
= n
.begin();
93 TNode::iterator it_end
= n
.end();
94 for (; it
!= it_end
; ++ it
) {
95 TypeNode t
= (*it
).getType(check
);
97 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
100 return nodeManager
->regexpType();
104 class RegExpInterTypeRule
{
106 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
107 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
108 TNode::iterator it
= n
.begin();
109 TNode::iterator it_end
= n
.end();
110 for (; it
!= it_end
; ++ it
) {
111 TypeNode t
= (*it
).getType(check
);
113 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
116 return nodeManager
->regexpType();
120 class RegExpStarTypeRule
{
122 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
123 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
124 TNode::iterator it
= n
.begin();
125 TNode::iterator it_end
= n
.end();
126 TypeNode t
= (*it
).getType(check
);
128 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
131 throw TypeCheckingExceptionPrivate(n
, "too many regexp");
134 return nodeManager
->regexpType();
138 class RegExpPlusTypeRule
{
140 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
141 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
142 TNode::iterator it
= n
.begin();
143 TNode::iterator it_end
= n
.end();
144 TypeNode t
= (*it
).getType(check
);
146 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
149 throw TypeCheckingExceptionPrivate(n
, "too many regexp");
152 return nodeManager
->regexpType();
156 class RegExpOptTypeRule
{
158 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
159 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
160 TNode::iterator it
= n
.begin();
161 TNode::iterator it_end
= n
.end();
162 TypeNode t
= (*it
).getType(check
);
164 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
167 throw TypeCheckingExceptionPrivate(n
, "too many regexp");
170 return nodeManager
->regexpType();
174 class StringToRegExpTypeRule
{
176 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
177 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
178 TNode::iterator it
= n
.begin();
179 TNode::iterator it_end
= n
.end();
180 TypeNode t
= (*it
).getType(check
);
182 throw TypeCheckingExceptionPrivate(n
, "expecting string terms");
184 if( (*it
).getKind() != kind::CONST_STRING
) {
185 throw TypeCheckingExceptionPrivate(n
, "expecting constant string terms");
188 throw TypeCheckingExceptionPrivate(n
, "too many terms");
191 return nodeManager
->regexpType();
195 class StringInRegExpTypeRule
{
197 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
198 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
199 TNode::iterator it
= n
.begin();
200 TNode::iterator it_end
= n
.end();
201 TypeNode t
= (*it
).getType(check
);
203 throw TypeCheckingExceptionPrivate(n
, "expecting string terms");
206 t
= (*it
).getType(check
);
208 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
211 throw TypeCheckingExceptionPrivate(n
, "too many terms");
214 return nodeManager
->booleanType();
219 }/* CVC4::theory::strings namespace */
220 }/* CVC4::theory namespace */
221 }/* CVC4 namespace */
223 #endif /* __CVC4__THEORY__STRINGS__THEORY_STRINGS_TYPE_RULES_H */