/** * Makes an unaligned type to view the given type without alignment requirements. */ inline ndt::type make_view(const ndt::type& value_type, const ndt::type& operand_type) { if (value_type.get_kind() != expr_kind) { return ndt::type(new view_type(value_type, operand_type), false); } else { // When the value type has an expr_kind, we need to chain things together // so that the view operation happens just at the primitive level. return value_type.extended<base_expr_type>()->with_replaced_storage_type( ndt::type(new view_type(value_type.storage_type(), operand_type), false)); } }
/** * Makes a conversion type to convert from the operand_type to the value_type. * If the value_type has expression_kind, it chains operand_type.value_type() * into value_type.storage_type(). */ inline ndt::type make_convert(const ndt::type& value_type, const ndt::type& operand_type, assign_error_mode errmode = assign_error_default) { if (operand_type.value_type() != value_type) { if (value_type.get_kind() != expression_kind) { // Create a conversion type when the value kind is different return ndt::type(new convert_type(value_type, operand_type, errmode), false); } else if (value_type.storage_type() == operand_type.value_type()) { // No conversion required at the connection return static_cast<const base_expression_type *>( value_type.extended())->with_replaced_storage_type(operand_type); } else { // A conversion required at the connection return static_cast<const base_expression_type *>( value_type.extended())->with_replaced_storage_type( ndt::type(new convert_type( value_type.storage_type(), operand_type, errmode), false)); } } else { return operand_type; } }
ndt::type ndt::make_unaligned(const ndt::type& value_type) { if (value_type.get_data_alignment() > 1) { // Only do something if it requires alignment if (value_type.get_kind() != expr_kind) { return ndt::make_view( value_type, ndt::make_fixed_bytes(value_type.get_data_size(), 1)); } else { const ndt::type &sdt = value_type.storage_type(); return ndt::type( value_type.extended<base_expr_type>()->with_replaced_storage_type( ndt::make_view(sdt, ndt::make_fixed_bytes(sdt.get_data_size(), 1)))); } } else { return value_type; } }