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_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 ] */
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, long size)
321 res = cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c);
325 ctype ctype_makeInnerFixedArray (ctype c, long size)
329 if (ctype_isFixedArray (c))
331 ctype cb = ctype_baseArrayPtr (c);
332 long osize = ctype_getArraySize (c);
334 res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size),
337 else if (ctype_isArray (c))
339 ctype cb = ctype_baseArrayPtr (c);
341 res = ctype_makeArray (ctype_makeInnerFixedArray (cb, size));
345 res = ctype_makeFixedArray (c, size);
348 DPRINTF (("Make inner fixed array: %s", ctype_unparse (res)));
352 ctype ctype_makeInnerArray (ctype c)
356 DPRINTF (("Make inner array: %s", ctype_unparse (c)));
358 if (ctype_isFixedArray (c))
360 ctype cb = ctype_baseArrayPtr (c);
361 long osize = ctype_getArraySize (c);
363 res = ctype_makeFixedArray (ctype_makeInnerArray (cb),
368 res = ctype_makeArray (c);
371 DPRINTF (("Make inner array: %s", ctype_unparse (res)));
376 ctype_makeArray (ctype c)
378 ctentry cte = ctype_getCtentry (c);
379 ctype clp = ctentry_getArray (cte);
381 DPRINTF (("Make array: %s", ctype_unparse (c)));
383 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
385 ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
386 ctentry_setArray (cte, cnew);
396 ** requires c is a pointer of array
400 ctype_baseArrayPtr (ctype c)
402 ctentry cte = ctype_getCtentry (ctype_realType (c));
404 if (ctype_isConj (c))
406 if (ctype_isAP (ctype_getConjA (c)))
408 if (ctype_isAP (ctype_getConjB (c)))
410 return (ctype_makeConj (ctype_baseArrayPtr (ctype_getConjA (c)),
411 ctype_baseArrayPtr (ctype_getConjB (c))));
415 return (ctype_baseArrayPtr (ctype_getConjA (c)));
420 return (ctype_baseArrayPtr (ctype_getConjB (c)));
423 else if (ctype_isInt (c)) /* could be NULL */
425 return ctype_unknown;
429 ctype clp = ctentry_getBase (cte);
431 if (ctype_isBroken (clp))
433 llbuglit ("ctype_baseArrayPtr: bogus ctype");
445 ctype_makeWideString ()
447 static ctype res = ctype_unknown;
449 if (ctype_isUnknown (res))
453 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
455 wchart = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t")));
462 res = ctype_makePointer (wchart);
469 ctype_isWideString (ctype c)
471 if (ctype_isPointer (c))
473 ctype ct = ctype_baseArrayPtr (c);
475 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
477 return (ct == uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t"))));
491 ctype_getReturnType (ctype c)
493 if (ctype_isUnknown (c))
495 return ctype_unknown;
498 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
502 ** must be a shared pointer
505 /*@observer@*/ uentryList
506 ctype_argsFunction (ctype c)
508 if (ctype_isUnknown (c))
510 return uentryList_undefined;
513 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
517 ** Returns type with base type p and compound types from c.
519 ** i.e., c = char *[]; p = int
524 ctype_newBase (ctype c, ctype p)
526 return (ctbase_newBase (c, p));
530 ctype_sameAltTypes (ctype c1, ctype c2)
535 llassert (ctype_isConj (c1) && ctype_isConj (c2));
537 c1a = ctype_getConjA (c1);
538 c2a = ctype_getConjA (c2);
540 c1b = ctype_getConjB (c1);
541 c2b = ctype_getConjB (c2);
543 if (ctype_compare (c1a, c2a) == 0)
545 if (ctype_compare (c1b, c2b) == 0)
551 if (ctype_isConj (c1b) && ctype_isConj (c2b))
553 return ctype_sameAltTypes (c1b, c2b);
563 if (ctype_compare (c1a, c2b) == 0)
565 if (ctype_compare (c1b, c2a) == 0)
571 if (ctype_isConj (c1b) && ctype_isConj (c2a))
573 return ctype_sameAltTypes (c1b, c2a);
589 ctype_compare (ctype c1, ctype c2)
594 if (ctype_isUnknown (c1))
596 if (ctype_isUnknown (c2))
606 if (ctype_isUnknown (c2))
611 /* Can't get entries for special ctypes (elips marker) */
613 if (ctype_isElips (c1) || ctype_isElips (c2)
614 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
615 return int_compare (c1, c2);
618 ce1 = ctype_getCtentry (c1);
619 ce2 = ctype_getCtentry (c2);
621 if (ctentry_isComplex (ce1))
623 if (ctentry_isComplex (ce2))
625 return (ctbase_compare (ctype_getCtbase (c1),
626 ctype_getCtbase (c2), FALSE));
633 else if (ctentry_isComplex (ce2))
639 return (int_compare (c1, c2));
648 ** makeFunction: pointer to function returning base
652 ctype_makeParamsFunction (ctype base, /*@only@*/ uentryList p)
654 uentryList_fixImpParams (p);
655 return (ctype_makeFunction (base, p));
659 ctype_makeNFParamsFunction (ctype base, /*@only@*/ uentryList p)
661 uentryList_fixImpParams (p);
662 return (ctbase_makeNFFunction (base, p));
666 ctype_makeFunction (ctype base, /*@only@*/ uentryList p)
669 ret = ctbase_makeFunction (base, p);
673 ctype ctype_expectFunction (ctype c)
675 /* handle parenthesized declarations */
679 c = ctype_makePointer (c);
682 return (cttable_addComplex (ctbase_expectFunction (c)));
685 ctype ctype_dontExpectFunction (ctype c)
687 ctbase ctb = ctype_getCtbase (c);
692 c = ctype_makePointer (c);
696 return (ctbase_getExpectFunction (ctb));
700 ** makeRealFunction: function returning base
703 ctype ctype_makeRawFunction (ctype base, uentryList p)
705 return (cttable_addComplex (ctbase_makeLiveFunction (base, p)));
713 **** this is very poorly defined
715 **** need to unify function/function pointer meaning
719 ctype_isFunction (ctype c)
721 if (ctype_isKnown (c) && ctype_isDefined (c))
723 return (ctbase_isFunction (ctype_getCtbase (c)));
732 ctype_isExpFcn (ctype c)
734 return (ctype_isKnown (c) && ctbase_isExpFcn (ctype_getCtbase (c)));
738 ctype_isVoid (ctype c)
740 return (c == CTX_VOID);
744 ctype_isArbitraryIntegral (ctype c)
746 ctype cr = ctype_realType (c);
748 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
749 || cr == ctype_signedintegral);
753 ctype_isUnsignedIntegral (ctype c)
755 ctype cr = ctype_realType (c);
757 return (cr == ctype_unsignedintegral);
761 ctype_isSignedIntegral (ctype c)
763 ctype cr = ctype_realType (c);
765 return (cr == ctype_signedintegral);
769 ctype_isInt (ctype c)
771 cprim cp = ctype_toCprim (c);
773 return (c == ctype_unknown || cprim_isAnyInt (cp)
774 || (cprim_isAnyChar (cp) && context_msgCharInt ())
775 || (c == ctype_bool && context_msgBoolInt ())
776 || (ctype_isEnum (c) && context_msgEnumInt ()));
780 ctype_isRegularInt (ctype c)
782 cprim cp = ctype_toCprim (c);
784 return (c == ctype_unknown
785 || cprim_closeEnough (cprim_int, cp)
786 || (cprim_isAnyChar (cp) && context_msgCharInt ())
787 || (c == ctype_bool && context_msgBoolInt ())
788 || (ctype_isEnum (c) && context_msgEnumInt ()));
792 ctype_isString (ctype c)
794 return (c == ctype_string
795 || (ctype_isPointer (c)
796 && ctype_isChar (ctype_baseArrayPtr (c))));
800 ctype_isChar (ctype c)
802 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
803 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
807 ctype_isUnsignedChar (ctype c)
809 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
813 ctype_isSignedChar (ctype c)
815 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
819 ** Returns true if c matches the name -booltype <bool>
823 ctype_isManifestBool (ctype c)
826 ** Changed the meaning of ctype_isBool - evs 2000-07-24
827 ** The old meaning was very convoluted!
830 ** c == CTX_BOOL - its a direct bool
831 ** c is a user/abstract type matching the bool name
832 ** (should never occur?)
835 if (ctype_isDirectBool (c)) {
837 } else if (ctype_isUA (c)) {
838 return ctype_isUserBool (c);
845 ctype_isBool (ctype c)
848 ** Changed the meaning of ctype_isBool - evs 2000-07-24
849 ** The old meaning was very convoluted!
852 ** its a manifest bool
853 ** +boolint and ctype_isInt (c)
856 if (ctype_isManifestBool (c)) {
858 } else if (context_msgBoolInt ()) {
859 return ctype_isInt (c);
865 if (context_getFlag (FLG_ABSTRACTBOOL))
867 if (typeId_isInvalid (boolType))
869 boolType = usymtab_getTypeId (context_getBoolName ());
872 if (context_hasAccess (boolType))
874 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
875 || (context_msgBoolInt ()
877 || (c == CTX_CHAR && context_msgCharInt ()))))
882 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
883 || (context_msgBoolInt ()
884 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
889 ctype_isDirectBool (ctype c)
891 return (c == CTX_BOOL);
895 ctype_isReal (ctype c)
897 return (cprim_isAnyReal (ctype_toCprim (c)));
901 ctype_isFloat (ctype c)
903 return (c == ctype_float);
907 ctype_isDouble (ctype c)
909 return (c == ctype_double || c == ctype_ldouble);
913 ctype_isSigned (ctype c)
915 return (!ctype_isUnsigned (c));
919 ctype_isNumeric (ctype c)
921 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c)
922 /* evans 2001-10-05: added this: */
923 || ctype_isArbitraryIntegral (c));
930 ** work on actual type in current context
934 ctype_isRealNumeric (ctype c)
936 if (ctype_isPlain (c))
937 return (ctype_isNumeric (ctype_realType (c)));
938 if (ctype_isConj (c))
939 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
940 ctype_isRealNumeric (ctype_getConjB (c)));
946 ctype_isRealInt (ctype c)
948 if (ctype_isPlain (c))
949 return (ctype_isInt (ctype_realType (c)));
950 else if (ctype_isConj (c))
951 return (ctype_isRealInt (ctype_getConjA (c)) ||
952 ctype_isRealInt (ctype_getConjB (c)));
955 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
961 ctype_isRealVoid (ctype c)
963 if (ctype_isPlain (c))
965 return (ctype_isVoid (ctype_realType (c)));
967 else if (ctype_isConj (c))
969 return (ctype_isRealVoid (ctype_getConjA (c)) ||
970 ctype_isRealVoid (ctype_getConjB (c)));
979 ctype_isRealBool (ctype c)
981 if (ctype_isPlain (c))
983 return (ctype_isBool (ctype_realishType (c)));
985 else if (ctype_isConj (c))
987 return (ctype_isRealBool (ctype_getConjA (c)) ||
988 ctype_isRealBool (ctype_getConjB (c)));
997 ctype_isRealPointer (ctype c)
999 if (ctype_isConj (c))
1000 return (ctype_isRealPointer (ctype_getConjA (c)) ||
1001 ctype_isRealPointer (ctype_getConjB (c)));
1002 return (ctype_isPointer (ctype_realType (c)));
1006 ctype_isRealSU (ctype c)
1008 if (ctype_isConj (c))
1010 return (ctype_isRealSU (ctype_getConjA (c)) ||
1011 ctype_isRealSU (ctype_getConjB (c)));
1014 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
1015 return (ctype_isStructorUnion (ctype_realType (c)));
1019 ctype_isRealArray (ctype c)
1021 if (ctype_isConj (c))
1022 return (ctype_isRealArray (ctype_getConjA (c)) ||
1023 ctype_isRealArray (ctype_getConjB (c)));
1024 return (ctype_isArray (ctype_realType (c)));
1028 ctype_isRealAP (ctype c)
1030 if (ctype_isConj (c))
1031 return (ctype_isRealAP (ctype_getConjA (c)) ||
1032 ctype_isRealAP (ctype_getConjB (c)));
1033 return (ctype_isAP (ctype_realType (c)));
1037 ctype_isRealFunction (ctype c)
1039 if (ctype_isConj (c))
1040 return (ctype_isRealFunction (ctype_getConjA (c)) ||
1041 ctype_isRealFunction (ctype_getConjB (c)));
1042 return (ctype_isFunction (ctype_realType (c)));
1046 ctype_isDirectInt (ctype c)
1048 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
1052 ** forceful predicates
1054 ** take *ctype; if its a conjunct, and there is a match replace with match only.
1055 ** if both match, still conjunct
1059 ctype_isForcePred (ctype * c, bool (pred) (ctype))
1061 /*drl bee: pbr */ if (ctype_isConj (*c))
1063 ctype cbr = ctype_getConjA (*c);
1065 /*drl bee: si*/ if ((*pred) (cbr))
1067 if ((*pred) (ctype_getConjB (*c)))
1080 if ((*pred) (cbr = ctype_getConjB (*c)))
1088 return ((*pred) (*c));
1092 ctype_isForceRealNumeric (ctype * c)
1094 return (ctype_isForcePred (c, ctype_isRealNumeric));
1098 ctype_isForceRealInt (ctype * c)
1100 return (ctype_isForcePred (c, ctype_isRealInt));
1104 ctype_isForceRealBool (ctype * c)
1106 return (ctype_isForcePred (c, ctype_isRealBool));
1112 ** save int/char, int/bool, other random conjuncts
1116 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
1118 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
1122 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1130 return (ctype_makeExplicitConj (c1, c2));
1134 return (ctype_makeConj (c1, c2));
1140 ctype_makeExplicitConj (ctype c1, ctype c2)
1142 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1144 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1146 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1148 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1150 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1152 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1156 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1160 static ctype ic = ctype_unknown; /* int | char */
1161 static ctype ib = ctype_unknown; /* int | bool */
1162 static ctype ifl = ctype_unknown; /* int | float */
1163 static ctype ibf = ctype_unknown; /* int | bool | float */
1164 static ctype ibc = ctype_unknown; /* int | bool | char */
1165 static ctype iv = ctype_unknown; /* int | void * */
1166 static ctype ivf = ctype_unknown; /* int | void * | float */
1167 static ctype ivb = ctype_unknown; /* int | void * | bool */
1168 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1169 static ctype cuc = ctype_unknown; /* char | unsigned char */
1172 ctype_recordConj (ctype c)
1176 llassert (ctype_isConj (c));
1178 c1 = ctype_getConjA (c);
1179 c2 = ctype_getConjB (c);
1182 if (c2 == ctype_int && c1 != ctype_int)
1192 if (c1 == ctype_int)
1194 if (c2 == ctype_char)
1196 llassert (ic == ctype_unknown);
1199 else if (c2 == ctype_bool)
1201 llassert (ib == ctype_unknown);
1204 else if (c2 == ctype_float)
1206 llassert (ifl == ctype_unknown);
1209 else if (c2 == CTP_VOID)
1211 llassert (iv == ctype_unknown);
1219 else if (c1 == ib && ib != ctype_unknown)
1221 if (c2 == ctype_float)
1223 llassert (ibf == ctype_unknown);
1226 else if (c2 == ctype_char)
1228 llassert (ibc == ctype_unknown);
1238 if (c2 == ctype_bool)
1240 llassert (ivb == ctype_unknown);
1243 else if (c2 == ctype_float)
1245 llassert (ivf == ctype_unknown);
1255 if (c2 == ctype_bool)
1257 llassert (ivbf == ctype_unknown);
1263 if (c2 == ctype_float)
1265 llassert (ivbf == ctype_unknown);
1269 else if (c1 == ctype_char)
1271 if (c2 == ctype_uchar)
1273 llassert (cuc == ctype_unknown);
1285 ctype_makeConj (ctype c1, ctype c2)
1287 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1289 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1291 if (ctype_isUnknown (c1))
1295 else if (ctype_isUnknown (c2))
1299 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1301 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1302 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1304 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1306 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1307 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1311 if (ctype_isManifestBool (c1))
1316 if (ctype_isManifestBool (c2))
1321 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1323 c1 = ctype_voidPointer;
1326 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1328 c2 = ctype_voidPointer;
1332 ** Ouch, can't do this. unsigned, etc. modifiers might
1333 ** apply to wrong type!
1335 ** if (c2 == ctype_int && c1 != ctype_int)
1346 if (c1 == ctype_int)
1348 if (c2 == ctype_char)
1350 if (ic == ctype_unknown)
1352 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1357 else if (c2 == ctype_bool)
1359 if (ib == ctype_unknown)
1361 ib = cttable_addComplex
1362 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1367 else if (c2 == ctype_float)
1369 if (ifl == ctype_unknown)
1371 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1378 if (c2 == ctype_voidPointer)
1380 if (iv == ctype_unknown)
1382 iv = cttable_addComplex
1383 (ctbase_makeConj (ctype_int,
1392 else if (c1 == ib && ib != ctype_unknown)
1394 if (c2 == ctype_float)
1396 if (ibf == ctype_unknown)
1398 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1403 else if (c2 == ctype_char)
1405 if (ibc == ctype_unknown)
1407 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1419 if (c2 == ctype_bool)
1421 if (ivb == ctype_unknown)
1423 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1428 else if (c2 == ctype_float)
1430 if (ivf == ctype_unknown)
1432 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1444 if (c2 == ctype_bool)
1446 if (ivbf == ctype_unknown)
1448 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1456 if (c2 == ctype_float)
1458 if (ivbf == ctype_unknown)
1460 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1466 else if (c1 == ctype_char)
1468 if (c2 == ctype_uchar)
1470 if (cuc == ctype_unknown)
1472 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1484 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1490 ctype_isConj (ctype c)
1492 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1496 ctype_getConjA (ctype c)
1498 if (!ctype_isConj (c))
1499 llbuglit ("ctype_getConjA: not a conj");
1500 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1504 ctype_getConjB (ctype c)
1506 if (!ctype_isConj (c))
1507 llbuglit ("ctype_getConjB: not a conj");
1508 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1512 ctype_isExplicitConj (ctype c)
1514 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1517 /** << need to fix resolveConj >> **/
1520 ** structs and unions
1524 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1528 DPRINTF (("Creating a struct: %s / %s",
1529 n, uentryList_unparse (f)));
1531 ct = cttable_addComplex (ctbase_createStruct (n, f));
1532 DPRINTF (("ct: %s", ctype_unparse (ct)));
1537 ctype_getFields (ctype c)
1539 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1543 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1547 ret = cttable_addComplex (ctbase_createUnion (n, f));
1554 ** if ctype's are same, definite match.
1555 ** else, need to call ctbase_match.
1557 ** if necessary context can memoize matches
1561 quickMatch (ctype c1, ctype c2)
1570 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1574 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1576 if (quickMatch (c1, c2))
1581 if (ctype_isElips (c1) || ctype_isElips (c2))
1587 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1593 ctype_sameName (ctype c1, ctype c2)
1595 if (quickMatch (c1, c2))
1598 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1602 ctype_almostEqual (ctype c1, ctype c2)
1604 if (ctype_equal (c1, c2))
1610 if (ctype_isUnknown (c1))
1612 return ctype_isUnknown (c2);
1614 else if (ctype_isUnknown (c2))
1620 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1626 ctype_matchDef (ctype c1, ctype c2)
1628 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1630 if (quickMatch (c1, c2))
1633 if (ctype_isElips (c1))
1634 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1636 if (ctype_isElips (c2))
1638 return (ctype_isUnknown (c2));
1642 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1645 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1646 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1647 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1652 bool ctype_match (ctype c1, ctype c2)
1654 if (quickMatch (c1, c2))
1657 if (ctype_isElips (c1))
1658 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1660 if (ctype_isElips (c2))
1661 return (ctype_isUnknown (c2));
1663 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1667 ctype_forceMatch (ctype c1, ctype c2)
1669 if (quickMatch (c1, c2))
1672 if (ctype_isElips (c1))
1673 return (ctype_isElips (c2));
1675 if (ctype_isElips (c2))
1679 /* The call forceMatch may modify the observer params, but, we don't care. */
1680 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1685 ctype_matchArg (ctype c1, ctype c2)
1687 if (quickMatch (c1, c2))
1693 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1698 ** simple ctype_is operations.
1699 ** DO NOT use real type of c, only direct type.
1703 ** ctype_isVoidPointer
1709 ctype_isVoidPointer (ctype c)
1711 if (ctype_isComplex (c))
1713 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1715 if (ctype_isConj (c))
1717 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1718 ctype_isVoidPointer (ctype_getConjB (c)));
1722 return (c == ctype_voidPointer
1723 || (ctype_isRealPointer (c)
1724 && ctype_isVoid (ctype_baseArrayPtr (c))));
1731 ** true for C and LCL pointers
1735 ctype_isPointer (ctype c)
1737 if (ctype_isElips (c)) return FALSE;
1739 if (ctype_isComplex (c))
1741 ctbase ctb = ctype_getCtbaseSafe (c);
1742 bool res = ctbase_isPointer (ctb);
1748 bool res = ctentry_isPointer (ctype_getCtentry (c));
1757 ** true for C and LCL array's
1761 ctype_isArray (ctype c)
1763 if (ctype_isElips (c)) return FALSE;
1765 if (ctype_isComplex (c))
1766 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1768 return (ctentry_isArray (ctype_getCtentry (c)));
1771 bool ctype_isIncompleteArray (ctype c)
1773 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1777 ctype_isArrayPtr (ctype c)
1779 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1783 ctype_typeId (ctype c)
1785 return (ctbase_typeId (ctype_getCtbase (c)));
1789 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1791 llassert (! (ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1793 if (ctype_isUnknown (c))
1795 return message ("? %q", name);
1799 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1804 ctype_unparse (ctype c)
1806 if (ctype_isElips (c))
1808 return cstring_makeLiteralTemp ("...");
1810 else if (ctype_isMissingParamsMarker (c))
1812 return cstring_makeLiteralTemp ("-");
1814 else if (ctype_isUnknown (c))
1816 return cstring_makeLiteralTemp ("?");
1821 return (ctentry_doUnparse (ctype_getCtentry (c)));
1827 ctype_unparseSafe (ctype c)
1829 if (ctype_isElips (c))
1831 return cstring_makeLiteralTemp ("...");
1833 else if (ctype_isMissingParamsMarker (c))
1835 return cstring_makeLiteralTemp ("-");
1841 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1843 ctentry cte = ctype_getCtentry (c);
1845 if (cstring_isDefined (cte->unparse))
1847 return (cte->unparse);
1851 ret = message ("[%d]", (int) c);
1852 cstring_markOwned (ret);
1858 ctype_unparseDeep (ctype c)
1860 if (ctype_isElips (c))
1862 return cstring_makeLiteralTemp ("...");
1864 if (ctype_isMissingParamsMarker (c))
1866 return cstring_makeLiteralTemp ("-");
1869 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1873 ctype_undump (char **c)
1875 return ((ctype) reader_getInt (c)); /* check its valid? */
1879 ctype_dump (ctype c)
1881 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1885 /* Handle invalid types in a kludgey way. */
1886 return (message ("0"));
1891 cstring tname = usymtab_getTypeEntryName
1892 (usymtab_convertId (ctype_typeId (c)));
1894 if (cstring_equal (tname, context_getBoolName ()))
1896 cstring_free (tname);
1897 return (message ("%d", ctype_bool));
1900 cstring_free (tname);
1903 DPRINTF (("Returning: %d", c));
1904 return (message ("%d", c));
1908 ctype_getBaseType (ctype c)
1910 ctentry cte = ctype_getCtentry (c);
1912 switch (ctentry_getKind (cte))
1920 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1923 ctbase ctb = cte->ctbase;
1925 if (ctbase_isDefined (ctb))
1944 return (ctype_getBaseType (ctb->contents.base));
1946 return (ctype_getBaseType (ctb->contents.farray->base));
1947 case CT_CONJ: /* base type of A conj branch? */
1948 return (ctype_getBaseType (ctb->contents.conj->a));
1950 /*@noaccess ctbase@*/
1958 llbuglit ("ctype_newBase: bad case");
1960 llcontbuglit ("ctype_getBaseType: unreachable code");
1961 return ((ctype)NULL);
1965 ctype_adjustPointers (int np, ctype c)
1968 if (ctype_isFunction (c))
1970 c = ctype_makeParamsFunction
1971 (ctype_adjustPointers (np, ctype_getReturnType (c)),
1972 uentryList_copy (ctype_argsFunction (c)));
1976 /* fix this should not use getBaseType ??? */
1977 ctype cb = ctype_getBaseType (c);
1981 cb = ctype_makePointer (cb);
1984 c = ctype_newBase (c, cb);
1992 ctype_elist (ctype c)
1994 return (ctbase_elist (ctype_getCtbase (c)));
1998 ctype_isFirstVoid (ctype c)
2000 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
2004 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
2006 return (cttable_addComplex (ctbase_createEnum (tag, el)));
2010 ctype_isEnum (ctype c)
2012 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
2016 ctype_enumTag (ctype c)
2018 llassert (ctype_isEnum (c));
2020 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
2024 ctype_isStruct (ctype c)
2026 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
2030 ctype_isUnion (ctype c)
2032 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
2036 ctype_resolveNumerics (ctype c1, ctype c2)
2039 ** returns longest type of c1 and c2
2042 if (c1 == c2) return c1;
2044 c1 = ctype_realType (c1);
2045 c2 = ctype_realType (c2);
2047 if (ctype_isEnum (c1)) c1 = ctype_unknown;
2048 if (ctype_isEnum (c2)) c2 = ctype_int;
2050 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
2052 /* 2001-06-08: This fix provided by Jim Zelenka. */
2053 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
2054 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
2056 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
2057 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
2058 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
2059 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
2061 /* 2001-06-08: This fix provided by Jim Zelenka. */
2062 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
2064 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
2066 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
2067 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
2069 if (ctype_isKnown (c1)) return c1;
2074 ctype_isStructorUnion (ctype c)
2076 return (ctype_isStruct (c) || ctype_isUnion (c));
2080 ctype_fixArrayPtr (ctype c)
2082 if (ctype_isArray (c))
2084 return (ctype_makePointer (ctype_baseArrayPtr (c)));
2091 ** createUnnamedStruct/Union
2093 ** check if it corresponds to an existing LCL-specified unnamed struct
2094 ** otherwise, give it a new tag
2098 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
2100 ctype ret = usymtab_structFieldsType (f);
2102 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
2104 if (ctype_isDefined (ret))
2106 uentryList_free (f);
2111 cstring ft = fakeTag ();
2112 ctype ct = ctype_createStruct (cstring_copy (ft), f);
2113 uentry ue = uentry_makeStructTagLoc (ft, ct);
2115 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2116 ue = usymtab_supGlobalEntryReturn (ue);
2117 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2125 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2127 ctype ret = usymtab_unionFieldsType (f);
2129 if (ctype_isDefined (ret))
2131 uentryList_free (f);
2136 cstring ft = fakeTag ();
2137 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2138 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2140 usymtab_supGlobalEntry (ue);
2147 ctype_isUnnamedSU (ctype c)
2151 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2160 ctype_createForwardStruct (cstring n)
2162 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2163 ctype ct = usymtab_supForwardTypeEntry (ue);
2170 ctype_createForwardUnion (cstring n)
2172 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2173 ctype ct = usymtab_supForwardTypeEntry (ue);
2180 ctype_removePointers (ctype c)
2184 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2187 c = ctype_baseArrayPtr (c);
2188 llassert (c != oldc);
2194 bool ctype_isMutable (ctype t)
2198 return (uentry_isMutableDatatype
2199 (usymtab_getTypeEntry (ctype_typeId (t))));
2203 return (ctype_isPointer (ctype_realType (t)));
2204 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2208 bool ctype_isRefCounted (ctype t)
2212 return (uentry_isRefCountedDatatype
2213 (usymtab_getTypeEntry (ctype_typeId (t))));
2219 bool ctype_isVisiblySharable (ctype t)
2221 if (ctype_isUnknown (t)) return TRUE;
2223 if (ctype_isConj (t))
2225 return (ctype_isVisiblySharable (ctype_getConjA (t))
2226 || ctype_isVisiblySharable (ctype_getConjB (t)));
2229 if (ctype_isMutable (t))
2233 ctype rt = ctype_realType (t);
2241 return ctype_isVisiblySharable (rt);
2255 /* Replaced by ctype_isMutable (more sensible) */
2256 bool ctype_canAlias (ctype ct)
2258 /* can ct refer to memory locations?
2259 ** ==> a pointer or a mutable abstract type
2263 ctype tr = ctype_realType (ct);
2265 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2270 ** c1 is the dominant type; c2 is the modifier type
2272 ** eg. double + long int => long double
2275 ctype ctype_combine (ctype dominant, ctype modifier)
2277 DPRINTF (("Combine: %s + %s",
2278 ctype_unparse (dominant),
2279 ctype_unparse (modifier)));
2281 if (ctype_isConj (dominant))
2285 if (ctype_isExplicitConj (dominant))
2287 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2289 ctype_getConjB (dominant));
2293 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2295 ctype_getConjB (dominant));
2301 if (ctype_isUnknown (modifier))
2305 else if (ctype_isUnknown (dominant))
2311 if (ctype_isEnum (dominant)) dominant = ctype_int;
2312 if (ctype_isEnum (modifier)) modifier = ctype_int;
2314 if (modifier == ctype_uint)
2316 if (dominant == ctype_int) return ctype_uint;
2317 if (dominant == ctype_lint) return ctype_ulint;
2318 if (dominant == ctype_sint) return ctype_usint;
2319 if (dominant == ctype_char) return ctype_uchar;
2321 /* evs 2000-07-28: added this line */
2322 if (dominant == ctype_llint) return ctype_ullint;
2324 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2326 voptgenerror (FLG_DUPLICATEQUALS,
2327 message ("Duplicate unsigned qualifier"),
2334 voptgenerror (FLG_DUPLICATEQUALS,
2335 message ("Type qualifier unsigned used with %s",
2336 ctype_unparse (dominant)),
2342 else if (modifier == ctype_llint)
2344 if (dominant == ctype_int)
2349 voptgenerror (FLG_DUPLICATEQUALS,
2350 message ("Duplicate long qualifier on non-int"),
2353 else if (modifier == ctype_lint)
2355 if (dominant == ctype_int) return ctype_lint;
2356 if (dominant == ctype_uint) return ctype_ulint;
2357 if (dominant == ctype_double) return ctype_ldouble;
2359 if (dominant == ctype_lint || dominant == ctype_ulint
2360 || dominant == ctype_sint || dominant == ctype_usint
2361 || dominant == ctype_ldouble)
2363 if (dominant == ctype_lint)
2365 /* long long not supported by ANSI */
2370 if (dominant == ctype_ulint)
2372 /* unsigned long long not supported by ANSI */
2373 return ctype_ullint;
2377 if (dominant == ctype_sint || dominant == ctype_usint)
2379 if (!context_getFlag (FLG_IGNOREQUALS))
2381 llerrorlit (FLG_SYNTAX,
2382 "Contradictory long and short type qualifiers");
2387 voptgenerror (FLG_DUPLICATEQUALS,
2388 message ("Duplicate long qualifier"),
2395 else if (modifier == ctype_sint)
2397 if (dominant == ctype_int) return ctype_sint;
2398 if (dominant == ctype_uint) return ctype_usint;
2400 if (dominant == ctype_sint || dominant == ctype_usint)
2402 voptgenerror (FLG_DUPLICATEQUALS,
2403 message ("Duplicate short qualifier"),
2407 else if (dominant == ctype_lint)
2409 if (!context_getFlag (FLG_IGNOREQUALS))
2411 llerrorlit (FLG_SYNTAX,
2412 "Contradictory long and short type qualifiers");
2418 else if (dominant == ctype_llint)
2420 if (!context_getFlag (FLG_IGNOREQUALS))
2422 llerrorlit (FLG_SYNTAX,
2423 "Contradictory long long and short type qualifiers");
2431 if (!context_getFlag (FLG_IGNOREQUALS))
2433 llerror (FLG_SYNTAX,
2434 message ("Type qualifier short used with %s",
2435 ctype_unparse (dominant)));
2441 else if (modifier == ctype_ulint)
2443 if (dominant == ctype_int) return modifier;
2445 if (dominant == ctype_lint || dominant == ctype_ulint)
2447 voptgenerror (FLG_DUPLICATEQUALS,
2448 message ("Duplicate long qualifier"),
2454 if (dominant == ctype_uint || dominant == ctype_usint)
2456 voptgenerror (FLG_DUPLICATEQUALS,
2457 message ("Duplicate unsigned qualifier"),
2463 if (dominant == ctype_sint || dominant == ctype_usint)
2465 if (!context_getFlag (FLG_IGNOREQUALS))
2467 llerrorlit (FLG_SYNTAX,
2468 "Contradictory long and short type qualifiers");
2474 if (!context_getFlag (FLG_IGNOREQUALS))
2476 llerror (FLG_SYNTAX,
2477 message ("Type qualifiers unsigned long used with %s",
2478 ctype_unparse (dominant)));
2483 else if (modifier == ctype_usint)
2485 if (dominant == ctype_int) return modifier;
2487 if (dominant == ctype_sint || dominant == ctype_usint)
2489 voptgenerror (FLG_DUPLICATEQUALS,
2490 message ("Duplicate short qualifier"),
2495 if (dominant == ctype_uint)
2497 voptgenerror (FLG_DUPLICATEQUALS,
2498 message ("Duplicate unsigned qualifier"),
2504 if (dominant == ctype_lint || dominant == ctype_ulint
2505 || dominant == ctype_llint)
2507 if (!context_getFlag (FLG_IGNOREQUALS))
2509 llerrorlit (FLG_SYNTAX,
2510 "Contradictory long and short type qualifiers");
2516 if (!context_getFlag (FLG_IGNOREQUALS))
2518 llerror (FLG_SYNTAX,
2519 message ("Type qualifiers unsigned short used with %s",
2520 ctype_unparse (dominant)));
2534 ctype ctype_resolve (ctype c)
2536 if (ctype_isUnknown (c)) return ctype_int;
2540 ctype ctype_fromQual (qual q)
2542 if (qual_isSigned (q)) return ctype_int;
2543 if (qual_isUnsigned (q)) return ctype_uint;
2544 if (qual_isLong (q)) return ctype_lint;
2545 if (qual_isShort (q)) return ctype_sint;
2547 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2548 return ctype_unknown;
2552 ctype_isAnyFloat (ctype c)
2554 return (cprim_isAnyReal (ctype_toCprim (c)));
2558 ctype_isUnsigned (ctype c)
2560 if (ctype_isConj (c))
2561 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2562 ctype_isUnsigned (ctype_getConjB (c)));
2564 return (c == ctype_uint || c == ctype_uchar
2565 || c == ctype_usint || c == ctype_ulint
2566 || c == ctype_ullint
2567 || c == ctype_unsignedintegral);
2572 ctype_isLongLong (ctype c)
2574 if (ctype_isConj (c))
2575 return (ctype_isLongLong (ctype_getConjA (c)) ||
2576 ctype_isLongLong (ctype_getConjB (c)));
2578 return (c == ctype_llint || c == ctype_ullint);
2583 ctype_isLong (ctype c)
2585 if (ctype_isConj (c))
2586 return (ctype_isLong (ctype_getConjA (c)) ||
2587 ctype_isLong (ctype_getConjB (c)));
2589 return (c == ctype_lint || c == ctype_ulint);
2593 ctype_isShort (ctype c)
2595 if (ctype_isConj (c))
2596 return (ctype_isShort (ctype_getConjA (c)) ||
2597 ctype_isShort (ctype_getConjB (c)));
2599 return (c == ctype_sint || c == ctype_usint);
2603 ctype_isStackAllocated (ctype c)
2605 ctype ct = ctype_realType (c);
2607 if (ctype_isConj (ct))
2608 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2609 ctype_isStackAllocated (ctype_getConjB (ct)));
2611 return (ctype_isArray (c) || ctype_isSU (c));
2614 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2616 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2619 static bool ctype_isLonger (ctype c1, ctype c2)
2621 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2622 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2623 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2624 || (ctype_isLong (c1)
2625 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2626 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2630 ctype_widest (ctype c1, ctype c2)
2632 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2642 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2645 if (c >= 0 && c < cttab.size)
2647 return (cttab.entries[c]->ctbase);
2651 if (c == ctype_unknown)
2652 llbuglit ("ctype_getCtbase: ctype unknown");
2653 if (c == ctype_undefined)
2654 llbuglit ("ctype_getCtbase: ctype undefined");
2656 llbuglit ("ctype_getCtbase: ctype dne");
2657 if (c == ctype_elipsMarker)
2658 llbuglit ("ctype_getCtbase: elips marker");
2660 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2667 static /*@notnull@*/ /*@observer@*/ ctbase
2668 ctype_getCtbaseSafe (ctype c)
2670 ctbase res = ctype_getCtbase (c);
2672 llassert (ctbase_isDefined (res));
2681 ctype_getCtentry (ctype c)
2683 static /*@only@*/ ctentry errorEntry = NULL;
2685 if (cttab.size == 0)
2687 if (errorEntry == NULL)
2689 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2696 if (c >= CTK_PLAIN && c < cttab.size)
2698 return (cttab.entries[c]);
2700 else if (c == CTK_UNKNOWN)
2701 llcontbuglit ("ctype_getCtentry: ctype unknown");
2702 else if (c == CTK_INVALID)
2703 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2704 else if (c == CTK_DNE)
2705 llcontbuglit ("ctype_getCtentry: ctype dne");
2706 else if (c == CTK_ELIPS)
2707 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2708 else if (c == CTK_MISSINGPARAMS)
2709 llcontbuglit ("ctype_getCtentry: ctype missing params");
2711 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2713 return (cttab.entries[ctype_unknown]);
2718 bool ctype_isFixedArray (ctype c)
2720 if (ctype_isElips (c)) return FALSE;
2722 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
2727 /* requires that the type is an fixed array */
2728 /* return the size of the array */
2730 long int ctype_getArraySize (ctype c)
2736 llassert (ctype_isFixedArray (c));
2738 ctb = ctype_getCtbaseSafe(c);
2739 size = ctbase_getArraySize (ctb);
2741 DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",