diff --git a/src/parser/daphnedsl/DaphneDSLVisitor.cpp b/src/parser/daphnedsl/DaphneDSLVisitor.cpp index b83955736..f6ae08660 100644 --- a/src/parser/daphnedsl/DaphneDSLVisitor.cpp +++ b/src/parser/daphnedsl/DaphneDSLVisitor.cpp @@ -1278,67 +1278,71 @@ antlrcpp::Any DaphneDSLVisitor::visitCondExpr(DaphneDSLGrammarParser::CondExprCo valueOrErrorOnVisit(ctx->elseExpr))); } +// convenience function +template +static void fillRes(std::shared_ptr& constValues, std::vector& nonConstValsIdx, int64_t i, + std::pair constValue) { + // currently supported types for matrix literals support conversions + // to (most general) array's value type. if unsigned integers are + // added, this can lead to conflicts + if (constValue.first) + constValues.get()[i] = constValue.second; // FIXME: consider casting to unsigned char here suggested by clang tidy + else { + constValues.get()[i] = 0; + nonConstValsIdx.emplace_back(i); + } +} + template mlir::Value DaphneDSLVisitor::buildColMatrixFromValues(mlir::Location loc, const std::vector &values, - const std::vector &valueTypes, mlir::Type matrixVt) { - std::shared_ptr constValues = std::shared_ptr(new VT[values.size()]); + const std::vector &valueTypes, mlir::Type matrixVt) { + auto constValues = std::make_shared(values.size()); std::vector nonConstValsIdx; - // convenience function - auto fillRes = [&constValues, &nonConstValsIdx](int64_t i, std::pair constValue) { - if (constValue.first) { - // currently supported types for matrix literals support conversions - // to (most general) array's value type. if unsigned integers are - // added, this can lead to conflicts - constValues.get()[i] = constValue.second; - } else { - constValues.get()[i] = 0; - nonConstValsIdx.emplace_back(i); - } - }; - for (int64_t i = 0; i < static_cast(values.size()); ++i) { mlir::Value currentValue = values[i]; mlir::Type currentType = valueTypes[i]; - if (mlir::IntegerType valueIntType = currentType.dyn_cast()) { + if (auto valueIntType = currentType.dyn_cast()) { if (currentType.isSignedInteger()) { switch (valueIntType.getWidth()) { case 64: - fillRes(i, CompilerUtils::isConstant(currentValue)); + fillRes(constValues, nonConstValsIdx, i, CompilerUtils::isConstant(currentValue)); break; case 32: - fillRes(i, CompilerUtils::isConstant(currentValue)); + fillRes(constValues, nonConstValsIdx, i, CompilerUtils::isConstant(currentValue)); break; case 8: - fillRes(i, CompilerUtils::isConstant(currentValue)); + fillRes(constValues, nonConstValsIdx, i, CompilerUtils::isConstant(currentValue)); break; default: throw ErrorHandler::compilerError(loc, "DSLVisitor", "matrix literal of invalid value type"); } - } else if (currentType.isUnsignedInteger()) { + } + else if (currentType.isUnsignedInteger()) { switch (valueIntType.getWidth()) { case 64: - fillRes(i, CompilerUtils::isConstant(currentValue)); - break; + fillRes(constValues, nonConstValsIdx, i, CompilerUtils::isConstant(currentValue)); + break; case 32: - fillRes(i, CompilerUtils::isConstant(currentValue)); + fillRes(constValues, nonConstValsIdx, i, CompilerUtils::isConstant(currentValue)); break; case 8: - fillRes(i, CompilerUtils::isConstant(currentValue)); + fillRes(constValues, nonConstValsIdx, i, CompilerUtils::isConstant(currentValue)); break; default: throw ErrorHandler::compilerError(loc, "DSLVisitor", "matrix literal of invalid value type"); } } else if (currentType.isSignlessInteger(1)) - fillRes(i, CompilerUtils::isConstant(currentValue)); + fillRes(constValues, nonConstValsIdx, i, CompilerUtils::isConstant(currentValue)); else throw ErrorHandler::compilerError(loc, "DSLVisitor", "matrix literal of invalid value type"); - } else if (currentType.isF64()) - fillRes(i, CompilerUtils::isConstant(currentValue)); + } + else if (currentType.isF64()) + fillRes(constValues, nonConstValsIdx, i, CompilerUtils::isConstant(currentValue)); else if (currentType.isF32()) - fillRes(i, CompilerUtils::isConstant(currentValue)); + fillRes(constValues, nonConstValsIdx, i, CompilerUtils::isConstant(currentValue)); else { throw ErrorHandler::compilerError(loc, "DSLVisitor", "matrix literal of invalid value type"); }