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));
1728 bool ctype_isFixedArray (ctype c)
1730 if (ctype_isElips (c)) return FALSE;
1732 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
1736 ctype_isArrayPtr (ctype c)
1738 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1742 ctype_typeId (ctype c)
1744 return (ctbase_typeId (ctype_getCtbase (c)));
1748 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1750 llassert (! (ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1752 if (ctype_isUnknown (c))
1754 return message ("? %q", name);
1758 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1763 ctype_unparse (ctype c)
1765 if (ctype_isElips (c))
1767 return cstring_makeLiteralTemp ("...");
1769 else if (ctype_isMissingParamsMarker (c))
1771 return cstring_makeLiteralTemp ("-");
1773 else if (ctype_isUnknown (c))
1775 return cstring_makeLiteralTemp ("?");
1780 return (ctentry_doUnparse (ctype_getCtentry (c)));
1786 ctype_unparseSafe (ctype c)
1788 if (ctype_isElips (c))
1790 return cstring_makeLiteralTemp ("...");
1792 else if (ctype_isMissingParamsMarker (c))
1794 return cstring_makeLiteralTemp ("-");
1800 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1802 ctentry cte = ctype_getCtentry (c);
1804 if (cstring_isDefined (cte->unparse))
1806 return (cte->unparse);
1810 ret = message ("[%d]", (int) c);
1811 cstring_markOwned (ret);
1817 ctype_unparseDeep (ctype c)
1819 if (ctype_isElips (c))
1821 return cstring_makeLiteralTemp ("...");
1823 if (ctype_isMissingParamsMarker (c))
1825 return cstring_makeLiteralTemp ("-");
1828 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1832 ctype_undump (char **c)
1834 return ((ctype) reader_getInt (c)); /* check its valid? */
1838 ctype_dump (ctype c)
1840 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1844 /* Handle invalid types in a kludgey way. */
1845 return (message ("0"));
1850 cstring tname = usymtab_getTypeEntryName
1851 (usymtab_convertId (ctype_typeId (c)));
1853 if (cstring_equal (tname, context_getBoolName ()))
1855 cstring_free (tname);
1856 return (message ("%d", ctype_bool));
1859 cstring_free (tname);
1862 DPRINTF (("Returning: %d", c));
1863 return (message ("%d", c));
1867 ctype_getBaseType (ctype c)
1869 ctentry cte = ctype_getCtentry (c);
1871 switch (ctentry_getKind (cte))
1879 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1882 ctbase ctb = cte->ctbase;
1884 if (ctbase_isDefined (ctb))
1903 return (ctype_getBaseType (ctb->contents.base));
1905 return (ctype_getBaseType (ctb->contents.farray->base));
1906 case CT_CONJ: /* base type of A conj branch? */
1907 return (ctype_getBaseType (ctb->contents.conj->a));
1909 /*@noaccess ctbase@*/
1917 llbuglit ("ctype_newBase: bad case");
1919 llcontbuglit ("ctype_getBaseType: unreachable code");
1920 return ((ctype)NULL);
1924 ctype_adjustPointers (int np, ctype c)
1927 if (ctype_isFunction (c))
1929 c = ctype_makeParamsFunction
1930 (ctype_adjustPointers (np, ctype_getReturnType (c)),
1931 uentryList_copy (ctype_argsFunction (c)));
1935 /* fix this should not use getBaseType ??? */
1936 ctype cb = ctype_getBaseType (c);
1940 cb = ctype_makePointer (cb);
1943 c = ctype_newBase (c, cb);
1951 ctype_elist (ctype c)
1953 return (ctbase_elist (ctype_getCtbase (c)));
1957 ctype_isFirstVoid (ctype c)
1959 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
1963 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
1965 return (cttable_addComplex (ctbase_createEnum (tag, el)));
1969 ctype_isEnum (ctype c)
1971 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
1975 ctype_enumTag (ctype c)
1977 llassert (ctype_isEnum (c));
1979 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
1983 ctype_isStruct (ctype c)
1985 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
1989 ctype_isUnion (ctype c)
1991 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
1995 ctype_resolveNumerics (ctype c1, ctype c2)
1998 ** returns longest type of c1 and c2
2001 if (c1 == c2) return c1;
2003 c1 = ctype_realType (c1);
2004 c2 = ctype_realType (c2);
2006 if (ctype_isEnum (c1)) c1 = ctype_unknown;
2007 if (ctype_isEnum (c2)) c2 = ctype_int;
2009 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
2011 /* 2001-06-08: This fix provided by Jim Zelenka. */
2012 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
2013 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
2015 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
2016 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
2017 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
2018 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
2020 /* 2001-06-08: This fix provided by Jim Zelenka. */
2021 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
2023 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
2025 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
2026 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
2028 if (ctype_isKnown (c1)) return c1;
2033 ctype_isStructorUnion (ctype c)
2035 return (ctype_isStruct (c) || ctype_isUnion (c));
2039 ctype_fixArrayPtr (ctype c)
2041 if (ctype_isArray (c))
2043 return (ctype_makePointer (ctype_baseArrayPtr (c)));
2050 ** createUnnamedStruct/Union
2052 ** check if it corresponds to an existing LCL-specified unnamed struct
2053 ** otherwise, give it a new tag
2057 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
2059 ctype ret = usymtab_structFieldsType (f);
2061 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
2063 if (ctype_isDefined (ret))
2065 uentryList_free (f);
2070 cstring ft = fakeTag ();
2071 ctype ct = ctype_createStruct (cstring_copy (ft), f);
2072 uentry ue = uentry_makeStructTagLoc (ft, ct);
2074 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2075 ue = usymtab_supGlobalEntryReturn (ue);
2076 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2084 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2086 ctype ret = usymtab_unionFieldsType (f);
2088 if (ctype_isDefined (ret))
2090 uentryList_free (f);
2095 cstring ft = fakeTag ();
2096 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2097 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2099 usymtab_supGlobalEntry (ue);
2106 ctype_isUnnamedSU (ctype c)
2110 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2119 ctype_createForwardStruct (cstring n)
2121 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2122 ctype ct = usymtab_supForwardTypeEntry (ue);
2129 ctype_createForwardUnion (cstring n)
2131 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2132 ctype ct = usymtab_supForwardTypeEntry (ue);
2139 ctype_removePointers (ctype c)
2143 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2146 c = ctype_baseArrayPtr (c);
2147 llassert (c != oldc);
2153 bool ctype_isMutable (ctype t)
2157 return (uentry_isMutableDatatype
2158 (usymtab_getTypeEntry (ctype_typeId (t))));
2162 return (ctype_isPointer (ctype_realType (t)));
2163 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2167 bool ctype_isRefCounted (ctype t)
2171 return (uentry_isRefCountedDatatype
2172 (usymtab_getTypeEntry (ctype_typeId (t))));
2178 bool ctype_isVisiblySharable (ctype t)
2180 if (ctype_isUnknown (t)) return TRUE;
2182 if (ctype_isConj (t))
2184 return (ctype_isVisiblySharable (ctype_getConjA (t))
2185 || ctype_isVisiblySharable (ctype_getConjB (t)));
2188 if (ctype_isMutable (t))
2192 ctype rt = ctype_realType (t);
2200 return ctype_isVisiblySharable (rt);
2214 /* Replaced by ctype_isMutable (more sensible) */
2215 bool ctype_canAlias (ctype ct)
2217 /* can ct refer to memory locations?
2218 ** ==> a pointer or a mutable abstract type
2222 ctype tr = ctype_realType (ct);
2224 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2229 ** c1 is the dominant type; c2 is the modifier type
2231 ** eg. double + long int => long double
2234 ctype ctype_combine (ctype dominant, ctype modifier)
2236 DPRINTF (("Combine: %s + %s",
2237 ctype_unparse (dominant),
2238 ctype_unparse (modifier)));
2240 if (ctype_isConj (dominant))
2244 if (ctype_isExplicitConj (dominant))
2246 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2248 ctype_getConjB (dominant));
2252 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2254 ctype_getConjB (dominant));
2260 if (ctype_isUnknown (modifier))
2264 else if (ctype_isUnknown (dominant))
2270 if (ctype_isEnum (dominant)) dominant = ctype_int;
2271 if (ctype_isEnum (modifier)) modifier = ctype_int;
2273 if (modifier == ctype_uint)
2275 if (dominant == ctype_int) return ctype_uint;
2276 if (dominant == ctype_lint) return ctype_ulint;
2277 if (dominant == ctype_sint) return ctype_usint;
2278 if (dominant == ctype_char) return ctype_uchar;
2280 /* evs 2000-07-28: added this line */
2281 if (dominant == ctype_llint) return ctype_ullint;
2283 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2285 voptgenerror (FLG_DUPLICATEQUALS,
2286 message ("Duplicate unsigned qualifier"),
2293 voptgenerror (FLG_DUPLICATEQUALS,
2294 message ("Type qualifier unsigned used with %s",
2295 ctype_unparse (dominant)),
2301 else if (modifier == ctype_llint)
2303 if (dominant == ctype_int)
2308 voptgenerror (FLG_DUPLICATEQUALS,
2309 message ("Duplicate long qualifier on non-int"),
2312 else if (modifier == ctype_lint)
2314 if (dominant == ctype_int) return ctype_lint;
2315 if (dominant == ctype_uint) return ctype_ulint;
2316 if (dominant == ctype_double) return ctype_ldouble;
2318 if (dominant == ctype_lint || dominant == ctype_ulint
2319 || dominant == ctype_sint || dominant == ctype_usint
2320 || dominant == ctype_ldouble)
2322 if (dominant == ctype_lint)
2324 /* long long not supported by ANSI */
2329 if (dominant == ctype_ulint)
2331 /* unsigned long long not supported by ANSI */
2332 return ctype_ullint;
2336 if (dominant == ctype_sint || dominant == ctype_usint)
2338 if (!context_getFlag (FLG_IGNOREQUALS))
2340 llerrorlit (FLG_SYNTAX,
2341 "Contradictory long and short type qualifiers");
2346 voptgenerror (FLG_DUPLICATEQUALS,
2347 message ("Duplicate long qualifier"),
2354 else if (modifier == ctype_sint)
2356 if (dominant == ctype_int) return ctype_sint;
2357 if (dominant == ctype_uint) return ctype_usint;
2359 if (dominant == ctype_sint || dominant == ctype_usint)
2361 voptgenerror (FLG_DUPLICATEQUALS,
2362 message ("Duplicate short qualifier"),
2366 else if (dominant == ctype_lint)
2368 if (!context_getFlag (FLG_IGNOREQUALS))
2370 llerrorlit (FLG_SYNTAX,
2371 "Contradictory long and short type qualifiers");
2377 else if (dominant == ctype_llint)
2379 if (!context_getFlag (FLG_IGNOREQUALS))
2381 llerrorlit (FLG_SYNTAX,
2382 "Contradictory long long and short type qualifiers");
2390 if (!context_getFlag (FLG_IGNOREQUALS))
2392 llerror (FLG_SYNTAX,
2393 message ("Type qualifier short used with %s",
2394 ctype_unparse (dominant)));
2400 else if (modifier == ctype_ulint)
2402 if (dominant == ctype_int) return modifier;
2404 if (dominant == ctype_lint || dominant == ctype_ulint)
2406 voptgenerror (FLG_DUPLICATEQUALS,
2407 message ("Duplicate long qualifier"),
2413 if (dominant == ctype_uint || dominant == ctype_usint)
2415 voptgenerror (FLG_DUPLICATEQUALS,
2416 message ("Duplicate unsigned qualifier"),
2422 if (dominant == ctype_sint || dominant == ctype_usint)
2424 if (!context_getFlag (FLG_IGNOREQUALS))
2426 llerrorlit (FLG_SYNTAX,
2427 "Contradictory long and short type qualifiers");
2433 if (!context_getFlag (FLG_IGNOREQUALS))
2435 llerror (FLG_SYNTAX,
2436 message ("Type qualifiers unsigned long used with %s",
2437 ctype_unparse (dominant)));
2442 else if (modifier == ctype_usint)
2444 if (dominant == ctype_int) return modifier;
2446 if (dominant == ctype_sint || dominant == ctype_usint)
2448 voptgenerror (FLG_DUPLICATEQUALS,
2449 message ("Duplicate short qualifier"),
2454 if (dominant == ctype_uint)
2456 voptgenerror (FLG_DUPLICATEQUALS,
2457 message ("Duplicate unsigned qualifier"),
2463 if (dominant == ctype_lint || dominant == ctype_ulint
2464 || dominant == ctype_llint)
2466 if (!context_getFlag (FLG_IGNOREQUALS))
2468 llerrorlit (FLG_SYNTAX,
2469 "Contradictory long and short type qualifiers");
2475 if (!context_getFlag (FLG_IGNOREQUALS))
2477 llerror (FLG_SYNTAX,
2478 message ("Type qualifiers unsigned short used with %s",
2479 ctype_unparse (dominant)));
2493 ctype ctype_resolve (ctype c)
2495 if (ctype_isUnknown (c)) return ctype_int;
2499 ctype ctype_fromQual (qual q)
2501 if (qual_isSigned (q)) return ctype_int;
2502 if (qual_isUnsigned (q)) return ctype_uint;
2503 if (qual_isLong (q)) return ctype_lint;
2504 if (qual_isShort (q)) return ctype_sint;
2506 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2507 return ctype_unknown;
2511 ctype_isAnyFloat (ctype c)
2513 return (cprim_isAnyReal (ctype_toCprim (c)));
2517 ctype_isUnsigned (ctype c)
2519 if (ctype_isConj (c))
2520 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2521 ctype_isUnsigned (ctype_getConjB (c)));
2523 return (c == ctype_uint || c == ctype_uchar
2524 || c == ctype_usint || c == ctype_ulint
2525 || c == ctype_ullint
2526 || c == ctype_unsignedintegral);
2531 ctype_isLongLong (ctype c)
2533 if (ctype_isConj (c))
2534 return (ctype_isLongLong (ctype_getConjA (c)) ||
2535 ctype_isLongLong (ctype_getConjB (c)));
2537 return (c == ctype_llint || c == ctype_ullint);
2542 ctype_isLong (ctype c)
2544 if (ctype_isConj (c))
2545 return (ctype_isLong (ctype_getConjA (c)) ||
2546 ctype_isLong (ctype_getConjB (c)));
2548 return (c == ctype_lint || c == ctype_ulint);
2552 ctype_isShort (ctype c)
2554 if (ctype_isConj (c))
2555 return (ctype_isShort (ctype_getConjA (c)) ||
2556 ctype_isShort (ctype_getConjB (c)));
2558 return (c == ctype_sint || c == ctype_usint);
2562 ctype_isStackAllocated (ctype c)
2564 ctype ct = ctype_realType (c);
2566 if (ctype_isConj (ct))
2567 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2568 ctype_isStackAllocated (ctype_getConjB (ct)));
2570 return (ctype_isArray (c) || ctype_isSU (c));
2573 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2575 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2578 static bool ctype_isLonger (ctype c1, ctype c2)
2580 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2581 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2582 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2583 || (ctype_isLong (c1)
2584 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2585 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2589 ctype_widest (ctype c1, ctype c2)
2591 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2601 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2604 if (c >= 0 && c < cttab.size)
2606 return (cttab.entries[c]->ctbase);
2610 if (c == ctype_unknown)
2611 llbuglit ("ctype_getCtbase: ctype unknown");
2612 if (c == ctype_undefined)
2613 llbuglit ("ctype_getCtbase: ctype undefined");
2615 llbuglit ("ctype_getCtbase: ctype dne");
2616 if (c == ctype_elipsMarker)
2617 llbuglit ("ctype_getCtbase: elips marker");
2619 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2626 static /*@notnull@*/ /*@observer@*/ ctbase
2627 ctype_getCtbaseSafe (ctype c)
2629 ctbase res = ctype_getCtbase (c);
2631 llassert (ctbase_isDefined (res));
2640 ctype_getCtentry (ctype c)
2642 static /*@only@*/ ctentry errorEntry = NULL;
2644 if (cttab.size == 0)
2646 if (errorEntry == NULL)
2648 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2655 if (c >= CTK_PLAIN && c < cttab.size)
2657 return (cttab.entries[c]);
2659 else if (c == CTK_UNKNOWN)
2660 llcontbuglit ("ctype_getCtentry: ctype unknown");
2661 else if (c == CTK_INVALID)
2662 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2663 else if (c == CTK_DNE)
2664 llcontbuglit ("ctype_getCtentry: ctype dne");
2665 else if (c == CTK_ELIPS)
2666 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2667 else if (c == CTK_MISSINGPARAMS)
2668 llcontbuglit ("ctype_getCtentry: ctype missing params");
2670 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2672 return (cttab.entries[ctype_unknown]);
2677 /* requires that the type is an fixed array */
2678 /* return the size of the array */
2680 long int ctype_getArraySize (ctype c)
2683 ctentry cte = ctype_getCtentry (c);
2686 llassert (ctype_isFixedArray (c));
2687 llassert ((ctentry_getKind (cte) == CTK_COMPLEX) || (ctentry_getKind (cte) == CTK_ARRAY));
2690 size = ctbase_getArraySize (ctb);
2692 DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",