Skip to content
Snippets Groups Projects
Commit c1967c23 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Fix tuple outputs

parent 36e5bb02
No related branches found
No related tags found
1 merge request!135Forbid dangerous(?) implicit conversion to AggregateDataVariant
...@@ -314,8 +314,8 @@ struct BinaryExpressionProcessor<BinaryOpT, std::shared_ptr<ValueT>, std::shared ...@@ -314,8 +314,8 @@ struct BinaryExpressionProcessor<BinaryOpT, std::shared_ptr<ValueT>, std::shared
PUGS_INLINE DataVariant PUGS_INLINE DataVariant
_eval(const DataVariant& a, const DataVariant& b) _eval(const DataVariant& a, const DataVariant& b)
{ {
if constexpr ((std::is_arithmetic_v<B_DataT>) or (is_tiny_matrix_v<B_DataT>) or (is_tiny_vector_v<B_DataT>) or if constexpr (std::is_arithmetic_v<B_DataT> or is_tiny_matrix_v<B_DataT> or is_tiny_vector_v<B_DataT> or
(std::is_same_v<std::string, B_DataT>)) { std::is_same_v<std::string, B_DataT> or is_std_vector_v<B_DataT>) {
const auto& embedded_a = std::get<EmbeddedData>(a); const auto& embedded_a = std::get<EmbeddedData>(a);
const auto& b_value = std::get<B_DataT>(b); const auto& b_value = std::get<B_DataT>(b);
......
...@@ -12,6 +12,10 @@ BinaryOperatorRegisterForB::_register_ostream() ...@@ -12,6 +12,10 @@ BinaryOperatorRegisterForB::_register_ostream()
repository.addBinaryOperator<language::shift_left_op>( repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>, std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, bool>>()); std::shared_ptr<const OStream>, bool>>());
repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, std::vector<bool>>>());
} }
void void
......
...@@ -12,6 +12,10 @@ BinaryOperatorRegisterForN::_register_ostream() ...@@ -12,6 +12,10 @@ BinaryOperatorRegisterForN::_register_ostream()
repository.addBinaryOperator<language::shift_left_op>( repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>, std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, uint64_t>>()); std::shared_ptr<const OStream>, uint64_t>>());
repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, std::vector<uint64_t>>>());
} }
void void
......
...@@ -12,6 +12,10 @@ BinaryOperatorRegisterForR::_register_ostream() ...@@ -12,6 +12,10 @@ BinaryOperatorRegisterForR::_register_ostream()
repository.addBinaryOperator<language::shift_left_op>( repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>, std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, double>>()); std::shared_ptr<const OStream>, double>>());
repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, std::vector<double>>>());
} }
void void
......
...@@ -16,6 +16,10 @@ BinaryOperatorRegisterForRn<Dimension>::_register_ostream() ...@@ -16,6 +16,10 @@ BinaryOperatorRegisterForRn<Dimension>::_register_ostream()
repository.addBinaryOperator<language::shift_left_op>( repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>, std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, Rn>>()); std::shared_ptr<const OStream>, Rn>>());
repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, std::vector<Rn>>>());
} }
template <size_t Dimension> template <size_t Dimension>
......
...@@ -16,6 +16,10 @@ BinaryOperatorRegisterForRnxn<Dimension>::_register_ostream() ...@@ -16,6 +16,10 @@ BinaryOperatorRegisterForRnxn<Dimension>::_register_ostream()
repository.addBinaryOperator<language::shift_left_op>( repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>, std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, Rnxn>>()); std::shared_ptr<const OStream>, Rnxn>>());
repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, std::vector<Rnxn>>>());
} }
template <size_t Dimension> template <size_t Dimension>
......
...@@ -14,6 +14,10 @@ BinaryOperatorRegisterForString::_register_ostream() ...@@ -14,6 +14,10 @@ BinaryOperatorRegisterForString::_register_ostream()
repository.addBinaryOperator<language::shift_left_op>( repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>, std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, std::string>>()); std::shared_ptr<const OStream>, std::string>>());
repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, std::vector<std::string>>>());
} }
void void
......
...@@ -12,6 +12,10 @@ BinaryOperatorRegisterForZ::_register_ostream() ...@@ -12,6 +12,10 @@ BinaryOperatorRegisterForZ::_register_ostream()
repository.addBinaryOperator<language::shift_left_op>( repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>, std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, int64_t>>()); std::shared_ptr<const OStream>, int64_t>>());
repository.addBinaryOperator<language::shift_left_op>(
std::make_shared<BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const OStream>,
std::shared_ptr<const OStream>, std::vector<int64_t>>>());
} }
void void
......
...@@ -13,6 +13,9 @@ operator<<(std::ostream& os, const DataVariant& v) ...@@ -13,6 +13,9 @@ operator<<(std::ostream& os, const DataVariant& v)
os << "--"; os << "--";
} else if constexpr (is_std_vector_v<ValueT>) { } else if constexpr (is_std_vector_v<ValueT>) {
os << '('; os << '(';
if constexpr (std::is_same_v<bool, typename ValueT::value_type>) {
os << std::boolalpha;
}
if (v.size() > 0) { if (v.size() > 0) {
os << v[0]; os << v[0];
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <fstream> #include <fstream>
#include <netdb.h> #include <netdb.h>
#include <regex>
#include <unistd.h> #include <unistd.h>
// clazy:excludeall=non-pod-global-static // clazy:excludeall=non-pod-global-static
...@@ -24,8 +25,29 @@ TEST_CASE("BinaryExpressionProcessor shift", "[language]") ...@@ -24,8 +25,29 @@ TEST_CASE("BinaryExpressionProcessor shift", "[language]")
data << R"(import socket;)"; data << R"(import socket;)";
data << "let fout:ostream, fout = ofstream(\"" << path.string() << "\");\n"; data << "let fout:ostream, fout = ofstream(\"" << path.string() << "\");\n";
data << R"(fout << 2 << " " << true << " " << 2 + 3 << "\n"; data << R"(fout << 2 << " " << true << " " << 2 + 3 << "\n";
fout << createSocketServer(0);)"; fout << createSocketServer(0) << "\n";)";
data << "let b:(B), b = (true,false);\n";
data << "let n:(N), n = (1,3);\n";
data << "let z:(Z), z = (-1,3);\n";
data << "let r:(R), r = (2.3,4);\n";
data << "let u1:(R^1), u1 = (2.3,4);\n";
data << "let u2:(R^2), u2 = ((2.3,4), (3,2));\n";
data << "let u3:(R^3), u3 = ((2.3,4,-1), (3,2,1));\n";
data << "let A1:(R^1x1), A1 = (2.3, 4);\n";
data << "let A2:(R^2x2), A2 = ((2.3,4,2,0.3), (3,2.3,1,-4));\n";
data << "let A3:(R^3x3), A3 = ((2.3,4,-1,2,7,2.3,6,2,8), (3,2,1,1,2,5,2.1,3,-2.6));\n";
data << R"(let s:(string), s = ("foo", "bar");)";
data << R"(fout << b << "\n";)";
data << R"(fout << n << "\n";)";
data << R"(fout << z << "\n";)";
data << R"(fout << r << "\n";)";
data << R"(fout << u1 << "\n";)";
data << R"(fout << u2 << "\n";)";
data << R"(fout << u3 << "\n";)";
data << R"(fout << A1 << "\n";)";
data << R"(fout << A2 << "\n";)";
data << R"(fout << A3 << "\n";)";
data << R"(fout << s << "\n";)";
TAO_PEGTL_NAMESPACE::string_input input{data.str(), "test.pgs"}; TAO_PEGTL_NAMESPACE::string_input input{data.str(), "test.pgs"};
auto ast = ASTBuilder::build(input); auto ast = ASTBuilder::build(input);
...@@ -69,7 +91,9 @@ fout << createSocketServer(0);)"; ...@@ -69,7 +91,9 @@ fout << createSocketServer(0);)";
auto is_int = [](const std::string& s) { auto is_int = [](const std::string& s) {
for (const char& c : s) { for (const char& c : s) {
if (not std::isdigit(c)) { if (c == '\n') {
break;
} else if (not std::isdigit(c)) {
return false; return false;
} }
} }
...@@ -79,6 +103,54 @@ fout << createSocketServer(0);)"; ...@@ -79,6 +103,54 @@ fout << createSocketServer(0);)";
REQUIRE(is_int(suffix)); REQUIRE(is_int(suffix));
} }
{
std::ifstream fin(filename.c_str());
char line[1024];
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "2 true 5");
char hbuf[NI_MAXHOST];
::gethostname(hbuf, NI_MAXHOST);
std::ostringstream os;
os << '^' << hbuf << ":\\d+$";
fin.getline(line, 1023);
REQUIRE(std::regex_match(line, std::regex{os.str()}));
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "(true, false)");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "(1, 3)");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "(-1, 3)");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "(2.3, 4)");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "((2.3), (4))");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "((2.3,4), (3,2))");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "((2.3,4,-1), (3,2,1))");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "([(2.3)], [(4)])");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "([(2.3,4)(2,0.3)], [(3,2.3)(1,-4)])");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "([(2.3,4,-1)(2,7,2.3)(6,2,8)], [(3,2,1)(1,2,5)(2.1,3,-2.6)])");
fin.getline(line, 1023);
REQUIRE(std::string_view(line) == "(foo, bar)");
}
std::filesystem::remove(filename); std::filesystem::remove(filename);
REQUIRE(not std::filesystem::exists(filename)); REQUIRE(not std::filesystem::exists(filename));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment