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
238 return (!ctype_isUnknown (c) && ctbase_isUA (ctype_getCtbase (c)));
242 ctype_isUser (ctype c)
244 return (!ctype_isUnknown (c) && ctbase_isUser (ctype_getCtbase (c)));
248 ctype_isAbstract (ctype c)
250 return (!ctype_isUnknown (c)
251 && ((ctype_isPlain (c) && ctbase_isAbstract (ctype_getCtbaseSafe (c))) ||
253 (ctype_isAbstract (ctype_getConjA (c))
254 || ctype_isAbstract (ctype_getConjB (c))))));
258 ctype_isImmutableAbstract (ctype t)
260 return (ctype_isAbstract (t) && !ctype_isMutable (t));
264 ctype_isRealAbstract (ctype c)
266 return (ctype_isAbstract (ctype_realType (c)) ||
268 (ctype_isRealAbstract (ctype_getConjA (c)) ||
269 ctype_isRealAbstract (ctype_getConjB (c)))));
273 ** primitive creators
277 ** createPrim not necessary --- subsumed by ctype_int, etc.
281 ** ctbase_unknown --- removed argument
286 ** requires: if DerivedType (T) exists in cttable, then T->derivedType is it.
290 ctype_makePointer (ctype c)
296 else if (c == ctype_void)
298 return ctype_voidPointer;
302 ctentry cte = ctype_getCtentry (c);
303 ctype clp = ctentry_getPtr (cte);
305 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
307 ctype cnew = cttable_addDerived (CTK_PTR, ctbase_makePointer (c), c);
308 ctentry_setPtr (cte, cnew);
318 ctype ctype_makeFixedArray (ctype c, size_t size)
321 res = cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c);
325 ctype ctype_makeInnerFixedArray (ctype c, size_t size)
329 if (ctype_isFixedArray (c))
331 ctype cb = ctype_baseArrayPtr (c);
332 size_t osize = ctype_getArraySize (c);
334 res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size), osize);
336 else if (ctype_isArray (c))
338 ctype cb = ctype_baseArrayPtr (c);
340 res = ctype_makeArray (ctype_makeInnerFixedArray (cb, size));
344 res = ctype_makeFixedArray (c, size);
347 DPRINTF (("Make inner fixed array: %s", ctype_unparse (res)));
351 ctype ctype_makeInnerArray (ctype c)
355 DPRINTF (("Make inner array: %s", ctype_unparse (c)));
357 if (ctype_isFixedArray (c))
359 ctype cb = ctype_baseArrayPtr (c);
360 size_t osize = ctype_getArraySize (c);
362 res = ctype_makeFixedArray (ctype_makeInnerArray (cb), osize);
366 res = ctype_makeArray (c);
369 DPRINTF (("Make inner array: %s", ctype_unparse (res)));
374 ctype_makeArray (ctype c)
376 ctentry cte = ctype_getCtentry (c);
377 ctype clp = ctentry_getArray (cte);
379 DPRINTF (("Make array: %s", ctype_unparse (c)));
381 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
383 ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
384 ctentry_setArray (cte, cnew);
394 ** requires c is a pointer of array
398 ctype_baseArrayPtr (ctype c)
400 ctentry cte = ctype_getCtentry (ctype_realType (c));
402 if (ctype_isConj (c))
404 if (ctype_isAP (ctype_getConjA (c)))
406 if (ctype_isAP (ctype_getConjB (c)))
408 return (ctype_makeConj (ctype_baseArrayPtr (ctype_getConjA (c)),
409 ctype_baseArrayPtr (ctype_getConjB (c))));
413 return (ctype_baseArrayPtr (ctype_getConjA (c)));
418 return (ctype_baseArrayPtr (ctype_getConjB (c)));
421 else if (ctype_isInt (c)) /* could be NULL */
423 return ctype_unknown;
427 ctype clp = ctentry_getBase (cte);
429 if (ctype_isBroken (clp))
431 llbuglit ("ctype_baseArrayPtr: bogus ctype");
443 ctype_makeWideString ()
445 static ctype res = ctype_unknown;
447 if (ctype_isUnknown (res))
451 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
453 wchart = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t")));
460 res = ctype_makePointer (wchart);
467 ctype_isWideString (ctype c)
469 if (ctype_isPointer (c))
471 ctype ct = ctype_baseArrayPtr (c);
473 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
475 return (ct == uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t"))));
489 ctype_getReturnType (ctype c)
491 if (ctype_isUnknown (c))
493 return ctype_unknown;
496 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
500 ** must be a shared pointer
503 /*@observer@*/ uentryList
504 ctype_argsFunction (ctype c)
506 if (ctype_isUnknown (c))
508 return uentryList_undefined;
511 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
515 ** Returns type with base type p and compound types from c.
517 ** i.e., c = char *[]; p = int
522 ctype_newBase (ctype c, ctype p)
524 return (ctbase_newBase (c, p));
528 ctype_sameAltTypes (ctype c1, ctype c2)
533 llassert (ctype_isConj (c1) && ctype_isConj (c2));
535 c1a = ctype_getConjA (c1);
536 c2a = ctype_getConjA (c2);
538 c1b = ctype_getConjB (c1);
539 c2b = ctype_getConjB (c2);
541 if (ctype_compare (c1a, c2a) == 0)
543 if (ctype_compare (c1b, c2b) == 0)
549 if (ctype_isConj (c1b) && ctype_isConj (c2b))
551 return ctype_sameAltTypes (c1b, c2b);
561 if (ctype_compare (c1a, c2b) == 0)
563 if (ctype_compare (c1b, c2a) == 0)
569 if (ctype_isConj (c1b) && ctype_isConj (c2a))
571 return ctype_sameAltTypes (c1b, c2a);
587 ctype_compare (ctype c1, ctype c2)
592 if (ctype_isUnknown (c1))
594 if (ctype_isUnknown (c2))
604 if (ctype_isUnknown (c2))
609 /* Can't get entries for special ctypes (elips marker) */
611 if (ctype_isElips (c1) || ctype_isElips (c2)
612 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
613 return int_compare (c1, c2);
616 ce1 = ctype_getCtentry (c1);
617 ce2 = ctype_getCtentry (c2);
619 if (ctentry_isComplex (ce1))
621 if (ctentry_isComplex (ce2))
623 return (ctbase_compare (ctype_getCtbase (c1),
624 ctype_getCtbase (c2), FALSE));
631 else if (ctentry_isComplex (ce2))
637 return (int_compare (c1, c2));
646 ** makeFunction: pointer to function returning base
650 ctype_makeParamsFunction (ctype base, /*@only@*/ uentryList p)
652 uentryList_fixImpParams (p);
653 return (ctype_makeFunction (base, p));
657 ctype_makeNFParamsFunction (ctype base, /*@only@*/ uentryList p)
659 uentryList_fixImpParams (p);
660 return (ctbase_makeNFFunction (base, p));
664 ctype_makeFunction (ctype base, /*@only@*/ uentryList p)
667 ret = ctbase_makeFunction (base, p);
671 ctype ctype_expectFunction (ctype c)
673 /* handle parenthesized declarations */
677 c = ctype_makePointer (c);
680 return (cttable_addComplex (ctbase_expectFunction (c)));
683 ctype ctype_dontExpectFunction (ctype c)
685 ctbase ctb = ctype_getCtbase (c);
690 c = ctype_makePointer (c);
694 return (ctbase_getExpectFunction (ctb));
698 ** makeRealFunction: function returning base
701 ctype ctype_makeRawFunction (ctype base, uentryList p)
703 return (cttable_addComplex (ctbase_makeLiveFunction (base, p)));
711 **** this is very poorly defined
713 **** need to unify function/function pointer meaning
717 ctype_isFunction (ctype c)
719 if (ctype_isKnown (c) && ctype_isDefined (c))
721 return (ctbase_isFunction (ctype_getCtbase (c)));
730 ctype_isExpFcn (ctype c)
732 return (ctype_isKnown (c) && ctbase_isExpFcn (ctype_getCtbase (c)));
736 ctype_isVoid (ctype c)
738 return (c == CTX_VOID);
742 ctype_isArbitraryIntegral (ctype c)
744 ctype cr = ctype_realType (c);
746 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
747 || cr == ctype_signedintegral);
751 ctype_isUnsignedIntegral (ctype c)
753 ctype cr = ctype_realType (c);
755 return (cr == ctype_unsignedintegral);
759 ctype_isSignedIntegral (ctype c)
761 ctype cr = ctype_realType (c);
763 return (cr == ctype_signedintegral);
767 ctype_isInt (ctype c)
769 cprim cp = ctype_toCprim (c);
771 return (c == ctype_unknown || cprim_isAnyInt (cp)
772 || (cprim_isAnyChar (cp) && context_msgCharInt ())
773 || (c == ctype_bool && context_msgBoolInt ())
774 || (ctype_isEnum (c) && context_msgEnumInt ()));
778 ctype_isRegularInt (ctype c)
780 cprim cp = ctype_toCprim (c);
782 return (c == ctype_unknown
783 || cprim_closeEnough (cprim_int, cp)
784 || (cprim_isAnyChar (cp) && context_msgCharInt ())
785 || (c == ctype_bool && context_msgBoolInt ())
786 || (ctype_isEnum (c) && context_msgEnumInt ()));
790 ctype_isString (ctype c)
792 return (c == ctype_string
793 || (ctype_isPointer (c)
794 && ctype_isChar (ctype_baseArrayPtr (c))));
798 ctype_isChar (ctype c)
800 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
801 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
805 ctype_isUnsignedChar (ctype c)
807 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
811 ctype_isSignedChar (ctype c)
813 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
817 ** Returns true if c matches the name -booltype <bool>
821 ctype_isManifestBool (ctype c)
824 ** Changed the meaning of ctype_isBool - evs 2000-07-24
825 ** The old meaning was very convoluted!
828 ** c == CTX_BOOL - its a direct bool
829 ** c is a user/abstract type matching the bool name
830 ** (should never occur?)
833 if (ctype_isDirectBool (c)) {
835 } else if (ctype_isUA (c)) {
836 return ctype_isUserBool (c);
843 ctype_isBool (ctype c)
846 ** Changed the meaning of ctype_isBool - evs 2000-07-24
847 ** The old meaning was very convoluted!
850 ** its a manifest bool
851 ** +boolint and ctype_isInt (c)
854 if (ctype_isManifestBool (c)) {
856 } else if (context_msgBoolInt ()) {
857 return ctype_isInt (c);
863 if (context_getFlag (FLG_ABSTRACTBOOL))
865 if (typeId_isInvalid (boolType))
867 boolType = usymtab_getTypeId (context_getBoolName ());
870 if (context_hasAccess (boolType))
872 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
873 || (context_msgBoolInt ()
875 || (c == CTX_CHAR && context_msgCharInt ()))))
880 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
881 || (context_msgBoolInt ()
882 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
887 ctype_isDirectBool (ctype c)
889 return (c == CTX_BOOL);
893 ctype_isReal (ctype c)
895 return (cprim_isAnyReal (ctype_toCprim (c)));
899 ctype_isFloat (ctype c)
901 return (c == ctype_float);
905 ctype_isDouble (ctype c)
907 return (c == ctype_double || c == ctype_ldouble);
911 ctype_isSigned (ctype c)
913 return (!ctype_isUnsigned (c));
917 ctype_isNumeric (ctype c)
919 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c)
920 /* evans 2001-10-05: added this: */
921 || ctype_isArbitraryIntegral (c));
928 ** work on actual type in current context
932 ctype_isRealNumeric (ctype c)
934 if (ctype_isPlain (c))
935 return (ctype_isNumeric (ctype_realType (c)));
936 if (ctype_isConj (c))
937 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
938 ctype_isRealNumeric (ctype_getConjB (c)));
944 ctype_isRealInt (ctype c)
946 if (ctype_isPlain (c))
947 return (ctype_isInt (ctype_realType (c)));
948 else if (ctype_isConj (c))
949 return (ctype_isRealInt (ctype_getConjA (c)) ||
950 ctype_isRealInt (ctype_getConjB (c)));
953 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
959 ctype_isRealVoid (ctype c)
961 if (ctype_isPlain (c))
963 return (ctype_isVoid (ctype_realType (c)));
965 else if (ctype_isConj (c))
967 return (ctype_isRealVoid (ctype_getConjA (c)) ||
968 ctype_isRealVoid (ctype_getConjB (c)));
977 ctype_isRealBool (ctype c)
979 if (ctype_isPlain (c))
981 return (ctype_isBool (ctype_realishType (c)));
983 else if (ctype_isConj (c))
985 return (ctype_isRealBool (ctype_getConjA (c)) ||
986 ctype_isRealBool (ctype_getConjB (c)));
995 ctype_isRealPointer (ctype c)
997 if (ctype_isConj (c))
998 return (ctype_isRealPointer (ctype_getConjA (c)) ||
999 ctype_isRealPointer (ctype_getConjB (c)));
1000 return (ctype_isPointer (ctype_realType (c)));
1004 ctype_isRealSU (ctype c)
1006 if (ctype_isConj (c))
1008 return (ctype_isRealSU (ctype_getConjA (c)) ||
1009 ctype_isRealSU (ctype_getConjB (c)));
1012 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
1013 return (ctype_isStructorUnion (ctype_realType (c)));
1017 ctype_isRealArray (ctype c)
1019 if (ctype_isConj (c))
1020 return (ctype_isRealArray (ctype_getConjA (c)) ||
1021 ctype_isRealArray (ctype_getConjB (c)));
1022 return (ctype_isArray (ctype_realType (c)));
1026 ctype_isRealAP (ctype c)
1028 if (ctype_isConj (c))
1029 return (ctype_isRealAP (ctype_getConjA (c)) ||
1030 ctype_isRealAP (ctype_getConjB (c)));
1031 return (ctype_isAP (ctype_realType (c)));
1035 ctype_isRealFunction (ctype c)
1037 if (ctype_isConj (c))
1038 return (ctype_isRealFunction (ctype_getConjA (c)) ||
1039 ctype_isRealFunction (ctype_getConjB (c)));
1040 return (ctype_isFunction (ctype_realType (c)));
1044 ctype_isDirectInt (ctype c)
1046 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
1050 ** forceful predicates
1052 ** take *ctype; if its a conjunct, and there is a match replace with match only.
1053 ** if both match, still conjunct
1057 ctype_isForcePred (ctype * c, bool (pred) (ctype))
1059 /*drl bee: pbr */ if (ctype_isConj (*c))
1061 ctype cbr = ctype_getConjA (*c);
1063 /*drl bee: si*/ if ((*pred) (cbr))
1065 if ((*pred) (ctype_getConjB (*c)))
1078 if ((*pred) (cbr = ctype_getConjB (*c)))
1086 return ((*pred) (*c));
1090 ctype_isForceRealNumeric (ctype * c)
1092 return (ctype_isForcePred (c, ctype_isRealNumeric));
1096 ctype_isForceRealInt (ctype * c)
1098 return (ctype_isForcePred (c, ctype_isRealInt));
1102 ctype_isForceRealBool (ctype * c)
1104 return (ctype_isForcePred (c, ctype_isRealBool));
1110 ** save int/char, int/bool, other random conjuncts
1114 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
1116 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
1120 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1128 return (ctype_makeExplicitConj (c1, c2));
1132 return (ctype_makeConj (c1, c2));
1138 ctype_makeExplicitConj (ctype c1, ctype c2)
1140 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1142 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1144 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1146 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1148 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1150 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1154 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1158 static ctype ic = ctype_unknown; /* int | char */
1159 static ctype ib = ctype_unknown; /* int | bool */
1160 static ctype ifl = ctype_unknown; /* int | float */
1161 static ctype ibf = ctype_unknown; /* int | bool | float */
1162 static ctype ibc = ctype_unknown; /* int | bool | char */
1163 static ctype iv = ctype_unknown; /* int | void * */
1164 static ctype ivf = ctype_unknown; /* int | void * | float */
1165 static ctype ivb = ctype_unknown; /* int | void * | bool */
1166 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1167 static ctype cuc = ctype_unknown; /* char | unsigned char */
1170 ctype_recordConj (ctype c)
1174 llassert (ctype_isConj (c));
1176 c1 = ctype_getConjA (c);
1177 c2 = ctype_getConjB (c);
1180 if (c2 == ctype_int && c1 != ctype_int)
1190 if (c1 == ctype_int)
1192 if (c2 == ctype_char)
1194 llassert (ic == ctype_unknown);
1197 else if (c2 == ctype_bool)
1199 llassert (ib == ctype_unknown);
1202 else if (c2 == ctype_float)
1204 llassert (ifl == ctype_unknown);
1207 else if (c2 == CTP_VOID)
1209 llassert (iv == ctype_unknown);
1217 else if (c1 == ib && ib != ctype_unknown)
1219 if (c2 == ctype_float)
1221 llassert (ibf == ctype_unknown);
1224 else if (c2 == ctype_char)
1226 llassert (ibc == ctype_unknown);
1236 if (c2 == ctype_bool)
1238 llassert (ivb == ctype_unknown);
1241 else if (c2 == ctype_float)
1243 llassert (ivf == ctype_unknown);
1253 if (c2 == ctype_bool)
1255 llassert (ivbf == ctype_unknown);
1261 if (c2 == ctype_float)
1263 llassert (ivbf == ctype_unknown);
1267 else if (c1 == ctype_char)
1269 if (c2 == ctype_uchar)
1271 llassert (cuc == ctype_unknown);
1283 ctype_makeConj (ctype c1, ctype c2)
1285 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1287 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1289 if (ctype_isUnknown (c1))
1293 else if (ctype_isUnknown (c2))
1297 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1299 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1300 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1302 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1304 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1305 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1309 if (ctype_isManifestBool (c1))
1314 if (ctype_isManifestBool (c2))
1319 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1321 c1 = ctype_voidPointer;
1324 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1326 c2 = ctype_voidPointer;
1330 ** Ouch, can't do this. unsigned, etc. modifiers might
1331 ** apply to wrong type!
1333 ** if (c2 == ctype_int && c1 != ctype_int)
1344 if (c1 == ctype_int)
1346 if (c2 == ctype_char)
1348 if (ic == ctype_unknown)
1350 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1355 else if (c2 == ctype_bool)
1357 if (ib == ctype_unknown)
1359 ib = cttable_addComplex
1360 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1365 else if (c2 == ctype_float)
1367 if (ifl == ctype_unknown)
1369 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1376 if (c2 == ctype_voidPointer)
1378 if (iv == ctype_unknown)
1380 iv = cttable_addComplex
1381 (ctbase_makeConj (ctype_int,
1390 else if (c1 == ib && ib != ctype_unknown)
1392 if (c2 == ctype_float)
1394 if (ibf == ctype_unknown)
1396 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1401 else if (c2 == ctype_char)
1403 if (ibc == ctype_unknown)
1405 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1417 if (c2 == ctype_bool)
1419 if (ivb == ctype_unknown)
1421 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1426 else if (c2 == ctype_float)
1428 if (ivf == ctype_unknown)
1430 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1442 if (c2 == ctype_bool)
1444 if (ivbf == ctype_unknown)
1446 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1454 if (c2 == ctype_float)
1456 if (ivbf == ctype_unknown)
1458 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1464 else if (c1 == ctype_char)
1466 if (c2 == ctype_uchar)
1468 if (cuc == ctype_unknown)
1470 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1482 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1488 ctype_isConj (ctype c)
1490 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1494 ctype_getConjA (ctype c)
1496 if (!ctype_isConj (c))
1497 llbuglit ("ctype_getConjA: not a conj");
1498 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1502 ctype_getConjB (ctype c)
1504 if (!ctype_isConj (c))
1505 llbuglit ("ctype_getConjB: not a conj");
1506 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1510 ctype_isExplicitConj (ctype c)
1512 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1515 /** << need to fix resolveConj >> **/
1518 ** structs and unions
1522 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1526 DPRINTF (("Creating a struct: %s / %s",
1527 n, uentryList_unparse (f)));
1529 ct = cttable_addComplex (ctbase_createStruct (n, f));
1530 DPRINTF (("ct: %s", ctype_unparse (ct)));
1535 ctype_getFields (ctype c)
1537 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1541 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1545 ret = cttable_addComplex (ctbase_createUnion (n, f));
1552 ** if ctype's are same, definite match.
1553 ** else, need to call ctbase_match.
1555 ** if necessary context can memoize matches
1559 quickMatch (ctype c1, ctype c2)
1568 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1572 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1574 if (quickMatch (c1, c2))
1579 if (ctype_isElips (c1) || ctype_isElips (c2))
1585 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1591 ctype_sameName (ctype c1, ctype c2)
1593 if (quickMatch (c1, c2))
1596 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1600 ctype_almostEqual (ctype c1, ctype c2)
1602 if (ctype_equal (c1, c2))
1608 if (ctype_isUnknown (c1))
1610 return ctype_isUnknown (c2);
1612 else if (ctype_isUnknown (c2))
1618 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1624 ctype_matchDef (ctype c1, ctype c2)
1626 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1628 if (quickMatch (c1, c2))
1631 if (ctype_isElips (c1))
1632 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1634 if (ctype_isElips (c2))
1636 return (ctype_isUnknown (c2));
1640 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1643 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1644 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1645 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1650 bool ctype_match (ctype c1, ctype c2)
1652 if (quickMatch (c1, c2))
1655 if (ctype_isElips (c1))
1656 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1658 if (ctype_isElips (c2))
1659 return (ctype_isUnknown (c2));
1661 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1665 ctype_forceMatch (ctype c1, ctype c2)
1667 if (quickMatch (c1, c2))
1670 if (ctype_isElips (c1))
1671 return (ctype_isElips (c2));
1673 if (ctype_isElips (c2))
1677 /* The call forceMatch may modify the observer params, but, we don't care. */
1678 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1683 ctype_matchArg (ctype c1, ctype c2)
1685 if (quickMatch (c1, c2))
1691 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1696 ** simple ctype_is operations.
1697 ** DO NOT use real type of c, only direct type.
1701 ** ctype_isVoidPointer
1707 ctype_isVoidPointer (ctype c)
1709 if (ctype_isComplex (c))
1711 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1713 if (ctype_isConj (c))
1715 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1716 ctype_isVoidPointer (ctype_getConjB (c)));
1720 return (c == ctype_voidPointer
1721 || (ctype_isRealPointer (c)
1722 && ctype_isVoid (ctype_baseArrayPtr (c))));
1729 ** true for C and LCL pointers
1733 ctype_isPointer (ctype c)
1735 if (ctype_isElips (c)) return FALSE;
1737 if (ctype_isComplex (c))
1739 ctbase ctb = ctype_getCtbaseSafe (c);
1740 bool res = ctbase_isPointer (ctb);
1746 bool res = ctentry_isPointer (ctype_getCtentry (c));
1755 ** true for C and LCL array's
1759 ctype_isArray (ctype c)
1761 if (ctype_isElips (c)) return FALSE;
1763 if (ctype_isComplex (c))
1764 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1766 return (ctentry_isArray (ctype_getCtentry (c)));
1769 bool ctype_isIncompleteArray (ctype c)
1771 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1775 ctype_isArrayPtr (ctype c)
1777 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1781 ctype_typeId (ctype c)
1783 return (ctbase_typeId (ctype_getCtbase (c)));
1787 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1789 llassert (! (ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1791 if (ctype_isUnknown (c))
1793 return message ("? %q", name);
1797 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1802 ctype_unparse (ctype c)
1804 if (ctype_isElips (c))
1806 return cstring_makeLiteralTemp ("...");
1808 else if (ctype_isMissingParamsMarker (c))
1810 return cstring_makeLiteralTemp ("-");
1812 else if (ctype_isUnknown (c))
1814 return cstring_makeLiteralTemp ("?");
1816 else if (ctype_isAnytype (c))
1818 return cstring_makeLiteralTemp ("<any>");
1823 return (ctentry_doUnparse (ctype_getCtentry (c)));
1829 ctype_unparseSafe (ctype c)
1831 if (ctype_isElips (c))
1833 return cstring_makeLiteralTemp ("...");
1835 else if (ctype_isMissingParamsMarker (c))
1837 return cstring_makeLiteralTemp ("-");
1843 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1845 ctentry cte = ctype_getCtentry (c);
1847 if (cstring_isDefined (cte->unparse))
1849 return (cte->unparse);
1853 ret = message ("[%d]", (int) c);
1854 cstring_markOwned (ret);
1860 ctype_unparseDeep (ctype c)
1862 if (ctype_isElips (c))
1864 return cstring_makeLiteralTemp ("...");
1866 if (ctype_isMissingParamsMarker (c))
1868 return cstring_makeLiteralTemp ("-");
1871 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1875 ctype_undump (char **c)
1877 return ((ctype) reader_getInt (c)); /* check its valid? */
1881 ctype_dump (ctype c)
1883 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1887 /* Handle invalid types in a kludgey way. */
1888 return (message ("0"));
1893 cstring tname = usymtab_getTypeEntryName
1894 (usymtab_convertId (ctype_typeId (c)));
1896 if (cstring_equal (tname, context_getBoolName ()))
1898 cstring_free (tname);
1899 return (message ("%d", ctype_bool));
1902 cstring_free (tname);
1905 DPRINTF (("Returning: %d", c));
1906 return (message ("%d", c));
1910 ctype_getBaseType (ctype c)
1912 ctentry cte = ctype_getCtentry (c);
1914 switch (ctentry_getKind (cte))
1923 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1926 ctbase ctb = cte->ctbase;
1928 if (ctbase_isDefined (ctb))
1947 return (ctype_getBaseType (ctb->contents.base));
1949 return (ctype_getBaseType (ctb->contents.farray->base));
1950 case CT_CONJ: /* base type of A conj branch? */
1951 return (ctype_getBaseType (ctb->contents.conj->a));
1953 /*@noaccess ctbase@*/
1961 llbuglit ("ctype_newBase: bad case");
1963 llcontbuglit ("ctype_getBaseType: unreachable code");
1964 return ((ctype)NULL);
1968 ctype_adjustPointers (int np, ctype c)
1971 if (ctype_isFunction (c))
1973 c = ctype_makeParamsFunction
1974 (ctype_adjustPointers (np, ctype_getReturnType (c)),
1975 uentryList_copy (ctype_argsFunction (c)));
1979 /* fix this should not use getBaseType ??? */
1980 ctype cb = ctype_getBaseType (c);
1984 cb = ctype_makePointer (cb);
1987 c = ctype_newBase (c, cb);
1995 ctype_elist (ctype c)
1997 return (ctbase_elist (ctype_getCtbase (c)));
2001 ctype_isFirstVoid (ctype c)
2003 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
2007 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
2009 return (cttable_addComplex (ctbase_createEnum (tag, el)));
2013 ctype_isEnum (ctype c)
2015 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
2019 ctype_enumTag (ctype c)
2021 llassert (ctype_isEnum (c));
2023 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
2027 ctype_isStruct (ctype c)
2029 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
2033 ctype_isUnion (ctype c)
2035 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
2039 ctype_resolveNumerics (ctype c1, ctype c2)
2042 ** returns longest type of c1 and c2
2045 if (c1 == c2) return c1;
2047 c1 = ctype_realType (c1);
2048 c2 = ctype_realType (c2);
2050 if (ctype_isEnum (c1)) c1 = ctype_unknown;
2051 if (ctype_isEnum (c2)) c2 = ctype_int;
2053 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
2055 /* 2001-06-08: This fix provided by Jim Zelenka. */
2056 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
2057 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
2059 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
2060 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
2061 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
2062 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
2064 /* 2001-06-08: This fix provided by Jim Zelenka. */
2065 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
2067 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
2069 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
2070 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
2072 if (ctype_isKnown (c1)) return c1;
2077 ctype_isStructorUnion (ctype c)
2079 return (ctype_isStruct (c) || ctype_isUnion (c));
2083 ctype_fixArrayPtr (ctype c)
2085 if (ctype_isArray (c))
2087 return (ctype_makePointer (ctype_baseArrayPtr (c)));
2094 ** createUnnamedStruct/Union
2096 ** check if it corresponds to an existing LCL-specified unnamed struct
2097 ** otherwise, give it a new tag
2101 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
2103 ctype ret = usymtab_structFieldsType (f);
2105 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
2107 if (ctype_isDefined (ret))
2109 uentryList_free (f);
2114 cstring ft = fakeTag ();
2115 ctype ct = ctype_createStruct (cstring_copy (ft), f);
2116 uentry ue = uentry_makeStructTagLoc (ft, ct);
2118 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2119 ue = usymtab_supGlobalEntryReturn (ue);
2120 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2128 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2130 ctype ret = usymtab_unionFieldsType (f);
2132 if (ctype_isDefined (ret))
2134 uentryList_free (f);
2139 cstring ft = fakeTag ();
2140 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2141 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2143 usymtab_supGlobalEntry (ue);
2150 ctype_isUnnamedSU (ctype c)
2154 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2163 ctype_createForwardStruct (cstring n)
2165 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2166 ctype ct = usymtab_supForwardTypeEntry (ue);
2173 ctype_createForwardUnion (cstring n)
2175 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2176 ctype ct = usymtab_supForwardTypeEntry (ue);
2183 ctype_removePointers (ctype c)
2187 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2190 c = ctype_baseArrayPtr (c);
2191 llassert (c != oldc);
2197 bool ctype_isMutable (ctype t)
2201 return (uentry_isMutableDatatype
2202 (usymtab_getTypeEntry (ctype_typeId (t))));
2206 return (ctype_isPointer (ctype_realType (t)));
2207 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2211 bool ctype_isRefCounted (ctype t)
2215 return (uentry_isRefCountedDatatype
2216 (usymtab_getTypeEntry (ctype_typeId (t))));
2222 bool ctype_isVisiblySharable (ctype t)
2224 if (ctype_isUnknown (t)) return TRUE;
2226 if (ctype_isConj (t))
2228 return (ctype_isVisiblySharable (ctype_getConjA (t))
2229 || ctype_isVisiblySharable (ctype_getConjB (t)));
2232 if (ctype_isMutable (t))
2236 ctype rt = ctype_realType (t);
2244 return ctype_isVisiblySharable (rt);
2258 /* Replaced by ctype_isMutable (more sensible) */
2259 bool ctype_canAlias (ctype ct)
2261 /* can ct refer to memory locations?
2262 ** ==> a pointer or a mutable abstract type
2266 ctype tr = ctype_realType (ct);
2268 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2273 ** c1 is the dominant type; c2 is the modifier type
2275 ** eg. double + long int => long double
2278 ctype ctype_combine (ctype dominant, ctype modifier)
2280 DPRINTF (("Combine: %s + %s",
2281 ctype_unparse (dominant),
2282 ctype_unparse (modifier)));
2284 if (ctype_isConj (dominant))
2288 if (ctype_isExplicitConj (dominant))
2290 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2292 ctype_getConjB (dominant));
2296 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2298 ctype_getConjB (dominant));
2304 if (ctype_isUnknown (modifier))
2308 else if (ctype_isUnknown (dominant))
2314 if (ctype_isEnum (dominant)) dominant = ctype_int;
2315 if (ctype_isEnum (modifier)) modifier = ctype_int;
2317 if (modifier == ctype_uint)
2319 if (dominant == ctype_int) return ctype_uint;
2320 if (dominant == ctype_lint) return ctype_ulint;
2321 if (dominant == ctype_sint) return ctype_usint;
2322 if (dominant == ctype_char) return ctype_uchar;
2324 /* evs 2000-07-28: added this line */
2325 if (dominant == ctype_llint) return ctype_ullint;
2327 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2329 voptgenerror (FLG_DUPLICATEQUALS,
2330 message ("Duplicate unsigned qualifier"),
2337 voptgenerror (FLG_DUPLICATEQUALS,
2338 message ("Type qualifier unsigned used with %s",
2339 ctype_unparse (dominant)),
2345 else if (modifier == ctype_llint)
2347 if (dominant == ctype_int)
2352 voptgenerror (FLG_DUPLICATEQUALS,
2353 message ("Duplicate long qualifier on non-int"),
2356 else if (modifier == ctype_lint)
2358 if (dominant == ctype_int) return ctype_lint;
2359 if (dominant == ctype_uint) return ctype_ulint;
2360 if (dominant == ctype_double) return ctype_ldouble;
2362 if (dominant == ctype_lint || dominant == ctype_ulint
2363 || dominant == ctype_sint || dominant == ctype_usint
2364 || dominant == ctype_ldouble)
2366 if (dominant == ctype_lint)
2368 /* long long not supported by ANSI */
2373 if (dominant == ctype_ulint)
2375 /* unsigned long long not supported by ANSI */
2376 return ctype_ullint;
2380 if (dominant == ctype_sint || dominant == ctype_usint)
2382 if (!context_getFlag (FLG_IGNOREQUALS))
2384 llerrorlit (FLG_SYNTAX,
2385 "Contradictory long and short type qualifiers");
2390 voptgenerror (FLG_DUPLICATEQUALS,
2391 message ("Duplicate long qualifier"),
2398 else if (modifier == ctype_sint)
2400 if (dominant == ctype_int) return ctype_sint;
2401 if (dominant == ctype_uint) return ctype_usint;
2403 if (dominant == ctype_sint || dominant == ctype_usint)
2405 voptgenerror (FLG_DUPLICATEQUALS,
2406 message ("Duplicate short qualifier"),
2410 else if (dominant == ctype_lint)
2412 if (!context_getFlag (FLG_IGNOREQUALS))
2414 llerrorlit (FLG_SYNTAX,
2415 "Contradictory long and short type qualifiers");
2421 else if (dominant == ctype_llint)
2423 if (!context_getFlag (FLG_IGNOREQUALS))
2425 llerrorlit (FLG_SYNTAX,
2426 "Contradictory long long and short type qualifiers");
2434 if (!context_getFlag (FLG_IGNOREQUALS))
2436 llerror (FLG_SYNTAX,
2437 message ("Type qualifier short used with %s",
2438 ctype_unparse (dominant)));
2444 else if (modifier == ctype_ulint)
2446 if (dominant == ctype_int) return modifier;
2448 if (dominant == ctype_lint || dominant == ctype_ulint)
2450 voptgenerror (FLG_DUPLICATEQUALS,
2451 message ("Duplicate long qualifier"),
2457 if (dominant == ctype_uint || dominant == ctype_usint)
2459 voptgenerror (FLG_DUPLICATEQUALS,
2460 message ("Duplicate unsigned qualifier"),
2466 if (dominant == ctype_sint || dominant == ctype_usint)
2468 if (!context_getFlag (FLG_IGNOREQUALS))
2470 llerrorlit (FLG_SYNTAX,
2471 "Contradictory long and short type qualifiers");
2477 if (!context_getFlag (FLG_IGNOREQUALS))
2479 llerror (FLG_SYNTAX,
2480 message ("Type qualifiers unsigned long used with %s",
2481 ctype_unparse (dominant)));
2486 else if (modifier == ctype_usint)
2488 if (dominant == ctype_int) return modifier;
2490 if (dominant == ctype_sint || dominant == ctype_usint)
2492 voptgenerror (FLG_DUPLICATEQUALS,
2493 message ("Duplicate short qualifier"),
2498 if (dominant == ctype_uint)
2500 voptgenerror (FLG_DUPLICATEQUALS,
2501 message ("Duplicate unsigned qualifier"),
2507 if (dominant == ctype_lint || dominant == ctype_ulint
2508 || dominant == ctype_llint)
2510 if (!context_getFlag (FLG_IGNOREQUALS))
2512 llerrorlit (FLG_SYNTAX,
2513 "Contradictory long and short type qualifiers");
2519 if (!context_getFlag (FLG_IGNOREQUALS))
2521 llerror (FLG_SYNTAX,
2522 message ("Type qualifiers unsigned short used with %s",
2523 ctype_unparse (dominant)));
2537 ctype ctype_resolve (ctype c)
2539 if (ctype_isUnknown (c))
2543 else if (c == ctype_anytype)
2545 return ctype_unknown;
2553 ctype ctype_fromQual (qual q)
2555 if (qual_isSigned (q)) return ctype_int;
2556 if (qual_isUnsigned (q)) return ctype_uint;
2557 if (qual_isLong (q)) return ctype_lint;
2558 if (qual_isShort (q)) return ctype_sint;
2560 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2561 return ctype_unknown;
2565 ctype_isAnyFloat (ctype c)
2567 return (cprim_isAnyReal (ctype_toCprim (c)));
2571 ctype_isUnsigned (ctype c)
2573 if (ctype_isConj (c))
2574 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2575 ctype_isUnsigned (ctype_getConjB (c)));
2577 return (c == ctype_uint || c == ctype_uchar
2578 || c == ctype_usint || c == ctype_ulint
2579 || c == ctype_ullint
2580 || c == ctype_unsignedintegral);
2585 ctype_isLongLong (ctype c)
2587 if (ctype_isConj (c))
2588 return (ctype_isLongLong (ctype_getConjA (c)) ||
2589 ctype_isLongLong (ctype_getConjB (c)));
2591 return (c == ctype_llint || c == ctype_ullint);
2596 ctype_isLong (ctype c)
2598 if (ctype_isConj (c))
2599 return (ctype_isLong (ctype_getConjA (c)) ||
2600 ctype_isLong (ctype_getConjB (c)));
2602 return (c == ctype_lint || c == ctype_ulint);
2606 ctype_isShort (ctype c)
2608 if (ctype_isConj (c))
2609 return (ctype_isShort (ctype_getConjA (c)) ||
2610 ctype_isShort (ctype_getConjB (c)));
2612 return (c == ctype_sint || c == ctype_usint);
2616 ctype_isStackAllocated (ctype c)
2618 ctype ct = ctype_realType (c);
2620 if (ctype_isConj (ct))
2621 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2622 ctype_isStackAllocated (ctype_getConjB (ct)));
2624 return (ctype_isArray (c) || ctype_isSU (c));
2627 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2629 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2632 static bool ctype_isLonger (ctype c1, ctype c2)
2634 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2635 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2636 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2637 || (ctype_isLong (c1)
2638 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2639 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2643 ctype_widest (ctype c1, ctype c2)
2645 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2655 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2658 if (c >= 0 && c < cttab.size)
2660 return (cttab.entries[c]->ctbase);
2664 if (c == ctype_unknown)
2665 llbuglit ("ctype_getCtbase: ctype unknown");
2666 if (c == ctype_undefined)
2667 llbuglit ("ctype_getCtbase: ctype undefined");
2669 llbuglit ("ctype_getCtbase: ctype dne");
2670 if (c == ctype_elipsMarker)
2671 llbuglit ("ctype_getCtbase: elips marker");
2672 if (c == ctype_anytype)
2673 llbuglit ("ctype_getCtbase: ctype anytype");
2675 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2682 static /*@notnull@*/ /*@observer@*/ ctbase
2683 ctype_getCtbaseSafe (ctype c)
2685 ctbase res = ctype_getCtbase (c);
2687 llassert (ctbase_isDefined (res));
2696 ctype_getCtentry (ctype c)
2698 static /*@only@*/ ctentry errorEntry = NULL;
2700 if (cttab.size == 0)
2702 if (errorEntry == NULL)
2704 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2711 if (c >= CTK_PLAIN && c < cttab.size)
2713 return (cttab.entries[c]);
2715 else if (c == CTK_UNKNOWN)
2716 llcontbuglit ("ctype_getCtentry: ctype unknown");
2717 else if (c == CTK_ANYTYPE)
2718 llcontbuglit ("ctype_getCtentry: ctype unknown");
2719 else if (c == CTK_INVALID)
2720 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2721 else if (c == CTK_DNE)
2722 llcontbuglit ("ctype_getCtentry: ctype dne");
2723 else if (c == CTK_ELIPS)
2724 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2725 else if (c == CTK_MISSINGPARAMS)
2726 llcontbuglit ("ctype_getCtentry: ctype missing params");
2728 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2730 return (cttab.entries[ctype_unknown]);
2735 bool ctype_isFixedArray (ctype c)
2737 if (ctype_isElips (c)) return FALSE;
2739 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
2744 /* requires that the type is an fixed array */
2745 /* return the size of the array */
2747 size_t ctype_getArraySize (ctype c)
2753 llassert (ctype_isFixedArray (c));
2755 ctb = ctype_getCtbaseSafe(c);
2756 size = ctbase_getArraySize (ctb);
2758 DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",