@@ -697,28 +697,188 @@ class Int128Type extends IntegralType {
697
697
override string getCanonicalQLClass ( ) { result = "Int128Type" }
698
698
}
699
699
700
+ private newtype TTypeDomain =
701
+ TRealDomain ( ) or
702
+ TComplexDomain ( ) or
703
+ TImaginaryDomain ( )
704
+
700
705
/**
701
- * The C/C++ floating point types. See 4.5. This includes `float`,
702
- * `double` and `long double` types.
703
- * ```
704
- * float f;
705
- * double d;
706
- * long double ld;
707
- * ```
706
+ * The type ___domain of a floating-point type. One of `RealDomain`, `ComplexDomain`, or
707
+ * `ImaginaryDomain`.
708
+ */
709
+ class TypeDomain extends TTypeDomain {
710
+ /** Gets a textual representation of this type ___domain. */
711
+ string toString ( ) { none ( ) }
712
+ }
713
+
714
+ /**
715
+ * The type ___domain of a floating-point type that represents a real number.
716
+ */
717
+ class RealDomain extends TypeDomain , TRealDomain {
718
+ final override string toString ( ) { result = "real" }
719
+ }
720
+
721
+ /**
722
+ * The type ___domain of a floating-point type that represents a complex number.
723
+ */
724
+ class ComplexDomain extends TypeDomain , TComplexDomain {
725
+ final override string toString ( ) { result = "complex" }
726
+ }
727
+
728
+ /**
729
+ * The type ___domain of a floating-point type that represents an imaginary number.
730
+ */
731
+ class ImaginaryDomain extends TypeDomain , TImaginaryDomain {
732
+ final override string toString ( ) { result = "imaginary" }
733
+ }
734
+
735
+ /**
736
+ * Data for floating-point types.
737
+ *
738
+ * kind: The original type kind. Can be any floating-point type kind.
739
+ * base: The numeric base of the number's representation. Can be 2 (binary) or 10 (decimal).
740
+ * ___domain: The type ___domain of the type. Can be `RealDomain`, `ComplexDomain`, or `ImaginaryDomain`.
741
+ * realKind: The type kind of the corresponding real type. For example, the corresponding real type
742
+ * of `_Complex double` is `double`.
743
+ * extended: `true` if the number is an extended-precision floating-point number, such as
744
+ * `_Float32x`.
745
+ */
746
+ private predicate floatingPointTypeMapping (
747
+ int kind , int base , TTypeDomain ___domain , int realKind , boolean extended
748
+ ) {
749
+ // float
750
+ kind = 24 and base = 2 and ___domain = TRealDomain ( ) and realKind = 24 and extended = false
751
+ or
752
+ // double
753
+ kind = 25 and base = 2 and ___domain = TRealDomain ( ) and realKind = 25 and extended = false
754
+ or
755
+ // long double
756
+ kind = 26 and base = 2 and ___domain = TRealDomain ( ) and realKind = 26 and extended = false
757
+ or
758
+ // _Complex float
759
+ kind = 27 and base = 2 and ___domain = TComplexDomain ( ) and realKind = 24 and extended = false
760
+ or
761
+ // _Complex double
762
+ kind = 28 and base = 2 and ___domain = TComplexDomain ( ) and realKind = 25 and extended = false
763
+ or
764
+ // _Complex long double
765
+ kind = 29 and base = 2 and ___domain = TComplexDomain ( ) and realKind = 26 and extended = false
766
+ or
767
+ // _Imaginary float
768
+ kind = 30 and base = 2 and ___domain = TImaginaryDomain ( ) and realKind = 24 and extended = false
769
+ or
770
+ // _Imaginary double
771
+ kind = 31 and base = 2 and ___domain = TImaginaryDomain ( ) and realKind = 25 and extended = false
772
+ or
773
+ // _Imaginary long double
774
+ kind = 32 and base = 2 and ___domain = TImaginaryDomain ( ) and realKind = 26 and extended = false
775
+ or
776
+ // __float128
777
+ kind = 38 and base = 2 and ___domain = TRealDomain ( ) and realKind = 38 and extended = false
778
+ or
779
+ // _Complex __float128
780
+ kind = 39 and base = 2 and ___domain = TComplexDomain ( ) and realKind = 38 and extended = false
781
+ or
782
+ // _Decimal32
783
+ kind = 40 and base = 10 and ___domain = TRealDomain ( ) and realKind = 40 and extended = false
784
+ or
785
+ // _Decimal64
786
+ kind = 41 and base = 10 and ___domain = TRealDomain ( ) and realKind = 41 and extended = false
787
+ or
788
+ // _Decimal128
789
+ kind = 42 and base = 10 and ___domain = TRealDomain ( ) and realKind = 42 and extended = false
790
+ or
791
+ // _Float32
792
+ kind = 45 and base = 2 and ___domain = TRealDomain ( ) and realKind = 45 and extended = false
793
+ or
794
+ // _Float32x
795
+ kind = 46 and base = 2 and ___domain = TRealDomain ( ) and realKind = 46 and extended = true
796
+ or
797
+ // _Float64
798
+ kind = 47 and base = 2 and ___domain = TRealDomain ( ) and realKind = 47 and extended = false
799
+ or
800
+ // _Float64x
801
+ kind = 48 and base = 2 and ___domain = TRealDomain ( ) and realKind = 48 and extended = true
802
+ or
803
+ // _Float128
804
+ kind = 49 and base = 2 and ___domain = TRealDomain ( ) and realKind = 49 and extended = false
805
+ or
806
+ // _Float128x
807
+ kind = 50 and base = 2 and ___domain = TRealDomain ( ) and realKind = 50 and extended = true
808
+ }
809
+
810
+ /**
811
+ * The C/C++ floating point types. See 4.5. This includes `float`, `double` and `long double`, the
812
+ * fixed-size floating-point types like `_Float32`, the extended-precision floating-point types like
813
+ * `_Float64x`, and the decimal floating-point types like `_Decimal32`. It also includes the complex
814
+ * and imaginary versions of all of these types.
708
815
*/
709
816
class FloatingPointType extends ArithmeticType {
817
+ final int base ;
818
+ final TypeDomain ___domain ;
819
+ final int realKind ;
820
+ final boolean extended ;
821
+
710
822
FloatingPointType ( ) {
711
823
exists ( int kind |
712
824
builtintypes ( underlyingElement ( this ) , _, kind , _, _, _) and
713
- (
714
- kind >= 24 and kind <= 32
715
- or
716
- kind >= 38 and kind <= 42
717
- or
718
- kind >= 45 and kind <= 50
719
- )
825
+ floatingPointTypeMapping ( kind , base , ___domain , realKind , extended )
720
826
)
721
827
}
828
+
829
+ /** Gets the numeric base of this type's representation: 2 (binary) or 10 (decimal). */
830
+ final int getBase ( ) { result = base }
831
+
832
+ /**
833
+ * Gets the type ___domain of this type. Can be `RealDomain`, `ComplexDomain`, or `ImaginaryDomain`.
834
+ */
835
+ final TypeDomain getDomain ( ) { result = ___domain }
836
+
837
+ /**
838
+ * Gets the corresponding real type of this type. For example, the corresponding real type of
839
+ * `_Complex double` is `double`.
840
+ */
841
+ final RealNumberType getRealType ( ) {
842
+ builtintypes ( unresolveElement ( result ) , _, realKind , _, _, _)
843
+ }
844
+
845
+ /** Holds if this type is an extended precision floating-point type, such as `_Float32x`. */
846
+ final predicate isExtendedPrecision ( ) { extended = true }
847
+ }
848
+
849
+ /**
850
+ * A floating-point type representing a real number.
851
+ */
852
+ class RealNumberType extends FloatingPointType {
853
+ RealNumberType ( ) { ___domain instanceof RealDomain }
854
+ }
855
+
856
+ /**
857
+ * A floating-point type representing a complex number.
858
+ */
859
+ class ComplexNumberType extends FloatingPointType {
860
+ ComplexNumberType ( ) { ___domain instanceof ComplexDomain }
861
+ }
862
+
863
+ /**
864
+ * A floating-point type representing an imaginary number.
865
+ */
866
+ class ImaginaryNumberType extends FloatingPointType {
867
+ ImaginaryNumberType ( ) { ___domain instanceof ImaginaryDomain }
868
+ }
869
+
870
+ /**
871
+ * A floating-point type whose representation is base 2.
872
+ */
873
+ class BinaryFloatingPointType extends FloatingPointType {
874
+ BinaryFloatingPointType ( ) { base = 2 }
875
+ }
876
+
877
+ /**
878
+ * A floating-point type whose representation is base 10.
879
+ */
880
+ class DecimalFloatingPointType extends FloatingPointType {
881
+ DecimalFloatingPointType ( ) { base = 10 }
722
882
}
723
883
724
884
/**
@@ -727,7 +887,7 @@ class FloatingPointType extends ArithmeticType {
727
887
* float f;
728
888
* ```
729
889
*/
730
- class FloatType extends FloatingPointType {
890
+ class FloatType extends RealNumberType , BinaryFloatingPointType {
731
891
FloatType ( ) { builtintypes ( underlyingElement ( this ) , _, 24 , _, _, _) }
732
892
733
893
override string getCanonicalQLClass ( ) { result = "FloatType" }
@@ -739,7 +899,7 @@ class FloatType extends FloatingPointType {
739
899
* double d;
740
900
* ```
741
901
*/
742
- class DoubleType extends FloatingPointType {
902
+ class DoubleType extends RealNumberType , BinaryFloatingPointType {
743
903
DoubleType ( ) { builtintypes ( underlyingElement ( this ) , _, 25 , _, _, _) }
744
904
745
905
override string getCanonicalQLClass ( ) { result = "DoubleType" }
@@ -751,7 +911,7 @@ class DoubleType extends FloatingPointType {
751
911
* long double ld;
752
912
* ```
753
913
*/
754
- class LongDoubleType extends FloatingPointType {
914
+ class LongDoubleType extends RealNumberType , BinaryFloatingPointType {
755
915
LongDoubleType ( ) { builtintypes ( underlyingElement ( this ) , _, 26 , _, _, _) }
756
916
757
917
override string getCanonicalQLClass ( ) { result = "LongDoubleType" }
@@ -763,7 +923,7 @@ class LongDoubleType extends FloatingPointType {
763
923
* __float128 f128;
764
924
* ```
765
925
*/
766
- class Float128Type extends FloatingPointType {
926
+ class Float128Type extends RealNumberType , BinaryFloatingPointType {
767
927
Float128Type ( ) { builtintypes ( underlyingElement ( this ) , _, 38 , _, _, _) }
768
928
769
929
override string getCanonicalQLClass ( ) { result = "Float128Type" }
@@ -775,7 +935,7 @@ class Float128Type extends FloatingPointType {
775
935
* _Decimal32 d32;
776
936
* ```
777
937
*/
778
- class Decimal32Type extends FloatingPointType {
938
+ class Decimal32Type extends RealNumberType , DecimalFloatingPointType {
779
939
Decimal32Type ( ) { builtintypes ( underlyingElement ( this ) , _, 40 , _, _, _) }
780
940
781
941
override string getCanonicalQLClass ( ) { result = "Decimal32Type" }
@@ -787,7 +947,7 @@ class Decimal32Type extends FloatingPointType {
787
947
* _Decimal64 d64;
788
948
* ```
789
949
*/
790
- class Decimal64Type extends FloatingPointType {
950
+ class Decimal64Type extends RealNumberType , DecimalFloatingPointType {
791
951
Decimal64Type ( ) { builtintypes ( underlyingElement ( this ) , _, 41 , _, _, _) }
792
952
793
953
override string getCanonicalQLClass ( ) { result = "Decimal64Type" }
@@ -799,7 +959,7 @@ class Decimal64Type extends FloatingPointType {
799
959
* _Decimal128 d128;
800
960
* ```
801
961
*/
802
- class Decimal128Type extends FloatingPointType {
962
+ class Decimal128Type extends RealNumberType , DecimalFloatingPointType {
803
963
Decimal128Type ( ) { builtintypes ( underlyingElement ( this ) , _, 42 , _, _, _) }
804
964
805
965
override string getCanonicalQLClass ( ) { result = "Decimal128Type" }
0 commit comments