@@ -209,10 +209,12 @@ template <typename TO, TypeCategory FROMCAT = TO::category>
209
209
struct Convert : public Operation <Convert<TO, FROMCAT>, TO, SomeKind<FROMCAT>> {
210
210
// Fortran doesn't have conversions between kinds of CHARACTER apart from
211
211
// assignments, and in those the data must be convertible to/from 7-bit ASCII.
212
- static_assert (((TO::category == TypeCategory::Integer ||
213
- TO::category == TypeCategory::Real) &&
214
- (FROMCAT == TypeCategory::Integer ||
215
- FROMCAT == TypeCategory::Real)) ||
212
+ static_assert (
213
+ ((TO::category == TypeCategory::Integer ||
214
+ TO::category == TypeCategory::Real ||
215
+ TO::category == TypeCategory::Unsigned) &&
216
+ (FROMCAT == TypeCategory::Integer || FROMCAT == TypeCategory::Real ||
217
+ FROMCAT == TypeCategory::Unsigned)) ||
216
218
TO::category == FROMCAT);
217
219
using Result = TO;
218
220
using Operand = SomeKind<FROMCAT>;
@@ -526,7 +528,8 @@ class Expr<Type<TypeCategory::Integer, KIND>>
526
528
527
529
private:
528
530
using Conversions = std::tuple<Convert<Result, TypeCategory::Integer>,
529
- Convert<Result, TypeCategory::Real>>;
531
+ Convert<Result, TypeCategory::Real>,
532
+ Convert<Result, TypeCategory::Unsigned>>;
530
533
using Operations = std::tuple<Parentheses<Result>, Negate<Result>,
531
534
Add<Result>, Subtract<Result>, Multiply<Result>, Divide<Result>,
532
535
Power<Result>, Extremum<Result>>;
@@ -547,6 +550,29 @@ class Expr<Type<TypeCategory::Integer, KIND>>
547
550
u;
548
551
};
549
552
553
+ template <int KIND>
554
+ class Expr <Type<TypeCategory::Unsigned, KIND>>
555
+ : public ExpressionBase<Type<TypeCategory::Unsigned, KIND>> {
556
+ public:
557
+ using Result = Type<TypeCategory::Unsigned, KIND>;
558
+
559
+ EVALUATE_UNION_CLASS_BOILERPLATE (Expr)
560
+
561
+ private:
562
+ using Conversions = std::tuple<Convert<Result, TypeCategory::Integer>,
563
+ Convert<Result, TypeCategory::Real>,
564
+ Convert<Result, TypeCategory::Unsigned>>;
565
+ using Operations =
566
+ std::tuple<Parentheses<Result>, Negate<Result>, Add<Result>,
567
+ Subtract<Result>, Multiply<Result>, Divide<Result>, Extremum<Result>>;
568
+ using Others = std::tuple<Constant<Result>, ArrayConstructor<Result>,
569
+ Designator<Result>, FunctionRef<Result>>;
570
+
571
+ public:
572
+ common::TupleToVariant<common::CombineTuples<Operations, Conversions, Others>>
573
+ u;
574
+ };
575
+
550
576
template <int KIND>
551
577
class Expr <Type<TypeCategory::Real, KIND>>
552
578
: public ExpressionBase<Type<TypeCategory::Real, KIND>> {
@@ -560,7 +586,8 @@ class Expr<Type<TypeCategory::Real, KIND>>
560
586
// N.B. Real->Complex and Complex->Real conversions are done with CMPLX
561
587
// and part access operations (resp.).
562
588
using Conversions = std::variant<Convert<Result, TypeCategory::Integer>,
563
- Convert<Result, TypeCategory::Real>>;
589
+ Convert<Result, TypeCategory::Real>,
590
+ Convert<Result, TypeCategory::Unsigned>>;
564
591
using Operations = std::variant<ComplexComponent<KIND>, Parentheses<Result>,
565
592
Negate<Result>, Add<Result>, Subtract<Result>, Multiply<Result>,
566
593
Divide<Result>, Power<Result>, RealToIntPower<Result>, Extremum<Result>>;
@@ -590,6 +617,7 @@ class Expr<Type<TypeCategory::Complex, KIND>>
590
617
};
591
618
592
619
FOR_EACH_INTEGER_KIND (extern template class Expr , )
620
+ FOR_EACH_UNSIGNED_KIND (extern template class Expr , )
593
621
FOR_EACH_REAL_KIND (extern template class Expr , )
594
622
FOR_EACH_COMPLEX_KIND (extern template class Expr , )
595
623
@@ -629,7 +657,8 @@ class Relational : public Operation<Relational<T>, LogicalResult, T, T> {
629
657
static_assert (Operand::category == TypeCategory::Integer ||
630
658
Operand::category == TypeCategory::Real ||
631
659
Operand::category == TypeCategory::Complex ||
632
- Operand::category == TypeCategory::Character);
660
+ Operand::category == TypeCategory::Character ||
661
+ Operand::category == TypeCategory::Unsigned);
633
662
CLASS_BOILERPLATE (Relational)
634
663
Relational (
635
664
RelationalOperator r, const Expr<Operand> &a, const Expr<Operand> &b)
@@ -642,7 +671,7 @@ class Relational : public Operation<Relational<T>, LogicalResult, T, T> {
642
671
643
672
template <> class Relational <SomeType> {
644
673
using DirectlyComparableTypes = common::CombineTuples<IntegerTypes, RealTypes,
645
- ComplexTypes, CharacterTypes>;
674
+ ComplexTypes, CharacterTypes, UnsignedTypes >;
646
675
647
676
public:
648
677
using Result = LogicalResult;
@@ -656,6 +685,7 @@ template <> class Relational<SomeType> {
656
685
};
657
686
658
687
FOR_EACH_INTEGER_KIND (extern template class Relational , )
688
+ FOR_EACH_UNSIGNED_KIND (extern template class Relational , )
659
689
FOR_EACH_REAL_KIND (extern template class Relational , )
660
690
FOR_EACH_CHARACTER_KIND (extern template class Relational , )
661
691
extern template class Relational <SomeType>;
@@ -886,6 +916,7 @@ FOR_EACH_INTRINSIC_KIND(extern template class ArrayConstructor, )
886
916
FOR_EACH_INTRINSIC_KIND (template class Expr , ) \
887
917
FOR_EACH_CATEGORY_TYPE (template class Expr , ) \
888
918
FOR_EACH_INTEGER_KIND (template class Relational , ) \
919
+ FOR_EACH_UNSIGNED_KIND (template class Relational , ) \
889
920
FOR_EACH_REAL_KIND (template class Relational , ) \
890
921
FOR_EACH_CHARACTER_KIND (template class Relational , ) \
891
922
template class Relational <SomeType>; \
0 commit comments