2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 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_ANYTYPE || 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 ] */
159 return (cttable_addFullSafe (ctentry_makeNew (CTK_PLAIN, ctbase_createAbstract (u))));
169 ctype_realType (ctype c)
173 if (ctype_isElips (c) || ctype_isMissingParamsMarker (c))
180 r = uentry_getRealType (usymtab_getTypeEntry (ctype_typeId (c)));
183 if (ctype_isManifestBool (r))
185 if (context_canAccessBool ())
187 r = context_boolImplementationType ();
195 ctype_isSimple (ctype c)
197 return (! (ctype_isPointer (c)
199 || ctype_isFunction (c)));
203 ctype_forceRealType (ctype c)
209 r = uentry_getForceRealType (usymtab_getTypeEntry (ctype_typeId (c)));
216 ctype_realishType (ctype c)
220 if (ctype_isManifestBool (c))
226 ctype r = uentry_getRealType (usymtab_getTypeEntry
236 ctype_isSpecialType (ctype c)
238 return (ctype_isUnknown (c) || ctype_isAnytype (c));
244 return (!ctype_isSpecialType (c)
245 && ctbase_isUA (ctype_getCtbase (c)));
249 ctype_isUser (ctype c)
251 return (!ctype_isSpecialType (c)
252 && ctbase_isUser (ctype_getCtbase (c)));
256 ctype_isAbstract (ctype c)
258 return (!ctype_isSpecialType (c)
259 && ((ctype_isPlain (c) && ctbase_isAbstract (ctype_getCtbaseSafe (c))) ||
261 (ctype_isAbstract (ctype_getConjA (c))
262 || ctype_isAbstract (ctype_getConjB (c))))));
266 ctype_isImmutableAbstract (ctype t)
268 return (ctype_isAbstract (t) && !ctype_isMutable (t));
272 ctype_isRealAbstract (ctype c)
274 return (ctype_isAbstract (ctype_realType (c)) ||
276 (ctype_isRealAbstract (ctype_getConjA (c)) ||
277 ctype_isRealAbstract (ctype_getConjB (c)))));
281 ** primitive creators
285 ** createPrim not necessary --- subsumed by ctype_int, etc.
289 ** ctbase_unknown --- removed argument
294 ** requires: if DerivedType (T) exists in cttable, then T->derivedType is it.
298 ctype_makePointer (ctype c)
304 else if (c == ctype_void)
306 return ctype_voidPointer;
310 ctentry cte = ctype_getCtentry (c);
311 ctype clp = ctentry_getPtr (cte);
313 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
315 ctype cnew = cttable_addDerived (CTK_PTR, ctbase_makePointer (c), c);
316 ctentry_setPtr (cte, cnew);
326 ctype ctype_makeFixedArray (ctype c, size_t size)
329 res = cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c);
333 ctype ctype_makeInnerFixedArray (ctype c, size_t size)
337 if (ctype_isFixedArray (c))
339 ctype cb = ctype_baseArrayPtr (c);
340 size_t osize = ctype_getArraySize (c);
342 res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size), osize);
344 else if (ctype_isArray (c))
346 ctype cb = ctype_baseArrayPtr (c);
348 res = ctype_makeArray (ctype_makeInnerFixedArray (cb, size));
352 res = ctype_makeFixedArray (c, size);
355 DPRINTF (("Make inner fixed array: %s", ctype_unparse (res)));
359 ctype ctype_makeInnerArray (ctype c)
363 DPRINTF (("Make inner array: %s", ctype_unparse (c)));
365 if (ctype_isFixedArray (c))
367 ctype cb = ctype_baseArrayPtr (c);
368 size_t osize = ctype_getArraySize (c);
370 res = ctype_makeFixedArray (ctype_makeInnerArray (cb), osize);
374 res = ctype_makeArray (c);
377 DPRINTF (("Make inner array: %s", ctype_unparse (res)));
382 ctype_makeArray (ctype c)
384 ctentry cte = ctype_getCtentry (c);
385 ctype clp = ctentry_getArray (cte);
387 DPRINTF (("Make array: %s", ctype_unparse (c)));
389 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
391 ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
392 ctentry_setArray (cte, cnew);
402 ** requires c is a pointer of array
406 ctype_baseArrayPtr (ctype c)
408 ctentry cte = ctype_getCtentry (ctype_realType (c));
410 if (ctype_isConj (c))
412 if (ctype_isAP (ctype_getConjA (c)))
414 if (ctype_isAP (ctype_getConjB (c)))
416 return (ctype_makeConj (ctype_baseArrayPtr (ctype_getConjA (c)),
417 ctype_baseArrayPtr (ctype_getConjB (c))));
421 return (ctype_baseArrayPtr (ctype_getConjA (c)));
426 return (ctype_baseArrayPtr (ctype_getConjB (c)));
429 else if (ctype_isInt (c)) /* could be NULL */
431 return ctype_unknown;
435 ctype clp = ctentry_getBase (cte);
437 if (ctype_isBroken (clp))
439 llbuglit ("ctype_baseArrayPtr: bogus ctype");
451 ctype_makeWideString ()
453 static ctype res = ctype_unknown;
455 if (ctype_isUnknown (res))
459 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
461 wchart = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t")));
468 res = ctype_makePointer (wchart);
475 ctype_isWideString (ctype c)
477 if (ctype_isPointer (c))
479 ctype ct = ctype_baseArrayPtr (c);
481 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
483 return (ct == uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t"))));
497 ctype_getReturnType (ctype c)
499 if (ctype_isSpecialType (c))
504 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
508 ** must be a shared pointer
511 /*@observer@*/ uentryList
512 ctype_argsFunction (ctype c)
514 if (ctype_isSpecialType (c))
516 return uentryList_undefined;
519 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
523 ** Returns type with base type p and compound types from c.
525 ** i.e., c = char *[]; p = int
530 ctype_newBase (ctype c, ctype p)
532 return (ctbase_newBase (c, p));
536 ctype_sameAltTypes (ctype c1, ctype c2)
541 llassert (ctype_isConj (c1) && ctype_isConj (c2));
543 c1a = ctype_getConjA (c1);
544 c2a = ctype_getConjA (c2);
546 c1b = ctype_getConjB (c1);
547 c2b = ctype_getConjB (c2);
549 if (ctype_compare (c1a, c2a) == 0)
551 if (ctype_compare (c1b, c2b) == 0)
557 if (ctype_isConj (c1b) && ctype_isConj (c2b))
559 return ctype_sameAltTypes (c1b, c2b);
569 if (ctype_compare (c1a, c2b) == 0)
571 if (ctype_compare (c1b, c2a) == 0)
577 if (ctype_isConj (c1b) && ctype_isConj (c2a))
579 return ctype_sameAltTypes (c1b, c2a);
595 ctype_compare (ctype c1, ctype c2)
600 if (ctype_isSpecialType (c1))
602 if (ctype_isSpecialType (c2))
612 if (ctype_isSpecialType (c2))
617 /* Can't get entries for special ctypes (elips marker) */
619 if (ctype_isElips (c1) || ctype_isElips (c2)
620 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
621 return int_compare (c1, c2);
624 ce1 = ctype_getCtentry (c1);
625 ce2 = ctype_getCtentry (c2);
627 if (ctentry_isComplex (ce1))
629 if (ctentry_isComplex (ce2))
631 return (ctbase_compare (ctype_getCtbase (c1),
632 ctype_getCtbase (c2), FALSE));
639 else if (ctentry_isComplex (ce2))
645 return (int_compare (c1, c2));
654 ** makeFunction: pointer to function returning base
658 ctype_makeParamsFunction (ctype base, /*@only@*/ uentryList p)
660 uentryList_fixImpParams (p);
661 return (ctype_makeFunction (base, p));
665 ctype_makeNFParamsFunction (ctype base, /*@only@*/ uentryList p)
667 uentryList_fixImpParams (p);
668 return (ctbase_makeNFFunction (base, p));
672 ctype_makeFunction (ctype base, /*@only@*/ uentryList p)
675 ret = ctbase_makeFunction (base, p);
679 ctype ctype_expectFunction (ctype c)
681 /* handle parenthesized declarations */
685 c = ctype_makePointer (c);
688 return (cttable_addComplex (ctbase_expectFunction (c)));
691 ctype ctype_dontExpectFunction (ctype c)
693 ctbase ctb = ctype_getCtbase (c);
698 c = ctype_makePointer (c);
702 return (ctbase_getExpectFunction (ctb));
706 ** makeRealFunction: function returning base
709 ctype ctype_makeRawFunction (ctype base, uentryList p)
711 return (cttable_addComplex (ctbase_makeLiveFunction (base, p)));
719 **** this is very poorly defined
721 **** need to unify function/function pointer meaning
725 ctype_isFunction (ctype c)
727 if (ctype_isKnown (c) && ctype_isDefined (c))
729 return (ctbase_isFunction (ctype_getCtbase (c)));
738 ctype_isExpFcn (ctype c)
740 return (ctype_isKnown (c) && ctbase_isExpFcn (ctype_getCtbase (c)));
744 ctype_isVoid (ctype c)
746 return (c == CTX_VOID);
750 ctype_isArbitraryIntegral (ctype c)
752 ctype cr = ctype_realType (c);
754 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
755 || cr == ctype_signedintegral);
759 ctype_isUnsignedIntegral (ctype c)
761 ctype cr = ctype_realType (c);
763 return (cr == ctype_unsignedintegral);
767 ctype_isSignedIntegral (ctype c)
769 ctype cr = ctype_realType (c);
771 return (cr == ctype_signedintegral);
775 ctype_isInt (ctype c)
777 cprim cp = ctype_toCprim (c);
779 return (c == ctype_unknown || cprim_isAnyInt (cp)
780 || (cprim_isAnyChar (cp) && context_msgCharInt ())
781 || (c == ctype_bool && context_msgBoolInt ())
782 || (ctype_isEnum (c) && context_msgEnumInt ()));
786 ctype_isRegularInt (ctype c)
788 cprim cp = ctype_toCprim (c);
790 return (c == ctype_unknown
791 || cprim_closeEnough (cprim_int, cp)
792 || (cprim_isAnyChar (cp) && context_msgCharInt ())
793 || (c == ctype_bool && context_msgBoolInt ())
794 || (ctype_isEnum (c) && context_msgEnumInt ()));
798 ctype_isString (ctype c)
800 return (c == ctype_string
801 || (ctype_isPointer (c)
802 && ctype_isChar (ctype_baseArrayPtr (c))));
806 ctype_isChar (ctype c)
808 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
809 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
813 ctype_isUnsignedChar (ctype c)
815 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
819 ctype_isSignedChar (ctype c)
821 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
825 ** Returns true if c matches the name -booltype <bool>
829 ctype_isManifestBool (ctype c)
832 ** Changed the meaning of ctype_isBool - evs 2000-07-24
833 ** The old meaning was very convoluted!
836 ** c == CTX_BOOL - its a direct bool
837 ** c is a user/abstract type matching the bool name
838 ** (should never occur?)
841 if (ctype_isDirectBool (c)) {
843 } else if (ctype_isUA (c)) {
844 return ctype_isUserBool (c);
851 ctype_isBool (ctype c)
854 ** Changed the meaning of ctype_isBool - evs 2000-07-24
855 ** The old meaning was very convoluted!
858 ** its a manifest bool
859 ** +boolint and ctype_isInt (c)
862 if (ctype_isManifestBool (c)) {
864 } else if (context_msgBoolInt ()) {
865 return ctype_isInt (c);
871 if (context_getFlag (FLG_ABSTRACTBOOL))
873 if (typeId_isInvalid (boolType))
875 boolType = usymtab_getTypeId (context_getBoolName ());
878 if (context_hasAccess (boolType))
880 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
881 || (context_msgBoolInt ()
883 || (c == CTX_CHAR && context_msgCharInt ()))))
888 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
889 || (context_msgBoolInt ()
890 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
895 ctype_isDirectBool (ctype c)
897 return (c == CTX_BOOL);
901 ctype_isReal (ctype c)
903 return (cprim_isAnyReal (ctype_toCprim (c)));
907 ctype_isFloat (ctype c)
909 return (c == ctype_float);
913 ctype_isDouble (ctype c)
915 return (c == ctype_double || c == ctype_ldouble);
919 ctype_isSigned (ctype c)
921 return (!ctype_isUnsigned (c));
925 ctype_isNumeric (ctype c)
927 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c)
928 /* evans 2001-10-05: added this: */
929 || ctype_isArbitraryIntegral (c));
936 ** work on actual type in current context
940 ctype_isRealNumeric (ctype c)
942 if (ctype_isPlain (c))
943 return (ctype_isNumeric (ctype_realType (c)));
944 if (ctype_isConj (c))
945 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
946 ctype_isRealNumeric (ctype_getConjB (c)));
952 ctype_isRealInt (ctype c)
954 if (ctype_isPlain (c))
955 return (ctype_isInt (ctype_realType (c)));
956 else if (ctype_isConj (c))
957 return (ctype_isRealInt (ctype_getConjA (c)) ||
958 ctype_isRealInt (ctype_getConjB (c)));
961 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
967 ctype_isRealVoid (ctype c)
969 if (ctype_isPlain (c))
971 return (ctype_isVoid (ctype_realType (c)));
973 else if (ctype_isConj (c))
975 return (ctype_isRealVoid (ctype_getConjA (c)) ||
976 ctype_isRealVoid (ctype_getConjB (c)));
985 ctype_isRealBool (ctype c)
987 if (ctype_isPlain (c))
989 return (ctype_isBool (ctype_realishType (c)));
991 else if (ctype_isConj (c))
993 return (ctype_isRealBool (ctype_getConjA (c)) ||
994 ctype_isRealBool (ctype_getConjB (c)));
1003 ctype_isRealPointer (ctype c)
1005 if (ctype_isConj (c))
1006 return (ctype_isRealPointer (ctype_getConjA (c)) ||
1007 ctype_isRealPointer (ctype_getConjB (c)));
1008 return (ctype_isPointer (ctype_realType (c)));
1012 ctype_isRealSU (ctype c)
1014 if (ctype_isConj (c))
1016 return (ctype_isRealSU (ctype_getConjA (c)) ||
1017 ctype_isRealSU (ctype_getConjB (c)));
1020 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
1021 return (ctype_isStructorUnion (ctype_realType (c)));
1025 ctype_isRealArray (ctype c)
1027 if (ctype_isConj (c))
1028 return (ctype_isRealArray (ctype_getConjA (c)) ||
1029 ctype_isRealArray (ctype_getConjB (c)));
1030 return (ctype_isArray (ctype_realType (c)));
1034 ctype_isRealAP (ctype c)
1036 if (ctype_isConj (c))
1037 return (ctype_isRealAP (ctype_getConjA (c)) ||
1038 ctype_isRealAP (ctype_getConjB (c)));
1039 return (ctype_isAP (ctype_realType (c)));
1043 ctype_isRealFunction (ctype c)
1045 if (ctype_isConj (c))
1046 return (ctype_isRealFunction (ctype_getConjA (c)) ||
1047 ctype_isRealFunction (ctype_getConjB (c)));
1048 return (ctype_isFunction (ctype_realType (c)));
1052 ctype_isDirectInt (ctype c)
1054 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
1058 ** forceful predicates
1060 ** take *ctype; if its a conjunct, and there is a match replace with match only.
1061 ** if both match, still conjunct
1065 ctype_isForcePred (ctype * c, bool (pred) (ctype))
1067 /*drl bee: pbr */ if (ctype_isConj (*c))
1069 ctype cbr = ctype_getConjA (*c);
1071 /*drl bee: si*/ if ((*pred) (cbr))
1073 if ((*pred) (ctype_getConjB (*c)))
1086 if ((*pred) (cbr = ctype_getConjB (*c)))
1094 return ((*pred) (*c));
1098 ctype_isForceRealNumeric (ctype * c)
1100 return (ctype_isForcePred (c, ctype_isRealNumeric));
1104 ctype_isForceRealInt (ctype * c)
1106 return (ctype_isForcePred (c, ctype_isRealInt));
1110 ctype_isForceRealBool (ctype * c)
1112 return (ctype_isForcePred (c, ctype_isRealBool));
1118 ** save int/char, int/bool, other random conjuncts
1122 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
1124 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1126 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
1130 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1138 return (ctype_makeExplicitConj (c1, c2));
1142 return (ctype_makeConj (c1, c2));
1148 ctype_makeExplicitConj (ctype c1, ctype c2)
1150 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1152 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1154 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1156 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1158 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1160 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1162 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1166 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1170 static ctype ic = ctype_unknown; /* int | char */
1171 static ctype ib = ctype_unknown; /* int | bool */
1172 static ctype ifl = ctype_unknown; /* int | float */
1173 static ctype ibf = ctype_unknown; /* int | bool | float */
1174 static ctype ibc = ctype_unknown; /* int | bool | char */
1175 static ctype iv = ctype_unknown; /* int | void * */
1176 static ctype ivf = ctype_unknown; /* int | void * | float */
1177 static ctype ivb = ctype_unknown; /* int | void * | bool */
1178 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1179 static ctype cuc = ctype_unknown; /* char | unsigned char */
1182 ctype_recordConj (ctype c)
1186 llassert (ctype_isConj (c));
1188 c1 = ctype_getConjA (c);
1189 c2 = ctype_getConjB (c);
1192 if (c2 == ctype_int && c1 != ctype_int)
1202 if (c1 == ctype_int)
1204 if (c2 == ctype_char)
1206 llassert (ic == ctype_unknown);
1209 else if (c2 == ctype_bool)
1211 llassert (ib == ctype_unknown);
1214 else if (c2 == ctype_float)
1216 llassert (ifl == ctype_unknown);
1219 else if (c2 == CTP_VOID)
1221 llassert (iv == ctype_unknown);
1229 else if (c1 == ib && ib != ctype_unknown)
1231 if (c2 == ctype_float)
1233 llassert (ibf == ctype_unknown);
1236 else if (c2 == ctype_char)
1238 llassert (ibc == ctype_unknown);
1248 if (c2 == ctype_bool)
1250 llassert (ivb == ctype_unknown);
1253 else if (c2 == ctype_float)
1255 llassert (ivf == ctype_unknown);
1265 if (c2 == ctype_bool)
1267 llassert (ivbf == ctype_unknown);
1273 if (c2 == ctype_float)
1275 llassert (ivbf == ctype_unknown);
1279 else if (c1 == ctype_char)
1281 if (c2 == ctype_uchar)
1283 llassert (cuc == ctype_unknown);
1295 ctype_makeConj (ctype c1, ctype c2)
1297 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1299 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1301 if (ctype_isUnknown (c1))
1305 else if (ctype_isUnknown (c2))
1309 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1311 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1312 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1314 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1316 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1317 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1321 if (ctype_isManifestBool (c1))
1326 if (ctype_isManifestBool (c2))
1331 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1333 c1 = ctype_voidPointer;
1336 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1338 c2 = ctype_voidPointer;
1342 ** Ouch, can't do this. unsigned, etc. modifiers might
1343 ** apply to wrong type!
1345 ** if (c2 == ctype_int && c1 != ctype_int)
1356 if (c1 == ctype_int)
1358 if (c2 == ctype_char)
1360 if (ic == ctype_unknown)
1362 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1367 else if (c2 == ctype_bool)
1369 if (ib == ctype_unknown)
1371 ib = cttable_addComplex
1372 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1377 else if (c2 == ctype_float)
1379 if (ifl == ctype_unknown)
1381 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1388 if (c2 == ctype_voidPointer)
1390 if (iv == ctype_unknown)
1392 iv = cttable_addComplex
1393 (ctbase_makeConj (ctype_int,
1402 else if (c1 == ib && ib != ctype_unknown)
1404 if (c2 == ctype_float)
1406 if (ibf == ctype_unknown)
1408 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1413 else if (c2 == ctype_char)
1415 if (ibc == ctype_unknown)
1417 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1429 if (c2 == ctype_bool)
1431 if (ivb == ctype_unknown)
1433 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1438 else if (c2 == ctype_float)
1440 if (ivf == ctype_unknown)
1442 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1454 if (c2 == ctype_bool)
1456 if (ivbf == ctype_unknown)
1458 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1466 if (c2 == ctype_float)
1468 if (ivbf == ctype_unknown)
1470 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1476 else if (c1 == ctype_char)
1478 if (c2 == ctype_uchar)
1480 if (cuc == ctype_unknown)
1482 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1494 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1500 ctype_isConj (ctype c)
1502 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1506 ctype_getConjA (ctype c)
1508 if (!ctype_isConj (c))
1509 llbuglit ("ctype_getConjA: not a conj");
1510 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1514 ctype_getConjB (ctype c)
1516 if (!ctype_isConj (c))
1517 llbuglit ("ctype_getConjB: not a conj");
1518 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1522 ctype_isExplicitConj (ctype c)
1524 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1527 /** << need to fix resolveConj >> **/
1530 ** structs and unions
1534 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1538 DPRINTF (("Creating a struct: %s / %s",
1539 n, uentryList_unparse (f)));
1541 ct = cttable_addComplex (ctbase_createStruct (n, f));
1542 DPRINTF (("ct: %s", ctype_unparse (ct)));
1547 ctype_getFields (ctype c)
1549 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1553 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1557 ret = cttable_addComplex (ctbase_createUnion (n, f));
1564 ** if ctype's are same, definite match.
1565 ** else, need to call ctbase_match.
1567 ** if necessary context can memoize matches
1571 quickMatch (ctype c1, ctype c2)
1580 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1584 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1586 if (quickMatch (c1, c2))
1591 if (ctype_isElips (c1) || ctype_isElips (c2))
1597 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1603 ctype_sameName (ctype c1, ctype c2)
1605 if (quickMatch (c1, c2))
1608 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1612 ctype_almostEqual (ctype c1, ctype c2)
1614 if (ctype_equal (c1, c2))
1620 if (ctype_isUnknown (c1))
1622 return ctype_isUnknown (c2);
1624 else if (ctype_isUnknown (c2))
1630 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1636 ctype_matchDef (ctype c1, ctype c2)
1638 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1640 if (quickMatch (c1, c2))
1643 if (ctype_isElips (c1))
1644 return (ctype_isElips (c2) || ctype_isSpecialType (c2));
1646 if (ctype_isElips (c2))
1648 return (ctype_isSpecialType (c2));
1652 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1655 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1656 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1657 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1662 bool ctype_match (ctype c1, ctype c2)
1664 if (quickMatch (c1, c2))
1667 if (ctype_isElips (c1))
1669 return (ctype_isElips (c2) || ctype_isSpecialType (c2));
1672 if (ctype_isElips (c2))
1674 return (ctype_isSpecialType (c2));
1677 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1681 ctype_forceMatch (ctype c1, ctype c2)
1683 if (quickMatch (c1, c2))
1686 if (ctype_isElips (c1))
1687 return (ctype_isElips (c2));
1689 if (ctype_isElips (c2))
1693 /* The call forceMatch may modify the observer params, but, we don't care. */
1694 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1699 ctype_matchArg (ctype c1, ctype c2)
1701 if (quickMatch (c1, c2))
1707 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1712 ** simple ctype_is operations.
1713 ** DO NOT use real type of c, only direct type.
1717 ** ctype_isVoidPointer
1723 ctype_isVoidPointer (ctype c)
1725 if (ctype_isComplex (c))
1727 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1729 if (ctype_isConj (c))
1731 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1732 ctype_isVoidPointer (ctype_getConjB (c)));
1736 return (c == ctype_voidPointer
1737 || (ctype_isRealPointer (c)
1738 && ctype_isVoid (ctype_baseArrayPtr (c))));
1745 ** true for C and LCL pointers
1749 ctype_isPointer (ctype c)
1751 if (ctype_isElips (c)) return FALSE;
1753 if (ctype_isComplex (c))
1755 ctbase ctb = ctype_getCtbaseSafe (c);
1756 bool res = ctbase_isPointer (ctb);
1762 bool res = ctentry_isPointer (ctype_getCtentry (c));
1771 ** true for C and LCL array's
1775 ctype_isArray (ctype c)
1777 if (ctype_isElips (c)) return FALSE;
1779 if (ctype_isComplex (c))
1780 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1782 return (ctentry_isArray (ctype_getCtentry (c)));
1785 bool ctype_isIncompleteArray (ctype c)
1787 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1791 ctype_isArrayPtr (ctype c)
1793 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1797 ctype_typeId (ctype c)
1799 return (ctbase_typeId (ctype_getCtbase (c)));
1803 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1805 llassert (! (ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1807 if (ctype_isSpecialType (c))
1809 return message ("? %q", name);
1813 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1818 ctype_unparse (ctype c)
1820 if (ctype_isElips (c))
1822 return cstring_makeLiteralTemp ("...");
1824 else if (ctype_isMissingParamsMarker (c))
1826 return cstring_makeLiteralTemp ("-");
1828 else if (ctype_isUnknown (c))
1830 return cstring_makeLiteralTemp ("?");
1832 else if (ctype_isAnytype (c))
1834 return cstring_makeLiteralTemp ("<any>");
1839 return (ctentry_doUnparse (ctype_getCtentry (c)));
1845 ctype_unparseSafe (ctype c)
1847 if (ctype_isElips (c))
1849 return cstring_makeLiteralTemp ("...");
1851 else if (ctype_isMissingParamsMarker (c))
1853 return cstring_makeLiteralTemp ("-");
1859 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1861 ctentry cte = ctype_getCtentry (c);
1863 if (cstring_isDefined (cte->unparse))
1865 return (cte->unparse);
1869 ret = message ("[%d]", (int) c);
1870 cstring_markOwned (ret);
1876 ctype_unparseDeep (ctype c)
1878 if (ctype_isElips (c))
1880 return cstring_makeLiteralTemp ("...");
1882 if (ctype_isMissingParamsMarker (c))
1884 return cstring_makeLiteralTemp ("-");
1887 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1891 ctype_undump (char **c)
1893 return ((ctype) reader_getInt (c)); /* check its valid? */
1897 ctype_dump (ctype c)
1899 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1903 /* Handle invalid types in a kludgey way. */
1904 return (message ("0"));
1909 cstring tname = usymtab_getTypeEntryName
1910 (usymtab_convertId (ctype_typeId (c)));
1912 if (cstring_equal (tname, context_getBoolName ()))
1914 cstring_free (tname);
1915 return (message ("%d", ctype_bool));
1918 cstring_free (tname);
1921 DPRINTF (("Returning: %d", c));
1922 return (message ("%d", c));
1926 ctype_getBaseType (ctype c)
1928 ctentry cte = ctype_getCtentry (c);
1930 switch (ctentry_getKind (cte))
1939 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1942 ctbase ctb = cte->ctbase;
1944 if (ctbase_isDefined (ctb))
1963 return (ctype_getBaseType (ctb->contents.base));
1965 return (ctype_getBaseType (ctb->contents.farray->base));
1966 case CT_CONJ: /* base type of A conj branch? */
1967 return (ctype_getBaseType (ctb->contents.conj->a));
1969 /*@noaccess ctbase@*/
1977 llbuglit ("ctype_newBase: bad case");
1979 llcontbuglit ("ctype_getBaseType: unreachable code");
1980 return ((ctype)NULL);
1984 ctype_adjustPointers (int np, ctype c)
1987 if (ctype_isFunction (c))
1989 c = ctype_makeParamsFunction
1990 (ctype_adjustPointers (np, ctype_getReturnType (c)),
1991 uentryList_copy (ctype_argsFunction (c)));
1995 /* fix this should not use getBaseType ??? */
1996 ctype cb = ctype_getBaseType (c);
2000 cb = ctype_makePointer (cb);
2003 c = ctype_newBase (c, cb);
2011 ctype_elist (ctype c)
2013 return (ctbase_elist (ctype_getCtbase (c)));
2017 ctype_isFirstVoid (ctype c)
2019 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
2023 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
2025 return (cttable_addComplex (ctbase_createEnum (tag, el)));
2029 ctype_isEnum (ctype c)
2031 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
2035 ctype_enumTag (ctype c)
2037 llassert (ctype_isEnum (c));
2039 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
2043 ctype_isStruct (ctype c)
2045 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
2049 ctype_isUnion (ctype c)
2051 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
2055 ctype_resolveNumerics (ctype c1, ctype c2)
2058 ** returns longest type of c1 and c2
2061 if (c1 == c2) return c1;
2063 c1 = ctype_realType (c1);
2064 c2 = ctype_realType (c2);
2066 if (ctype_isEnum (c1)) c1 = ctype_unknown;
2067 if (ctype_isEnum (c2)) c2 = ctype_int;
2069 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
2071 /* 2001-06-08: This fix provided by Jim Zelenka. */
2072 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
2073 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
2075 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
2076 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
2077 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
2078 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
2080 /* 2001-06-08: This fix provided by Jim Zelenka. */
2081 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
2083 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
2085 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
2086 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
2088 if (ctype_isKnown (c1)) return c1;
2093 ctype_isStructorUnion (ctype c)
2095 return (ctype_isStruct (c) || ctype_isUnion (c));
2099 ctype_fixArrayPtr (ctype c)
2101 if (ctype_isArray (c))
2103 return (ctype_makePointer (ctype_baseArrayPtr (c)));
2110 ** createUnnamedStruct/Union
2112 ** check if it corresponds to an existing LCL-specified unnamed struct
2113 ** otherwise, give it a new tag
2117 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
2119 ctype ret = usymtab_structFieldsType (f);
2121 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
2123 if (ctype_isDefined (ret))
2125 uentryList_free (f);
2130 cstring ft = fakeTag ();
2131 ctype ct = ctype_createStruct (cstring_copy (ft), f);
2132 uentry ue = uentry_makeStructTagLoc (ft, ct);
2134 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2135 ue = usymtab_supGlobalEntryReturn (ue);
2136 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2144 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2146 ctype ret = usymtab_unionFieldsType (f);
2148 if (ctype_isDefined (ret))
2150 uentryList_free (f);
2155 cstring ft = fakeTag ();
2156 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2157 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2159 usymtab_supGlobalEntry (ue);
2166 ctype_isUnnamedSU (ctype c)
2170 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2179 ctype_createForwardStruct (cstring n)
2181 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2182 ctype ct = usymtab_supForwardTypeEntry (ue);
2189 ctype_createForwardUnion (cstring n)
2191 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2192 ctype ct = usymtab_supForwardTypeEntry (ue);
2199 ctype_removePointers (ctype c)
2203 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2206 c = ctype_baseArrayPtr (c);
2207 llassert (c != oldc);
2213 bool ctype_isMutable (ctype t)
2217 return (uentry_isMutableDatatype
2218 (usymtab_getTypeEntry (ctype_typeId (t))));
2222 return (ctype_isPointer (ctype_realType (t)));
2223 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2227 bool ctype_isRefCounted (ctype t)
2231 return (uentry_isRefCountedDatatype
2232 (usymtab_getTypeEntry (ctype_typeId (t))));
2238 bool ctype_isVisiblySharable (ctype t)
2240 if (ctype_isSpecialType (t)) return TRUE;
2242 if (ctype_isConj (t))
2244 return (ctype_isVisiblySharable (ctype_getConjA (t))
2245 || ctype_isVisiblySharable (ctype_getConjB (t)));
2248 if (ctype_isMutable (t))
2252 ctype rt = ctype_realType (t);
2260 return ctype_isVisiblySharable (rt);
2274 /* Replaced by ctype_isMutable (more sensible) */
2275 bool ctype_canAlias (ctype ct)
2277 /* can ct refer to memory locations?
2278 ** ==> a pointer or a mutable abstract type
2282 ctype tr = ctype_realType (ct);
2284 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2289 ** c1 is the dominant type; c2 is the modifier type
2291 ** eg. double + long int => long double
2294 ctype ctype_combine (ctype dominant, ctype modifier)
2296 DPRINTF (("Combine: %s + %s",
2297 ctype_unparse (dominant),
2298 ctype_unparse (modifier)));
2300 if (ctype_isConj (dominant))
2304 if (ctype_isExplicitConj (dominant))
2306 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2308 ctype_getConjB (dominant));
2312 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2314 ctype_getConjB (dominant));
2320 if (ctype_isUnknown (modifier))
2324 else if (ctype_isUnknown (dominant))
2330 if (ctype_isEnum (dominant)) dominant = ctype_int;
2331 if (ctype_isEnum (modifier)) modifier = ctype_int;
2333 if (modifier == ctype_uint)
2335 if (dominant == ctype_int) return ctype_uint;
2336 if (dominant == ctype_lint) return ctype_ulint;
2337 if (dominant == ctype_sint) return ctype_usint;
2338 if (dominant == ctype_char) return ctype_uchar;
2340 /* evs 2000-07-28: added this line */
2341 if (dominant == ctype_llint) return ctype_ullint;
2343 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2345 voptgenerror (FLG_DUPLICATEQUALS,
2346 message ("Duplicate unsigned qualifier"),
2353 voptgenerror (FLG_DUPLICATEQUALS,
2354 message ("Type qualifier unsigned used with %s",
2355 ctype_unparse (dominant)),
2361 else if (modifier == ctype_llint)
2363 if (dominant == ctype_int)
2368 voptgenerror (FLG_DUPLICATEQUALS,
2369 message ("Duplicate long qualifier on non-int"),
2372 else if (modifier == ctype_lint)
2374 if (dominant == ctype_int) return ctype_lint;
2375 if (dominant == ctype_uint) return ctype_ulint;
2376 if (dominant == ctype_double) return ctype_ldouble;
2378 if (dominant == ctype_lint || dominant == ctype_ulint
2379 || dominant == ctype_sint || dominant == ctype_usint
2380 || dominant == ctype_ldouble)
2382 if (dominant == ctype_lint)
2384 /* long long not supported by ANSI */
2389 if (dominant == ctype_ulint)
2391 /* unsigned long long not supported by ANSI */
2392 return ctype_ullint;
2396 if (dominant == ctype_sint || dominant == ctype_usint)
2398 if (!context_getFlag (FLG_IGNOREQUALS))
2400 llerrorlit (FLG_SYNTAX,
2401 "Contradictory long and short type qualifiers");
2406 voptgenerror (FLG_DUPLICATEQUALS,
2407 message ("Duplicate long qualifier"),
2414 else if (modifier == ctype_sint)
2416 if (dominant == ctype_int) return ctype_sint;
2417 if (dominant == ctype_uint) return ctype_usint;
2419 if (dominant == ctype_sint || dominant == ctype_usint)
2421 voptgenerror (FLG_DUPLICATEQUALS,
2422 message ("Duplicate short qualifier"),
2426 else if (dominant == ctype_lint)
2428 if (!context_getFlag (FLG_IGNOREQUALS))
2430 llerrorlit (FLG_SYNTAX,
2431 "Contradictory long and short type qualifiers");
2437 else if (dominant == ctype_llint)
2439 if (!context_getFlag (FLG_IGNOREQUALS))
2441 llerrorlit (FLG_SYNTAX,
2442 "Contradictory long long and short type qualifiers");
2450 if (!context_getFlag (FLG_IGNOREQUALS))
2452 llerror (FLG_SYNTAX,
2453 message ("Type qualifier short used with %s",
2454 ctype_unparse (dominant)));
2460 else if (modifier == ctype_ulint)
2462 if (dominant == ctype_int) return modifier;
2464 if (dominant == ctype_lint || dominant == ctype_ulint)
2466 voptgenerror (FLG_DUPLICATEQUALS,
2467 message ("Duplicate long qualifier"),
2473 if (dominant == ctype_uint || dominant == ctype_usint)
2475 voptgenerror (FLG_DUPLICATEQUALS,
2476 message ("Duplicate unsigned qualifier"),
2482 if (dominant == ctype_sint || dominant == ctype_usint)
2484 if (!context_getFlag (FLG_IGNOREQUALS))
2486 llerrorlit (FLG_SYNTAX,
2487 "Contradictory long and short type qualifiers");
2493 if (!context_getFlag (FLG_IGNOREQUALS))
2495 llerror (FLG_SYNTAX,
2496 message ("Type qualifiers unsigned long used with %s",
2497 ctype_unparse (dominant)));
2502 else if (modifier == ctype_usint)
2504 if (dominant == ctype_int) return modifier;
2506 if (dominant == ctype_sint || dominant == ctype_usint)
2508 voptgenerror (FLG_DUPLICATEQUALS,
2509 message ("Duplicate short qualifier"),
2514 if (dominant == ctype_uint)
2516 voptgenerror (FLG_DUPLICATEQUALS,
2517 message ("Duplicate unsigned qualifier"),
2523 if (dominant == ctype_lint || dominant == ctype_ulint
2524 || dominant == ctype_llint)
2526 if (!context_getFlag (FLG_IGNOREQUALS))
2528 llerrorlit (FLG_SYNTAX,
2529 "Contradictory long and short type qualifiers");
2535 if (!context_getFlag (FLG_IGNOREQUALS))
2537 llerror (FLG_SYNTAX,
2538 message ("Type qualifiers unsigned short used with %s",
2539 ctype_unparse (dominant)));
2553 ctype ctype_resolve (ctype c)
2555 if (ctype_isUnknown (c))
2557 DPRINTF (("Resolving! %s", ctype_unparse (c)));
2560 else if (c == ctype_anytype)
2562 return ctype_unknown;
2570 ctype ctype_fromQual (qual q)
2572 if (qual_isSigned (q)) return ctype_int;
2573 if (qual_isUnsigned (q)) return ctype_uint;
2574 if (qual_isLong (q)) return ctype_lint;
2575 if (qual_isShort (q)) return ctype_sint;
2577 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2578 return ctype_unknown;
2582 ctype_isAnyFloat (ctype c)
2584 return (cprim_isAnyReal (ctype_toCprim (c)));
2588 ctype_isUnsigned (ctype c)
2590 if (ctype_isConj (c))
2591 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2592 ctype_isUnsigned (ctype_getConjB (c)));
2594 return (c == ctype_uint || c == ctype_uchar
2595 || c == ctype_usint || c == ctype_ulint
2596 || c == ctype_ullint
2597 || c == ctype_unsignedintegral);
2602 ctype_isLongLong (ctype c)
2604 if (ctype_isConj (c))
2605 return (ctype_isLongLong (ctype_getConjA (c)) ||
2606 ctype_isLongLong (ctype_getConjB (c)));
2608 return (c == ctype_llint || c == ctype_ullint);
2613 ctype_isLong (ctype c)
2615 if (ctype_isConj (c))
2616 return (ctype_isLong (ctype_getConjA (c)) ||
2617 ctype_isLong (ctype_getConjB (c)));
2619 return (c == ctype_lint || c == ctype_ulint);
2623 ctype_isShort (ctype c)
2625 if (ctype_isConj (c))
2626 return (ctype_isShort (ctype_getConjA (c)) ||
2627 ctype_isShort (ctype_getConjB (c)));
2629 return (c == ctype_sint || c == ctype_usint);
2633 ctype_isStackAllocated (ctype c)
2635 ctype ct = ctype_realType (c);
2637 if (ctype_isConj (ct))
2638 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2639 ctype_isStackAllocated (ctype_getConjB (ct)));
2641 return (ctype_isArray (c) || ctype_isSU (c));
2644 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2646 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2649 static bool ctype_isLonger (ctype c1, ctype c2)
2651 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2652 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2653 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2654 || (ctype_isLong (c1)
2655 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2656 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2660 ctype_widest (ctype c1, ctype c2)
2662 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2672 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2675 if (c >= 0 && c < cttab.size)
2677 return (cttab.entries[c]->ctbase);
2681 if (c == ctype_unknown)
2682 llbuglit ("ctype_getCtbase: ctype unknown");
2683 if (c == ctype_undefined)
2684 llbuglit ("ctype_getCtbase: ctype undefined");
2686 llbuglit ("ctype_getCtbase: ctype dne");
2687 if (c == ctype_elipsMarker)
2688 llbuglit ("ctype_getCtbase: elips marker");
2689 if (c == ctype_anytype)
2690 llbuglit ("ctype_getCtbase: ctype anytype");
2692 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2699 static /*@notnull@*/ /*@observer@*/ ctbase
2700 ctype_getCtbaseSafe (ctype c)
2702 ctbase res = ctype_getCtbase (c);
2704 llassert (ctbase_isDefined (res));
2713 ctype_getCtentry (ctype c)
2715 static /*@only@*/ ctentry errorEntry = NULL;
2717 if (cttab.size == 0)
2719 if (errorEntry == NULL)
2721 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2728 if (c >= CTK_PLAIN && c < cttab.size)
2730 return (cttab.entries[c]);
2732 else if (c == CTK_UNKNOWN)
2733 llcontbuglit ("ctype_getCtentry: ctype unknown");
2734 else if (c == CTK_ANYTYPE)
2735 llcontbuglit ("ctype_getCtentry: ctype unknown");
2736 else if (c == CTK_INVALID)
2737 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2738 else if (c == CTK_DNE)
2739 llcontbuglit ("ctype_getCtentry: ctype dne");
2740 else if (c == CTK_ELIPS)
2741 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2742 else if (c == CTK_MISSINGPARAMS)
2743 llcontbuglit ("ctype_getCtentry: ctype missing params");
2745 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2747 return (cttab.entries[ctype_unknown]);
2752 bool ctype_isFixedArray (ctype c)
2754 if (ctype_isElips (c)) return FALSE;
2756 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
2761 /* requires that the type is an fixed array */
2762 /* return the size of the array */
2764 size_t ctype_getArraySize (ctype c)
2770 llassert (ctype_isFixedArray (c));
2772 ctb = ctype_getCtbaseSafe(c);
2773 size = ctbase_getArraySize (ctb);
2775 DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",