|
3 | 3 | #include <kllvm/parser/KOREParser.h>
|
4 | 4 | #include <kllvm/util/transitive_closure.h>
|
5 | 5 |
|
| 6 | +#include <iostream> |
6 | 7 | #include <string>
|
7 | 8 | #include <unordered_set>
|
8 | 9 |
|
@@ -104,7 +105,53 @@ void KOREDefinition::buildOverloadRelation() {
|
104 | 105 | overloads = transitive_closure(overloads);
|
105 | 106 | }
|
106 | 107 |
|
107 |
| -void KOREDefinition::buildSortContainsRelation() { } |
| 108 | +void KOREDefinition::buildSortContainsRelation() { |
| 109 | + auto const &supersorts = getSupersorts(); |
| 110 | + |
| 111 | + for (auto const &[name, decl] : getSymbolDeclarations()) { |
| 112 | + auto const &atts = decl->getAttributes(); |
| 113 | + if (atts.find("function") != atts.end()) { |
| 114 | + // TODO: exclude collection sorts |
| 115 | + continue; |
| 116 | + } |
| 117 | + |
| 118 | + auto *symbol = decl->getSymbol(); |
| 119 | + auto const &return_sort |
| 120 | + = std::dynamic_pointer_cast<KORECompositeSort>(symbol->getSort()); |
| 121 | + if (!return_sort) { |
| 122 | + continue; |
| 123 | + } |
| 124 | + |
| 125 | + auto &children = sortContains[return_sort.get()]; |
| 126 | + children.insert(return_sort.get()); |
| 127 | + |
| 128 | + for (auto const &arg : symbol->getArguments()) { |
| 129 | + children.insert(arg.get()); |
| 130 | + } |
| 131 | + |
| 132 | + auto subsorts = std::vector<KORESort *>{}; |
| 133 | + for (auto const &child_sort : children) { |
| 134 | + if (supersorts.find(child_sort) != supersorts.end()) { |
| 135 | + for (auto const &child_subsort : supersorts.at(child_sort)) { |
| 136 | + subsorts.push_back(child_subsort); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + std::copy( |
| 142 | + subsorts.begin(), subsorts.end(), |
| 143 | + std::inserter(children, children.begin())); |
| 144 | + } |
| 145 | + |
| 146 | + sortContains = transitive_closure(sortContains); |
| 147 | + |
| 148 | + // Hooked sorts produce empty relations in the transitive closure because they |
| 149 | + // cannot occur as the return sort of a constructor symbol, and cannot be |
| 150 | + // subsorted. However, we want the relation to encode that a term of hooked |
| 151 | + // sort H _can_ contain a term of hooked sort H, and so we take the reflexive |
| 152 | + // closure of the transitive closure to ensure this. |
| 153 | + sortContains = reflexive_closure(sortContains); |
| 154 | +} |
108 | 155 |
|
109 | 156 | // NOLINTNEXTLINE(*-function-cognitive-complexity)
|
110 | 157 | void KOREDefinition::preprocess() {
|
|
0 commit comments