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 project.
8 ** Copyright (c) 2009-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();
41 for (; it
!= it_end
; ++ it
) {
42 TypeNode t
= (*it
).getType(check
);
44 throw TypeCheckingExceptionPrivate(n
, "expecting string terms in string concat");
49 throw TypeCheckingExceptionPrivate(n
, "expecting at least 2 terms in string concat");
51 return nodeManager
->stringType();
55 class StringLengthTypeRule
{
57 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
58 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
60 TypeNode t
= n
[0].getType(check
);
62 throw TypeCheckingExceptionPrivate(n
, "expecting string terms in string length");
65 return nodeManager
->integerType();
69 class StringSubstrTypeRule
{
71 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
72 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
74 TypeNode t
= n
[0].getType(check
);
76 throw TypeCheckingExceptionPrivate(n
, "expecting a string term in substr");
78 t
= n
[1].getType(check
);
80 throw TypeCheckingExceptionPrivate(n
, "expecting a start int term in substr");
82 t
= n
[2].getType(check
);
84 throw TypeCheckingExceptionPrivate(n
, "expecting a length int term in substr");
87 return nodeManager
->stringType();
91 class StringContainTypeRule
{
93 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
94 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
96 TypeNode t
= n
[0].getType(check
);
98 throw TypeCheckingExceptionPrivate(n
, "expecting an orginal string term in string contain");
100 t
= n
[1].getType(check
);
102 throw TypeCheckingExceptionPrivate(n
, "expecting a target string term in string contain");
105 return nodeManager
->booleanType();
109 class StringCharAtTypeRule
{
111 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
112 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
114 TypeNode t
= n
[0].getType(check
);
116 throw TypeCheckingExceptionPrivate(n
, "expecting a string term in string char at");
118 t
= n
[1].getType(check
);
119 if (!t
.isInteger()) {
120 throw TypeCheckingExceptionPrivate(n
, "expecting an integer string term in string char at");
123 return nodeManager
->stringType();
127 class RegExpConstantTypeRule
{
129 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
130 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
131 return nodeManager
->regexpType();
135 class RegExpConcatTypeRule
{
137 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
138 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
139 TNode::iterator it
= n
.begin();
140 TNode::iterator it_end
= n
.end();
142 for (; it
!= it_end
; ++ it
) {
143 TypeNode t
= (*it
).getType(check
);
145 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms in regexp concat");
150 throw TypeCheckingExceptionPrivate(n
, "expecting at least 2 terms in regexp concat");
152 return nodeManager
->regexpType();
156 class RegExpOrTypeRule
{
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 for (; it
!= it_end
; ++ it
) {
163 TypeNode t
= (*it
).getType(check
);
165 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
168 return nodeManager
->regexpType();
172 class RegExpInterTypeRule
{
174 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
175 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
176 TNode::iterator it
= n
.begin();
177 TNode::iterator it_end
= n
.end();
178 for (; it
!= it_end
; ++ it
) {
179 TypeNode t
= (*it
).getType(check
);
181 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
184 return nodeManager
->regexpType();
188 class RegExpStarTypeRule
{
190 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
191 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
192 TNode::iterator it
= n
.begin();
193 TNode::iterator it_end
= n
.end();
194 TypeNode t
= (*it
).getType(check
);
196 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
199 throw TypeCheckingExceptionPrivate(n
, "too many regexp");
202 return nodeManager
->regexpType();
206 class RegExpPlusTypeRule
{
208 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
209 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
210 TNode::iterator it
= n
.begin();
211 TNode::iterator it_end
= n
.end();
212 TypeNode t
= (*it
).getType(check
);
214 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
217 throw TypeCheckingExceptionPrivate(n
, "too many regexp");
220 return nodeManager
->regexpType();
224 class RegExpOptTypeRule
{
226 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
227 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
228 TNode::iterator it
= n
.begin();
229 TNode::iterator it_end
= n
.end();
230 TypeNode t
= (*it
).getType(check
);
232 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
235 throw TypeCheckingExceptionPrivate(n
, "too many regexp");
238 return nodeManager
->regexpType();
242 class RegExpRangeTypeRule
{
244 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
245 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
246 TNode::iterator it
= n
.begin();
247 TNode::iterator it_end
= n
.end();
250 for(int i
=0; i
<2; ++i
) {
251 TypeNode t
= (*it
).getType(check
);
253 throw TypeCheckingExceptionPrivate(n
, "expecting a string term in regexp range");
255 if( (*it
).getKind() != kind::CONST_STRING
) {
256 throw TypeCheckingExceptionPrivate(n
, "expecting a constant string term in regexp range");
258 if( (*it
).getConst
<String
>().size() != 1 ) {
259 throw TypeCheckingExceptionPrivate(n
, "expecting a single constant string term in regexp range");
261 ch
[i
] = (*it
).getConst
<String
>().getFirstChar();
265 throw TypeCheckingExceptionPrivate(n
, "expecting the first constant is less or equal to the second one in regexp range");
269 throw TypeCheckingExceptionPrivate(n
, "too many terms in regexp range");
272 return nodeManager
->regexpType();
276 class StringToRegExpTypeRule
{
278 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
279 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
280 TNode::iterator it
= n
.begin();
281 TNode::iterator it_end
= n
.end();
282 TypeNode t
= (*it
).getType(check
);
284 throw TypeCheckingExceptionPrivate(n
, "expecting string terms");
286 //if( (*it).getKind() != kind::CONST_STRING ) {
287 // throw TypeCheckingExceptionPrivate(n, "expecting constant string terms");
290 throw TypeCheckingExceptionPrivate(n
, "too many terms");
293 return nodeManager
->regexpType();
297 class StringInRegExpTypeRule
{
299 inline static TypeNode
computeType(NodeManager
* nodeManager
, TNode n
, bool check
)
300 throw (TypeCheckingExceptionPrivate
, AssertionException
) {
301 TNode::iterator it
= n
.begin();
302 TNode::iterator it_end
= n
.end();
303 TypeNode t
= (*it
).getType(check
);
305 throw TypeCheckingExceptionPrivate(n
, "expecting string terms");
308 t
= (*it
).getType(check
);
310 throw TypeCheckingExceptionPrivate(n
, "expecting regexp terms");
313 throw TypeCheckingExceptionPrivate(n
, "too many terms");
316 return nodeManager
->booleanType();
321 }/* CVC4::theory::strings namespace */
322 }/* CVC4::theory namespace */
323 }/* CVC4 namespace */
325 #endif /* __CVC4__THEORY__STRINGS__THEORY_STRINGS_TYPE_RULES_H */