2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
27 ** This files implements three types: ctentry, cttable and ctype.
28 ** They should probably be separated soon.
31 # include "splintMacros.nf"
33 # include "structNames.h"
35 static void ctype_recordConj (ctype p_c);
50 static ctype ctype_getConjA (ctype p_c) /*@*/ ;
51 static ctype ctype_getConjB (ctype p_c) /*@*/ ;
53 static bool ctype_isComplex (ctype c)
55 return (ctentry_isComplex (ctype_getCtentry (c)));
58 static bool ctype_isPlain (ctype c)
60 return (ctentry_isPlain (ctype_getCtentry (c)));
63 static bool ctype_isBroken (ctype c)
66 if (c == CTK_DNE || c == CTK_INVALID || c == CTK_UNKNOWN)
73 ctentry cte = ctype_getCtentry (c);
75 return (ctentry_isBogus (cte));
80 ctkind_fromInt (int i)
83 if (i < CTK_UNKNOWN || i > CTK_COMPLEX)
85 llcontbug (message ("ctkind_fromInt: out of range: %d", i));
109 ctype_loadTable (FILE *f)
111 DPRINTF (("Loading cttable!"));
116 ctype_dumpTable (FILE *f)
118 DPRINTF (("Dumping cttable!"));
123 ctype_unparseTable ()
125 return (cttable_unparse ());
135 ctype_isUserBool (ctype ct)
139 return (usymtab_isBoolType (ctype_typeId (ct)));
146 ctype_createUser (typeId u)
148 /* requires: ctype_createUser (u) is never called more than once for any u. */
150 ctbase ct = ctbase_createUser (u);
151 return (cttable_addFullSafe (ctentry_makeNew (CTK_PLAIN, ct)));
155 ctype_createAbstract (typeId u)
157 /* requires: ctype_createAbstract (u) is never called more than once for any u. */
158 /* [ tested by cttable_addFullSafe, not really required ] */
160 return (cttable_addFullSafe
161 (ctentry_makeNew (CTK_PLAIN, ctbase_createAbstract (u))));
165 ctype_createNumAbstract (typeId u)
167 /* requires: ctype_createAbstract (u) is never called more than once for any u. */
168 /* [ tested by cttable_addFullSafe, not really required ] */
170 return (cttable_addFullSafe
171 (ctentry_makeNew (CTK_PLAIN, ctbase_createNumAbstract (u))));
181 ctype_realType (ctype c)
185 if (ctype_isElips (c) || ctype_isMissingParamsMarker (c))
192 r = uentry_getRealType (usymtab_getTypeEntry (ctype_typeId (c)));
195 if (ctype_isManifestBool (r))
197 if (context_canAccessBool ())
199 r = context_boolImplementationType ();
207 ctype_isSimple (ctype c)
209 return (! (ctype_isPointer (c)
211 || ctype_isFunction (c)));
215 ctype_forceRealType (ctype c)
221 r = uentry_getForceRealType (usymtab_getTypeEntry (ctype_typeId (c)));
228 ctype_realishType (ctype c)
232 if (ctype_isManifestBool (c))
238 ctype r = uentry_getRealType (usymtab_getTypeEntry
250 return (!ctype_isUnknown (c)
251 && ctbase_isUA (ctype_getCtbase (c)));
255 ctype_isUser (ctype c)
257 return (!ctype_isUnknown (c) && ctbase_isUser (ctype_getCtbase (c)));
261 ctype_isAbstract (ctype c)
263 return (!ctype_isUnknown (c)
264 && ((ctype_isPlain (c) && ctbase_isAbstract (ctype_getCtbaseSafe (c))) ||
266 (ctype_isAbstract (ctype_getConjA (c))
267 || ctype_isAbstract (ctype_getConjB (c))))));
271 ctype_isNumAbstract (ctype c)
273 return (!ctype_isUnknown (c)
274 && ((ctype_isPlain (c) && ctbase_isNumAbstract (ctype_getCtbaseSafe (c))) ||
276 (ctype_isNumAbstract (ctype_getConjA (c))
277 || ctype_isNumAbstract (ctype_getConjB (c))))));
281 ctype_isImmutableAbstract (ctype t)
283 return (ctype_isAbstract (t) && !ctype_isMutable (t));
287 ctype_isRealAbstract (ctype c)
289 return (ctype_isAbstract (ctype_realType (c)) ||
291 (ctype_isRealAbstract (ctype_getConjA (c)) ||
292 ctype_isRealAbstract (ctype_getConjB (c)))));
296 ctype_isRealNumAbstract (ctype c)
298 return (ctype_isNumAbstract (ctype_realType (c)) ||
300 (ctype_isRealNumAbstract (ctype_getConjA (c)) ||
301 ctype_isRealNumAbstract (ctype_getConjB (c)))));
305 ** primitive creators
309 ** createPrim not necessary --- subsumed by ctype_int, etc.
313 ** ctbase_unknown --- removed argument
318 ** requires: if DerivedType (T) exists in cttable, then T->derivedType is it.
322 ctype_makePointer (ctype c)
328 else if (c == ctype_void)
330 return ctype_voidPointer;
334 ctentry cte = ctype_getCtentry (c);
335 ctype clp = ctentry_getPtr (cte);
337 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
339 ctype cnew = cttable_addDerived (CTK_PTR, ctbase_makePointer (c), c);
340 ctentry_setPtr (cte, cnew);
350 ctype ctype_makeFixedArray (ctype c, size_t size)
353 res = cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c);
357 ctype ctype_makeInnerFixedArray (ctype c, size_t size)
361 if (ctype_isFixedArray (c))
363 ctype cb = ctype_baseArrayPtr (c);
364 size_t osize = ctype_getArraySize (c);
366 res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size), osize);
368 else if (ctype_isArray (c))
370 ctype cb = ctype_baseArrayPtr (c);
372 res = ctype_makeArray (ctype_makeInnerFixedArray (cb, size));
376 res = ctype_makeFixedArray (c, size);
379 DPRINTF (("Make inner fixed array: %s", ctype_unparse (res)));
383 ctype ctype_makeInnerArray (ctype c)
387 DPRINTF (("Make inner array: %s", ctype_unparse (c)));
389 if (ctype_isFixedArray (c))
391 ctype cb = ctype_baseArrayPtr (c);
392 size_t osize = ctype_getArraySize (c);
394 res = ctype_makeFixedArray (ctype_makeInnerArray (cb), osize);
398 res = ctype_makeArray (c);
401 DPRINTF (("Make inner array: %s", ctype_unparse (res)));
406 ctype_makeArray (ctype c)
408 ctentry cte = ctype_getCtentry (c);
409 ctype clp = ctentry_getArray (cte);
411 DPRINTF (("Make array: %s", ctype_unparse (c)));
413 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
415 ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
416 ctentry_setArray (cte, cnew);
426 ** requires c is a pointer of array
430 ctype_baseArrayPtr (ctype c)
432 ctentry cte = ctype_getCtentry (ctype_realType (c));
434 if (ctype_isConj (c))
436 if (ctype_isAP (ctype_getConjA (c)))
438 if (ctype_isAP (ctype_getConjB (c)))
440 return (ctype_makeConj (ctype_baseArrayPtr (ctype_getConjA (c)),
441 ctype_baseArrayPtr (ctype_getConjB (c))));
445 return (ctype_baseArrayPtr (ctype_getConjA (c)));
450 return (ctype_baseArrayPtr (ctype_getConjB (c)));
453 else if (ctype_isInt (c)) /* could be NULL */
455 return ctype_unknown;
459 ctype clp = ctentry_getBase (cte);
461 if (ctype_isBroken (clp))
463 llbuglit ("ctype_baseArrayPtr: bogus ctype");
475 ctype_makeWideString ()
477 static ctype res = ctype_unknown;
479 if (ctype_isUnknown (res))
483 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
485 wchart = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t")));
492 res = ctype_makePointer (wchart);
499 ctype_isWideString (ctype c)
501 if (ctype_isPointer (c))
503 ctype ct = ctype_baseArrayPtr (c);
505 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
507 return (ct == uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t"))));
521 ctype_getReturnType (ctype c)
523 if (ctype_isUnknown (c))
525 return ctype_unknown;
528 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
532 ** must be a shared pointer
535 /*@observer@*/ uentryList
536 ctype_argsFunction (ctype c)
538 if (ctype_isUnknown (c))
540 return uentryList_undefined;
543 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
547 ** Returns type with base type p and compound types from c.
549 ** i.e., c = char *[]; p = int
554 ctype_newBase (ctype c, ctype p)
556 return (ctbase_newBase (c, p));
560 ctype_sameAltTypes (ctype c1, ctype c2)
565 llassert (ctype_isConj (c1) && ctype_isConj (c2));
567 c1a = ctype_getConjA (c1);
568 c2a = ctype_getConjA (c2);
570 c1b = ctype_getConjB (c1);
571 c2b = ctype_getConjB (c2);
573 if (ctype_compare (c1a, c2a) == 0)
575 if (ctype_compare (c1b, c2b) == 0)
581 if (ctype_isConj (c1b) && ctype_isConj (c2b))
583 return ctype_sameAltTypes (c1b, c2b);
593 if (ctype_compare (c1a, c2b) == 0)
595 if (ctype_compare (c1b, c2a) == 0)
601 if (ctype_isConj (c1b) && ctype_isConj (c2a))
603 return ctype_sameAltTypes (c1b, c2a);
619 ctype_compare (ctype c1, ctype c2)
624 if (ctype_isUnknown (c1))
626 if (ctype_isUnknown (c2))
636 if (ctype_isUnknown (c2))
641 /* Can't get entries for special ctypes (elips marker) */
643 if (ctype_isElips (c1) || ctype_isElips (c2)
644 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
645 return int_compare (c1, c2);
648 ce1 = ctype_getCtentry (c1);
649 ce2 = ctype_getCtentry (c2);
651 if (ctentry_isComplex (ce1))
653 if (ctentry_isComplex (ce2))
655 return (ctbase_compare (ctype_getCtbase (c1),
656 ctype_getCtbase (c2), FALSE));
663 else if (ctentry_isComplex (ce2))
669 return (int_compare (c1, c2));
678 ** makeFunction: pointer to function returning base
682 ctype_makeParamsFunction (ctype base, /*@only@*/ uentryList p)
684 uentryList_fixImpParams (p);
685 return (ctype_makeFunction (base, p));
689 ctype_makeNFParamsFunction (ctype base, /*@only@*/ uentryList p)
691 uentryList_fixImpParams (p);
692 return (ctbase_makeNFFunction (base, p));
696 ctype_makeFunction (ctype base, /*@only@*/ uentryList p)
699 ret = ctbase_makeFunction (base, p);
703 ctype ctype_expectFunction (ctype c)
705 /* handle parenthesized declarations */
709 c = ctype_makePointer (c);
712 return (cttable_addComplex (ctbase_expectFunction (c)));
715 ctype ctype_dontExpectFunction (ctype c)
717 ctbase ctb = ctype_getCtbase (c);
722 c = ctype_makePointer (c);
726 return (ctbase_getExpectFunction (ctb));
730 ** makeRealFunction: function returning base
733 ctype ctype_makeRawFunction (ctype base, uentryList p)
735 return (cttable_addComplex (ctbase_makeLiveFunction (base, p)));
743 **** this is very poorly defined
745 **** need to unify function/function pointer meaning
749 ctype_isFunction (ctype c)
751 if (ctype_isKnown (c) && ctype_isDefined (c))
753 return (ctbase_isFunction (ctype_getCtbase (c)));
762 ctype_isExpFcn (ctype c)
764 return (ctype_isKnown (c) && ctbase_isExpFcn (ctype_getCtbase (c)));
768 ctype_isVoid (ctype c)
770 return (c == CTX_VOID);
774 ctype_isArbitraryIntegral (ctype c)
776 ctype cr = ctype_realType (c);
778 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
779 || cr == ctype_signedintegral);
783 ctype_isUnsignedIntegral (ctype c)
785 ctype cr = ctype_realType (c);
787 return (cr == ctype_unsignedintegral);
791 ctype_isSignedIntegral (ctype c)
793 ctype cr = ctype_realType (c);
795 return (cr == ctype_signedintegral);
799 ctype_isInt (ctype c)
801 cprim cp = ctype_toCprim (c);
803 return (c == ctype_unknown || cprim_isAnyInt (cp)
804 || (cprim_isAnyChar (cp) && context_msgCharInt ())
805 || (c == ctype_bool && context_msgBoolInt ())
806 || (ctype_isEnum (c) && context_msgEnumInt ()));
810 ctype_isRegularInt (ctype c)
812 cprim cp = ctype_toCprim (c);
814 return (c == ctype_unknown
815 || cprim_closeEnough (cprim_int, cp)
816 || (cprim_isAnyChar (cp) && context_msgCharInt ())
817 || (c == ctype_bool && context_msgBoolInt ())
818 || (ctype_isEnum (c) && context_msgEnumInt ()));
822 ctype_isString (ctype c)
824 return (c == ctype_string
825 || (ctype_isPointer (c)
826 && ctype_isChar (ctype_baseArrayPtr (c))));
830 ctype_isChar (ctype c)
832 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
833 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
837 ctype_isUnsignedChar (ctype c)
839 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
843 ctype_isSignedChar (ctype c)
845 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
849 ** Returns true if c matches the name -booltype <bool>
853 ctype_isManifestBool (ctype c)
856 ** Changed the meaning of ctype_isBool - evs 2000-07-24
857 ** The old meaning was very convoluted!
860 ** c == CTX_BOOL - its a direct bool
861 ** c is a user/abstract type matching the bool name
862 ** (should never occur?)
865 if (ctype_isDirectBool (c)) {
867 } else if (ctype_isUA (c)) {
868 return ctype_isUserBool (c);
875 ctype_isBool (ctype c)
878 ** Changed the meaning of ctype_isBool - evs 2000-07-24
879 ** The old meaning was very convoluted!
882 ** its a manifest bool
883 ** +boolint and ctype_isInt (c)
886 if (ctype_isManifestBool (c)) {
888 } else if (context_msgBoolInt ()) {
889 return ctype_isInt (c);
895 if (context_getFlag (FLG_ABSTRACTBOOL))
897 if (typeId_isInvalid (boolType))
899 boolType = usymtab_getTypeId (context_getBoolName ());
902 if (context_hasAccess (boolType))
904 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
905 || (context_msgBoolInt ()
907 || (c == CTX_CHAR && context_msgCharInt ()))))
912 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
913 || (context_msgBoolInt ()
914 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
919 ctype_isDirectBool (ctype c)
921 return (c == CTX_BOOL);
925 ctype_isReal (ctype c)
927 return (cprim_isAnyReal (ctype_toCprim (c)));
931 ctype_isFloat (ctype c)
933 return (c == ctype_float);
937 ctype_isDouble (ctype c)
939 return (c == ctype_double || c == ctype_ldouble);
943 ctype_isSigned (ctype c)
945 return (!ctype_isUnsigned (c));
949 ctype_isNumeric (ctype c)
951 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c)
952 /* evans 2001-10-05: added this: */
953 || ctype_isArbitraryIntegral (c));
960 ** work on actual type in current context
964 ctype_isRealNumeric (ctype c)
966 if (ctype_isPlain (c))
967 return (ctype_isNumeric (ctype_realType (c)));
968 if (ctype_isConj (c))
969 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
970 ctype_isRealNumeric (ctype_getConjB (c)));
976 ctype_isRealInt (ctype c)
978 if (ctype_isPlain (c))
979 return (ctype_isInt (ctype_realType (c)));
980 else if (ctype_isConj (c))
981 return (ctype_isRealInt (ctype_getConjA (c)) ||
982 ctype_isRealInt (ctype_getConjB (c)));
985 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
991 ctype_isRealVoid (ctype c)
993 if (ctype_isPlain (c))
995 return (ctype_isVoid (ctype_realType (c)));
997 else if (ctype_isConj (c))
999 return (ctype_isRealVoid (ctype_getConjA (c)) ||
1000 ctype_isRealVoid (ctype_getConjB (c)));
1009 ctype_isRealBool (ctype c)
1011 if (ctype_isPlain (c))
1013 return (ctype_isBool (ctype_realishType (c)));
1015 else if (ctype_isConj (c))
1017 return (ctype_isRealBool (ctype_getConjA (c)) ||
1018 ctype_isRealBool (ctype_getConjB (c)));
1027 ctype_isRealPointer (ctype c)
1029 if (ctype_isConj (c))
1030 return (ctype_isRealPointer (ctype_getConjA (c)) ||
1031 ctype_isRealPointer (ctype_getConjB (c)));
1032 return (ctype_isPointer (ctype_realType (c)));
1036 ctype_isRealSU (ctype c)
1038 if (ctype_isConj (c))
1040 return (ctype_isRealSU (ctype_getConjA (c)) ||
1041 ctype_isRealSU (ctype_getConjB (c)));
1044 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
1045 return (ctype_isStructorUnion (ctype_realType (c)));
1049 ctype_isRealArray (ctype c)
1051 if (ctype_isConj (c))
1052 return (ctype_isRealArray (ctype_getConjA (c)) ||
1053 ctype_isRealArray (ctype_getConjB (c)));
1054 return (ctype_isArray (ctype_realType (c)));
1058 ctype_isRealAP (ctype c)
1060 if (ctype_isConj (c))
1061 return (ctype_isRealAP (ctype_getConjA (c)) ||
1062 ctype_isRealAP (ctype_getConjB (c)));
1063 return (ctype_isAP (ctype_realType (c)));
1067 ctype_isRealFunction (ctype c)
1069 if (ctype_isConj (c))
1070 return (ctype_isRealFunction (ctype_getConjA (c)) ||
1071 ctype_isRealFunction (ctype_getConjB (c)));
1072 return (ctype_isFunction (ctype_realType (c)));
1076 ctype_isDirectInt (ctype c)
1078 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
1082 ** forceful predicates
1084 ** take *ctype; if its a conjunct, and there is a match replace with match only.
1085 ** if both match, still conjunct
1089 ctype_isForcePred (ctype * c, bool (pred) (ctype))
1091 /*drl bee: pbr */ if (ctype_isConj (*c))
1093 ctype cbr = ctype_getConjA (*c);
1097 if ((*pred) (ctype_getConjB (*c)))
1110 if ((*pred) (cbr = ctype_getConjB (*c)))
1118 return ((*pred) (*c));
1122 ctype_isForceRealNumeric (ctype * c)
1124 return (ctype_isForcePred (c, ctype_isRealNumeric));
1128 ctype_isForceRealInt (ctype * c)
1130 return (ctype_isForcePred (c, ctype_isRealInt));
1134 ctype_isForceRealBool (ctype * c)
1136 return (ctype_isForcePred (c, ctype_isRealBool));
1142 ** save int/char, int/bool, other random conjuncts
1146 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
1148 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
1152 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1160 return (ctype_makeExplicitConj (c1, c2));
1164 return (ctype_makeConj (c1, c2));
1170 ctype_makeExplicitConj (ctype c1, ctype c2)
1172 if (ctype_isAnytype (c1) || ctype_isAnytype (c2))
1174 return ctype_makeAnytype ();
1176 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1178 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1180 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1182 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1184 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1186 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1190 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1194 static ctype ic = ctype_unknown; /* int | char */
1195 static ctype ib = ctype_unknown; /* int | bool */
1196 static ctype ifl = ctype_unknown; /* int | float */
1197 static ctype ibf = ctype_unknown; /* int | bool | float */
1198 static ctype ibc = ctype_unknown; /* int | bool | char */
1199 static ctype iv = ctype_unknown; /* int | void * */
1200 static ctype ivf = ctype_unknown; /* int | void * | float */
1201 static ctype ivb = ctype_unknown; /* int | void * | bool */
1202 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1203 static ctype cuc = ctype_unknown; /* char | unsigned char */
1205 static ctype cany = ctype_unknown;
1208 ctype_makeAnytype ()
1210 if (cany == ctype_unknown)
1212 cany = ctype_makeConj (ctype_unknown, ctype_dne);
1213 llassert (ctype_isAnytype (cany));
1216 DPRINTF (("make anytype: %s", ctype_unparse (cany)));
1221 ctype_isAnytype (ctype c)
1227 ctype_recordConj (ctype c)
1231 llassert (ctype_isConj (c));
1233 c1 = ctype_getConjA (c);
1234 c2 = ctype_getConjB (c);
1237 if (c2 == ctype_int && c1 != ctype_int)
1247 if (c1 == ctype_int)
1249 if (c2 == ctype_char)
1251 llassert (ic == ctype_unknown);
1254 else if (c2 == ctype_bool)
1256 llassert (ib == ctype_unknown);
1259 else if (c2 == ctype_float)
1261 llassert (ifl == ctype_unknown);
1264 else if (c2 == CTP_VOID)
1266 llassert (iv == ctype_unknown);
1274 else if (c1 == ib && ib != ctype_unknown)
1276 if (c2 == ctype_float)
1278 llassert (ibf == ctype_unknown);
1281 else if (c2 == ctype_char)
1283 llassert (ibc == ctype_unknown);
1293 if (c2 == ctype_bool)
1295 llassert (ivb == ctype_unknown);
1298 else if (c2 == ctype_float)
1300 llassert (ivf == ctype_unknown);
1310 if (c2 == ctype_bool)
1312 llassert (ivbf == ctype_unknown);
1318 if (c2 == ctype_float)
1320 llassert (ivbf == ctype_unknown);
1324 else if (c1 == ctype_char)
1326 if (c2 == ctype_uchar)
1328 llassert (cuc == ctype_unknown);
1340 ctype_makeConj (ctype c1, ctype c2)
1342 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1344 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1346 if (ctype_isAnytype (c1))
1350 else if (ctype_isAnytype (c2))
1354 else if (ctype_isUnknown (c1))
1358 else if (ctype_isUnknown (c2))
1362 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1364 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1365 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1367 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1369 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1370 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1374 if (ctype_isManifestBool (c1))
1379 if (ctype_isManifestBool (c2))
1384 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1386 c1 = ctype_voidPointer;
1389 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1391 c2 = ctype_voidPointer;
1395 ** Ouch, can't do this. unsigned, etc. modifiers might
1396 ** apply to wrong type!
1398 ** if (c2 == ctype_int && c1 != ctype_int)
1409 if (c1 == ctype_int)
1411 if (c2 == ctype_char)
1413 if (ic == ctype_unknown)
1415 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1420 else if (c2 == ctype_bool)
1422 if (ib == ctype_unknown)
1424 ib = cttable_addComplex
1425 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1430 else if (c2 == ctype_float)
1432 if (ifl == ctype_unknown)
1434 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1441 if (c2 == ctype_voidPointer)
1443 if (iv == ctype_unknown)
1445 iv = cttable_addComplex
1446 (ctbase_makeConj (ctype_int,
1455 else if (c1 == ib && ib != ctype_unknown)
1457 if (c2 == ctype_float)
1459 if (ibf == ctype_unknown)
1461 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1466 else if (c2 == ctype_char)
1468 if (ibc == ctype_unknown)
1470 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1482 if (c2 == ctype_bool)
1484 if (ivb == ctype_unknown)
1486 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1491 else if (c2 == ctype_float)
1493 if (ivf == ctype_unknown)
1495 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1507 if (c2 == ctype_bool)
1509 if (ivbf == ctype_unknown)
1511 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1519 if (c2 == ctype_float)
1521 if (ivbf == ctype_unknown)
1523 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1529 else if (c1 == ctype_char)
1531 if (c2 == ctype_uchar)
1533 if (cuc == ctype_unknown)
1535 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1546 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1552 ctype_isConj (ctype c)
1554 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1558 ctype_getConjA (ctype c)
1560 if (!ctype_isConj (c))
1561 llbuglit ("ctype_getConjA: not a conj");
1562 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1566 ctype_getConjB (ctype c)
1568 if (!ctype_isConj (c))
1569 llbuglit ("ctype_getConjB: not a conj");
1570 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1574 ctype_isExplicitConj (ctype c)
1576 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1579 /** << need to fix resolveConj >> **/
1582 ** structs and unions
1586 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1590 DPRINTF (("Creating a struct: %s / %s",
1591 n, uentryList_unparse (f)));
1593 ct = cttable_addComplex (ctbase_createStruct (n, f));
1594 DPRINTF (("ct: %s", ctype_unparse (ct)));
1599 ctype_getFields (ctype c)
1601 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1605 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1609 ret = cttable_addComplex (ctbase_createUnion (n, f));
1616 ** if ctype's are same, definite match.
1617 ** else, need to call ctbase_match.
1619 ** if necessary context can memoize matches
1623 quickMatch (ctype c1, ctype c2)
1632 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1636 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1638 if (quickMatch (c1, c2))
1643 if (ctype_isElips (c1) || ctype_isElips (c2))
1649 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1655 ctype_sameName (ctype c1, ctype c2)
1657 if (quickMatch (c1, c2))
1660 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1664 ctype_almostEqual (ctype c1, ctype c2)
1666 if (ctype_equal (c1, c2))
1672 if (ctype_isUnknown (c1))
1674 return ctype_isUnknown (c2);
1676 else if (ctype_isUnknown (c2))
1682 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1688 ctype_matchDef (ctype c1, ctype c2)
1690 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1692 if (quickMatch (c1, c2))
1695 if (ctype_isElips (c1))
1696 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1698 if (ctype_isElips (c2))
1700 return (ctype_isUnknown (c2));
1704 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1707 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1708 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1709 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1714 bool ctype_match (ctype c1, ctype c2)
1716 if (quickMatch (c1, c2))
1719 if (ctype_isElips (c1))
1720 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1722 if (ctype_isElips (c2))
1723 return (ctype_isUnknown (c2));
1725 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1729 ctype_forceMatch (ctype c1, ctype c2)
1731 if (quickMatch (c1, c2))
1734 if (ctype_isElips (c1))
1735 return (ctype_isElips (c2));
1737 if (ctype_isElips (c2))
1741 /* The call forceMatch may modify the observer params, but, we don't care. */
1742 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1747 ctype_matchArg (ctype c1, ctype c2)
1749 if (quickMatch (c1, c2))
1755 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1760 ** simple ctype_is operations.
1761 ** DO NOT use real type of c, only direct type.
1765 ** ctype_isVoidPointer
1771 ctype_isVoidPointer (ctype c)
1773 if (ctype_isComplex (c))
1775 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1777 if (ctype_isConj (c))
1779 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1780 ctype_isVoidPointer (ctype_getConjB (c)));
1784 return (c == ctype_voidPointer
1785 || (ctype_isRealPointer (c)
1786 && ctype_isVoid (ctype_baseArrayPtr (c))));
1793 ** true for C and LCL pointers
1797 ctype_isPointer (ctype c)
1799 if (ctype_isElips (c)) return FALSE;
1801 if (ctype_isComplex (c))
1803 ctbase ctb = ctype_getCtbaseSafe (c);
1804 bool res = ctbase_isPointer (ctb);
1810 bool res = ctentry_isPointer (ctype_getCtentry (c));
1819 ** true for C and LCL array's
1823 ctype_isArray (ctype c)
1825 if (ctype_isElips (c)) return FALSE;
1827 if (ctype_isComplex (c))
1828 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1830 return (ctentry_isArray (ctype_getCtentry (c)));
1833 bool ctype_isIncompleteArray (ctype c)
1835 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1839 ctype_isArrayPtr (ctype c)
1841 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1845 ctype_typeId (ctype c)
1847 return (ctbase_typeId (ctype_getCtbase (c)));
1851 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1853 llassert (!(ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1855 if (ctype_isUnknown (c))
1857 return message ("? %q", name);
1861 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1866 ctype_unparse (ctype c)
1868 if (ctype_isElips (c))
1870 return cstring_makeLiteralTemp ("...");
1872 else if (ctype_isMissingParamsMarker (c))
1874 return cstring_makeLiteralTemp ("-");
1876 else if (ctype_isAnytype (c))
1878 return cstring_makeLiteralTemp ("<any>");
1880 else if (ctype_isUnknown (c))
1882 return cstring_makeLiteralTemp ("?");
1887 return (ctentry_doUnparse (ctype_getCtentry (c)));
1893 ctype_unparseSafe (ctype c)
1895 if (ctype_isElips (c))
1897 return cstring_makeLiteralTemp ("...");
1899 else if (ctype_isMissingParamsMarker (c))
1901 return cstring_makeLiteralTemp ("-");
1907 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1909 ctentry cte = ctype_getCtentry (c);
1911 if (cstring_isDefined (cte->unparse))
1913 return (cte->unparse);
1917 ret = message ("[%d]", (int) c);
1918 cstring_markOwned (ret);
1924 ctype_unparseDeep (ctype c)
1926 if (ctype_isElips (c))
1928 return cstring_makeLiteralTemp ("...");
1930 if (ctype_isMissingParamsMarker (c))
1932 return cstring_makeLiteralTemp ("-");
1935 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1939 ctype_undump (char **c)
1941 return ((ctype) reader_getInt (c)); /* check its valid? */
1945 ctype_dump (ctype c)
1947 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1951 /* Handle invalid types in a kludgey way. */
1952 return (message ("0"));
1957 cstring tname = usymtab_getTypeEntryName (usymtab_convertTypeId (ctype_typeId (c)));
1959 if (cstring_equal (tname, context_getBoolName ()))
1961 cstring_free (tname);
1962 return (message ("%d", ctype_bool));
1965 cstring_free (tname);
1968 DPRINTF (("Returning: %d", c));
1969 return (message ("%d", c));
1973 ctype_getBaseType (ctype c)
1975 ctentry cte = ctype_getCtentry (c);
1977 switch (ctentry_getKind (cte))
1985 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1988 ctbase ctb = cte->ctbase;
1990 if (ctbase_isDefined (ctb))
2010 return (ctype_getBaseType (ctb->contents.base));
2012 return (ctype_getBaseType (ctb->contents.farray->base));
2013 case CT_CONJ: /* base type of A conj branch? */
2014 return (ctype_getBaseType (ctb->contents.conj->a));
2016 /*@noaccess ctbase@*/
2024 llbuglit ("ctype_newBase: bad case");
2026 llcontbuglit ("ctype_getBaseType: unreachable code");
2027 return ((ctype)NULL);
2031 ctype_adjustPointers (pointers p, ctype c)
2033 int np = pointers_depth (p);
2035 if (ctype_isFunction (c))
2037 c = ctype_makeParamsFunction
2038 (ctype_adjustPointers (p, ctype_getReturnType (c)),
2039 uentryList_copy (ctype_argsFunction (c)));
2043 /* fix this should not use getBaseType ??? */
2044 ctype cb = ctype_getBaseType (c);
2048 cb = ctype_makePointer (cb);
2051 c = ctype_newBase (c, cb);
2059 ctype_elist (ctype c)
2061 return (ctbase_elist (ctype_getCtbase (c)));
2065 ctype_isFirstVoid (ctype c)
2067 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
2071 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
2073 return (cttable_addComplex (ctbase_createEnum (tag, el)));
2077 ctype_isEnum (ctype c)
2079 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
2083 ctype_enumTag (ctype c)
2085 llassert (ctype_isEnum (c));
2087 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
2091 ctype_isStruct (ctype c)
2093 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
2097 ctype_isUnion (ctype c)
2099 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
2103 ctype_resolveNumerics (ctype c1, ctype c2)
2106 ** returns longest type of c1 and c2
2109 if (c1 == c2) return c1;
2111 c1 = ctype_realType (c1);
2112 c2 = ctype_realType (c2);
2114 if (ctype_isEnum (c1)) c1 = ctype_unknown;
2115 if (ctype_isEnum (c2)) c2 = ctype_int;
2117 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
2119 /* 2001-06-08: This fix provided by Jim Zelenka. */
2120 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
2121 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
2123 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
2124 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
2125 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
2126 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
2128 /* 2001-06-08: This fix provided by Jim Zelenka. */
2129 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
2131 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
2133 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
2134 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
2136 if (ctype_isKnown (c1)) return c1;
2141 ctype_isStructorUnion (ctype c)
2143 return (ctype_isStruct (c) || ctype_isUnion (c));
2147 ctype_fixArrayPtr (ctype c)
2149 if (ctype_isArray (c))
2151 return (ctype_makePointer (ctype_baseArrayPtr (c)));
2158 ** createUnnamedStruct/Union
2160 ** check if it corresponds to an existing LCL-specified unnamed struct
2161 ** otherwise, give it a new tag
2165 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
2167 ctype ret = usymtab_structFieldsType (f);
2169 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
2171 if (ctype_isDefined (ret))
2173 uentryList_free (f);
2178 cstring ft = fakeTag ();
2179 ctype ct = ctype_createStruct (cstring_copy (ft), f);
2180 uentry ue = uentry_makeStructTagLoc (ft, ct);
2182 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2183 ue = usymtab_supGlobalEntryReturn (ue);
2184 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2192 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2194 ctype ret = usymtab_unionFieldsType (f);
2196 if (ctype_isDefined (ret))
2198 uentryList_free (f);
2203 cstring ft = fakeTag ();
2204 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2205 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2207 usymtab_supGlobalEntry (ue);
2214 ctype_isUnnamedSU (ctype c)
2218 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2227 ctype_createForwardStruct (cstring n)
2229 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2230 ctype ct = usymtab_supForwardTypeEntry (ue);
2237 ctype_createForwardUnion (cstring n)
2239 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2240 ctype ct = usymtab_supForwardTypeEntry (ue);
2247 ctype_createForwardEnum (cstring n)
2249 uentry ue = uentry_makeEnumTag (n, ctype_unknown, fileloc_undefined);
2250 ctype ct = usymtab_supForwardTypeEntry (ue);
2257 ctype_removePointers (ctype c)
2261 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2264 c = ctype_baseArrayPtr (c);
2265 llassert (c != oldc);
2271 bool ctype_isMutable (ctype t)
2275 return (uentry_isMutableDatatype
2276 (usymtab_getTypeEntry (ctype_typeId (t))));
2280 return (ctype_isPointer (ctype_realType (t)));
2281 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2285 bool ctype_isRefCounted (ctype t)
2289 return (uentry_isRefCountedDatatype
2290 (usymtab_getTypeEntry (ctype_typeId (t))));
2296 bool ctype_isVisiblySharable (ctype t)
2298 if (ctype_isUnknown (t))
2303 if (ctype_isConj (t))
2305 return (ctype_isVisiblySharable (ctype_getConjA (t))
2306 || ctype_isVisiblySharable (ctype_getConjB (t)));
2309 if (ctype_isMutable (t))
2313 ctype rt = ctype_realType (t);
2317 if (ctype_isNumAbstract (t))
2328 return ctype_isVisiblySharable (rt);
2342 /* Replaced by ctype_isMutable (more sensible) */
2343 bool ctype_canAlias (ctype ct)
2345 /* can ct refer to memory locations?
2346 ** ==> a pointer or a mutable abstract type
2350 ctype tr = ctype_realType (ct);
2352 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2357 ** c1 is the dominant type; c2 is the modifier type
2359 ** eg. double + long int => long double
2362 ctype ctype_combine (ctype dominant, ctype modifier)
2364 DPRINTF (("Combine: %s + %s",
2365 ctype_unparse (dominant),
2366 ctype_unparse (modifier)));
2368 if (ctype_isConj (dominant))
2372 if (ctype_isExplicitConj (dominant))
2374 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2376 ctype_getConjB (dominant));
2380 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2382 ctype_getConjB (dominant));
2388 if (ctype_isUnknown (modifier))
2392 else if (ctype_isUnknown (dominant))
2398 if (ctype_isEnum (dominant)) dominant = ctype_int;
2399 if (ctype_isEnum (modifier)) modifier = ctype_int;
2401 if (modifier == ctype_uint)
2403 if (dominant == ctype_int) return ctype_uint;
2404 if (dominant == ctype_lint) return ctype_ulint;
2405 if (dominant == ctype_sint) return ctype_usint;
2406 if (dominant == ctype_char) return ctype_uchar;
2408 /* evs 2000-07-28: added this line */
2409 if (dominant == ctype_llint) return ctype_ullint;
2411 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2413 voptgenerror (FLG_DUPLICATEQUALS,
2414 message ("Duplicate unsigned qualifier"),
2421 voptgenerror (FLG_DUPLICATEQUALS,
2422 message ("Type qualifier unsigned used with %s",
2423 ctype_unparse (dominant)),
2429 else if (modifier == ctype_llint)
2431 if (dominant == ctype_int)
2436 voptgenerror (FLG_DUPLICATEQUALS,
2437 message ("Duplicate long qualifier on non-int"),
2440 else if (modifier == ctype_lint)
2442 if (dominant == ctype_int) return ctype_lint;
2443 if (dominant == ctype_uint) return ctype_ulint;
2444 if (dominant == ctype_double) return ctype_ldouble;
2446 if (dominant == ctype_lint || dominant == ctype_ulint
2447 || dominant == ctype_sint || dominant == ctype_usint
2448 || dominant == ctype_ldouble)
2450 if (dominant == ctype_lint)
2452 /* long long not supported by ANSI */
2457 if (dominant == ctype_ulint)
2459 /* unsigned long long not supported by ANSI */
2460 return ctype_ullint;
2464 if (dominant == ctype_sint || dominant == ctype_usint)
2466 if (!context_getFlag (FLG_IGNOREQUALS))
2468 llerrorlit (FLG_SYNTAX,
2469 "Contradictory long and short type qualifiers");
2474 voptgenerror (FLG_DUPLICATEQUALS,
2475 message ("Duplicate long qualifier"),
2482 else if (modifier == ctype_sint)
2484 if (dominant == ctype_int) return ctype_sint;
2485 if (dominant == ctype_uint) return ctype_usint;
2487 if (dominant == ctype_sint || dominant == ctype_usint)
2489 voptgenerror (FLG_DUPLICATEQUALS,
2490 message ("Duplicate short qualifier"),
2494 else if (dominant == ctype_lint)
2496 if (!context_getFlag (FLG_IGNOREQUALS))
2498 llerrorlit (FLG_SYNTAX,
2499 "Contradictory long and short type qualifiers");
2505 else if (dominant == ctype_llint)
2507 if (!context_getFlag (FLG_IGNOREQUALS))
2509 llerrorlit (FLG_SYNTAX,
2510 "Contradictory long long and short type qualifiers");
2518 if (!context_getFlag (FLG_IGNOREQUALS))
2520 llerror (FLG_SYNTAX,
2521 message ("Type qualifier short used with %s",
2522 ctype_unparse (dominant)));
2528 else if (modifier == ctype_ulint)
2530 if (dominant == ctype_int) return modifier;
2532 if (dominant == ctype_lint || dominant == ctype_ulint)
2534 voptgenerror (FLG_DUPLICATEQUALS,
2535 message ("Duplicate long qualifier"),
2541 if (dominant == ctype_uint || dominant == ctype_usint)
2543 voptgenerror (FLG_DUPLICATEQUALS,
2544 message ("Duplicate unsigned qualifier"),
2550 if (dominant == ctype_sint || dominant == ctype_usint)
2552 if (!context_getFlag (FLG_IGNOREQUALS))
2554 llerrorlit (FLG_SYNTAX,
2555 "Contradictory long and short type qualifiers");
2561 if (!context_getFlag (FLG_IGNOREQUALS))
2563 llerror (FLG_SYNTAX,
2564 message ("Type qualifiers unsigned long used with %s",
2565 ctype_unparse (dominant)));
2570 else if (modifier == ctype_usint)
2572 if (dominant == ctype_int) return modifier;
2574 if (dominant == ctype_sint || dominant == ctype_usint)
2576 voptgenerror (FLG_DUPLICATEQUALS,
2577 message ("Duplicate short qualifier"),
2582 if (dominant == ctype_uint)
2584 voptgenerror (FLG_DUPLICATEQUALS,
2585 message ("Duplicate unsigned qualifier"),
2591 if (dominant == ctype_lint || dominant == ctype_ulint
2592 || dominant == ctype_llint)
2594 if (!context_getFlag (FLG_IGNOREQUALS))
2596 llerrorlit (FLG_SYNTAX,
2597 "Contradictory long and short type qualifiers");
2603 if (!context_getFlag (FLG_IGNOREQUALS))
2605 llerror (FLG_SYNTAX,
2606 message ("Type qualifiers unsigned short used with %s",
2607 ctype_unparse (dominant)));
2621 ctype ctype_resolve (ctype c)
2623 if (ctype_isUnknown (c) && !ctype_isAnytype (c))
2625 DPRINTF (("Resolving to int: %s", ctype_unparse (c)));
2632 ctype ctype_fromQual (qual q)
2634 if (qual_isSigned (q)) return ctype_int;
2635 if (qual_isUnsigned (q)) return ctype_uint;
2636 if (qual_isLong (q)) return ctype_lint;
2637 if (qual_isShort (q)) return ctype_sint;
2639 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2640 return ctype_unknown;
2644 ctype_isAnyFloat (ctype c)
2646 return (cprim_isAnyReal (ctype_toCprim (c)));
2650 ctype_isUnsigned (ctype c)
2652 if (ctype_isConj (c))
2653 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2654 ctype_isUnsigned (ctype_getConjB (c)));
2656 return (c == ctype_uint || c == ctype_uchar
2657 || c == ctype_usint || c == ctype_ulint
2658 || c == ctype_ullint
2659 || c == ctype_unsignedintegral);
2664 ctype_isLongLong (ctype c)
2666 if (ctype_isConj (c))
2667 return (ctype_isLongLong (ctype_getConjA (c)) ||
2668 ctype_isLongLong (ctype_getConjB (c)));
2670 return (c == ctype_llint || c == ctype_ullint);
2675 ctype_isLong (ctype c)
2677 if (ctype_isConj (c))
2678 return (ctype_isLong (ctype_getConjA (c)) ||
2679 ctype_isLong (ctype_getConjB (c)));
2681 return (c == ctype_lint || c == ctype_ulint);
2685 ctype_isShort (ctype c)
2687 if (ctype_isConj (c))
2688 return (ctype_isShort (ctype_getConjA (c)) ||
2689 ctype_isShort (ctype_getConjB (c)));
2691 return (c == ctype_sint || c == ctype_usint);
2695 ctype_isStackAllocated (ctype c)
2697 ctype ct = ctype_realType (c);
2699 if (ctype_isConj (ct))
2700 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2701 ctype_isStackAllocated (ctype_getConjB (ct)));
2703 return (ctype_isArray (c) || ctype_isSU (c));
2706 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2708 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2711 static bool ctype_isLonger (ctype c1, ctype c2)
2713 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2714 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2715 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2716 || (ctype_isLong (c1)
2717 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2718 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2722 ctype_widest (ctype c1, ctype c2)
2724 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2734 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2737 if (c >= 0 && c < cttab.size)
2739 return (cttab.entries[c]->ctbase);
2743 if (c == ctype_unknown)
2744 llbuglit ("ctype_getCtbase: ctype unknown");
2745 if (c == ctype_undefined)
2746 llbuglit ("ctype_getCtbase: ctype undefined");
2748 llbuglit ("ctype_getCtbase: ctype dne");
2749 if (c == ctype_elipsMarker)
2750 llbuglit ("ctype_getCtbase: elips marker");
2752 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2759 static /*@notnull@*/ /*@observer@*/ ctbase
2760 ctype_getCtbaseSafe (ctype c)
2762 ctbase res = ctype_getCtbase (c);
2764 llassert (ctbase_isDefined (res));
2773 ctype_getCtentry (ctype c)
2775 static /*@only@*/ ctentry errorEntry = NULL;
2777 if (cttab.size == 0)
2779 if (errorEntry == NULL)
2781 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2788 if (c >= CTK_PLAIN && c < cttab.size)
2790 return (cttab.entries[c]);
2792 else if (c == CTK_UNKNOWN)
2793 llcontbuglit ("ctype_getCtentry: ctype unknown");
2794 else if (c == CTK_INVALID)
2795 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2796 else if (c == CTK_DNE)
2797 llcontbuglit ("ctype_getCtentry: ctype dne");
2798 else if (c == CTK_ELIPS)
2799 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2800 else if (c == CTK_MISSINGPARAMS)
2801 llcontbuglit ("ctype_getCtentry: ctype missing params");
2803 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2805 return (cttab.entries[ctype_unknown]);
2810 bool ctype_isFixedArray (ctype c)
2812 if (ctype_isElips (c)) return FALSE;
2814 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
2819 /* requires that the type is an fixed array */
2820 /* return the size of the array */
2822 size_t ctype_getArraySize (ctype c)
2828 llassert (ctype_isFixedArray (c));
2830 ctb = ctype_getCtbaseSafe(c);
2831 size = ctbase_getArraySize (ctb);
2833 DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",
2839 ctype ctype_biggerType (ctype c1, ctype c2)
2841 if (ctbase_isBigger (ctype_getCtbaseSafe (c2), ctype_getCtbaseSafe (c1)) )