Skip to content
Snippets Groups Projects

Add R^dxd and R^d expressions in pugs' language (with d=1,2 or 3)

1 file
+ 43
49
Compare changes
  • Side-by-side
  • Inline
@@ -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)
{
@@ -96,29 +105,19 @@ class AffectationExecutor final : public IAffectationExecutor
affect(ExecutionPolicy&, DataVariant&& rhs)
{
if constexpr (m_is_defined) {
auto stringify = [](auto&& value) {
std::ostringstream os;
if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) {
os << std::boolalpha << value;
} else {
os << value;
}
return os.str();
};
if constexpr (not std::is_same_v<DataT, ZeroType>) {
if constexpr (std::is_same_v<ValueT, std::string>) {
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 {
m_lhs = std::move(stringify(std::get<DataT>(rhs)));
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 {
m_lhs += std::move(stringify(std::get<DataT>(rhs)));
m_lhs += std::move(_stringify(std::get<DataT>(rhs)));
}
}
} else {
@@ -184,9 +183,16 @@ class AffectationExecutor final : public IAffectationExecutor
std::visit(
[&](auto&& v) {
if constexpr (is_std_vector_v<std::decay_t<decltype(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) {
m_lhs[i] = std::move(stringify(v[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
@@ -270,7 +276,7 @@ class AffectationExecutor final : public IAffectationExecutor
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));
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>>) {
@@ -320,7 +326,7 @@ class AffectationExecutor final : public IAffectationExecutor
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));
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>>) {
@@ -443,20 +449,19 @@ class AffectationToTupleProcessor final : public AffectationToDataVariantProcess
private:
ASTNode& m_rhs_node;
template <typename T>
std::string
_stringify(const T& value)
{
std::ostringstream os;
os << std::boolalpha << value;
return os.str();
}
public:
DataVariant
execute(ExecutionPolicy& exec_policy)
{
auto stringify = [](auto&& value) {
std::ostringstream os;
if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) {
os << std::boolalpha << value;
} else {
os << value;
}
return os.str();
};
DataVariant value = m_rhs_node.execute(exec_policy);
std::visit(
@@ -467,7 +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>) {
*m_lhs = std::vector{std::move(stringify(v))};
*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)}};
@@ -503,19 +508,18 @@ 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)
{
auto stringify = [](auto&& value) {
std::ostringstream os;
if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) {
os << std::boolalpha << value;
} else {
os << value;
}
return os.str();
};
std::vector<ValueT> tuple_value(children_values.size());
for (size_t i = 0; i < children_values.size(); ++i) {
std::visit(
@@ -526,7 +530,7 @@ 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>) {
tuple_value[i] = std::move(stringify(child_value));
tuple_value[i] = std::move(_stringify(child_value));
} else if constexpr (is_tiny_vector_v<ValueT>) {
if constexpr (std::is_arithmetic_v<T>) {
if constexpr (std::is_same_v<ValueT, TinyVector<1>>) {
@@ -573,16 +577,6 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian
void
_copyVector(const std::vector<DataType>& values)
{
auto stringify = [](auto&& value) {
std::ostringstream os;
if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) {
os << std::boolalpha << value;
} else {
os << value;
}
return os.str();
};
std::vector<ValueT> v(values.size());
if constexpr (std::is_same_v<ValueT, DataType>) {
for (size_t i = 0; i < values.size(); ++i) {
@@ -594,7 +588,7 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian
}
} else if constexpr (std::is_same_v<ValueT, std::string>) {
for (size_t i = 0; i < values.size(); ++i) {
v[i] = std::move(stringify(values[i]));
v[i] = std::move(_stringify(values[i]));
}
} else {
// LCOV_EXCL_START
Loading