diff --git a/src/algebra/TinyMatrix.hpp b/src/algebra/TinyMatrix.hpp index f4c66232816b33d8ee7e8ac897436507181d5644..e34f98ed8c25df7a77ba90bbd7cd05305b5eb115 100644 --- a/src/algebra/TinyMatrix.hpp +++ b/src/algebra/TinyMatrix.hpp @@ -150,11 +150,14 @@ class [[nodiscard]] TinyMatrix { os << '['; for (size_t i = 0; i < M; ++i) { - os << '(' << NaNHelper(A(i, 0)); + if (i > 0) { + os << ','; + } + os << '[' << NaNHelper(A(i, 0)); for (size_t j = 1; j < N; ++j) { os << ',' << NaNHelper(A(i, j)); } - os << ')'; + os << ']'; } os << ']'; diff --git a/src/algebra/TinyVector.hpp b/src/algebra/TinyVector.hpp index 3ca3d2a38550b5a31bb16843d25a35cebdb10fd0..ae616a4849d0e681bf09e613ad4d19263d0f035a 100644 --- a/src/algebra/TinyVector.hpp +++ b/src/algebra/TinyVector.hpp @@ -100,11 +100,11 @@ class [[nodiscard]] TinyVector PUGS_INLINE constexpr friend std::ostream& operator<<(std::ostream& os, const TinyVector& v) { - os << '(' << NaNHelper(v.m_values[0]); + os << '[' << NaNHelper(v.m_values[0]); for (size_t i = 1; i < N; ++i) { os << ',' << NaNHelper(v.m_values[i]); } - os << ')'; + os << ']'; return os; } diff --git a/src/language/PEGGrammar.hpp b/src/language/PEGGrammar.hpp index d173f50745e781d2be5cade0372a0b15524f4850..78aaafe96e4795542a639144827851bbc3421029 100644 --- a/src/language/PEGGrammar.hpp +++ b/src/language/PEGGrammar.hpp @@ -55,6 +55,9 @@ struct character : if_must_else< one< '\\' >, escaped_c, ascii::any> {}; struct open_parent : seq< one< '(' >, ignored > {}; struct close_parent : seq< one< ')' >, ignored > {}; +struct open_bracket : seq< one< '[' >, ignored > {}; +struct close_bracket : seq< one< ']' >, ignored > {}; + struct literal : star< minus<character, one < '"' > > >{}; struct quoted_literal : if_must< one< '"' >, seq< literal, one< '"' > > >{}; @@ -153,11 +156,16 @@ struct COMMA : seq< comma , ignored > {}; struct expression; struct parented_expression : if_must< open_parent, expression, close_parent >{}; -struct tuple_expression; -struct function_argument_list : if_must< open_parent, opt< list_must< sor< tuple_expression, expression >, COMMA > >, close_parent >{}; +struct vector_expression : if_must< open_bracket, list_must<expression, COMMA >, close_bracket >{}; + +struct row_expression : if_must< open_bracket, list_must<expression, COMMA >, close_bracket >{}; +struct matrix_expression : seq< open_bracket, list_must<row_expression, COMMA >, close_bracket >{}; + +struct inner_expression_list; +struct function_argument_list : if_must< open_parent, opt< list_must< sor< inner_expression_list, expression >, COMMA > >, close_parent >{}; struct function_evaluation : seq< NAME, function_argument_list > {}; -struct primary_expression : sor< BOOL, REAL, INTEGER, LITERAL, function_evaluation, NAME, parented_expression > {}; +struct primary_expression : sor< BOOL, REAL, INTEGER, LITERAL, function_evaluation, NAME, parented_expression, matrix_expression, vector_expression >{}; struct unary_plusplus : TAO_PEGTL_STRING("++") {}; struct unary_minusminus : TAO_PEGTL_STRING("--") {}; @@ -174,9 +182,6 @@ struct post_minusminus : TAO_PEGTL_STRING("--") {}; struct postfix_operator : seq< sor< post_plusplus, post_minusminus>, ignored > {}; -struct open_bracket : seq< one< '[' >, ignored > {}; -struct close_bracket : seq< one< ']' >, ignored > {}; - struct subscript_expression : if_must< open_bracket, list_must<expression, COMMA>, close_bracket >{}; struct postfix_expression : seq< primary_expression, star< sor< subscript_expression , postfix_operator> > >{}; @@ -228,12 +233,12 @@ struct logical_or : list_must< logical_and, or_op >{}; struct expression : logical_or {}; -struct tuple_expression : seq< open_parent, expression, plus< if_must< COMMA, expression > >, close_parent >{}; +struct inner_expression_list : seq< open_parent, expression, plus< if_must< COMMA, expression > >, close_parent >{}; -struct expression_list : seq< open_parent, sor< seq< tuple_expression, - star< if_must< COMMA, sor< tuple_expression, expression > > > >, +struct expression_list : seq< open_parent, sor< seq< inner_expression_list, + star< if_must< COMMA, sor< inner_expression_list, expression > > > >, seq< expression, - plus< if_must< COMMA, sor< tuple_expression, expression > > > > >, close_parent >{}; + plus< if_must< COMMA, sor< inner_expression_list, expression > > > > >, close_parent >{}; struct affect_op : sor< eq_op, multiplyeq_op, divideeq_op, pluseq_op, minuseq_op > {}; diff --git a/src/language/ast/ASTBuilder.cpp b/src/language/ast/ASTBuilder.cpp index db7f77b29695bf82fc650ade4176592eefe5b651..4e380783e3af91072e130f9fa71a19164fcae08f 100644 --- a/src/language/ast/ASTBuilder.cpp +++ b/src/language/ast/ASTBuilder.cpp @@ -229,8 +229,11 @@ using selector = TAO_PEGTL_NAMESPACE::parse_tree::selector< language::Z_set, language::R_set, language::type_name_id, - language::tuple_expression, + language::inner_expression_list, + language::vector_expression, language::vector_type, + language::matrix_expression, + language::row_expression, language::matrix_type, language::string_type, language::var_declaration, diff --git a/src/language/ast/ASTNodeAffectationExpressionBuilder.cpp b/src/language/ast/ASTNodeAffectationExpressionBuilder.cpp index cc26d368ee6cb0d6a3f105604ae6484628d69890..32117039587e2c53907ea030ac73a7e10e544255 100644 --- a/src/language/ast/ASTNodeAffectationExpressionBuilder.cpp +++ b/src/language/ast/ASTNodeAffectationExpressionBuilder.cpp @@ -37,12 +37,6 @@ ASTNodeAffectationExpressionBuilder::ASTNodeAffectationExpressionBuilder(ASTNode ASTNode& lhs_node = *node.children[0]; ASTNode& rhs_node = *node.children[1]; - if (rhs_node.m_data_type == ASTNodeDataType::list_t) { - if ((lhs_node.m_data_type == ASTNodeDataType::vector_t) or (lhs_node.m_data_type == ASTNodeDataType::matrix_t)) { - ASTNodeNaturalConversionChecker(rhs_node, lhs_node.m_data_type); - } - } - node.m_node_processor = optional_processor_builder.value()->getNodeProcessor(lhs_node, rhs_node); } else { std::ostringstream error_message; diff --git a/src/language/ast/ASTNodeBuiltinFunctionExpressionBuilder.cpp b/src/language/ast/ASTNodeBuiltinFunctionExpressionBuilder.cpp index cdd9c43d977c6718dc5d900dbe0b96a15de54f47..e2b4a947f1f93fff1060e6fab3f578265b37526c 100644 --- a/src/language/ast/ASTNodeBuiltinFunctionExpressionBuilder.cpp +++ b/src/language/ast/ASTNodeBuiltinFunctionExpressionBuilder.cpp @@ -85,16 +85,6 @@ ASTNodeBuiltinFunctionExpressionBuilder::_getArgumentConverter(const ASTNodeData // LCOV_EXCL_STOP } } - case ASTNodeDataType::list_t: { - if (argument_node_sub_data_type.m_parent_node.children.size() == parameter_v.dimension()) { - return std::make_unique<FunctionTinyVectorArgumentConverter<ParameterT, ParameterT>>(argument_number); - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: invalid argument dimension", - std::vector{argument_node_sub_data_type.m_parent_node.begin()}); - // LCOV_EXCL_STOP - } - } case ASTNodeDataType::int_t: { if (argument_node_sub_data_type.m_parent_node.is_type<language::integer>()) { if (std::stoi(argument_node_sub_data_type.m_parent_node.string()) == 0) { @@ -162,17 +152,6 @@ ASTNodeBuiltinFunctionExpressionBuilder::_getArgumentConverter(const ASTNodeData // LCOV_EXCL_STOP } } - case ASTNodeDataType::list_t: { - if (argument_node_sub_data_type.m_parent_node.children.size() == - (parameter_v.numberOfRows() * parameter_v.numberOfColumns())) { - return std::make_unique<FunctionTinyMatrixArgumentConverter<ParameterT, ParameterT>>(argument_number); - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: invalid argument dimension", - std::vector{argument_node_sub_data_type.m_parent_node.begin()}); - // LCOV_EXCL_STOP - } - } case ASTNodeDataType::int_t: { if (argument_node_sub_data_type.m_parent_node.is_type<language::integer>()) { if (std::stoi(argument_node_sub_data_type.m_parent_node.string()) == 0) { diff --git a/src/language/ast/ASTNodeDataTypeBuilder.cpp b/src/language/ast/ASTNodeDataTypeBuilder.cpp index cb9e479df5f2e1f64edb4d5cb732acebcb505af6..6793bdcd1078fa738e1edd3f7a6146c4101e766c 100644 --- a/src/language/ast/ASTNodeDataTypeBuilder.cpp +++ b/src/language/ast/ASTNodeDataTypeBuilder.cpp @@ -45,45 +45,7 @@ ASTNodeDataTypeBuilder::_buildDeclarationNodeDataTypes(ASTNode& type_node, ASTNo } else if (type_node.is_type<language::matrix_type>()) { data_type = getMatrixDataType(type_node); } else if (type_node.is_type<language::tuple_type_specifier>()) { - const auto& content_node = type_node.children[0]; - - if (content_node->is_type<language::type_name_id>()) { - const std::string& type_name_id = content_node->string(); - - auto& symbol_table = *type_node.m_symbol_table; - - const auto [i_type_symbol, found] = symbol_table.find(type_name_id, content_node->begin()); - if (not found) { - throw ParseError("undefined type identifier", std::vector{content_node->begin()}); - } else if (i_type_symbol->attributes().dataType() != ASTNodeDataType::type_name_id_t) { - std::ostringstream os; - os << "invalid type identifier, '" << type_name_id << "' was previously defined as a '" - << dataTypeName(i_type_symbol->attributes().dataType()) << '\''; - throw ParseError(os.str(), std::vector{content_node->begin()}); - } - - content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::type_id_t>(type_name_id); - } else if (content_node->is_type<language::B_set>()) { - content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::bool_t>(); - } else if (content_node->is_type<language::Z_set>()) { - content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::int_t>(); - } else if (content_node->is_type<language::N_set>()) { - content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::unsigned_int_t>(); - } else if (content_node->is_type<language::R_set>()) { - content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::double_t>(); - } else if (content_node->is_type<language::vector_type>()) { - content_node->m_data_type = getVectorDataType(*type_node.children[0]); - } else if (content_node->is_type<language::matrix_type>()) { - content_node->m_data_type = getMatrixDataType(*type_node.children[0]); - } else if (content_node->is_type<language::string_type>()) { - content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::string_t>(); - } else { - // LCOV_EXCL_START - throw UnexpectedError("unexpected content type in tuple"); - // LCOV_EXCL_STOP - } - - data_type = ASTNodeDataType::build<ASTNodeDataType::tuple_t>(content_node->m_data_type); + data_type = getTupleDataType(type_node); } else if (type_node.is_type<language::string_type>()) { data_type = ASTNodeDataType::build<ASTNodeDataType::string_t>(); } else if (type_node.is_type<language::type_name_id>()) { @@ -154,6 +116,8 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) const n.m_data_type = ASTNodeDataType::build<ASTNodeDataType::double_t>(); } else if (n.is_type<language::integer>()) { n.m_data_type = ASTNodeDataType::build<ASTNodeDataType::int_t>(); + } else if (n.is_type<language::row_expression>()) { + n.m_data_type = ASTNodeDataType::build<ASTNodeDataType::void_t>(); } else if (n.is_type<language::vector_type>()) { n.m_data_type = getVectorDataType(n); } else if (n.is_type<language::matrix_type>()) { @@ -322,6 +286,11 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) const this->_buildNodeDataTypes(*child); } + if (n.is_type<language::vector_expression>()) { + n.m_data_type = getVectorExpressionType(n); + } else if (n.is_type<language::matrix_expression>()) { + n.m_data_type = getMatrixExpressionType(n); + } if (n.is_type<language::break_kw>() or n.is_type<language::continue_kw>()) { n.m_data_type = ASTNodeDataType::build<ASTNodeDataType::void_t>(); } else if (n.is_type<language::eq_op>() or n.is_type<language::multiplyeq_op>() or @@ -329,7 +298,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) const n.is_type<language::minuseq_op>()) { n.m_data_type = ASTNodeDataType::build<ASTNodeDataType::void_t>(); - } else if (n.is_type<language::tuple_expression>()) { + } else if (n.is_type<language::inner_expression_list>()) { std::vector<std::shared_ptr<const ASTNodeDataType>> sub_data_type_list; sub_data_type_list.reserve(n.children.size()); @@ -365,6 +334,8 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) const value_type = ASTNodeDataType::build<ASTNodeDataType::string_t>(); } else if (image_node.is_type<language::type_name_id>()) { value_type = ASTNodeDataType::build<ASTNodeDataType::type_id_t>(image_node.m_data_type.nameOfTypeId()); + } else if (image_node.is_type<language::tuple_type_specifier>()) { + value_type = getTupleDataType(image_node); } // LCOV_EXCL_START diff --git a/src/language/ast/ASTNodeExpressionBuilder.cpp b/src/language/ast/ASTNodeExpressionBuilder.cpp index bbbcda43e788356d6bf4ec338643a79049069fc0..70722aea1a1ac73851df7157820a029e87266a66 100644 --- a/src/language/ast/ASTNodeExpressionBuilder.cpp +++ b/src/language/ast/ASTNodeExpressionBuilder.cpp @@ -16,10 +16,11 @@ #include <language/node_processor/FakeProcessor.hpp> #include <language/node_processor/ForProcessor.hpp> #include <language/node_processor/IfProcessor.hpp> +#include <language/node_processor/InnerListToVectorProcessor.hpp> #include <language/node_processor/LocalNameProcessor.hpp> #include <language/node_processor/NameProcessor.hpp> -#include <language/node_processor/TupleToTinyVectorProcessor.hpp> -#include <language/node_processor/TupleToVectorProcessor.hpp> +#include <language/node_processor/TinyMatrixExpressionProcessor.hpp> +#include <language/node_processor/TinyVectorExpressionProcessor.hpp> #include <language/node_processor/ValueProcessor.hpp> #include <language/node_processor/WhileProcessor.hpp> #include <language/utils/ParseError.hpp> @@ -51,8 +52,9 @@ ASTNodeExpressionBuilder::_buildExpression(ASTNode& n) ASTNodeAffectationExpressionBuilder{n}; } - } else if (n.is_type<language::tuple_expression>()) { - n.m_node_processor = std::make_unique<TupleToVectorProcessor<ASTNodeExpressionListProcessor>>(n); + } else if (n.is_type<language::inner_expression_list>()) { + n.m_node_processor = std::make_unique<InnerListToVectorProcessor>(n); + } else if (n.is_type<language::function_definition>()) { this->_checkIsPureFunction(n); @@ -75,6 +77,54 @@ ASTNodeExpressionBuilder::_buildExpression(ASTNode& n) } else if (n.is_type<language::false_kw>()) { n.m_node_processor = std::make_unique<ValueProcessor>(n); + } else if (n.is_type<language::vector_expression>()) { + Assert(n.m_data_type == ASTNodeDataType::vector_t); + switch (n.m_data_type.dimension()) { + case 1: { + n.m_node_processor = std::make_unique<TinyVectorExpressionProcessor<1>>(n); + break; + } + case 2: { + n.m_node_processor = std::make_unique<TinyVectorExpressionProcessor<2>>(n); + break; + } + case 3: { + n.m_node_processor = std::make_unique<TinyVectorExpressionProcessor<3>>(n); + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid vector dimension"); + } + // LCOV_EXCL_STOP + } + } else if (n.is_type<language::matrix_expression>()) { + Assert(n.m_data_type == ASTNodeDataType::matrix_t); + Assert(n.m_data_type.numberOfRows() == n.m_data_type.numberOfColumns()); + + switch (n.m_data_type.numberOfRows()) { + case 1: { + n.m_node_processor = std::make_unique<TinyMatrixExpressionProcessor<1, 1>>(n); + break; + } + case 2: { + n.m_node_processor = std::make_unique<TinyMatrixExpressionProcessor<2, 2>>(n); + break; + } + case 3: { + n.m_node_processor = std::make_unique<TinyMatrixExpressionProcessor<3, 3>>(n); + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid matrix dimension"); + } + // LCOV_EXCL_STOP + } + + } else if ((n.is_type<language::row_expression>())) { + n.m_node_processor = std::make_unique<FakeProcessor>(); + } else if ((n.is_type<language::function_argument_list>()) or (n.is_type<language::expression_list>())) { n.m_node_processor = std::make_unique<ASTNodeExpressionListProcessor>(n); diff --git a/src/language/ast/ASTNodeFunctionExpressionBuilder.cpp b/src/language/ast/ASTNodeFunctionExpressionBuilder.cpp index 6a91a15d13978b423daa563c1b668c5fe0f93489..a381123884250e9cd574495d7c3add369863aa59 100644 --- a/src/language/ast/ASTNodeFunctionExpressionBuilder.cpp +++ b/src/language/ast/ASTNodeFunctionExpressionBuilder.cpp @@ -3,8 +3,6 @@ #include <language/PEGGrammar.hpp> #include <language/ast/ASTNodeDataTypeFlattener.hpp> #include <language/node_processor/FunctionProcessor.hpp> -#include <language/node_processor/TupleToTinyMatrixProcessor.hpp> -#include <language/node_processor/TupleToTinyVectorProcessor.hpp> #include <language/utils/ASTNodeNaturalConversionChecker.hpp> #include <language/utils/FunctionTable.hpp> #include <language/utils/SymbolTable.hpp> @@ -80,16 +78,6 @@ ASTNodeFunctionExpressionBuilder::_getArgumentConverter(SymbolType& parameter_sy // LCOV_EXCL_STOP } } - case ASTNodeDataType::list_t: { - if (node_sub_data_type.m_parent_node.children.size() == parameter_v.dimension()) { - return std::make_unique<FunctionTinyVectorArgumentConverter<ParameterT, ParameterT>>(parameter_id); - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: invalid argument dimension", - std::vector{node_sub_data_type.m_parent_node.begin()}); - // LCOV_EXCL_STOP - } - } case ASTNodeDataType::int_t: { if (node_sub_data_type.m_parent_node.is_type<language::integer>()) { if (std::stoi(node_sub_data_type.m_parent_node.string()) == 0) { @@ -122,16 +110,6 @@ ASTNodeFunctionExpressionBuilder::_getArgumentConverter(SymbolType& parameter_sy // LCOV_EXCL_STOP } } - case ASTNodeDataType::list_t: { - if (node_sub_data_type.m_parent_node.children.size() == parameter_v.dimension()) { - return std::make_unique<FunctionTinyMatrixArgumentConverter<ParameterT, ParameterT>>(parameter_id); - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: invalid argument dimension", - std::vector{node_sub_data_type.m_parent_node.begin()}); - // LCOV_EXCL_STOP - } - } case ASTNodeDataType::int_t: { if (node_sub_data_type.m_parent_node.is_type<language::integer>()) { if (std::stoi(node_sub_data_type.m_parent_node.string()) == 0) { @@ -327,17 +305,6 @@ ASTNodeFunctionExpressionBuilder::_getFunctionProcessor(const ASTNodeDataType& r // LCOV_EXCL_STOP } } - case ASTNodeDataType::list_t: { - if (function_component_expression.children.size() == return_v.dimension()) { - return std::make_unique<FunctionExpressionProcessor<ReturnT, AggregateDataVariant>>( - function_component_expression); - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: invalid dimension for returned vector", - std::vector{function_component_expression.begin()}); - // LCOV_EXCL_STOP - } - } case ASTNodeDataType::int_t: { if (function_component_expression.is_type<language::integer>()) { if (std::stoi(function_component_expression.string()) == 0) { @@ -372,17 +339,6 @@ ASTNodeFunctionExpressionBuilder::_getFunctionProcessor(const ASTNodeDataType& r // LCOV_EXCL_STOP } } - case ASTNodeDataType::list_t: { - if (function_component_expression.children.size() == return_v.dimension()) { - return std::make_unique<FunctionExpressionProcessor<ReturnT, AggregateDataVariant>>( - function_component_expression); - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: invalid dimension for returned vector", - std::vector{function_component_expression.begin()}); - // LCOV_EXCL_STOP - } - } case ASTNodeDataType::int_t: { if (function_component_expression.is_type<language::integer>()) { if (std::stoi(function_component_expression.string()) == 0) { @@ -561,33 +517,7 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node ASTNodeNaturalConversionChecker<AllowRToR1Conversion>{function_expression, vector_type}; - if (function_expression.is_type<language::expression_list>()) { - Assert(vector_type.dimension() == function_expression.children.size()); - - for (size_t i = 0; i < vector_type.dimension(); ++i) { - function_processor->addFunctionExpressionProcessor( - this->_getFunctionProcessor(ASTNodeDataType::build<ASTNodeDataType::double_t>(), node, - *function_expression.children[i])); - } - - switch (vector_type.dimension()) { - case 2: { - node.m_node_processor = - std::make_unique<TupleToTinyVectorProcessor<FunctionProcessor, 2>>(node, std::move(function_processor)); - break; - } - case 3: { - node.m_node_processor = - std::make_unique<TupleToTinyVectorProcessor<FunctionProcessor, 3>>(node, std::move(function_processor)); - break; - } - // LCOV_EXCL_START - default: { - throw ParseError("unexpected error: invalid vector_t dimension", std::vector{node.begin()}); - } - // LCOV_EXCL_STOP - } - } else if (function_expression.is_type<language::integer>()) { + if (function_expression.is_type<language::integer>()) { if (std::stoi(function_expression.string()) == 0) { switch (vector_type.dimension()) { case 1: { @@ -628,33 +558,7 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node ASTNodeNaturalConversionChecker<AllowRToR1Conversion>{function_expression, matrix_type}; - if (function_expression.is_type<language::expression_list>()) { - Assert(matrix_type.numberOfRows() * matrix_type.numberOfColumns() == function_expression.children.size()); - - for (size_t i = 0; i < matrix_type.numberOfRows() * matrix_type.numberOfColumns(); ++i) { - function_processor->addFunctionExpressionProcessor( - this->_getFunctionProcessor(ASTNodeDataType::build<ASTNodeDataType::double_t>(), node, - *function_expression.children[i])); - } - - switch (matrix_type.numberOfRows()) { - case 2: { - node.m_node_processor = - std::make_unique<TupleToTinyMatrixProcessor<FunctionProcessor, 2>>(node, std::move(function_processor)); - break; - } - case 3: { - node.m_node_processor = - std::make_unique<TupleToTinyMatrixProcessor<FunctionProcessor, 3>>(node, std::move(function_processor)); - break; - } - // LCOV_EXCL_START - default: { - throw ParseError("unexpected error: invalid matrix_t dimensions", std::vector{node.begin()}); - } - // LCOV_EXCL_STOP - } - } else if (function_expression.is_type<language::integer>()) { + if (function_expression.is_type<language::integer>()) { if (std::stoi(function_expression.string()) == 0) { switch (matrix_type.numberOfRows()) { case 1: { diff --git a/src/language/ast/ASTNodeListAffectationExpressionBuilder.cpp b/src/language/ast/ASTNodeListAffectationExpressionBuilder.cpp index edec0c149615f28a35256afc62f3ceef3182c3e1..5ec9c784508f92d9051e23d72e8cbd420712346c 100644 --- a/src/language/ast/ASTNodeListAffectationExpressionBuilder.cpp +++ b/src/language/ast/ASTNodeListAffectationExpressionBuilder.cpp @@ -37,8 +37,7 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( } // LCOV_EXCL_START default: { - throw ParseError("unexpected error: invalid operand type for affectation", - std::vector{node_sub_data_type.m_parent_node.begin()}); + throw UnexpectedError("invalid operand type for affectation"); } // LCOV_EXCL_STOP } @@ -58,25 +57,21 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( if ((node_sub_data_type.m_data_type == ASTNodeDataType::vector_t) and (node_sub_data_type.m_data_type.dimension() == value.dimension())) { list_affectation_processor->template add<ValueT, ValueT>(value_node); - } else if ((node_sub_data_type.m_data_type == ASTNodeDataType::list_t) and - (node_sub_data_type.m_parent_node.children.size() == value.dimension())) { - list_affectation_processor->template add<ValueT, AggregateDataVariant>(value_node); } else if (node_sub_data_type.m_parent_node.is_type<language::integer>()) { if (std::stoi(node_sub_data_type.m_parent_node.string()) == 0) { list_affectation_processor->template add<ValueT, ZeroType>(value_node); } else { // LCOV_EXCL_START - throw ParseError("unexpected error: invalid operand value", - std::vector{node_sub_data_type.m_parent_node.begin()}); + throw UnexpectedError("unexpected error: invalid operand value"); // LCOV_EXCL_STOP } } else { // LCOV_EXCL_START - throw ParseError("unexpected error: invalid dimension", std::vector{node_sub_data_type.m_parent_node.begin()}); + throw UnexpectedError("invalid dimension"); // LCOV_EXCL_STOP } } else { - throw ParseError("unexpected error: invalid value type", std::vector{node_sub_data_type.m_parent_node.begin()}); + static_assert(std::is_same_v<ValueT, TinyVector<1>>, "unexpected value type"); } }; @@ -96,25 +91,585 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( (node_sub_data_type.m_data_type.numberOfRows() == value.numberOfRows()) and (node_sub_data_type.m_data_type.numberOfColumns() == value.numberOfColumns())) { list_affectation_processor->template add<ValueT, ValueT>(value_node); - } else if ((node_sub_data_type.m_data_type == ASTNodeDataType::list_t) and - (node_sub_data_type.m_parent_node.children.size() == value.numberOfRows() * value.numberOfColumns())) { - list_affectation_processor->template add<ValueT, AggregateDataVariant>(value_node); } else if (node_sub_data_type.m_parent_node.is_type<language::integer>()) { if (std::stoi(node_sub_data_type.m_parent_node.string()) == 0) { list_affectation_processor->template add<ValueT, ZeroType>(value_node); } else { // LCOV_EXCL_START - throw ParseError("unexpected error: invalid operand value", - std::vector{node_sub_data_type.m_parent_node.begin()}); + throw UnexpectedError("invalid operand value"); // LCOV_EXCL_STOP } } else { // LCOV_EXCL_START - throw ParseError("unexpected error: invalid dimension", std::vector{node_sub_data_type.m_parent_node.begin()}); + throw UnexpectedError("invalid dimension"); // LCOV_EXCL_STOP } } else { - throw ParseError("unexpected error: invalid value type", std::vector{node_sub_data_type.m_parent_node.begin()}); + static_assert(std::is_same_v<ValueT, TinyMatrix<1>>, "unexpected value type"); + } + }; + + auto add_affectation_processor_for_tuple_data = [&](const ASTNodeDataType& tuple_type, + const ASTNodeSubDataType& node_sub_data_type) { + if constexpr (std::is_same_v<OperatorT, language::eq_op>) { + if (node_sub_data_type.m_data_type == ASTNodeDataType::tuple_t) { + const ASTNodeDataType& rhs_tuple_content = node_sub_data_type.m_data_type.contentType(); + switch (tuple_type.contentType()) { + case ASTNodeDataType::bool_t: { + if (rhs_tuple_content == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<bool>, std::vector<bool>>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::unsigned_int_t: { + if (rhs_tuple_content == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<uint64_t>, std::vector<bool>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<uint64_t>, std::vector<uint64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<uint64_t>, std::vector<int64_t>>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::int_t: { + if (rhs_tuple_content == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<int64_t>, std::vector<bool>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<int64_t>, std::vector<uint64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<int64_t>, std::vector<int64_t>>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::double_t: { + if (rhs_tuple_content == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<double>, std::vector<bool>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<double>, std::vector<uint64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<double>, std::vector<int64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::double_t) { + list_affectation_processor->template add<std::vector<double>, std::vector<double>>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::string_t: { + if (rhs_tuple_content == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<std::string>, std::vector<bool>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<std::string>, std::vector<uint64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<std::string>, std::vector<int64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::double_t) { + list_affectation_processor->template add<std::vector<std::string>, std::vector<double>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::string_t) { + list_affectation_processor->template add<std::vector<std::string>, std::vector<std::string>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::vector_t) { + switch (rhs_tuple_content.dimension()) { + case 1: { + list_affectation_processor->template add<std::vector<std::string>, std::vector<TinyVector<1>>>( + value_node); + break; + } + case 2: { + list_affectation_processor->template add<std::vector<std::string>, std::vector<TinyVector<2>>>( + value_node); + break; + } + case 3: { + list_affectation_processor->template add<std::vector<std::string>, std::vector<TinyVector<3>>>( + value_node); + break; + } + } + } else if (rhs_tuple_content == ASTNodeDataType::matrix_t) { + Assert(rhs_tuple_content.numberOfRows() == rhs_tuple_content.numberOfColumns()); + switch (rhs_tuple_content.numberOfRows()) { + case 1: { + list_affectation_processor->template add<std::vector<std::string>, std::vector<TinyMatrix<1>>>( + value_node); + break; + } + case 2: { + list_affectation_processor->template add<std::vector<std::string>, std::vector<TinyMatrix<2>>>( + value_node); + break; + } + case 3: { + list_affectation_processor->template add<std::vector<std::string>, std::vector<TinyMatrix<3>>>( + value_node); + break; + } + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::vector_t: { + switch (tuple_type.contentType().dimension()) { + case 1: { + if (rhs_tuple_content == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<TinyVector<1>>, std::vector<bool>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<TinyVector<1>>, std::vector<uint64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<TinyVector<1>>, std::vector<int64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::double_t) { + list_affectation_processor->template add<std::vector<TinyVector<1>>, std::vector<double>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::vector_t) { + Assert(rhs_tuple_content.dimension() == 1); + list_affectation_processor->template add<std::vector<TinyVector<1>>, std::vector<TinyVector<1>>>( + value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case 2: { + if (rhs_tuple_content == ASTNodeDataType::vector_t) { + Assert(rhs_tuple_content.dimension() == 2); + list_affectation_processor->template add<std::vector<TinyVector<2>>, std::vector<TinyVector<2>>>( + value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case 3: { + if (rhs_tuple_content == ASTNodeDataType::vector_t) { + Assert(rhs_tuple_content.dimension() == 3); + list_affectation_processor->template add<std::vector<TinyVector<3>>, std::vector<TinyVector<3>>>( + value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid dimension"); + } + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::matrix_t: { + Assert(tuple_type.contentType().numberOfRows() == tuple_type.contentType().numberOfColumns()); + switch (tuple_type.contentType().numberOfRows()) { + case 1: { + if (rhs_tuple_content == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, std::vector<bool>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, std::vector<uint64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, std::vector<int64_t>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::double_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, std::vector<double>>(value_node); + } else if (rhs_tuple_content == ASTNodeDataType::matrix_t) { + Assert(rhs_tuple_content.numberOfRows() == 1); + Assert(rhs_tuple_content.numberOfColumns() == 1); + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, std::vector<TinyMatrix<1>>>( + value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case 2: { + if (rhs_tuple_content == ASTNodeDataType::matrix_t) { + Assert(rhs_tuple_content.numberOfRows() == 2); + Assert(rhs_tuple_content.numberOfColumns() == 2); + list_affectation_processor->template add<std::vector<TinyMatrix<2>>, std::vector<TinyMatrix<2>>>( + value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case 3: { + if (rhs_tuple_content == ASTNodeDataType::matrix_t) { + Assert(rhs_tuple_content.numberOfRows() == 3); + Assert(rhs_tuple_content.numberOfColumns() == 3); + list_affectation_processor->template add<std::vector<TinyMatrix<3>>, std::vector<TinyMatrix<3>>>( + value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid dimension"); + } + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::type_id_t: { + if (rhs_tuple_content == ASTNodeDataType::type_id_t) { + Assert(rhs_tuple_content.nameOfTypeId() == tuple_type.contentType().nameOfTypeId()); + list_affectation_processor->template add<std::vector<EmbeddedData>, std::vector<EmbeddedData>>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid operand type for tuple affectation"); + } + // LCOV_EXCL_STOP + } + } else if (node_sub_data_type.m_data_type == ASTNodeDataType::list_t) { + switch (tuple_type.contentType()) { + case ASTNodeDataType::bool_t: { + list_affectation_processor->template add<std::vector<bool>, AggregateDataVariant>(value_node); + break; + } + case ASTNodeDataType::unsigned_int_t: { + list_affectation_processor->template add<std::vector<uint64_t>, AggregateDataVariant>(value_node); + break; + } + case ASTNodeDataType::int_t: { + list_affectation_processor->template add<std::vector<int64_t>, AggregateDataVariant>(value_node); + break; + } + case ASTNodeDataType::double_t: { + list_affectation_processor->template add<std::vector<double_t>, AggregateDataVariant>(value_node); + break; + } + case ASTNodeDataType::string_t: { + list_affectation_processor->template add<std::vector<std::string>, AggregateDataVariant>(value_node); + break; + } + case ASTNodeDataType::vector_t: { + switch (tuple_type.contentType().dimension()) { + case 1: { + list_affectation_processor->template add<std::vector<TinyVector<1>>, AggregateDataVariant>(value_node); + break; + } + case 2: { + list_affectation_processor->template add<std::vector<TinyVector<2>>, AggregateDataVariant>(value_node); + break; + } + case 3: { + list_affectation_processor->template add<std::vector<TinyVector<3>>, AggregateDataVariant>(value_node); + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid vector dimension"); + } + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::matrix_t: { + Assert(tuple_type.contentType().numberOfRows() == tuple_type.contentType().numberOfColumns()); + switch (tuple_type.contentType().numberOfRows()) { + case 1: { + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, AggregateDataVariant>(value_node); + break; + } + case 2: { + list_affectation_processor->template add<std::vector<TinyMatrix<2>>, AggregateDataVariant>(value_node); + break; + } + case 3: { + list_affectation_processor->template add<std::vector<TinyMatrix<3>>, AggregateDataVariant>(value_node); + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid matrix dimension"); + } + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::type_id_t: { + list_affectation_processor->template add<std::vector<EmbeddedData>, AggregateDataVariant>(value_node); + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid operand type for tuple affectation"); + } + // LCOV_EXCL_STOP + } + } else { + const ASTNodeDataType& rhs_type = node_sub_data_type.m_data_type; + switch (tuple_type.contentType()) { + case ASTNodeDataType::bool_t: { + if (rhs_type == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<bool>, bool>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::unsigned_int_t: { + if (rhs_type == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<uint64_t>, bool>(value_node); + } else if (rhs_type == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<uint64_t>, uint64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<uint64_t>, int64_t>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::int_t: { + if (rhs_type == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<int64_t>, bool>(value_node); + } else if (rhs_type == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<int64_t>, uint64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<int64_t>, int64_t>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::double_t: { + if (rhs_type == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<double>, bool>(value_node); + } else if (rhs_type == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<double>, uint64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<double>, int64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::double_t) { + list_affectation_processor->template add<std::vector<double>, double>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::string_t: { + if (rhs_type == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<std::string>, bool>(value_node); + } else if (rhs_type == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<std::string>, uint64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<std::string>, int64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::double_t) { + list_affectation_processor->template add<std::vector<std::string>, double>(value_node); + } else if (rhs_type == ASTNodeDataType::string_t) { + list_affectation_processor->template add<std::vector<std::string>, std::string>(value_node); + } else if (rhs_type == ASTNodeDataType::vector_t) { + switch (rhs_type.dimension()) { + case 1: { + list_affectation_processor->template add<std::vector<std::string>, TinyVector<1>>(value_node); + break; + } + case 2: { + list_affectation_processor->template add<std::vector<std::string>, TinyVector<2>>(value_node); + break; + } + case 3: { + list_affectation_processor->template add<std::vector<std::string>, TinyVector<3>>(value_node); + break; + } + } + } else if (rhs_type == ASTNodeDataType::matrix_t) { + Assert(rhs_type.numberOfRows() == rhs_type.numberOfColumns()); + switch (rhs_type.numberOfRows()) { + case 1: { + list_affectation_processor->template add<std::vector<std::string>, TinyMatrix<1>>(value_node); + break; + } + case 2: { + list_affectation_processor->template add<std::vector<std::string>, TinyMatrix<2>>(value_node); + break; + } + case 3: { + list_affectation_processor->template add<std::vector<std::string>, TinyMatrix<3>>(value_node); + break; + } + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible rhs type in tuple affectation"); + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::vector_t: { + switch (tuple_type.contentType().dimension()) { + case 1: { + if (rhs_type == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<TinyVector<1>>, bool>(value_node); + } else if (rhs_type == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<TinyVector<1>>, uint64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<TinyVector<1>>, int64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::double_t) { + list_affectation_processor->template add<std::vector<TinyVector<1>>, double>(value_node); + } else if (rhs_type == ASTNodeDataType::vector_t) { + Assert(rhs_type.dimension() == 1); + list_affectation_processor->template add<std::vector<TinyVector<1>>, TinyVector<1>>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case 2: { + if (rhs_type == ASTNodeDataType::vector_t) { + Assert(rhs_type.dimension() == 2); + list_affectation_processor->template add<std::vector<TinyVector<2>>, TinyVector<2>>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<TinyVector<2>>, int64_t>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case 3: { + if (rhs_type == ASTNodeDataType::vector_t) { + Assert(rhs_type.dimension() == 3); + list_affectation_processor->template add<std::vector<TinyVector<3>>, TinyVector<3>>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<TinyVector<3>>, int64_t>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid vector dimension for tuple affectation"); + } + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::matrix_t: { + Assert(tuple_type.contentType().numberOfRows() == tuple_type.contentType().numberOfColumns()); + switch (tuple_type.contentType().numberOfRows()) { + case 1: { + if (rhs_type == ASTNodeDataType::bool_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, bool>(value_node); + } else if (rhs_type == ASTNodeDataType::unsigned_int_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, uint64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, int64_t>(value_node); + } else if (rhs_type == ASTNodeDataType::double_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, double>(value_node); + } else if (rhs_type == ASTNodeDataType::matrix_t) { + Assert(rhs_type.numberOfRows() == 1); + Assert(rhs_type.numberOfColumns() == 1); + list_affectation_processor->template add<std::vector<TinyMatrix<1>>, TinyMatrix<1>>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case 2: { + if (rhs_type == ASTNodeDataType::matrix_t) { + Assert(rhs_type.numberOfRows() == 2); + Assert(rhs_type.numberOfColumns() == 2); + list_affectation_processor->template add<std::vector<TinyMatrix<2>>, TinyMatrix<2>>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<2>>, int64_t>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + case 3: { + if (rhs_type == ASTNodeDataType::matrix_t) { + Assert(rhs_type.numberOfRows() == 3); + Assert(rhs_type.numberOfColumns() == 3); + list_affectation_processor->template add<std::vector<TinyMatrix<3>>, TinyMatrix<3>>(value_node); + } else if (rhs_type == ASTNodeDataType::int_t) { + list_affectation_processor->template add<std::vector<TinyMatrix<3>>, int64_t>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid vector dimension for tuple affectation"); + } + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::type_id_t: { + if (rhs_type == ASTNodeDataType::type_id_t) { + Assert(rhs_type.nameOfTypeId() == tuple_type.contentType().nameOfTypeId()); + list_affectation_processor->template add<std::vector<EmbeddedData>, EmbeddedData>(value_node); + } else { + // LCOV_EXCL_START + throw UnexpectedError("incompatible tuple types in affectation"); + // LCOV_EXCL_STOP + } + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid operand type for tuple affectation"); + } + // LCOV_EXCL_STOP + } + } + } else { + static_assert(std::is_same_v<OperatorT, language::eq_op>, "unexpected operator type"); } }; @@ -127,14 +682,12 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( } // LCOV_EXCL_START default: { - throw ParseError("unexpected error:invalid operand type for embedded data affectation", - std::vector{node_sub_data_type.m_parent_node.begin()}); + throw UnexpectedError("invalid operand type for embedded data affectation"); } // LCOV_EXCL_STOP } } else { - throw ParseError("unexpected error: undefined operator type for embedded data affectation", - std::vector{m_node.begin()}); + static_assert(std::is_same_v<OperatorT, language::eq_op>, "unexpected operator type"); } }; @@ -177,22 +730,44 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( } // LCOV_EXCL_START default: { - throw ParseError("unexpected error: invalid vector dimension", - std::vector{node_sub_data_type.m_parent_node.begin()}); + throw UnexpectedError("invalid vector dimension"); + } + // LCOV_EXCL_STOP + } + break; + } + case ASTNodeDataType::matrix_t: { + Assert(node_sub_data_type.m_data_type.numberOfRows() == node_sub_data_type.m_data_type.numberOfColumns()); + switch (node_sub_data_type.m_data_type.numberOfRows()) { + case 1: { + list_affectation_processor->template add<std::string, TinyMatrix<1>>(value_node); + break; + } + case 2: { + list_affectation_processor->template add<std::string, TinyMatrix<2>>(value_node); + break; + } + case 3: { + list_affectation_processor->template add<std::string, TinyMatrix<3>>(value_node); + break; + } + // LCOV_EXCL_START + default: { + throw UnexpectedError("invalid vector dimension"); } // LCOV_EXCL_STOP } break; } + // LCOV_EXCL_START default: { - throw ParseError("unexpected error:invalid operand type for string affectation", - std::vector{node_sub_data_type.m_parent_node.begin()}); + throw UnexpectedError("invalid operand type for string affectation"); } // LCOV_EXCL_STOP } } else { - throw ParseError("unexpected error: undefined operator type for string affectation", std::vector{m_node.begin()}); + static_assert(std::is_same_v<OperatorT, language::eq_op>, "unexpected operator type"); } }; @@ -235,7 +810,7 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( } // LCOV_EXCL_START default: { - throw ParseError("invalid dimension", std::vector{value_node.begin()}); + throw UnexpectedError("invalid dimension"); } // LCOV_EXCL_STOP } @@ -258,7 +833,7 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( } // LCOV_EXCL_START default: { - throw ParseError("invalid dimension", std::vector{value_node.begin()}); + throw UnexpectedError("invalid dimension"); } // LCOV_EXCL_STOP } @@ -267,10 +842,14 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( case ASTNodeDataType::string_t: { add_affectation_processor_for_string_data(node_sub_data_type); break; + } + case ASTNodeDataType::tuple_t: { + add_affectation_processor_for_tuple_data(value_type, node_sub_data_type); + break; } // LCOV_EXCL_START default: { - throw ParseError("unexpected error: undefined value type for tuple affectation", std::vector{value_node.begin()}); + throw UnexpectedError("unexpected error: undefined value type for tuple affectation"); } // LCOV_EXCL_STOP } diff --git a/src/language/node_processor/AffectationProcessor.hpp b/src/language/node_processor/AffectationProcessor.hpp index 6b764b8d8a0d013b1170f754cb6d551e68ab0fff..bb9b7f03667783c99d19dc34ac5d0befbd98d969 100644 --- a/src/language/node_processor/AffectationProcessor.hpp +++ b/src/language/node_processor/AffectationProcessor.hpp @@ -82,6 +82,15 @@ class AffectationExecutor final : public IAffectationExecutor return true; }()}; + template <typename T> + std::string + _stringify(const T& value) + { + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); + } + public: AffectationExecutor(ASTNode& node, ValueT& lhs) : m_lhs(lhs) { @@ -101,65 +110,20 @@ class AffectationExecutor final : public IAffectationExecutor if constexpr (std::is_same_v<OperatorT, language::eq_op>) { if constexpr (std::is_same_v<std::string, DataT>) { m_lhs = std::get<DataT>(rhs); - } else if constexpr (std::is_arithmetic_v<DataT>) { - m_lhs = std::to_string(std::get<DataT>(rhs)); } else { - std::ostringstream os; - os << std::get<DataT>(rhs); - m_lhs = os.str(); + m_lhs = std::move(_stringify(std::get<DataT>(rhs))); } } else { if constexpr (std::is_same_v<std::string, DataT>) { m_lhs += std::get<std::string>(rhs); - } else if constexpr (std::is_arithmetic_v<DataT>) { - m_lhs += std::to_string(std::get<DataT>(rhs)); } else { - std::ostringstream os; - os << std::get<DataT>(rhs); - m_lhs += os.str(); + m_lhs += std::move(_stringify(std::get<DataT>(rhs))); } } } else { if constexpr (std::is_same_v<OperatorT, language::eq_op>) { if constexpr (std::is_convertible_v<DataT, ValueT>) { m_lhs = std::get<DataT>(rhs); - } else if constexpr (std::is_same_v<DataT, AggregateDataVariant>) { - const AggregateDataVariant& v = std::get<AggregateDataVariant>(rhs); - if constexpr (is_tiny_vector_v<ValueT>) { - for (size_t i = 0; i < m_lhs.dimension(); ++i) { - std::visit( - [&](auto&& vi) { - using Vi_T = std::decay_t<decltype(vi)>; - if constexpr (std::is_convertible_v<Vi_T, double>) { - m_lhs[i] = vi; - } else { - // LCOV_EXCL_START - throw UnexpectedError("unexpected rhs type in affectation"); - // LCOV_EXCL_STOP - } - }, - v[i]); - } - } else if constexpr (is_tiny_matrix_v<ValueT>) { - for (size_t i = 0, l = 0; i < m_lhs.numberOfRows(); ++i) { - for (size_t j = 0; j < m_lhs.numberOfColumns(); ++j, ++l) { - std::visit( - [&](auto&& Aij) { - using Aij_T = std::decay_t<decltype(Aij)>; - if constexpr (std::is_convertible_v<Aij_T, double>) { - m_lhs(i, j) = Aij; - } else { - // LCOV_EXCL_START - throw UnexpectedError("unexpected rhs type in affectation"); - // LCOV_EXCL_STOP - } - }, - v[l]); - } - } - } else { - static_assert(is_tiny_matrix_v<ValueT> or is_tiny_vector_v<ValueT>, "invalid rhs type"); - } } else if constexpr (std::is_same_v<TinyVector<1>, ValueT>) { std::visit( [&](auto&& v) { @@ -186,8 +150,223 @@ class AffectationExecutor final : public IAffectationExecutor } }, rhs); + } else if constexpr (is_std_vector_v<ValueT> and is_std_vector_v<DataT>) { + using ValueContentT = typename ValueT::value_type; + using DataContentT = typename DataT::value_type; + + static_assert(not std::is_same_v<ValueContentT, DataContentT>, + "the case should have been treated previously"); + if constexpr (std::is_convertible_v<DataContentT, ValueContentT>) { + m_lhs.resize(std::get<DataT>(rhs).size()); + std::visit( + [&](auto&& v) { + using Vi_T = std::decay_t<decltype(v)>; + if constexpr (is_std_vector_v<Vi_T>) { + if constexpr (std::is_arithmetic_v<typename Vi_T::value_type>) { + for (size_t i = 0; i < v.size(); ++i) { + m_lhs[i] = v[i]; + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected rhs type in affectation"); + // LCOV_EXCL_STOP + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected rhs type in affectation"); + // LCOV_EXCL_STOP + } + }, + rhs); + } else if constexpr (std::is_same_v<ValueContentT, std::string>) { + m_lhs.resize(std::get<DataT>(rhs).size()); + + std::visit( + [&](auto&& v) { + using V_T = std::decay_t<decltype(v)>; + if constexpr (is_std_vector_v<V_T>) { + for (size_t i = 0; i < v.size(); ++i) { + if constexpr (std::is_same_v<typename V_T::value_type, bool>) { + // Ugly workaround to allow compilation with libstdc++-9 + bool v_i = v[i]; + m_lhs[i] = std::move(_stringify(v_i)); + } else { + m_lhs[i] = std::move(_stringify(v[i])); + } + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected rhs type in affectation"); + // LCOV_EXCL_STOP + } + }, + rhs); + } else if constexpr (is_tiny_vector_v<ValueContentT>) { + static_assert(not std::is_same_v<DataContentT, ValueContentT>, "should have been treated before"); + static_assert(ValueContentT::Dimension == 1, + "conversions are only allowed for dimension 1 TinyVector's"); + + m_lhs.resize(std::get<DataT>(rhs).size()); + + std::visit( + [&](auto&& v) { + if constexpr (is_std_vector_v<std::decay_t<decltype(v)>>) { + using Vi_T = typename std::decay_t<decltype(v)>::value_type; + for (size_t i = 0; i < v.size(); ++i) { + if constexpr (std::is_arithmetic_v<Vi_T>) { + m_lhs[i][0] = v[i]; + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected rhs type in affectation"); + // LCOV_EXCL_STOP + } + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected rhs type in affectation"); + // LCOV_EXCL_STOP + } + }, + rhs); + + } else if constexpr (is_tiny_matrix_v<ValueContentT>) { + static_assert(not std::is_same_v<DataContentT, ValueContentT>, "should have been treated before"); + static_assert(ValueContentT::Dimension == 1, "conversions are only allowed for 1x1 TinyMatrix's"); + + m_lhs.resize(std::get<DataT>(rhs).size()); + + std::visit( + [&](auto&& v) { + if constexpr (is_std_vector_v<std::decay_t<decltype(v)>>) { + using Vi_T = typename std::decay_t<decltype(v)>::value_type; + for (size_t i = 0; i < v.size(); ++i) { + if constexpr (std::is_arithmetic_v<Vi_T>) { + m_lhs[i](0, 0) = v[i]; + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected rhs type in affectation"); + // LCOV_EXCL_STOP + } + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected rhs type in affectation"); + // LCOV_EXCL_STOP + } + }, + rhs); + + } else { + // LCOV_EXCL_START + throw UnexpectedError("invalid value type"); + // LCOV_EXCL_STOP + } + } else if constexpr (is_std_vector_v<ValueT> and std::is_same_v<DataT, AggregateDataVariant>) { + using ValueContentT = typename ValueT::value_type; + const AggregateDataVariant& children_values = std::get<AggregateDataVariant>(rhs); + m_lhs.resize(children_values.size()); + auto& tuple_value = m_lhs; + for (size_t i = 0; i < children_values.size(); ++i) { + std::visit( + [&](auto&& child_value) { + using T = std::decay_t<decltype(child_value)>; + if constexpr (std::is_same_v<T, ValueContentT>) { + tuple_value[i] = child_value; + } else if constexpr (std::is_arithmetic_v<ValueContentT> and + std::is_convertible_v<T, ValueContentT>) { + tuple_value[i] = static_cast<ValueContentT>(child_value); + } else if constexpr (std::is_same_v<std::string, ValueContentT>) { + tuple_value[i] = std::move(_stringify(child_value)); + } else if constexpr (is_tiny_vector_v<ValueContentT>) { + if constexpr (std::is_arithmetic_v<T>) { + if constexpr (std::is_same_v<ValueContentT, TinyVector<1>>) { + tuple_value[i][0] = child_value; + } else { + // in this case a 0 is given + Assert(child_value == 0); + tuple_value[i] = ZeroType{}; + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected error: unexpected right hand side type in affectation"); + // LCOV_EXCL_STOP + } + } else if constexpr (is_tiny_matrix_v<ValueContentT>) { + if constexpr (std::is_arithmetic_v<T>) { + if constexpr (std::is_same_v<ValueContentT, TinyMatrix<1>>) { + tuple_value[i](0, 0) = child_value; + } else { + // in this case a 0 is given + Assert(child_value == 0); + tuple_value[i] = ZeroType{}; + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected error: unexpected right hand side type in affectation"); + // LCOV_EXCL_STOP + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected error: unexpected right hand side type in affectation"); + // LCOV_EXCL_STOP + } + }, + children_values[i]); + } + } else if constexpr (is_std_vector_v<ValueT>) { + using ValueContentT = typename ValueT::value_type; + m_lhs.resize(1); + auto& tuple_value = m_lhs; + std::visit( + [&](auto&& child_value) { + using T = std::decay_t<decltype(child_value)>; + if constexpr (std::is_same_v<T, ValueContentT>) { + tuple_value[0] = child_value; + } else if constexpr (std::is_arithmetic_v<ValueContentT> and + std::is_convertible_v<T, ValueContentT>) { + tuple_value[0] = static_cast<ValueContentT>(child_value); + } else if constexpr (std::is_same_v<std::string, ValueContentT>) { + tuple_value[0] = std::move(_stringify(child_value)); + } else if constexpr (is_tiny_vector_v<ValueContentT>) { + if constexpr (std::is_arithmetic_v<T>) { + if constexpr (std::is_same_v<ValueContentT, TinyVector<1>>) { + tuple_value[0][0] = child_value; + } else { + // in this case a 0 is given + Assert(child_value == 0); + tuple_value[0] = ZeroType{}; + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected error: unexpected right hand side type in affectation"); + // LCOV_EXCL_STOP + } + } else if constexpr (is_tiny_matrix_v<ValueContentT>) { + if constexpr (std::is_arithmetic_v<T>) { + if constexpr (std::is_same_v<ValueContentT, TinyMatrix<1>>) { + tuple_value[0](0, 0) = child_value; + } else { + // in this case a 0 is given + Assert(child_value == 0); + tuple_value[0] = ZeroType{}; + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected error: unexpected right hand side type in affectation"); + // LCOV_EXCL_STOP + } + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected error: unexpected right hand side type in affectation"); + // LCOV_EXCL_STOP + } + }, + rhs); + } else { + // LCOV_EXCL_START throw UnexpectedError("invalid value type"); + // LCOV_EXCL_STOP } } else { AffOp<OperatorT>().eval(m_lhs, std::get<DataT>(rhs)); @@ -264,94 +443,21 @@ class AffectationToDataVariantProcessorBase : public INodeProcessor virtual ~AffectationToDataVariantProcessorBase() = default; }; -template <typename OperatorT, typename ValueT> -class AffectationToTinyVectorFromListProcessor final : public AffectationToDataVariantProcessorBase -{ - private: - ASTNode& m_rhs_node; - - public: - DataVariant - execute(ExecutionPolicy& exec_policy) - { - AggregateDataVariant children_values = std::get<AggregateDataVariant>(m_rhs_node.execute(exec_policy)); - - static_assert(std::is_same_v<OperatorT, language::eq_op>, "forbidden affection operator for list to vectors"); - - ValueT v; - for (size_t i = 0; i < v.dimension(); ++i) { - std::visit( - [&](auto&& child_value) { - using T = std::decay_t<decltype(child_value)>; - if constexpr (std::is_same_v<T, bool> or std::is_same_v<T, uint64_t> or std::is_same_v<T, int64_t> or - std::is_same_v<T, double>) { - v[i] = child_value; - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: unexpected right hand side type in affectation", m_rhs_node.begin()); - // LCOV_EXCL_STOP - } - }, - children_values[i]); - } - - *m_lhs = v; - return {}; - } - - AffectationToTinyVectorFromListProcessor(ASTNode& lhs_node, ASTNode& rhs_node) - : AffectationToDataVariantProcessorBase(lhs_node), m_rhs_node{rhs_node} - {} -}; - -template <typename OperatorT, typename ValueT> -class AffectationToTinyMatrixFromListProcessor final : public AffectationToDataVariantProcessorBase +template <typename ValueT> +class AffectationToTupleProcessor final : public AffectationToDataVariantProcessorBase { private: ASTNode& m_rhs_node; - public: - DataVariant - execute(ExecutionPolicy& exec_policy) + template <typename T> + std::string + _stringify(const T& value) { - AggregateDataVariant children_values = std::get<AggregateDataVariant>(m_rhs_node.execute(exec_policy)); - - static_assert(std::is_same_v<OperatorT, language::eq_op>, "forbidden affection operator for list to vectors"); - - ValueT v; - for (size_t i = 0, l = 0; i < v.numberOfRows(); ++i) { - for (size_t j = 0; j < v.numberOfColumns(); ++j, ++l) { - std::visit( - [&](auto&& child_value) { - using T = std::decay_t<decltype(child_value)>; - if constexpr (std::is_same_v<T, bool> or std::is_same_v<T, uint64_t> or std::is_same_v<T, int64_t> or - std::is_same_v<T, double>) { - v(i, j) = child_value; - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: unexpected right hand side type in affectation", m_rhs_node.begin()); - // LCOV_EXCL_STOP - } - }, - children_values[l]); - } - } - - *m_lhs = v; - return {}; + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); } - AffectationToTinyMatrixFromListProcessor(ASTNode& lhs_node, ASTNode& rhs_node) - : AffectationToDataVariantProcessorBase(lhs_node), m_rhs_node{rhs_node} - {} -}; - -template <typename ValueT> -class AffectationToTupleProcessor final : public AffectationToDataVariantProcessorBase -{ - private: - ASTNode& m_rhs_node; - public: DataVariant execute(ExecutionPolicy& exec_policy) @@ -366,13 +472,7 @@ class AffectationToTupleProcessor final : public AffectationToDataVariantProcess } else if constexpr (std::is_arithmetic_v<ValueT> and std::is_convertible_v<T, ValueT>) { *m_lhs = std::vector{std::move(static_cast<ValueT>(v))}; } else if constexpr (std::is_same_v<std::string, ValueT>) { - if constexpr (std::is_arithmetic_v<T>) { - *m_lhs = std::vector{std::move(std::to_string(v))}; - } else { - std::ostringstream os; - os << v; - *m_lhs = std::vector<std::string>{os.str()}; - } + *m_lhs = std::vector{std::move(_stringify(v))}; } else if constexpr (is_tiny_vector_v<ValueT> or is_tiny_matrix_v<ValueT>) { if constexpr (std::is_same_v<ValueT, TinyVector<1>> and std::is_arithmetic_v<T>) { *m_lhs = std::vector<TinyVector<1>>{TinyVector<1>{static_cast<double>(v)}}; @@ -408,6 +508,15 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian private: ASTNode& m_rhs_node; + template <typename T> + std::string + _stringify(const T& value) + { + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); + } + void _copyAggregateDataVariant(const AggregateDataVariant& children_values) { @@ -421,33 +530,9 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian } else if constexpr (std::is_arithmetic_v<ValueT> and std::is_convertible_v<T, ValueT>) { tuple_value[i] = static_cast<ValueT>(child_value); } else if constexpr (std::is_same_v<std::string, ValueT>) { - if constexpr (std::is_arithmetic_v<T>) { - tuple_value[i] = std::to_string(child_value); - } else { - std::ostringstream os; - os << child_value; - tuple_value[i] = os.str(); - } + tuple_value[i] = std::move(_stringify(child_value)); } else if constexpr (is_tiny_vector_v<ValueT>) { - if constexpr (std::is_same_v<T, AggregateDataVariant>) { - ValueT& v = tuple_value[i]; - Assert(ValueT::Dimension == child_value.size()); - for (size_t j = 0; j < ValueT::Dimension; ++j) { - std::visit( - [&](auto&& vj) { - using Ti = std::decay_t<decltype(vj)>; - if constexpr (std::is_convertible_v<Ti, typename ValueT::data_type>) { - v[j] = vj; - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: unexpected right hand side type in affectation", - m_rhs_node.children[i]->begin()); - // LCOV_EXCL_STOP - } - }, - child_value[j]); - } - } else if constexpr (std::is_arithmetic_v<T>) { + if constexpr (std::is_arithmetic_v<T>) { if constexpr (std::is_same_v<ValueT, TinyVector<1>>) { tuple_value[i][0] = child_value; } else { @@ -462,27 +547,7 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian // LCOV_EXCL_STOP } } else if constexpr (is_tiny_matrix_v<ValueT>) { - if constexpr (std::is_same_v<T, AggregateDataVariant>) { - ValueT& A = tuple_value[i]; - Assert(A.numberOfRows() * A.numberOfColumns() == child_value.size()); - for (size_t j = 0, l = 0; j < A.numberOfRows(); ++j) { - for (size_t k = 0; k < A.numberOfColumns(); ++k, ++l) { - std::visit( - [&](auto&& Ajk) { - using Ti = std::decay_t<decltype(Ajk)>; - if constexpr (std::is_convertible_v<Ti, typename ValueT::data_type>) { - A(j, k) = Ajk; - } else { - // LCOV_EXCL_START - throw ParseError("unexpected error: unexpected right hand side type in affectation", - m_rhs_node.children[i]->begin()); - // LCOV_EXCL_STOP - } - }, - child_value[l]); - } - } - } else if constexpr (std::is_arithmetic_v<T>) { + if constexpr (std::is_arithmetic_v<T>) { if constexpr (std::is_same_v<ValueT, TinyMatrix<1>>) { tuple_value[i](0, 0) = child_value; } else { @@ -522,16 +587,8 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian v[i] = static_cast<DataType>(values[i]); } } else if constexpr (std::is_same_v<ValueT, std::string>) { - if constexpr (std::is_arithmetic_v<DataType>) { - for (size_t i = 0; i < values.size(); ++i) { - v[i] = std::to_string(values[i]); - } - } else { - for (size_t i = 0; i < values.size(); ++i) { - std::ostringstream sout; - sout << values[i]; - v[i] = sout.str(); - } + for (size_t i = 0; i < values.size(); ++i) { + v[i] = std::move(_stringify(values[i])); } } else { // LCOV_EXCL_START diff --git a/src/language/node_processor/FunctionProcessor.hpp b/src/language/node_processor/FunctionProcessor.hpp index 16e65e6e1e1ca63a7e1fa57e109856b3da25610a..9dd9203275ef91c08742f9f58769e9023e24b852 100644 --- a/src/language/node_processor/FunctionProcessor.hpp +++ b/src/language/node_processor/FunctionProcessor.hpp @@ -20,38 +20,6 @@ class FunctionExpressionProcessor final : public INodeProcessor { if constexpr (std::is_same_v<ReturnType, ExpressionValueType>) { return m_function_expression.execute(exec_policy); - } else if constexpr (std::is_same_v<AggregateDataVariant, ExpressionValueType>) { - static_assert(is_tiny_vector_v<ReturnType> or is_tiny_matrix_v<ReturnType>, "unexpected return type"); - ReturnType return_value{}; - auto value = std::get<ExpressionValueType>(m_function_expression.execute(exec_policy)); - if constexpr (is_tiny_vector_v<ReturnType>) { - for (size_t i = 0; i < ReturnType::Dimension; ++i) { - std::visit( - [&](auto&& vi) { - using Vi_T = std::decay_t<decltype(vi)>; - if constexpr (std::is_convertible_v<Vi_T, double>) { - return_value[i] = vi; - } - }, - value[i]); - } - } else { - static_assert(is_tiny_matrix_v<ReturnType>); - - for (size_t i = 0, l = 0; i < return_value.numberOfRows(); ++i) { - for (size_t j = 0; j < return_value.numberOfColumns(); ++j, ++l) { - std::visit( - [&](auto&& Aij) { - using Vi_T = std::decay_t<decltype(Aij)>; - if constexpr (std::is_convertible_v<Vi_T, double>) { - return_value(i, j) = Aij; - } - }, - value[l]); - } - } - } - return return_value; } else if constexpr (std::is_same_v<ReturnType, std::string>) { return std::to_string(std::get<ExpressionValueType>(m_function_expression.execute(exec_policy))); } else if constexpr (std::is_same_v<ExpressionValueType, ZeroType>) { @@ -63,7 +31,9 @@ class FunctionExpressionProcessor final : public INodeProcessor static_assert(ReturnType::Dimension == 1, "invalid conversion"); return ReturnType(std::get<ExpressionValueType>(m_function_expression.execute(exec_policy))); } else { + // LCOV_EXCL_START throw UnexpectedError("invalid conversion"); + // LCOV_EXCL_STOP } } diff --git a/src/language/node_processor/InnerListToVectorProcessor.hpp b/src/language/node_processor/InnerListToVectorProcessor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ef74daaabe5c0e2f475b1693b7bb9627ed600f40 --- /dev/null +++ b/src/language/node_processor/InnerListToVectorProcessor.hpp @@ -0,0 +1,30 @@ +#ifndef INNER_LIST_TO_VECTOR_PROCESSOR_HPP +#define INNER_LIST_TO_VECTOR_PROCESSOR_HPP + +#include <language/ast/ASTNode.hpp> +#include <language/node_processor/ASTNodeExpressionListProcessor.hpp> +#include <language/node_processor/INodeProcessor.hpp> + +class InnerListToVectorProcessor final : public INodeProcessor +{ + private: + std::unique_ptr<ASTNodeExpressionListProcessor> m_expression_list_processor; + + public: + DataVariant + execute(ExecutionPolicy& exec_policy) + { + AggregateDataVariant v = std::get<AggregateDataVariant>(m_expression_list_processor->execute(exec_policy)); + + v.setIsFlattenable(false); + return v; + } + + InnerListToVectorProcessor(ASTNode& node) + : m_expression_list_processor{std::make_unique<ASTNodeExpressionListProcessor>(node)} + {} + + ~InnerListToVectorProcessor() = default; +}; + +#endif // INNER_LIST_TO_VECTOR_PROCESSOR_HPP diff --git a/src/language/node_processor/TinyMatrixExpressionProcessor.hpp b/src/language/node_processor/TinyMatrixExpressionProcessor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bcb3e65f35b301c6adbe12eeb02e6024cb9ea0da --- /dev/null +++ b/src/language/node_processor/TinyMatrixExpressionProcessor.hpp @@ -0,0 +1,46 @@ +#ifndef TINY_MATRIX_EXPRESSION_PROCESSOR_HPP +#define TINY_MATRIX_EXPRESSION_PROCESSOR_HPP + +#include <algebra/TinyMatrix.hpp> +#include <language/PEGGrammar.hpp> +#include <language/ast/ASTNode.hpp> +#include <language/node_processor/INodeProcessor.hpp> + +template <size_t M, size_t N> +class TinyMatrixExpressionProcessor final : public INodeProcessor +{ + private: + ASTNode& m_node; + + public: + PUGS_INLINE + DataVariant + execute(ExecutionPolicy& exec_policy) + { + TinyMatrix<M, N> A{}; + Assert(m_node.children.size() == M); + + for (size_t i = 0; i < M; ++i) { + for (size_t j = 0; j < N; ++j) { + std::visit( + [&](auto&& x) { + using ValueT = std::decay_t<decltype(x)>; + if constexpr (std::is_arithmetic_v<ValueT>) { + A(i, j) = x; + } else { + // LCOV_EXCL_START + Assert(false, "unexpected value type"); + // LCOV_EXCL_STOP + } + }, + m_node.children[i]->children[j]->execute(exec_policy)); + } + } + + return A; + } + + TinyMatrixExpressionProcessor(ASTNode& node) : m_node{node} {} +}; + +#endif // TINY_MATRIX_EXPRESSION_PROCESSOR_HPP diff --git a/src/language/node_processor/TinyVectorExpressionProcessor.hpp b/src/language/node_processor/TinyVectorExpressionProcessor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ac86b9025b54f673c3cad636aaf1178a55e436a1 --- /dev/null +++ b/src/language/node_processor/TinyVectorExpressionProcessor.hpp @@ -0,0 +1,44 @@ +#ifndef TINY_VECTOR_EXPRESSION_PROCESSOR_HPP +#define TINY_VECTOR_EXPRESSION_PROCESSOR_HPP + +#include <algebra/TinyVector.hpp> +#include <language/PEGGrammar.hpp> +#include <language/ast/ASTNode.hpp> +#include <language/node_processor/INodeProcessor.hpp> + +template <size_t Dimension> +class TinyVectorExpressionProcessor final : public INodeProcessor +{ + private: + ASTNode& m_node; + + public: + PUGS_INLINE + DataVariant + execute(ExecutionPolicy& exec_policy) + { + TinyVector<Dimension> v{}; + Assert(m_node.children.size() == Dimension); + + for (size_t i = 0; i < Dimension; ++i) { + std::visit( + [&](auto&& x) { + using ValueT = std::decay_t<decltype(x)>; + if constexpr (std::is_arithmetic_v<ValueT>) { + v[i] = x; + } else { + // LCOV_EXCL_START + Assert(false, "unexpected value type"); + // LCOV_EXCL_STOP + } + }, + m_node.children[i]->execute(exec_policy)); + } + + return v; + } + + TinyVectorExpressionProcessor(ASTNode& node) : m_node{node} {} +}; + +#endif // TINY_VECTOR_EXPRESSION_PROCESSOR_HPP diff --git a/src/language/node_processor/TupleToTinyMatrixProcessor.hpp b/src/language/node_processor/TupleToTinyMatrixProcessor.hpp deleted file mode 100644 index 77bc45e8419f7d2e58447247aef3975c337813c5..0000000000000000000000000000000000000000 --- a/src/language/node_processor/TupleToTinyMatrixProcessor.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef TUPLE_TO_TINY_MATRIX_PROCESSOR_HPP -#define TUPLE_TO_TINY_MATRIX_PROCESSOR_HPP - -#include <language/ast/ASTNode.hpp> -#include <language/node_processor/INodeProcessor.hpp> - -template <typename TupleProcessorT, size_t N> -class TupleToTinyMatrixProcessor final : public INodeProcessor -{ - private: - ASTNode& m_node; - - std::unique_ptr<TupleProcessorT> m_tuple_processor; - - public: - DataVariant - execute(ExecutionPolicy& exec_policy) - { - AggregateDataVariant v = std::get<AggregateDataVariant>(m_tuple_processor->execute(exec_policy)); - - Assert(v.size() == N * N); - - TinyMatrix<N> A; - - for (size_t i = 0, l = 0; i < N; ++i) { - for (size_t j = 0; j < N; ++j, ++l) { - std::visit( - [&](auto&& Aij) { - using ValueT = std::decay_t<decltype(Aij)>; - if constexpr (std::is_arithmetic_v<ValueT>) { - A(i, j) = Aij; - } else { - // LCOV_EXCL_START - Assert(false, "unexpected value type"); - // LCOV_EXCL_STOP - } - }, - v[l]); - } - } - - return DataVariant{std::move(A)}; - } - - TupleToTinyMatrixProcessor(ASTNode& node) : m_node{node}, m_tuple_processor{std::make_unique<TupleProcessorT>(node)} - {} - - TupleToTinyMatrixProcessor(ASTNode& node, std::unique_ptr<TupleProcessorT>&& tuple_processor) - : m_node{node}, m_tuple_processor{std::move(tuple_processor)} - {} -}; - -#endif // TUPLE_TO_TINY_MATRIX_PROCESSOR_HPP diff --git a/src/language/node_processor/TupleToTinyVectorProcessor.hpp b/src/language/node_processor/TupleToTinyVectorProcessor.hpp deleted file mode 100644 index da4f1e08dc0351e43df185e13415669f1ef26b44..0000000000000000000000000000000000000000 --- a/src/language/node_processor/TupleToTinyVectorProcessor.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef TUPLE_TO_TINY_VECTOR_PROCESSOR_HPP -#define TUPLE_TO_TINY_VECTOR_PROCESSOR_HPP - -#include <language/ast/ASTNode.hpp> -#include <language/node_processor/INodeProcessor.hpp> - -template <typename TupleProcessorT, size_t N> -class TupleToTinyVectorProcessor final : public INodeProcessor -{ - private: - ASTNode& m_node; - - std::unique_ptr<TupleProcessorT> m_tuple_processor; - - public: - DataVariant - execute(ExecutionPolicy& exec_policy) - { - AggregateDataVariant v = std::get<AggregateDataVariant>(m_tuple_processor->execute(exec_policy)); - - Assert(v.size() == N); - - TinyVector<N> x; - - for (size_t i = 0; i < N; ++i) { - std::visit( - [&](auto&& v) { - using ValueT = std::decay_t<decltype(v)>; - if constexpr (std::is_arithmetic_v<ValueT>) { - x[i] = v; - } else { - // LCOV_EXCL_START - Assert(false, "unexpected value type"); - // LCOV_EXCL_STOP - } - }, - v[i]); - } - - return DataVariant{std::move(x)}; - } - - TupleToTinyVectorProcessor(ASTNode& node) : m_node{node}, m_tuple_processor{std::make_unique<TupleProcessorT>(node)} - {} - - TupleToTinyVectorProcessor(ASTNode& node, std::unique_ptr<TupleProcessorT>&& tuple_processor) - : m_node{node}, m_tuple_processor{std::move(tuple_processor)} - {} -}; - -#endif // TUPLE_TO_TINY_VECTOR_PROCESSOR_HPP diff --git a/src/language/node_processor/TupleToVectorProcessor.hpp b/src/language/node_processor/TupleToVectorProcessor.hpp deleted file mode 100644 index 74ad59acb95e0e853a880fb171e93d77c55dcd74..0000000000000000000000000000000000000000 --- a/src/language/node_processor/TupleToVectorProcessor.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef TUPLE_TO_VECTOR_PROCESSOR_HPP -#define TUPLE_TO_VECTOR_PROCESSOR_HPP - -#include <language/ast/ASTNode.hpp> -#include <language/node_processor/INodeProcessor.hpp> - -template <typename TupleProcessorT> -class TupleToVectorProcessor final : public INodeProcessor -{ - private: - ASTNode& m_node; - - std::unique_ptr<TupleProcessorT> m_tuple_processor; - - public: - DataVariant - execute(ExecutionPolicy& exec_policy) - { - AggregateDataVariant v = std::get<AggregateDataVariant>(m_tuple_processor->execute(exec_policy)); - - v.setIsFlattenable(false); - return v; - } - - TupleToVectorProcessor(ASTNode& node) : m_node{node}, m_tuple_processor{std::make_unique<TupleProcessorT>(node)} {} - - TupleToVectorProcessor(ASTNode& node, std::unique_ptr<TupleProcessorT>&& tuple_processor) - : m_node{node}, m_tuple_processor{std::move(tuple_processor)} - {} -}; - -#endif // TUPLE_TO_TINY_VECTOR_PROCESSOR_HPP diff --git a/src/language/utils/ASTNodeDataType.cpp b/src/language/utils/ASTNodeDataType.cpp index ddea3a6dd9a6a79fda474bb93e05645d55dd7503..3c6d4af0f8be9f4002834fb15548316f301b0159 100644 --- a/src/language/utils/ASTNodeDataType.cpp +++ b/src/language/utils/ASTNodeDataType.cpp @@ -2,7 +2,9 @@ #include <language/PEGGrammar.hpp> #include <language/ast/ASTNode.hpp> +#include <language/utils/ASTNodeNaturalConversionChecker.hpp> #include <language/utils/ParseError.hpp> +#include <language/utils/SymbolTable.hpp> #include <utils/PugsAssert.hpp> ASTNodeDataType @@ -19,6 +21,28 @@ getVectorDataType(const ASTNode& type_node) if (not(dimension > 0 and dimension <= 3)) { throw ParseError("invalid dimension (must be 1, 2 or 3)", dimension_node.begin()); } + + return ASTNodeDataType::build<ASTNodeDataType::vector_t>(dimension); +} + +ASTNodeDataType +getVectorExpressionType(const ASTNode& vector_expression_node) +{ + if (not(vector_expression_node.is_type<language::vector_expression>() and + (vector_expression_node.children.size() > 0))) { + throw ParseError("unexpected node type", vector_expression_node.begin()); + } + + const size_t dimension = vector_expression_node.children.size(); + if (not(dimension > 0 and dimension <= 3)) { + throw ParseError("invalid dimension (must be 1, 2 or 3)", vector_expression_node.begin()); + } + + for (size_t i = 0; i < dimension; ++i) { + ASTNodeNaturalConversionChecker(*vector_expression_node.children[i], + ASTNodeDataType::build<ASTNodeDataType::double_t>()); + } + return ASTNodeDataType::build<ASTNodeDataType::vector_t>(dimension); } @@ -52,6 +76,89 @@ getMatrixDataType(const ASTNode& type_node) return ASTNodeDataType::build<ASTNodeDataType::matrix_t>(dimension0, dimension1); } +ASTNodeDataType +getMatrixExpressionType(const ASTNode& matrix_expression_node) +{ + if (not(matrix_expression_node.is_type<language::matrix_expression>() and + matrix_expression_node.children.size() > 0)) { + throw ParseError("unexpected node type", matrix_expression_node.begin()); + } + + const size_t dimension0 = matrix_expression_node.children.size(); + if (not(dimension0 > 0 and dimension0 <= 3)) { + throw ParseError("invalid dimension (must be 1, 2 or 3)", matrix_expression_node.begin()); + } + for (size_t i = 0; i < dimension0; ++i) { + if (not matrix_expression_node.children[i]->is_type<language::row_expression>()) { + throw ParseError("expecting row expression", matrix_expression_node.children[i]->begin()); + } + } + + const size_t dimension1 = matrix_expression_node.children[0]->children.size(); + if (dimension0 != dimension1) { + throw ParseError("only square matrices are supported", matrix_expression_node.begin()); + } + + for (size_t i = 1; i < dimension0; ++i) { + if (matrix_expression_node.children[i]->children.size() != dimension1) { + throw ParseError("row must have same sizes", matrix_expression_node.begin()); + } + } + + for (size_t i = 0; i < dimension0; ++i) { + for (size_t j = 0; j < dimension1; ++j) { + ASTNodeNaturalConversionChecker(*matrix_expression_node.children[i]->children[j], + ASTNodeDataType::build<ASTNodeDataType::double_t>()); + } + } + + return ASTNodeDataType::build<ASTNodeDataType::matrix_t>(dimension0, dimension1); +} + +ASTNodeDataType +getTupleDataType(const ASTNode& type_node) +{ + const auto& content_node = type_node.children[0]; + + if (content_node->is_type<language::type_name_id>()) { + const std::string& type_name_id = content_node->string(); + + auto& symbol_table = *type_node.m_symbol_table; + + const auto [i_type_symbol, found] = symbol_table.find(type_name_id, content_node->begin()); + if (not found) { + throw ParseError("undefined type identifier", std::vector{content_node->begin()}); + } else if (i_type_symbol->attributes().dataType() != ASTNodeDataType::type_name_id_t) { + std::ostringstream os; + os << "invalid type identifier, '" << type_name_id << "' was previously defined as a '" + << dataTypeName(i_type_symbol->attributes().dataType()) << '\''; + throw ParseError(os.str(), std::vector{content_node->begin()}); + } + + content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::type_id_t>(type_name_id); + } else if (content_node->is_type<language::B_set>()) { + content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::bool_t>(); + } else if (content_node->is_type<language::Z_set>()) { + content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::int_t>(); + } else if (content_node->is_type<language::N_set>()) { + content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::unsigned_int_t>(); + } else if (content_node->is_type<language::R_set>()) { + content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::double_t>(); + } else if (content_node->is_type<language::vector_type>()) { + content_node->m_data_type = getVectorDataType(*type_node.children[0]); + } else if (content_node->is_type<language::matrix_type>()) { + content_node->m_data_type = getMatrixDataType(*type_node.children[0]); + } else if (content_node->is_type<language::string_type>()) { + content_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::string_t>(); + } else { + // LCOV_EXCL_START + throw UnexpectedError("unexpected content type in tuple"); + // LCOV_EXCL_STOP + } + + return ASTNodeDataType::build<ASTNodeDataType::tuple_t>(content_node->m_data_type); +} + std::string dataTypeName(const ASTNodeDataType& data_type) { diff --git a/src/language/utils/ASTNodeDataType.hpp b/src/language/utils/ASTNodeDataType.hpp index ea744757cf68b5055605111d35acc14564b06b30..b7cc48fefaa6d849cf970641b37279a5a85ca15e 100644 --- a/src/language/utils/ASTNodeDataType.hpp +++ b/src/language/utils/ASTNodeDataType.hpp @@ -13,8 +13,12 @@ class ASTNode; class ASTNodeDataType; ASTNodeDataType getVectorDataType(const ASTNode& type_node); +ASTNodeDataType getVectorExpressionType(const ASTNode& vector_expression_node); ASTNodeDataType getMatrixDataType(const ASTNode& type_node); +ASTNodeDataType getMatrixExpressionType(const ASTNode& matrix_expression_node); + +ASTNodeDataType getTupleDataType(const ASTNode& type_node); std::string dataTypeName(const std::vector<ASTNodeDataType>& data_type_vector); diff --git a/src/language/utils/ASTNodeNaturalConversionChecker.cpp b/src/language/utils/ASTNodeNaturalConversionChecker.cpp index a05c5aa1b4fcc79d531ea51544fb47dc1b40698e..b3ad34eeabdcaa942590fa34a7b1940f7a552834 100644 --- a/src/language/utils/ASTNodeNaturalConversionChecker.cpp +++ b/src/language/utils/ASTNodeNaturalConversionChecker.cpp @@ -48,23 +48,9 @@ ASTNodeNaturalConversionChecker<RToR1Conversion>::_checkIsNaturalExpressionConve } else if (target_data_type == ASTNodeDataType::vector_t) { switch (data_type) { case ASTNodeDataType::list_t: { - const auto& content_type_list = data_type.contentTypeList(); - if (content_type_list.size() != target_data_type.dimension()) { - std::ostringstream os; - os << "incompatible dimensions in affectation: expecting " << target_data_type.dimension() << ", but provided " - << content_type_list.size(); - throw ParseError(os.str(), std::vector{node.begin()}); - } - - Assert(content_type_list.size() == node.children.size()); - for (size_t i = 0; i < content_type_list.size(); ++i) { - const auto& child_type = *content_type_list[i]; - const auto& child_node = *node.children[i]; - Assert(child_type == child_node.m_data_type); - this->_checkIsNaturalExpressionConversion(child_node, child_type, - ASTNodeDataType::build<ASTNodeDataType::double_t>()); - } - + std::ostringstream os; + os << "cannot convert list to " << dataTypeName(target_data_type); + throw ParseError(os.str(), std::vector{node.begin()}); break; } case ASTNodeDataType::vector_t: { @@ -92,24 +78,9 @@ ASTNodeNaturalConversionChecker<RToR1Conversion>::_checkIsNaturalExpressionConve } else if (target_data_type == ASTNodeDataType::matrix_t) { switch (data_type) { case ASTNodeDataType::list_t: { - const auto& content_type_list = data_type.contentTypeList(); - if (content_type_list.size() != (target_data_type.numberOfRows() * target_data_type.numberOfColumns())) { - std::ostringstream os; - os << "incompatible dimensions in affectation: expecting " - << target_data_type.numberOfRows() * target_data_type.numberOfColumns() << ", but provided " - << content_type_list.size(); - throw ParseError(os.str(), std::vector{node.begin()}); - } - - Assert(content_type_list.size() == node.children.size()); - for (size_t i = 0; i < content_type_list.size(); ++i) { - const auto& child_type = *content_type_list[i]; - const auto& child_node = *node.children[i]; - Assert(child_type == child_node.m_data_type); - this->_checkIsNaturalExpressionConversion(child_node, child_type, - ASTNodeDataType::build<ASTNodeDataType::double_t>()); - } - + std::ostringstream os; + os << "cannot convert list to " << dataTypeName(target_data_type); + throw ParseError(os.str(), std::vector{node.begin()}); break; } case ASTNodeDataType::matrix_t: { @@ -137,7 +108,7 @@ ASTNodeNaturalConversionChecker<RToR1Conversion>::_checkIsNaturalExpressionConve } } else if (target_data_type == ASTNodeDataType::tuple_t) { const ASTNodeDataType& target_content_type = target_data_type.contentType(); - if (node.m_data_type == ASTNodeDataType::tuple_t) { + if ((data_type == ASTNodeDataType::tuple_t) or (node.m_data_type == ASTNodeDataType::tuple_t)) { this->_checkIsNaturalExpressionConversion(node, data_type.contentType(), target_content_type); } else if (node.m_data_type == ASTNodeDataType::list_t) { for (const auto& child : node.children) { diff --git a/src/language/utils/AffectationProcessorBuilder.hpp b/src/language/utils/AffectationProcessorBuilder.hpp index 0e4b7ace65654b650989e817dbe2e4a545ae320f..ed1995106225f6c04ce583a4e8ef257fca54b038 100644 --- a/src/language/utils/AffectationProcessorBuilder.hpp +++ b/src/language/utils/AffectationProcessorBuilder.hpp @@ -56,30 +56,6 @@ class AffectationToTupleFromListProcessorBuilder final : public IAffectationProc } }; -template <typename OperatorT, typename ValueT> -class AffectationToTinyVectorFromListProcessorBuilder final : public IAffectationProcessorBuilder -{ - public: - AffectationToTinyVectorFromListProcessorBuilder() = default; - std::unique_ptr<INodeProcessor> - getNodeProcessor(ASTNode& lhs_node, ASTNode& rhs_node) const final - { - return std::make_unique<AffectationToTinyVectorFromListProcessor<OperatorT, ValueT>>(lhs_node, rhs_node); - } -}; - -template <typename OperatorT, typename ValueT> -class AffectationToTinyMatrixFromListProcessorBuilder final : public IAffectationProcessorBuilder -{ - public: - AffectationToTinyMatrixFromListProcessorBuilder() = default; - std::unique_ptr<INodeProcessor> - getNodeProcessor(ASTNode& lhs_node, ASTNode& rhs_node) const final - { - return std::make_unique<AffectationToTinyMatrixFromListProcessor<OperatorT, ValueT>>(lhs_node, rhs_node); - } -}; - template <typename OperatorT, typename ValueT> class AffectationFromZeroProcessorBuilder final : public IAffectationProcessorBuilder { diff --git a/src/language/utils/AffectationRegisterForRn.cpp b/src/language/utils/AffectationRegisterForRn.cpp index 7d38dc64c1d245d4d6c530e891ffd6eaecd63372..180bd5ebce8d19dd8aa6f4b628a700632ea44ab0 100644 --- a/src/language/utils/AffectationRegisterForRn.cpp +++ b/src/language/utils/AffectationRegisterForRn.cpp @@ -16,12 +16,6 @@ AffectationRegisterForRn<Dimension>::_register_eq_op() language::eq_op>(Rn, ASTNodeDataType::build<ASTNodeDataType::int_t>(), std::make_shared<AffectationFromZeroProcessorBuilder<language::eq_op, TinyVector<Dimension>>>()); - repository.addAffectation<language::eq_op>(Rn, - ASTNodeDataType::build<ASTNodeDataType::list_t>( - std::vector<std::shared_ptr<const ASTNodeDataType>>{}), - std::make_shared<AffectationToTinyVectorFromListProcessorBuilder< - language::eq_op, TinyVector<Dimension>>>()); - repository .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rn), ASTNodeDataType::build<ASTNodeDataType::int_t>(), diff --git a/src/language/utils/AffectationRegisterForRnxn.cpp b/src/language/utils/AffectationRegisterForRnxn.cpp index efa95d92bbcfd32af37f6c3f69477d7ee985a560..0eaf1c6af2e0caccf0fa143208c774a047d6e550 100644 --- a/src/language/utils/AffectationRegisterForRnxn.cpp +++ b/src/language/utils/AffectationRegisterForRnxn.cpp @@ -16,12 +16,6 @@ AffectationRegisterForRnxn<Dimension>::_register_eq_op() language::eq_op>(Rnxn, ASTNodeDataType::build<ASTNodeDataType::int_t>(), std::make_shared<AffectationFromZeroProcessorBuilder<language::eq_op, TinyMatrix<Dimension>>>()); - repository.addAffectation<language::eq_op>(Rnxn, - ASTNodeDataType::build<ASTNodeDataType::list_t>( - std::vector<std::shared_ptr<const ASTNodeDataType>>{}), - std::make_shared<AffectationToTinyMatrixFromListProcessorBuilder< - language::eq_op, TinyMatrix<Dimension>>>()); - repository .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rnxn), ASTNodeDataType::build<ASTNodeDataType::int_t>(), diff --git a/src/language/utils/BuiltinFunctionEmbedderUtils.cpp b/src/language/utils/BuiltinFunctionEmbedderUtils.cpp index ba6658ff7b5dc901182c62f7a07c0018ed94bd5a..be3474ef7ae4e657d7553715c8414180ddc15d52 100644 --- a/src/language/utils/BuiltinFunctionEmbedderUtils.cpp +++ b/src/language/utils/BuiltinFunctionEmbedderUtils.cpp @@ -82,24 +82,7 @@ getBuiltinFunctionEmbedder(ASTNode& n) } bool is_castable = true; if (target_type.dimension() > 1) { - switch (arg_type) { - case ASTNodeDataType::int_t: { - break; - } - case ASTNodeDataType::list_t: { - if (arg_type.contentTypeList().size() != target_type.dimension()) { - is_castable = false; - break; - } - for (auto list_arg : arg_type.contentTypeList()) { - is_castable &= isNaturalConversion(*list_arg, ASTNodeDataType::build<ASTNodeDataType::double_t>()); - } - break; - } - default: { - is_castable &= false; - } - } + return (arg_type == ASTNodeDataType::int_t); } else { is_castable &= isNaturalConversion(arg_type, ASTNodeDataType::build<ASTNodeDataType::double_t>()); } @@ -113,24 +96,7 @@ getBuiltinFunctionEmbedder(ASTNode& n) bool is_castable = true; if (target_type.numberOfRows() > 1) { - switch (arg_type) { - case ASTNodeDataType::int_t: { - break; - } - case ASTNodeDataType::list_t: { - if (arg_type.contentTypeList().size() != target_type.numberOfRows() * target_type.numberOfColumns()) { - is_castable = false; - break; - } - for (auto list_arg : arg_type.contentTypeList()) { - is_castable &= isNaturalConversion(*list_arg, ASTNodeDataType::build<ASTNodeDataType::double_t>()); - } - break; - } - default: { - is_castable &= false; - } - } + return (arg_type == ASTNodeDataType::int_t); } else { is_castable &= isNaturalConversion(arg_type, ASTNodeDataType::build<ASTNodeDataType::double_t>()); } diff --git a/src/language/utils/PugsFunctionAdapter.hpp b/src/language/utils/PugsFunctionAdapter.hpp index d39e0f4233df70709d3d765146447727f7541ae4..de5e884bf63bc0ac3726864c4c4571c0a0fb9f55 100644 --- a/src/language/utils/PugsFunctionAdapter.hpp +++ b/src/language/utils/PugsFunctionAdapter.hpp @@ -154,28 +154,6 @@ class PugsFunctionAdapter<OutputType(InputType...)> { if constexpr (is_tiny_vector_v<OutputType>) { switch (data_type) { - case ASTNodeDataType::list_t: { - return [](DataVariant&& result) -> OutputType { - AggregateDataVariant& v = std::get<AggregateDataVariant>(result); - OutputType x; - - for (size_t i = 0; i < x.dimension(); ++i) { - std::visit( - [&](auto&& vi) { - using Vi_T = std::decay_t<decltype(vi)>; - if constexpr (std::is_arithmetic_v<Vi_T>) { - x[i] = vi; - } else { - // LCOV_EXCL_START - throw UnexpectedError("expecting arithmetic value"); - // LCOV_EXCL_STOP - } - }, - v[i]); - } - return x; - }; - } case ASTNodeDataType::vector_t: { return [](DataVariant&& result) -> OutputType { return std::get<OutputType>(result); }; } @@ -231,30 +209,6 @@ class PugsFunctionAdapter<OutputType(InputType...)> } } else if constexpr (is_tiny_matrix_v<OutputType>) { switch (data_type) { - case ASTNodeDataType::list_t: { - return [](DataVariant&& result) -> OutputType { - AggregateDataVariant& v = std::get<AggregateDataVariant>(result); - OutputType x; - - for (size_t i = 0, l = 0; i < x.numberOfRows(); ++i) { - for (size_t j = 0; j < x.numberOfColumns(); ++j, ++l) { - std::visit( - [&](auto&& Aij) { - using Aij_T = std::decay_t<decltype(Aij)>; - if constexpr (std::is_arithmetic_v<Aij_T>) { - x(i, j) = Aij; - } else { - // LCOV_EXCL_START - throw UnexpectedError("expecting arithmetic value"); - // LCOV_EXCL_STOP - } - }, - v[l]); - } - } - return x; - }; - } case ASTNodeDataType::matrix_t: { return [](DataVariant&& result) -> OutputType { return std::get<OutputType>(result); }; } diff --git a/tests/test_ASTBuilder.cpp b/tests/test_ASTBuilder.cpp index 262a0cd30b60cee5da070fe6fa8d62d8981e7b1d..2a9bcf4e41c039ac87dd6d3535a47710fb1a86e7 100644 --- a/tests/test_ASTBuilder.cpp +++ b/tests/test_ASTBuilder.cpp @@ -636,10 +636,10 @@ let y:(R^2), y=((0)); | | `-(language::integer:2) | +-(language::name:x) | `-(language::expression_list) - | +-(language::tuple_expression) + | +-(language::inner_expression_list) | | +-(language::integer:0) | | `-(language::integer:0) - | `-(language::tuple_expression) + | `-(language::inner_expression_list) | +-(language::integer:2) | `-(language::integer:3) `-(language::var_declaration) diff --git a/tests/test_ASTNodeAffectationExpressionBuilder.cpp b/tests/test_ASTNodeAffectationExpressionBuilder.cpp index 81ff4f95cffb91fe3352ff5560043d75a309e700..edd68ca67131579b980faa728959f854dea2dcf4 100644 --- a/tests/test_ASTNodeAffectationExpressionBuilder.cpp +++ b/tests/test_ASTNodeAffectationExpressionBuilder.cpp @@ -486,17 +486,17 @@ let y : R^2, y = x; CHECK_AST(data, result); } - SECTION("R^2 <- (.,.)") + SECTION("R^2 <- value") { std::string_view data = R"( -let y : R^2, y = (0,1); +let y : R^2, y = [0,1]; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - `-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + `-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) +-(language::name:y:NameProcessor) - `-(language::expression_list:ASTNodeExpressionListProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) +-(language::integer:0:ValueProcessor) `-(language::integer:1:ValueProcessor) )"; @@ -553,17 +553,17 @@ let x : R^3, x = 0; CHECK_AST(data, result); } - SECTION("R^3 <- (.,.)") + SECTION("R^3 <- value") { std::string_view data = R"( -let y : R^3, y = (1,2,3); +let y : R^3, y = [1,2,3]; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - `-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + `-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) +-(language::name:y:NameProcessor) - `-(language::expression_list:ASTNodeExpressionListProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) +-(language::integer:1:ValueProcessor) +-(language::integer:2:ValueProcessor) `-(language::integer:3:ValueProcessor) @@ -767,24 +767,24 @@ let t : (R), t = (2, 3.1, 5); SECTION("R^d tuples") { std::string_view data = R"( -let a : R^2, a = (2,3.1); -let t1 : (R^2), t1 = (a, (1,2), 0); +let a : R^2, a = [2,3.1]; +let t1 : (R^2), t1 = (a, [1,2], 0); let t2 : (R^3), t2 = (0, 0); let t3 : (R^1), t3 = (1, 2.3, 0); )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:a:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::integer:2:ValueProcessor) | `-(language::real:3.1:ValueProcessor) +-(language::eq_op:AffectationToTupleFromListProcessor<TinyVector<2ul, double> >) | +-(language::name:t1:NameProcessor) | `-(language::expression_list:ASTNodeExpressionListProcessor) | +-(language::name:a:NameProcessor) - | +-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + | +-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | | +-(language::integer:1:ValueProcessor) | | `-(language::integer:2:ValueProcessor) | `-(language::integer:0:ValueProcessor) @@ -800,7 +800,6 @@ let t3 : (R^1), t3 = (1, 2.3, 0); +-(language::real:2.3:ValueProcessor) `-(language::integer:0:ValueProcessor) )"; - CHECK_AST(data, result); } @@ -916,7 +915,7 @@ let t : (R), t = 3.1; SECTION("R^d tuples") { std::string_view data = R"( -let a : R^2, a = (2,3.1); +let a : R^2, a = [2,3.1]; let t1 : (R^2), t1 = a; let t2 : (R^3), t2 = 0; let t3 : (R^1), t3 = 2.3; @@ -924,9 +923,9 @@ let t3 : (R^1), t3 = 2.3; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:a:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::integer:2:ValueProcessor) | `-(language::real:3.1:ValueProcessor) +-(language::eq_op:AffectationToTupleProcessor<TinyVector<2ul, double> >) diff --git a/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp b/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp index 175093d61f214c4bf0d793a5ccf4fea26126f1d4..ee402307f95b0323bd726b0e093a1bb9af6e8f99 100644 --- a/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp +++ b/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp @@ -169,15 +169,15 @@ let x : R^1, x = 3.7; SECTION("R^2") { std::string_view data = R"( -let x : R^2, x = (3.2,6); +let x : R^2, x = [3.2,6]; 2*x; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::real:3.2:ValueProcessor) | `-(language::integer:6:ValueProcessor) `-(language::multiply_op:BinaryExpressionProcessor<language::multiply_op, TinyVector<2ul, double>, long, TinyVector<2ul, double> >) @@ -191,15 +191,15 @@ let x : R^2, x = (3.2,6); SECTION("R^3") { std::string_view data = R"( -let x : R^3, x = (3.2,6,1.2); +let x : R^3, x = [3.2,6,1.2]; 2*x; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::real:3.2:ValueProcessor) | +-(language::integer:6:ValueProcessor) | `-(language::real:1.2:ValueProcessor) @@ -381,7 +381,7 @@ a+3+a; CHECK_AST(data, result); } - SECTION("R^1") + SECTION("R^1 with variables") { std::string_view data = R"( let x : R^1, x = 1; @@ -405,24 +405,42 @@ x+y; CHECK_AST(data, result); } - SECTION("R^2") + SECTION("R^1 raw") + { + std::string_view data = R"( +[1]+[2]; +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + `-(language::plus_op:BinaryExpressionProcessor<language::plus_op, TinyVector<1ul, double>, TinyVector<1ul, double>, TinyVector<1ul, double> >) + +-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + | `-(language::integer:1:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + `-(language::integer:2:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("R^2 with variables") { std::string_view data = R"( -let x : R^2, x = (1,2); -let y : R^2, y = (0.3,0.7); +let x : R^2, x = [1,2]; +let y : R^2, y = [0.3,0.7]; x+y; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::integer:1:ValueProcessor) | `-(language::integer:2:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:y:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::real:0.3:ValueProcessor) | `-(language::real:0.7:ValueProcessor) `-(language::plus_op:BinaryExpressionProcessor<language::plus_op, TinyVector<2ul, double>, TinyVector<2ul, double>, TinyVector<2ul, double> >) @@ -433,25 +451,45 @@ x+y; CHECK_AST(data, result); } - SECTION("R^3") + SECTION("R^2 raw") + { + std::string_view data = R"( +[1,2]+[0.3,0.7]; +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + `-(language::plus_op:BinaryExpressionProcessor<language::plus_op, TinyVector<2ul, double>, TinyVector<2ul, double>, TinyVector<2ul, double> >) + +-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + +-(language::real:0.3:ValueProcessor) + `-(language::real:0.7:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("R^3 with variables") { std::string_view data = R"( -let x : R^3, x = (1,2,3); -let y : R^3, y = (4,3,2); +let x : R^3, x = [1,2,3]; +let y : R^3, y = [4,3,2]; x+y; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) | +-(language::name:y:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:4:ValueProcessor) | +-(language::integer:3:ValueProcessor) | `-(language::integer:2:ValueProcessor) @@ -463,6 +501,28 @@ x+y; CHECK_AST(data, result); } + SECTION("R^3 raw") + { + std::string_view data = R"( +[1,2,3]+[4,3,2]; +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + `-(language::plus_op:BinaryExpressionProcessor<language::plus_op, TinyVector<3ul, double>, TinyVector<3ul, double>, TinyVector<3ul, double> >) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + +-(language::integer:4:ValueProcessor) + +-(language::integer:3:ValueProcessor) + `-(language::integer:2:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + SECTION("string concatenate bool") { std::string_view data = R"( @@ -659,24 +719,42 @@ x-y; CHECK_AST(data, result); } - SECTION("R^2") + SECTION("R^1 raw") { std::string_view data = R"( -let x : R^2, x = (1,2); -let y : R^2, y = (0.3,0.7); +[1]-[2]; +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + `-(language::minus_op:BinaryExpressionProcessor<language::minus_op, TinyVector<1ul, double>, TinyVector<1ul, double>, TinyVector<1ul, double> >) + +-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + | `-(language::integer:1:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + `-(language::integer:2:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("R^2 with variables") + { + std::string_view data = R"( +let x : R^2, x = [1,2]; +let y : R^2, y = [0.3,0.7]; x-y; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::integer:1:ValueProcessor) | `-(language::integer:2:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:y:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::real:0.3:ValueProcessor) | `-(language::real:0.7:ValueProcessor) `-(language::minus_op:BinaryExpressionProcessor<language::minus_op, TinyVector<2ul, double>, TinyVector<2ul, double>, TinyVector<2ul, double> >) @@ -687,25 +765,45 @@ x-y; CHECK_AST(data, result); } - SECTION("R^3") + SECTION("R^2 raw") { std::string_view data = R"( -let x : R^3, x = (1,2,3); -let y : R^3, y = (4,3,2); +[1,2]-[0.3,0.7]; +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + `-(language::minus_op:BinaryExpressionProcessor<language::minus_op, TinyVector<2ul, double>, TinyVector<2ul, double>, TinyVector<2ul, double> >) + +-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + +-(language::real:0.3:ValueProcessor) + `-(language::real:0.7:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("R^3 with variables") + { + std::string_view data = R"( +let x : R^3, x = [1,2,3]; +let y : R^3, y = [4,3,2]; x-y; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) | +-(language::name:y:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:4:ValueProcessor) | +-(language::integer:3:ValueProcessor) | `-(language::integer:2:ValueProcessor) @@ -716,6 +814,28 @@ x-y; CHECK_AST(data, result); } + + SECTION("R^3 raw") + { + std::string_view data = R"( +[1,2,3]-[4,3,2]; +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + `-(language::minus_op:BinaryExpressionProcessor<language::minus_op, TinyVector<3ul, double>, TinyVector<3ul, double>, TinyVector<3ul, double> >) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + +-(language::integer:4:ValueProcessor) + +-(language::integer:3:ValueProcessor) + `-(language::integer:2:ValueProcessor) +)"; + + CHECK_AST(data, result); + } } SECTION("or") @@ -1172,8 +1292,7 @@ a == 3; { std::string_view data = R"( let x : R^1, x = 1; -let y : R^1, y = 2; -x==y; +x==[2]; )"; std::string_view result = R"( @@ -1181,12 +1300,10 @@ x==y; +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<1ul, double>, long>) | +-(language::name:x:NameProcessor) | `-(language::integer:1:ValueProcessor) - +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<1ul, double>, long>) - | +-(language::name:y:NameProcessor) - | `-(language::integer:2:ValueProcessor) `-(language::eqeq_op:BinaryExpressionProcessor<language::eqeq_op, bool, TinyVector<1ul, double>, TinyVector<1ul, double> >) +-(language::name:x:NameProcessor) - `-(language::name:y:NameProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + `-(language::integer:2:ValueProcessor) )"; CHECK_AST(data, result); @@ -1195,26 +1312,22 @@ x==y; SECTION("R^2") { std::string_view data = R"( -let x : R^2, x = (1,2); -let y : R^2, y = (0.3,0.7); -x==y; +let x : R^2, x = [1,2]; +x==[0.3,0.7]; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::integer:1:ValueProcessor) | `-(language::integer:2:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) - | +-(language::name:y:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) - | +-(language::real:0.3:ValueProcessor) - | `-(language::real:0.7:ValueProcessor) `-(language::eqeq_op:BinaryExpressionProcessor<language::eqeq_op, bool, TinyVector<2ul, double>, TinyVector<2ul, double> >) +-(language::name:x:NameProcessor) - `-(language::name:y:NameProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + +-(language::real:0.3:ValueProcessor) + `-(language::real:0.7:ValueProcessor) )"; CHECK_AST(data, result); @@ -1223,28 +1336,24 @@ x==y; SECTION("R^3") { std::string_view data = R"( -let x : R^3, x = (1,2,3); -let y : R^3, y = (4,3,2); -x==y; +let x : R^3, x = [1,2,3]; +x==[4,3,2]; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) - | +-(language::name:y:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) - | +-(language::integer:4:ValueProcessor) - | +-(language::integer:3:ValueProcessor) - | `-(language::integer:2:ValueProcessor) `-(language::eqeq_op:BinaryExpressionProcessor<language::eqeq_op, bool, TinyVector<3ul, double>, TinyVector<3ul, double> >) +-(language::name:x:NameProcessor) - `-(language::name:y:NameProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + +-(language::integer:4:ValueProcessor) + +-(language::integer:3:ValueProcessor) + `-(language::integer:2:ValueProcessor) )"; CHECK_AST(data, result); @@ -1325,8 +1434,7 @@ a != 3; { std::string_view data = R"( let x : R^1, x = 1; -let y : R^1, y = 2; -x!=y; +x!=[2]; )"; std::string_view result = R"( @@ -1334,12 +1442,10 @@ x!=y; +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<1ul, double>, long>) | +-(language::name:x:NameProcessor) | `-(language::integer:1:ValueProcessor) - +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<1ul, double>, long>) - | +-(language::name:y:NameProcessor) - | `-(language::integer:2:ValueProcessor) `-(language::not_eq_op:BinaryExpressionProcessor<language::not_eq_op, bool, TinyVector<1ul, double>, TinyVector<1ul, double> >) +-(language::name:x:NameProcessor) - `-(language::name:y:NameProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + `-(language::integer:2:ValueProcessor) )"; CHECK_AST(data, result); @@ -1348,26 +1454,22 @@ x!=y; SECTION("R^2") { std::string_view data = R"( -let x : R^2, x = (1,2); -let y : R^2, y = (0.3,0.7); -x!=y; +let x : R^2, x = [1,2]; +x!=[0.3,0.7]; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::integer:1:ValueProcessor) | `-(language::integer:2:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) - | +-(language::name:y:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) - | +-(language::real:0.3:ValueProcessor) - | `-(language::real:0.7:ValueProcessor) `-(language::not_eq_op:BinaryExpressionProcessor<language::not_eq_op, bool, TinyVector<2ul, double>, TinyVector<2ul, double> >) +-(language::name:x:NameProcessor) - `-(language::name:y:NameProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + +-(language::real:0.3:ValueProcessor) + `-(language::real:0.7:ValueProcessor) )"; CHECK_AST(data, result); @@ -1376,28 +1478,24 @@ x!=y; SECTION("R^3") { std::string_view data = R"( -let x : R^3, x = (1,2,3); -let y : R^3, y = (4,3,2); -x!=y; +let x : R^3, x = [1,2,3]; +x!=[4,3,2]; )"; std::string_view result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) - | +-(language::name:y:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) - | +-(language::integer:4:ValueProcessor) - | +-(language::integer:3:ValueProcessor) - | `-(language::integer:2:ValueProcessor) `-(language::not_eq_op:BinaryExpressionProcessor<language::not_eq_op, bool, TinyVector<3ul, double>, TinyVector<3ul, double> >) +-(language::name:x:NameProcessor) - `-(language::name:y:NameProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + +-(language::integer:4:ValueProcessor) + +-(language::integer:3:ValueProcessor) + `-(language::integer:2:ValueProcessor) )"; CHECK_AST(data, result); diff --git a/tests/test_ASTNodeBuiltinFunctionExpressionBuilder.cpp b/tests/test_ASTNodeBuiltinFunctionExpressionBuilder.cpp index 7fb68cd69c16331c07db8354a40dcb029fcb5c14..05b64ce5127758d9772e297c5d8a2c62bb62119c 100644 --- a/tests/test_ASTNodeBuiltinFunctionExpressionBuilder.cpp +++ b/tests/test_ASTNodeBuiltinFunctionExpressionBuilder.cpp @@ -474,10 +474,10 @@ R2toR(0); CHECK_AST(data, result); } - SECTION("from R^2") + SECTION("from R^2 variable") { std::string_view data = R"( -let x:R^2, x = (1,2); +let x:R^2, x = [1,2]; R2toR(x); )"; @@ -491,17 +491,17 @@ R2toR(x); CHECK_AST(data, result); } - SECTION("from list") + SECTION("from R^2 value") { std::string_view data = R"( -R2toR((1,2)); +R2toR([1,2]); )"; std::string_view result = R"( (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:R2toR:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) +-(language::integer:1:ValueProcessor) `-(language::integer:2:ValueProcessor) )"; @@ -528,10 +528,10 @@ R22toR(0); CHECK_AST(data, result); } - SECTION("from R^2x2") + SECTION("from R^2x2 variable") { std::string_view data = R"( -let x:R^2x2, x = (1,2,3,4); +let x:R^2x2, x = [[1,2],[3,4]]; R22toR(x); )"; @@ -545,21 +545,23 @@ R22toR(x); CHECK_AST(data, result); } - SECTION("from list") + SECTION("from R^2x2 value") { std::string_view data = R"( -R22toR((1,2,3,4)); +R22toR([[1,2],[3,4]]); )"; std::string_view result = R"( (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:R22toR:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) - +-(language::integer:1:ValueProcessor) - +-(language::integer:2:ValueProcessor) - +-(language::integer:3:ValueProcessor) - `-(language::integer:4:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::row_expression:FakeProcessor) + +-(language::integer:3:ValueProcessor) + `-(language::integer:4:ValueProcessor) )"; CHECK_AST(data, result); @@ -584,10 +586,10 @@ R3toR(0); CHECK_AST(data, result); } - SECTION("from R^3") + SECTION("from R^3 variable") { std::string_view data = R"( -let x:R^3, x = (1,2,4); +let x:R^3, x = [1,2,4]; R3toR(x); )"; @@ -601,17 +603,17 @@ R3toR(x); CHECK_AST(data, result); } - SECTION("from list") + SECTION("from R^3 value") { std::string_view data = R"( -R3toR((1,2,3)); +R3toR([1,2,3]); )"; std::string_view result = R"( (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:R3toR:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) +-(language::integer:1:ValueProcessor) +-(language::integer:2:ValueProcessor) `-(language::integer:3:ValueProcessor) @@ -639,10 +641,10 @@ R33toR(0); CHECK_AST(data, result); } - SECTION("from R^3x3") + SECTION("from R^3x3 variable") { std::string_view data = R"( -let x:R^3x3, x = (1,2,3,4,5,6,7,8,9); +let x:R^3x3, x = [[1,2,3],[4,5,6],[7,8,9]]; R33toR(x); )"; @@ -656,26 +658,29 @@ R33toR(x); CHECK_AST(data, result); } - SECTION("from list") + SECTION("from R^3x3 value") { std::string_view data = R"( -R33toR((1,2,3,4,5,6,7,8,9)); +R33toR([[1,2,3],[4,5,6],[7,8,9]]); )"; std::string_view result = R"( (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:R33toR:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) - +-(language::integer:1:ValueProcessor) - +-(language::integer:2:ValueProcessor) - +-(language::integer:3:ValueProcessor) - +-(language::integer:4:ValueProcessor) - +-(language::integer:5:ValueProcessor) - +-(language::integer:6:ValueProcessor) - +-(language::integer:7:ValueProcessor) - +-(language::integer:8:ValueProcessor) - `-(language::integer:9:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:4:ValueProcessor) + | +-(language::integer:5:ValueProcessor) + | `-(language::integer:6:ValueProcessor) + `-(language::row_expression:FakeProcessor) + +-(language::integer:7:ValueProcessor) + +-(language::integer:8:ValueProcessor) + `-(language::integer:9:ValueProcessor) )"; CHECK_AST(data, result); @@ -828,8 +833,8 @@ RRtoB(1., 0.); SECTION("from R^3*R^2") { std::string_view data = R"( -let x : R^3, x = (1,2,3); -let y : R^2, y = (2,3); +let x : R^3, x = [1,2,3]; +let y : R^2, y = [2,3]; R3R2toR(x,y); )"; @@ -845,10 +850,10 @@ R3R2toR(x,y); CHECK_AST(data, result); } - SECTION("from (R,R,R)*(R,R)") + SECTION("from R^3*R^2 value") { std::string_view data = R"( -R3R2toR((1,2,3),(3,4)); +R3R2toR([1,2,3],[3,4]); )"; std::string_view result = R"( @@ -856,11 +861,11 @@ R3R2toR((1,2,3),(3,4)); `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:R3R2toR:FakeProcessor) `-(language::function_argument_list:ASTNodeExpressionListProcessor) - +-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) +-(language::integer:3:ValueProcessor) `-(language::integer:4:ValueProcessor) )"; @@ -868,10 +873,10 @@ R3R2toR((1,2,3),(3,4)); CHECK_AST(data, result); } - SECTION("from (R,R,R)*(0)") + SECTION("from R^3*'0'") { std::string_view data = R"( -R3R2toR((1,2,3),0); +R3R2toR([1,2,3],0); )"; std::string_view result = R"( @@ -879,7 +884,7 @@ R3R2toR((1,2,3),0); `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:R3R2toR:FakeProcessor) `-(language::function_argument_list:ASTNodeExpressionListProcessor) - +-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) @@ -895,8 +900,8 @@ R3R2toR((1,2,3),0); SECTION("from R^3x3*R^2x2") { std::string_view data = R"( -let x : R^3x3, x = (1,2,3,4,5,6,7,8,9); -let y : R^2x2, y = (1,2,3,4); +let x : R^3x3, x = [[1,2,3],[4,5,6],[7,8,9]]; +let y : R^2x2, y = [[1,2],[3,4]]; R33R22toR(x,y); )"; @@ -912,10 +917,10 @@ R33R22toR(x,y); CHECK_AST(data, result); } - SECTION("from (R,R,R,R,R,R,R,R,R)*(R,R,R,R)") + SECTION("from R^3x3*R^2x2 value") { std::string_view data = R"( -R33R22toR((1,2,3,4,5,6,7,8,9),(1,2,3,4)); +R33R22toR([[1,2,3],[4,5,6],[7,8,9]],[[1,2],[3,4]]); )"; std::string_view result = R"( @@ -923,30 +928,35 @@ R33R22toR((1,2,3,4,5,6,7,8,9),(1,2,3,4)); `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:R33R22toR:FakeProcessor) `-(language::function_argument_list:ASTNodeExpressionListProcessor) - +-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) - | +-(language::integer:1:ValueProcessor) - | +-(language::integer:2:ValueProcessor) - | +-(language::integer:3:ValueProcessor) - | +-(language::integer:4:ValueProcessor) - | +-(language::integer:5:ValueProcessor) - | +-(language::integer:6:ValueProcessor) - | +-(language::integer:7:ValueProcessor) - | +-(language::integer:8:ValueProcessor) - | `-(language::integer:9:ValueProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) - +-(language::integer:1:ValueProcessor) - +-(language::integer:2:ValueProcessor) - +-(language::integer:3:ValueProcessor) - `-(language::integer:4:ValueProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:1:ValueProcessor) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::integer:3:ValueProcessor) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:4:ValueProcessor) + | | +-(language::integer:5:ValueProcessor) + | | `-(language::integer:6:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::integer:7:ValueProcessor) + | +-(language::integer:8:ValueProcessor) + | `-(language::integer:9:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::row_expression:FakeProcessor) + +-(language::integer:3:ValueProcessor) + `-(language::integer:4:ValueProcessor) )"; CHECK_AST(data, result); } - SECTION("from (R,R,R,R,R,R,R,R,R)*(0)") + SECTION("from R^3x3*'0'") { std::string_view data = R"( -R33R22toR((1,2,3,4,5,6,7,8,9),0); +R33R22toR([[1,2,3],[4,5,6],[7,8,9]],0); )"; std::string_view result = R"( @@ -954,16 +964,19 @@ R33R22toR((1,2,3,4,5,6,7,8,9),0); `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:R33R22toR:FakeProcessor) `-(language::function_argument_list:ASTNodeExpressionListProcessor) - +-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) - | +-(language::integer:1:ValueProcessor) - | +-(language::integer:2:ValueProcessor) - | +-(language::integer:3:ValueProcessor) - | +-(language::integer:4:ValueProcessor) - | +-(language::integer:5:ValueProcessor) - | +-(language::integer:6:ValueProcessor) - | +-(language::integer:7:ValueProcessor) - | +-(language::integer:8:ValueProcessor) - | `-(language::integer:9:ValueProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:1:ValueProcessor) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::integer:3:ValueProcessor) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:4:ValueProcessor) + | | +-(language::integer:5:ValueProcessor) + | | `-(language::integer:6:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::integer:7:ValueProcessor) + | +-(language::integer:8:ValueProcessor) + | `-(language::integer:9:ValueProcessor) `-(language::integer:0:ValueProcessor) )"; @@ -1216,7 +1229,7 @@ tuple_RtoB((1.2, 2, true, n)); (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:tuple_RtoB:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::inner_expression_list:InnerListToVectorProcessor) +-(language::real:1.2:ValueProcessor) +-(language::integer:2:ValueProcessor) +-(language::true_kw:ValueProcessor) @@ -1319,7 +1332,7 @@ tuple_stringtoB(("foo",2,"bar")); (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:tuple_stringtoB:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::inner_expression_list:InnerListToVectorProcessor) +-(language::literal:"foo":ValueProcessor) +-(language::integer:2:ValueProcessor) `-(language::literal:"bar":ValueProcessor) @@ -1354,7 +1367,7 @@ tuple_builtinToB((a,b,a)); (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:tuple_builtinToB:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::inner_expression_list:InnerListToVectorProcessor) +-(language::name:a:NameProcessor) +-(language::name:b:NameProcessor) `-(language::name:a:NameProcessor) @@ -1514,7 +1527,7 @@ tuple_R2ToR(r); SECTION("compound_list -> tuple(R^2)") { std::string_view data = R"( -let r:R^2, r = (1,2); +let r:R^2, r = [1,2]; tuple_R2ToR((r,r)); )"; @@ -1522,7 +1535,7 @@ tuple_R2ToR((r,r)); (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:tuple_R2ToR:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::inner_expression_list:InnerListToVectorProcessor) +-(language::name:r:NameProcessor) `-(language::name:r:NameProcessor) )"; @@ -1549,7 +1562,7 @@ tuple_R22ToR(0); SECTION("R^2x2 -> tuple(R^2x2)") { std::string_view data = R"( -let r:R^2x2, r = (1,2,3,4); +let r:R^2x2, r = [[1,2],[3,4]]; tuple_R22ToR(r); )"; @@ -1566,7 +1579,7 @@ tuple_R22ToR(r); SECTION("compound_list -> tuple(R^2x2)") { std::string_view data = R"( -let r:R^2x2, r = (1,2,3,4); +let r:R^2x2, r = [[1,2],[3,4]]; tuple_R22ToR((r,r)); )"; @@ -1574,7 +1587,7 @@ tuple_R22ToR((r,r)); (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:tuple_R22ToR:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::inner_expression_list:InnerListToVectorProcessor) +-(language::name:r:NameProcessor) `-(language::name:r:NameProcessor) )"; @@ -1601,7 +1614,7 @@ tuple_R3ToR(0); SECTION("R^3 -> tuple(R^3)") { std::string_view data = R"( -let r:R^3, r = (1,2,3); +let r:R^3, r = [1,2,3]; tuple_R3ToR(r); )"; @@ -1634,7 +1647,7 @@ tuple_R33ToR(0); SECTION("R^3x3 -> tuple(R^3x3)") { std::string_view data = R"( -let r:R^3x3, r = (1,2,3,4,5,6,7,8,9); +let r:R^3x3, r = [[1,2,3],[4,5,6],[7,8,9]]; tuple_R33ToR(r); )"; @@ -1676,7 +1689,7 @@ fidTupleToR((f,f)); (root:ASTNodeListProcessor) `-(language::function_evaluation:BuiltinFunctionProcessor) +-(language::name:fidTupleToR:FakeProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::inner_expression_list:InnerListToVectorProcessor) +-(language::name:f:NameProcessor) `-(language::name:f:NameProcessor) )"; diff --git a/tests/test_ASTNodeDataType.cpp b/tests/test_ASTNodeDataType.cpp index 023ec9963bcd66286c9ffcfcadbc4fb3b2abdbee..29ee313082bd7908699c1227d0486aa31538300f 100644 --- a/tests/test_ASTNodeDataType.cpp +++ b/tests/test_ASTNodeDataType.cpp @@ -182,6 +182,68 @@ TEST_CASE("ASTNodeDataType", "[language]") } } + SECTION("getVectorExpressionType") + { + std::unique_ptr vector_expression_node = std::make_unique<ASTNode>(); + vector_expression_node->set_type<language::vector_expression>(); + vector_expression_node->emplace_back(std::make_unique<ASTNode>()); + + SECTION("good nodes") + { + vector_expression_node->children.resize(1); + for (size_t i = 0; i < vector_expression_node->children.size(); ++i) { + vector_expression_node->children[i] = std::make_unique<ASTNode>(); + vector_expression_node->children[i]->m_data_type = ASTNodeDataType::build<ASTNodeDataType::bool_t>(); + } + REQUIRE(getVectorExpressionType(*vector_expression_node) == ASTNodeDataType::build<ASTNodeDataType::vector_t>(1)); + REQUIRE(getVectorExpressionType(*vector_expression_node).dimension() == 1); + + vector_expression_node->children.resize(2); + for (size_t i = 0; i < vector_expression_node->children.size(); ++i) { + vector_expression_node->children[i] = std::make_unique<ASTNode>(); + vector_expression_node->children[i]->m_data_type = ASTNodeDataType::build<ASTNodeDataType::double_t>(); + } + REQUIRE(getVectorExpressionType(*vector_expression_node) == ASTNodeDataType::build<ASTNodeDataType::vector_t>(2)); + REQUIRE(getVectorExpressionType(*vector_expression_node).dimension() == 2); + + vector_expression_node->children.resize(3); + for (size_t i = 0; i < vector_expression_node->children.size(); ++i) { + vector_expression_node->children[i] = std::make_unique<ASTNode>(); + vector_expression_node->children[i]->m_data_type = ASTNodeDataType::build<ASTNodeDataType::unsigned_int_t>(); + } + REQUIRE(getVectorExpressionType(*vector_expression_node) == ASTNodeDataType::build<ASTNodeDataType::vector_t>(3)); + REQUIRE(getVectorExpressionType(*vector_expression_node).dimension() == 3); + } + + SECTION("bad content type") + { + vector_expression_node->children.resize(3); + for (size_t i = 0; i < vector_expression_node->children.size(); ++i) { + vector_expression_node->children[i] = std::make_unique<ASTNode>(); + } + REQUIRE_THROWS_WITH(getVectorExpressionType(*vector_expression_node), + "unexpected error: invalid implicit conversion: undefined -> R"); + } + + SECTION("bad node type") + { + vector_expression_node->set_type<language::real>(); + REQUIRE_THROWS_WITH(getVectorExpressionType(*vector_expression_node), "unexpected node type"); + } + + SECTION("bad children size 2") + { + vector_expression_node->children.resize(4); + REQUIRE_THROWS_WITH(getVectorExpressionType(*vector_expression_node), "invalid dimension (must be 1, 2 or 3)"); + } + + SECTION("bad children size 2") + { + vector_expression_node->children.clear(); + REQUIRE_THROWS_WITH(getVectorExpressionType(*vector_expression_node), "unexpected node type"); + } + } + SECTION("getMatrixDataType") { std::unique_ptr type_node = std::make_unique<ASTNode>(); @@ -229,7 +291,7 @@ TEST_CASE("ASTNodeDataType", "[language]") REQUIRE_THROWS_WITH(getMatrixDataType(*type_node), "unexpected node type"); } - SECTION("bad children size 1") + SECTION("bad children size 2") { type_node->children.emplace_back(std::unique_ptr<ASTNode>()); REQUIRE_THROWS_WITH(getMatrixDataType(*type_node), "unexpected node type"); @@ -298,6 +360,137 @@ TEST_CASE("ASTNodeDataType", "[language]") } } + SECTION("getMatrixExpressionType") + { + std::unique_ptr matrix_expression_node = std::make_unique<ASTNode>(); + matrix_expression_node->set_type<language::matrix_expression>(); + matrix_expression_node->emplace_back(std::make_unique<ASTNode>()); + + SECTION("good nodes") + { + { + const size_t dimension = 1; + matrix_expression_node->children.clear(); + for (size_t i = 0; i < dimension; ++i) { + matrix_expression_node->children.emplace_back(std::make_unique<ASTNode>()); + matrix_expression_node->children[i]->set_type<language::row_expression>(); + for (size_t j = 0; j < dimension; ++j) { + matrix_expression_node->children[i]->children.emplace_back(std::make_unique<ASTNode>()); + matrix_expression_node->children[i]->children[j]->m_data_type = + ASTNodeDataType::build<ASTNodeDataType::int_t>(); + } + } + REQUIRE(getMatrixExpressionType(*matrix_expression_node) == + ASTNodeDataType::build<ASTNodeDataType::matrix_t>(dimension, dimension)); + REQUIRE(getMatrixExpressionType(*matrix_expression_node).numberOfRows() == dimension); + REQUIRE(getMatrixExpressionType(*matrix_expression_node).numberOfColumns() == dimension); + } + + { + const size_t dimension = 2; + matrix_expression_node->children.clear(); + for (size_t i = 0; i < dimension; ++i) { + matrix_expression_node->children.emplace_back(std::make_unique<ASTNode>()); + matrix_expression_node->children[i]->set_type<language::row_expression>(); + for (size_t j = 0; j < dimension; ++j) { + matrix_expression_node->children[i]->children.emplace_back(std::make_unique<ASTNode>()); + matrix_expression_node->children[i]->children[j]->m_data_type = + ASTNodeDataType::build<ASTNodeDataType::int_t>(); + } + } + REQUIRE(getMatrixExpressionType(*matrix_expression_node) == + ASTNodeDataType::build<ASTNodeDataType::matrix_t>(dimension, dimension)); + REQUIRE(getMatrixExpressionType(*matrix_expression_node).numberOfRows() == dimension); + REQUIRE(getMatrixExpressionType(*matrix_expression_node).numberOfColumns() == dimension); + } + + { + const size_t dimension = 3; + matrix_expression_node->children.clear(); + for (size_t i = 0; i < dimension; ++i) { + matrix_expression_node->children.emplace_back(std::make_unique<ASTNode>()); + matrix_expression_node->children[i]->set_type<language::row_expression>(); + for (size_t j = 0; j < dimension; ++j) { + matrix_expression_node->children[i]->children.emplace_back(std::make_unique<ASTNode>()); + matrix_expression_node->children[i]->children[j]->m_data_type = + ASTNodeDataType::build<ASTNodeDataType::int_t>(); + } + } + REQUIRE(getMatrixExpressionType(*matrix_expression_node) == + ASTNodeDataType::build<ASTNodeDataType::matrix_t>(dimension, dimension)); + REQUIRE(getMatrixExpressionType(*matrix_expression_node).numberOfRows() == dimension); + REQUIRE(getMatrixExpressionType(*matrix_expression_node).numberOfColumns() == dimension); + } + } + + SECTION("bad content type") + { + const size_t dimension = 3; + matrix_expression_node->children.clear(); + for (size_t i = 0; i < dimension; ++i) { + matrix_expression_node->children.emplace_back(std::make_unique<ASTNode>()); + matrix_expression_node->children[i]->set_type<language::row_expression>(); + for (size_t j = 0; j < dimension; ++j) { + matrix_expression_node->children[i]->children.emplace_back(std::make_unique<ASTNode>()); + } + } + REQUIRE_THROWS_WITH(getMatrixExpressionType(*matrix_expression_node), + "unexpected error: invalid implicit conversion: undefined -> R"); + } + + SECTION("bad node type") + { + matrix_expression_node->set_type<language::real>(); + REQUIRE_THROWS_WITH(getMatrixExpressionType(*matrix_expression_node), "unexpected node type"); + } + + SECTION("bad content type") + { + const size_t dimension = 3; + matrix_expression_node->children.clear(); + for (size_t i = 0; i < dimension; ++i) { + matrix_expression_node->children.emplace_back(std::make_unique<ASTNode>()); + } + REQUIRE_THROWS_WITH(getMatrixExpressionType(*matrix_expression_node), "expecting row expression"); + } + + SECTION("bad children size 1") + { + matrix_expression_node->children.resize(4); + REQUIRE_THROWS_WITH(getMatrixExpressionType(*matrix_expression_node), "invalid dimension (must be 1, 2 or 3)"); + } + + SECTION("bad children size 2") + { + const size_t dimension = 2; + matrix_expression_node->children.clear(); + for (size_t i = 0; i < dimension; ++i) { + matrix_expression_node->children.emplace_back(std::make_unique<ASTNode>()); + matrix_expression_node->children[i]->set_type<language::row_expression>(); + for (size_t j = 0; j < dimension + 1; ++j) { + matrix_expression_node->children[i]->children.emplace_back(std::make_unique<ASTNode>()); + } + } + REQUIRE_THROWS_WITH(getMatrixExpressionType(*matrix_expression_node), "only square matrices are supported"); + } + + SECTION("bad children size 3") + { + const size_t dimension = 2; + matrix_expression_node->children.clear(); + for (size_t i = 0; i < dimension; ++i) { + matrix_expression_node->children.emplace_back(std::make_unique<ASTNode>()); + matrix_expression_node->children[i]->set_type<language::row_expression>(); + for (size_t j = 0; j < dimension; ++j) { + matrix_expression_node->children[i]->children.emplace_back(std::make_unique<ASTNode>()); + } + } + matrix_expression_node->children[1]->children.emplace_back(std::make_unique<ASTNode>()); + + REQUIRE_THROWS_WITH(getMatrixExpressionType(*matrix_expression_node), "row must have same sizes"); + } + } + SECTION("isNaturalConversion") { SECTION("-> B") diff --git a/tests/test_ASTNodeDataTypeBuilder.cpp b/tests/test_ASTNodeDataTypeBuilder.cpp index 5dcd6f57cb77dc3e91b8e2e084f98b9143a75f1c..9ec4f8dabbf448916ca491cc262be1edf5fa412c 100644 --- a/tests/test_ASTNodeDataTypeBuilder.cpp +++ b/tests/test_ASTNodeDataTypeBuilder.cpp @@ -520,9 +520,10 @@ let t : (R), t = (2, 3.1, 5); SECTION("R^d tuples") { std::string_view data = R"( -let a : R^2, a = (2,3.1); -let t1 : (R^2), t1 = (a, (1,2), 0); +let a : R^2, a = [2,3.1]; +let t1 : (R^2), t1 = (a, [1,2], 0); let t2 : (R^3), t2 = (0, 0); +let t3 : (R^2), t3 = ([1,2], a, 0); )"; std::string_view result = R"( @@ -533,7 +534,7 @@ let t2 : (R^3), t2 = (0, 0); | | +-(language::R_set:R) | | `-(language::integer:2:Z) | +-(language::name:a:R^2) - | `-(language::expression_list:Z*R) + | `-(language::vector_expression:R^2) | +-(language::integer:2:Z) | `-(language::real:3.1:R) +-(language::var_declaration:void) @@ -543,21 +544,34 @@ let t2 : (R^3), t2 = (0, 0); | | +-(language::R_set:R) | | `-(language::integer:2:Z) | +-(language::name:t1:(R^2...)) - | `-(language::expression_list:R^2*(Z*Z)*Z) + | `-(language::expression_list:R^2*R^2*Z) | +-(language::name:a:R^2) - | +-(language::tuple_expression:Z*Z) + | +-(language::vector_expression:R^2) | | +-(language::integer:1:Z) | | `-(language::integer:2:Z) | `-(language::integer:0:Z) + +-(language::var_declaration:void) + | +-(language::name:t2:(R^3...)) + | +-(language::tuple_type_specifier:(R^3...)) + | | `-(language::vector_type:R^3) + | | +-(language::R_set:R) + | | `-(language::integer:3:Z) + | +-(language::name:t2:(R^3...)) + | `-(language::expression_list:Z*Z) + | +-(language::integer:0:Z) + | `-(language::integer:0:Z) `-(language::var_declaration:void) - +-(language::name:t2:(R^3...)) - +-(language::tuple_type_specifier:(R^3...)) - | `-(language::vector_type:R^3) + +-(language::name:t3:(R^2...)) + +-(language::tuple_type_specifier:(R^2...)) + | `-(language::vector_type:R^2) | +-(language::R_set:R) - | `-(language::integer:3:Z) - +-(language::name:t2:(R^3...)) - `-(language::expression_list:Z*Z) - +-(language::integer:0:Z) + | `-(language::integer:2:Z) + +-(language::name:t3:(R^2...)) + `-(language::expression_list:R^2*R^2*Z) + +-(language::vector_expression:R^2) + | +-(language::integer:1:Z) + | `-(language::integer:2:Z) + +-(language::name:a:R^2) `-(language::integer:0:Z) )"; @@ -567,9 +581,10 @@ let t2 : (R^3), t2 = (0, 0); SECTION("R^dxd tuples") { std::string_view data = R"( -let a : R^2x2, a = (2, 3.1, -1.2, 4); -let t1 : (R^2x2), t1 = (a, (1,2,1,3), 0); +let a : R^2x2, a = [[2, 3.1], [-1.2, 4]]; +let t1 : (R^2x2), t1 = (a, [[1,2],[1,3]], 0); let t2 : (R^3x3), t2 = (0, 0); +let t3 : (R^2x2), t3 = ([[1,2],[1,3]], a, 0); )"; std::string_view result = R"( @@ -581,12 +596,14 @@ let t2 : (R^3x3), t2 = (0, 0); | | +-(language::integer:2:Z) | | `-(language::integer:2:Z) | +-(language::name:a:R^2x2) - | `-(language::expression_list:Z*R*R*Z) - | +-(language::integer:2:Z) - | +-(language::real:3.1:R) - | +-(language::unary_minus:R) - | | `-(language::real:1.2:R) - | `-(language::integer:4:Z) + | `-(language::matrix_expression:R^2x2) + | +-(language::row_expression:void) + | | +-(language::integer:2:Z) + | | `-(language::real:3.1:R) + | `-(language::row_expression:void) + | +-(language::unary_minus:R) + | | `-(language::real:1.2:R) + | `-(language::integer:4:Z) +-(language::var_declaration:void) | +-(language::name:t1:(R^2x2...)) | +-(language::tuple_type_specifier:(R^2x2...)) @@ -595,24 +612,44 @@ let t2 : (R^3x3), t2 = (0, 0); | | +-(language::integer:2:Z) | | `-(language::integer:2:Z) | +-(language::name:t1:(R^2x2...)) - | `-(language::expression_list:R^2x2*(Z*Z*Z*Z)*Z) + | `-(language::expression_list:R^2x2*R^2x2*Z) | +-(language::name:a:R^2x2) - | +-(language::tuple_expression:Z*Z*Z*Z) - | | +-(language::integer:1:Z) - | | +-(language::integer:2:Z) - | | +-(language::integer:1:Z) - | | `-(language::integer:3:Z) + | +-(language::matrix_expression:R^2x2) + | | +-(language::row_expression:void) + | | | +-(language::integer:1:Z) + | | | `-(language::integer:2:Z) + | | `-(language::row_expression:void) + | | +-(language::integer:1:Z) + | | `-(language::integer:3:Z) + | `-(language::integer:0:Z) + +-(language::var_declaration:void) + | +-(language::name:t2:(R^3x3...)) + | +-(language::tuple_type_specifier:(R^3x3...)) + | | `-(language::matrix_type:R^3x3) + | | +-(language::R_set:R) + | | +-(language::integer:3:Z) + | | `-(language::integer:3:Z) + | +-(language::name:t2:(R^3x3...)) + | `-(language::expression_list:Z*Z) + | +-(language::integer:0:Z) | `-(language::integer:0:Z) `-(language::var_declaration:void) - +-(language::name:t2:(R^3x3...)) - +-(language::tuple_type_specifier:(R^3x3...)) - | `-(language::matrix_type:R^3x3) + +-(language::name:t3:(R^2x2...)) + +-(language::tuple_type_specifier:(R^2x2...)) + | `-(language::matrix_type:R^2x2) | +-(language::R_set:R) - | +-(language::integer:3:Z) - | `-(language::integer:3:Z) - +-(language::name:t2:(R^3x3...)) - `-(language::expression_list:Z*Z) - +-(language::integer:0:Z) + | +-(language::integer:2:Z) + | `-(language::integer:2:Z) + +-(language::name:t3:(R^2x2...)) + `-(language::expression_list:R^2x2*R^2x2*Z) + +-(language::matrix_expression:R^2x2) + | +-(language::row_expression:void) + | | +-(language::integer:1:Z) + | | `-(language::integer:2:Z) + | `-(language::row_expression:void) + | +-(language::integer:1:Z) + | `-(language::integer:3:Z) + +-(language::name:a:R^2x2) `-(language::integer:0:Z) )"; @@ -743,7 +780,7 @@ let double : R^2 -> R^2, x -> 2*x; SECTION("R-list -> R^d") { std::string_view data = R"( -let square : R -> R^2, x -> (x, x*x); +let square : R -> R^2, x -> [x, x*x]; )"; std::string_view result = R"( @@ -806,7 +843,7 @@ let det : R^2x2 -> R, x -> x[0,0]*x[1,1]-x[1,0]*x[0,1]; SECTION("R-list -> R^dxd") { std::string_view data = R"( -let f : R -> R^2x2, x -> (x, x*x, 2-x, 0); +let f : R -> R^2x2, x -> [[x, x*x], [2-x, 0]]; )"; std::string_view result = R"( @@ -821,7 +858,7 @@ let f : R -> R^2x2, x -> (x, x*x, 2-x, 0); SECTION("R^d*R^d -> R^dxd") { std::string_view data = R"( -let f : R^2*R^2 -> R^2x2, (x,y) -> (x[0], y[0], x[1], y[1]); +let f : R^2*R^2 -> R^2x2, (x,y) -> [[x[0], y[0]], [x[1], y[1]]]; )"; std::string_view result = R"( @@ -1153,8 +1190,8 @@ let f: R -> X, x -> x; SECTION("single argument") { std::string_view data = R"( -let f : R^2 -> R^2, x -> (x[0]+1, x[1]-2); -let x : R^2, x = (1,2); +let f : R^2 -> R^2, x -> [x[0]+1, x[1]-2]; +let x : R^2, x = [1,2]; x = f(x); )"; @@ -1168,7 +1205,7 @@ x = f(x); | | +-(language::R_set:R) | | `-(language::integer:2:Z) | +-(language::name:x:R^2) - | `-(language::expression_list:Z*Z) + | `-(language::vector_expression:R^2) | +-(language::integer:1:Z) | `-(language::integer:2:Z) `-(language::eq_op:void) diff --git a/tests/test_ASTNodeExpressionBuilder.cpp b/tests/test_ASTNodeExpressionBuilder.cpp index 56af1db48dce6019d5cb3fedf93c3e32cfc12e25..127b2e01624a07ba9579494692573106ced0bc9a 100644 --- a/tests/test_ASTNodeExpressionBuilder.cpp +++ b/tests/test_ASTNodeExpressionBuilder.cpp @@ -273,7 +273,7 @@ z -= 2; SECTION("tuple -> R^3") { std::string_view data = R"( -let (t,x): R*R^3, (t,x) = (0,(1,2,3)); +let (t,x): R*R^3, (t,x) = (0,[1,2,3]); )"; std::string result = R"( @@ -284,7 +284,7 @@ let (t,x): R*R^3, (t,x) = (0,(1,2,3)); | `-(language::name:x:NameProcessor) `-(language::expression_list:ASTNodeExpressionListProcessor) +-(language::integer:0:ValueProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) +-(language::integer:1:ValueProcessor) +-(language::integer:2:ValueProcessor) `-(language::integer:3:ValueProcessor) @@ -296,7 +296,7 @@ let (t,x): R*R^3, (t,x) = (0,(1,2,3)); SECTION("tuple -> R^2") { std::string_view data = R"( -let (t,x): R*R^2, (t,x) = (0,(1,2)); +let (t,x): R*R^2, (t,x) = (0,[1,2]); )"; std::string result = R"( @@ -307,7 +307,7 @@ let (t,x): R*R^2, (t,x) = (0,(1,2)); | `-(language::name:x:NameProcessor) `-(language::expression_list:ASTNodeExpressionListProcessor) +-(language::integer:0:ValueProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) +-(language::integer:1:ValueProcessor) `-(language::integer:2:ValueProcessor) )"; @@ -466,15 +466,15 @@ a--; SECTION("array subscript") { std::string_view data = R"( -let x: R^3, x = (1, 2, 3); +let x: R^3, x = [1, 2, 3]; let y: R, y = x[2]; )"; std::string result = R"( (root:ASTNodeListProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) | +-(language::name:x:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) diff --git a/tests/test_ASTNodeFunctionExpressionBuilder.cpp b/tests/test_ASTNodeFunctionExpressionBuilder.cpp index 4bf775a679490306efecc2617547cb424c6a256b..3429ed5bb152725ee667a96247623628284c1159 100644 --- a/tests/test_ASTNodeFunctionExpressionBuilder.cpp +++ b/tests/test_ASTNodeFunctionExpressionBuilder.cpp @@ -492,13 +492,13 @@ f(1); SECTION("Return tuple -> R^2") { std::string_view data = R"( -let f : R*R -> R^2, (x,y) -> (x,y); +let f : R*R -> R^2, (x,y) -> [x,y]; f(1,2); )"; std::string_view result = R"( (root:ASTNodeListProcessor) - `-(language::function_evaluation:TupleToTinyVectorProcessor<FunctionProcessor, 2ul>) + `-(language::function_evaluation:FunctionProcessor) +-(language::name:f:NameProcessor) `-(language::function_argument_list:ASTNodeExpressionListProcessor) +-(language::integer:1:ValueProcessor) @@ -511,13 +511,13 @@ f(1,2); SECTION("Return tuple -> R^3") { std::string_view data = R"( -let f : R*R*R -> R^3, (x,y,z) -> (x,y,z); +let f : R*R*R -> R^3, (x,y,z) -> [x,y,z]; f(1,2,3); )"; std::string_view result = R"( (root:ASTNodeListProcessor) - `-(language::function_evaluation:TupleToTinyVectorProcessor<FunctionProcessor, 3ul>) + `-(language::function_evaluation:FunctionProcessor) +-(language::name:f:NameProcessor) `-(language::function_argument_list:ASTNodeExpressionListProcessor) +-(language::integer:1:ValueProcessor) @@ -548,13 +548,13 @@ f(1); SECTION("Return tuple -> R^2x2") { std::string_view data = R"( -let f : R*R*R*R -> R^2x2, (x,y,z,t) -> (x,y,z,t); +let f : R*R*R*R -> R^2x2, (x,y,z,t) -> [[x,y],[z,t]]; f(1,2,3,4); )"; std::string_view result = R"( (root:ASTNodeListProcessor) - `-(language::function_evaluation:TupleToTinyMatrixProcessor<FunctionProcessor, 2ul>) + `-(language::function_evaluation:FunctionProcessor) +-(language::name:f:NameProcessor) `-(language::function_argument_list:ASTNodeExpressionListProcessor) +-(language::integer:1:ValueProcessor) @@ -569,24 +569,24 @@ f(1,2,3,4); SECTION("Return tuple -> R^3x3") { std::string_view data = R"( -let f : R^3*R^3*R^3 -> R^3x3, (x,y,z) -> (x[0],x[1],x[2],y[0],y[1],y[2],z[0],z[1],z[2]); -f((1,2,3),(4,5,6),(7,8,9)); +let f : R^3*R^3*R^3 -> R^3x3, (x,y,z) -> [[x[0],x[1],x[2]],[y[0],y[1],y[2]],[z[0],z[1],z[2]]]; +f([1,2,3],[4,5,6],[7,8,9]); )"; std::string_view result = R"( (root:ASTNodeListProcessor) - `-(language::function_evaluation:TupleToTinyMatrixProcessor<FunctionProcessor, 3ul>) + `-(language::function_evaluation:FunctionProcessor) +-(language::name:f:NameProcessor) `-(language::function_argument_list:ASTNodeExpressionListProcessor) - +-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) - +-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:4:ValueProcessor) | +-(language::integer:5:ValueProcessor) | `-(language::integer:6:ValueProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) +-(language::integer:7:ValueProcessor) +-(language::integer:8:ValueProcessor) `-(language::integer:9:ValueProcessor) @@ -700,7 +700,7 @@ f(1); SECTION("Return embedded R^d compound") { std::string_view data = R"( -let f : R*R*R*R -> R*R^1*R^2*R^3, (x,y,z,t) -> (t, (x), (x,y), (x,y,z)); +let f : R*R*R*R -> R*R^1*R^2*R^3, (x,y,z,t) -> (t, [x], [x,y], [x,y,z]); f(1,2,3,4); )"; @@ -721,7 +721,7 @@ f(1,2,3,4); SECTION("Return embedded R^dxd compound") { std::string_view data = R"( -let f : R*R*R*R -> R*R^1x1*R^2x2*R^3x3, (x,y,z,t) -> (t, (x), (x,y,z,t), (x,y,z, x,x,x, t,t,t)); +let f : R*R*R*R -> R*R^1x1*R^2x2*R^3x3, (x,y,z,t) -> (t, [[x]], [[x,y],[z,t]], [[x,y,z], [x,x,x], [t,t,t]]); f(1,2,3,4); )"; @@ -742,7 +742,7 @@ f(1,2,3,4); SECTION("Return embedded R^d compound with '0'") { std::string_view data = R"( -let f : R*R*R*R -> R*R^1*R^2*R^3, (x,y,z,t) -> (t, 0, 0, (x,y,z)); +let f : R*R*R*R -> R*R^1*R^2*R^3, (x,y,z,t) -> (t, 0, 0, [x,y,z]); f(1,2,3,4); )"; @@ -763,7 +763,7 @@ f(1,2,3,4); SECTION("Return embedded R^dxd compound with '0'") { std::string_view data = R"( -let f : R*R*R*R -> R*R^1x1*R^2x2*R^3x3, (x,y,z,t) -> (t, 0, 0, (x, y, z, t, x, y, z, t, x)); +let f : R*R*R*R -> R*R^1x1*R^2x2*R^3x3, (x,y,z,t) -> (t, 0, 0, [[x, y, z], [t, x, y], [z, t, x]]); f(1,2,3,4); )"; @@ -887,14 +887,14 @@ f(0); { std::string_view data = R"( let f: R^3 -> R, x -> x[0]+x[1]+x[2]; -f((1,2,3)); +f([1,2,3]); )"; std::string_view result = R"( (root:ASTNodeListProcessor) `-(language::function_evaluation:FunctionProcessor) +-(language::name:f:NameProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) +-(language::integer:1:ValueProcessor) +-(language::integer:2:ValueProcessor) `-(language::integer:3:ValueProcessor) @@ -907,23 +907,26 @@ f((1,2,3)); { std::string_view data = R"( let f: R^3x3 -> R, x -> x[0,0]+x[0,1]+x[0,2]; -f((1,2,3,4,5,6,7,8,9)); +f([[1,2,3],[4,5,6],[7,8,9]]); )"; std::string_view result = R"( (root:ASTNodeListProcessor) `-(language::function_evaluation:FunctionProcessor) +-(language::name:f:NameProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) - +-(language::integer:1:ValueProcessor) - +-(language::integer:2:ValueProcessor) - +-(language::integer:3:ValueProcessor) - +-(language::integer:4:ValueProcessor) - +-(language::integer:5:ValueProcessor) - +-(language::integer:6:ValueProcessor) - +-(language::integer:7:ValueProcessor) - +-(language::integer:8:ValueProcessor) - `-(language::integer:9:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:4:ValueProcessor) + | +-(language::integer:5:ValueProcessor) + | `-(language::integer:6:ValueProcessor) + `-(language::row_expression:FakeProcessor) + +-(language::integer:7:ValueProcessor) + +-(language::integer:8:ValueProcessor) + `-(language::integer:9:ValueProcessor) )"; CHECK_AST(data, result); @@ -933,7 +936,7 @@ f((1,2,3,4,5,6,7,8,9)); { std::string_view data = R"( let f: R*R^3*R^2x2->R, (t,x,y) -> t*(x[0]+x[1]+x[2])*y[0,0]+y[1,1]; -f(2,(1,2,3),(2,3,-1,1.3)); +f(2,[1,2,3],[[2,3],[-1,1.3]]); )"; std::string_view result = R"( @@ -942,16 +945,18 @@ f(2,(1,2,3),(2,3,-1,1.3)); +-(language::name:f:NameProcessor) `-(language::function_argument_list:ASTNodeExpressionListProcessor) +-(language::integer:2:ValueProcessor) - +-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) - `-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor>) - +-(language::integer:2:ValueProcessor) - +-(language::integer:3:ValueProcessor) - +-(language::unary_minus:UnaryExpressionProcessor<language::unary_minus, long, long>) - | `-(language::integer:1:ValueProcessor) - `-(language::real:1.3:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::row_expression:FakeProcessor) + +-(language::unary_minus:UnaryExpressionProcessor<language::unary_minus, long, long>) + | `-(language::integer:1:ValueProcessor) + `-(language::real:1.3:ValueProcessor) )"; CHECK_AST(data, result); @@ -1114,52 +1119,44 @@ prev(3 + .24); SECTION("arguments invalid tuple -> R^d conversion") { - SECTION("tuple[3] -> R^2") + SECTION("tuple[2] -> R^2") { std::string_view data = R"( let f : R^2 -> R, x->x[0]; -f((1,2,3)); +f((1,2)); )"; - CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, - std::string{ - "incompatible dimensions in affectation: expecting 2, but provided 3"}); + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{"cannot convert list to R^2"}); } - SECTION("tuple[2] -> R^3") + SECTION("tuple[3] -> R^3") { std::string_view data = R"( let f : R^3 -> R, x->x[0]; -f((1,2)); +f((1,2,3)); )"; - CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, - std::string{ - "incompatible dimensions in affectation: expecting 3, but provided 2"}); + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{"cannot convert list to R^3"}); } - SECTION("compound tuple[3] -> R^2") + SECTION("compound tuple[2] -> R^2") { std::string_view data = R"( let f : R*R^2 -> R, (t,x)->x[0]; -f(1,(1,2,3)); +f(1,(1,2)); )"; - CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, - std::string{ - "incompatible dimensions in affectation: expecting 2, but provided 3"}); + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{"cannot convert list to R^2"}); } SECTION("compound tuple[2] -> R^3") { std::string_view data = R"( let f : R^3*R^2 -> R, (x,y)->x[0]*y[1]; -f((1,2),(3,4)); +f((1,2,3),[3,4]); )"; - CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, - std::string{ - "incompatible dimensions in affectation: expecting 3, but provided 2"}); + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{"cannot convert list to R^3"}); } SECTION("list instead of tuple -> R^3") @@ -1176,7 +1173,7 @@ f(1,2,3); { std::string_view data = R"( let f : R^3*R^2 -> R, (x,y) -> x[0]*x[1]-y[0]; -f((1,2,3),2,3); +f([1,2,3],2,3); )"; CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{"bad number of arguments: expecting 2, provided 3"}); diff --git a/tests/test_ASTNodeListAffectationExpressionBuilder.cpp b/tests/test_ASTNodeListAffectationExpressionBuilder.cpp index 8d495053e0d0e09b67c103a4f387ecf6afc018bf..02aa43085baca268485d48af950cfde2f3485846 100644 --- a/tests/test_ASTNodeListAffectationExpressionBuilder.cpp +++ b/tests/test_ASTNodeListAffectationExpressionBuilder.cpp @@ -189,8 +189,8 @@ let (r,b,z,m): R*R*R*R , (r,b,z,m) = (3.2, 1, 6, 2); { std::string_view data = R"( let a:R^1, a = 0; -let b:R^2, b = (1,2); -let c:R^3, c = (1,2,3); +let b:R^2, b = [1,2]; +let c:R^3, c = [1,2,3]; let (x1,x2,x3,x) : R^1*R^2*R^3*R, (x1,x2,x3,x) = (a, b, c, 2); )"; @@ -200,14 +200,14 @@ let (x1,x2,x3,x) : R^1*R^2*R^3*R, +-(language::eq_op:AffectationFromZeroProcessor<TinyVector<1ul, double> >) | +-(language::name:a:NameProcessor) | `-(language::integer:0:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<2ul, double>, TinyVector<2ul, double> >) | +-(language::name:b:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) | +-(language::integer:1:ValueProcessor) | `-(language::integer:2:ValueProcessor) - +-(language::eq_op:AffectationToTinyVectorFromListProcessor<language::eq_op, TinyVector<3ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyVector<3ul, double>, TinyVector<3ul, double> >) | +-(language::name:c:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) | +-(language::integer:1:ValueProcessor) | +-(language::integer:2:ValueProcessor) | `-(language::integer:3:ValueProcessor) @@ -231,8 +231,8 @@ let (x1,x2,x3,x) : R^1*R^2*R^3*R, { std::string_view data = R"( let a:R^1x1, a = 0; -let b:R^2x2, b = (1, 2, 3, 4); -let c:R^3x3, c = (9, 8, 7, 6, 5, 4, 3, 2, 1); +let b:R^2x2, b = [[1, 2], [3, 4]]; +let c:R^3x3, c = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]; let (x1,x2,x3,x) : R^1x1*R^2x2*R^3x3*R, (x1,x2,x3,x) = (a, b, c, 2); )"; @@ -242,25 +242,30 @@ let (x1,x2,x3,x) : R^1x1*R^2x2*R^3x3*R, +-(language::eq_op:AffectationProcessor<language::eq_op, TinyMatrix<1ul, 1ul, double>, long>) | +-(language::name:a:NameProcessor) | `-(language::integer:0:ValueProcessor) - +-(language::eq_op:AffectationToTinyMatrixFromListProcessor<language::eq_op, TinyMatrix<2ul, 2ul, double> >) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyMatrix<2ul, 2ul, double>, TinyMatrix<2ul, 2ul, double> >) | +-(language::name:b:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) - | +-(language::integer:1:ValueProcessor) - | +-(language::integer:2:ValueProcessor) - | +-(language::integer:3:ValueProcessor) - | `-(language::integer:4:ValueProcessor) - +-(language::eq_op:AffectationToTinyMatrixFromListProcessor<language::eq_op, TinyMatrix<3ul, 3ul, double> >) + | `-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:1:ValueProcessor) + | | `-(language::integer:2:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:4:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, TinyMatrix<3ul, 3ul, double>, TinyMatrix<3ul, 3ul, double> >) | +-(language::name:c:NameProcessor) - | `-(language::expression_list:ASTNodeExpressionListProcessor) - | +-(language::integer:9:ValueProcessor) - | +-(language::integer:8:ValueProcessor) - | +-(language::integer:7:ValueProcessor) - | +-(language::integer:6:ValueProcessor) - | +-(language::integer:5:ValueProcessor) - | +-(language::integer:4:ValueProcessor) - | +-(language::integer:3:ValueProcessor) - | +-(language::integer:2:ValueProcessor) - | `-(language::integer:1:ValueProcessor) + | `-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:9:ValueProcessor) + | | +-(language::integer:8:ValueProcessor) + | | `-(language::integer:7:ValueProcessor) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:6:ValueProcessor) + | | +-(language::integer:5:ValueProcessor) + | | `-(language::integer:4:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::integer:3:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:1:ValueProcessor) `-(language::eq_op:ListAffectationProcessor<language::eq_op>) +-(language::name_list:FakeProcessor) | +-(language::name:x1:NameProcessor) @@ -325,6 +330,1019 @@ let (x1,x2,x3,x) : R^1x1*R^2x2*R^3x3*R, (x1,x2,x3,x) = (0, 0, 0, 0); CHECK_AST(data, result); } + SECTION("with tuples from lists") + { + std::string_view data = R"( +let (x,n,s) : (R)*(N)*(string), (x,n,s) = ((1.2,3.4), (1,2,3), (2.1,4,3.3,17.2)); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:x:NameProcessor) + | +-(language::name:n:NameProcessor) + | `-(language::name:s:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::real:1.2:ValueProcessor) + | `-(language::real:3.4:ValueProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::real:2.1:ValueProcessor) + +-(language::integer:4:ValueProcessor) + +-(language::real:3.3:ValueProcessor) + `-(language::real:17.2:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("with tuples from tuples") + { + SECTION("tuple of B") + { + std::string_view data = R"( +let b:(B), b = (true, false); +let (b1,b2,b3) : (B)*(B)*(B), (b1,b2,b3) = (b, false, (true, true, false)); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<bool>) + | +-(language::name:b:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::true_kw:ValueProcessor) + | `-(language::false_kw:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:b1:NameProcessor) + | +-(language::name:b2:NameProcessor) + | `-(language::name:b3:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:b:NameProcessor) + +-(language::false_kw:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::true_kw:ValueProcessor) + +-(language::true_kw:ValueProcessor) + `-(language::false_kw:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of N") + { + std::string_view data = R"( +let b:(B), b = (true, false); +let n:(N), n = (2, 3, 2); +let z:(Z), z = (1, 3, 4); +let i1:N, i1 = 3; +let i2:N, i2 = 3; +let (n1,n2,n3,n4,n5,n6,n7,n8) : (N)*(N)*(N)*(N)*(N)*(N)*(N)*(N), + (n1,n2,n3,n4,n5,n6,n7,n8) = (b, n, z, false, 2, i1, (2, 3, 2), (i1, i2)); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<bool>) + | +-(language::name:b:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::true_kw:ValueProcessor) + | `-(language::false_kw:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<unsigned long>) + | +-(language::name:n:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<long>) + | +-(language::name:z:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:4:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i1:NameProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i2:NameProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:n1:NameProcessor) + | +-(language::name:n2:NameProcessor) + | +-(language::name:n3:NameProcessor) + | +-(language::name:n4:NameProcessor) + | +-(language::name:n5:NameProcessor) + | +-(language::name:n6:NameProcessor) + | +-(language::name:n7:NameProcessor) + | `-(language::name:n8:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:b:NameProcessor) + +-(language::name:n:NameProcessor) + +-(language::name:z:NameProcessor) + +-(language::false_kw:ValueProcessor) + +-(language::integer:2:ValueProcessor) + +-(language::name:i1:NameProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::name:i1:NameProcessor) + `-(language::name:i2:NameProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of Z") + { + std::string_view data = R"( +let b:(B), b = (true, false); +let n:(N), n = (2, 3, 2); +let z:(Z), z = (1, 3, 4); +let i1:N, i1 = 3; +let i2:N, i2 = 3; +let (z1,z2,z3,z4,z5,z6,z7,z8) : (Z)*(Z)*(Z)*(Z)*(Z)*(Z)*(Z)*(Z), + (z1,z2,z3,z4,z5,z6,z7,z8) = (b, n, z, false, 2, i1, (2, 3, 2), (i1, i2)); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<bool>) + | +-(language::name:b:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::true_kw:ValueProcessor) + | `-(language::false_kw:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<unsigned long>) + | +-(language::name:n:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<long>) + | +-(language::name:z:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:4:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i1:NameProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i2:NameProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:z1:NameProcessor) + | +-(language::name:z2:NameProcessor) + | +-(language::name:z3:NameProcessor) + | +-(language::name:z4:NameProcessor) + | +-(language::name:z5:NameProcessor) + | +-(language::name:z6:NameProcessor) + | +-(language::name:z7:NameProcessor) + | `-(language::name:z8:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:b:NameProcessor) + +-(language::name:n:NameProcessor) + +-(language::name:z:NameProcessor) + +-(language::false_kw:ValueProcessor) + +-(language::integer:2:ValueProcessor) + +-(language::name:i1:NameProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::name:i1:NameProcessor) + `-(language::name:i2:NameProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of R") + { + std::string_view data = R"( +let b:(B), b = (true, false); +let n:(N), n = (2, 3, 2); +let z:(Z), z = (1, 3, 4); +let r:(R), r = (1.2, 3.3, 2.4); +let i1:N, i1 = 3; +let i2:N, i2 = 3; +let (r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11) : (R)*(R)*(R)*(R)*(R)*(R)*(R)*(R)*(R)*(R)*(R), + (r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11) = (b, n, z, r, true, 2, i1, 2.3, (2, 3, 2), (i1, i2), (2.2, 1.4)); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<bool>) + | +-(language::name:b:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::true_kw:ValueProcessor) + | `-(language::false_kw:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<unsigned long>) + | +-(language::name:n:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<long>) + | +-(language::name:z:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:4:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<double>) + | +-(language::name:r:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::real:1.2:ValueProcessor) + | +-(language::real:3.3:ValueProcessor) + | `-(language::real:2.4:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i1:NameProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i2:NameProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:r1:NameProcessor) + | +-(language::name:r2:NameProcessor) + | +-(language::name:r3:NameProcessor) + | +-(language::name:r4:NameProcessor) + | +-(language::name:r5:NameProcessor) + | +-(language::name:r6:NameProcessor) + | +-(language::name:r7:NameProcessor) + | +-(language::name:r8:NameProcessor) + | +-(language::name:r9:NameProcessor) + | +-(language::name:r10:NameProcessor) + | `-(language::name:r11:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:b:NameProcessor) + +-(language::name:n:NameProcessor) + +-(language::name:z:NameProcessor) + +-(language::name:r:NameProcessor) + +-(language::true_kw:ValueProcessor) + +-(language::integer:2:ValueProcessor) + +-(language::name:i1:NameProcessor) + +-(language::real:2.3:ValueProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::name:i1:NameProcessor) + | `-(language::name:i2:NameProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::real:2.2:ValueProcessor) + `-(language::real:1.4:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of string") + { + std::string_view data = R"( +import utils; + +let b:(B), b = (true, false); +let n:(N), n = (2, 3, 2); +let z:(Z), z = (1, 3, 4); +let r:(R), r = (1.2, 3.3, 2.4); +let s:(string), s = ("foo", "bar"); +let i1:N, i1 = 3; +let i2:N, i2 = 3; +let (s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13): + (string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string), + (s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13) + = (b, n, z, r, s, 2, i1, 2.3, "foobar", (2, 3, 2), (i1, i2), (2.2, 1.4), ("hello", "world")); + +let v1:(R^1), v1 = (2, [3], [5]); +let v2:(R^2), v2 = ([2,3], [3,5]); +let v3:(R^3), v3 = ([2,2,3], 0, [1,3,5]); +let A1:(R^1x1), A1 = (2, [[3]]); +let A2:(R^2x2), A2 = ([[2,3], [3,5]],0); +let A3:(R^3x3), A3 = ([[2,2,3], [1,2,7], [1,3,5]], [[1,3,2], [6,3,5], [3,2,-1]]); +let (t1,t2,t3,t4,t5,t6,t7,t8,t9,t10): + (string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string), + (t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) + = (v1, v2, v3, A1, A2, A3, [[0]], [2,3], [[1,2],[3,4]], ([1,2,3], [2,3,1])); + +let (u1,u2,u3,u4): (string)*(string)*(string)*(string), + (u1,u2,u3,u4) = (true, [1], [1,2,3], [[1,2,3],[4,5,6],[7,8,9]]); +)"; + + std::string result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<bool>) + | +-(language::name:b:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::true_kw:ValueProcessor) + | `-(language::false_kw:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<unsigned long>) + | +-(language::name:n:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<long>) + | +-(language::name:z:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:4:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<double>) + | +-(language::name:r:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::real:1.2:ValueProcessor) + | +-(language::real:3.3:ValueProcessor) + | `-(language::real:2.4:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<)" + + demangled_stdstring + R"( >) + | +-(language::name:s:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::literal:"foo":ValueProcessor) + | `-(language::literal:"bar":ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i1:NameProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i2:NameProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::eq_op:ListAffectationProcessor<language::eq_op>) + | +-(language::name_list:FakeProcessor) + | | +-(language::name:s1:NameProcessor) + | | +-(language::name:s2:NameProcessor) + | | +-(language::name:s3:NameProcessor) + | | +-(language::name:s4:NameProcessor) + | | +-(language::name:s5:NameProcessor) + | | +-(language::name:s6:NameProcessor) + | | +-(language::name:s7:NameProcessor) + | | +-(language::name:s8:NameProcessor) + | | +-(language::name:s9:NameProcessor) + | | +-(language::name:s10:NameProcessor) + | | +-(language::name:s11:NameProcessor) + | | +-(language::name:s12:NameProcessor) + | | `-(language::name:s13:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::name:b:NameProcessor) + | +-(language::name:n:NameProcessor) + | +-(language::name:z:NameProcessor) + | +-(language::name:r:NameProcessor) + | +-(language::name:s:NameProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::name:i1:NameProcessor) + | +-(language::real:2.3:ValueProcessor) + | +-(language::literal:"foobar":ValueProcessor) + | +-(language::inner_expression_list:InnerListToVectorProcessor) + | | +-(language::integer:2:ValueProcessor) + | | +-(language::integer:3:ValueProcessor) + | | `-(language::integer:2:ValueProcessor) + | +-(language::inner_expression_list:InnerListToVectorProcessor) + | | +-(language::name:i1:NameProcessor) + | | `-(language::name:i2:NameProcessor) + | +-(language::inner_expression_list:InnerListToVectorProcessor) + | | +-(language::real:2.2:ValueProcessor) + | | `-(language::real:1.4:ValueProcessor) + | `-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::literal:"hello":ValueProcessor) + | `-(language::literal:"world":ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyVector<1ul, double> >) + | +-(language::name:v1:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + | | `-(language::integer:3:ValueProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + | `-(language::integer:5:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyVector<2ul, double> >) + | +-(language::name:v2:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::integer:3:ValueProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:5:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyVector<3ul, double> >) + | +-(language::name:v3:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | | +-(language::integer:2:ValueProcessor) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::integer:3:ValueProcessor) + | +-(language::integer:0:ValueProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:5:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyMatrix<1ul, 1ul, double> >) + | +-(language::name:A1:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::matrix_expression:TinyMatrixExpressionProcessor<1ul, 1ul>) + | `-(language::row_expression:FakeProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyMatrix<2ul, 2ul, double> >) + | +-(language::name:A2:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + | | +-(language::row_expression:FakeProcessor) + | | | +-(language::integer:2:ValueProcessor) + | | | `-(language::integer:3:ValueProcessor) + | | `-(language::row_expression:FakeProcessor) + | | +-(language::integer:3:ValueProcessor) + | | `-(language::integer:5:ValueProcessor) + | `-(language::integer:0:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyMatrix<3ul, 3ul, double> >) + | +-(language::name:A3:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + | | +-(language::row_expression:FakeProcessor) + | | | +-(language::integer:2:ValueProcessor) + | | | +-(language::integer:2:ValueProcessor) + | | | `-(language::integer:3:ValueProcessor) + | | +-(language::row_expression:FakeProcessor) + | | | +-(language::integer:1:ValueProcessor) + | | | +-(language::integer:2:ValueProcessor) + | | | `-(language::integer:7:ValueProcessor) + | | `-(language::row_expression:FakeProcessor) + | | +-(language::integer:1:ValueProcessor) + | | +-(language::integer:3:ValueProcessor) + | | `-(language::integer:5:ValueProcessor) + | `-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:1:ValueProcessor) + | | +-(language::integer:3:ValueProcessor) + | | `-(language::integer:2:ValueProcessor) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:6:ValueProcessor) + | | +-(language::integer:3:ValueProcessor) + | | `-(language::integer:5:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::integer:3:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::unary_minus:UnaryExpressionProcessor<language::unary_minus, long, long>) + | `-(language::integer:1:ValueProcessor) + +-(language::eq_op:ListAffectationProcessor<language::eq_op>) + | +-(language::name_list:FakeProcessor) + | | +-(language::name:t1:NameProcessor) + | | +-(language::name:t2:NameProcessor) + | | +-(language::name:t3:NameProcessor) + | | +-(language::name:t4:NameProcessor) + | | +-(language::name:t5:NameProcessor) + | | +-(language::name:t6:NameProcessor) + | | +-(language::name:t7:NameProcessor) + | | +-(language::name:t8:NameProcessor) + | | +-(language::name:t9:NameProcessor) + | | `-(language::name:t10:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::name:v1:NameProcessor) + | +-(language::name:v2:NameProcessor) + | +-(language::name:v3:NameProcessor) + | +-(language::name:A1:NameProcessor) + | +-(language::name:A2:NameProcessor) + | +-(language::name:A3:NameProcessor) + | +-(language::matrix_expression:TinyMatrixExpressionProcessor<1ul, 1ul>) + | | `-(language::row_expression:FakeProcessor) + | | `-(language::integer:0:ValueProcessor) + | +-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::integer:3:ValueProcessor) + | +-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + | | +-(language::row_expression:FakeProcessor) + | | | +-(language::integer:1:ValueProcessor) + | | | `-(language::integer:2:ValueProcessor) + | | `-(language::row_expression:FakeProcessor) + | | +-(language::integer:3:ValueProcessor) + | | `-(language::integer:4:ValueProcessor) + | `-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | | +-(language::integer:1:ValueProcessor) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::integer:3:ValueProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:1:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:u1:NameProcessor) + | +-(language::name:u2:NameProcessor) + | +-(language::name:u3:NameProcessor) + | `-(language::name:u4:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::true_kw:ValueProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + | `-(language::integer:1:ValueProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:4:ValueProcessor) + | +-(language::integer:5:ValueProcessor) + | `-(language::integer:6:ValueProcessor) + `-(language::row_expression:FakeProcessor) + +-(language::integer:7:ValueProcessor) + +-(language::integer:8:ValueProcessor) + `-(language::integer:9:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of R^1") + { + std::string_view data = R"( +let b:(B), b = (true, false); +let n:(N), n = (2, 3, 2); +let z:(Z), z = (1, 3, 4); +let r:(R), r = (1.2, 3.3, 2.4); +let X:(R^1), X = (1.2, [3.3], 2.4); +let i1:N, i1 = 3; +let i2:N, i2 = 3; +let (X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14) : (R^1)*(R^1)*(R^1)*(R^1)*(R^1)*(R^1)*(R^1)*(R^1)*(R^1)*(R^1)*(R^1)*(R^1)*(R^1)*(R^1), + (X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14) = (b, n, z, r, true, 2, i1, 2.3, [1.2], X, (2, 3, 2), (i1, i2), (2.2, 1.4), ([1], [2])); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<bool>) + | +-(language::name:b:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::true_kw:ValueProcessor) + | `-(language::false_kw:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<unsigned long>) + | +-(language::name:n:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<long>) + | +-(language::name:z:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:4:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<double>) + | +-(language::name:r:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::real:1.2:ValueProcessor) + | +-(language::real:3.3:ValueProcessor) + | `-(language::real:2.4:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyVector<1ul, double> >) + | +-(language::name:X:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::real:1.2:ValueProcessor) + | +-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + | | `-(language::real:3.3:ValueProcessor) + | `-(language::real:2.4:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i1:NameProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i2:NameProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:X1:NameProcessor) + | +-(language::name:X2:NameProcessor) + | +-(language::name:X3:NameProcessor) + | +-(language::name:X4:NameProcessor) + | +-(language::name:X5:NameProcessor) + | +-(language::name:X6:NameProcessor) + | +-(language::name:X7:NameProcessor) + | +-(language::name:X8:NameProcessor) + | +-(language::name:X9:NameProcessor) + | +-(language::name:X10:NameProcessor) + | +-(language::name:X11:NameProcessor) + | +-(language::name:X12:NameProcessor) + | +-(language::name:X13:NameProcessor) + | `-(language::name:X14:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:b:NameProcessor) + +-(language::name:n:NameProcessor) + +-(language::name:z:NameProcessor) + +-(language::name:r:NameProcessor) + +-(language::true_kw:ValueProcessor) + +-(language::integer:2:ValueProcessor) + +-(language::name:i1:NameProcessor) + +-(language::real:2.3:ValueProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + | `-(language::real:1.2:ValueProcessor) + +-(language::name:X:NameProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::name:i1:NameProcessor) + | `-(language::name:i2:NameProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::real:2.2:ValueProcessor) + | `-(language::real:1.4:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + | `-(language::integer:1:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + `-(language::integer:2:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of R^2") + { + std::string_view data = R"( +let X:(R^2), X = ([1.2,2], 0, [2.4, 2]); +let (X1,X2,X3) : (R^2)*(R^2)*(R^2), (X1,X2,X3) = (X, [1,2], ([0,2], [1,0])); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyVector<2ul, double> >) + | +-(language::name:X:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | | +-(language::real:1.2:ValueProcessor) + | | `-(language::integer:2:ValueProcessor) + | +-(language::integer:0:ValueProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | +-(language::real:2.4:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:X1:NameProcessor) + | +-(language::name:X2:NameProcessor) + | `-(language::name:X3:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:X:NameProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | +-(language::integer:0:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + +-(language::integer:1:ValueProcessor) + `-(language::integer:0:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of R^3") + { + std::string_view data = R"( +let X:(R^3), X = ([1.2,2,4.2], 0, [2.4, 1, 2]); +let (X1,X2,X3) : (R^3)*(R^3)*(R^3), (X1,X2,X3) = (X, [2,1,4], ([0,2,1.2], [1,2.1,3.1])); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyVector<3ul, double> >) + | +-(language::name:X:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | | +-(language::real:1.2:ValueProcessor) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::real:4.2:ValueProcessor) + | +-(language::integer:0:ValueProcessor) + | `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | +-(language::real:2.4:ValueProcessor) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:X1:NameProcessor) + | +-(language::name:X2:NameProcessor) + | `-(language::name:X3:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:X:NameProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:4:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + | +-(language::integer:0:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::real:1.2:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + +-(language::integer:1:ValueProcessor) + +-(language::real:2.1:ValueProcessor) + `-(language::real:3.1:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of R^1x1") + { + std::string_view data = R"( +let b:(B), b = (true, false); +let n:(N), n = (2, 3, 2); +let z:(Z), z = (1, 3, 4); +let r:(R), r = (1.2, 3.3, 2.4); +let A:(R^1x1), A = (1.2, [[3.3]], 2.4); +let i1:N, i1 = 3; +let i2:N, i2 = 3; +let (A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14) : (R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1), + (A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14) = (b, n, z, r, true, 2, i1, 2.3, [[1.2]], A, (2, 3, 2), (i1, i2), (2.2, 1.4), ([[1]], [[2]])); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<bool>) + | +-(language::name:b:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::true_kw:ValueProcessor) + | `-(language::false_kw:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<unsigned long>) + | +-(language::name:n:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<long>) + | +-(language::name:z:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:4:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<double>) + | +-(language::name:r:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::real:1.2:ValueProcessor) + | +-(language::real:3.3:ValueProcessor) + | `-(language::real:2.4:ValueProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyMatrix<1ul, 1ul, double> >) + | +-(language::name:A:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::real:1.2:ValueProcessor) + | +-(language::matrix_expression:TinyMatrixExpressionProcessor<1ul, 1ul>) + | | `-(language::row_expression:FakeProcessor) + | | `-(language::real:3.3:ValueProcessor) + | `-(language::real:2.4:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i1:NameProcessor) + | `-(language::integer:3:ValueProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, unsigned long, long>) + | +-(language::name:i2:NameProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:A1:NameProcessor) + | +-(language::name:A2:NameProcessor) + | +-(language::name:A3:NameProcessor) + | +-(language::name:A4:NameProcessor) + | +-(language::name:A5:NameProcessor) + | +-(language::name:A6:NameProcessor) + | +-(language::name:A7:NameProcessor) + | +-(language::name:A8:NameProcessor) + | +-(language::name:A9:NameProcessor) + | +-(language::name:A10:NameProcessor) + | +-(language::name:A11:NameProcessor) + | +-(language::name:A12:NameProcessor) + | +-(language::name:A13:NameProcessor) + | `-(language::name:A14:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:b:NameProcessor) + +-(language::name:n:NameProcessor) + +-(language::name:z:NameProcessor) + +-(language::name:r:NameProcessor) + +-(language::true_kw:ValueProcessor) + +-(language::integer:2:ValueProcessor) + +-(language::name:i1:NameProcessor) + +-(language::real:2.3:ValueProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<1ul, 1ul>) + | `-(language::row_expression:FakeProcessor) + | `-(language::real:1.2:ValueProcessor) + +-(language::name:A:NameProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::name:i1:NameProcessor) + | `-(language::name:i2:NameProcessor) + +-(language::inner_expression_list:InnerListToVectorProcessor) + | +-(language::real:2.2:ValueProcessor) + | `-(language::real:1.4:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<1ul, 1ul>) + | `-(language::row_expression:FakeProcessor) + | `-(language::integer:1:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<1ul, 1ul>) + `-(language::row_expression:FakeProcessor) + `-(language::integer:2:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of embedded data") + { + std::string_view data = R"( +let b: builtin_t, b = b; +let tb: (builtin_t), tb = (b,b); +let (tb1,tb2,tb3): (builtin_t)*(builtin_t)*(builtin_t), (tb1,tb2,tb3) = (b,tb, (b,b,b)); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationProcessor<language::eq_op, EmbeddedData, EmbeddedData>) + | +-(language::name:b:NameProcessor) + | `-(language::name:b:NameProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<EmbeddedData>) + | +-(language::name:tb:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::name:b:NameProcessor) + | `-(language::name:b:NameProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:tb1:NameProcessor) + | +-(language::name:tb2:NameProcessor) + | `-(language::name:tb3:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:b:NameProcessor) + +-(language::name:tb:NameProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::name:b:NameProcessor) + +-(language::name:b:NameProcessor) + `-(language::name:b:NameProcessor) +)"; + + CHECK_AST(data, result); + } + } + + SECTION("tuple of R^2x2") + { + std::string_view data = R"( +let A:(R^2x2), A = ([[1.2,2],[2.1,1]], 0, [[1.4, 2],[2.4, 2]]); +let (A1,A2,A3) : (R^2x2)*(R^2x2)*(R^2x2), (A1,A2,A3) = (A, [[1,2],[4,1]], ([[0,2], [1,0]], [[1.3,2], [3,1]])); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyMatrix<2ul, 2ul, double> >) + | +-(language::name:A:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + | | +-(language::row_expression:FakeProcessor) + | | | +-(language::real:1.2:ValueProcessor) + | | | `-(language::integer:2:ValueProcessor) + | | `-(language::row_expression:FakeProcessor) + | | +-(language::real:2.1:ValueProcessor) + | | `-(language::integer:1:ValueProcessor) + | +-(language::integer:0:ValueProcessor) + | `-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::real:1.4:ValueProcessor) + | | `-(language::integer:2:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::real:2.4:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:A1:NameProcessor) + | +-(language::name:A2:NameProcessor) + | `-(language::name:A3:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:A:NameProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:1:ValueProcessor) + | | `-(language::integer:2:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::integer:4:ValueProcessor) + | `-(language::integer:1:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:0:ValueProcessor) + | | `-(language::integer:2:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:0:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + +-(language::row_expression:FakeProcessor) + | +-(language::real:1.3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + `-(language::row_expression:FakeProcessor) + +-(language::integer:3:ValueProcessor) + `-(language::integer:1:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("tuple of R^3x3") + { + std::string_view data = R"( +let A:(R^3x3), A = ([[1.2,2,1],[2.1,1,3],[1.2,1.2,3.2]], 0, [[1.4, 2, 1],[2.4, 0, 2],[2.1, 0.1, 3.2]]); +let (A1,A2,A3) : (R^3x3)*(R^3x3)*(R^3x3), (A1,A2,A3) = (A, [[1,2,3],[1.2,3.1,1.8],[2,4,1]], ([[0,2,1], [2,1,0], [0.2,1,3]], [[1.3,2,1], [0.3,3,1], [0.1,2,4.3]])); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + +-(language::eq_op:AffectationToTupleFromListProcessor<TinyMatrix<3ul, 3ul, double> >) + | +-(language::name:A:NameProcessor) + | `-(language::expression_list:ASTNodeExpressionListProcessor) + | +-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + | | +-(language::row_expression:FakeProcessor) + | | | +-(language::real:1.2:ValueProcessor) + | | | +-(language::integer:2:ValueProcessor) + | | | `-(language::integer:1:ValueProcessor) + | | +-(language::row_expression:FakeProcessor) + | | | +-(language::real:2.1:ValueProcessor) + | | | +-(language::integer:1:ValueProcessor) + | | | `-(language::integer:3:ValueProcessor) + | | `-(language::row_expression:FakeProcessor) + | | +-(language::real:1.2:ValueProcessor) + | | +-(language::real:1.2:ValueProcessor) + | | `-(language::real:3.2:ValueProcessor) + | +-(language::integer:0:ValueProcessor) + | `-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::real:1.4:ValueProcessor) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::integer:1:ValueProcessor) + | +-(language::row_expression:FakeProcessor) + | | +-(language::real:2.4:ValueProcessor) + | | +-(language::integer:0:ValueProcessor) + | | `-(language::integer:2:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::real:2.1:ValueProcessor) + | +-(language::real:0.1:ValueProcessor) + | `-(language::real:3.2:ValueProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:A1:NameProcessor) + | +-(language::name:A2:NameProcessor) + | `-(language::name:A3:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::name:A:NameProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:1:ValueProcessor) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::integer:3:ValueProcessor) + | +-(language::row_expression:FakeProcessor) + | | +-(language::real:1.2:ValueProcessor) + | | +-(language::real:3.1:ValueProcessor) + | | `-(language::real:1.8:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:4:ValueProcessor) + | `-(language::integer:1:ValueProcessor) + `-(language::inner_expression_list:InnerListToVectorProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:0:ValueProcessor) + | | +-(language::integer:2:ValueProcessor) + | | `-(language::integer:1:ValueProcessor) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:2:ValueProcessor) + | | +-(language::integer:1:ValueProcessor) + | | `-(language::integer:0:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::real:0.2:ValueProcessor) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + +-(language::row_expression:FakeProcessor) + | +-(language::real:1.3:ValueProcessor) + | +-(language::integer:2:ValueProcessor) + | `-(language::integer:1:ValueProcessor) + +-(language::row_expression:FakeProcessor) + | +-(language::real:0.3:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:1:ValueProcessor) + `-(language::row_expression:FakeProcessor) + +-(language::real:0.1:ValueProcessor) + +-(language::integer:2:ValueProcessor) + `-(language::real:4.3:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + SECTION("from function") { std::string_view data = R"( @@ -366,10 +1384,10 @@ let (s,r): string*string, (s,r) = ("foo","bar"); CHECK_AST(data, result); } - SECTION("string with conversion") + SECTION("string with scalar conversions") { std::string_view data = R"( -let n:N, n =2; +let n:N, n = 2; let (r,s,t,u) : string*string*string*string, (r,s,t,u) = (3.2, -2, true, n); )"; @@ -396,6 +1414,80 @@ let (r,s,t,u) : string*string*string*string, CHECK_AST(data, result); } + SECTION("string with vector conversions") + { + std::string_view data = R"( +let (r,s,t) : string*string*string, + (r,s,t) = ([3.2], [-2, 3], [1,3,2]); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:r:NameProcessor) + | +-(language::name:s:NameProcessor) + | `-(language::name:t:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<1ul>) + | `-(language::real:3.2:ValueProcessor) + +-(language::vector_expression:TinyVectorExpressionProcessor<2ul>) + | +-(language::unary_minus:UnaryExpressionProcessor<language::unary_minus, long, long>) + | | `-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::vector_expression:TinyVectorExpressionProcessor<3ul>) + +-(language::integer:1:ValueProcessor) + +-(language::integer:3:ValueProcessor) + `-(language::integer:2:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + + SECTION("string with matrix conversions") + { + std::string_view data = R"( +let (r,s,t) : string*string*string, + (r,s,t) = ([[3.2]], [[1, 2],[-2, 3]], [[1,3,2],[2,1,3],[4,1,2]]); +)"; + + std::string_view result = R"( +(root:ASTNodeListProcessor) + `-(language::eq_op:ListAffectationProcessor<language::eq_op>) + +-(language::name_list:FakeProcessor) + | +-(language::name:r:NameProcessor) + | +-(language::name:s:NameProcessor) + | `-(language::name:t:NameProcessor) + `-(language::expression_list:ASTNodeExpressionListProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<1ul, 1ul>) + | `-(language::row_expression:FakeProcessor) + | `-(language::real:3.2:ValueProcessor) + +-(language::matrix_expression:TinyMatrixExpressionProcessor<2ul, 2ul>) + | +-(language::row_expression:FakeProcessor) + | | +-(language::integer:1:ValueProcessor) + | | `-(language::integer:2:ValueProcessor) + | `-(language::row_expression:FakeProcessor) + | +-(language::unary_minus:UnaryExpressionProcessor<language::unary_minus, long, long>) + | | `-(language::integer:2:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::matrix_expression:TinyMatrixExpressionProcessor<3ul, 3ul>) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:1:ValueProcessor) + | +-(language::integer:3:ValueProcessor) + | `-(language::integer:2:ValueProcessor) + +-(language::row_expression:FakeProcessor) + | +-(language::integer:2:ValueProcessor) + | +-(language::integer:1:ValueProcessor) + | `-(language::integer:3:ValueProcessor) + `-(language::row_expression:FakeProcessor) + +-(language::integer:4:ValueProcessor) + +-(language::integer:1:ValueProcessor) + `-(language::integer:2:ValueProcessor) +)"; + + CHECK_AST(data, result); + } + SECTION("embedded data") { std::string_view data = R"( @@ -503,7 +1595,7 @@ let x:R; SECTION("invalid R^n -> R^m conversion") { std::string_view data = R"( -let x:R^2, x = (1,2); +let x:R^2, x = [1,2]; let y:R^3, y = x; )"; diff --git a/tests/test_ASTNodeNaturalConversionChecker.cpp b/tests/test_ASTNodeNaturalConversionChecker.cpp index 6852222ae307f2cdac86463ecc2b59fde4536618..7823664a1319f7699c3264805ac4c4fb68085e4a 100644 --- a/tests/test_ASTNodeNaturalConversionChecker.cpp +++ b/tests/test_ASTNodeNaturalConversionChecker.cpp @@ -94,19 +94,6 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::matrix_t>(1, 1)}); } - SECTION("list -> R^1x1") - { - data_node->m_data_type = - ASTNodeDataType::build<ASTNodeDataType::list_t>({std::make_shared<const ASTNodeDataType>(double_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - } - REQUIRE_NOTHROW( - ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::matrix_t>(1, 1)}); - } - SECTION("'0' -> R^dxd") { data_node->m_data_type = int_dt; @@ -140,88 +127,12 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::matrix_t>(2, 2)}); } - SECTION("list -> R^2x2") - { - data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::list_t>( - {std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), - std::make_shared<const ASTNodeDataType>(unsigned_int_dt), - std::make_shared<const ASTNodeDataType>(unsigned_int_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - - std::unique_ptr list1_node = std::make_unique<ASTNode>(); - list1_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list1_node)); - - std::unique_ptr list2_node = std::make_unique<ASTNode>(); - list2_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list2_node)); - - std::unique_ptr list3_node = std::make_unique<ASTNode>(); - list3_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list3_node)); - } - REQUIRE_NOTHROW( - ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::matrix_t>(2, 2)}); - } - SECTION("R^3x3 -> R^3x3") { data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::matrix_t>(3, 3); REQUIRE_NOTHROW( ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::matrix_t>(3, 3)}); } - - SECTION("list -> R^3x3") - { - data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::list_t>( - {std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), - std::make_shared<const ASTNodeDataType>(int_dt), std::make_shared<const ASTNodeDataType>(double_dt), - std::make_shared<const ASTNodeDataType>(unsigned_int_dt), std::make_shared<const ASTNodeDataType>(int_dt), - std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), - std::make_shared<const ASTNodeDataType>(int_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - - std::unique_ptr list1_node = std::make_unique<ASTNode>(); - list1_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list1_node)); - - std::unique_ptr list2_node = std::make_unique<ASTNode>(); - list2_node->m_data_type = int_dt; - data_node->emplace_back(std::move(list2_node)); - - std::unique_ptr list3_node = std::make_unique<ASTNode>(); - list3_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list3_node)); - - std::unique_ptr list4_node = std::make_unique<ASTNode>(); - list4_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list4_node)); - - std::unique_ptr list5_node = std::make_unique<ASTNode>(); - list5_node->m_data_type = int_dt; - data_node->emplace_back(std::move(list5_node)); - - std::unique_ptr list6_node = std::make_unique<ASTNode>(); - list6_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list6_node)); - - std::unique_ptr list7_node = std::make_unique<ASTNode>(); - list7_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list7_node)); - - std::unique_ptr list8_node = std::make_unique<ASTNode>(); - list8_node->m_data_type = int_dt; - data_node->emplace_back(std::move(list8_node)); - } - REQUIRE_NOTHROW( - ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::matrix_t>(3, 3)}); - } } SECTION("-> R^d") @@ -233,19 +144,6 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::vector_t>(1)}); } - SECTION("list -> R^1") - { - data_node->m_data_type = - ASTNodeDataType::build<ASTNodeDataType::list_t>({std::make_shared<const ASTNodeDataType>(double_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - } - REQUIRE_NOTHROW( - ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::vector_t>(1)}); - } - SECTION("'0' -> R^d") { data_node->m_data_type = int_dt; @@ -279,52 +177,12 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::vector_t>(2)}); } - SECTION("list -> R^2") - { - data_node->m_data_type = - ASTNodeDataType::build<ASTNodeDataType::list_t>({std::make_shared<const ASTNodeDataType>(double_dt), - std::make_shared<const ASTNodeDataType>(unsigned_int_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - - std::unique_ptr list1_node = std::make_unique<ASTNode>(); - list1_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list1_node)); - } - REQUIRE_NOTHROW( - ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::vector_t>(2)}); - } - SECTION("R^3 -> R^3") { data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::vector_t>(3); REQUIRE_NOTHROW( ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::vector_t>(3)}); } - - SECTION("list -> R^3") - { - data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::list_t>( - {std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), - std::make_shared<const ASTNodeDataType>(int_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - - std::unique_ptr list1_node = std::make_unique<ASTNode>(); - list1_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list1_node)); - - std::unique_ptr list2_node = std::make_unique<ASTNode>(); - list2_node->m_data_type = int_dt; - data_node->emplace_back(std::move(list2_node)); - } - REQUIRE_NOTHROW( - ASTNodeNaturalConversionChecker{*data_node, ASTNodeDataType::build<ASTNodeDataType::vector_t>(3)}); - } } SECTION("-> R") @@ -908,99 +766,6 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") "invalid implicit conversion: R^2x2 -> R^3x3"); } - SECTION("list1 -> R^dxd") - { - data_node->m_data_type = - ASTNodeDataType::build<ASTNodeDataType::list_t>({std::make_shared<const ASTNodeDataType>(double_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - } - - SECTION("d=2") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::matrix_t>(2, - 2)}), - "incompatible dimensions in affectation: expecting 4, but provided 1"); - } - - SECTION("d=3") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::matrix_t>(3, - 3)}), - "incompatible dimensions in affectation: expecting 9, but provided 1"); - } - } - - SECTION("list2 -> R^dxd") - { - data_node->m_data_type = list_dt; - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - - std::unique_ptr list1_node = std::make_unique<ASTNode>(); - list1_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list1_node)); - } - - SECTION("d=1") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::matrix_t>(1, - 1)}), - "incompatible dimensions in affectation: expecting 1, but provided 2"); - } - - SECTION("d=3") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::matrix_t>(3, - 3)}), - "incompatible dimensions in affectation: expecting 9, but provided 2"); - } - } - - SECTION("list3 -> R^dxd") - { - data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::list_t>( - {std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), - std::make_shared<const ASTNodeDataType>(int_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - - std::unique_ptr list1_node = std::make_unique<ASTNode>(); - list1_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list1_node)); - - std::unique_ptr list2_node = std::make_unique<ASTNode>(); - list2_node->m_data_type = int_dt; - data_node->emplace_back(std::move(list2_node)); - } - - SECTION("d=1") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::matrix_t>(1, - 1)}), - "incompatible dimensions in affectation: expecting 1, but provided 3"); - } - - SECTION("d=2") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::matrix_t>(2, - 2)}), - "incompatible dimensions in affectation: expecting 4, but provided 3"); - } - } - SECTION("tuple -> R^dxd") { SECTION("tuple(N) -> R^1x1") @@ -1273,6 +1038,98 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") "invalid implicit conversion: string -> R^3x3"); } } + + SECTION("invalid list -> R^1x1") + { + data_node->m_data_type = + ASTNodeDataType::build<ASTNodeDataType::list_t>({std::make_shared<const ASTNodeDataType>(double_dt)}); + { + std::unique_ptr list0_node = std::make_unique<ASTNode>(); + list0_node->m_data_type = double_dt; + data_node->emplace_back(std::move(list0_node)); + } + REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, + ASTNodeDataType::build<ASTNodeDataType::matrix_t>(1, 1)}), + "cannot convert list to R^1x1"); + } + + SECTION("invalid list -> R^2x2") + { + data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::list_t>( + {std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), + std::make_shared<const ASTNodeDataType>(unsigned_int_dt), + std::make_shared<const ASTNodeDataType>(unsigned_int_dt)}); + { + std::unique_ptr list0_node = std::make_unique<ASTNode>(); + list0_node->m_data_type = double_dt; + data_node->emplace_back(std::move(list0_node)); + + std::unique_ptr list1_node = std::make_unique<ASTNode>(); + list1_node->m_data_type = unsigned_int_dt; + data_node->emplace_back(std::move(list1_node)); + + std::unique_ptr list2_node = std::make_unique<ASTNode>(); + list2_node->m_data_type = unsigned_int_dt; + data_node->emplace_back(std::move(list2_node)); + + std::unique_ptr list3_node = std::make_unique<ASTNode>(); + list3_node->m_data_type = unsigned_int_dt; + data_node->emplace_back(std::move(list3_node)); + } + REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, + ASTNodeDataType::build<ASTNodeDataType::matrix_t>(2, 2)}), + "cannot convert list to R^2x2"); + } + + SECTION("invalid list -> R^3x3") + { + data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::list_t>( + {std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), + std::make_shared<const ASTNodeDataType>(int_dt), std::make_shared<const ASTNodeDataType>(double_dt), + std::make_shared<const ASTNodeDataType>(unsigned_int_dt), std::make_shared<const ASTNodeDataType>(int_dt), + std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), + std::make_shared<const ASTNodeDataType>(int_dt)}); + { + std::unique_ptr list0_node = std::make_unique<ASTNode>(); + list0_node->m_data_type = double_dt; + data_node->emplace_back(std::move(list0_node)); + + std::unique_ptr list1_node = std::make_unique<ASTNode>(); + list1_node->m_data_type = unsigned_int_dt; + data_node->emplace_back(std::move(list1_node)); + + std::unique_ptr list2_node = std::make_unique<ASTNode>(); + list2_node->m_data_type = int_dt; + data_node->emplace_back(std::move(list2_node)); + + std::unique_ptr list3_node = std::make_unique<ASTNode>(); + list3_node->m_data_type = double_dt; + data_node->emplace_back(std::move(list3_node)); + + std::unique_ptr list4_node = std::make_unique<ASTNode>(); + list4_node->m_data_type = unsigned_int_dt; + data_node->emplace_back(std::move(list4_node)); + + std::unique_ptr list5_node = std::make_unique<ASTNode>(); + list5_node->m_data_type = int_dt; + data_node->emplace_back(std::move(list5_node)); + + std::unique_ptr list6_node = std::make_unique<ASTNode>(); + list6_node->m_data_type = double_dt; + data_node->emplace_back(std::move(list6_node)); + + std::unique_ptr list7_node = std::make_unique<ASTNode>(); + list7_node->m_data_type = unsigned_int_dt; + data_node->emplace_back(std::move(list7_node)); + + std::unique_ptr list8_node = std::make_unique<ASTNode>(); + list8_node->m_data_type = int_dt; + data_node->emplace_back(std::move(list8_node)); + } + REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, + ASTNodeDataType::build<ASTNodeDataType::matrix_t>(3, 3)}), + "cannot convert list to R^3x3"); + } } SECTION("-> R^d") @@ -1325,93 +1182,6 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") "invalid implicit conversion: R^2 -> R^3"); } - SECTION("list1 -> R^d") - { - data_node->m_data_type = - ASTNodeDataType::build<ASTNodeDataType::list_t>({std::make_shared<const ASTNodeDataType>(double_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - } - - SECTION("d=2") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::vector_t>(2)}), - "incompatible dimensions in affectation: expecting 2, but provided 1"); - } - - SECTION("d=3") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::vector_t>(3)}), - "incompatible dimensions in affectation: expecting 3, but provided 1"); - } - } - - SECTION("list2 -> R^d") - { - data_node->m_data_type = list_dt; - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - - std::unique_ptr list1_node = std::make_unique<ASTNode>(); - list1_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list1_node)); - } - - SECTION("d=1") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::vector_t>(1)}), - "incompatible dimensions in affectation: expecting 1, but provided 2"); - } - - SECTION("d=3") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::vector_t>(3)}), - "incompatible dimensions in affectation: expecting 3, but provided 2"); - } - } - - SECTION("list3 -> R^d") - { - data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::list_t>( - {std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), - std::make_shared<const ASTNodeDataType>(int_dt)}); - { - std::unique_ptr list0_node = std::make_unique<ASTNode>(); - list0_node->m_data_type = double_dt; - data_node->emplace_back(std::move(list0_node)); - - std::unique_ptr list1_node = std::make_unique<ASTNode>(); - list1_node->m_data_type = unsigned_int_dt; - data_node->emplace_back(std::move(list1_node)); - - std::unique_ptr list2_node = std::make_unique<ASTNode>(); - list2_node->m_data_type = int_dt; - data_node->emplace_back(std::move(list2_node)); - } - - SECTION("d=1") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::vector_t>(1)}), - "incompatible dimensions in affectation: expecting 1, but provided 3"); - } - - SECTION("d=2") - { - REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, - ASTNodeDataType::build<ASTNodeDataType::vector_t>(2)}), - "incompatible dimensions in affectation: expecting 2, but provided 3"); - } - } - SECTION("tuple -> R^d") { SECTION("tuple(N) -> R^1") @@ -1714,6 +1484,62 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") "invalid implicit conversion: string -> R^3"); } } + + SECTION("invalid list -> R^1") + { + data_node->m_data_type = + ASTNodeDataType::build<ASTNodeDataType::list_t>({std::make_shared<const ASTNodeDataType>(double_dt)}); + { + std::unique_ptr list0_node = std::make_unique<ASTNode>(); + list0_node->m_data_type = double_dt; + data_node->emplace_back(std::move(list0_node)); + } + REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, + ASTNodeDataType::build<ASTNodeDataType::vector_t>(1)}), + "cannot convert list to R^1"); + } + + SECTION("invalid list -> R^2") + { + data_node->m_data_type = + ASTNodeDataType::build<ASTNodeDataType::list_t>({std::make_shared<const ASTNodeDataType>(double_dt), + std::make_shared<const ASTNodeDataType>(unsigned_int_dt)}); + { + std::unique_ptr list0_node = std::make_unique<ASTNode>(); + list0_node->m_data_type = double_dt; + data_node->emplace_back(std::move(list0_node)); + + std::unique_ptr list1_node = std::make_unique<ASTNode>(); + list1_node->m_data_type = unsigned_int_dt; + data_node->emplace_back(std::move(list1_node)); + } + REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, + ASTNodeDataType::build<ASTNodeDataType::vector_t>(2)}), + "cannot convert list to R^2"); + } + + SECTION("invalid list -> R^3") + { + data_node->m_data_type = ASTNodeDataType::build<ASTNodeDataType::list_t>( + {std::make_shared<const ASTNodeDataType>(double_dt), std::make_shared<const ASTNodeDataType>(unsigned_int_dt), + std::make_shared<const ASTNodeDataType>(int_dt)}); + { + std::unique_ptr list0_node = std::make_unique<ASTNode>(); + list0_node->m_data_type = double_dt; + data_node->emplace_back(std::move(list0_node)); + + std::unique_ptr list1_node = std::make_unique<ASTNode>(); + list1_node->m_data_type = unsigned_int_dt; + data_node->emplace_back(std::move(list1_node)); + + std::unique_ptr list2_node = std::make_unique<ASTNode>(); + list2_node->m_data_type = int_dt; + data_node->emplace_back(std::move(list2_node)); + } + REQUIRE_THROWS_WITH((ASTNodeNaturalConversionChecker{*data_node, + ASTNodeDataType::build<ASTNodeDataType::vector_t>(3)}), + "cannot convert list to R^3"); + } } SECTION("-> R") diff --git a/tests/test_AffectationProcessor.cpp b/tests/test_AffectationProcessor.cpp index 42c0514f963d5c452558bf6a8676c8d69395658d..2f8c4bb92067614fe1eb62d527fc1656301c2d87 100644 --- a/tests/test_AffectationProcessor.cpp +++ b/tests/test_AffectationProcessor.cpp @@ -108,21 +108,25 @@ TEST_CASE("AffectationProcessor", "[language]") CHECK_AFFECTATION_RESULT("let x : R^1, x = true;", "x", (TinyVector<1>{true})); CHECK_AFFECTATION_RESULT("let x : R^1, x = false;", "x", (TinyVector<1>{false})); CHECK_AFFECTATION_RESULT("let x : R^1, x = -2.3;", "x", (TinyVector<1>{-2.3})); + CHECK_AFFECTATION_RESULT("let x : R^1, x = [-1];", "x", (TinyVector<1>{-1})); + CHECK_AFFECTATION_RESULT("let x : R^1, x = [true];", "x", (TinyVector<1>{true})); + CHECK_AFFECTATION_RESULT("let x : R^1, x = [false];", "x", (TinyVector<1>{false})); + CHECK_AFFECTATION_RESULT("let x : R^1, x = [-2.3];", "x", (TinyVector<1>{-2.3})); CHECK_AFFECTATION_RESULT("let x : R^1, x = 0;", "x", (TinyVector<1>{zero})); } SECTION("R^2") { - CHECK_AFFECTATION_RESULT("let x : R^2, x = (-1, true);", "x", (TinyVector<2>{-1, true})); - CHECK_AFFECTATION_RESULT("let x : R^2, x = (true, false);", "x", (TinyVector<2>{true, false})); - CHECK_AFFECTATION_RESULT("let x : R^2, x = (-0.3, 12);", "x", (TinyVector<2>{-0.3, 12})); + CHECK_AFFECTATION_RESULT("let x : R^2, x = [-1, true];", "x", (TinyVector<2>{-1, true})); + CHECK_AFFECTATION_RESULT("let x : R^2, x = [true, false];", "x", (TinyVector<2>{true, false})); + CHECK_AFFECTATION_RESULT("let x : R^2, x = [-0.3, 12];", "x", (TinyVector<2>{-0.3, 12})); CHECK_AFFECTATION_RESULT("let x : R^2, x = 0;", "x", (TinyVector<2>{zero})); } SECTION("R^3") { - CHECK_AFFECTATION_RESULT("let x : R^3, x = (-1, true, false);", "x", (TinyVector<3>{-1, true, false})); - CHECK_AFFECTATION_RESULT("let x : R^3, x = (-0.3, 12, 6.2);", "x", (TinyVector<3>{-0.3, 12, 6.2})); + CHECK_AFFECTATION_RESULT("let x : R^3, x = [-1, true, false];", "x", (TinyVector<3>{-1, true, false})); + CHECK_AFFECTATION_RESULT("let x : R^3, x = [-0.3, 12, 6.2];", "x", (TinyVector<3>{-0.3, 12, 6.2})); CHECK_AFFECTATION_RESULT("let x : R^3; x = 0;", "x", (TinyVector<3>{zero})); } @@ -132,23 +136,27 @@ TEST_CASE("AffectationProcessor", "[language]") CHECK_AFFECTATION_RESULT("let x : R^1x1, x = true;", "x", (TinyMatrix<1>{true})); CHECK_AFFECTATION_RESULT("let x : R^1x1, x = false;", "x", (TinyMatrix<1>{false})); CHECK_AFFECTATION_RESULT("let x : R^1x1, x = -2.3;", "x", (TinyMatrix<1>{-2.3})); + CHECK_AFFECTATION_RESULT("let x : R^1x1, x = [[-1]];", "x", (TinyMatrix<1>{-1})); + CHECK_AFFECTATION_RESULT("let x : R^1x1, x = [[true]];", "x", (TinyMatrix<1>{true})); + CHECK_AFFECTATION_RESULT("let x : R^1x1, x = [[false]];", "x", (TinyMatrix<1>{false})); + CHECK_AFFECTATION_RESULT("let x : R^1x1, x = [[-2.3]];", "x", (TinyMatrix<1>{-2.3})); CHECK_AFFECTATION_RESULT("let x : R^1x1; x = 0;", "x", (TinyMatrix<1>{zero})); } SECTION("R^2x2") { - CHECK_AFFECTATION_RESULT("let x : R^2x2, x = (-1, true, 3, 5);", "x", (TinyMatrix<2>{-1, true, 3, 5})); - CHECK_AFFECTATION_RESULT("let x : R^2x2, x = (true, false, 1==2, 2==2);", "x", + CHECK_AFFECTATION_RESULT("let x : R^2x2, x = [[-1, true], [3, 5]];", "x", (TinyMatrix<2>{-1, true, 3, 5})); + CHECK_AFFECTATION_RESULT("let x : R^2x2, x = [[true, false], [1==2, 2==2]];", "x", (TinyMatrix<2>{true, false, false, true})); - CHECK_AFFECTATION_RESULT("let x : R^2x2, x = (-0.3, 12, 2, -3);", "x", (TinyMatrix<2>{-0.3, 12, 2, -3})); + CHECK_AFFECTATION_RESULT("let x : R^2x2, x = [[-0.3, 12],[2, -3]];", "x", (TinyMatrix<2>{-0.3, 12, 2, -3})); CHECK_AFFECTATION_RESULT("let x : R^2x2, x = 0;", "x", (TinyMatrix<2>{zero})); } SECTION("R^3x3") { - CHECK_AFFECTATION_RESULT("let x : R^3x3, x = (-1, true, false, 2, 3.1, 4, -1, true, 2);", "x", + CHECK_AFFECTATION_RESULT("let x : R^3x3, x = [[-1, true, false], [2, 3.1, 4], [-1, true, 2]];", "x", (TinyMatrix<3>{-1, true, false, 2, 3.1, 4, -1, true, 2})); - CHECK_AFFECTATION_RESULT("let x : R^3x3, x = (-0.3, 12, 6.2, 7.1, 3.2, 2-3, 2, -1, 0);", "x", + CHECK_AFFECTATION_RESULT("let x : R^3x3, x = [[-0.3, 12, 6.2], [7.1, 3.2, 2-3], [2, -1, 0]];", "x", (TinyMatrix<3>{-0.3, 12, 6.2, 7.1, 3.2, 2 - 3, 2, -1, 0})); CHECK_AFFECTATION_RESULT("let x : R^3x3, x = 0;", "x", (TinyMatrix<3>{zero})); } @@ -189,13 +197,13 @@ TEST_CASE("AffectationProcessor", "[language]") SECTION("R^2") { - CHECK_AFFECTATION_RESULT("let x : R^2, x = (-1, true); let y : R^2, y = (1,3); x += y;", "x", + CHECK_AFFECTATION_RESULT("let x : R^2, x = [-1, true]; x += [1,3];", "x", (TinyVector<2>{-1, true} + TinyVector<2>{1, 3})); } SECTION("R^3") { - CHECK_AFFECTATION_RESULT("let x : R^3, x = (-1, true, false); let y : R^3, y = (1,2,3); x += y;", "x", + CHECK_AFFECTATION_RESULT("let x : R^3, x = [-1, true, false]; x += [1,2,3];", "x", (TinyVector<3>{-1, true, false} + TinyVector<3>{1, 2, 3})); } } @@ -229,19 +237,18 @@ TEST_CASE("AffectationProcessor", "[language]") SECTION("R^1") { - CHECK_AFFECTATION_RESULT("let x : R^1, x = -1; let y : R^1, y = 1; x -= y;", "x", - (TinyVector<1>{-1} - TinyVector<1>{1})); + CHECK_AFFECTATION_RESULT("let x : R^1, x = [-1]; x -= [1];", "x", (TinyVector<1>{-1} - TinyVector<1>{1})); } SECTION("R^2") { - CHECK_AFFECTATION_RESULT("let x : R^2, x = (-1, true); let y : R^2, y = (1,3); x -= y;", "x", + CHECK_AFFECTATION_RESULT("let x : R^2, x = [-1, true]; x -= [1,3];", "x", (TinyVector<2>{-1, true} - TinyVector<2>{1, 3})); } SECTION("R^3") { - CHECK_AFFECTATION_RESULT("let x : R^3, x = (-1, true, false); let y : R^3, y = (1,2,3); x-=y;", "x", + CHECK_AFFECTATION_RESULT("let x : R^3, x = [-1, true, false]; x-=[1,2,3];", "x", (TinyVector<3>{-1, true, false} - TinyVector<3>{1, 2, 3})); } } @@ -280,13 +287,13 @@ TEST_CASE("AffectationProcessor", "[language]") SECTION("R^2") { - CHECK_AFFECTATION_RESULT("let x : R^2, x = (-1, true); x *= 3;", "x", + CHECK_AFFECTATION_RESULT("let x : R^2, x = [-1, true]; x *= 3;", "x", (TinyVector<2>{TinyVector<2>{-1, true} *= 3})); } SECTION("R^3") { - CHECK_AFFECTATION_RESULT("let x : R^3, x = (-1, true, false); x*=5.2;", "x", + CHECK_AFFECTATION_RESULT("let x : R^3, x = [-1, true, false]; x*=5.2;", "x", (TinyVector<3>{TinyVector<3>{-1, true, false} *= 5.2})); } @@ -297,13 +304,13 @@ TEST_CASE("AffectationProcessor", "[language]") SECTION("R^2x2") { - CHECK_AFFECTATION_RESULT("let x : R^2x2, x = (-1, true, 3, 6); x *= 3;", "x", + CHECK_AFFECTATION_RESULT("let x : R^2x2, x = [[-1, true], [3, 6]]; x *= 3;", "x", (TinyMatrix<2>{TinyMatrix<2>{-1, true, 3, 6} *= 3})); } SECTION("R^3x3") { - CHECK_AFFECTATION_RESULT("let x : R^3x3, x = (-1, true, false, 2, -3, 11, 5, -4, 2); x*=5.2;", "x", + CHECK_AFFECTATION_RESULT("let x : R^3x3, x = [[-1, true, false], [2, -3, 11], [5, -4, 2]]; x*=5.2;", "x", (TinyMatrix<3>{TinyMatrix<3>{-1, true, false, 2, -3, 11, 5, -4, 2} *= 5.2})); } } @@ -401,9 +408,9 @@ TEST_CASE("AffectationProcessor", "[language]") CHECK_AFFECTATION_THROWS_WITH("let x : R^1; let y : R^1x1, y = 1; x = y;", "undefined affectation type: R^1 = R^1x1"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^2; let y : R^2x2, y = (1,2,4,4); x = y;", + CHECK_AFFECTATION_THROWS_WITH("let x : R^2; let y : R^2x2, y = [[1,2],[4,4]]; x = y;", "undefined affectation type: R^2 = R^2x2"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^3; let y : R^3x3, y = (1,2,3,4,5,6,7,8,9); x = y;", + CHECK_AFFECTATION_THROWS_WITH("let x : R^3; let y : R^3x3, y = [[1,2,3],[4,5,6],[7,8,9]]; x = y;", "undefined affectation type: R^3 = R^3x3"); CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = 4;", "invalid integral value (0 is the solely valid value)"); @@ -425,14 +432,8 @@ TEST_CASE("AffectationProcessor", "[language]") "undefined affectation type: R^2 = R^3"); CHECK_AFFECTATION_THROWS_WITH("let x : R^1, x = (1,2);", "undefined affectation type: R^1 = list"); - - CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = (1,2,3);", - "incompatible dimensions in affectation: expecting 2, but provided 3"); - - CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2);", - "incompatible dimensions in affectation: expecting 3, but provided 2"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2,3,4);", - "incompatible dimensions in affectation: expecting 3, but provided 4"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = (1,2);", "undefined affectation type: R^2 = list"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2,3);", "undefined affectation type: R^3 = list"); } SECTION("-> R^n (affectation of components is forbidden)") @@ -478,11 +479,9 @@ TEST_CASE("AffectationProcessor", "[language]") CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = 3.2;", "undefined affectation type: R^2 = R"); CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 2.3;", "undefined affectation type: R^3 = R"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^1; let y : R^1x1, y = 1; x = y;", - "undefined affectation type: R^1 = R^1x1"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^2; let y : R^2x2, y = (1,2,4,4); x = y;", - "undefined affectation type: R^2 = R^2x2"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^3; let y : R^3x3, y = (1,2,3,4,5,6,7,8,9); x = y;", + CHECK_AFFECTATION_THROWS_WITH("let x : R^1; x = [[1]];", "undefined affectation type: R^1 = R^1x1"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2; x = [[1,2],[4,4]];", "undefined affectation type: R^2 = R^2x2"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3; x = [[1,2,3],[4,5,6],[7,8,9]];", "undefined affectation type: R^3 = R^3x3"); CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = 4;", "invalid integral value (0 is the solely valid value)"); @@ -504,14 +503,8 @@ TEST_CASE("AffectationProcessor", "[language]") "undefined affectation type: R^2 = R^3"); CHECK_AFFECTATION_THROWS_WITH("let x : R^1, x = (1,2);", "undefined affectation type: R^1 = list"); - - CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = (1,2,3);", - "incompatible dimensions in affectation: expecting 2, but provided 3"); - - CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2);", - "incompatible dimensions in affectation: expecting 3, but provided 2"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2,3,4);", - "incompatible dimensions in affectation: expecting 3, but provided 4"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = (1,2);", "undefined affectation type: R^2 = list"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2,3);", "undefined affectation type: R^3 = list"); } SECTION("-> R^nxn") @@ -557,12 +550,9 @@ TEST_CASE("AffectationProcessor", "[language]") CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 3.2;", "undefined affectation type: R^2x2 = R"); CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 2.3;", "undefined affectation type: R^3x3 = R"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1; let y : R^1, y = 1; x = y;", - "undefined affectation type: R^1x1 = R^1"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2; let y : R^2, y = (1,2); x = y;", - "undefined affectation type: R^2x2 = R^2"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3; let y : R^3, y = (1,2,3); x = y;", - "undefined affectation type: R^3x3 = R^3"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1; x = [1];", "undefined affectation type: R^1x1 = R^1"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2; x = [1,2];", "undefined affectation type: R^2x2 = R^2"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3; x = [1,2,3];", "undefined affectation type: R^3x3 = R^3"); CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2; x = 3.2;", "undefined affectation type: R^2x2 = R"); CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3; x = 2.3;", "undefined affectation type: R^3x3 = R"); @@ -570,10 +560,8 @@ TEST_CASE("AffectationProcessor", "[language]") CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 4;", "invalid integral value (0 is the solely valid value)"); CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 3;", "invalid integral value (0 is the solely valid value)"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1, x = 0; let y : R^2x2, y = x;", - "undefined affectation type: R^2x2 = R^1x1"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1, x = 0; let y : R^3x3, y = x;", - "undefined affectation type: R^3x3 = R^1x1"); + CHECK_AFFECTATION_THROWS_WITH("let y : R^2x2, y = [[0]];", "undefined affectation type: R^2x2 = R^1x1"); + CHECK_AFFECTATION_THROWS_WITH("let y : R^3x3, y = [[0]];", "undefined affectation type: R^3x3 = R^1x1"); CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 0; let y : R^1x1, y = x;", "undefined affectation type: R^1x1 = R^2x2"); @@ -586,16 +574,9 @@ TEST_CASE("AffectationProcessor", "[language]") "undefined affectation type: R^2x2 = R^3x3"); CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1, x = (1,2);", "undefined affectation type: R^1x1 = list"); - - CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = (1,2,3);", - "incompatible dimensions in affectation: expecting 4, but provided 3"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = (1,2,3,4,5);", - "incompatible dimensions in affectation: expecting 4, but provided 5"); - - CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = (1,2,3,4,5,6,7,8);", - "incompatible dimensions in affectation: expecting 9, but provided 8"); - CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = (1,2,3,4,5,6,7,8,9,10);", - "incompatible dimensions in affectation: expecting 9, but provided 10"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = (1,2,3,4);", "undefined affectation type: R^2x2 = list"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = (1,2,3,4,5,6,7,8,9);", + "undefined affectation type: R^3x3 = list"); } } } diff --git a/tests/test_AffectationToStringProcessor.cpp b/tests/test_AffectationToStringProcessor.cpp index 01c7ba7b938945dc9f929f602a3fe071b052379c..6b20e7ca84e7c7f80654ed6a053a34068df83889 100644 --- a/tests/test_AffectationToStringProcessor.cpp +++ b/tests/test_AffectationToStringProcessor.cpp @@ -51,54 +51,38 @@ TEST_CASE("ASTAffectationToStringProcessor", "[language]") { + auto stringify = [](auto&& value) { + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); + }; + SECTION("Affectations") { CHECK_AFFECTATION_RESULT(R"(let s : string; s = "foo";)", "s", std::string("foo")); - CHECK_AFFECTATION_RESULT(R"(let n : N, n = 2; let s : string; s = n;)", "s", std::to_string(2ul)); - CHECK_AFFECTATION_RESULT(R"(let s : string; s = -1;)", "s", std::to_string(-1l)); - CHECK_AFFECTATION_RESULT(R"(let s : string; s = true;)", "s", std::to_string(true)); - CHECK_AFFECTATION_RESULT(R"(let s : string; s = 2.3;)", "s", std::to_string(2.3)); - { - std::ostringstream os; - os << TinyVector<1>{13}; - CHECK_AFFECTATION_RESULT(R"(let x : R^1, x = 13; let s : string; s = x;)", "s", os.str()); - } - { - std::ostringstream os; - os << TinyVector<2>{2, 3}; - CHECK_AFFECTATION_RESULT(R"(let x : R^2, x = (2,3); let s : string; s = x;)", "s", os.str()); - } - { - std::ostringstream os; - os << TinyVector<3>{1, 2, 3}; - CHECK_AFFECTATION_RESULT(R"(let x : R^3, x = (1,2,3); let s : string; s = x;)", "s", os.str()); - } + CHECK_AFFECTATION_RESULT(R"(let n : N, n = 2; let s : string; s = n;)", "s", stringify(2ul)); + CHECK_AFFECTATION_RESULT(R"(let s : string; s = -1;)", "s", stringify(-1l)); + CHECK_AFFECTATION_RESULT(R"(let s : string; s = true;)", "s", stringify(true)); + CHECK_AFFECTATION_RESULT(R"(let s : string; s = 2.3;)", "s", stringify(2.3)); + CHECK_AFFECTATION_RESULT(R"(let x : R^1, x = 13; let s : string; s = x;)", "s", stringify(TinyVector<1>{13})); + CHECK_AFFECTATION_RESULT(R"(let x : R^2, x = [2,3]; let s : string; s = x;)", "s", stringify(TinyVector<2>{2, 3})); + CHECK_AFFECTATION_RESULT(R"(let x : R^3, x = [1,2,3]; let s : string; s = x;)", "s", + stringify(TinyVector<3>{1, 2, 3})); } SECTION("+=") { CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += "bar";)", "s", std::string("foobar")); CHECK_AFFECTATION_RESULT(R"(let n : N, n = 2; let s : string, s = "foo"; s += n;)", "s", - (std::string("foo") + std::to_string(2ul))); - CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += -1;)", "s", (std::string("foo") + std::to_string(-1l))); - CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += true;)", "s", - (std::string("foo") + std::to_string(true))); - CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += 2.3;)", "s", - (std::string("foo") + std::to_string(2.3))); - { - std::ostringstream os; - os << "foo" << TinyVector<1>{13}; - CHECK_AFFECTATION_RESULT(R"(let x : R^1, x = 13; let s : string, s="foo"; s += x;)", "s", os.str()); - } - { - std::ostringstream os; - os << "foo" << TinyVector<2>{2, 3}; - CHECK_AFFECTATION_RESULT(R"(let x : R^2, x = (2,3); let s : string, s="foo"; s += x;)", "s", os.str()); - } - { - std::ostringstream os; - os << "foo" << TinyVector<3>{1, 2, 3}; - CHECK_AFFECTATION_RESULT(R"(let x : R^3, x = (1,2,3); let s : string, s="foo"; s += x;)", "s", os.str()); - } + (std::string("foo") + stringify(2ul))); + CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += -1;)", "s", (std::string("foo") + stringify(-1l))); + CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += true;)", "s", (std::string("foo") + stringify(true))); + CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += 2.3;)", "s", (std::string("foo") + stringify(2.3))); + CHECK_AFFECTATION_RESULT(R"(let x : R^1, x = 13; let s : string, s="foo"; s += x;)", "s", + (std::string("foo") + stringify(TinyVector<1>{13}))); + CHECK_AFFECTATION_RESULT(R"(let x : R^2, x = [2,3]; let s : string, s="foo"; s += x;)", "s", + (std::string("foo") + stringify(TinyVector<2>{2, 3}))); + CHECK_AFFECTATION_RESULT(R"(let x : R^3, x = [1,2,3]; let s : string, s="foo"; s += x;)", "s", + (std::string("foo") + stringify(TinyVector<3>{1, 2, 3}))); } } diff --git a/tests/test_AffectationToTupleProcessor.cpp b/tests/test_AffectationToTupleProcessor.cpp index d832ac2739cb6b8417e6dfd3818e11252639b7b4..47913987007fb5860308530532572625efcf4b5d 100644 --- a/tests/test_AffectationToTupleProcessor.cpp +++ b/tests/test_AffectationToTupleProcessor.cpp @@ -51,6 +51,12 @@ TEST_CASE("ASTAffectationToTupleProcessor", "[language]") { + auto stringify = [](auto&& value) { + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); + }; + SECTION("Affectations from value") { CHECK_AFFECTATION_RESULT(R"( @@ -66,36 +72,24 @@ let s :(R); s = 2; CHECK_AFFECTATION_RESULT(R"( let s :(string); s = 2.; )", - "s", (std::vector<std::string>{std::to_string(2.)})); - - const std::string x_string = []() -> std::string { - std::ostringstream os; - os << TinyVector<3, double>{1, 2, 3}; - return os.str(); - }(); + "s", (std::vector<std::string>{stringify(2.)})); CHECK_AFFECTATION_RESULT(R"( -let x :R^3, x = (1,2,3); +let x :R^3, x = [1,2,3]; let s :(string); s = x; )", - "s", (std::vector<std::string>{x_string})); + "s", (std::vector<std::string>{stringify(TinyVector<3, double>{1, 2, 3})})); CHECK_AFFECTATION_RESULT(R"( let s :(R^1); s = 1.3; )", "s", (std::vector<TinyVector<1>>{TinyVector<1>{1.3}})); - const std::string A_string = []() -> std::string { - std::ostringstream os; - os << TinyMatrix<2>{1, 2, 3, 4}; - return os.str(); - }(); - CHECK_AFFECTATION_RESULT(R"( -let A :R^2x2, A = (1,2,3,4); +let A :R^2x2, A = [[1,2],[3,4]]; let s :(string); s = A; )", - "s", (std::vector<std::string>{A_string})); + "s", (std::vector<std::string>{stringify(TinyMatrix<2>{1, 2, 3, 4})})); CHECK_AFFECTATION_RESULT(R"( let s :(R^1x1); s = 1.3; @@ -113,34 +107,29 @@ let t :(R); t = (2.,3); CHECK_AFFECTATION_RESULT(R"( let s :(string); s = (2.,3); )", - "s", (std::vector<std::string>{std::to_string(2.), std::to_string(3)})); + "s", (std::vector<std::string>{stringify(2.), stringify(3)})); CHECK_AFFECTATION_RESULT(R"( let s :(string); s = (2.,3,"foo"); )", - "s", - (std::vector<std::string>{std::to_string(2.), std::to_string(3), std::string{"foo"}})); - - const std::string x_string = []() -> std::string { - std::ostringstream os; - os << TinyVector<2, double>{1, 2}; - return os.str(); - }(); + "s", (std::vector<std::string>{stringify(2.), stringify(3), std::string("foo")})); CHECK_AFFECTATION_RESULT(R"( -let x : R^2, x = (1,2); +let x : R^2, x = [1,2]; let s : (string); s = (2.,3, x); )", - "s", (std::vector<std::string>{std::to_string(2.), std::to_string(3), x_string})); + "s", + (std::vector<std::string>{stringify(2.), stringify(3), + stringify(TinyVector<2, double>{1, 2})})); CHECK_AFFECTATION_RESULT(R"( -let x : R^2, x = (1,2); +let x : R^2, x = [1,2]; let t :(R^2); t = (x,0); )", "t", (std::vector<TinyVector<2>>{TinyVector<2>{1, 2}, TinyVector<2>{0, 0}})); CHECK_AFFECTATION_RESULT(R"( -let t :(R^2); t = ((1,2),0); +let t :(R^2); t = ([1,2],0); )", "t", (std::vector<TinyVector<2>>{TinyVector<2>{1, 2}, TinyVector<2>{0, 0}})); @@ -160,26 +149,22 @@ let t :(R^1); t = (x,2); )", "t", (std::vector<TinyVector<1>>{TinyVector<1>{1}, TinyVector<1>{2}})); - const std::string A_string = []() -> std::string { - std::ostringstream os; - os << TinyMatrix<2>{1, 2, 3, 4}; - return os.str(); - }(); - CHECK_AFFECTATION_RESULT(R"( -let A : R^2x2, A = (1,2,3,4); +let A : R^2x2, A = [[1,2],[3,4]]; let s : (string); s = (2.,3, A); )", - "s", (std::vector<std::string>{std::to_string(2.), std::to_string(3), A_string})); + "s", + (std::vector<std::string>{stringify(2.), stringify(3), + stringify(TinyMatrix<2>{1, 2, 3, 4})})); CHECK_AFFECTATION_RESULT(R"( -let A : R^2x2, A = (1,2,3,4); +let A : R^2x2, A = [[1,2],[3,4]]; let t :(R^2x2); t = (A,0); )", "t", (std::vector<TinyMatrix<2>>{TinyMatrix<2>{1, 2, 3, 4}, TinyMatrix<2>{0, 0, 0, 0}})); CHECK_AFFECTATION_RESULT(R"( -let t :(R^2x2); t = ((1,2,3,4),0); +let t :(R^2x2); t = ([[1,2],[3,4]],0); )", "t", (std::vector<TinyMatrix<2>>{TinyMatrix<2>{1, 2, 3, 4}, TinyMatrix<2>{0, 0, 0, 0}})); @@ -202,36 +187,23 @@ let t :(R^1x1); t = (x,2); SECTION("Affectations from tuple") { - const std::string x_string = []() -> std::string { - std::ostringstream os; - os << TinyVector<3, double>{1, 2, 3}; - return os.str(); - }(); - CHECK_AFFECTATION_RESULT(R"( -let x :(R^3), x = ((1,2,3)); +let x :(R^3), x = [1,2,3]; let s :(string); s = x; )", - "s", (std::vector<std::string>{x_string})); - - const std::string A_string = []() -> std::string { - std::ostringstream os; - os << TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9}; - return os.str(); - }(); + "s", (std::vector<std::string>{stringify(TinyVector<3, double>{1, 2, 3})})); CHECK_AFFECTATION_RESULT(R"( -let A :(R^3x3), A = ((1,2,3,4,5,6,7,8,9)); +let A :(R^3x3), A = ([[1,2,3],[4,5,6],[7,8,9]]); let s :(string); s = A; )", - "s", (std::vector<std::string>{A_string})); + "s", (std::vector<std::string>{stringify(TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9})})); CHECK_AFFECTATION_RESULT(R"( let x :(R), x = (1,2,3); let s :(string); s = x; )", - "s", - (std::vector<std::string>{std::to_string(1.), std::to_string(2.), std::to_string(3.)})); + "s", (std::vector<std::string>{stringify(1.), stringify(2.), stringify(3.)})); CHECK_AFFECTATION_RESULT(R"( let n :(N), n = (1,2,3); diff --git a/tests/test_ArraySubscriptProcessor.cpp b/tests/test_ArraySubscriptProcessor.cpp index cac519c63447a307864a1a8940dfbf3427388317..5b1ac6c1cf0a00f56a4da806b86bb4124c42b317 100644 --- a/tests/test_ArraySubscriptProcessor.cpp +++ b/tests/test_ArraySubscriptProcessor.cpp @@ -88,7 +88,7 @@ let x0: R, x0 = x[0]; SECTION("R^2 component access") { std::string_view data = R"( -let x : R^2, x = (1,2); +let x : R^2, x = [1,2]; let x0: R, x0 = x[0]; let x1: R, x1 = x[1]; )"; @@ -99,7 +99,7 @@ let x1: R, x1 = x[1]; SECTION("R^3 component access") { std::string_view data = R"( -let x : R^3, x = (1,2,3); +let x : R^3, x = [1,2,3]; let x0 : R, x0 = x[0]; let x1 : R, x1 = x[1]; let x2 : R, x2 = x[2]; @@ -121,7 +121,7 @@ let x00: R, x00 = x[0,0]; SECTION("R^2x2 component access") { std::string_view data = R"( -let x : R^2x2, x = (1,2,3,4); +let x : R^2x2, x = [[1,2],[3,4]]; let x00: R, x00 = x[0,0]; let x01: R, x01 = x[0,1]; let x10: R, x10 = x[1,0]; @@ -136,7 +136,7 @@ let x11: R, x11 = x[1,1]; SECTION("R^3x3 component access") { std::string_view data = R"( -let x : R^3x3, x = (1,2,3,4,5,6,7,8,9); +let x : R^3x3, x = [[1,2,3],[4,5,6],[7,8,9]]; let x00 : R, x00 = x[0,0]; let x01 : R, x01 = x[0,1]; let x02 : R, x02 = x[0,2]; @@ -161,10 +161,10 @@ let x22 : R, x22 = x[2,2]; SECTION("R^d component access from integer expression") { std::string_view data = R"( -let x : R^3, x = (1,2,3); +let x : R^3, x = [1,2,3]; let x0: R, x0 = x[3-2-1]; -let y : R^2, y = (2,7); +let y : R^2, y = [2,7]; let y1: R, y1 = y[2/2]; let z : R^1, z = 8; @@ -178,10 +178,10 @@ let z0: R, z0 = z[(2-2)*1]; SECTION("R^dxd component access from integer expression") { std::string_view data = R"( -let x : R^3x3, x = (1,2,3,4,5,6,7,8,9); +let x : R^3x3, x = [[1,2,3],[4,5,6],[7,8,9]]; let x01: R, x01 = x[3-2-1,2+3-4]; -let y : R^2x2, y = (2,7,6,-2); +let y : R^2x2, y = [[2,7],[6,-2]]; let y11: R, y11 = y[2/2, 3/1-2]; let z : R^1x1, z = 8; @@ -197,7 +197,7 @@ let z00: R, z00 = z[(2-2)*1, (3-1)*2-4]; SECTION("R index type") { std::string_view data = R"( -let x : R^3, x = (1,2,3); +let x : R^3, x = [1,2,3]; let x0: R, x0 = x[2.3]; )"; @@ -207,7 +207,7 @@ let x0: R, x0 = x[2.3]; SECTION("string index type") { std::string_view data = R"( -let x : R^3, x = (1,2,3); +let x : R^3, x = [1,2,3]; let x0: R, x0 = x["foo"]; )"; @@ -217,7 +217,7 @@ let x0: R, x0 = x["foo"]; SECTION("R^d index type") { std::string_view data = R"( -let x : R^3, x = (1,2,3); +let x : R^3, x = [1,2,3]; let x0: R, x0 = x[x]; )"; diff --git a/tests/test_BinaryExpressionProcessor_shift.cpp b/tests/test_BinaryExpressionProcessor_shift.cpp index 127e90161416444f652c16206ddbd8c4f97d5718..010201d122ea543b828a1de7060700aa78313593 100644 --- a/tests/test_BinaryExpressionProcessor_shift.cpp +++ b/tests/test_BinaryExpressionProcessor_shift.cpp @@ -30,12 +30,12 @@ fout << createSocketServer(0) << "\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 << "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";)"; @@ -130,22 +130,22 @@ fout << createSocketServer(0) << "\n";)"; REQUIRE(std::string_view(line) == "(2.3, 4)"); fin.getline(line, 1023); - REQUIRE(std::string_view(line) == "((2.3), (4))"); + REQUIRE(std::string_view(line) == "([2.3], [4])"); fin.getline(line, 1023); - REQUIRE(std::string_view(line) == "((2.3,4), (3,2))"); + 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))"); + REQUIRE(std::string_view(line) == "([2.3,4,-1], [3,2,1])"); fin.getline(line, 1023); - REQUIRE(std::string_view(line) == "([(2.3)], [(4)])"); + 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)])"); + 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)])"); + 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)"); diff --git a/tests/test_BuiltinFunctionEmbedderUtils.cpp b/tests/test_BuiltinFunctionEmbedderUtils.cpp index da2fbdd1dc8466377621b077af3ef790ec15e24e..ebb0195dc01ed45a25085b8f3150d71de08005ac 100644 --- a/tests/test_BuiltinFunctionEmbedderUtils.cpp +++ b/tests/test_BuiltinFunctionEmbedderUtils.cpp @@ -349,7 +349,7 @@ foo(3,0); SECTION("builtin function R*R^2 -> R^2 (R^2 from list)") { std::string_view data = R"( -foo(3.1,(1,2.3)); +foo(3.1,[1,2.3]); )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -431,7 +431,7 @@ foo(3,0); SECTION("builtin function R*R^3 -> R^2 (R^3 from list)") { std::string_view data = R"( -foo(3.1,(1,2.3,4)); +foo(3.1,[1,2.3,4]); )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -621,7 +621,7 @@ foo(3,0); SECTION("builtin function R*R^2x2 -> R^2x2 (R^2x2 from list)") { std::string_view data = R"( -foo(3.1,(1,2.3,0,3)); +foo(3.1,[[1,2.3],[0,3]]); )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -704,7 +704,7 @@ foo(3,0); SECTION("builtin function R*R^3x3 -> R^2x2 (R^3x3 from list)") { std::string_view data = R"( -foo(3.1,(1, 2.3, 4, 0.3, 2.5, 4.6, 2.7, 8.1, -9)); +foo(3.1,[[1, 2.3, 4], [0.3, 2.5, 4.6], [2.7, 8.1, -9]]); )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1009,29 +1009,6 @@ foo(0); REQUIRE(function_embedder->getParameterDataTypes()[0].contentType().dimension() == 2); } - SECTION("builtin function (R^2x2...) -> N (from castable list)") - { - std::string_view data = R"( -foo((1,2,3)); -)"; - - TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; - auto root_node = ASTBuilder::build(input); - register_functions(root_node, - FunctionList{std::make_pair("foo", std::make_shared<BuiltinFunctionEmbedder<uint64_t( - const std::vector<TinyMatrix<2>>&)>>( - [](const std::vector<TinyMatrix<2>>& x) -> uint64_t { - return x.size(); - }))}); - - auto function_embedder = getBuiltinFunctionEmbedder(*root_node->children[0]); - REQUIRE(function_embedder->getReturnDataType() == ASTNodeDataType::unsigned_int_t); - REQUIRE(function_embedder->getParameterDataTypes().size() == 1); - REQUIRE(function_embedder->getParameterDataTypes()[0] == ASTNodeDataType::tuple_t); - REQUIRE(function_embedder->getParameterDataTypes()[0].contentType() == ASTNodeDataType::matrix_t); - REQUIRE(function_embedder->getParameterDataTypes()[0].contentType().numberOfRows() == 2); - } - SECTION("builtin function (R^2x2...) -> N (from 0)") { std::string_view data = R"( @@ -1126,10 +1103,10 @@ foo(0); REQUIRE(function_embedder->getParameterDataTypes()[0].contentType().dimension() == 3); } - SECTION("builtin function (R^3x3...) -> N (from castable list)") + SECTION("builtin function (R^3x3...) -> N (from 0)") { std::string_view data = R"( -foo((1,2,3)); +foo(0); )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1149,10 +1126,11 @@ foo((1,2,3)); REQUIRE(function_embedder->getParameterDataTypes()[0].contentType().numberOfRows() == 3); } - SECTION("builtin function (R^3x3...) -> N (from 0)") + SECTION("builtin function (R^3x3...) -> N (from list)") { std::string_view data = R"( -foo(0); +let x:R^3x3; +foo((x,2*x)); )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1170,68 +1148,89 @@ foo(0); REQUIRE(function_embedder->getParameterDataTypes()[0] == ASTNodeDataType::tuple_t); REQUIRE(function_embedder->getParameterDataTypes()[0].contentType() == ASTNodeDataType::matrix_t); REQUIRE(function_embedder->getParameterDataTypes()[0].contentType().numberOfRows() == 3); + REQUIRE(function_embedder->getParameterDataTypes()[0].contentType().numberOfColumns() == 3); } + } - SECTION("builtin function (R^3x3...) -> N (from list)") + SECTION("complete case") + { + SECTION("tuple first") { std::string_view data = R"( let x:R^3x3; -foo((x,2*x)); +foo((x,2*x), 1, "bar", [2,3]); )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto root_node = ASTBuilder::build(input); register_functions(root_node, - FunctionList{std::make_pair("foo", std::make_shared<BuiltinFunctionEmbedder<uint64_t( - const std::vector<TinyMatrix<3>>&)>>( - [](const std::vector<TinyMatrix<3>>& x) -> uint64_t { - return x.size(); - }))}); + FunctionList{ + std::make_pair("foo", + std::make_shared<BuiltinFunctionEmbedder< + std::tuple<uint64_t, double, std::string>(const std::vector<TinyMatrix<3>>&, + const double&, const std::string&, + const TinyVector<2>&)>>( + [](const std::vector<TinyMatrix<3>>& x, const double& a, + const std::string& s, + const TinyVector<2>& y) -> std::tuple<uint64_t, double, std::string> { + return std::make_tuple(x.size(), a * y[0] + y[1], s + "_foo"); + }))}); auto function_embedder = getBuiltinFunctionEmbedder(*root_node->children[0]); - REQUIRE(function_embedder->getReturnDataType() == ASTNodeDataType::unsigned_int_t); - REQUIRE(function_embedder->getParameterDataTypes().size() == 1); + REQUIRE(function_embedder->getReturnDataType() == ASTNodeDataType::list_t); + REQUIRE(function_embedder->getReturnDataType().contentTypeList().size() == 3); + REQUIRE(*function_embedder->getReturnDataType().contentTypeList()[0] == ASTNodeDataType::unsigned_int_t); + REQUIRE(*function_embedder->getReturnDataType().contentTypeList()[1] == ASTNodeDataType::double_t); + REQUIRE(*function_embedder->getReturnDataType().contentTypeList()[2] == ASTNodeDataType::string_t); + REQUIRE(function_embedder->getParameterDataTypes().size() == 4); REQUIRE(function_embedder->getParameterDataTypes()[0] == ASTNodeDataType::tuple_t); REQUIRE(function_embedder->getParameterDataTypes()[0].contentType() == ASTNodeDataType::matrix_t); REQUIRE(function_embedder->getParameterDataTypes()[0].contentType().numberOfRows() == 3); + REQUIRE(function_embedder->getParameterDataTypes()[0].contentType().numberOfColumns() == 3); + REQUIRE(function_embedder->getParameterDataTypes()[1] == ASTNodeDataType::double_t); + REQUIRE(function_embedder->getParameterDataTypes()[2] == ASTNodeDataType::string_t); + REQUIRE(function_embedder->getParameterDataTypes()[3] == ASTNodeDataType::vector_t); + REQUIRE(function_embedder->getParameterDataTypes()[3].dimension() == 2); } - } - SECTION("complete case") - { - std::string_view data = R"( + SECTION("tuple not first") + { + std::string_view data = R"( let x:R^3x3; -foo(1, "bar", (x,2*x), (2,3)); +foo(1, "bar", (x,2*x), [2,3]); )"; - TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; - auto root_node = ASTBuilder::build(input); - register_functions(root_node, - FunctionList{ - std::make_pair("foo", - std::make_shared<BuiltinFunctionEmbedder< - std::tuple<uint64_t, double, std::string>(const double&, const std::string&, - const std::vector<TinyMatrix<3>>&, - const TinyVector<2>&)>>( - [](const double& a, const std::string& s, const std::vector<TinyMatrix<3>>& x, - const TinyVector<2>& y) -> std::tuple<uint64_t, double, std::string> { - return std::make_tuple(x.size(), a * y[0] + y[1], s + "_foo"); - }))}); - - auto function_embedder = getBuiltinFunctionEmbedder(*root_node->children[0]); - REQUIRE(function_embedder->getReturnDataType() == ASTNodeDataType::list_t); - REQUIRE(function_embedder->getReturnDataType().contentTypeList().size() == 3); - REQUIRE(*function_embedder->getReturnDataType().contentTypeList()[0] == ASTNodeDataType::unsigned_int_t); - REQUIRE(*function_embedder->getReturnDataType().contentTypeList()[1] == ASTNodeDataType::double_t); - REQUIRE(*function_embedder->getReturnDataType().contentTypeList()[2] == ASTNodeDataType::string_t); - REQUIRE(function_embedder->getParameterDataTypes().size() == 4); - REQUIRE(function_embedder->getParameterDataTypes()[0] == ASTNodeDataType::double_t); - REQUIRE(function_embedder->getParameterDataTypes()[1] == ASTNodeDataType::string_t); - REQUIRE(function_embedder->getParameterDataTypes()[2] == ASTNodeDataType::tuple_t); - REQUIRE(function_embedder->getParameterDataTypes()[2].contentType() == ASTNodeDataType::matrix_t); - REQUIRE(function_embedder->getParameterDataTypes()[2].contentType().numberOfRows() == 3); - REQUIRE(function_embedder->getParameterDataTypes()[3] == ASTNodeDataType::vector_t); - REQUIRE(function_embedder->getParameterDataTypes()[3].dimension() == 2); + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; + auto root_node = ASTBuilder::build(input); + register_functions(root_node, + FunctionList{ + std::make_pair("foo", + std::make_shared<BuiltinFunctionEmbedder< + std::tuple<uint64_t, double, std::string>(const double&, const std::string&, + const std::vector<TinyMatrix<3>>&, + const TinyVector<2>&)>>( + [](const double& a, const std::string& s, + const std::vector<TinyMatrix<3>>& x, + const TinyVector<2>& y) -> std::tuple<uint64_t, double, std::string> { + return std::make_tuple(x.size(), a * y[0] + y[1], s + "_foo"); + }))}); + + auto function_embedder = getBuiltinFunctionEmbedder(*root_node->children[0]); + REQUIRE(function_embedder->getReturnDataType() == ASTNodeDataType::list_t); + REQUIRE(function_embedder->getReturnDataType().contentTypeList().size() == 3); + REQUIRE(*function_embedder->getReturnDataType().contentTypeList()[0] == ASTNodeDataType::unsigned_int_t); + REQUIRE(*function_embedder->getReturnDataType().contentTypeList()[1] == ASTNodeDataType::double_t); + REQUIRE(*function_embedder->getReturnDataType().contentTypeList()[2] == ASTNodeDataType::string_t); + REQUIRE(function_embedder->getParameterDataTypes().size() == 4); + REQUIRE(function_embedder->getParameterDataTypes()[0] == ASTNodeDataType::double_t); + REQUIRE(function_embedder->getParameterDataTypes()[1] == ASTNodeDataType::string_t); + REQUIRE(function_embedder->getParameterDataTypes()[2] == ASTNodeDataType::tuple_t); + REQUIRE(function_embedder->getParameterDataTypes()[2].contentType() == ASTNodeDataType::matrix_t); + REQUIRE(function_embedder->getParameterDataTypes()[2].contentType().numberOfRows() == 3); + REQUIRE(function_embedder->getParameterDataTypes()[2].contentType().numberOfColumns() == 3); + REQUIRE(function_embedder->getParameterDataTypes()[3] == ASTNodeDataType::vector_t); + REQUIRE(function_embedder->getParameterDataTypes()[3].dimension() == 2); + } } SECTION("errors") @@ -1332,7 +1331,7 @@ foo(x); SECTION("R^2: invalid argument list size") { std::string_view data = R"( -foo((1,2,3,4)); +foo(1,2,3,4); )"; std::string error_msg = "no matching function to call foo: Z*Z*Z*Z\n" @@ -1362,7 +1361,7 @@ foo((1,2,3,4)); SECTION("R^3: invalid argument list size") { std::string_view data = R"( -foo((1,2,3,4)); +foo(1,2,3,4); )"; std::string error_msg = "no matching function to call foo: Z*Z*Z*Z\n" @@ -1485,7 +1484,7 @@ foo(x); SECTION("R^2x2: invalid argument list size") { std::string_view data = R"( -foo((1,2,3)); +foo(1,2,3); )"; std::string error_msg = "no matching function to call foo: Z*Z*Z\n" @@ -1515,7 +1514,7 @@ foo((1,2,3)); SECTION("R^3x3: invalid argument list size") { std::string_view data = R"( -foo((1,2,3,4)); +foo(1,2,3,4); )"; std::string error_msg = "no matching function to call foo: Z*Z*Z*Z\n" diff --git a/tests/test_BuiltinFunctionProcessor.cpp b/tests/test_BuiltinFunctionProcessor.cpp index bbc5ac52e1a6e8034b68b591adff83c1d8701ff5..57f5d65ac3b745e65b4d40047db87444b9550b55 100644 --- a/tests/test_BuiltinFunctionProcessor.cpp +++ b/tests/test_BuiltinFunctionProcessor.cpp @@ -17,6 +17,8 @@ TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ + test_only::test_BuiltinFunctionRegister{*ast}; \ + \ ASTModulesImporter{*ast}; \ ASTNodeTypeCleaner<language::import_instruction>{*ast}; \ \ @@ -329,8 +331,8 @@ let s:R, s = dot(x,y); tested_function_set.insert("dot:R^2*R^2"); std::string_view data = R"( import math; -let x:R^2, x = (-2, 3); -let y:R^2, y = (4, 3); +let x:R^2, x = [-2, 3]; +let y:R^2, y = [4, 3]; let s:R, s = dot(x,y); )"; CHECK_BUILTIN_FUNCTION_EVALUATION_RESULT(data, "s", dot(TinyVector<2>{-2, 3}, TinyVector<2>{4, 3})); @@ -340,8 +342,8 @@ let s:R, s = dot(x,y); tested_function_set.insert("dot:R^3*R^3"); std::string_view data = R"( import math; -let x:R^3, x = (-2, 3, 4); -let y:R^3, y = (4, 3, 5); +let x:R^3, x = [-2, 3, 4]; +let y:R^3, y = [4, 3, 5]; let s:R, s = dot(x,y); )"; CHECK_BUILTIN_FUNCTION_EVALUATION_RESULT(data, "s", dot(TinyVector<3>{-2, 3, 4}, TinyVector<3>{4, 3, 5})); @@ -369,4 +371,31 @@ runtimeError(); CHECK_AST_THROWS_WITH(data, error); } } + + SECTION("int list -> tuple args evalation") + { + { + std::string_view data = R"( +let x:R, x = tuple_ZtoR((1,2,3,-4)); +)"; + CHECK_BUILTIN_FUNCTION_EVALUATION_RESULT(data, "x", 0.5 * (1 + 2 + 3 - 4)); + } + + { + std::string_view data = R"( +let (X,x):(R)*R, (X,x) = R22ToTupleRxR([[1,1], [2,3]]); +)"; + CHECK_BUILTIN_FUNCTION_EVALUATION_RESULT(data, "X", (std::vector<double>{1, 1, 2, 3})); + } + } + + SECTION("simple N to tuple args evalation") + { + { + std::string_view data = R"( +let x:R, x = tuple_ZtoR(3); +)"; + CHECK_BUILTIN_FUNCTION_EVALUATION_RESULT(data, "x", 0.5 * 3); + } + } } diff --git a/tests/test_BuiltinFunctionRegister.hpp b/tests/test_BuiltinFunctionRegister.hpp index 49bceabb565ec13b04350f083009c85702886fc2..bcabd3ad49c5933b938eea5bb6f97b46a6bd4cc4 100644 --- a/tests/test_BuiltinFunctionRegister.hpp +++ b/tests/test_BuiltinFunctionRegister.hpp @@ -121,7 +121,13 @@ class test_BuiltinFunctionRegister m_name_builtin_function_map.insert( std::make_pair("tuple_ZtoR:(Z...)", std::make_shared<BuiltinFunctionEmbedder<double(std::vector<int64_t>)>>( - [](const std::vector<int64_t>&) -> double { return 0.5; }))); + [](const std::vector<int64_t>& v) -> double { + int64_t sum = 0; + for (auto vi : v) { + sum += vi; + } + return 0.5 * sum; + }))); m_name_builtin_function_map.insert( std::make_pair("tuple_RtoB:(R...)", std::make_shared<BuiltinFunctionEmbedder<bool(std::vector<double>)>>( @@ -162,6 +168,14 @@ class test_BuiltinFunctionRegister std::make_shared<BuiltinFunctionEmbedder<double(const std::vector<TinyMatrix<2>>&)>>( [](const std::vector<TinyMatrix<2>>&) -> double { return 1; }))); + m_name_builtin_function_map.insert( + std::make_pair("R22ToTupleRxR:(R^2x2)", + std::make_shared< + BuiltinFunctionEmbedder<std::tuple<std::vector<double>, double>(const TinyMatrix<2>&)>>( + [](const TinyMatrix<2>& A) -> std::tuple<std::vector<double>, double> { + return std::make_tuple(std::vector<double>{A(0, 0), A(0, 1), A(1, 0), A(1, 1)}, A(0, 0)); + }))); + m_name_builtin_function_map.insert( std::make_pair("tuple_R33ToR:(R^3x3...)", std::make_shared<BuiltinFunctionEmbedder<double(const std::vector<TinyMatrix<3>>)>>( diff --git a/tests/test_ConcatExpressionProcessor.cpp b/tests/test_ConcatExpressionProcessor.cpp index 4c5e202b71a1b9630683145aa4ffb30863ce9a27..ce6c23ddcbc3719907d43ea2b14cff52337dc655 100644 --- a/tests/test_ConcatExpressionProcessor.cpp +++ b/tests/test_ConcatExpressionProcessor.cpp @@ -90,7 +90,7 @@ TEST_CASE("ConcatExpressionProcessor", "[language]") std::ostringstream os; os << "foo_" << TinyVector<2>{1, 2}; - CHECK_CONCAT_EXPRESSION_RESULT(R"(let x:R^2, x = (1,2); let s:string, s = "foo_"; s = s+x;)", "s", os.str()); + CHECK_CONCAT_EXPRESSION_RESULT(R"(let x:R^2, x = [1,2]; let s:string, s = "foo_"; s = s+x;)", "s", os.str()); } SECTION("string + R^3") @@ -98,6 +98,6 @@ TEST_CASE("ConcatExpressionProcessor", "[language]") std::ostringstream os; os << "foo_" << TinyVector<3>{1, 2, 3}; - CHECK_CONCAT_EXPRESSION_RESULT(R"(let x:R^3, x = (1,2,3); let s:string, s = "foo_"; s = s+x;)", "s", os.str()); + CHECK_CONCAT_EXPRESSION_RESULT(R"(let s:string, s = "foo_"; s = s+[1,2,3];)", "s", os.str()); } } diff --git a/tests/test_DiscreteFunctionIntegrator.cpp b/tests/test_DiscreteFunctionIntegrator.cpp index 465288f67d4efcd9a7a78eff53ab9649d381e572..031f6c62bd4f123e0a001eacdea0721716325978 100644 --- a/tests/test_DiscreteFunctionIntegrator.cpp +++ b/tests/test_DiscreteFunctionIntegrator.cpp @@ -61,11 +61,11 @@ let N_scalar_non_linear_1d: R^1 -> N, x -> floor(3 * x[0] * x[0] + 2); let Z_scalar_non_linear_1d: R^1 -> Z, x -> floor(exp(2 * x[0]) - 1); let R_scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; let R1_non_linear_1d: R^1 -> R^1, x -> 2 * exp(x[0]); -let R2_non_linear_1d: R^1 -> R^2, x -> (2 * exp(x[0]), -3*x[0]); -let R3_non_linear_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); +let R2_non_linear_1d: R^1 -> R^2, x -> [2 * exp(x[0]), -3*x[0]]; +let R3_non_linear_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; let R1x1_non_linear_1d: R^1 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[0]) + 3); -let R2x2_non_linear_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); -let R3x3_non_linear_1d: R^1 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0], -4*x[0], 2*x[0]+1, 3, -6*x[0], exp(x[0])); +let R2x2_non_linear_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; +let R3x3_non_linear_1d: R^1 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3], [x[0] * x[0], -4*x[0], 2*x[0]+1], [3, -6*x[0], exp(x[0])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -307,11 +307,11 @@ let N_scalar_non_linear_2d: R^2 -> N, x -> floor(3 * (x[0] + x[1]) * (x[0] + x[1 let Z_scalar_non_linear_2d: R^2 -> Z, x -> floor(exp(2 * x[0]) - 3 * x[1]); let R_scalar_non_linear_2d: R^2 -> R, x -> 2 * exp(x[0]) + 3 * x[1]; let R1_non_linear_2d: R^2 -> R^1, x -> 2 * exp(x[0]); -let R2_non_linear_2d: R^2 -> R^2, x -> (2 * exp(x[0]), -3*x[1]); -let R3_non_linear_2d: R^2 -> R^3, x -> (2 * exp(x[0]) + 3, x[1] - 2, 3); -let R1x1_non_linear_2d: R^2 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[1]) + 3); -let R2x2_non_linear_2d: R^2 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3, x[1] * x[0]); -let R3x3_non_linear_2d: R^2 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3, x[1] * x[0], -4*x[1], 2*x[0]+1, 3, -6*x[0], exp(x[1])); +let R2_non_linear_2d: R^2 -> R^2, x -> [2 * exp(x[0]), -3*x[1]]; +let R3_non_linear_2d: R^2 -> R^3, x -> [2 * exp(x[0]) + 3, x[1] - 2, 3]; +let R1x1_non_linear_2d: R^2 -> R^1x1, x -> 2 * exp(x[0]) * sin(x[1]) + 3; +let R2x2_non_linear_2d: R^2 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0])], [3, x[1] * x[0]]]; +let R3x3_non_linear_2d: R^2 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3], [x[1] * x[0], -4*x[1], 2*x[0]+1], [3, -6*x[0], exp(x[1])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -553,11 +553,11 @@ let N_scalar_non_linear_3d: R^3 -> N, x -> floor(3 * (x[0] + x[1]) * (x[0] + x[1 let Z_scalar_non_linear_3d: R^3 -> Z, x -> floor(exp(2 * x[0]) - 3 * x[1] + x[2]); let R_scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]+x[2]) + 3 * x[1]; let R1_non_linear_3d: R^3 -> R^1, x -> 2 * exp(x[0])+sin(x[1] + x[2]); -let R2_non_linear_3d: R^3 -> R^2, x -> (2 * exp(x[0]), -3*x[1] * x[2]); -let R3_non_linear_3d: R^3 -> R^3, x -> (2 * exp(x[0]) + 3, x[1] - 2, 3 * x[2]); +let R2_non_linear_3d: R^3 -> R^2, x -> [2 * exp(x[0]), -3*x[1] * x[2]]; +let R3_non_linear_3d: R^3 -> R^3, x -> [2 * exp(x[0]) + 3, x[1] - 2, 3 * x[2]]; let R1x1_non_linear_3d: R^3 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * x[2]); -let R2x2_non_linear_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[2] - 2 * x[0]), 3, x[1] * x[0] - x[2]); -let R3x3_non_linear_3d: R^3 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[2]), 3, x[1] * x[2], -4*x[1], 2*x[2]+1, 3, -6*x[2], exp(x[1] + x[2])); +let R2x2_non_linear_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[2] - 2 * x[0])], [3, x[1] * x[0] - x[2]]]; +let R3x3_non_linear_3d: R^3 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[2]), 3], [x[1] * x[2], -4*x[1], 2*x[2]+1], [3, -6*x[2], exp(x[1] + x[2])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_DiscreteFunctionIntegratorByZone.cpp b/tests/test_DiscreteFunctionIntegratorByZone.cpp index 071f8cddb7e9f71e0b102bf361afb8715a7afe87..19c0ac87c1d941e4c5f0026e154087be305c55f2 100644 --- a/tests/test_DiscreteFunctionIntegratorByZone.cpp +++ b/tests/test_DiscreteFunctionIntegratorByZone.cpp @@ -64,11 +64,11 @@ let N_scalar_non_linear_1d: R^1 -> N, x -> floor(3 * x[0] * x[0] + 2); let Z_scalar_non_linear_1d: R^1 -> Z, x -> floor(exp(2 * x[0]) - 1); let R_scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; let R1_non_linear_1d: R^1 -> R^1, x -> 2 * exp(x[0]); -let R2_non_linear_1d: R^1 -> R^2, x -> (2 * exp(x[0]), -3*x[0]); -let R3_non_linear_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); +let R2_non_linear_1d: R^1 -> R^2, x -> [2 * exp(x[0]), -3*x[0]]; +let R3_non_linear_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; let R1x1_non_linear_1d: R^1 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[0]) + 3); -let R2x2_non_linear_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); -let R3x3_non_linear_1d: R^1 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0], -4*x[0], 2*x[0]+1, 3, -6*x[0], exp(x[0])); +let R2x2_non_linear_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; +let R3x3_non_linear_1d: R^1 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3], [x[0] * x[0], -4*x[0], 2*x[0]+1], [3, -6*x[0], exp(x[0])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -403,11 +403,11 @@ let N_scalar_non_linear_2d: R^2 -> N, x -> floor(3 * (x[0] + x[1]) * (x[0] + x[1 let Z_scalar_non_linear_2d: R^2 -> Z, x -> floor(exp(2 * x[0]) - 3 * x[1]); let R_scalar_non_linear_2d: R^2 -> R, x -> 2 * exp(x[0]) + 3 * x[1]; let R1_non_linear_2d: R^2 -> R^1, x -> 2 * exp(x[0]); -let R2_non_linear_2d: R^2 -> R^2, x -> (2 * exp(x[0]), -3*x[1]); -let R3_non_linear_2d: R^2 -> R^3, x -> (2 * exp(x[0]) + 3, x[1] - 2, 3); +let R2_non_linear_2d: R^2 -> R^2, x -> [2 * exp(x[0]), -3*x[1]]; +let R3_non_linear_2d: R^2 -> R^3, x -> [2 * exp(x[0]) + 3, x[1] - 2, 3]; let R1x1_non_linear_2d: R^2 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[1]) + 3); -let R2x2_non_linear_2d: R^2 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3, x[1] * x[0]); -let R3x3_non_linear_2d: R^2 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3, x[1] * x[0], -4*x[1], 2*x[0]+1, 3, -6*x[0], exp(x[1])); +let R2x2_non_linear_2d: R^2 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0])], [3, x[1] * x[0]]]; +let R3x3_non_linear_2d: R^2 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3], [x[1] * x[0], -4*x[1], 2*x[0]+1], [3, -6*x[0], exp(x[1])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -742,11 +742,11 @@ let N_scalar_non_linear_3d: R^3 -> N, x -> floor(3 * (x[0] + x[1]) * (x[0] + x[1 let Z_scalar_non_linear_3d: R^3 -> Z, x -> floor(exp(2 * x[0]) - 3 * x[1] + x[2]); let R_scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]+x[2]) + 3 * x[1]; let R1_non_linear_3d: R^3 -> R^1, x -> 2 * exp(x[0])+sin(x[1] + x[2]); -let R2_non_linear_3d: R^3 -> R^2, x -> (2 * exp(x[0]), -3*x[1] * x[2]); -let R3_non_linear_3d: R^3 -> R^3, x -> (2 * exp(x[0]) + 3, x[1] - 2, 3 * x[2]); +let R2_non_linear_3d: R^3 -> R^2, x -> [2 * exp(x[0]), -3*x[1] * x[2]]; +let R3_non_linear_3d: R^3 -> R^3, x -> [2 * exp(x[0]) + 3, x[1] - 2, 3 * x[2]]; let R1x1_non_linear_3d: R^3 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * x[2]); -let R2x2_non_linear_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[2] - 2 * x[0]), 3, x[1] * x[0] - x[2]); -let R3x3_non_linear_3d: R^3 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[2]), 3, x[1] * x[2], -4*x[1], 2*x[2]+1, 3, -6*x[2], exp(x[1] + x[2])); +let R2x2_non_linear_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[2] - 2 * x[0])], [3, x[1] * x[0] - x[2]]]; +let R3x3_non_linear_3d: R^3 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[2]), 3], [x[1] * x[2], -4*x[1], 2*x[2]+1], [3, -6*x[2], exp(x[1] + x[2])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_DiscreteFunctionInterpoler.cpp b/tests/test_DiscreteFunctionInterpoler.cpp index 809ca559ca254cbbb5d90c63f8dcd943a5df23c8..f9d870d29dbd53f6eef9f49bf114be2566475d0d 100644 --- a/tests/test_DiscreteFunctionInterpoler.cpp +++ b/tests/test_DiscreteFunctionInterpoler.cpp @@ -59,11 +59,11 @@ let N_scalar_non_linear_1d: R^1 -> N, x -> floor(3 * x[0] * x[0] + 2); let Z_scalar_non_linear_1d: R^1 -> Z, x -> floor(exp(2 * x[0]) - 1); let R_scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; let R1_non_linear_1d: R^1 -> R^1, x -> 2 * exp(x[0]); -let R2_non_linear_1d: R^1 -> R^2, x -> (2 * exp(x[0]), -3*x[0]); -let R3_non_linear_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); +let R2_non_linear_1d: R^1 -> R^2, x -> [2 * exp(x[0]), -3*x[0]]; +let R3_non_linear_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; let R1x1_non_linear_1d: R^1 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[0]) + 3); -let R2x2_non_linear_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); -let R3x3_non_linear_1d: R^1 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0], -4*x[0], 2*x[0]+1, 3, -6*x[0], exp(x[0])); +let R2x2_non_linear_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; +let R3x3_non_linear_1d: R^1 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3], [x[0] * x[0], -4*x[0], 2*x[0]+1], [3, -6*x[0], exp(x[0])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -358,11 +358,11 @@ let N_scalar_non_linear_2d: R^2 -> N, x -> floor(3 * (x[0] + x[1]) * (x[0] + x[1 let Z_scalar_non_linear_2d: R^2 -> Z, x -> floor(exp(2 * x[0]) - 3 * x[1]); let R_scalar_non_linear_2d: R^2 -> R, x -> 2 * exp(x[0]) + 3 * x[1]; let R1_non_linear_2d: R^2 -> R^1, x -> 2 * exp(x[0]); -let R2_non_linear_2d: R^2 -> R^2, x -> (2 * exp(x[0]), -3*x[1]); -let R3_non_linear_2d: R^2 -> R^3, x -> (2 * exp(x[0]) + 3, x[1] - 2, 3); -let R1x1_non_linear_2d: R^2 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[1]) + 3); -let R2x2_non_linear_2d: R^2 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3, x[1] * x[0]); -let R3x3_non_linear_2d: R^2 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3, x[1] * x[0], -4*x[1], 2*x[0]+1, 3, -6*x[0], exp(x[1])); +let R2_non_linear_2d: R^2 -> R^2, x -> [2 * exp(x[0]), -3*x[1]]; +let R3_non_linear_2d: R^2 -> R^3, x -> [2 * exp(x[0]) + 3, x[1] - 2, 3]; +let R1x1_non_linear_2d: R^2 -> R^1x1, x -> [[2 * exp(x[0]) * sin(x[1]) + 3]]; +let R2x2_non_linear_2d: R^2 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0])], [3, x[1] * x[0]]]; +let R3x3_non_linear_2d: R^2 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3], [x[1] * x[0], -4*x[1], 2*x[0]+1], [3, -6*x[0], exp(x[1])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -658,11 +658,11 @@ let N_scalar_non_linear_3d: R^3 -> N, x -> floor(3 * (x[0] + x[1]) * (x[0] + x[1 let Z_scalar_non_linear_3d: R^3 -> Z, x -> floor(exp(2 * x[0]) - 3 * x[1] + x[2]); let R_scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]+x[2]) + 3 * x[1]; let R1_non_linear_3d: R^3 -> R^1, x -> 2 * exp(x[0])+sin(x[1] + x[2]); -let R2_non_linear_3d: R^3 -> R^2, x -> (2 * exp(x[0]), -3*x[1] * x[2]); -let R3_non_linear_3d: R^3 -> R^3, x -> (2 * exp(x[0]) + 3, x[1] - 2, 3 * x[2]); -let R1x1_non_linear_3d: R^3 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * x[2]); -let R2x2_non_linear_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[2] - 2 * x[0]), 3, x[1] * x[0] - x[2]); -let R3x3_non_linear_3d: R^3 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[2]), 3, x[1] * x[2], -4*x[1], 2*x[2]+1, 3, -6*x[2], exp(x[1] + x[2])); +let R2_non_linear_3d: R^3 -> R^2, x -> [2 * exp(x[0]), -3*x[1] * x[2]]; +let R3_non_linear_3d: R^3 -> R^3, x -> [2 * exp(x[0]) + 3, x[1] - 2, 3 * x[2]]; +let R1x1_non_linear_3d: R^3 -> R^1x1, x -> 2 * exp(x[0]) * sin(x[1]) + 3 * x[2]; +let R2x2_non_linear_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[2] - 2 * x[0])], [3, x[1] * x[0] - x[2]]]; +let R3x3_non_linear_3d: R^3 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[2]), 3], [x[1] * x[2], -4*x[1], 2*x[2]+1], [3, -6*x[2], exp(x[1] + x[2])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_DiscreteFunctionInterpolerByZone.cpp b/tests/test_DiscreteFunctionInterpolerByZone.cpp index 4ad5f464f5fe276bf489df459cd2cfc90e42a519..dce3b645a7e98ee91b41f8cd5f158edb019d94ed 100644 --- a/tests/test_DiscreteFunctionInterpolerByZone.cpp +++ b/tests/test_DiscreteFunctionInterpolerByZone.cpp @@ -67,11 +67,11 @@ let N_scalar_non_linear_1d: R^1 -> N, x -> floor(3 * x[0] * x[0] + 2); let Z_scalar_non_linear_1d: R^1 -> Z, x -> floor(exp(2 * x[0]) - 1); let R_scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; let R1_non_linear_1d: R^1 -> R^1, x -> 2 * exp(x[0]); -let R2_non_linear_1d: R^1 -> R^2, x -> (2 * exp(x[0]), -3*x[0]); -let R3_non_linear_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); -let R1x1_non_linear_1d: R^1 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[0]) + 3); -let R2x2_non_linear_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); -let R3x3_non_linear_1d: R^1 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0], -4*x[0], 2*x[0]+1, 3, -6*x[0], exp(x[0])); +let R2_non_linear_1d: R^1 -> R^2, x -> [2 * exp(x[0]), -3*x[0]]; +let R3_non_linear_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; +let R1x1_non_linear_1d: R^1 -> R^1x1, x -> 2 * exp(x[0]) * sin(x[0]) + 3; +let R2x2_non_linear_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; +let R3x3_non_linear_1d: R^1 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3], [x[0] * x[0], -4*x[0], 2*x[0]+1], [3, -6*x[0], exp(x[0])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -410,11 +410,11 @@ let N_scalar_non_linear_2d: R^2 -> N, x -> floor(3 * (x[0] + x[1]) * (x[0] + x[1 let Z_scalar_non_linear_2d: R^2 -> Z, x -> floor(exp(2 * x[0]) - 3 * x[1]); let R_scalar_non_linear_2d: R^2 -> R, x -> 2 * exp(x[0]) + 3 * x[1]; let R1_non_linear_2d: R^2 -> R^1, x -> 2 * exp(x[0]); -let R2_non_linear_2d: R^2 -> R^2, x -> (2 * exp(x[0]), -3*x[1]); -let R3_non_linear_2d: R^2 -> R^3, x -> (2 * exp(x[0]) + 3, x[1] - 2, 3); +let R2_non_linear_2d: R^2 -> R^2, x -> [2 * exp(x[0]), -3*x[1]]; +let R3_non_linear_2d: R^2 -> R^3, x -> [2 * exp(x[0]) + 3, x[1] - 2, 3]; let R1x1_non_linear_2d: R^2 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[1]) + 3); -let R2x2_non_linear_2d: R^2 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3, x[1] * x[0]); -let R3x3_non_linear_2d: R^2 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3, x[1] * x[0], -4*x[1], 2*x[0]+1, 3, -6*x[0], exp(x[1])); +let R2x2_non_linear_2d: R^2 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0])], [3, x[1] * x[0]]]; +let R3x3_non_linear_2d: R^2 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[0]), 3], [x[1] * x[0], -4*x[1], 2*x[0]+1], [3, -6*x[0], exp(x[1])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -754,11 +754,11 @@ let N_scalar_non_linear_3d: R^3 -> N, x -> floor(3 * (x[0] + x[1]) * (x[0] + x[1 let Z_scalar_non_linear_3d: R^3 -> Z, x -> floor(exp(2 * x[0]) - 3 * x[1] + x[2]); let R_scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]+x[2]) + 3 * x[1]; let R1_non_linear_3d: R^3 -> R^1, x -> 2 * exp(x[0])+sin(x[1] + x[2]); -let R2_non_linear_3d: R^3 -> R^2, x -> (2 * exp(x[0]), -3*x[1] * x[2]); -let R3_non_linear_3d: R^3 -> R^3, x -> (2 * exp(x[0]) + 3, x[1] - 2, 3 * x[2]); +let R2_non_linear_3d: R^3 -> R^2, x -> [2 * exp(x[0]), -3*x[1] * x[2]]; +let R3_non_linear_3d: R^3 -> R^3, x -> [2 * exp(x[0]) + 3, x[1] - 2, 3 * x[2]]; let R1x1_non_linear_3d: R^3 -> R^1x1, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * x[2]); -let R2x2_non_linear_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[2] - 2 * x[0]), 3, x[1] * x[0] - x[2]); -let R3x3_non_linear_3d: R^3 -> R^3x3, x -> (2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[2]), 3, x[1] * x[2], -4*x[1], 2*x[2]+1, 3, -6*x[2], exp(x[1] + x[2])); +let R2x2_non_linear_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[2] - 2 * x[0])], [3, x[1] * x[0] - x[2]]]; +let R3x3_non_linear_3d: R^3 -> R^3x3, x -> [[2 * exp(x[0]) * sin(x[1]) + 3, sin(x[1] - 2 * x[2]), 3], [x[1] * x[2], -4*x[1], 2*x[2]+1], [3, -6*x[2], exp(x[1] + x[2])]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_DiscreteFunctionVectorIntegrator.cpp b/tests/test_DiscreteFunctionVectorIntegrator.cpp index d0a9d6a78fd260c0b259aa630d9e79f85271ae89..31fd447f525f2b002ead1246219319454c792588 100644 --- a/tests/test_DiscreteFunctionVectorIntegrator.cpp +++ b/tests/test_DiscreteFunctionVectorIntegrator.cpp @@ -348,7 +348,7 @@ let B_scalar_non_linear_2d: R^2 -> B, x -> (exp(2 * x[0] + x[1]) + 3 > 4); let N_scalar_non_linear_1d: R^1 -> N, x -> floor(3 * x[0] * x[0] + 2); let Z_scalar_non_linear_3d: R^3 -> Z, x -> floor(exp(2 * x[1]) - x[2]); let R_scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0] + x[1]) + 3 * x[2]; -let R2_scalar_non_linear_3d: R^3 -> R^2, x -> (2 * exp(x[0] + x[1]) + 3 * x[2], x[0] - x[1]); +let R2_scalar_non_linear_3d: R^3 -> R^2, x -> [2 * exp(x[0] + x[1]) + 3 * x[2], x[0] - x[1]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_DiscreteFunctionVectorInterpoler.cpp b/tests/test_DiscreteFunctionVectorInterpoler.cpp index 692dd8c6c18ad85f87f5c85dcc41a6bcb0838312..3c3fefc38aba5b7377a86eb28ce4c6439ed82164 100644 --- a/tests/test_DiscreteFunctionVectorInterpoler.cpp +++ b/tests/test_DiscreteFunctionVectorInterpoler.cpp @@ -390,7 +390,7 @@ let B_scalar_non_linear_2d: R^2 -> B, x -> (exp(2 * x[0] + x[1]) + 3 > 4); let N_scalar_non_linear_1d: R^1 -> N, x -> floor(3 * x[0] * x[0] + 2); let Z_scalar_non_linear_3d: R^3 -> Z, x -> floor(exp(2 * x[1]) - x[2]); let R_scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0] + x[1]) + 3 * x[2]; -let R2_scalar_non_linear_3d: R^3 -> R^2, x -> (2 * exp(x[0] + x[1]) + 3 * x[2], x[0] - x[1]); +let R2_scalar_non_linear_3d: R^3 -> R^2, x -> [2 * exp(x[0] + x[1]) + 3 * x[2], x[0] - x[1]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_DiscreteFunctionVectorInterpolerByZone.cpp b/tests/test_DiscreteFunctionVectorInterpolerByZone.cpp index 172c68d4f59f318d0f36c315aaf4962e71195dbe..c3605a232c7b032ad4215db72cdf711695818c6e 100644 --- a/tests/test_DiscreteFunctionVectorInterpolerByZone.cpp +++ b/tests/test_DiscreteFunctionVectorInterpolerByZone.cpp @@ -443,7 +443,7 @@ let B_scalar_non_linear_2d: R^2 -> B, x -> (exp(2 * x[0] + x[1]) + 3 > 4); let N_scalar_non_linear_1d: R^1 -> N, x -> floor(3 * x[0] * x[0] + 2); let Z_scalar_non_linear_3d: R^3 -> Z, x -> floor(exp(2 * x[1]) - x[2]); let R_scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0] + x[1]) + 3 * x[2]; -let R2_scalar_non_linear_3d: R^3 -> R^2, x -> (2 * exp(x[0] + x[1]) + 3 * x[2], x[0] - x[1]); +let R2_scalar_non_linear_3d: R^3 -> R^2, x -> [2 * exp(x[0] + x[1]) + 3 * x[2], x[0] - x[1]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_FunctionArgumentConverter.cpp b/tests/test_FunctionArgumentConverter.cpp index 643fbba0b092d337743ea5aeaedb25eb86a5b445..909353f79e3b7a1dcada5bfcaba92d80967420f6 100644 --- a/tests/test_FunctionArgumentConverter.cpp +++ b/tests/test_FunctionArgumentConverter.cpp @@ -136,6 +136,34 @@ TEST_CASE("FunctionArgumentConverter", "[language]") "unexpected error: cannot convert 'unsigned long' to 'TinyVector<3ul, double>'"); } + SECTION("FunctionTupleArgumentConverter (string tuple)") + { + const TinyVector<3> x3{1.7, 2.9, -3}; + FunctionTupleArgumentConverter<std::string, TinyVector<3>> converter0{0}; + converter0.convert(execution_policy, TinyVector{x3}); + + FunctionTupleArgumentConverter<std::string, std::vector<std::string>> converter1{1}; + converter1.convert(execution_policy, std::vector<std::string>{"foo"}); + + FunctionTupleArgumentConverter<std::string, std::vector<TinyVector<3>>> converter2{2}; + converter2.convert(execution_policy, std::vector<TinyVector<3>>{TinyVector<3>{1, 2, 3}}); + + REQUIRE(std::get<std::vector<std::string>>(execution_policy.currentContext()[0]) == + std::vector<std::string>{[](auto x) { + std::ostringstream os; + os << x; + return os.str(); + }(x3)}); + REQUIRE(std::get<std::vector<std::string>>(execution_policy.currentContext()[1]) == + std::vector<std::string>{"foo"}); + + REQUIRE(std::get<std::vector<std::string>>(execution_policy.currentContext()[2]) == std::vector<std::string>{[]() { + std::ostringstream os; + os << TinyVector<3>{1, 2, 3}; + return os.str(); + }()}); + } + SECTION("FunctionListArgumentConverter") { const uint64_t i = 3; diff --git a/tests/test_FunctionProcessor.cpp b/tests/test_FunctionProcessor.cpp index 5c72fd0d7b96a4919490b6707bde1bef03aa0b28..7a1780e900efb31addcab6112ebc6424c5547d52 100644 --- a/tests/test_FunctionProcessor.cpp +++ b/tests/test_FunctionProcessor.cpp @@ -358,7 +358,7 @@ let fx:R^1, fx = f(x); { std::string_view data = R"( let f : R^2 -> R^2, x -> 2*x; -let x:R^2, x = (3, 7); +let x:R^2, x = [3, 7]; let fx:R^2, fx = f(x); )"; @@ -369,9 +369,8 @@ let fx:R^2, fx = f(x); { std::string_view data = R"( let f : R^3 -> R^3, x -> 2*x; -let x:R^3, x = (2, 4, 7); -let fx:R^3, fx = f(x); +let fx:R^3, fx = f([2, 4, 7]); )"; CHECK_FUNCTION_EVALUATION_RESULT(data, "fx", (2 * TinyVector<3>{2, 4, 7})); } @@ -390,7 +389,7 @@ let fx:R^1, fx = f(x); SECTION(" R*R -> R^2") { std::string_view data = R"( -let f : R*R -> R^2, (x,y) -> (2*x, 3*y); +let f : R*R -> R^2, (x,y) -> [2*x, 3*y]; let fx:R^2, fx = f(2, 3); )"; CHECK_FUNCTION_EVALUATION_RESULT(data, "fx", (TinyVector<2>{2 * 2, 3 * 3})); @@ -399,7 +398,7 @@ let fx:R^2, fx = f(2, 3); SECTION(" R -> R^3") { std::string_view data = R"( -let f : R -> R^3, x -> (x, 2*x, x*x); +let f : R -> R^3, x -> [x, 2*x, x*x]; let fx:R^3, fx = f(3); )"; @@ -424,9 +423,8 @@ let fx:R^1x1, fx = f(x); { std::string_view data = R"( let f : R^2x2 -> R^2x2, x -> 2*x; -let x:R^2x2, x = (3, 7, 6, -2); -let fx:R^2x2, fx = f(x); +let fx:R^2x2, fx = f([[3, 7], [6, -2]]); )"; CHECK_FUNCTION_EVALUATION_RESULT(data, "fx", (2 * TinyMatrix<2>{3, 7, 6, -2})); } @@ -435,7 +433,7 @@ let fx:R^2x2, fx = f(x); { std::string_view data = R"( let f : R^3x3 -> R^3x3, x -> 2*x; -let x:R^3x3, x = (2, 4, 7, 1, 3, 5, -6, 2, -3); +let x:R^3x3, x = [[2, 4, 7],[1, 3, 5],[-6, 2, -3]]; let fx:R^3x3, fx = f(x); )"; @@ -456,7 +454,7 @@ let fx:R^1x1, fx = f(x); SECTION(" R*R -> R^2x2") { std::string_view data = R"( -let f : R*R -> R^2x2, (x,y) -> (2*x, 3*y, 5*(x-y), 2*x-y); +let f : R*R -> R^2x2, (x,y) -> [[2*x, 3*y], [5*(x-y), 2*x-y]]; let fx:R^2x2, fx = f(2, 3); )"; @@ -468,7 +466,7 @@ let fx:R^2x2, fx = f(2, 3); SECTION(" R -> R^3x3") { std::string_view data = R"( -let f : R -> R^3x3, x -> (x, 2*x, x*x, 3*x, 2+x, x-1, x+0.5, 2*x-1, 1/x); +let f : R -> R^3x3, x -> [[x, 2*x, x*x], [3*x, 2+x, x-1], [x+0.5, 2*x-1, 1/x]]; let fx:R^3x3, fx = f(3); )"; @@ -485,7 +483,7 @@ let fx:R^3x3, fx = f(3); SECTION(" R -> R*R^1*R^2*R^3") { std::string_view data = R"( -let f : R -> R*R^1*R^2*R^3, x -> (x+1, 2*x, (x-2, x+2), (1, 0.5*x, x*x)); +let f : R -> R*R^1*R^2*R^3, x -> (x+1, 2*x, [x-2, x+2], [1, 0.5*x, x*x]); let (x, x1, x2, x3):R*R^1*R^2*R^3, (x, x1, x2, x3) = f(3); )"; @@ -501,10 +499,10 @@ let (x, x1, x2, x3):R*R^1*R^2*R^3, (x, x1, x2, x3) = f(3); { std::string_view data = R"( let f : R^2*R^3 -> R*R^1*R^2*R^3, - (x2, x3) -> (x2[0]+x3[2], x3[1], (x3[0], x2[1]), (x3[0], x3[0]+x2[1], x3[2])); + (x2, x3) -> (x2[0]+x3[2], [x3[1]], [x3[0], x2[1]], [x3[0], x3[0]+x2[1], x3[2]]); -let y2:R^2, y2 = (2.3, 4.1); -let y3:R^3, y3 = (1.2, 1.3, 2.1); +let y2:R^2, y2 = [2.3, 4.1]; +let y3:R^3, y3 = [1.2, 1.3, 2.1]; let(x, x1, x2, x3) : R*R^1*R^2*R^3, (x, x1, x2, x3) = f(y2, y3); )"; @@ -520,9 +518,9 @@ let(x, x1, x2, x3) : R*R^1*R^2*R^3, (x, x1, x2, x3) = f(y2, y3); { std::string_view data = R"( let f : R^2*R^3 -> R*R^1*R^2*R^3, - (x2, x3) -> (x2[0]+x3[2], x3[1], (x3[0], x2[1]), (x3[0], x3[0]+x2[1], x3[2])); + (x2, x3) -> (x2[0]+x3[2], [x3[1]], [x3[0], x2[1]], [x3[0], x3[0]+x2[1], x3[2]]); -let y2:R^2, y2 = (2.3, 4.1); +let y2:R^2, y2 = [2.3, 4.1]; let (x, x1, x2, x3) : R*R^1*R^2*R^3, (x, x1, x2, x3) = f(y2, 0); )"; @@ -540,7 +538,7 @@ let (x, x1, x2, x3) : R*R^1*R^2*R^3, (x, x1, x2, x3) = f(y2, 0); let f : R^2*R^3 -> R*R^1*R^2*R^3, (x2, x3) -> (x2[0]+x3[2], x3[1], 0, 0); -let y2:R^2, y2 = (2.3, 4.1); +let y2:R^2, y2 = [2.3, 4.1]; let (x, x1, x2, x3):R*R^1*R^2*R^3, (x, x1, x2, x3) = f(y2, 0); )"; @@ -558,7 +556,7 @@ let (x, x1, x2, x3):R*R^1*R^2*R^3, (x, x1, x2, x3) = f(y2, 0); SECTION(" R -> R*R^1x1*R^2x2*R^3x3") { std::string_view data = R"( -let f : R -> R*R^1x1*R^2x2*R^3x3, x -> (x+1, 2*x, (x-2, x+2, 3, 2), (1, 0.5*x, x*x, x+1, 1/x, 2, x*x, 2*x-1, 3*x)); +let f : R -> R*R^1x1*R^2x2*R^3x3, x -> (x+1, 2*x, [[x-2, x+2], [3, 2]], [[1, 0.5*x, x*x], [x+1, 1/x, 2], [x*x, 2*x-1, 3*x]]); let (x, x11, x22, x33):R*R^1x1*R^2x2*R^3x3, (x, x11, x22, x33) = f(3); )"; @@ -575,10 +573,10 @@ let (x, x11, x22, x33):R*R^1x1*R^2x2*R^3x3, (x, x11, x22, x33) = f(3); { std::string_view data = R"( let f : R^2x2*R^3x3 -> R*R^1x1*R^2x2*R^3x3, - (x22, x33) -> (x22[0,0]+x33[2,0], x33[1,2], (x33[0,1], x22[1,1], x22[0,0], x33[2,2]), x22[0,0]*x33); + (x22, x33) -> (x22[0,0]+x33[2,0], x33[1,2], [[x33[0,1], x22[1,1]], [x22[0,0], x33[2,2]]], x22[0,0]*x33); -let y22:R^2x2, y22 = (2.3, 4.1, 6, -3); -let y33:R^3x3, y33 = (1.2, 1.3, 2.1, 3.2, -1.5, 2.3, -0.2, 3.1, -2.6); +let y22:R^2x2, y22 = [[2.3, 4.1], [6, -3]]; +let y33:R^3x3, y33 = [[1.2, 1.3, 2.1], [3.2,-1.5, 2.3],[-0.2, 3.1, -2.6]]; let(x, x11, x22, x33) : R*R^1x1*R^2x2*R^3x3, (x, x11, x22, x33) = f(y22, y33); )"; @@ -594,15 +592,15 @@ let(x, x11, x22, x33) : R*R^1x1*R^2x2*R^3x3, (x, x11, x22, x33) = f(y22, y33); { std::string_view data = R"( let f : R^2x2*R^3x3 -> R*R^1x1*R^2x2*R^3x3, - (x22, x33) -> (x22[0,0]+x33[2,1], x33[1,2], (x33[0,1], x22[1,0], x22[0,1], x33[2,2]), - (x22[1,0], x33[0,2]+x22[1,1], x33[2,2], - x33[2,0], x33[2,0]+x22[0,0], x33[1,1], - x33[2,1], x33[1,2]+x22[1,1], x33[0,0])); - -let y22:R^2x2, y22 = (2.3, 4.1, 3.1, 1.7); -let y33:R^3x3, y33 = (2.7, 3.1, 2.1, - 0.3, 1.2, 1.6, - 1.7, 2.2, 1.4); + (x22, x33) -> (x22[0,0]+x33[2,1], x33[1,2], [[x33[0,1], x22[1,0]], [x22[0,1], x33[2,2]]], + [[x22[1,0], x33[0,2]+x22[1,1], x33[2,2]], + [x33[2,0], x33[2,0]+x22[0,0], x33[1,1]], + [x33[2,1], x33[1,2]+x22[1,1], x33[0,0]]]); + +let y22:R^2x2, y22 = [[2.3, 4.1], [3.1, 1.7]]; +let y33:R^3x3, y33 = [[2.7, 3.1, 2.1], + [0.3, 1.2, 1.6], + [1.7, 2.2, 1.4]]; let (x, x11, x22, x33) : R*R^1x1*R^2x2*R^3x3, (x, x11, x22, x33) = f(y22, y33); )"; @@ -623,7 +621,7 @@ let (x, x11, x22, x33) : R*R^1x1*R^2x2*R^3x3, (x, x11, x22, x33) = f(y22, y33); let f : R^2x2*R^3x3 -> R*R^1x1*R^2x2*R^3x3, (x22, x33) -> (x22[0,0]+x33[2,0], x33[1,1], 0, 0); -let y22:R^2x2, y22 = (2.3, 4.1, 3.1, 1.7); +let y22:R^2x2, y22 = [[2.3, 4.1],[3.1, 1.7]]; let (x, x11, x22, x33):R*R^1x1*R^2x2*R^3x3, (x, x11, x22, x33) = f(y22, 0); )"; @@ -675,7 +673,7 @@ let x:R, x = pow(f(2)); SECTION("R -> R^2 -> R") { std::string_view data = R"( -let f : R -> R^2, x -> (x+1, x*2); +let f : R -> R^2, x -> [x+1, x*2]; let g : R^2 -> R, x -> x[0] + x[1]; let x:R, x = g(f(3)); @@ -688,7 +686,7 @@ let x:R, x = g(f(3)); SECTION("R -> R^2*R^3 -> R") { std::string_view data = R"( -let f : R -> R^2*R^3, x -> ((x+1, x*2), (6*x, 7-x, x/2.3)); +let f : R -> R^2*R^3, x -> ([x+1, x*2], [6*x, 7-x, x/2.3]); let g : R^2*R^3 -> R, (x, y) -> x[0]*x[1] + y[0]*y[1]-y[2]; let x:R, x = g(f(3)); @@ -701,7 +699,7 @@ let x:R, x = g(f(3)); SECTION("R -> R^2x2 -> R") { std::string_view data = R"( -let f : R -> R^2x2, x -> (x+1, x*2, x-1, x); +let f : R -> R^2x2, x -> [[x+1, x*2], [x-1, x]]; let g : R^2x2 -> R, A -> A[0,0] + 2*A[1,1] + 3*A[0,1]+ A[1, 0]; let x:R, x = g(f(3)); @@ -715,7 +713,7 @@ let x:R, x = g(f(3)); SECTION("R -> R^2x2*R^3x3 -> R") { std::string_view data = R"( -let f : R -> R^2x2*R^3x3, x -> ((x+1, x*2, x-1, x), (6*x, 7-x, x/2.3, -x, 2*x, x/2.5, x*x, 2*x, x)); +let f : R -> R^2x2*R^3x3, x -> ([[x+1, x*2], [x-1, x]], [[6*x, 7-x, x/2.3], [-x, 2*x, x/2.5], [x*x, 2*x, x]]); let g : R^2x2*R^3x3 -> R, (A22, A33) -> A22[0,0]*A22[1,1] + (A33[0,0]*A33[1,0]-A33[2,2])*A22[0,1]-A33[2,0]*A33[0,2]-A22[1,1]; let x:R, x = g(f(3)); diff --git a/tests/test_IntegrateCellValue.cpp b/tests/test_IntegrateCellValue.cpp index df35a215bea28b236cd2bcd7b243e2f759c4f40b..5df4d0c447c50751db43c0ce2db5345612fc514f 100644 --- a/tests/test_IntegrateCellValue.cpp +++ b/tests/test_IntegrateCellValue.cpp @@ -56,7 +56,7 @@ TEST_CASE("IntegrateCellValue", "[language]") std::string_view data = R"( import math; -let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); +let R2x2_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -113,7 +113,7 @@ let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x std::string_view data = R"( import math; -let R3_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); +let R3_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -325,7 +325,7 @@ let scalar_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; std::string_view data = R"( import math; -let R3_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); +let R3_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -404,7 +404,7 @@ let R3_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); std::string_view data = R"( import math; -let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2]), 3, x[0] * x[1] * x[2]); +let R2x2_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2])], [3, x[0] * x[1] * x[2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_IntegrateOnCells.cpp b/tests/test_IntegrateOnCells.cpp index cf2d770265fd3dbf1812b14606aa7fadda972d05..80463f0831bc21c3c172bb62b0564c261629b7f0 100644 --- a/tests/test_IntegrateOnCells.cpp +++ b/tests/test_IntegrateOnCells.cpp @@ -59,8 +59,8 @@ TEST_CASE("IntegrateOnCells", "[language]") std::string_view data = R"( import math; let scalar_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; -let R3_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); -let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); +let R3_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; +let R2x2_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -159,8 +159,8 @@ let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x std::string_view data = R"( import math; let scalar_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; -let R3_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); -let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x[0]*x[1]); +let R3_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; +let R2x2_2d: R^2 -> R^2x2, x -> [[2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1])], [3, x[0]*x[1]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -272,8 +272,8 @@ let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x std::string_view data = R"( import math; let scalar_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; -let R3_3d: R^3 -> R^3, x -> (2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3); -let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2]), 3, x[0] * x[1] * x[2]); +let R3_3d: R^3 -> R^3, x -> [2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3]; +let R2x2_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2])], [3, x[0] * x[1] * x[2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -400,8 +400,8 @@ let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin( std::string_view data = R"( import math; let scalar_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; -let R3_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); -let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); +let R3_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; +let R2x2_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -510,8 +510,8 @@ let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x std::string_view data = R"( import math; let scalar_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; -let R3_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); -let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x[0]*x[1]); +let R3_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; +let R2x2_2d: R^2 -> R^2x2, x -> [[2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1])], [3, x[0]*x[1]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -633,8 +633,8 @@ let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x std::string_view data = R"( import math; let scalar_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; -let R3_3d: R^3 -> R^3, x -> (2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3); -let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2]), 3, x[0] * x[1] * x[2]); +let R3_3d: R^3 -> R^3, x -> [2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3]; +let R2x2_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2])], [3, x[0] * x[1] * x[2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -755,8 +755,8 @@ let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin( std::string_view data = R"( import math; let scalar_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; -let R3_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); -let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); +let R3_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; +let R2x2_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -855,8 +855,8 @@ let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x std::string_view data = R"( import math; let scalar_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; -let R3_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); -let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x[0]*x[1]); +let R3_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; +let R2x2_2d: R^2 -> R^2x2, x -> [[2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1])], [3, x[0]*x[1]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -968,8 +968,8 @@ let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x std::string_view data = R"( import math; let scalar_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; -let R3_3d: R^3 -> R^3, x -> (2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3); -let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2]), 3, x[0] * x[1] * x[2]); +let R3_3d: R^3 -> R^3, x -> [2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3]; +let R2x2_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2])], [3, x[0] * x[1] * x[2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1096,8 +1096,8 @@ let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin( std::string_view data = R"( import math; let scalar_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; -let R3_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); -let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); +let R3_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; +let R2x2_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1206,8 +1206,8 @@ let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x std::string_view data = R"( import math; let scalar_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; -let R3_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); -let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x[0]*x[1]); +let R3_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; +let R2x2_2d: R^2 -> R^2x2, x -> [[2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1])], [3, x[0]*x[1]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1329,8 +1329,8 @@ let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x std::string_view data = R"( import math; let scalar_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; -let R3_3d: R^3 -> R^3, x -> (2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3); -let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2]), 3, x[0] * x[1] * x[2]); +let R3_3d: R^3 -> R^3, x -> [2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3]; +let R2x2_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2])], [3, x[0] * x[1] * x[2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1451,8 +1451,8 @@ let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin( std::string_view data = R"( import math; let scalar_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; -let R3_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); -let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); +let R3_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; +let R2x2_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1551,8 +1551,8 @@ let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x std::string_view data = R"( import math; let scalar_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; -let R3_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); -let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x[0]*x[1]); +let R3_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; +let R2x2_2d: R^2 -> R^2x2, x -> [[2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1])], [3, x[0]*x[1]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1664,8 +1664,8 @@ let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x std::string_view data = R"( import math; let scalar_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; -let R3_3d: R^3 -> R^3, x -> (2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3); -let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2]), 3, x[0] * x[1] * x[2]); +let R3_3d: R^3 -> R^3, x -> [2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3]; +let R2x2_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2])], [3, x[0] * x[1] * x[2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1792,8 +1792,8 @@ let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin( std::string_view data = R"( import math; let scalar_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; -let R3_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); -let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); +let R3_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; +let R2x2_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -1902,8 +1902,8 @@ let R2x2_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x std::string_view data = R"( import math; let scalar_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; -let R3_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); -let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x[0]*x[1]); +let R3_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; +let R2x2_2d: R^2 -> R^2x2, x -> [[2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1])], [3, x[0]*x[1]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -2025,8 +2025,8 @@ let R2x2_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x std::string_view data = R"( import math; let scalar_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; -let R3_3d: R^3 -> R^3, x -> (2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3); -let R2x2_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2]), 3, x[0] * x[1] * x[2]); +let R3_3d: R^3 -> R^3, x -> [2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3]; +let R2x2_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2])], [3, x[0] * x[1] * x[2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_InterpolateItemValue.cpp b/tests/test_InterpolateItemValue.cpp index 1d7032c660ee001d652339abc0d2daee8a825fff..45832349fd50410aa70cadfb6df74ad59156c045 100644 --- a/tests/test_InterpolateItemValue.cpp +++ b/tests/test_InterpolateItemValue.cpp @@ -56,10 +56,10 @@ TEST_CASE("InterpolateItemValue", "[language]") import math; let scalar_affine_1d: R^1 -> R, x -> 2*x[0] + 2; let scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; -let R3_affine_1d: R^1 -> R^3, x -> (2 * x[0] + 2, 3 * x[0], 2); -let R3_non_linear_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); -let R2x2_affine_1d: R^1 -> R^2x2, x -> (2 * x[0] + 3 + 2, 3 * x[0], 2 * x[0], 2); -let R2x2_non_linear_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); +let R3_affine_1d: R^1 -> R^3, x -> [2 * x[0] + 2, 3 * x[0], 2]; +let R3_non_linear_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; +let R2x2_affine_1d: R^1 -> R^2x2, x -> [[2 * x[0] + 3 + 2, 3 * x[0]], [2 * x[0], 2]]; +let R2x2_non_linear_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -227,10 +227,10 @@ let R2x2_non_linear_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x import math; let scalar_affine_2d: R^2 -> R, x -> 2*x[0] + 3*x[1] + 2; let scalar_non_linear_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; -let R3_affine_2d: R^2 -> R^3, x -> (2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1], 2 * x[1]); -let R3_non_linear_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); -let R2x2_affine_2d: R^2 -> R^2x2, x -> (2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1], 2 * x[0] + x[1], 2); -let R2x2_non_linear_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x[0]*x[1]); +let R3_affine_2d: R^2 -> R^3, x -> [2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1], 2 * x[1]]; +let R3_non_linear_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; +let R2x2_affine_2d: R^2 -> R^2x2, x -> [[2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1]], [2 * x[0] + x[1], 2]]; +let R2x2_non_linear_2d: R^2 -> R^2x2, x -> [[2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1])], [3, x[0]*x[1]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -392,10 +392,10 @@ let R2x2_non_linear_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2* import math; let scalar_affine_3d: R^3 -> R, x -> 2 * x[0] + 3 * x[1] + 2 * x[2] - 1; let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; -let R3_affine_3d: R^3 -> R^3, x -> (2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1] + 2 * x[2], 2 * x[2]); -let R3_non_linear_3d: R^3 -> R^3, x -> (2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3); -let R2x2_affine_3d: R^3 -> R^2x2, x -> (2 * x[0] + 3 * x[1] + 2 * x[2] + 1, 3 * x[0] + x[1] + 2 * x[2], 2 * x[0] + x[1] + x[2], 2); -let R2x2_non_linear_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2]), 3, x[0] * x[1] * x[2]); +let R3_affine_3d: R^3 -> R^3, x -> [2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1] + 2 * x[2], 2 * x[2]]; +let R3_non_linear_3d: R^3 -> R^3, x -> [2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3]; +let R2x2_affine_3d: R^3 -> R^2x2, x -> [[2 * x[0] + 3 * x[1] + 2 * x[2] + 1, 3 * x[0] + x[1] + 2 * x[2]], [2 * x[0] + x[1] + x[2], 2]]; +let R2x2_non_linear_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2])], [3, x[0] * x[1] * x[2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -579,10 +579,10 @@ let R2x2_non_linear_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos( import math; let scalar_affine_1d: R^1 -> R, x -> 2*x[0] + 2; let scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; -let R3_affine_1d: R^1 -> R^3, x -> (2 * x[0] + 2, 3 * x[0], 2); -let R3_non_linear_1d: R^1 -> R^3, x -> (2 * exp(x[0]) + 3, x[0] - 2, 3); -let R2x2_affine_1d: R^1 -> R^2x2, x -> (2 * x[0] + 3 + 2, 3 * x[0], 2 * x[0], 2); -let R2x2_non_linear_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0]), 3, x[0] * x[0]); +let R3_affine_1d: R^1 -> R^3, x -> [2 * x[0] + 2, 3 * x[0], 2]; +let R3_non_linear_1d: R^1 -> R^3, x -> [2 * exp(x[0]) + 3, x[0] - 2, 3]; +let R2x2_affine_1d: R^1 -> R^2x2, x -> [[2 * x[0] + 3 + 2, 3 * x[0]], [2 * x[0], 2]]; +let R2x2_non_linear_1d: R^1 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[0]) + 3, sin(x[0] - 2 * x[0])], [3, x[0] * x[0]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -758,10 +758,10 @@ let R2x2_non_linear_1d: R^1 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[0]) + 3, sin(x import math; let scalar_affine_2d: R^2 -> R, x -> 2*x[0] + 3*x[1] + 2; let scalar_non_linear_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; -let R3_affine_2d: R^2 -> R^3, x -> (2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1], 2 * x[1]); -let R3_non_linear_2d: R^2 -> R^3, x -> (2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3); -let R2x2_affine_2d: R^2 -> R^2x2, x -> (2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1], 2 * x[0] + x[1], 2); -let R2x2_non_linear_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1]), 3, x[0]*x[1]); +let R3_affine_2d: R^2 -> R^3, x -> [2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1], 2 * x[1]]; +let R3_non_linear_2d: R^2 -> R^3, x -> [2*exp(x[0])*sin(x[1])+3, x[0]-2*x[1], 3]; +let R2x2_affine_2d: R^2 -> R^2x2, x -> [[2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1]], [2 * x[0] + x[1], 2]]; +let R2x2_non_linear_2d: R^2 -> R^2x2, x -> [[2*exp(x[0])*sin(x[1])+3, sin(x[0]-2*x[1])], [3, x[0]*x[1]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; @@ -932,10 +932,10 @@ let R2x2_non_linear_2d: R^2 -> R^2x2, x -> (2*exp(x[0])*sin(x[1])+3, sin(x[0]-2* import math; let scalar_affine_3d: R^3 -> R, x -> 2 * x[0] + 3 * x[1] + 2 * x[2] - 1; let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; -let R3_affine_3d: R^3 -> R^3, x -> (2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1] + 2 * x[2], 2 * x[2]); -let R3_non_linear_3d: R^3 -> R^3, x -> (2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3); -let R2x2_affine_3d: R^3 -> R^2x2, x -> (2 * x[0] + 3 * x[1] + 2 * x[2] + 1, 3 * x[0] + x[1] + 2 * x[2], 2 * x[0] + x[1] + x[2], 2); -let R2x2_non_linear_3d: R^3 -> R^2x2, x -> (2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2]), 3, x[0] * x[1] * x[2]); +let R3_affine_3d: R^3 -> R^3, x -> [2 * x[0] + 3 * x[1] + 2, 3 * x[0] + x[1] + 2 * x[2], 2 * x[2]]; +let R3_non_linear_3d: R^3 -> R^3, x -> [2 * exp(x[0]) * sin(x[1]) + x[2] + 3, x[0] * x[2] - 2 * x[1], 3]; +let R2x2_affine_3d: R^3 -> R^2x2, x -> [[2 * x[0] + 3 * x[1] + 2 * x[2] + 1, 3 * x[0] + x[1] + 2 * x[2]], [2 * x[0] + x[1] + x[2], 2]]; +let R2x2_non_linear_3d: R^3 -> R^2x2, x -> [[2 * exp(x[0]) * sin(x[1]) + 3 * cos(x[2]), sin(x[0] - 2 * x[1] * x[2])], [3, x[0] * x[1] * x[2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_ListAffectationProcessor.cpp b/tests/test_ListAffectationProcessor.cpp index f84ee471a7b2b4621ca4ef45d7c9a07610484a38..219b9a2f16907f3d6010d3144b7d2b903455d6fa 100644 --- a/tests/test_ListAffectationProcessor.cpp +++ b/tests/test_ListAffectationProcessor.cpp @@ -49,42 +49,36 @@ TEST_CASE("ListAffectationProcessor", "[language]") { - SECTION("ListAffectations") + auto stringify = [](auto&& value) { + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); + }; + + SECTION("basic types list affectations") { SECTION("R*R^2*R^2x2*string") { - CHECK_AFFECTATION_RESULT(R"(let (x,u,A,s): R*R^2*R^2x2*string, (x,u,A,s) = (1.2, (2,3), (4,3,2,1), "foo");)", "x", - double{1.2}); - CHECK_AFFECTATION_RESULT(R"(let (x,u,A,s): R*R^2*R^2x2*string, (x,u,A,s) = (1.2, (2,3), (4,3,2,1), "foo");)", "u", - (TinyVector<2>{2, 3})); - CHECK_AFFECTATION_RESULT(R"(let (x,u,A,s): R*R^2*R^2x2*string, (x,u,A,s) = (1.2, (2,3), (4,3,2,1), "foo");)", "A", - (TinyMatrix<2>{4, 3, 2, 1})); - CHECK_AFFECTATION_RESULT(R"(let (x,u,A,s): R*R^2*R^2x2*string, (x,u,A,s) = (1.2, (2,3), (4,3,2,1), "foo");)", "s", - std::string{"foo"}); + CHECK_AFFECTATION_RESULT(R"(let (x,u,A,s): R*R^2*R^2x2*string, (x,u,A,s) = (1.2, [2,3], [[4,3],[2,1]], "foo");)", + "x", double{1.2}); + CHECK_AFFECTATION_RESULT(R"(let (x,u,A,s): R*R^2*R^2x2*string, (x,u,A,s) = (1.2, [2,3], [[4,3],[2,1]], "foo");)", + "u", (TinyVector<2>{2, 3})); + CHECK_AFFECTATION_RESULT(R"(let (x,u,A,s): R*R^2*R^2x2*string, (x,u,A,s) = (1.2, [2,3], [[4,3],[2,1]], "foo");)", + "A", (TinyMatrix<2>{4, 3, 2, 1})); + CHECK_AFFECTATION_RESULT(R"(let (x,u,A,s): R*R^2*R^2x2*string, (x,u,A,s) = (1.2, [2,3], [[4,3],[2,1]], "foo");)", + "s", std::string{"foo"}); } SECTION("compound with string conversion") { - CHECK_AFFECTATION_RESULT(R"(let z:R, z = 3; let (x,u,s):R*R^2*string, (x,u,s) = (1.2, (2,3), z);)", "s", - std::to_string(double{3})); - { - std::ostringstream os; - os << TinyVector<1>{7}; - CHECK_AFFECTATION_RESULT(R"(let v:R^1, v = 7; let (x,u,s):R*R^2*string, (x,u,s) = (1.2, (2,3), v);)", "s", - os.str()); - } - { - std::ostringstream os; - os << TinyVector<2>{6, 3}; - CHECK_AFFECTATION_RESULT(R"(let v: R^2, v = (6,3); let (x,u,s):R*R^2*string, (x,u,s) = (1.2, (2,3), v);)", "s", - os.str()); - } - { - std::ostringstream os; - os << TinyVector<3>{1, 2, 3}; - CHECK_AFFECTATION_RESULT(R"(let v:R^3, v = (1,2,3); let (x,u,s):R*R^2*string, (x,u,s) = (1.2, (2,3), v);)", "s", - os.str()); - } + CHECK_AFFECTATION_RESULT(R"(let z:R, z = 3; let (x,u,s):R*R^2*string, (x,u,s) = (1.2, [2,3], z);)", "s", + stringify(double{3})); + CHECK_AFFECTATION_RESULT(R"(let v:R^1, v = 7; let (x,u,s):R*R^2*string, (x,u,s) = (1.2, [2,3], v);)", "s", + stringify(TinyVector<1>{7})); + CHECK_AFFECTATION_RESULT(R"(let v: R^2, v = [6,3]; let (x,u,s):R*R^2*string, (x,u,s) = (1.2, [2,3], v);)", "s", + stringify(TinyVector<2>{6, 3})); + CHECK_AFFECTATION_RESULT(R"(let v:R^3, v = [1,2,3]; let (x,u,s):R*R^2*string, (x,u,s) = (1.2, [2,3], v);)", "s", + stringify(TinyVector<3>{1, 2, 3})); } SECTION("compound R^d from '0'") @@ -101,4 +95,647 @@ TEST_CASE("ListAffectationProcessor", "[language]") CHECK_AFFECTATION_RESULT(R"(let (x,y,z):R^3x3*R^2x2*R^1x1, (x,y,z) = (0,0,0);)", "z", (TinyMatrix<1>{zero})); } } + + SECTION("lists with tuples affectation") + { + auto stringify = [](auto&& value) { + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); + }; + + SECTION("with (B)") + { + SECTION("from value") + { + std::string_view data = R"( +let (b1,b2): (B)*(B), (b1,b2) = (false, true); +)"; + + CHECK_AFFECTATION_RESULT(data, "b1", (std::vector<bool>{false})); + CHECK_AFFECTATION_RESULT(data, "b2", (std::vector<bool>{true})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (b1,b2): (B)*B, (b1,b2) = ((true,false), true); +)"; + + CHECK_AFFECTATION_RESULT(data, "b1", (std::vector<bool>{true, false})); + CHECK_AFFECTATION_RESULT(data, "b2", true); + } + + SECTION("from (B)") + { + std::string_view data = R"( +let b : (B), b = (true, false); +let (b1,b2) : (B)*B, (b1,b2) = (b, false); +)"; + CHECK_AFFECTATION_RESULT(data, "b1", (std::vector<bool>{true, false})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + } + + SECTION("(N)") + { + SECTION("from value") + { + std::string_view data = R"( +let n:N, n = 9; +let (n1,n2,n3): (N)*(N)*(N), (n1,n2,n3) = (false, 1, n); +)"; + + CHECK_AFFECTATION_RESULT(data, "n1", (std::vector<uint64_t>{false})); + CHECK_AFFECTATION_RESULT(data, "n2", (std::vector<uint64_t>{1})); + CHECK_AFFECTATION_RESULT(data, "n3", (std::vector<uint64_t>{9})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (n,m) :(N)*N, (n,m) = ((1,2,3), 7); +)"; + CHECK_AFFECTATION_RESULT(data, "n", (std::vector<uint64_t>{1, 2, 3})); + CHECK_AFFECTATION_RESULT(data, "m", 7ul); + } + + SECTION("from (B)") + { + std::string_view data = R"( +let b :(B), b = (true,false,true); +let (n,m) :(N)*(N), (n,m) = (b, (false,true)); +)"; + CHECK_AFFECTATION_RESULT(data, "n", (std::vector<uint64_t>{1, 0, 1})); + CHECK_AFFECTATION_RESULT(data, "m", (std::vector<uint64_t>{0, 1})); + } + + SECTION("from (N)") + { + std::string_view data = R"( +let l:(N), l = (1,2,3); +let (n,m):(N)*(N), (n,m) = (l,(2,3,1)); +)"; + CHECK_AFFECTATION_RESULT(data, "n", (std::vector<uint64_t>{1, 2, 3})); + CHECK_AFFECTATION_RESULT(data, "m", (std::vector<uint64_t>{2, 3, 1})); + } + + SECTION("from (Z)") + { + std::string_view data = R"( +let z:(Z), z = (1,2,3); +let (n,x):(N)*R, (n,x) = (z,2.3); +)"; + CHECK_AFFECTATION_RESULT(data, "n", (std::vector<uint64_t>{1, 2, 3})); + CHECK_AFFECTATION_RESULT(data, "x", double{2.3}); + } + } + + SECTION("(Z)") + { + SECTION("from value") + { + std::string_view data = R"( +let n:N, n = 9; +let (z1,z2,z3): (Z)*(Z)*(Z), (z1,z2,z3) = (false, -1, n); +)"; + + CHECK_AFFECTATION_RESULT(data, "z1", (std::vector<int64_t>{false})); + CHECK_AFFECTATION_RESULT(data, "z2", (std::vector<int64_t>{-1})); + CHECK_AFFECTATION_RESULT(data, "z3", (std::vector<int64_t>{9})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (z1,z2):(Z)*(Z), (z1,z2) = ((1,2,3),(2,1,3)); +)"; + CHECK_AFFECTATION_RESULT(data, "z1", (std::vector<int64_t>{1, 2, 3})); + CHECK_AFFECTATION_RESULT(data, "z2", (std::vector<int64_t>{2, 1, 3})); + } + + SECTION("from (N)") + { + std::string_view data = R"( +let m : (N), m = (1,2,3); +let (z,n) : (Z)*N, (z,n) = (m,2); +)"; + CHECK_AFFECTATION_RESULT(data, "z", (std::vector<int64_t>{1, 2, 3})); + CHECK_AFFECTATION_RESULT(data, "n", 2ul); + } + + SECTION("from (Z)") + { + std::string_view data = R"( +let z0:(Z), z0 = (1,2,3); +let (z,a): (Z)*Z, (z,a) = (z0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "z", (std::vector<int64_t>{1, 2, 3})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + } + + SECTION("(R)") + { + SECTION("from value") + { + std::string_view data = R"( +let n:N, n = 9; +let (r1,r2,r3,r4): (R)*(R)*(R)*(R), (r1,r2,r3,r4) = (false, -1, n, 2.3); +)"; + + CHECK_AFFECTATION_RESULT(data, "r1", (std::vector<double>{false})); + CHECK_AFFECTATION_RESULT(data, "r2", (std::vector<double>{-1})); + CHECK_AFFECTATION_RESULT(data, "r3", (std::vector<double>{9})); + CHECK_AFFECTATION_RESULT(data, "r4", (std::vector<double>{2.3})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (r1,r2):(R)*(R), (r1,r2) = ((1.2,2,3.1),(2.4,1,1.3)); +)"; + CHECK_AFFECTATION_RESULT(data, "r1", (std::vector<double>{1.2, 2, 3.1})); + CHECK_AFFECTATION_RESULT(data, "r2", (std::vector<double>{2.4, 1, 1.3})); + } + + SECTION("from (N)") + { + std::string_view data = R"( +let m : (N), m = (1,2,3); +let (r,n) : (R)*N, (r,n) = (m,2); +)"; + CHECK_AFFECTATION_RESULT(data, "r", (std::vector<double>{1, 2, 3})); + CHECK_AFFECTATION_RESULT(data, "n", 2ul); + } + + SECTION("from (Z)") + { + std::string_view data = R"( +let z0:(Z), z0 = (1,2,3); +let (r,a): (R)*Z, (r,a) = (z0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "r", (std::vector<double>{1, 2, 3})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + + SECTION("from (R)") + { + std::string_view data = R"( +let r0:(R), r0 = (1.2,2,3); +let (r,a): (R)*Z, (r,a) = (r0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "r", (std::vector<double>{1.2, 2, 3})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + } + + SECTION("(R^1)") + { + using R1 = TinyVector<1>; + + SECTION("from value") + { + std::string_view data = R"( +let n:N, n = 9; +let (X1,X2,X3,X4,X5): (R^1)*(R^1)*(R^1)*(R^1)*(R^1), (X1,X2,X3,X4,X5) = (false, -1, n, 2.3, [7.2]); +)"; + + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R1>{R1(false)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R1>{R1(-1)})); + CHECK_AFFECTATION_RESULT(data, "X3", (std::vector<R1>{R1(9)})); + CHECK_AFFECTATION_RESULT(data, "X4", (std::vector<R1>{R1(2.3)})); + CHECK_AFFECTATION_RESULT(data, "X5", (std::vector<R1>{R1(7.2)})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (X1,X2):(R^1)*(R^1), (X1,X2) = (([1.2],2,3.1),([2.4],1, true,1.3)); +)"; + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R1>{R1(1.2), R1(2), R1(3.1)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R1>{R1(2.4), R1(1), R1(true), R1(1.3)})); + } + + SECTION("from (N)") + { + std::string_view data = R"( +let m : (N), m = (1,2,3); +let (X,n) : (R^1)*N, (X,n) = (m,2); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R1>{R1(1), R1(2), R1(3)})); + CHECK_AFFECTATION_RESULT(data, "n", 2ul); + } + + SECTION("from (Z)") + { + std::string_view data = R"( +let z0:(Z), z0 = (1,2,3); +let (X,a): (R^1)*Z, (X,a) = (z0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R1>{R1(1), R1(2), R1(3)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + + SECTION("from (R)") + { + std::string_view data = R"( +let r0:(R), r0 = (1.2,2,3); +let (X,a): (R^1)*Z, (X,a) = (r0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R1>{R1(1.2), R1(2), R1(3)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + + SECTION("from (R^1)") + { + std::string_view data = R"( +let X0:(R^1), X0 = (1.2,2,3); +let (X,a): (R^1)*Z, (X,a) = (X0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R1>{R1(1.2), R1(2), R1(3)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + } + + SECTION("R^2") + { + using R2 = TinyVector<2>; + + SECTION("from value") + { + std::string_view data = R"( +let (X1,X2): (R^2)*(R^2), (X1,X2) = ([1,2], 0); +)"; + + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R2>{R2(1, 2)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R2>{R2(0, 0)})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (X1,X2):(R^2)*(R^2), (X1,X2) = (([1.2, 2],0,[3,1]),([2.4,1],[true,1.3])); +)"; + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R2>{R2(1.2, 2), R2(0, 0), R2(3, 1)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R2>{R2(2.4, 1), R2(true, 1.3)})); + } + + SECTION("from (R^2)") + { + std::string_view data = R"( +let X0:(R^2), X0 = ([1.2,2],[3,1],0); +let (X,a): (R^2)*Z, (X,a) = (X0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R2>{R2(1.2, 2), R2(3, 1), R2(0, 0)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + } + + SECTION("R^3") + { + using R3 = TinyVector<3>; + + SECTION("from value") + { + std::string_view data = R"( +let (X1,X2): (R^3)*(R^3), (X1,X2) = ([1,2,3], 0); +)"; + + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R3>{R3(1, 2, 3)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R3>{R3(0, 0, 0)})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (X1,X2):(R^3)*(R^3), (X1,X2) = (([5, 1.2, 2],0,[3,6,1]),([2.4,1,1.3],[true,1.3,2])); +)"; + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R3>{R3(5, 1.2, 2), R3(0, 0, 0), R3(3, 6, 1)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R3>{R3(2.4, 1, 1.3), R3(true, 1.3, 2)})); + } + + SECTION("from (R^3)") + { + std::string_view data = R"( +let X0:(R^3), X0 = ([1.2,-1.3,2],[3,1,5],0); +let (X,a): (R^3)*Z, (X,a) = (X0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R3>{R3(1.2, -1.3, 2), R3(3, 1, 5), R3(0, 0, 0)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + } + + SECTION("R^1x1") + { + using R1x1 = TinyMatrix<1>; + + SECTION("from value") + { + std::string_view data = R"( +let n:N, n = 9; +let (X1,X2,X3,X4,X5): (R^1x1)*(R^1x1)*(R^1x1)*(R^1x1)*(R^1x1), (X1,X2,X3,X4,X5) = (false, -1, n, 2.3, [[7.2]]); +)"; + + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R1x1>{R1x1(false)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R1x1>{R1x1(-1)})); + CHECK_AFFECTATION_RESULT(data, "X3", (std::vector<R1x1>{R1x1(9)})); + CHECK_AFFECTATION_RESULT(data, "X4", (std::vector<R1x1>{R1x1(2.3)})); + CHECK_AFFECTATION_RESULT(data, "X5", (std::vector<R1x1>{R1x1(7.2)})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (X1,X2):(R^1x1)*(R^1x1), (X1,X2) = (([[1.2]],2,3.1),([[2.4]],1, true,1.3)); +)"; + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R1x1>{R1x1(1.2), R1x1(2), R1x1(3.1)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R1x1>{R1x1(2.4), R1x1(1), R1x1(true), R1x1(1.3)})); + } + + SECTION("from (N)") + { + std::string_view data = R"( +let m : (N), m = (1,2,3); +let (X,n) : (R^1x1)*N, (X,n) = (m,2); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R1x1>{R1x1(1), R1x1(2), R1x1(3)})); + CHECK_AFFECTATION_RESULT(data, "n", 2ul); + } + + SECTION("from (Z)") + { + std::string_view data = R"( +let z0:(Z), z0 = (1,2,3); +let (X,a): (R^1x1)*Z, (X,a) = (z0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R1x1>{R1x1(1), R1x1(2), R1x1(3)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + + SECTION("from (R)") + { + std::string_view data = R"( +let r0:(R), r0 = (1.2,2,3); +let (X,a): (R^1x1)*Z, (X,a) = (r0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R1x1>{R1x1(1.2), R1x1(2), R1x1(3)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + + SECTION("from (R^1x1)") + { + std::string_view data = R"( +let X0:(R^1x1), X0 = (1.2,2,3); +let (X,a): (R^1x1)*Z, (X,a) = (X0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", (std::vector<R1x1>{R1x1(1.2), R1x1(2), R1x1(3)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + } + + SECTION("R^2x2") + { + using R2x2 = TinyMatrix<2>; + + SECTION("from value") + { + std::string_view data = R"( +let (X1,X2): (R^2x2)*(R^2x2), (X1,X2) = ([[1,2],[3,4]], 0); +)"; + + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R2x2>{R2x2(1, 2, 3, 4)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R2x2>{R2x2(0, 0, 0, 0)})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (X1,X2):(R^2x2)*(R^2x2), (X1,X2) = (([[1.2, 2],[7,4]],0,[[3,1],[5,2]]),([[2.4,1],[1,3]],[[true,1.3],[2,2]])); +)"; + CHECK_AFFECTATION_RESULT(data, "X1", + (std::vector<R2x2>{R2x2(1.2, 2, 7, 4), R2x2(0, 0, 0, 0), R2x2(3, 1, 5, 2)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R2x2>{R2x2(2.4, 1, 1, 3), R2x2(true, 1.3, 2, 2)})); + } + + SECTION("from (R^2x2)") + { + std::string_view data = R"( +let X0:(R^2x2), X0 = ([[1.2,2],[3,1]],[[3,1],[5,8]],0); +let (X,a): (R^2x2)*Z, (X,a) = (X0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", + (std::vector<R2x2>{R2x2(1.2, 2, 3, 1), R2x2(3, 1, 5, 8), R2x2(0, 0, 0, 0)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + } + + SECTION("R^3x3") + { + using R3x3 = TinyMatrix<3>; + + SECTION("from value") + { + std::string_view data = R"( +let (X1,X2): (R^3x3)*(R^3x3), (X1,X2) = ([[1,2,3],[4,5,6],[7,8,9]], 0); +)"; + + CHECK_AFFECTATION_RESULT(data, "X1", (std::vector<R3x3>{R3x3(1, 2, 3, 4, 5, 6, 7, 8, 9)})); + CHECK_AFFECTATION_RESULT(data, "X2", (std::vector<R3x3>{R3x3(0, 0, 0, 0, 0, 0, 0, 0, 0)})); + } + + SECTION("from list") + { + std::string_view data = R"( +let (X1,X2):(R^3x3)*(R^3x3), (X1,X2) = (([[1.2, 2, 1],[3,1,9],[7,5,4]],0,[[3,0.3,1],[5,7,2],[2,1,8]]),([[3,2.4,1],[2,1,3],[2.2,1.8,3]],[[true,2,1.3],[2.1,4,2],[1.2,2.4,1.2]])); +)"; + CHECK_AFFECTATION_RESULT(data, "X1", + (std::vector<R3x3>{R3x3(1.2, 2, 1, 3, 1, 9, 7, 5, 4), R3x3(0, 0, 0, 0, 0, 0, 0, 0, 0), + R3x3(3, 0.3, 1, 5, 7, 2, 2, 1, 8)})); + CHECK_AFFECTATION_RESULT(data, "X2", + (std::vector<R3x3>{R3x3(3, 2.4, 1, 2, 1, 3, 2.2, 1.8, 3), + R3x3(true, 2, 1.3, 2.1, 4, 2, 1.2, 2.4, 1.2)})); + } + + SECTION("from (R^3x3)") + { + std::string_view data = R"( +let X0:(R^3x3), X0 = ([[1.2,7,2],[2,1,6],[1,3,1]],[[3,1,6],[2,7,1],[1,5,8]]); +let (X,a): (R^3x3)*Z, (X,a) = (X0,3); +)"; + CHECK_AFFECTATION_RESULT(data, "X", + (std::vector<R3x3>{R3x3(1.2, 7, 2, 2, 1, 6, 1, 3, 1), + R3x3(3, 1, 6, 2, 7, 1, 1, 5, 8)})); + CHECK_AFFECTATION_RESULT(data, "a", 3l); + } + } + + SECTION("with (string)") + { + SECTION("from value") + { + std::string_view data = R"( +let n: N, n = 3; +let (s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11) + : (string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string)*(string), + (s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11) = (false, n, 1, 1.3, [1], [1,2], [1,2,3], [[1]], [[1,2],[3,4]], [[1,2,3],[4,5,6],[7,8,9]], "foo"); +)"; + + CHECK_AFFECTATION_RESULT(data, "s1", (std::vector<std::string>{stringify(false)})); + CHECK_AFFECTATION_RESULT(data, "s2", (std::vector<std::string>{stringify(3ul)})); + CHECK_AFFECTATION_RESULT(data, "s3", (std::vector<std::string>{stringify(1l)})); + CHECK_AFFECTATION_RESULT(data, "s4", (std::vector<std::string>{stringify(double{1.3})})); + CHECK_AFFECTATION_RESULT(data, "s5", (std::vector<std::string>{stringify(TinyVector<1>{1})})); + CHECK_AFFECTATION_RESULT(data, "s6", (std::vector<std::string>{stringify(TinyVector<2>{1, 2})})); + CHECK_AFFECTATION_RESULT(data, "s7", (std::vector<std::string>{stringify(TinyVector<3>{1, 2, 3})})); + CHECK_AFFECTATION_RESULT(data, "s8", (std::vector<std::string>{stringify(TinyMatrix<1>{1})})); + CHECK_AFFECTATION_RESULT(data, "s9", (std::vector<std::string>{stringify(TinyMatrix<2>{1, 2, 3, 4})})); + CHECK_AFFECTATION_RESULT(data, "s10", + (std::vector<std::string>{stringify(TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9})})); + CHECK_AFFECTATION_RESULT(data, "s11", (std::vector<std::string>{stringify("foo")})); + } + + SECTION("from list") + { + std::string_view data = R"( +let n: N, n = 3; +let (s1,s2): (string)*string, + (s1,s2) = ((false, n, 1, 1.3, [1], [1,2], [1,2,3], [[1]], [[1,2],[3,4]], [[1,2,3],[4,5,6],[7,8,9]], "foo"), "bar"); +)"; + + CHECK_AFFECTATION_RESULT(data, "s1", + (std::vector<std::string>{stringify(false), stringify(3ul), stringify(1l), + stringify(double{1.3}), stringify(TinyVector<1>{1}), + stringify(TinyVector<2>{1, 2}), + stringify(TinyVector<3>{1, 2, 3}), + stringify(TinyMatrix<1>{1}), + stringify(TinyMatrix<2>{1, 2, 3, 4}), + stringify(TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9}), + stringify("foo")})); + CHECK_AFFECTATION_RESULT(data, "s2", std::string("bar")); + } + + SECTION("from (B)") + { + std::string_view data = R"( +let b : (B), b = (true, false); +let (s1,b2) : (string)*B, (s1,b2) = (b, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", (std::vector<std::string>{stringify(true), stringify(false)})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (N)") + { + std::string_view data = R"( +let n : (N), n = (1, 2); +let (s1,b2) : (string)*B, (s1,b2) = (n, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", (std::vector<std::string>{stringify(1ul), stringify(2ul)})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (Z)") + { + std::string_view data = R"( +let z : (Z), z = (1, -2); +let (s1,b2) : (string)*B, (s1,b2) = (z, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", (std::vector<std::string>{stringify(1l), stringify(-2l)})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (R)") + { + std::string_view data = R"( +let r : (R), r = (1, -2.3); +let (s1,b2) : (string)*B, (s1,b2) = (r, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", (std::vector<std::string>{stringify(double{1}), stringify(double{-2.3})})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (R^1)") + { + std::string_view data = R"( +let r : (R^1), r = (1, -2.3); +let (s1,b2) : (string)*B, (s1,b2) = (r, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", + (std::vector<std::string>{stringify(TinyVector<1>{1}), + stringify(TinyVector<1>{-2.3})})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (R^2)") + { + std::string_view data = R"( +let r : (R^2), r = ([1,2],[-2.3,4]); +let (s1,b2) : (string)*B, (s1,b2) = (r, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", + (std::vector<std::string>{stringify(TinyVector<2>{1, 2}), + stringify(TinyVector<2>{-2.3, 4})})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (R^3)") + { + std::string_view data = R"( +let r : (R^3), r = ([1,2,3],[-2.3,4,7]); +let (s1,b2) : (string)*B, (s1,b2) = (r, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", + (std::vector<std::string>{stringify(TinyVector<3>{1, 2, 3}), + stringify(TinyVector<3>{-2.3, 4, 7})})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (R^1x1)") + { + std::string_view data = R"( +let r : (R^1x1), r = (1, -2.3); +let (s1,b2) : (string)*B, (s1,b2) = (r, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", + (std::vector<std::string>{stringify(TinyMatrix<1>{1}), + stringify(TinyMatrix<1>{-2.3})})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (R^2x2)") + { + std::string_view data = R"( +let r : (R^2x2), r = ([[1,2],[3,4]], [[-2.3,4],[7,2]]); +let (s1,b2) : (string)*B, (s1,b2) = (r, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", + (std::vector<std::string>{stringify(TinyMatrix<2>{1, 2, 3, 4}), + stringify(TinyMatrix<2>{-2.3, 4, 7, 2})})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (R^3)") + { + std::string_view data = R"( +let r : (R^3x3), r = ([[1,2,3],[4,5,6],[7,8,9]], [[-2.3,4,7],[6,2,1],[8,3,4]]); +let (s1,b2) : (string)*B, (s1,b2) = (r, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", + (std::vector<std::string>{stringify(TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9}), + stringify(TinyMatrix<3>{-2.3, 4, 7, 6, 2, 1, 8, 3, 4})})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + + SECTION("from (string)") + { + std::string_view data = R"( +let s : (string), s = ("foo", "bar", "foobar"); +let (s1,b2) : (string)*B, (s1,b2) = (s, false); +)"; + CHECK_AFFECTATION_RESULT(data, "s1", (std::vector<std::string>{"foo", "bar", "foobar"})); + CHECK_AFFECTATION_RESULT(data, "b2", false); + } + } + } } diff --git a/tests/test_PugsFunctionAdapter.cpp b/tests/test_PugsFunctionAdapter.cpp index d8708c49a9601d38602251a5179cad939382f291..9e645802fde6e286abfeb57e7c4c35dd584583c4 100644 --- a/tests/test_PugsFunctionAdapter.cpp +++ b/tests/test_PugsFunctionAdapter.cpp @@ -72,7 +72,7 @@ let BandB: B*B -> B, (a,b) -> a and b; let NplusN: N*N -> N, (x,y) -> x+y; let ZplusZ: Z*Z -> Z, (x,y) -> x+y; let RplusR: R*R -> R, (x,y) -> x+y; -let RRtoR2: R*R -> R^2, (x,y) -> (x+y, x-y); +let RRtoR2: R*R -> R^2, (x,y) -> [x+y, x-y]; let R3times2: R^3 -> R^3, x -> 2*x; let R33times2: R^3x3 -> R^3x3, x -> 2*x; let BtoR1: B -> R^1, b -> not b; @@ -368,11 +368,11 @@ let R33toR33zero: R^3x3 -> R^3x3, x -> 0; std::string_view data = R"( let R1toR1: R^1 -> R^1, x -> x; let R3toR3: R^3 -> R^3, x -> 0; -let RRRtoR3: R*R*R -> R^3, (x,y,z) -> (x,y,z); -let R3toR2: R^3 -> R^2, x -> (x[0],x[1]+x[2]); +let RRRtoR3: R*R*R -> R^3, (x,y,z) -> [x,y,z]; +let R3toR2: R^3 -> R^2, x -> [x[0],x[1]+x[2]]; let RtoNS: R -> N*string, x -> (1, "foo"); let RtoR: R -> R, x -> 2*x; -let R33toR22: R^3x3 -> R^2x2, x -> (x[0,0], x[0,1]+x[0,2], x[2,0]*x[1,1], x[2,1]+x[2,2]); +let R33toR22: R^3x3 -> R^2x2, x -> [[x[0,0], x[0,1]+x[0,2]], [x[2,0]*x[1,1], x[2,1]+x[2,2]]]; )"; TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; diff --git a/tests/test_TinyMatrix.cpp b/tests/test_TinyMatrix.cpp index 81c187dc2f5c7663fb7491cfa5c68fc2fc2d7eb6..2f4c09d4ad9ce1dbb5e3d856d8737d27344459f2 100644 --- a/tests/test_TinyMatrix.cpp +++ b/tests/test_TinyMatrix.cpp @@ -272,8 +272,8 @@ TEST_CASE("TinyMatrix", "[algebra]") SECTION("checking for matrices output") { - REQUIRE(Catch::Detail::stringify(A) == "[(1,2,3,4)(5,6,7,8)(9,10,11,12)]"); - REQUIRE(Catch::Detail::stringify(TinyMatrix<1, 1, int>(7)) == "[(7)]"); + REQUIRE(Catch::Detail::stringify(A) == "[[1,2,3,4],[5,6,7,8],[9,10,11,12]]"); + REQUIRE(Catch::Detail::stringify(TinyMatrix<1, 1, int>(7)) == "[[7]]"); } #ifndef NDEBUG @@ -287,7 +287,7 @@ TEST_CASE("TinyMatrix", "[algebra]") A_ost << A; std::ostringstream ref_ost; - ref_ost << "[(1,nan,3)(2,nan,nan)]"; + ref_ost << "[[1,nan,3],[2,nan,nan]]"; REQUIRE(A_ost.str() == ref_ost.str()); } diff --git a/tests/test_TinyVector.cpp b/tests/test_TinyVector.cpp index 0613e721cbce46386e6b1c86c3bc3e1123fdd1aa..9c4dc2e5a2c4b185904fcf04a706fa70b572a197 100644 --- a/tests/test_TinyVector.cpp +++ b/tests/test_TinyVector.cpp @@ -30,7 +30,7 @@ TEST_CASE("TinyVector", "[algebra]") REQUIRE(((z[0] == 0) and (z[1] == 0) and (z[2] == 0))); v = TinyVector<3, int>(3, 2, 4); - REQUIRE(Catch::Detail::stringify(v) == "(3,2,4)"); + REQUIRE(Catch::Detail::stringify(v) == "[3,2,4]"); TinyVector<3, int> w(1, 2, 6); REQUIRE(dot(v, w) == 31); @@ -96,7 +96,7 @@ TEST_CASE("TinyVector", "[algebra]") x_ost << x; std::ostringstream ref_ost; - ref_ost << "(nan,1,nan)"; + ref_ost << "[nan,1,nan]"; REQUIRE(x_ost.str() == ref_ost.str()); } diff --git a/tests/test_TupleToVectorProcessor.cpp b/tests/test_TupleToVectorProcessor.cpp index 817e5c9ba54af0664a34045d5de528f80c59db4a..74865d2ce1019e19e2474f059fde4708a2e5e735 100644 --- a/tests/test_TupleToVectorProcessor.cpp +++ b/tests/test_TupleToVectorProcessor.cpp @@ -77,17 +77,17 @@ TEST_CASE("TupleToVectorProcessor", "[language]") SECTION("Return tuple -> R^3") { std::string_view data = R"( -let f: R*R*R->R^3, (x,y,z) -> (x,y,z); +let f: R*R*R->R^3, (x,y,z) -> [y,z,x]; let x:R^3, x = f(1,2,3); )"; - CHECK_EVALUATION_RESULT(data, "x", (TinyVector<3>{1, 2, 3})); + CHECK_EVALUATION_RESULT(data, "x", (TinyVector<3>{2, 3, 1})); } SECTION("Return tuple -> R^2") { std::string_view data = R"( -let f: R^3->R^2, x -> (x[2],x[1]); -let x:R^3, x = (1,2,3); +let f: R^3->R^2, x -> [x[2],x[1]]; +let x:R^3, x = [1,2,3]; let y:R^2, y = f(x); )"; CHECK_EVALUATION_RESULT(data, "y", (TinyVector<2>{3, 2}));