44 #include <type_traits>
53 class IOAttributesTransformer :
public Transformer {
55 std::string
getName()
const override {
56 return "IOAttributesTransformer";
59 IOAttributesTransformer*
clone()
const override {
85 std::vector<std::string> attributesParams;
87 for (
const auto* attribute :
rel->getAttributes()) {
88 attributesParams.push_back(attribute->getName());
92 long long arity{
static_cast<long long>(
rel->getArity() - auxArityAnalysis->getArity(
rel))};
93 long long auxArity{
static_cast<long long>(auxArityAnalysis->getArity(
rel))};
101 io->addParameter(
"params", params.
dump());
108 bool changed =
false;
109 Program& program = translationUnit.getProgram();
110 for (Directive* io : program.getDirectives()) {
114 if (io->hasParameter(
"attributeNames")) {
118 std::string delimiter(
"\t");
119 if (io->hasParameter(
"delimiter")) {
120 delimiter = io->getParameter(
"delimiter");
123 std::vector<std::string> attributeNames;
124 for (
const auto* attribute :
rel->getAttributes()) {
125 attributeNames.push_back(attribute->getName());
130 std::vector<std::string> originalAttributeNames(
131 attributeNames.begin(), attributeNames.end() - auxArityAnalysis->getArity(
rel));
132 io->addParameter(
"attributeNames",
toString(
join(originalAttributeNames, delimiter)));
134 io->addParameter(
"attributeNames",
toString(
join(attributeNames, delimiter)));
142 bool changed =
false;
143 Program& program = translationUnit.getProgram();
144 auto auxArityAnalysis = translationUnit.getAnalysis<analysis::AuxiliaryArityAnalysis>();
146 &translationUnit.getAnalysis<analysis::TypeEnvironmentAnalysis>()->getTypeEnvironment();
148 for (Directive* io : program.getDirectives()) {
151 std::vector<std::string> attributesTypes;
153 for (
const auto* attribute :
rel->getAttributes()) {
154 auto typeName = attribute->getTypeName();
156 attributesTypes.push_back(
type);
160 long long arity{
static_cast<long long>(
rel->getArity() - auxArityAnalysis->getArity(
rel))};
161 long long auxArity{
static_cast<long long>(auxArityAnalysis->getArity(
rel))};
170 io->addParameter(
"types",
types.dump());
177 return toString(
join(node->getQualifiedName().getQualifiers(),
"."));
196 Program& program = translationUnit.getProgram();
200 std::map<std::string, json11::Json> sumTypes;
204 dynamic_cast<const analysis::AlgebraicDataType&>(typeEnv.getType(astAlgebraicDataType));
206 auto& branches = sumType.getBranches();
208 std::vector<json11::Json> branchesInfo;
210 for (const auto& branch : branches) {
211 std::vector<json11::Json> branchTypes;
212 for (auto* type : branch.types) {
213 branchTypes.push_back(getTypeQualifier(*type));
217 json11::Json::object{{{
"types", std::move(branchTypes)}, {
"name", branch.name}}};
218 branchesInfo.push_back(std::move(branchInfo));
223 {
"arity", static_cast<long long>(branches.size())}, {
"enum", isADTEnum(sumType)}}};
224 sumTypes.emplace(std::move(typeQualifier), std::move(sumInfo));
231 json11::Json getRecordsTypes(TranslationUnit& translationUnit)
const {
234 if (!ramRecordTypes.
is_null()) {
235 return ramRecordTypes;
238 Program& program = translationUnit.getProgram();
240 &translationUnit.getAnalysis<analysis::TypeEnvironmentAnalysis>()->getTypeEnvironment();
241 std::vector<std::string> elementTypes;
242 std::map<std::string, json11::Json> records;
245 for (
auto* astType : program.getTypes()) {
246 const auto&
type = typeEnv->getType(*astType);
247 if (isA<analysis::RecordType>(
type)) {
248 elementTypes.clear();
253 const size_t recordArity = elementTypes.size();
255 {
"types", std::move(elementTypes)}, {
"arity",
static_cast<long long>(recordArity)}};
261 return ramRecordTypes;
267 if (!ramRecordParams.
is_null()) {
268 return ramRecordParams;
271 Program& program = translationUnit.
getProgram();
272 std::vector<std::string> elementParams;
273 std::map<std::string, json11::Json> records;
276 for (
auto* astType : program.getTypes()) {
277 if (isA<ast::RecordType>(astType)) {
278 elementParams.clear();
280 for (
const auto field : as<ast::RecordType>(astType)->getFields()) {
281 elementParams.push_back(field->getName());
283 const size_t recordArity = elementParams.size();
285 {
"params", std::move(elementParams)}, {
"arity",
static_cast<long long>(recordArity)}};
286 records.emplace(astType->getQualifiedName().toString(), std::move(recordInfo));
291 return ramRecordParams;