1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.6),
3 // last updated on Nov 2, 1999.
4 // The original source file is "type.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_QUARK_USED
9 ///////////////////////////////////////////////////////////////////////////////
11 ///////////////////////////////////////////////////////////////////////////////
12 static const Quark
_t_y_p_eco_c_c_Q5("void");
13 static const Quark
_t_y_p_eco_c_c_Q2("int");
14 static const Quark
_t_y_p_eco_c_c_Q4("bool");
15 static const Quark
_t_y_p_eco_c_c_Q6("Quark");
16 static const Quark
_t_y_p_eco_c_c_Q1("char");
17 static const Quark
_t_y_p_eco_c_c_Q7("BigInt");
18 static const Quark
_t_y_p_eco_c_c_Q3("double");
20 /////////////////////////////////////////////////////////////////////////////
22 // This file implements the type analysis and type inference module
23 // in the Prop -> C++ translator.
25 /////////////////////////////////////////////////////////////////////////////
27 #include <AD/strings/quark.h>
31 #include "collection.h"
37 /////////////////////////////////////////////////////////////////////////////
41 /////////////////////////////////////////////////////////////////////////////
51 /////////////////////////////////////////////////////////////////////////////
53 // Initialize the types
55 /////////////////////////////////////////////////////////////////////////////
56 void initialize_types()
57 { character_ty
= mkidty(
70 string_ty
= mkptrty(QUALty(QUALconst
,character_ty
));
151 /////////////////////////////////////////////////////////////////////////////
153 // Make a type variable
155 /////////////////////////////////////////////////////////////////////////////
156 Ty
mkvar() { return VARty(NOty
); }
158 /////////////////////////////////////////////////////////////////////////////
160 // Constructors for some common types
162 /////////////////////////////////////////////////////////////////////////////
163 Ty
mkptrty (Ty ty
) { return TYCONty(POINTERtycon
,
170 Ty
mkrefty (Ty ty
) { return TYCONty(REFtycon
,
177 Ty
mkfunty (Ty a
, Ty b
) { return TYCONty(FUNtycon
,
180 list_1_(a
,list_1_(b
))
184 Ty
mkarrayty (Ty a
, Exp e
) { return TYCONty(ARRAYtycon(e
),
191 Ty
mkidty (Id id
, Tys args
) { return TYCONty(IDtycon(id
), args
); }
192 Ty
mkidvarty (Id id
, TyVars args
) { return TYCONty(IDtycon(id
), tyvars_to_tys(args
)); }
193 Ty
mktuplety (Tys tys
) { return TYCONty(TUPLEtycon
, tys
); }
194 Ty
mkrecordty (Ids l
, Tys t
, Bool f
) { return TYCONty(RECORDtycon(l
,f
), t
); }
195 Ty
mktypety () { return TYCONty(TYPEtycon
,
202 Tys
tyvars_to_tys (TyVars a
)
212 list_1_(mkidty(a
->_1
,nil_1_
),tyvars_to_tys(a
->_2
))
234 /////////////////////////////////////////////////////////////////////////////
236 // Return the representation tag of a constructor
238 /////////////////////////////////////////////////////////////////////////////
239 int tag_of(Cons cons
)
246 switch (cons
->alg_ty
->tag__
) {
247 case a_Ty::tag_TYCONty
: {
248 if (boxed(((Ty_TYCONty
*)cons
->alg_ty
)->_1
)) {
249 switch (((Ty_TYCONty
*)cons
->alg_ty
)->_1
->tag__
) {
250 case a_TyCon::tag_DATATYPEtycon
: {
252 return cons
->tag
+ ((((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)cons
->alg_ty
)->_1
)->qualifiers
& QUALlexeme
) ? 256 : 0);
264 default: { goto L1
; } break;
274 /////////////////////////////////////////////////////////////////////////////
275 // Convert type variables to a type list
276 /////////////////////////////////////////////////////////////////////////////
277 Tys
tyvars_to_type_list(int i
, TyVars tyvars
)
287 list_1_(INDty(tyvars
->_1
,i
),tyvars_to_type_list((i
+ 1),tyvars
->_2
))
309 /////////////////////////////////////////////////////////////////////////////
311 // Make a universally quantified type
313 /////////////////////////////////////////////////////////////////////////////
314 Ty
mkpolyty(Ty ty
, TyVars tyvars
)
315 { int arity
= length(tyvars
);
316 if (arity
== 0) return ty
;
317 Id
* bound_vars
= (Id
*)mem_pool
[arity
* sizeof(Id
)];
319 for_each (TyVar
, tv
, tyvars
)
320 bound_vars
[i
++] = tv
;
321 return POLYty(deref(ty
),arity
,bound_vars
);
326 (TYCONty(tycon,tyvars_to_type_list(0,tyvars)), arity, bound_vars);
328 | _: { bug("mkpolyty()"); }
333 /////////////////////////////////////////////////////////////////////////////
335 // Dereference a type expression
337 /////////////////////////////////////////////////////////////////////////////
346 case a_Ty::tag_VARty
: {
347 if (((Ty_VARty
*)ty
)->VARty
) {
349 ty
= ((Ty_VARty
*)ty
)->VARty
;
358 case a_Ty::tag_QUALty
: {
360 ty
= ((Ty_QUALty
*)ty
)->_2
;
363 case a_Ty::tag_TYCONty
: {
364 if (boxed(((Ty_TYCONty
*)ty
)->_1
)) {
365 switch (((Ty_TYCONty
*)ty
)->_1
->tag__
) {
366 case a_TyCon::tag_IDtycon
: {
367 if (((Ty_TYCONty
*)ty
)->_2
) {
373 Ty _V1
= lookup_ty(((TyCon_IDtycon
*)((Ty_TYCONty
*)ty
)->_1
)->IDtycon
);
375 switch (_V1
->tag__
) {
376 case a_Ty::tag_TYCONty
: {
378 return TYCONty(((Ty_TYCONty
*)_V1
)->_1
,((Ty_TYCONty
*)ty
)->_2
);
397 Ty t
= lookup_ty(((TyCon_IDtycon
*)((Ty_TYCONty
*)ty
)->_1
)->IDtycon
); if (t
!= NOty
) ty
= t
; else return ty
;
401 default: { goto L3
; } break;
405 case a_Ty::tag_DEFVALty
: {
407 ty
= ((Ty_DEFVALty
*)ty
)->_1
;
410 default: { goto L3
; } break;
420 /////////////////////////////////////////////////////////////////////////////
422 // Dereference a type expression.
424 /////////////////////////////////////////////////////////////////////////////
433 case a_Ty::tag_VARty
: {
434 if (((Ty_VARty
*)ty
)->VARty
) {
436 ty
= ((Ty_VARty
*)ty
)->VARty
;
440 default: { goto L5
; } break;
452 /////////////////////////////////////////////////////////////////////////////
454 // Get the default value of a type (if any)
456 /////////////////////////////////////////////////////////////////////////////
457 Exp
default_val(Ty ty
)
464 switch (_V2
->tag__
) {
465 case a_Ty::tag_DEFVALty
: {
467 return ((Ty_DEFVALty
*)_V2
)->_2
;
484 /////////////////////////////////////////////////////////////////////////////
486 // Test for qualifiers in a type
488 /////////////////////////////////////////////////////////////////////////////
489 Bool
has_qual(TyQual q
, Ty ty
)
497 case a_Ty::tag_VARty
: {
499 ty
= ((Ty_VARty
*)ty
)->VARty
;
502 case a_Ty::tag_QUALty
: {
504 if (q
& ((Ty_QUALty
*)ty
)->_1
) return true; ty
= ((Ty_QUALty
*)ty
)->_2
;
507 case a_Ty::tag_TYCONty
: {
508 if (boxed(((Ty_TYCONty
*)ty
)->_1
)) {
509 switch (((Ty_TYCONty
*)ty
)->_1
->tag__
) {
510 case a_TyCon::tag_DATATYPEtycon
: {
512 return ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)ty
)->_1
)->qualifiers
& q
;
515 default: { goto L7
; } break;
519 case a_Ty::tag_DEFVALty
: {
521 ty
= ((Ty_DEFVALty
*)ty
)->_1
;
524 case a_Ty::tag_NESTEDty
: {
526 ty
= ((Ty_NESTEDty
*)ty
)->_2
;
529 default: { goto L7
; } break;
541 /////////////////////////////////////////////////////////////////////////////
543 // Test if a type is grounded (i.e. contains no type variables.)
545 /////////////////////////////////////////////////////////////////////////////
546 Bool
is_ground(Ty ty
)
554 case a_Ty::tag_VARty
: {
556 ty
= ((Ty_VARty
*)ty
)->VARty
;
559 case a_Ty::tag_QUALty
: {
561 ty
= ((Ty_QUALty
*)ty
)->_2
;
564 case a_Ty::tag_TYCONty
: {
566 return is_ground(((Ty_TYCONty
*)ty
)->_2
);
569 case a_Ty::tag_DEFVALty
: {
571 ty
= ((Ty_DEFVALty
*)ty
)->_1
;
574 case a_Ty::tag_NESTEDty
: {
576 if (! is_ground(((Ty_NESTEDty
*)ty
)->_1
)) return false; ty
= ((Ty_NESTEDty
*)ty
)->_2
;
594 /////////////////////////////////////////////////////////////////////////////
596 // Test if a type list is grounded
598 /////////////////////////////////////////////////////////////////////////////
599 Bool
is_ground(Tys tys
)
600 { for_each (Ty
, t
, tys
) if (! is_ground(t
)) return false;
604 /////////////////////////////////////////////////////////////////////////////
606 // Test if a type is an array
608 /////////////////////////////////////////////////////////////////////////////
609 Bool
is_array_ty(Ty ty
)
614 Ty _V3
= deref_all(ty
);
616 switch (_V3
->tag__
) {
617 case a_Ty::tag_TYCONty
: {
618 if (boxed(((Ty_TYCONty
*)_V3
)->_1
)) {
619 switch (((Ty_TYCONty
*)_V3
)->_1
->tag__
) {
620 case a_TyCon::tag_ARRAYtycon
: {
621 if (((TyCon_ARRAYtycon
*)((Ty_TYCONty
*)_V3
)->_1
)->ARRAYtycon
) {
622 if (((Ty_TYCONty
*)_V3
)->_2
) {
624 if (((Ty_TYCONty
*)_V3
)->_2
->_2
) {
638 default: { goto L11
; } break;
642 case a_Ty::tag_NESTEDty
: {
644 return is_array_ty(((Ty_NESTEDty
*)_V3
)->_2
);
647 default: { goto L11
; } break;
656 /////////////////////////////////////////////////////////////////////////////
658 // Test if a type is a polymorphic datatype
660 /////////////////////////////////////////////////////////////////////////////
661 Bool
is_poly_datatype(Ty ty
)
666 Ty _V4
= deref_all(ty
);
668 switch (_V4
->tag__
) {
669 case a_Ty::tag_TYCONty
: {
670 if (boxed(((Ty_TYCONty
*)_V4
)->_1
)) {
671 switch (((Ty_TYCONty
*)_V4
)->_1
->tag__
) {
672 case a_TyCon::tag_DATATYPEtycon
: {
674 return ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V4
)->_1
)->tyvars
!=
692 default: { goto L13
; } break;
701 /////////////////////////////////////////////////////////////////////////////
703 // Test if a type is a datatype.
705 /////////////////////////////////////////////////////////////////////////////
706 Bool
is_datatype(Ty ty
)
711 Ty _V5
= deref_all(ty
);
713 switch (_V5
->tag__
) {
714 case a_Ty::tag_TYCONty
: {
715 if (boxed(((Ty_TYCONty
*)_V5
)->_1
)) {
716 switch (((Ty_TYCONty
*)_V5
)->_1
->tag__
) {
717 case a_TyCon::tag_DATATYPEtycon
: {
731 default: { goto L14
; } break;
740 /////////////////////////////////////////////////////////////////////////////
742 // Add a new class to an inheritance list
744 /////////////////////////////////////////////////////////////////////////////
745 Inherits
add_inherit(Id id
, TyVars p
, Inherits i
, Scope s
, TyQual t
)
749 INHERIT(mkidty(id
,tyvars_to_tys(p
)), s
, t
)
763 /////////////////////////////////////////////////////////////////////////////
765 // Test if a type is garbage collectable.
767 /////////////////////////////////////////////////////////////////////////////
776 case a_Ty::tag_VARty
: {
778 ty
= ((Ty_VARty
*)ty
)->VARty
;
781 case a_Ty::tag_QUALty
: {
783 if (((Ty_QUALty
*)ty
)->_1
& QUALcollectable
) return true; ty
= ((Ty_QUALty
*)ty
)->_2
;
786 case a_Ty::tag_TYCONty
: {
787 if (boxed(((Ty_TYCONty
*)ty
)->_1
)) {
788 switch (((Ty_TYCONty
*)ty
)->_1
->tag__
) {
789 case a_TyCon::tag_IDtycon
: {
791 Ty t
= deref_all(ty
);
792 if (t
== ty
) return false;
797 case a_TyCon::tag_DATATYPEtycon
: {
799 return (((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)ty
)->_1
)->qualifiers
& QUALcollectable
) && (((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)ty
)->_1
)->arg
> 0);
810 switch ((int)((Ty_TYCONty
*)ty
)->_1
) {
811 case ((int)POINTERtycon
): {
812 if (((Ty_TYCONty
*)ty
)->_2
) {
813 if (((Ty_TYCONty
*)ty
)->_2
->_2
) { goto L16
; } else {
815 ty
= ((Ty_TYCONty
*)ty
)->_2
->_1
;
820 case ((int)REFtycon
): {
821 if (((Ty_TYCONty
*)ty
)->_2
) {
822 if (((Ty_TYCONty
*)ty
)->_2
->_2
) { goto L16
; } else {
824 ty
= ((Ty_TYCONty
*)ty
)->_2
->_1
;
829 default: { goto L16
; } break;
833 case a_Ty::tag_DEFVALty
: {
835 ty
= ((Ty_DEFVALty
*)ty
)->_1
;
838 case a_Ty::tag_NESTEDty
: {
840 ty
= ((Ty_NESTEDty
*)ty
)->_2
;
843 default: { goto L16
; } break;
853 /////////////////////////////////////////////////////////////////////////////
855 // Test if type is a pointer.
857 /////////////////////////////////////////////////////////////////////////////
858 Bool
is_pointer_ty(Ty ty
)
863 Ty _V6
= deref_all(ty
);
865 switch (_V6
->tag__
) {
866 case a_Ty::tag_TYCONty
: {
867 if (boxed(((Ty_TYCONty
*)_V6
)->_1
)) {
868 switch (((Ty_TYCONty
*)_V6
)->_1
->tag__
) {
869 case a_TyCon::tag_DATATYPEtycon
: {
883 switch ((int)((Ty_TYCONty
*)_V6
)->_1
) {
884 case ((int)POINTERtycon
): { goto L17
; } break;
885 default: { goto L18
; } break;
889 default: { goto L18
; } break;
898 /////////////////////////////////////////////////////////////////////////////
900 // Test if type is embeddable into 1 word
902 /////////////////////////////////////////////////////////////////////////////
903 Bool
is_embeddable_ty(Ty ty
)
908 Ty _V7
= deref_all(ty
);
910 switch (_V7
->tag__
) {
911 case a_Ty::tag_TYCONty
: {
914 ((ty_equal(_V7
,integer_ty
) || ty_equal(_V7
,character_ty
)) || ty_equal(_V7
,bool_ty
))
918 if (boxed(((Ty_TYCONty
*)_V7
)->_1
)) {
919 switch (((Ty_TYCONty
*)_V7
)->_1
->tag__
) {
920 case a_TyCon::tag_DATATYPEtycon
: {
923 ((((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V7
)->_1
)->opt
& OPTtaggedpointer
) == 0)
928 switch (((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V7
)->_1
)->arg
) {
944 switch (((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V7
)->_1
)->arg
) {
945 case 0: { goto L20
; } break;
955 default: { goto L22
; } break;
958 switch ((int)((Ty_TYCONty
*)_V7
)->_1
) {
959 case ((int)POINTERtycon
): {
960 if (((Ty_TYCONty
*)_V7
)->_2
) {
961 if (((Ty_TYCONty
*)_V7
)->_2
->_2
) { goto L22
; } else {
964 (((Ty_TYCONty
*)_V7
)->_2
->_1
!= character_ty
)
977 default: { goto L22
; } break;
982 if (boxed(((Ty_TYCONty
*)_V7
)->_1
)) {
983 switch (((Ty_TYCONty
*)_V7
)->_1
->tag__
) {
984 case a_TyCon::tag_DATATYPEtycon
: {
987 ((((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V7
)->_1
)->opt
& OPTtaggedpointer
) == 0)
992 switch (((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V7
)->_1
)->arg
) {
993 case 0: { goto L20
; } break;
1003 default: { goto L24
; } break;
1006 switch ((int)((Ty_TYCONty
*)_V7
)->_1
) {
1007 case ((int)POINTERtycon
): {
1008 if (((Ty_TYCONty
*)_V7
)->_2
) {
1009 if (((Ty_TYCONty
*)_V7
)->_2
->_2
) { goto L24
; } else {
1011 #line 305 "type.pcc"
1012 (((Ty_TYCONty
*)_V7
)->_2
->_1
!= character_ty
)
1013 #line 305 "type.pcc"
1018 } else { goto L24
; }
1020 default: { goto L24
; } break;
1028 #line 306 "type.pcc"
1029 ((ty_equal(_V7
,integer_ty
) || ty_equal(_V7
,character_ty
)) || ty_equal(_V7
,bool_ty
))
1030 #line 308 "type.pcc"
1036 } else { goto L25
; }
1038 #line 310 "type.pcc"
1039 #line 310 "type.pcc"
1043 /////////////////////////////////////////////////////////////////////////////
1045 // Test if constructor is an array-style constructor
1047 /////////////////////////////////////////////////////////////////////////////
1048 Bool
is_array_constructor(Id id
) { return id
[1] == '|'; }
1049 Bool
is_list_constructor(Id id
) { return id
[0] == '#' &&
1053 Bool
is_list_constructor(Cons cons
)
1054 { return cons
!= NOcons
&& is_list_constructor(cons
->name
); }
1056 /////////////////////////////////////////////////////////////////////////////
1058 // Returns the number of boxed variants.
1060 /////////////////////////////////////////////////////////////////////////////
1061 int boxed_variants(Ty ty
)
1063 #line 332 "type.pcc"
1064 #line 334 "type.pcc"
1066 Ty _V8
= deref_all(ty
);
1068 switch (_V8
->tag__
) {
1069 case a_Ty::tag_TYCONty
: {
1070 if (boxed(((Ty_TYCONty
*)_V8
)->_1
)) {
1071 switch (((Ty_TYCONty
*)_V8
)->_1
->tag__
) {
1072 case a_TyCon::tag_DATATYPEtycon
: {
1073 #line 333 "type.pcc"
1074 return ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V8
)->_1
)->arg
;
1075 #line 333 "type.pcc"
1079 #line 334 "type.pcc"
1081 #line 334 "type.pcc"
1084 } else { goto L26
; }
1086 default: { goto L26
; } break;
1088 } else { goto L26
; }
1090 #line 335 "type.pcc"
1091 #line 335 "type.pcc"
1095 int unboxed_variants(Ty ty
)
1097 #line 339 "type.pcc"
1098 #line 341 "type.pcc"
1100 Ty _V9
= deref_all(ty
);
1102 switch (_V9
->tag__
) {
1103 case a_Ty::tag_TYCONty
: {
1104 if (boxed(((Ty_TYCONty
*)_V9
)->_1
)) {
1105 switch (((Ty_TYCONty
*)_V9
)->_1
->tag__
) {
1106 case a_TyCon::tag_DATATYPEtycon
: {
1107 #line 340 "type.pcc"
1108 return ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V9
)->_1
)->unit
;
1109 #line 340 "type.pcc"
1113 #line 341 "type.pcc"
1115 #line 341 "type.pcc"
1118 } else { goto L27
; }
1120 default: { goto L27
; } break;
1122 } else { goto L27
; }
1124 #line 342 "type.pcc"
1125 #line 342 "type.pcc"
1129 /////////////////////////////////////////////////////////////////////////////
1131 // Returns the arity of a type
1133 /////////////////////////////////////////////////////////////////////////////
1136 #line 351 "type.pcc"
1137 #line 355 "type.pcc"
1139 Ty _V10
= deref_all(ty
);
1141 switch (_V10
->tag__
) {
1142 case a_Ty::tag_TYCONty
: {
1143 if (boxed(((Ty_TYCONty
*)_V10
)->_1
)) {
1144 switch (((Ty_TYCONty
*)_V10
)->_1
->tag__
) {
1145 case a_TyCon::tag_RECORDtycon
: {
1147 #line 353 "type.pcc"
1148 return length(((Ty_TYCONty
*)_V10
)->_2
);
1149 #line 353 "type.pcc"
1153 #line 355 "type.pcc"
1155 #line 355 "type.pcc"
1159 switch ((int)((Ty_TYCONty
*)_V10
)->_1
) {
1160 case ((int)TUPLEtycon
): { goto L28
; } break;
1161 default: { goto L29
; } break;
1165 case a_Ty::tag_NESTEDty
: {
1166 #line 354 "type.pcc"
1167 return arity_of(((Ty_NESTEDty
*)_V10
)->_2
);
1168 #line 354 "type.pcc"
1170 default: { goto L29
; } break;
1173 #line 352 "type.pcc"
1175 #line 352 "type.pcc"
1178 #line 356 "type.pcc"
1179 #line 356 "type.pcc"
1183 /////////////////////////////////////////////////////////////////////////////
1185 // Instantiate a polymorphic type scheme
1187 /////////////////////////////////////////////////////////////////////////////
1188 Ty
inst (Ty ty
, int n
, Id bound_vars
[], Ty subst
[])
1190 #line 365 "type.pcc"
1191 #line 376 "type.pcc"
1193 Ty _V11
= deref(ty
);
1195 switch (_V11
->tag__
) {
1196 case a_Ty::tag_VARty
: {
1198 #line 366 "type.pcc"
1200 #line 366 "type.pcc"
1202 case a_Ty::tag_INDty
: {
1203 #line 368 "type.pcc"
1204 return subst
[((Ty_INDty
*)_V11
)->_2
] != NOty
? subst
[((Ty_INDty
*)_V11
)->_2
] : (subst
[((Ty_INDty
*)_V11
)->_2
] = mkvar());
1205 #line 368 "type.pcc"
1207 case a_Ty::tag_QUALty
: {
1208 #line 369 "type.pcc"
1209 return QUALty(((Ty_QUALty
*)_V11
)->_1
,inst(((Ty_QUALty
*)_V11
)->_2
,n
,bound_vars
,subst
));
1210 #line 369 "type.pcc"
1212 case a_Ty::tag_TYCONty
: {
1213 #line 375 "type.pcc"
1214 return TYCONty(((Ty_TYCONty
*)_V11
)->_1
, inst(((Ty_TYCONty
*)_V11
)->_2
,n
,bound_vars
,subst
));
1215 #line 375 "type.pcc"
1217 case a_Ty::tag_POLYty
: {
1218 #line 376 "type.pcc"
1219 bug("inst()"); return NOty
;
1220 #line 376 "type.pcc"
1222 case a_Ty::tag_DEFVALty
: {
1223 #line 370 "type.pcc"
1224 return DEFVALty(inst(((Ty_DEFVALty
*)_V11
)->_1
,n
,bound_vars
,subst
),((Ty_DEFVALty
*)_V11
)->_2
);
1225 #line 370 "type.pcc"
1228 #line 371 "type.pcc"
1229 return NESTEDty(inst(((Ty_NESTEDty
*)_V11
)->_1
,n
,bound_vars
,subst
),
1230 inst(((Ty_NESTEDty
*)_V11
)->_2
,n
,bound_vars
,subst
));
1232 #line 373 "type.pcc"
1235 } else { goto L30
; }
1237 #line 377 "type.pcc"
1238 #line 377 "type.pcc"
1242 /////////////////////////////////////////////////////////////////////////////
1244 // Instantiate a type list
1246 /////////////////////////////////////////////////////////////////////////////
1247 Tys
inst (Tys tys
, int n
, Id bound_vars
[], Ty subst
[])
1249 #line 386 "type.pcc"
1250 #line 390 "type.pcc"
1253 #line 388 "type.pcc"
1255 #line 388 "type.pcc"
1256 #line 388 "type.pcc"
1257 list_1_(inst(tys
->_1
,n
,bound_vars
,subst
),inst(tys
->_2
,n
,bound_vars
,subst
))
1258 #line 389 "type.pcc"
1259 #line 389 "type.pcc"
1262 #line 390 "type.pcc"
1264 #line 387 "type.pcc"
1266 #line 387 "type.pcc"
1267 #line 387 "type.pcc"
1269 #line 387 "type.pcc"
1270 #line 387 "type.pcc"
1272 #line 387 "type.pcc"
1275 #line 391 "type.pcc"
1276 #line 391 "type.pcc"
1280 /////////////////////////////////////////////////////////////////////////////
1282 // Instantiate a polymorphic type scheme
1284 /////////////////////////////////////////////////////////////////////////////
1287 #line 400 "type.pcc"
1288 #line 406 "type.pcc"
1291 switch (polyty
->tag__
) {
1292 case a_Ty::tag_POLYty
: {
1293 #line 402 "type.pcc"
1295 for (int i
= ((Ty_POLYty
*)polyty
)->_2
- 1; i
>= 0; i
--) subst
[i
] = NOty
;
1296 return inst(((Ty_POLYty
*)polyty
)->_1
, ((Ty_POLYty
*)polyty
)->_2
, ((Ty_POLYty
*)polyty
)->_3
, subst
);
1298 #line 405 "type.pcc"
1302 #line 406 "type.pcc"
1304 #line 406 "type.pcc"
1307 } else { goto L31
; }
1309 #line 407 "type.pcc"
1310 #line 407 "type.pcc"
1314 /////////////////////////////////////////////////////////////////////////////
1316 // Construct component types
1318 /////////////////////////////////////////////////////////////////////////////
1319 Ty
component_ty (Ty datatype_ty
, Cons cons
)
1321 #line 416 "type.pcc"
1322 #line 420 "type.pcc"
1324 Ty _V12
= deref_all(datatype_ty
);
1326 switch (_V12
->tag__
) {
1327 case a_Ty::tag_TYCONty
: {
1329 if (boxed(((Ty_TYCONty
*)_V12
)->_1
)) {
1330 switch (((Ty_TYCONty
*)_V12
)->_1
->tag__
) {
1331 case a_TyCon::tag_DATATYPEtycon
: {
1332 if (((Ty_TYCONty
*)_V12
)->_2
) {
1336 #line 418 "type.pcc"
1337 return apply_ty(cons
->cons_ty
,((Ty_TYCONty
*)_V12
)->_2
);
1338 #line 418 "type.pcc"
1341 #line 419 "type.pcc"
1343 #line 419 "type.pcc"
1345 } else { goto L33
; }
1346 } else { goto L33
; }
1348 default: { goto L33
; } break;
1350 } else { goto L33
; }
1352 if (boxed(((Ty_TYCONty
*)_V12
)->_1
)) {
1353 switch (((Ty_TYCONty
*)_V12
)->_1
->tag__
) {
1354 case a_TyCon::tag_DATATYPEtycon
: {
1355 if (((Ty_TYCONty
*)_V12
)->_2
) {
1357 if (cons
->ty
) { goto L32
; } else {
1359 #line 420 "type.pcc"
1361 #line 420 "type.pcc"
1363 } else { goto L34
; }
1364 } else { goto L34
; }
1366 default: { goto L34
; } break;
1368 } else { goto L34
; }
1373 if (cons
) { goto L33
; } else { goto L34
; }
1376 } else { goto L35
; }
1378 #line 421 "type.pcc"
1379 #line 421 "type.pcc"
1383 /////////////////////////////////////////////////////////////////////////////
1385 // Extract record type component
1387 /////////////////////////////////////////////////////////////////////////////
1388 Ty
component_ty (Ty record_ty
, Id label
)
1390 #line 430 "type.pcc"
1391 #line 441 "type.pcc"
1393 Ty _V13
= deref_all(record_ty
);
1395 switch (_V13
->tag__
) {
1396 case a_Ty::tag_TYCONty
: {
1397 if (boxed(((Ty_TYCONty
*)_V13
)->_1
)) {
1398 switch (((Ty_TYCONty
*)_V13
)->_1
->tag__
) {
1399 case a_TyCon::tag_RECORDtycon
: {
1400 #line 432 "type.pcc"
1402 for (ls
= ((TyCon_RECORDtycon
*)((Ty_TYCONty
*)_V13
)->_1
)->_1
, ts
= ((Ty_TYCONty
*)_V13
)->_2
; ls
&& ts
; ls
= ls
->_2
, ts
= ts
->_2
)
1403 if (ls
->_1
== label
) return ts
->_1
;
1405 #line 435 "type.pcc"
1411 switch ((int)((Ty_TYCONty
*)_V13
)->_1
) {
1412 case ((int)TUPLEtycon
): {
1414 #line 436 "type.pcc"
1416 #line 436 "type.pcc"
1419 #line 437 "type.pcc"
1420 int i
= atol(label
+1);
1421 if (i
> 0) return component_ty(_V13
,i
);
1423 #line 439 "type.pcc"
1427 default: { goto L36
; } break;
1431 default: { goto L36
; } break;
1433 } else { goto L36
; }
1435 #line 441 "type.pcc"
1436 #line 441 "type.pcc"
1438 error("%Ltype %T does not have component %s\n",record_ty
,label
);
1442 /////////////////////////////////////////////////////////////////////////////
1444 // Extract tuple type component
1446 /////////////////////////////////////////////////////////////////////////////
1447 Ty
component_ty (Ty tuple_ty
, int n
)
1449 #line 452 "type.pcc"
1450 #line 459 "type.pcc"
1452 Ty _V14
= deref_all(tuple_ty
);
1454 switch (_V14
->tag__
) {
1455 case a_Ty::tag_TYCONty
: {
1456 if (boxed(((Ty_TYCONty
*)_V14
)->_1
)) {
1458 switch ((int)((Ty_TYCONty
*)_V14
)->_1
) {
1459 case ((int)TUPLEtycon
): {
1460 #line 454 "type.pcc"
1462 for (i
= 1, ts
= ((Ty_TYCONty
*)_V14
)->_2
; ts
; ts
= ts
->_2
, i
++)
1463 if (i
== n
) return ts
->_1
;
1465 #line 457 "type.pcc"
1467 default: { goto L37
; } break;
1471 default: { goto L37
; } break;
1473 } else { goto L37
; }
1475 #line 459 "type.pcc"
1476 #line 459 "type.pcc"
1478 error("%Ltype %T does not have component #%i\n",tuple_ty
,n
);
1482 /////////////////////////////////////////////////////////////////////////////
1484 // Apply type arguments to a ty_scheme.
1486 /////////////////////////////////////////////////////////////////////////////
1487 Ty
apply_ty (Ty cons_ty
, Tys tys
)
1489 #line 470 "type.pcc"
1490 #line 495 "type.pcc"
1493 switch (cons_ty
->tag__
) {
1494 case a_Ty::tag_TYCONty
: {
1495 if (boxed(((Ty_TYCONty
*)cons_ty
)->_1
)) {
1497 #line 495 "type.pcc"
1499 #line 495 "type.pcc"
1501 switch ((int)((Ty_TYCONty
*)cons_ty
)->_1
) {
1502 case ((int)FUNtycon
): {
1503 if (((Ty_TYCONty
*)cons_ty
)->_2
) {
1504 #line 494 "type.pcc"
1505 return ((Ty_TYCONty
*)cons_ty
)->_2
->_1
;
1506 #line 494 "type.pcc"
1507 } else { goto L38
; }
1509 default: { goto L38
; } break;
1513 case a_Ty::tag_POLYty
: {
1514 #line 472 "type.pcc"
1515 Ty subst
[256]; int i
; Tys ts
;
1516 for (i
= 0, ts
= tys
; i
< ((Ty_POLYty
*)cons_ty
)->_2
&& ts
; i
++, ts
= ts
->_2
)
1519 #line 475 "type.pcc"
1520 #line 475 "type.pcc"
1522 #line 475 "type.pcc"
1523 #line 475 "type.pcc"
1525 {error("%Ltoo many arguments %P in instantiation of type scheme %T\n",
1529 if (i
!= ((Ty_POLYty
*)cons_ty
)->_2
)
1530 {error("%Ltoo few arguments %P in instantiation of type scheme %T\n",
1534 Ty t
= inst(((Ty_POLYty
*)cons_ty
)->_1
, ((Ty_POLYty
*)cons_ty
)->_2
, ((Ty_POLYty
*)cons_ty
)->_3
, subst
);
1536 #line 486 "type.pcc"
1537 #line 491 "type.pcc"
1541 switch (_V15
->tag__
) {
1542 case a_Ty::tag_TYCONty
: {
1543 if (boxed(((Ty_TYCONty
*)_V15
)->_1
)) {
1545 #line 488 "type.pcc"
1547 #line 488 "type.pcc"
1549 switch ((int)((Ty_TYCONty
*)_V15
)->_1
) {
1550 case ((int)FUNtycon
): {
1551 if (((Ty_TYCONty
*)_V15
)->_2
) {
1552 if (((Ty_TYCONty
*)_V15
)->_2
->_2
) {
1553 if (((Ty_TYCONty
*)_V15
)->_2
->_2
->_2
) { goto L39
; } else {
1554 #line 487 "type.pcc"
1555 return ((Ty_TYCONty
*)_V15
)->_2
->_1
;
1556 #line 487 "type.pcc"
1558 } else { goto L39
; }
1559 } else { goto L39
; }
1561 default: { goto L39
; } break;
1567 #line 489 "type.pcc"
1568 error ("%Lbad constructor type %T\n",cons_ty
);
1571 #line 491 "type.pcc"
1574 } else { goto L40
; }
1576 #line 492 "type.pcc"
1577 #line 492 "type.pcc"
1580 #line 493 "type.pcc"
1582 default: { goto L38
; } break;
1584 } else { goto L38
; }
1586 #line 496 "type.pcc"
1587 #line 496 "type.pcc"
1591 /////////////////////////////////////////////////////////////////////////////
1593 // Unify two type constructors
1595 /////////////////////////////////////////////////////////////////////////////
1596 Bool
unify(TyCon a
, TyCon b
)
1598 #line 505 "type.pcc"
1599 #line 520 "type.pcc"
1603 case a_TyCon::tag_IDtycon
: {
1606 case a_TyCon::tag_IDtycon
: {
1607 #line 509 "type.pcc"
1608 return ((TyCon_IDtycon
*)a
)->IDtycon
== ((TyCon_IDtycon
*)b
)->IDtycon
;
1609 #line 509 "type.pcc"
1613 #line 520 "type.pcc"
1615 #line 520 "type.pcc"
1618 } else { goto L41
; }
1620 case a_TyCon::tag_ARRAYtycon
: {
1624 case a_TyCon::tag_ARRAYtycon
: {
1626 #line 507 "type.pcc"
1628 #line 507 "type.pcc"
1630 default: { goto L41
; } break;
1634 case ((int)POINTERtycon
): { goto L43
; } break;
1635 default: { goto L41
; } break;
1639 case a_TyCon::tag_BITFIELDtycon
: {
1642 case a_TyCon::tag_BITFIELDtycon
: {
1643 #line 519 "type.pcc"
1644 return ((TyCon_BITFIELDtycon
*)a
)->width
== ((TyCon_BITFIELDtycon
*)b
)->width
&& ((TyCon_BITFIELDtycon
*)a
)->is_signed
== ((TyCon_BITFIELDtycon
*)b
)->is_signed
;
1645 #line 519 "type.pcc"
1647 default: { goto L41
; } break;
1649 } else { goto L41
; }
1651 case a_TyCon::tag_DATATYPEtycon
: {
1654 case a_TyCon::tag_DATATYPEtycon
: {
1655 #line 514 "type.pcc"
1657 #line 514 "type.pcc"
1659 default: { goto L41
; } break;
1661 } else { goto L41
; }
1663 case a_TyCon::tag_COLtycon
: {
1666 case a_TyCon::tag_COLtycon
: {
1667 #line 516 "type.pcc"
1668 return ((TyCon_COLtycon
*)a
)->COLtycon
->name
== ((TyCon_COLtycon
*)b
)->COLtycon
->name
;
1669 #line 516 "type.pcc"
1671 default: { goto L41
; } break;
1673 } else { goto L41
; }
1675 default: { goto L41
; } break;
1679 case ((int)POINTERtycon
): { goto L42
; } break;
1680 case ((int)REFtycon
): {
1681 if (boxed(b
)) { goto L41
; } else {
1683 case ((int)REFtycon
): {
1684 #line 508 "type.pcc"
1686 #line 508 "type.pcc"
1688 default: { goto L41
; } break;
1692 case ((int)TUPLEtycon
): {
1693 if (boxed(b
)) { goto L41
; } else {
1695 case ((int)TUPLEtycon
): {
1696 #line 510 "type.pcc"
1698 #line 510 "type.pcc"
1700 default: { goto L41
; } break;
1704 case ((int)EXTUPLEtycon
): {
1705 if (boxed(b
)) { goto L41
; } else {
1707 case ((int)EXTUPLEtycon
): {
1708 #line 511 "type.pcc"
1710 #line 511 "type.pcc"
1712 default: { goto L41
; } break;
1716 case ((int)FUNtycon
): {
1717 if (boxed(b
)) { goto L41
; } else {
1719 case ((int)FUNtycon
): {
1720 #line 513 "type.pcc"
1722 #line 513 "type.pcc"
1724 default: { goto L41
; } break;
1729 if (boxed(b
)) { goto L41
; } else {
1731 case ((int)TYPEtycon
): {
1732 #line 512 "type.pcc"
1734 #line 512 "type.pcc"
1736 default: { goto L41
; } break;
1743 #line 521 "type.pcc"
1744 #line 521 "type.pcc"
1748 /////////////////////////////////////////////////////////////////////////////
1750 // Unify two record types
1752 /////////////////////////////////////////////////////////////////////////////
1754 (Ty u
, Ids
& x
, Tys
& a
, Bool
& f
,
1755 Ty v
, Ids
& y
, Tys
& b
, Bool
& g
, Bool again
= true)
1760 for (i
= x
, p
= a
; i
; i
= i
->_2
, p
= p
->_2
) {
1761 Bool b_found
= false;
1762 for (j
= y
, q
= b
; j
; j
= j
->_2
, q
= q
->_2
) {
1763 if (i
->_1
== j
->_1
) {
1765 error ("%Lduplicated label '%s' in type %T\n", i
->_1
, v
);
1769 if (! unify(p
->_1
, q
->_1
)) ok
= false;
1772 if (! b_found
&& ! g
) {
1773 error ("%L%s label '%s' in type %T\n",
1774 (again
? "missing" : "extra"), i
->_1
, v
);
1779 // unify in the other direction if not flexible
1780 if (again
&& ! f
) unify_record(v
,y
,b
,g
,u
,x
,a
,f
,false);
1782 if (! f
&& g
) { y
= x
; b
= a
; }
1783 if (! g
&& f
) { x
= y
; a
= b
; }
1791 /////////////////////////////////////////////////////////////////////////////
1795 /////////////////////////////////////////////////////////////////////////////
1796 Bool
occurs (Ty ty
, Ty tyvar
)
1798 #line 573 "type.pcc"
1799 #line 579 "type.pcc"
1801 Ty _V16
= deref_all(ty
);
1803 switch (_V16
->tag__
) {
1804 case a_Ty::tag_VARty
: {
1806 #line 574 "type.pcc"
1808 #line 574 "type.pcc"
1811 #line 574 "type.pcc"
1813 #line 574 "type.pcc"
1817 #line 579 "type.pcc"
1819 #line 579 "type.pcc"
1822 case a_Ty::tag_TYCONty
: {
1823 #line 576 "type.pcc"
1824 for_each(Ty
, t
, ((Ty_TYCONty
*)_V16
)->_2
) if (occurs(t
,tyvar
)) return true;
1827 #line 578 "type.pcc"
1829 default: { goto L44
; } break;
1831 } else { goto L44
; }
1833 #line 580 "type.pcc"
1834 #line 580 "type.pcc"
1838 /////////////////////////////////////////////////////////////////////////////
1840 // Unify two types. Returns true iff unification succeeds.
1842 /////////////////////////////////////////////////////////////////////////////
1843 Bool
unify (Ty t1
, Ty t2
)
1845 #line 589 "type.pcc"
1846 #line 613 "type.pcc"
1848 Ty _V17
= deref(t1
);
1849 Ty _V18
= deref(t2
);
1851 #line 591 "type.pcc"
1853 #line 591 "type.pcc"
1859 #line 591 "type.pcc"
1861 #line 591 "type.pcc"
1864 #line 590 "type.pcc"
1866 #line 590 "type.pcc"
1868 } else { goto L46
; }
1872 switch (_V17
->tag__
) {
1873 case a_Ty::tag_VARty
: {
1875 switch (_V18
->tag__
) {
1876 case a_Ty::tag_VARty
: {
1878 #line 593 "type.pcc"
1879 if (occurs(_V17
,_V18
)) {
1880 error ("%Lunification fails occurs check with %T and %T\n",t1
,t2
);
1882 } else { ((Ty_VARty
*)_V18
)->VARty
= _V17
; return true; }
1884 #line 597 "type.pcc"
1887 #line 599 "type.pcc"
1888 if (occurs(_V18
,_V17
)) {
1889 error ("%Lunification fails occurs check with %T and %T\n",t1
,t2
);
1891 } else { ((Ty_VARty
*)_V17
)->VARty
= _V18
; return true; }
1893 #line 603 "type.pcc"
1896 } else { goto L46
; }
1900 switch (_V18
->tag__
) {
1901 case a_Ty::tag_VARty
: { goto L47
; } break;
1904 #line 605 "type.pcc"
1906 #line 605 "type.pcc"
1907 #line 611 "type.pcc"
1909 Ty _V19
= deref_all(t1
);
1910 Ty _V20
= deref_all(t2
);
1912 #line 606 "type.pcc"
1914 #line 606 "type.pcc"
1917 #line 606 "type.pcc"
1919 #line 606 "type.pcc"
1923 switch (_V19
->tag__
) {
1924 case a_Ty::tag_TYCONty
: {
1926 switch (_V20
->tag__
) {
1927 case a_Ty::tag_TYCONty
: {
1928 if (boxed(((Ty_TYCONty
*)_V19
)->_1
)) {
1929 switch (((Ty_TYCONty
*)_V19
)->_1
->tag__
) {
1930 case a_TyCon::tag_RECORDtycon
: {
1932 switch (_V20
->tag__
) {
1933 case a_Ty::tag_TYCONty
: {
1934 if (boxed(((Ty_TYCONty
*)_V20
)->_1
)) {
1935 switch (((Ty_TYCONty
*)_V20
)->_1
->tag__
) {
1936 case a_TyCon::tag_RECORDtycon
: {
1938 #line 608 "type.pcc"
1939 return unify_record(t1
,((TyCon_RECORDtycon
*)((Ty_TYCONty
*)_V19
)->_1
)->_1
,((Ty_TYCONty
*)_V19
)->_2
,((TyCon_RECORDtycon
*)((Ty_TYCONty
*)_V19
)->_1
)->_2
,t2
,((TyCon_RECORDtycon
*)((Ty_TYCONty
*)_V20
)->_1
)->_1
,((Ty_TYCONty
*)_V20
)->_2
,((TyCon_RECORDtycon
*)((Ty_TYCONty
*)_V20
)->_1
)->_2
);
1940 #line 608 "type.pcc"
1944 #line 609 "type.pcc"
1945 return unify(((Ty_TYCONty
*)_V19
)->_1
,((Ty_TYCONty
*)_V20
)->_1
) && unify(((Ty_TYCONty
*)_V19
)->_2
,((Ty_TYCONty
*)_V20
)->_2
);
1946 #line 609 "type.pcc"
1949 } else { goto L50
; }
1951 default: { goto L50
; } break;
1953 } else { goto L50
; }
1955 default: { goto L50
; } break;
1957 } else { goto L50
; }
1961 if (boxed(((Ty_TYCONty
*)_V19
)->_1
)) {
1962 switch (((Ty_TYCONty
*)_V19
)->_1
->tag__
) {
1963 case a_TyCon::tag_RECORDtycon
: {
1966 switch (_V20
->tag__
) {
1967 case a_Ty::tag_TYCONty
: {
1969 if (boxed(((Ty_TYCONty
*)_V20
)->_1
)) {
1970 switch (((Ty_TYCONty
*)_V20
)->_1
->tag__
) {
1971 case a_TyCon::tag_RECORDtycon
: { goto L49
; } break;
1974 #line 611 "type.pcc"
1976 #line 611 "type.pcc"
1979 } else { goto L54
; }
1981 default: { goto L54
; } break;
1983 } else { goto L54
; }
1985 default: { goto L54
; } break;
1987 } else { goto L54
; }
1990 } else { goto L51
; }
1992 case a_Ty::tag_NESTEDty
: {
1994 switch (_V20
->tag__
) {
1995 case a_Ty::tag_NESTEDty
: {
1996 #line 610 "type.pcc"
1997 return unify(((Ty_NESTEDty
*)_V19
)->_1
,((Ty_NESTEDty
*)_V20
)->_1
) && unify(((Ty_NESTEDty
*)_V19
)->_2
,((Ty_NESTEDty
*)_V20
)->_2
);
1998 #line 610 "type.pcc"
2000 default: { goto L54
; } break;
2002 } else { goto L54
; }
2004 default: { goto L54
; } break;
2006 } else { goto L54
; }
2009 #line 612 "type.pcc"
2010 #line 612 "type.pcc"
2013 #line 613 "type.pcc"
2016 } else { goto L46
; }
2019 } else { goto L46
; }
2022 #line 614 "type.pcc"
2023 #line 614 "type.pcc"
2027 /////////////////////////////////////////////////////////////////////////////
2029 // Unify two type lists.
2031 /////////////////////////////////////////////////////////////////////////////
2032 Bool
unify(Tys xs
, Tys ys
)
2035 #line 624 "type.pcc"
2036 #line 626 "type.pcc"
2041 #line 626 "type.pcc"
2042 if (! unify(xs
->_1
, ys
->_1
)) ok
= false; xs
= xs
->_2
; ys
= ys
->_2
;
2043 #line 626 "type.pcc"
2044 } else { goto L55
; }
2045 } else { goto L55
; }
2049 #line 627 "type.pcc"
2050 #line 627 "type.pcc"
2053 #line 628 "type.pcc"
2054 #line 628 "type.pcc"
2056 #line 628 "type.pcc"
2057 #line 628 "type.pcc"
2059 #line 628 "type.pcc"
2060 #line 628 "type.pcc"
2062 #line 628 "type.pcc"
2063 #line 628 "type.pcc"
2067 /////////////////////////////////////////////////////////////////////////////
2069 // Unify two types and print error message if fails.
2071 /////////////////////////////////////////////////////////////////////////////
2072 Bool
unify(Pat p
, Ty a
, Ty b
)
2074 { error ("%Ltype mismatch in pattern: %p\n"
2075 "%Lexpecting '%T' but found '%T'\n", p
, a
, b
);
2081 /////////////////////////////////////////////////////////////////////////////
2083 // Infer the type of literals
2085 /////////////////////////////////////////////////////////////////////////////
2086 Ty
type_of (Literal l
)
2088 #line 651 "type.pcc"
2089 #line 658 "type.pcc"
2092 case a_Literal::tag_INTlit
: {
2093 #line 652 "type.pcc"
2095 #line 652 "type.pcc"
2097 case a_Literal::tag_BOOLlit
: {
2098 #line 654 "type.pcc"
2100 #line 654 "type.pcc"
2102 case a_Literal::tag_CHARlit
: {
2103 #line 653 "type.pcc"
2104 return character_ty
;
2105 #line 653 "type.pcc"
2107 case a_Literal::tag_REALlit
: {
2108 #line 655 "type.pcc"
2110 #line 655 "type.pcc"
2112 case a_Literal::tag_QUARKlit
: {
2113 #line 656 "type.pcc"
2115 #line 656 "type.pcc"
2117 case a_Literal::tag_BIGINTlit
: {
2118 #line 657 "type.pcc"
2120 #line 657 "type.pcc"
2123 #line 658 "type.pcc"
2125 #line 658 "type.pcc"
2129 #line 659 "type.pcc"
2130 #line 659 "type.pcc"
2134 /////////////////////////////////////////////////////////////////////////////
2136 // Additional pattern variable type map.
2138 /////////////////////////////////////////////////////////////////////////////
2139 HashTable
* patvar_typemap
= 0;
2141 /////////////////////////////////////////////////////////////////////////////
2143 // Infer the type of a pattern.
2145 /////////////////////////////////////////////////////////////////////////////
2146 Ty
type_of (Pat pat
)
2149 #line 676 "type.pcc"
2150 #line 752 "type.pcc"
2153 switch (pat
->tag__
) {
2154 case a_Pat::tag_WILDpat
: {
2155 #line 678 "type.pcc"
2157 #line 678 "type.pcc"
2159 case a_Pat::tag_INDpat
: {
2160 #line 679 "type.pcc"
2161 t
= ((Pat_INDpat
*)pat
)->_3
;
2162 #line 679 "type.pcc"
2164 case a_Pat::tag_IDpat
: {
2165 #line 681 "type.pcc"
2166 t
= ((Pat_IDpat
*)pat
)->_2
;
2167 // If we have a pattern variable type map
2170 { HashTable::Entry
* e
= patvar_typemap
->lookup(((Pat_IDpat
*)pat
)->_1
);
2172 { Ty nonterm_ty
= Ty(e
->v
);
2173 if (!unify(nonterm_ty
,((Pat_IDpat
*)pat
)->_2
))
2174 { error("%Lexpecting non-terminal %s to have type %T but found %T\n",
2175 ((Pat_IDpat
*)pat
)->_1
, nonterm_ty
, ((Pat_IDpat
*)pat
)->_2
);
2180 #line 694 "type.pcc"
2182 case a_Pat::tag_CONSpat
: {
2183 if (((Pat_CONSpat
*)pat
)->CONSpat
) {
2184 #line 736 "type.pcc"
2185 t
= inst(((Pat_CONSpat
*)pat
)->CONSpat
->cons_ty
);
2186 #line 736 "type.pcc"
2188 #line 737 "type.pcc"
2189 errors
++; t
= mkvar();
2190 #line 737 "type.pcc"
2193 case a_Pat::tag_APPpat
: {
2194 #line 739 "type.pcc"
2195 Ty fun_ty
= type_of(((Pat_APPpat
*)pat
)->_1
);
2197 unify(pat
,fun_ty
,mkfunty(type_of(((Pat_APPpat
*)pat
)->_2
), range
));
2200 #line 743 "type.pcc"
2202 case a_Pat::tag_TYPEDpat
: {
2203 #line 734 "type.pcc"
2204 t
= type_of(((Pat_TYPEDpat
*)pat
)->_1
); unify(((Pat_TYPEDpat
*)pat
)->_1
,((Pat_TYPEDpat
*)pat
)->_2
,t
);
2205 #line 734 "type.pcc"
2207 case a_Pat::tag_ASpat
: {
2208 #line 695 "type.pcc"
2209 t
= type_of(((Pat_ASpat
*)pat
)->_2
); unify(pat
,((Pat_ASpat
*)pat
)->_3
,t
);
2210 #line 695 "type.pcc"
2212 case a_Pat::tag_LITERALpat
: {
2213 #line 697 "type.pcc"
2214 t
= type_of(((Pat_LITERALpat
*)pat
)->LITERALpat
);
2215 #line 697 "type.pcc"
2217 case a_Pat::tag_CONTEXTpat
: {
2218 #line 702 "type.pcc"
2219 t
= type_of(((Pat_CONTEXTpat
*)pat
)->_2
);
2220 #line 702 "type.pcc"
2222 case a_Pat::tag_LEXEMEpat
: {
2223 #line 698 "type.pcc"
2225 #line 698 "type.pcc"
2227 case a_Pat::tag_ARRAYpat
: {
2228 #line 711 "type.pcc"
2230 for_each(Pat
,p
,((Pat_ARRAYpat
*)pat
)->_1
) unify(pat
,ty
,type_of(p
));
2231 t
= mkptrty(QUALty(QUALconst
,ty
));
2233 #line 714 "type.pcc"
2235 case a_Pat::tag_TUPLEpat
: {
2236 #line 699 "type.pcc"
2237 t
= mktuplety(type_of(((Pat_TUPLEpat
*)pat
)->TUPLEpat
));
2238 #line 699 "type.pcc"
2240 case a_Pat::tag_EXTUPLEpat
: {
2241 #line 700 "type.pcc"
2242 t
= TYCONty(EXTUPLEtycon
,type_of(((Pat_EXTUPLEpat
*)pat
)->EXTUPLEpat
));
2243 #line 700 "type.pcc"
2245 case a_Pat::tag_RECORDpat
: {
2246 #line 703 "type.pcc"
2247 t
= mkrecordty(labels_of(((Pat_RECORDpat
*)pat
)->_1
),type_of(((Pat_RECORDpat
*)pat
)->_1
),((Pat_RECORDpat
*)pat
)->_2
);
2248 #line 703 "type.pcc"
2250 case a_Pat::tag_LISTpat
: {
2251 if (((Pat_LISTpat
*)pat
)->head
) {
2252 #line 749 "type.pcc"
2253 t
= type_of(APPpat(CONSpat(((Pat_LISTpat
*)pat
)->cons
),
2255 #line 750 "type.pcc"
2256 #line 750 "type.pcc"
2257 list_1_(((Pat_LISTpat
*)pat
)->head
->_1
,list_1_(LISTpat(((Pat_LISTpat
*)pat
)->cons
,((Pat_LISTpat
*)pat
)->nil
,((Pat_LISTpat
*)pat
)->head
->_2
,((Pat_LISTpat
*)pat
)->tail
)))
2258 #line 750 "type.pcc"
2259 #line 750 "type.pcc"
2262 #line 751 "type.pcc"
2264 if (((Pat_LISTpat
*)pat
)->tail
) {
2265 #line 747 "type.pcc"
2266 t
= type_of(((Pat_LISTpat
*)pat
)->tail
);
2267 #line 747 "type.pcc"
2269 #line 745 "type.pcc"
2270 t
= type_of(CONSpat(((Pat_LISTpat
*)pat
)->nil
));
2271 #line 745 "type.pcc"
2275 case a_Pat::tag_VECTORpat
: {
2276 #line 716 "type.pcc"
2277 Ty arg_ty
= mkvar();
2278 for_each(Pat
,p
,((Pat_VECTORpat
*)pat
)->elements
) unify(pat
,arg_ty
,type_of(p
));
2279 Ty vec_ty
= type_of(CONSpat(((Pat_VECTORpat
*)pat
)->cons
));
2280 Ty range_ty
= mkvar();
2281 if (((Pat_VECTORpat
*)pat
)->len
!= NOpat
)
2282 unify(pat
,integer_ty
,type_of(((Pat_VECTORpat
*)pat
)->len
));
2283 if (((Pat_VECTORpat
*)pat
)->array
!= NOpat
)
2284 unify(pat
,mkptrty(arg_ty
),type_of(((Pat_VECTORpat
*)pat
)->array
));
2285 unify(pat
,vec_ty
,mkfunty(arg_ty
, range_ty
));
2286 t
= deref(range_ty
);
2288 #line 726 "type.pcc"
2290 case a_Pat::tag_APPENDpat
: {
2291 #line 705 "type.pcc"
2292 Ty t1
= type_of(((Pat_APPENDpat
*)pat
)->_1
);
2293 Ty t2
= type_of(((Pat_APPENDpat
*)pat
)->_2
);
2294 t
= ((Pat_APPENDpat
*)pat
)->_3
= t1
;
2297 #line 709 "type.pcc"
2299 case a_Pat::tag_GUARDpat
: {
2300 #line 701 "type.pcc"
2301 t
= type_of(((Pat_GUARDpat
*)pat
)->_1
);
2302 #line 701 "type.pcc"
2304 case a_Pat::tag_LOGICALpat
: {
2305 switch (((Pat_LOGICALpat
*)pat
)->_1
) {
2307 #line 727 "type.pcc"
2308 t
= type_of(((Pat_LOGICALpat
*)pat
)->_2
);
2309 #line 727 "type.pcc"
2312 #line 728 "type.pcc"
2313 Ty ty1
= type_of(((Pat_LOGICALpat
*)pat
)->_2
);
2314 Ty ty2
= type_of(((Pat_LOGICALpat
*)pat
)->_3
);
2318 #line 732 "type.pcc"
2322 case a_Pat::tag_UNIFYpat
: {
2323 #line 696 "type.pcc"
2324 t
= type_of(((Pat_UNIFYpat
*)pat
)->_1
);
2325 #line 696 "type.pcc"
2327 case a_Pat::tag_MARKEDpat
: {
2328 #line 735 "type.pcc"
2329 t
= type_of(((Pat_MARKEDpat
*)pat
)->_2
);
2330 #line 735 "type.pcc"
2333 #line 752 "type.pcc"
2334 bug("type_of(Pat)");
2335 #line 752 "type.pcc"
2339 #line 677 "type.pcc"
2341 #line 677 "type.pcc"
2344 #line 753 "type.pcc"
2345 #line 753 "type.pcc"
2347 if (boxed(pat
)) pat
->ty
= t
;
2351 /////////////////////////////////////////////////////////////////////////////
2353 // Infer the type of a pattern list.
2355 /////////////////////////////////////////////////////////////////////////////
2356 Tys
type_of(Pats ps
)
2358 #line 764 "type.pcc"
2359 #line 766 "type.pcc"
2362 #line 766 "type.pcc"
2364 #line 766 "type.pcc"
2365 #line 766 "type.pcc"
2366 list_1_(type_of(ps
->_1
),type_of(ps
->_2
))
2367 #line 766 "type.pcc"
2368 #line 766 "type.pcc"
2370 #line 766 "type.pcc"
2372 #line 765 "type.pcc"
2374 #line 765 "type.pcc"
2375 #line 765 "type.pcc"
2377 #line 765 "type.pcc"
2378 #line 765 "type.pcc"
2380 #line 765 "type.pcc"
2383 #line 767 "type.pcc"
2384 #line 767 "type.pcc"
2388 /////////////////////////////////////////////////////////////////////////////
2390 // Infer the type of a labeled pattern list.
2392 /////////////////////////////////////////////////////////////////////////////
2393 Tys
type_of(LabPats ps
)
2395 #line 776 "type.pcc"
2396 #line 778 "type.pcc"
2399 #line 778 "type.pcc"
2401 #line 778 "type.pcc"
2402 #line 778 "type.pcc"
2403 list_1_(type_of(ps
->_1
.pat
),type_of(ps
->_2
))
2404 #line 778 "type.pcc"
2405 #line 778 "type.pcc"
2407 #line 778 "type.pcc"
2409 #line 777 "type.pcc"
2411 #line 777 "type.pcc"
2412 #line 777 "type.pcc"
2414 #line 777 "type.pcc"
2415 #line 777 "type.pcc"
2417 #line 777 "type.pcc"
2420 #line 779 "type.pcc"
2421 #line 779 "type.pcc"
2425 /////////////////////////////////////////////////////////////////////////////
2427 // Get the list of labels from a labeled pattern list.
2429 /////////////////////////////////////////////////////////////////////////////
2430 Ids
labels_of(LabPats ps
)
2432 #line 788 "type.pcc"
2433 #line 790 "type.pcc"
2436 #line 790 "type.pcc"
2438 #line 790 "type.pcc"
2439 #line 790 "type.pcc"
2440 list_1_(ps
->_1
.label
,labels_of(ps
->_2
))
2441 #line 790 "type.pcc"
2442 #line 790 "type.pcc"
2444 #line 790 "type.pcc"
2446 #line 789 "type.pcc"
2448 #line 789 "type.pcc"
2449 #line 789 "type.pcc"
2451 #line 789 "type.pcc"
2452 #line 789 "type.pcc"
2454 #line 789 "type.pcc"
2457 #line 791 "type.pcc"
2458 #line 791 "type.pcc"
2462 /////////////////////////////////////////////////////////////////////////////
2464 // Infer the type of a set of pattern rules.
2466 /////////////////////////////////////////////////////////////////////////////
2467 Ty
type_match_rules(MatchRules rules
)
2469 MEM::use_global_pools();
2471 for_each(MatchRule
, r
, rules
)
2473 #line 804 "type.pcc"
2474 #line 813 "type.pcc"
2476 #line 806 "type.pcc"
2478 Ty this_ty
= type_of(r
->_2
);
2479 if (this_ty
== NOty
)
2480 { error ("%!type error in pattern %p: %T\n",
2481 r
->loc(), r
->_2
, this_ty
);
2483 } else if (! unify(r
->_2
,ty
,this_ty
)) ok
= false;
2485 #line 813 "type.pcc"
2487 #line 814 "type.pcc"
2488 #line 814 "type.pcc"
2491 MEM::use_local_pools();
2492 return ok
? ty
: NOty
;
2495 /////////////////////////////////////////////////////////////////////////////
2497 // The type and constructor environments (both are flat for now.)
2499 /////////////////////////////////////////////////////////////////////////////
2500 HashTable
ty_env(string_hash
,string_equal
,91);
2501 HashTable
cons_env(string_hash
,string_equal
,129);
2502 HashTable
token_env(string_hash
,string_equal
,129);
2504 /////////////////////////////////////////////////////////////////////////////
2506 // Lookup the type from its name.
2508 /////////////////////////////////////////////////////////////////////////////
2510 { HashTable::Entry
* i
= ty_env
.lookup(id
);
2511 return i
? inst(value_of(Ty
,ty_env
,i
)) : NOty
;
2514 /////////////////////////////////////////////////////////////////////////////
2516 // Lookup the constructor from its name.
2518 /////////////////////////////////////////////////////////////////////////////
2519 Cons
lookup_cons(Id id
)
2520 { Cons c
= find_cons(id
);
2522 { error ("%Lconstructor '%s' is undefined\n", id
);
2527 Cons
lookup_token (Id id
)
2529 HashTable::Entry
* i
= token_env
.lookup(id
);
2530 if (i
) return (Cons
)i
->v
;
2534 error ("%Llexeme %s is undefined\n", id
);
2536 error ("%Lconstructor '%s' is undefined\n", id
);
2541 Cons
find_cons(Id id
)
2542 { HashTable::Entry
* i
= cons_env
.lookup(id
);
2543 return i
? value_of(Cons
,cons_env
,i
) : NOcons
;
2546 /////////////////////////////////////////////////////////////////////////////
2548 // Add a new type to the environment.
2550 /////////////////////////////////////////////////////////////////////////////
2551 void add_type(Id id
, TyVars tyvars
, Ty ty
)
2552 { HashTable::Entry
* i
= ty_env
.lookup(id
);
2554 error("%Ltype %s has already been defined as %T\n",
2555 id
, value_of(Ty
,ty_env
,i
));
2558 #line 882 "type.pcc"
2559 #line 886 "type.pcc"
2561 Ty _V21
= deref_all(ty
);
2563 switch (_V21
->tag__
) {
2564 case a_Ty::tag_TYCONty
: {
2565 if (boxed(((Ty_TYCONty
*)_V21
)->_1
)) {
2566 switch (((Ty_TYCONty
*)_V21
)->_1
->tag__
) {
2567 case a_TyCon::tag_IDtycon
: {
2569 #line 883 "type.pcc"
2570 (((TyCon_IDtycon
*)((Ty_TYCONty
*)_V21
)->_1
)->IDtycon
== id
)
2571 #line 883 "type.pcc"
2574 #line 884 "type.pcc"
2575 error("%Lcyclic type definition in type %s%V = %T\n",id
,tyvars
,ty
);
2577 #line 885 "type.pcc"
2581 #line 886 "type.pcc"
2582 ty_env
.insert(id
,mkpolyty(ty
,tyvars
));
2583 #line 886 "type.pcc"
2586 default: { goto L56
; } break;
2588 } else { goto L56
; }
2590 default: { goto L56
; } break;
2592 } else { goto L56
; }
2594 #line 887 "type.pcc"
2595 #line 887 "type.pcc"
2600 /////////////////////////////////////////////////////////////////////////////
2602 // Method to add a new datatype to the environment.
2604 /////////////////////////////////////////////////////////////////////////////
2605 void add_datatype( const Loc
* location
,
2614 { HashTable::Entry
* i
= ty_env
.lookup(id
);
2616 Ty ty
= (Ty
)ty_env
.value(i
);
2618 #line 908 "type.pcc"
2619 #line 915 "type.pcc"
2621 Ty _V22
= deref_all(ty
);
2623 switch (_V22
->tag__
) {
2624 case a_Ty::tag_TYCONty
: {
2625 if (boxed(((Ty_TYCONty
*)_V22
)->_1
)) {
2626 switch (((Ty_TYCONty
*)_V22
)->_1
->tag__
) {
2627 case a_TyCon::tag_DATATYPEtycon
: {
2628 #line 910 "type.pcc"
2629 error("%Lredefinition of datatype %s\n"
2630 "%!this is where datatype %s was previously defined\n",
2631 id
, ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V22
)->_1
)->location
, id
);
2633 #line 913 "type.pcc"
2637 #line 915 "type.pcc"
2638 error("%Lredefinition of datatype %s\n", id
);
2639 #line 915 "type.pcc"
2642 } else { goto L57
; }
2644 default: { goto L57
; } break;
2646 } else { goto L57
; }
2648 #line 916 "type.pcc"
2649 #line 916 "type.pcc"
2653 #line 918 "type.pcc"
2654 #line 918 "type.pcc"
2655 DATATYPEtycon(id
, 0, 0, 0, tyvars
, NOty
, inherit
, qual
, 0, body
, view_match
, location
, 0)
2656 #line 930 "type.pcc"
2657 #line 930 "type.pcc"
2659 Ty this_ty
= TYCONty(tycon
, tyvars_to_type_list(0,tyvars
));
2660 int variants
= length(terms
);
2663 Cons
* all_conses
= (Cons
*)mem_pool
[variants
* sizeof(Cons
)];
2666 int optimizations
= 0;
2667 int arity
= length(tyvars
);
2668 Id
* bound_vars
= (Id
*)mem_pool
[arity
* sizeof(Id
)];
2670 for_each (TyVar
, tv
, tyvars
)
2671 bound_vars
[i
++] = tv
;
2674 { for_each(TermDef
, t
, terms
)
2676 #line 947 "type.pcc"
2677 #line 949 "type.pcc"
2680 #line 949 "type.pcc"
2682 #line 949 "type.pcc"
2684 #line 948 "type.pcc"
2686 #line 948 "type.pcc"
2689 #line 950 "type.pcc"
2690 #line 950 "type.pcc"
2694 Ty poly
= mkpolyty(this_ty
, tyvars
);
2696 // compute optimizations.
2697 if (args
== 1) optimizations
|= OPTsubclassless
| OPTtagless
;
2698 if (args
> 1 && args
<= options
.max_embedded_tags
2699 && (qual
& QUALvirtual
) == 0
2700 && (options
.tagged_pointer
|| (qual
& QUALtaggedpointer
)))
2701 optimizations
|= OPTtaggedpointer
| OPTtagless
;
2703 optimizations
|= OPTtagless
;
2705 int actual_boxed
= 0;
2706 for_each(TermDef
, t
, terms
)
2708 #line 966 "type.pcc"
2709 #line 1034 "type.pcc"
2712 #line 967 "type.pcc"
2714 #line 967 "type.pcc"
2717 #line 968 "type.pcc"
2718 qual
|= QUALextensible
;
2719 #line 968 "type.pcc"
2722 #line 972 "type.pcc"
2725 (qual
& QUALlexeme
) && t
->id
[0] == '"'
2726 ? LITERALpat(STRINGlit(t
->id
)) : t
->pat
;
2727 Cons last_cons
= find_cons(t
->id
);
2728 if (last_cons
!= NOcons
) {
2729 error ("%!redefinition of constructor '%s'\n"
2730 "%!this is where '%s' was last defined.\n",
2731 t
->loc(), t
->id
, last_cons
->location
, t
->id
);
2733 if (t
->ty
== NOty
) tag
= unit_count
++; else tag
= arg_count
++;
2734 if (t
->print_formats
!=
2735 #line 983 "type.pcc"
2736 #line 983 "type.pcc"
2738 #line 983 "type.pcc"
2739 #line 983 "type.pcc"
2740 ) qual
|= QUALprintable
;
2741 Ty cons_ty
= t
->ty
== NOty
2743 : POLYty(mkfunty(t
->ty
, this_ty
), arity
, bound_vars
);
2745 // Use unboxed optimization
2746 // only if we are also using the tagged pointer rep.
2747 // Make sure (1) the type is embeddable into 1 word.
2748 // (2) We are monomorphic.
2749 // (3) We are not using any inheritance.
2750 int this_opt
= OPTnone
;
2751 if ((optimizations
& OPTtaggedpointer
) &&
2753 #line 995 "type.pcc"
2754 #line 995 "type.pcc"
2756 #line 995 "type.pcc"
2757 #line 995 "type.pcc"
2760 #line 996 "type.pcc"
2761 #line 996 "type.pcc"
2763 #line 996 "type.pcc"
2764 #line 996 "type.pcc"
2766 t
->opt
== OPTunboxed
&&
2767 (qual
& (QUALrewritable
| QUALcollectable
|
2768 QUALrelation
| QUALpersistent
))
2770 is_embeddable_ty(t
->ty
))
2771 this_opt
= OPTunboxed
;
2773 Exp
* view_selectors
=
2775 (Exp
*)mem_pool
.c_alloc(arity_of(t
->ty
) * sizeof(Exp
)) : 0;
2777 #line 1007 "type.pcc"
2778 #line 1007 "type.pcc"
2779 ONEcons(t
->id
, this_ty
, cons_ty
, t
->ty
, tag
, t
->print_formats
, t
->loc(), t
->inherits
, t
->decls
, this_opt
, t
->qual
, t
->view_predicate
, view_selectors
, lexeme_pat
, 0)
2780 #line 1021 "type.pcc"
2781 #line 1021 "type.pcc"
2783 all_conses
[t
->ty
== NOty
? tag
: tag
+ units
] = cons
;
2784 if (t
->ty
!= NOty
&& (this_opt
& OPTunboxed
) == 0)
2787 // update the constructor environment
2788 cons_env
.insert(t
->id
, cons
);
2790 // update the token environment
2792 #line 1030 "type.pcc"
2793 #line 1033 "type.pcc"
2796 switch (lexeme_pat
->tag__
) {
2797 case a_Pat::tag_LITERALpat
: {
2798 switch (((Pat_LITERALpat
*)lexeme_pat
)->LITERALpat
->tag__
) {
2799 case a_Literal::tag_STRINGlit
: {
2800 #line 1031 "type.pcc"
2801 token_env
.insert(((Literal_STRINGlit
*)((Pat_LITERALpat
*)lexeme_pat
)->LITERALpat
)->STRINGlit
, cons
);
2802 #line 1031 "type.pcc"
2808 default: { goto L58
; } break;
2810 } else { goto L58
; }
2812 #line 1033 "type.pcc"
2813 #line 1033 "type.pcc"
2816 #line 1034 "type.pcc"
2819 #line 1035 "type.pcc"
2820 #line 1035 "type.pcc"
2824 if (actual_boxed
<= 1) optimizations
|= OPTsubclassless
| OPTtagless
;
2826 if (tyvars
&& unit_count
> 1)
2827 error("%Lmultiple unit constructors in polymorphic type %s%V"
2828 " is not supported\n",
2832 #line 1045 "type.pcc"
2833 #line 1050 "type.pcc"
2836 switch (tycon
->tag__
) {
2837 case a_TyCon::tag_DATATYPEtycon
: {
2838 #line 1047 "type.pcc"
2839 ((TyCon_DATATYPEtycon
*)tycon
)->unit
= unit_count
; ((TyCon_DATATYPEtycon
*)tycon
)->arg
= arg_count
; ((TyCon_DATATYPEtycon
*)tycon
)->terms
= all_conses
;
2840 ((TyCon_DATATYPEtycon
*)tycon
)->polyty
= poly
; ((TyCon_DATATYPEtycon
*)tycon
)->opt
= optimizations
; ((TyCon_DATATYPEtycon
*)tycon
)->qualifiers
= qual
;
2842 #line 1049 "type.pcc"
2847 } else { goto L59
; }
2849 #line 1051 "type.pcc"
2850 #line 1051 "type.pcc"
2853 ty_env
.insert(id
, poly
);
2854 if (qual
& QUALlexeme
) update_lexeme_class(id
, terms
);
2856 // Create new type hierarchy
2857 new DatatypeHierarchy(id
,tyvars
,inherit
,qual
,terms
,body
);
2861 /////////////////////////////////////////////////////////////////////////////
2863 // Method to refine the implementation of a datatype.
2865 /////////////////////////////////////////////////////////////////////////////
2866 void update_datatype (Id id
, TyVars tyvars
, Inherits superclasses
,
2867 TyQual qual
, Decls decls
)
2870 #line 1069 "type.pcc"
2871 #line 1080 "type.pcc"
2873 Ty _V23
= lookup_ty(id
);
2875 switch (_V23
->tag__
) {
2876 case a_Ty::tag_TYCONty
: {
2877 if (boxed(((Ty_TYCONty
*)_V23
)->_1
)) {
2878 switch (((Ty_TYCONty
*)_V23
)->_1
->tag__
) {
2879 case a_TyCon::tag_DATATYPEtycon
: {
2881 #line 1070 "type.pcc"
2882 (((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V23
)->_1
)->hierarchy
!= 0)
2883 #line 1070 "type.pcc"
2886 #line 1071 "type.pcc"
2888 ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V23
)->_1
)->hierarchy
->inherited_classes
=
2889 append(((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V23
)->_1
)->hierarchy
->inherited_classes
,superclasses
);
2890 ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V23
)->_1
)->hierarchy
->qualifiers
|= qual
;
2891 ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V23
)->_1
)->qualifiers
|= qual
;
2893 ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V23
)->_1
)->hierarchy
->class_body
= append(((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V23
)->_1
)->hierarchy
->class_body
,decls
);
2895 #line 1078 "type.pcc"
2899 #line 1080 "type.pcc"
2900 error ("%Ltype %s = %T is not a datatype\n",id
, _V23
);
2901 #line 1080 "type.pcc"
2904 default: { goto L60
; } break;
2906 } else { goto L60
; }
2908 default: { goto L60
; } break;
2911 #line 1079 "type.pcc"
2913 #line 1079 "type.pcc"
2916 #line 1081 "type.pcc"
2917 #line 1081 "type.pcc"
2921 /////////////////////////////////////////////////////////////////////////////
2923 // Method to refine the implementation of a datatype constructor.
2925 /////////////////////////////////////////////////////////////////////////////
2926 void update_constructor
2927 (Id id
, Tys ty_args
, Inherits inh
, PrintFormats pf
, Decls decls
)
2929 #line 1091 "type.pcc"
2930 #line 1108 "type.pcc"
2932 Cons _V24
= lookup_cons(id
);
2935 switch (_V24
->alg_ty
->tag__
) {
2936 case a_Ty::tag_TYCONty
: {
2937 if (boxed(((Ty_TYCONty
*)_V24
->alg_ty
)->_1
)) {
2938 switch (((Ty_TYCONty
*)_V24
->alg_ty
)->_1
->tag__
) {
2939 case a_TyCon::tag_DATATYPEtycon
: {
2940 #line 1095 "type.pcc"
2942 if (_V24
->print_formats
)
2943 error("%Lconstructor %s already has print formats\n",id
);
2945 _V24
->print_formats
= pf
;
2946 ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V24
->alg_ty
)->_1
)->qualifiers
|= QUALprintable
;
2949 _V24
->class_def
->class_body
= append(_V24
->class_def
->class_body
,decls
);
2951 _V24
->class_def
->inherited_classes
= append(_V24
->class_def
->inherited_classes
,
2954 #line 1107 "type.pcc"
2958 #line 1108 "type.pcc"
2960 #line 1108 "type.pcc"
2963 } else { goto L61
; }
2965 default: { goto L61
; } break;
2967 } else { goto L61
; }
2968 } else { goto L61
; }
2970 #line 1109 "type.pcc"
2971 #line 1109 "type.pcc"
2975 /////////////////////////////////////////////////////////////////////////////
2977 // Hashing function on types
2979 /////////////////////////////////////////////////////////////////////////////
2980 unsigned int ty_hash(HashTable::Key k
)
2983 #line 1119 "type.pcc"
2984 #line 1144 "type.pcc"
2986 Ty _V25
= deref_all(ty
);
2988 switch (_V25
->tag__
) {
2989 case a_Ty::tag_VARty
: {
2990 #line 1121 "type.pcc"
2991 return (unsigned int)_V25
;
2992 #line 1121 "type.pcc"
2994 case a_Ty::tag_TYCONty
: {
2995 #line 1123 "type.pcc"
2998 #line 1124 "type.pcc"
2999 #line 1139 "type.pcc"
3001 TyCon _V26
= ((Ty_TYCONty
*)_V25
)->_1
;
3003 switch (_V26
->tag__
) {
3004 case a_TyCon::tag_IDtycon
: {
3005 #line 1132 "type.pcc"
3006 h
= string_hash(((TyCon_IDtycon
*)_V26
)->IDtycon
) + 89;
3007 #line 1132 "type.pcc"
3009 case a_TyCon::tag_RECORDtycon
: {
3010 #line 1128 "type.pcc"
3012 #line 1128 "type.pcc"
3014 case a_TyCon::tag_ARRAYtycon
: {
3015 #line 1131 "type.pcc"
3017 #line 1131 "type.pcc"
3019 case a_TyCon::tag_BITFIELDtycon
: {
3020 #line 1134 "type.pcc"
3021 h
= 733 + ((TyCon_BITFIELDtycon
*)_V26
)->width
;
3022 #line 1134 "type.pcc"
3024 case a_TyCon::tag_DATATYPEtycon
: {
3025 #line 1133 "type.pcc"
3026 h
= string_hash(((TyCon_DATATYPEtycon
*)_V26
)->id
) + 431;
3027 #line 1133 "type.pcc"
3029 case a_TyCon::tag_COLtycon
: {
3030 #line 1136 "type.pcc"
3031 h
= string_hash(((TyCon_COLtycon
*)_V26
)->COLtycon
->name
) + 1345;
3032 #line 1136 "type.pcc"
3034 case a_TyCon::tag_GRAPHtycon
: {
3035 #line 1137 "type.pcc"
3036 h
= (int)((TyCon_GRAPHtycon
*)_V26
)->GRAPHtycon
;
3037 #line 1137 "type.pcc"
3039 case a_TyCon::tag_NODEtycon
: {
3040 #line 1138 "type.pcc"
3041 h
= (int)((TyCon_NODEtycon
*)_V26
)->NODEtycon
;
3042 #line 1138 "type.pcc"
3045 #line 1139 "type.pcc"
3046 h
= (int)((TyCon_EDGEtycon
*)_V26
)->EDGEtycon
;
3047 #line 1139 "type.pcc"
3051 switch ((int)_V26
) {
3052 case ((int)POINTERtycon
): {
3053 #line 1125 "type.pcc"
3055 #line 1125 "type.pcc"
3057 case ((int)REFtycon
): {
3058 #line 1126 "type.pcc"
3060 #line 1126 "type.pcc"
3062 case ((int)TUPLEtycon
): {
3063 #line 1129 "type.pcc"
3065 #line 1129 "type.pcc"
3067 case ((int)EXTUPLEtycon
): {
3068 #line 1130 "type.pcc"
3070 #line 1130 "type.pcc"
3072 case ((int)FUNtycon
): {
3073 #line 1127 "type.pcc"
3075 #line 1127 "type.pcc"
3078 #line 1135 "type.pcc"
3080 #line 1135 "type.pcc"
3085 #line 1140 "type.pcc"
3086 #line 1140 "type.pcc"
3088 return h
+ tys_hash(((Ty_TYCONty
*)_V25
)->_2
);
3090 #line 1142 "type.pcc"
3092 case a_Ty::tag_NESTEDty
: {
3093 #line 1143 "type.pcc"
3094 return ty_hash(((Ty_NESTEDty
*)_V25
)->_1
) + ty_hash(((Ty_NESTEDty
*)_V25
)->_2
);
3095 #line 1143 "type.pcc"
3098 #line 1144 "type.pcc"
3100 #line 1144 "type.pcc"
3104 #line 1120 "type.pcc"
3106 #line 1120 "type.pcc"
3109 #line 1145 "type.pcc"
3110 #line 1145 "type.pcc"
3114 /////////////////////////////////////////////////////////////////////////////
3116 // Hashing function on type list
3118 /////////////////////////////////////////////////////////////////////////////
3119 unsigned int tys_hash(HashTable::Key k
)
3122 for_each (Ty
, t
, tys
) h
+= ty_hash(t
);
3126 /////////////////////////////////////////////////////////////////////////////
3128 // Equality function on types
3130 /////////////////////////////////////////////////////////////////////////////
3131 Bool
ty_equal(HashTable::Key a
, HashTable::Key b
)
3132 { Ty u
= (Ty
)a
, v
= (Ty
)b
;
3134 #line 1167 "type.pcc"
3135 #line 1194 "type.pcc"
3137 Ty _V27
= deref_all(u
);
3138 Ty _V28
= deref_all(v
);
3140 #line 1168 "type.pcc"
3142 #line 1168 "type.pcc"
3145 #line 1168 "type.pcc"
3147 #line 1168 "type.pcc"
3151 switch (_V27
->tag__
) {
3152 case a_Ty::tag_VARty
: {
3154 switch (_V28
->tag__
) {
3155 case a_Ty::tag_VARty
: {
3156 #line 1169 "type.pcc"
3157 return _V27
== _V28
;
3158 #line 1169 "type.pcc"
3162 #line 1194 "type.pcc"
3164 #line 1194 "type.pcc"
3167 } else { goto L62
; }
3169 case a_Ty::tag_TYCONty
: {
3171 switch (_V28
->tag__
) {
3172 case a_Ty::tag_TYCONty
: {
3173 if (boxed(((Ty_TYCONty
*)_V27
)->_1
)) {
3174 switch (((Ty_TYCONty
*)_V27
)->_1
->tag__
) {
3175 case a_TyCon::tag_RECORDtycon
: {
3177 switch (_V28
->tag__
) {
3178 case a_Ty::tag_TYCONty
: {
3179 if (boxed(((Ty_TYCONty
*)_V28
)->_1
)) {
3180 switch (((Ty_TYCONty
*)_V28
)->_1
->tag__
) {
3181 case a_TyCon::tag_RECORDtycon
: {
3183 #line 1174 "type.pcc"
3185 if (length(((Ty_TYCONty
*)_V27
)->_2
) != length(((Ty_TYCONty
*)_V28
)->_2
)) return false;
3186 for (i
= ((TyCon_RECORDtycon
*)((Ty_TYCONty
*)_V27
)->_1
)->_1
, t
= ((Ty_TYCONty
*)_V27
)->_2
; i
; i
= i
->_2
, t
= t
->_2
)
3187 { Bool found
= false;
3188 for (j
= ((TyCon_RECORDtycon
*)((Ty_TYCONty
*)_V28
)->_1
)->_1
, u
= ((Ty_TYCONty
*)_V28
)->_2
; j
; j
= j
->_2
, u
= u
->_2
)
3189 { if (i
->_1
== j
->_1
) {
3190 if (! ty_equal(t
->_1
, u
->_2
)) return false;
3191 found
= true; break;
3194 if (! found
) return false;
3198 #line 1187 "type.pcc"
3202 #line 1189 "type.pcc"
3203 if (! unify(((Ty_TYCONty
*)_V27
)->_1
,((Ty_TYCONty
*)_V28
)->_1
)) return false;
3204 return tys_equal(((Ty_TYCONty
*)_V27
)->_2
,((Ty_TYCONty
*)_V28
)->_2
);
3206 #line 1191 "type.pcc"
3209 } else { goto L64
; }
3211 default: { goto L64
; } break;
3213 } else { goto L64
; }
3215 case a_TyCon::tag_GRAPHtycon
: {
3217 switch (_V28
->tag__
) {
3218 case a_Ty::tag_TYCONty
: {
3219 if (boxed(((Ty_TYCONty
*)_V28
)->_1
)) {
3220 switch (((Ty_TYCONty
*)_V28
)->_1
->tag__
) {
3221 case a_TyCon::tag_GRAPHtycon
: {
3223 #line 1170 "type.pcc"
3224 return ((TyCon_GRAPHtycon
*)((Ty_TYCONty
*)_V27
)->_1
)->GRAPHtycon
== ((TyCon_GRAPHtycon
*)((Ty_TYCONty
*)_V28
)->_1
)->GRAPHtycon
;
3225 #line 1170 "type.pcc"
3227 default: { goto L64
; } break;
3229 } else { goto L64
; }
3231 default: { goto L64
; } break;
3233 } else { goto L64
; }
3235 case a_TyCon::tag_NODEtycon
: {
3237 switch (_V28
->tag__
) {
3238 case a_Ty::tag_TYCONty
: {
3239 if (boxed(((Ty_TYCONty
*)_V28
)->_1
)) {
3240 switch (((Ty_TYCONty
*)_V28
)->_1
->tag__
) {
3241 case a_TyCon::tag_NODEtycon
: {
3243 #line 1171 "type.pcc"
3244 return ((TyCon_NODEtycon
*)((Ty_TYCONty
*)_V27
)->_1
)->NODEtycon
== ((TyCon_NODEtycon
*)((Ty_TYCONty
*)_V28
)->_1
)->NODEtycon
;
3245 #line 1171 "type.pcc"
3247 default: { goto L64
; } break;
3249 } else { goto L64
; }
3251 default: { goto L64
; } break;
3253 } else { goto L64
; }
3255 case a_TyCon::tag_EDGEtycon
: {
3257 switch (_V28
->tag__
) {
3258 case a_Ty::tag_TYCONty
: {
3259 if (boxed(((Ty_TYCONty
*)_V28
)->_1
)) {
3260 switch (((Ty_TYCONty
*)_V28
)->_1
->tag__
) {
3261 case a_TyCon::tag_EDGEtycon
: {
3263 #line 1172 "type.pcc"
3264 return ((TyCon_EDGEtycon
*)((Ty_TYCONty
*)_V27
)->_1
)->EDGEtycon
== ((TyCon_EDGEtycon
*)((Ty_TYCONty
*)_V28
)->_1
)->EDGEtycon
;
3265 #line 1172 "type.pcc"
3267 default: { goto L64
; } break;
3269 } else { goto L64
; }
3271 default: { goto L64
; } break;
3273 } else { goto L64
; }
3275 default: { goto L64
; } break;
3277 } else { goto L64
; }
3281 if (boxed(((Ty_TYCONty
*)_V27
)->_1
)) {
3282 switch (((Ty_TYCONty
*)_V27
)->_1
->tag__
) {
3283 case a_TyCon::tag_RECORDtycon
: {
3286 switch (_V28
->tag__
) {
3287 case a_Ty::tag_TYCONty
: {
3289 if (boxed(((Ty_TYCONty
*)_V28
)->_1
)) {
3290 switch (((Ty_TYCONty
*)_V28
)->_1
->tag__
) {
3291 case a_TyCon::tag_RECORDtycon
: { goto L63
; } break;
3292 default: { goto L62
; } break;
3294 } else { goto L62
; }
3296 default: { goto L62
; } break;
3298 } else { goto L62
; }
3300 case a_TyCon::tag_GRAPHtycon
: {
3303 switch (_V28
->tag__
) {
3304 case a_Ty::tag_TYCONty
: {
3306 if (boxed(((Ty_TYCONty
*)_V28
)->_1
)) {
3307 switch (((Ty_TYCONty
*)_V28
)->_1
->tag__
) {
3308 case a_TyCon::tag_GRAPHtycon
: { goto L65
; } break;
3309 default: { goto L62
; } break;
3311 } else { goto L62
; }
3313 default: { goto L62
; } break;
3315 } else { goto L62
; }
3317 case a_TyCon::tag_NODEtycon
: {
3320 switch (_V28
->tag__
) {
3321 case a_Ty::tag_TYCONty
: {
3323 if (boxed(((Ty_TYCONty
*)_V28
)->_1
)) {
3324 switch (((Ty_TYCONty
*)_V28
)->_1
->tag__
) {
3325 case a_TyCon::tag_NODEtycon
: { goto L66
; } break;
3326 default: { goto L62
; } break;
3328 } else { goto L62
; }
3330 default: { goto L62
; } break;
3332 } else { goto L62
; }
3334 case a_TyCon::tag_EDGEtycon
: {
3337 switch (_V28
->tag__
) {
3338 case a_Ty::tag_TYCONty
: {
3340 if (boxed(((Ty_TYCONty
*)_V28
)->_1
)) {
3341 switch (((Ty_TYCONty
*)_V28
)->_1
->tag__
) {
3342 case a_TyCon::tag_EDGEtycon
: { goto L67
; } break;
3343 default: { goto L62
; } break;
3345 } else { goto L62
; }
3347 default: { goto L62
; } break;
3349 } else { goto L62
; }
3351 default: { goto L62
; } break;
3353 } else { goto L62
; }
3356 } else { goto L68
; }
3358 case a_Ty::tag_NESTEDty
: {
3360 switch (_V28
->tag__
) {
3361 case a_Ty::tag_NESTEDty
: {
3362 #line 1193 "type.pcc"
3363 return ty_equal(((Ty_NESTEDty
*)_V27
)->_1
,((Ty_NESTEDty
*)_V28
)->_1
) && ty_equal(((Ty_NESTEDty
*)_V27
)->_2
,((Ty_NESTEDty
*)_V28
)->_2
);
3364 #line 1193 "type.pcc"
3366 default: { goto L62
; } break;
3368 } else { goto L62
; }
3370 default: { goto L62
; } break;
3372 } else { goto L62
; }
3375 #line 1195 "type.pcc"
3376 #line 1195 "type.pcc"
3380 /////////////////////////////////////////////////////////////////////////////
3382 // Equality function on type lists
3384 /////////////////////////////////////////////////////////////////////////////
3385 Bool
tys_equal(HashTable::Key a
, HashTable::Key b
)
3386 { Tys u
= (Tys
)a
, v
= (Tys
)b
;
3388 #line 1205 "type.pcc"
3389 #line 1207 "type.pcc"
3394 #line 1207 "type.pcc"
3395 if (!ty_equal(u
->_1
,v
->_1
)) return false; u
= u
->_2
; v
= v
->_2
;
3396 #line 1207 "type.pcc"
3397 } else { goto L77
; }
3398 } else { goto L77
; }
3402 #line 1208 "type.pcc"
3403 #line 1208 "type.pcc"
3406 #line 1209 "type.pcc"
3407 #line 1209 "type.pcc"
3409 #line 1209 "type.pcc"
3410 #line 1209 "type.pcc"
3412 #line 1209 "type.pcc"
3413 #line 1209 "type.pcc"
3415 #line 1209 "type.pcc"
3416 #line 1209 "type.pcc"
3420 /////////////////////////////////////////////////////////////////////////////
3422 // Equality on qualified identifiers.
3424 /////////////////////////////////////////////////////////////////////////////
3425 #line 1217 "type.pcc"
3426 #line 1221 "type.pcc"
3427 Bool
qualid_equal (QualId x_1
, QualId x_2
);
3428 Bool
qualid_equal (QualId x_1
, QualId x_2
)
3434 #line 1217 "type.pcc"
3435 return ((QualId_SIMPLEid
*)derefp(x_1
))->SIMPLEid
== ((QualId_SIMPLEid
*)derefp(x_2
))->SIMPLEid
;
3436 #line 1217 "type.pcc"
3440 #line 1220 "type.pcc"
3442 #line 1220 "type.pcc"
3449 #line 1219 "type.pcc"
3450 return ty_equal(((QualId_NESTEDid
*)x_1
)->_1
,((QualId_NESTEDid
*)x_2
)->_1
) && qualid_equal(((QualId_NESTEDid
*)x_1
)->_2
,((QualId_NESTEDid
*)x_2
)->_2
);
3451 #line 1219 "type.pcc"
3455 #line 1221 "type.pcc"
3456 #line 1221 "type.pcc"
3458 #line 1222 "type.pcc"
3460 ------------------------------- Statistics -------------------------------
3461 Merge matching rules = yes
3462 Number of DFA nodes merged = 2865
3463 Number of ifs generated = 162
3464 Number of switches generated = 116
3465 Number of labels = 71
3466 Number of gotos = 198
3467 Adaptive matching = enabled
3468 Fast string matching = disabled
3469 Inline downcasts = enabled
3470 --------------------------------------------------------------------------