1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Tim King, Morgan Deters |
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 |
|
* A class representing a datatype selector. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "expr/dtype_selector.h" |
17 |
|
|
18 |
|
#include "options/set_language.h" |
19 |
|
|
20 |
|
using namespace cvc5::kind; |
21 |
|
|
22 |
|
namespace cvc5 { |
23 |
|
|
24 |
13862 |
DTypeSelector::DTypeSelector(std::string name, Node selector, Node updater) |
25 |
13862 |
: d_name(name), d_selector(selector), d_updater(updater), d_resolved(false) |
26 |
|
{ |
27 |
13862 |
Assert(name != ""); |
28 |
13862 |
} |
29 |
|
|
30 |
2037 |
const std::string& DTypeSelector::getName() const { return d_name; } |
31 |
|
|
32 |
882232 |
Node DTypeSelector::getSelector() const |
33 |
|
{ |
34 |
882232 |
Assert(d_resolved); |
35 |
882232 |
return d_selector; |
36 |
|
} |
37 |
27 |
Node DTypeSelector::getUpdater() const |
38 |
|
{ |
39 |
27 |
Assert(d_resolved); |
40 |
27 |
return d_updater; |
41 |
|
} |
42 |
|
|
43 |
|
Node DTypeSelector::getConstructor() const |
44 |
|
{ |
45 |
|
Assert(d_resolved); |
46 |
|
return d_constructor; |
47 |
|
} |
48 |
|
|
49 |
689975 |
TypeNode DTypeSelector::getType() const { return d_selector.getType(); } |
50 |
|
|
51 |
81141 |
TypeNode DTypeSelector::getRangeType() const |
52 |
|
{ |
53 |
81141 |
return getType().getRangeType(); |
54 |
|
} |
55 |
|
|
56 |
15722 |
bool DTypeSelector::isResolved() const { return d_resolved; } |
57 |
|
|
58 |
34 |
void DTypeSelector::toStream(std::ostream& out) const |
59 |
|
{ |
60 |
34 |
out << getName() << ": "; |
61 |
34 |
TypeNode t; |
62 |
34 |
if (d_resolved) |
63 |
|
{ |
64 |
|
// don't try to print the range type of null, instead we print null itself. |
65 |
|
if (!getType().isNull()) |
66 |
|
{ |
67 |
|
t = getRangeType(); |
68 |
|
} |
69 |
|
} |
70 |
34 |
else if (d_selector.isNull()) |
71 |
|
{ |
72 |
44 |
std::string typeName = d_name.substr(d_name.find('\0') + 1); |
73 |
22 |
out << ((typeName == "") ? "[self]" : typeName); |
74 |
22 |
return; |
75 |
|
} |
76 |
|
else |
77 |
|
{ |
78 |
12 |
out << "unresolved"; |
79 |
12 |
return; |
80 |
|
} |
81 |
|
out << t; |
82 |
|
} |
83 |
|
|
84 |
34 |
std::ostream& operator<<(std::ostream& os, const DTypeSelector& arg) |
85 |
|
{ |
86 |
34 |
arg.toStream(os); |
87 |
34 |
return os; |
88 |
|
} |
89 |
|
|
90 |
22755 |
} // namespace cvc5 |