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),
339 res = ctype_makeFixedArray (c, size);
346 ctype_makeArray (ctype c)
348 ctentry cte = ctype_getCtentry (c);
349 ctype clp = ctentry_getArray (cte);
351 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
353 ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
354 ctentry_setArray (cte, cnew);
362 ** requires c is a pointer of array
366 ctype_baseArrayPtr (ctype c)
368 ctentry cte = ctype_getCtentry (ctype_realType (c));
370 if (ctype_isConj (c))
372 if (ctype_isAP (ctype_getConjA (c)))
374 if (ctype_isAP (ctype_getConjB (c)))
376 return (ctype_makeConj (ctype_baseArrayPtr (ctype_getConjA (c)),
377 ctype_baseArrayPtr (ctype_getConjB (c))));
381 return (ctype_baseArrayPtr (ctype_getConjA (c)));
386 return (ctype_baseArrayPtr (ctype_getConjB (c)));
389 else if (ctype_isInt (c)) /* could be NULL */
391 return ctype_unknown;
395 ctype clp = ctentry_getBase (cte);
397 if (ctype_isBroken (clp))
399 llbuglit ("ctype_baseArrayPtr: bogus ctype");
411 ctype_makeWideString ()
413 static ctype res = ctype_unknown;
415 if (ctype_isUnknown (res))
419 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
421 wchart = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t")));
428 res = ctype_makePointer (wchart);
435 ctype_isWideString (ctype c)
437 if (ctype_isPointer (c))
439 ctype ct = ctype_baseArrayPtr (c);
441 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
443 return (ct == uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t"))));
457 ctype_getReturnType (ctype c)
459 if (ctype_isUnknown (c))
461 return ctype_unknown;
464 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
468 ** must be a shared pointer
471 /*@observer@*/ uentryList
472 ctype_argsFunction (ctype c)
474 if (ctype_isUnknown (c))
476 return uentryList_undefined;
479 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
483 ** Returns type with base type p and compound types from c.
485 ** i.e., c = char *[]; p = int
490 ctype_newBase (ctype c, ctype p)
492 return (ctbase_newBase (c, p));
496 ctype_sameAltTypes (ctype c1, ctype c2)
501 llassert (ctype_isConj (c1) && ctype_isConj (c2));
503 c1a = ctype_getConjA (c1);
504 c2a = ctype_getConjA (c2);
506 c1b = ctype_getConjB (c1);
507 c2b = ctype_getConjB (c2);
509 if (ctype_compare (c1a, c2a) == 0)
511 if (ctype_compare (c1b, c2b) == 0)
517 if (ctype_isConj (c1b) && ctype_isConj (c2b))
519 return ctype_sameAltTypes (c1b, c2b);
529 if (ctype_compare (c1a, c2b) == 0)
531 if (ctype_compare (c1b, c2a) == 0)
537 if (ctype_isConj (c1b) && ctype_isConj (c2a))
539 return ctype_sameAltTypes (c1b, c2a);
555 ctype_compare (ctype c1, ctype c2)
560 if (ctype_isUnknown (c1))
562 if (ctype_isUnknown (c2))
572 if (ctype_isUnknown (c2))
577 /* Can't get entries for special ctypes (elips marker) */
579 if (ctype_isElips (c1) || ctype_isElips (c2)
580 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
581 return int_compare (c1, c2);
584 ce1 = ctype_getCtentry (c1);
585 ce2 = ctype_getCtentry (c2);
587 if (ctentry_isComplex (ce1))
589 if (ctentry_isComplex (ce2))
591 return (ctbase_compare (ctype_getCtbase (c1),
592 ctype_getCtbase (c2), FALSE));
599 else if (ctentry_isComplex (ce2))
605 return (int_compare (c1, c2));
614 ** makeFunction: pointer to function returning base
618 ctype_makeParamsFunction (ctype base, /*@only@*/ uentryList p)
620 uentryList_fixImpParams (p);
621 return (ctype_makeFunction (base, p));
625 ctype_makeNFParamsFunction (ctype base, /*@only@*/ uentryList p)
627 uentryList_fixImpParams (p);
628 return (ctbase_makeNFFunction (base, p));
632 ctype_makeFunction (ctype base, /*@only@*/ uentryList p)
635 ret = ctbase_makeFunction (base, p);
639 ctype ctype_expectFunction (ctype c)
641 /* handle parenthesized declarations */
645 c = ctype_makePointer (c);
648 return (cttable_addComplex (ctbase_expectFunction (c)));
652 ** makeRealFunction: function returning base
655 ctype ctype_makeRawFunction (ctype base, uentryList p)
657 return (cttable_addComplex (ctbase_makeLiveFunction (base, p)));
665 **** this is very poorly defined
667 **** need to unify function/function pointer meaning
671 ctype_isFunction (ctype c)
673 if (ctype_isKnown (c) && ctype_isDefined (c))
675 return (ctbase_isFunction (ctype_getCtbase (c)));
684 ctype_isExpFcn (ctype c)
686 return (ctype_isKnown (c) && ctbase_isExpFcn (ctype_getCtbase (c)));
690 ctype_isVoid (ctype c)
692 return (c == CTX_VOID);
696 ctype_isArbitraryIntegral (ctype c)
698 ctype cr = ctype_realType (c);
700 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
701 || cr == ctype_signedintegral);
705 ctype_isUnsignedIntegral (ctype c)
707 ctype cr = ctype_realType (c);
709 return (cr == ctype_unsignedintegral);
713 ctype_isSignedIntegral (ctype c)
715 ctype cr = ctype_realType (c);
717 return (cr == ctype_signedintegral);
721 ctype_isInt (ctype c)
723 cprim cp = ctype_toCprim (c);
725 return (c == ctype_unknown || cprim_isAnyInt (cp)
726 || (cprim_isAnyChar (cp) && context_msgCharInt ())
727 || (c == ctype_bool && context_msgBoolInt ())
728 || (ctype_isEnum (c) && context_msgEnumInt ()));
732 ctype_isRegularInt (ctype c)
734 cprim cp = ctype_toCprim (c);
736 return (c == ctype_unknown
737 || cprim_closeEnough (cprim_int, cp)
738 || (cprim_isAnyChar (cp) && context_msgCharInt ())
739 || (c == ctype_bool && context_msgBoolInt ())
740 || (ctype_isEnum (c) && context_msgEnumInt ()));
744 ctype_isString (ctype c)
746 return (c == ctype_string
747 || (ctype_isPointer (c)
748 && ctype_isChar (ctype_baseArrayPtr (c))));
752 ctype_isChar (ctype c)
754 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
755 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
759 ctype_isUnsignedChar (ctype c)
761 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
765 ctype_isSignedChar (ctype c)
767 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
771 ** Returns true if c matches the name -booltype <bool>
775 ctype_isManifestBool (ctype c)
778 ** Changed the meaning of ctype_isBool - evs 2000-07-24
779 ** The old meaning was very convoluted!
782 ** c == CTX_BOOL - its a direct bool
783 ** c is a user/abstract type matching the bool name
784 ** (should never occur?)
787 if (ctype_isDirectBool (c)) {
789 } else if (ctype_isUA (c)) {
790 return ctype_isUserBool (c);
797 ctype_isBool (ctype c)
800 ** Changed the meaning of ctype_isBool - evs 2000-07-24
801 ** The old meaning was very convoluted!
804 ** its a manifest bool
805 ** +boolint and ctype_isInt (c)
808 if (ctype_isManifestBool (c)) {
810 } else if (context_msgBoolInt ()) {
811 return ctype_isInt (c);
817 if (context_getFlag (FLG_ABSTRACTBOOL))
819 if (typeId_isInvalid (boolType))
821 boolType = usymtab_getTypeId (context_getBoolName ());
824 if (context_hasAccess (boolType))
826 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
827 || (context_msgBoolInt ()
829 || (c == CTX_CHAR && context_msgCharInt ()))))
834 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
835 || (context_msgBoolInt ()
836 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
841 ctype_isDirectBool (ctype c)
843 return (c == CTX_BOOL);
847 ctype_isReal (ctype c)
849 return (cprim_isAnyReal (ctype_toCprim (c)));
853 ctype_isFloat (ctype c)
855 return (c == ctype_float);
859 ctype_isDouble (ctype c)
861 return (c == ctype_double || c == ctype_ldouble);
865 ctype_isSigned (ctype c)
867 return (!ctype_isUnsigned (c));
871 ctype_isNumeric (ctype c)
873 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c)
874 /* evans 2001-10-05: added this: */
875 || ctype_isArbitraryIntegral (c));
882 ** work on actual type in current context
886 ctype_isRealNumeric (ctype c)
888 if (ctype_isPlain (c))
889 return (ctype_isNumeric (ctype_realType (c)));
890 if (ctype_isConj (c))
891 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
892 ctype_isRealNumeric (ctype_getConjB (c)));
898 ctype_isRealInt (ctype c)
900 if (ctype_isPlain (c))
901 return (ctype_isInt (ctype_realType (c)));
902 else if (ctype_isConj (c))
903 return (ctype_isRealInt (ctype_getConjA (c)) ||
904 ctype_isRealInt (ctype_getConjB (c)));
907 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
913 ctype_isRealVoid (ctype c)
915 if (ctype_isPlain (c))
917 return (ctype_isVoid (ctype_realType (c)));
919 else if (ctype_isConj (c))
921 return (ctype_isRealVoid (ctype_getConjA (c)) ||
922 ctype_isRealVoid (ctype_getConjB (c)));
931 ctype_isRealBool (ctype c)
933 if (ctype_isPlain (c))
935 return (ctype_isBool (ctype_realishType (c)));
937 else if (ctype_isConj (c))
939 return (ctype_isRealBool (ctype_getConjA (c)) ||
940 ctype_isRealBool (ctype_getConjB (c)));
949 ctype_isRealPointer (ctype c)
951 if (ctype_isConj (c))
952 return (ctype_isRealPointer (ctype_getConjA (c)) ||
953 ctype_isRealPointer (ctype_getConjB (c)));
954 return (ctype_isPointer (ctype_realType (c)));
958 ctype_isRealSU (ctype c)
960 if (ctype_isConj (c))
962 return (ctype_isRealSU (ctype_getConjA (c)) ||
963 ctype_isRealSU (ctype_getConjB (c)));
966 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
967 return (ctype_isStructorUnion (ctype_realType (c)));
971 ctype_isRealArray (ctype c)
973 if (ctype_isConj (c))
974 return (ctype_isRealArray (ctype_getConjA (c)) ||
975 ctype_isRealArray (ctype_getConjB (c)));
976 return (ctype_isArray (ctype_realType (c)));
980 ctype_isRealAP (ctype c)
982 if (ctype_isConj (c))
983 return (ctype_isRealAP (ctype_getConjA (c)) ||
984 ctype_isRealAP (ctype_getConjB (c)));
985 return (ctype_isAP (ctype_realType (c)));
989 ctype_isRealFunction (ctype c)
991 if (ctype_isConj (c))
992 return (ctype_isRealFunction (ctype_getConjA (c)) ||
993 ctype_isRealFunction (ctype_getConjB (c)));
994 return (ctype_isFunction (ctype_realType (c)));
998 ctype_isDirectInt (ctype c)
1000 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
1004 ** forceful predicates
1006 ** take *ctype; if its a conjunct, and there is a match replace with match only.
1007 ** if both match, still conjunct
1011 ctype_isForcePred (ctype * c, bool (pred) (ctype))
1013 /*drl bee: pbr */ if (ctype_isConj (*c))
1015 ctype cbr = ctype_getConjA (*c);
1017 /*drl bee: si*/ if ((*pred) (cbr))
1019 if ((*pred) (ctype_getConjB (*c)))
1032 if ((*pred) (cbr = ctype_getConjB (*c)))
1040 return ((*pred) (*c));
1044 ctype_isForceRealNumeric (ctype * c)
1046 return (ctype_isForcePred (c, ctype_isRealNumeric));
1050 ctype_isForceRealInt (ctype * c)
1052 return (ctype_isForcePred (c, ctype_isRealInt));
1056 ctype_isForceRealBool (ctype * c)
1058 return (ctype_isForcePred (c, ctype_isRealBool));
1064 ** save int/char, int/bool, other random conjuncts
1068 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
1070 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
1074 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1082 return (ctype_makeExplicitConj (c1, c2));
1086 return (ctype_makeConj (c1, c2));
1092 ctype_makeExplicitConj (ctype c1, ctype c2)
1094 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1096 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1098 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1100 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1102 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1104 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1108 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1112 static ctype ic = ctype_unknown; /* int | char */
1113 static ctype ib = ctype_unknown; /* int | bool */
1114 static ctype ifl = ctype_unknown; /* int | float */
1115 static ctype ibf = ctype_unknown; /* int | bool | float */
1116 static ctype ibc = ctype_unknown; /* int | bool | char */
1117 static ctype iv = ctype_unknown; /* int | void * */
1118 static ctype ivf = ctype_unknown; /* int | void * | float */
1119 static ctype ivb = ctype_unknown; /* int | void * | bool */
1120 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1121 static ctype cuc = ctype_unknown; /* char | unsigned char */
1124 ctype_recordConj (ctype c)
1128 llassert (ctype_isConj (c));
1130 c1 = ctype_getConjA (c);
1131 c2 = ctype_getConjB (c);
1134 if (c2 == ctype_int && c1 != ctype_int)
1144 if (c1 == ctype_int)
1146 if (c2 == ctype_char)
1148 llassert (ic == ctype_unknown);
1151 else if (c2 == ctype_bool)
1153 llassert (ib == ctype_unknown);
1156 else if (c2 == ctype_float)
1158 llassert (ifl == ctype_unknown);
1161 else if (c2 == CTP_VOID)
1163 llassert (iv == ctype_unknown);
1171 else if (c1 == ib && ib != ctype_unknown)
1173 if (c2 == ctype_float)
1175 llassert (ibf == ctype_unknown);
1178 else if (c2 == ctype_char)
1180 llassert (ibc == ctype_unknown);
1190 if (c2 == ctype_bool)
1192 llassert (ivb == ctype_unknown);
1195 else if (c2 == ctype_float)
1197 llassert (ivf == ctype_unknown);
1207 if (c2 == ctype_bool)
1209 llassert (ivbf == ctype_unknown);
1215 if (c2 == ctype_float)
1217 llassert (ivbf == ctype_unknown);
1221 else if (c1 == ctype_char)
1223 if (c2 == ctype_uchar)
1225 llassert (cuc == ctype_unknown);
1237 ctype_makeConj (ctype c1, ctype c2)
1239 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1241 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1243 if (ctype_isUnknown (c1))
1247 else if (ctype_isUnknown (c2))
1251 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1253 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1254 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1256 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1258 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1259 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1263 if (ctype_isManifestBool (c1))
1268 if (ctype_isManifestBool (c2))
1273 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1275 c1 = ctype_voidPointer;
1278 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1280 c2 = ctype_voidPointer;
1284 ** Ouch, can't do this. unsigned, etc. modifiers might
1285 ** apply to wrong type!
1287 ** if (c2 == ctype_int && c1 != ctype_int)
1298 if (c1 == ctype_int)
1300 if (c2 == ctype_char)
1302 if (ic == ctype_unknown)
1304 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1309 else if (c2 == ctype_bool)
1311 if (ib == ctype_unknown)
1313 ib = cttable_addComplex
1314 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1319 else if (c2 == ctype_float)
1321 if (ifl == ctype_unknown)
1323 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1330 if (c2 == ctype_voidPointer)
1332 if (iv == ctype_unknown)
1334 iv = cttable_addComplex
1335 (ctbase_makeConj (ctype_int,
1344 else if (c1 == ib && ib != ctype_unknown)
1346 if (c2 == ctype_float)
1348 if (ibf == ctype_unknown)
1350 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1355 else if (c2 == ctype_char)
1357 if (ibc == ctype_unknown)
1359 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1371 if (c2 == ctype_bool)
1373 if (ivb == ctype_unknown)
1375 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1380 else if (c2 == ctype_float)
1382 if (ivf == ctype_unknown)
1384 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1396 if (c2 == ctype_bool)
1398 if (ivbf == ctype_unknown)
1400 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1408 if (c2 == ctype_float)
1410 if (ivbf == ctype_unknown)
1412 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1418 else if (c1 == ctype_char)
1420 if (c2 == ctype_uchar)
1422 if (cuc == ctype_unknown)
1424 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1436 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1442 ctype_isConj (ctype c)
1444 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1448 ctype_getConjA (ctype c)
1450 if (!ctype_isConj (c))
1451 llbuglit ("ctype_getConjA: not a conj");
1452 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1456 ctype_getConjB (ctype c)
1458 if (!ctype_isConj (c))
1459 llbuglit ("ctype_getConjB: not a conj");
1460 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1464 ctype_isExplicitConj (ctype c)
1466 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1469 /** << need to fix resolveConj >> **/
1472 ** structs and unions
1476 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1480 DPRINTF (("Creating a struct: %s / %s",
1481 n, uentryList_unparse (f)));
1483 ct = cttable_addComplex (ctbase_createStruct (n, f));
1484 DPRINTF (("ct: %s", ctype_unparse (ct)));
1489 ctype_getFields (ctype c)
1491 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1495 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1499 ret = cttable_addComplex (ctbase_createUnion (n, f));
1506 ** if ctype's are same, definite match.
1507 ** else, need to call ctbase_match.
1509 ** if necessary context can memoize matches
1513 quickMatch (ctype c1, ctype c2)
1522 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1526 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1528 if (quickMatch (c1, c2))
1533 if (ctype_isElips (c1) || ctype_isElips (c2))
1539 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1545 ctype_sameName (ctype c1, ctype c2)
1547 if (quickMatch (c1, c2))
1550 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1554 ctype_almostEqual (ctype c1, ctype c2)
1556 if (ctype_equal (c1, c2))
1562 if (ctype_isUnknown (c1))
1564 return ctype_isUnknown (c2);
1566 else if (ctype_isUnknown (c2))
1572 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1578 ctype_matchDef (ctype c1, ctype c2)
1580 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1582 if (quickMatch (c1, c2))
1585 if (ctype_isElips (c1))
1586 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1588 if (ctype_isElips (c2))
1590 return (ctype_isUnknown (c2));
1594 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1597 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1598 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1599 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1604 bool ctype_match (ctype c1, ctype c2)
1606 if (quickMatch (c1, c2))
1609 if (ctype_isElips (c1))
1610 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1612 if (ctype_isElips (c2))
1613 return (ctype_isUnknown (c2));
1615 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1619 ctype_forceMatch (ctype c1, ctype c2)
1621 if (quickMatch (c1, c2))
1624 if (ctype_isElips (c1))
1625 return (ctype_isElips (c2));
1627 if (ctype_isElips (c2))
1631 /* The call forceMatch may modify the observer params, but, we don't care. */
1632 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1637 ctype_matchArg (ctype c1, ctype c2)
1639 if (quickMatch (c1, c2))
1645 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1650 ** simple ctype_is operations.
1651 ** DO NOT use real type of c, only direct type.
1655 ** ctype_isVoidPointer
1661 ctype_isVoidPointer (ctype c)
1663 if (ctype_isComplex (c))
1665 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1667 if (ctype_isConj (c))
1669 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1670 ctype_isVoidPointer (ctype_getConjB (c)));
1674 return (c == ctype_voidPointer
1675 || (ctype_isRealPointer (c)
1676 && ctype_isVoid (ctype_baseArrayPtr (c))));
1683 ** true for C and LCL pointers
1687 ctype_isPointer (ctype c)
1689 if (ctype_isElips (c)) return FALSE;
1691 if (ctype_isComplex (c))
1693 ctbase ctb = ctype_getCtbaseSafe (c);
1694 bool res = ctbase_isPointer (ctb);
1700 bool res = ctentry_isPointer (ctype_getCtentry (c));
1709 ** true for C and LCL array's
1713 ctype_isArray (ctype c)
1715 if (ctype_isElips (c)) return FALSE;
1717 if (ctype_isComplex (c))
1718 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1720 return (ctentry_isArray (ctype_getCtentry (c)));
1723 bool ctype_isIncompleteArray (ctype c)
1725 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1729 ctype_isArrayPtr (ctype c)
1731 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1735 ctype_typeId (ctype c)
1737 return (ctbase_typeId (ctype_getCtbase (c)));
1741 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1743 llassert (! (ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1745 if (ctype_isUnknown (c))
1747 return message ("? %q", name);
1751 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1756 ctype_unparse (ctype c)
1758 if (ctype_isElips (c))
1760 return cstring_makeLiteralTemp ("...");
1762 else if (ctype_isMissingParamsMarker (c))
1764 return cstring_makeLiteralTemp ("-");
1766 else if (ctype_isUnknown (c))
1768 return cstring_makeLiteralTemp ("?");
1773 return (ctentry_doUnparse (ctype_getCtentry (c)));
1779 ctype_unparseSafe (ctype c)
1781 if (ctype_isElips (c))
1783 return cstring_makeLiteralTemp ("...");
1785 else if (ctype_isMissingParamsMarker (c))
1787 return cstring_makeLiteralTemp ("-");
1793 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1795 ctentry cte = ctype_getCtentry (c);
1797 if (cstring_isDefined (cte->unparse))
1799 return (cte->unparse);
1803 ret = message ("[%d]", (int) c);
1804 cstring_markOwned (ret);
1810 ctype_unparseDeep (ctype c)
1812 if (ctype_isElips (c))
1814 return cstring_makeLiteralTemp ("...");
1816 if (ctype_isMissingParamsMarker (c))
1818 return cstring_makeLiteralTemp ("-");
1821 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1825 ctype_undump (char **c)
1827 return ((ctype) reader_getInt (c)); /* check its valid? */
1831 ctype_dump (ctype c)
1833 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1837 /* Handle invalid types in a kludgey way. */
1838 return (message ("0"));
1843 cstring tname = usymtab_getTypeEntryName
1844 (usymtab_convertId (ctype_typeId (c)));
1846 if (cstring_equal (tname, context_getBoolName ()))
1848 cstring_free (tname);
1849 return (message ("%d", ctype_bool));
1852 cstring_free (tname);
1855 DPRINTF (("Returning: %d", c));
1856 return (message ("%d", c));
1860 ctype_getBaseType (ctype c)
1862 ctentry cte = ctype_getCtentry (c);
1864 switch (ctentry_getKind (cte))
1872 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1875 ctbase ctb = cte->ctbase;
1877 if (ctbase_isDefined (ctb))
1896 return (ctype_getBaseType (ctb->contents.base));
1898 return (ctype_getBaseType (ctb->contents.farray->base));
1899 case CT_CONJ: /* base type of A conj branch? */
1900 return (ctype_getBaseType (ctb->contents.conj->a));
1902 /*@noaccess ctbase@*/
1910 llbuglit ("ctype_newBase: bad case");
1912 llcontbuglit ("ctype_getBaseType: unreachable code");
1913 return ((ctype)NULL);
1917 ctype_adjustPointers (int np, ctype c)
1920 if (ctype_isFunction (c))
1922 c = ctype_makeParamsFunction
1923 (ctype_adjustPointers (np, ctype_getReturnType (c)),
1924 uentryList_copy (ctype_argsFunction (c)));
1928 /* fix this should not use getBaseType ??? */
1929 ctype cb = ctype_getBaseType (c);
1933 cb = ctype_makePointer (cb);
1936 c = ctype_newBase (c, cb);
1944 ctype_elist (ctype c)
1946 return (ctbase_elist (ctype_getCtbase (c)));
1950 ctype_isFirstVoid (ctype c)
1952 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
1956 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
1958 return (cttable_addComplex (ctbase_createEnum (tag, el)));
1962 ctype_isEnum (ctype c)
1964 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
1968 ctype_enumTag (ctype c)
1970 llassert (ctype_isEnum (c));
1972 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
1976 ctype_isStruct (ctype c)
1978 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
1982 ctype_isUnion (ctype c)
1984 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
1988 ctype_resolveNumerics (ctype c1, ctype c2)
1991 ** returns longest type of c1 and c2
1994 if (c1 == c2) return c1;
1996 c1 = ctype_realType (c1);
1997 c2 = ctype_realType (c2);
1999 if (ctype_isEnum (c1)) c1 = ctype_unknown;
2000 if (ctype_isEnum (c2)) c2 = ctype_int;
2002 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
2004 /* 2001-06-08: This fix provided by Jim Zelenka. */
2005 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
2006 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
2008 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
2009 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
2010 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
2011 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
2013 /* 2001-06-08: This fix provided by Jim Zelenka. */
2014 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
2016 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
2018 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
2019 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
2021 if (ctype_isKnown (c1)) return c1;
2026 ctype_isStructorUnion (ctype c)
2028 return (ctype_isStruct (c) || ctype_isUnion (c));
2032 ctype_fixArrayPtr (ctype c)
2034 if (ctype_isArray (c))
2036 return (ctype_makePointer (ctype_baseArrayPtr (c)));
2043 ** createUnnamedStruct/Union
2045 ** check if it corresponds to an existing LCL-specified unnamed struct
2046 ** otherwise, give it a new tag
2050 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
2052 ctype ret = usymtab_structFieldsType (f);
2054 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
2056 if (ctype_isDefined (ret))
2058 uentryList_free (f);
2063 cstring ft = fakeTag ();
2064 ctype ct = ctype_createStruct (cstring_copy (ft), f);
2065 uentry ue = uentry_makeStructTagLoc (ft, ct);
2067 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2068 ue = usymtab_supGlobalEntryReturn (ue);
2069 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2077 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2079 ctype ret = usymtab_unionFieldsType (f);
2081 if (ctype_isDefined (ret))
2083 uentryList_free (f);
2088 cstring ft = fakeTag ();
2089 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2090 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2092 usymtab_supGlobalEntry (ue);
2099 ctype_isUnnamedSU (ctype c)
2103 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2112 ctype_createForwardStruct (cstring n)
2114 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2115 ctype ct = usymtab_supForwardTypeEntry (ue);
2122 ctype_createForwardUnion (cstring n)
2124 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2125 ctype ct = usymtab_supForwardTypeEntry (ue);
2132 ctype_removePointers (ctype c)
2136 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2139 c = ctype_baseArrayPtr (c);
2140 llassert (c != oldc);
2146 bool ctype_isMutable (ctype t)
2150 return (uentry_isMutableDatatype
2151 (usymtab_getTypeEntry (ctype_typeId (t))));
2155 return (ctype_isPointer (ctype_realType (t)));
2156 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2160 bool ctype_isRefCounted (ctype t)
2164 return (uentry_isRefCountedDatatype
2165 (usymtab_getTypeEntry (ctype_typeId (t))));
2171 bool ctype_isVisiblySharable (ctype t)
2173 if (ctype_isUnknown (t)) return TRUE;
2175 if (ctype_isConj (t))
2177 return (ctype_isVisiblySharable (ctype_getConjA (t))
2178 || ctype_isVisiblySharable (ctype_getConjB (t)));
2181 if (ctype_isMutable (t))
2185 ctype rt = ctype_realType (t);
2193 return ctype_isVisiblySharable (rt);
2207 /* Replaced by ctype_isMutable (more sensible) */
2208 bool ctype_canAlias (ctype ct)
2210 /* can ct refer to memory locations?
2211 ** ==> a pointer or a mutable abstract type
2215 ctype tr = ctype_realType (ct);
2217 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2222 ** c1 is the dominant type; c2 is the modifier type
2224 ** eg. double + long int => long double
2227 ctype ctype_combine (ctype dominant, ctype modifier)
2229 DPRINTF (("Combine: %s + %s",
2230 ctype_unparse (dominant),
2231 ctype_unparse (modifier)));
2233 if (ctype_isConj (dominant))
2237 if (ctype_isExplicitConj (dominant))
2239 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2241 ctype_getConjB (dominant));
2245 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2247 ctype_getConjB (dominant));
2253 if (ctype_isUnknown (modifier))
2257 else if (ctype_isUnknown (dominant))
2263 if (ctype_isEnum (dominant)) dominant = ctype_int;
2264 if (ctype_isEnum (modifier)) modifier = ctype_int;
2266 if (modifier == ctype_uint)
2268 if (dominant == ctype_int) return ctype_uint;
2269 if (dominant == ctype_lint) return ctype_ulint;
2270 if (dominant == ctype_sint) return ctype_usint;
2271 if (dominant == ctype_char) return ctype_uchar;
2273 /* evs 2000-07-28: added this line */
2274 if (dominant == ctype_llint) return ctype_ullint;
2276 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2278 voptgenerror (FLG_DUPLICATEQUALS,
2279 message ("Duplicate unsigned qualifier"),
2286 voptgenerror (FLG_DUPLICATEQUALS,
2287 message ("Type qualifier unsigned used with %s",
2288 ctype_unparse (dominant)),
2294 else if (modifier == ctype_llint)
2296 if (dominant == ctype_int)
2301 voptgenerror (FLG_DUPLICATEQUALS,
2302 message ("Duplicate long qualifier on non-int"),
2305 else if (modifier == ctype_lint)
2307 if (dominant == ctype_int) return ctype_lint;
2308 if (dominant == ctype_uint) return ctype_ulint;
2309 if (dominant == ctype_double) return ctype_ldouble;
2311 if (dominant == ctype_lint || dominant == ctype_ulint
2312 || dominant == ctype_sint || dominant == ctype_usint
2313 || dominant == ctype_ldouble)
2315 if (dominant == ctype_lint)
2317 /* long long not supported by ANSI */
2322 if (dominant == ctype_ulint)
2324 /* unsigned long long not supported by ANSI */
2325 return ctype_ullint;
2329 if (dominant == ctype_sint || dominant == ctype_usint)
2331 if (!context_getFlag (FLG_IGNOREQUALS))
2333 llerrorlit (FLG_SYNTAX,
2334 "Contradictory long and short type qualifiers");
2339 voptgenerror (FLG_DUPLICATEQUALS,
2340 message ("Duplicate long qualifier"),
2347 else if (modifier == ctype_sint)
2349 if (dominant == ctype_int) return ctype_sint;
2350 if (dominant == ctype_uint) return ctype_usint;
2352 if (dominant == ctype_sint || dominant == ctype_usint)
2354 voptgenerror (FLG_DUPLICATEQUALS,
2355 message ("Duplicate short qualifier"),
2359 else if (dominant == ctype_lint)
2361 if (!context_getFlag (FLG_IGNOREQUALS))
2363 llerrorlit (FLG_SYNTAX,
2364 "Contradictory long and short type qualifiers");
2370 else if (dominant == ctype_llint)
2372 if (!context_getFlag (FLG_IGNOREQUALS))
2374 llerrorlit (FLG_SYNTAX,
2375 "Contradictory long long and short type qualifiers");
2383 if (!context_getFlag (FLG_IGNOREQUALS))
2385 llerror (FLG_SYNTAX,
2386 message ("Type qualifier short used with %s",
2387 ctype_unparse (dominant)));
2393 else if (modifier == ctype_ulint)
2395 if (dominant == ctype_int) return modifier;
2397 if (dominant == ctype_lint || dominant == ctype_ulint)
2399 voptgenerror (FLG_DUPLICATEQUALS,
2400 message ("Duplicate long qualifier"),
2406 if (dominant == ctype_uint || dominant == ctype_usint)
2408 voptgenerror (FLG_DUPLICATEQUALS,
2409 message ("Duplicate unsigned qualifier"),
2415 if (dominant == ctype_sint || dominant == ctype_usint)
2417 if (!context_getFlag (FLG_IGNOREQUALS))
2419 llerrorlit (FLG_SYNTAX,
2420 "Contradictory long and short type qualifiers");
2426 if (!context_getFlag (FLG_IGNOREQUALS))
2428 llerror (FLG_SYNTAX,
2429 message ("Type qualifiers unsigned long used with %s",
2430 ctype_unparse (dominant)));
2435 else if (modifier == ctype_usint)
2437 if (dominant == ctype_int) return modifier;
2439 if (dominant == ctype_sint || dominant == ctype_usint)
2441 voptgenerror (FLG_DUPLICATEQUALS,
2442 message ("Duplicate short qualifier"),
2447 if (dominant == ctype_uint)
2449 voptgenerror (FLG_DUPLICATEQUALS,
2450 message ("Duplicate unsigned qualifier"),
2456 if (dominant == ctype_lint || dominant == ctype_ulint
2457 || dominant == ctype_llint)
2459 if (!context_getFlag (FLG_IGNOREQUALS))
2461 llerrorlit (FLG_SYNTAX,
2462 "Contradictory long and short type qualifiers");
2468 if (!context_getFlag (FLG_IGNOREQUALS))
2470 llerror (FLG_SYNTAX,
2471 message ("Type qualifiers unsigned short used with %s",
2472 ctype_unparse (dominant)));
2486 ctype ctype_resolve (ctype c)
2488 if (ctype_isUnknown (c)) return ctype_int;
2492 ctype ctype_fromQual (qual q)
2494 if (qual_isSigned (q)) return ctype_int;
2495 if (qual_isUnsigned (q)) return ctype_uint;
2496 if (qual_isLong (q)) return ctype_lint;
2497 if (qual_isShort (q)) return ctype_sint;
2499 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2500 return ctype_unknown;
2504 ctype_isAnyFloat (ctype c)
2506 return (cprim_isAnyReal (ctype_toCprim (c)));
2510 ctype_isUnsigned (ctype c)
2512 if (ctype_isConj (c))
2513 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2514 ctype_isUnsigned (ctype_getConjB (c)));
2516 return (c == ctype_uint || c == ctype_uchar
2517 || c == ctype_usint || c == ctype_ulint
2518 || c == ctype_ullint
2519 || c == ctype_unsignedintegral);
2524 ctype_isLongLong (ctype c)
2526 if (ctype_isConj (c))
2527 return (ctype_isLongLong (ctype_getConjA (c)) ||
2528 ctype_isLongLong (ctype_getConjB (c)));
2530 return (c == ctype_llint || c == ctype_ullint);
2535 ctype_isLong (ctype c)
2537 if (ctype_isConj (c))
2538 return (ctype_isLong (ctype_getConjA (c)) ||
2539 ctype_isLong (ctype_getConjB (c)));
2541 return (c == ctype_lint || c == ctype_ulint);
2545 ctype_isShort (ctype c)
2547 if (ctype_isConj (c))
2548 return (ctype_isShort (ctype_getConjA (c)) ||
2549 ctype_isShort (ctype_getConjB (c)));
2551 return (c == ctype_sint || c == ctype_usint);
2555 ctype_isStackAllocated (ctype c)
2557 ctype ct = ctype_realType (c);
2559 if (ctype_isConj (ct))
2560 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2561 ctype_isStackAllocated (ctype_getConjB (ct)));
2563 return (ctype_isArray (c) || ctype_isSU (c));
2566 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2568 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2571 static bool ctype_isLonger (ctype c1, ctype c2)
2573 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2574 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2575 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2576 || (ctype_isLong (c1)
2577 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2578 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2582 ctype_widest (ctype c1, ctype c2)
2584 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2594 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2597 if (c >= 0 && c < cttab.size)
2599 return (cttab.entries[c]->ctbase);
2603 if (c == ctype_unknown)
2604 llbuglit ("ctype_getCtbase: ctype unknown");
2605 if (c == ctype_undefined)
2606 llbuglit ("ctype_getCtbase: ctype undefined");
2608 llbuglit ("ctype_getCtbase: ctype dne");
2609 if (c == ctype_elipsMarker)
2610 llbuglit ("ctype_getCtbase: elips marker");
2612 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2619 static /*@notnull@*/ /*@observer@*/ ctbase
2620 ctype_getCtbaseSafe (ctype c)
2622 ctbase res = ctype_getCtbase (c);
2624 llassert (ctbase_isDefined (res));
2633 ctype_getCtentry (ctype c)
2635 static /*@only@*/ ctentry errorEntry = NULL;
2637 if (cttab.size == 0)
2639 if (errorEntry == NULL)
2641 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2648 if (c >= CTK_PLAIN && c < cttab.size)
2650 return (cttab.entries[c]);
2652 else if (c == CTK_UNKNOWN)
2653 llcontbuglit ("ctype_getCtentry: ctype unknown");
2654 else if (c == CTK_INVALID)
2655 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2656 else if (c == CTK_DNE)
2657 llcontbuglit ("ctype_getCtentry: ctype dne");
2658 else if (c == CTK_ELIPS)
2659 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2660 else if (c == CTK_MISSINGPARAMS)
2661 llcontbuglit ("ctype_getCtentry: ctype missing params");
2663 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2665 return (cttab.entries[ctype_unknown]);
2670 bool ctype_isFixedArray (ctype c)
2672 if (ctype_isElips (c)) return FALSE;
2674 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
2679 /* requires that the type is an fixed array */
2680 /* return the size of the array */
2682 long int ctype_getArraySize (ctype c)
2688 llassert (ctype_isFixedArray (c));
2690 ctb = ctype_getCtbaseSafe(c);
2691 size = ctbase_getArraySize (ctb);
2693 DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",