1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Dejan Jovanovic, Morgan Deters, Christopher L. Conway |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Typing and cardinality rules for the theory of boolean. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/booleans/theory_bool_type_rules.h" |
17 |
|
|
18 |
|
#include <sstream> |
19 |
|
|
20 |
|
namespace cvc5 { |
21 |
|
namespace theory { |
22 |
|
namespace boolean { |
23 |
|
|
24 |
11374066 |
TypeNode BooleanTypeRule::computeType(NodeManager* nodeManager, |
25 |
|
TNode n, |
26 |
|
bool check) |
27 |
|
{ |
28 |
11374066 |
TypeNode booleanType = nodeManager->booleanType(); |
29 |
11374066 |
if (check) |
30 |
|
{ |
31 |
47497512 |
for (const auto& child : n) |
32 |
|
{ |
33 |
36130898 |
if (!child.getType(check).isBoolean()) |
34 |
|
{ |
35 |
326 |
Debug("pb") << "failed type checking: " << child << std::endl; |
36 |
652 |
Debug("pb") << " integer: " << child.getType(check).isInteger() |
37 |
326 |
<< std::endl; |
38 |
326 |
Debug("pb") << " real: " << child.getType(check).isReal() << std::endl; |
39 |
|
throw TypeCheckingExceptionPrivate(n, |
40 |
326 |
"expecting a Boolean subexpression"); |
41 |
|
} |
42 |
|
} |
43 |
|
} |
44 |
11373740 |
return booleanType; |
45 |
|
} |
46 |
|
|
47 |
1122559 |
TypeNode IteTypeRule::computeType(NodeManager* nodeManager, TNode n, bool check) |
48 |
|
{ |
49 |
2245118 |
TypeNode thenType = n[1].getType(check); |
50 |
2245118 |
TypeNode elseType = n[2].getType(check); |
51 |
1122559 |
TypeNode iteType = TypeNode::leastCommonTypeNode(thenType, elseType); |
52 |
1122559 |
if (check) |
53 |
|
{ |
54 |
2245118 |
TypeNode booleanType = nodeManager->booleanType(); |
55 |
1122559 |
if (n[0].getType(check) != booleanType) |
56 |
|
{ |
57 |
24 |
throw TypeCheckingExceptionPrivate(n, "condition of ITE is not Boolean"); |
58 |
|
} |
59 |
1122535 |
if (iteType.isNull()) |
60 |
|
{ |
61 |
16 |
std::stringstream ss; |
62 |
8 |
ss << "Both branches of the ITE must be a subtype of a common type." |
63 |
8 |
<< std::endl |
64 |
16 |
<< "then branch: " << n[1] << std::endl |
65 |
8 |
<< "its type : " << thenType << std::endl |
66 |
16 |
<< "else branch: " << n[2] << std::endl |
67 |
8 |
<< "its type : " << elseType << std::endl; |
68 |
8 |
throw TypeCheckingExceptionPrivate(n, ss.str()); |
69 |
|
} |
70 |
|
} |
71 |
2245054 |
return iteType; |
72 |
|
} |
73 |
|
|
74 |
|
} // namespace boolean |
75 |
|
} // namespace theory |
76 |
29517 |
} // namespace cvc5 |