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: splint@cs.virginia.edu
21 ** To report a bug: splint-bug@cs.virginia.edu
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)
320 return (cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c));
324 ctype_makeArray (ctype c)
326 ctentry cte = ctype_getCtentry (c);
327 ctype clp = ctentry_getArray (cte);
329 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
331 ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
332 ctentry_setArray (cte, cnew);
340 ** requires c is a pointer of array
344 ctype_baseArrayPtr (ctype c)
346 ctentry cte = ctype_getCtentry (ctype_realType (c));
348 if (ctype_isConj (c))
350 if (ctype_isAP (ctype_getConjA (c)))
352 if (ctype_isAP (ctype_getConjB (c)))
354 return (ctype_makeConj (ctype_baseArrayPtr (ctype_getConjA (c)),
355 ctype_baseArrayPtr (ctype_getConjB (c))));
359 return (ctype_baseArrayPtr (ctype_getConjA (c)));
364 return (ctype_baseArrayPtr (ctype_getConjB (c)));
367 else if (ctype_isInt (c)) /* could be NULL */
369 return ctype_unknown;
373 ctype clp = ctentry_getBase (cte);
375 if (ctype_isBroken (clp))
377 llbuglit ("ctype_baseArrayPtr: bogus ctype");
389 ctype_makeWideString ()
391 static ctype res = ctype_unknown;
393 if (ctype_isUnknown (res))
397 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
399 wchart = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t")));
406 res = ctype_makePointer (wchart);
413 ctype_isWideString (ctype c)
415 if (ctype_isPointer (c))
417 ctype ct = ctype_baseArrayPtr (c);
419 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
421 return (ct == uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t"))));
435 ctype_getReturnType (ctype c)
437 if (ctype_isUnknown (c))
439 return ctype_unknown;
442 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
446 ** must be a shared pointer
449 /*@observer@*/ uentryList
450 ctype_argsFunction (ctype c)
452 if (ctype_isUnknown (c))
454 return uentryList_undefined;
457 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
461 ** Returns type with base type p and compound types from c.
463 ** i.e., c = char *[]; p = int
468 ctype_newBase (ctype c, ctype p)
470 return (ctbase_newBase (c, p));
474 ctype_sameAltTypes (ctype c1, ctype c2)
479 llassert (ctype_isConj (c1) && ctype_isConj (c2));
481 c1a = ctype_getConjA (c1);
482 c2a = ctype_getConjA (c2);
484 c1b = ctype_getConjB (c1);
485 c2b = ctype_getConjB (c2);
487 if (ctype_compare (c1a, c2a) == 0)
489 if (ctype_compare (c1b, c2b) == 0)
495 if (ctype_isConj (c1b) && ctype_isConj (c2b))
497 return ctype_sameAltTypes (c1b, c2b);
507 if (ctype_compare (c1a, c2b) == 0)
509 if (ctype_compare (c1b, c2a) == 0)
515 if (ctype_isConj (c1b) && ctype_isConj (c2a))
517 return ctype_sameAltTypes (c1b, c2a);
533 ctype_compare (ctype c1, ctype c2)
538 if (ctype_isUnknown (c1))
540 if (ctype_isUnknown (c2))
550 if (ctype_isUnknown (c2))
555 /* Can't get entries for special ctypes (elips marker) */
557 if (ctype_isElips (c1) || ctype_isElips (c2)
558 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
559 return int_compare (c1, c2);
562 ce1 = ctype_getCtentry (c1);
563 ce2 = ctype_getCtentry (c2);
565 if (ctentry_isComplex (ce1))
567 if (ctentry_isComplex (ce2))
569 return (ctbase_compare (ctype_getCtbase (c1),
570 ctype_getCtbase (c2), FALSE));
577 else if (ctentry_isComplex (ce2))
583 return (int_compare (c1, c2));
592 ** makeFunction: pointer to function returning base
596 ctype_makeParamsFunction (ctype base, /*@only@*/ uentryList p)
598 uentryList_fixImpParams (p);
599 return (ctype_makeFunction (base, p));
603 ctype_makeNFParamsFunction (ctype base, /*@only@*/ uentryList p)
605 uentryList_fixImpParams (p);
606 return (ctbase_makeNFFunction (base, p));
610 ctype_makeFunction (ctype base, /*@only@*/ uentryList p)
613 ret = ctbase_makeFunction (base, p);
617 ctype ctype_expectFunction (ctype c)
619 /* handle parenthesized declarations */
623 c = ctype_makePointer (c);
626 return (cttable_addComplex (ctbase_expectFunction (c)));
630 ** makeRealFunction: function returning base
633 ctype ctype_makeRawFunction (ctype base, uentryList p)
635 return (cttable_addComplex (ctbase_makeLiveFunction (base, p)));
643 **** this is very poorly defined
645 **** need to unify function/function pointer meaning
649 ctype_isFunction (ctype c)
651 if (ctype_isKnown (c) && ctype_isDefined (c))
653 return (ctbase_isFunction (ctype_getCtbase (c)));
662 ctype_isExpFcn (ctype c)
664 return (ctype_isKnown (c) && ctbase_isExpFcn (ctype_getCtbase (c)));
668 ctype_isVoid (ctype c)
670 return (c == CTX_VOID);
674 ctype_isArbitraryIntegral (ctype c)
676 ctype cr = ctype_realType (c);
678 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
679 || cr == ctype_signedintegral);
683 ctype_isUnsignedIntegral (ctype c)
685 ctype cr = ctype_realType (c);
687 return (cr == ctype_unsignedintegral);
691 ctype_isSignedIntegral (ctype c)
693 ctype cr = ctype_realType (c);
695 return (cr == ctype_signedintegral);
699 ctype_isInt (ctype c)
701 cprim cp = ctype_toCprim (c);
703 return (c == ctype_unknown || cprim_isAnyInt (cp)
704 || (cprim_isAnyChar (cp) && context_msgCharInt ())
705 || (c == ctype_bool && context_msgBoolInt ())
706 || (ctype_isEnum (c) && context_msgEnumInt ()));
710 ctype_isRegularInt (ctype c)
712 cprim cp = ctype_toCprim (c);
714 return (c == ctype_unknown
715 || cprim_closeEnough (cprim_int, cp)
716 || (cprim_isAnyChar (cp) && context_msgCharInt ())
717 || (c == ctype_bool && context_msgBoolInt ())
718 || (ctype_isEnum (c) && context_msgEnumInt ()));
722 ctype_isString (ctype c)
724 return (c == ctype_string
725 || (ctype_isPointer (c)
726 && ctype_isChar (ctype_baseArrayPtr (c))));
730 ctype_isChar (ctype c)
732 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
733 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
737 ctype_isUnsignedChar (ctype c)
739 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
743 ctype_isSignedChar (ctype c)
745 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
749 ** Returns true if c matches the name -booltype <bool>
753 ctype_isManifestBool (ctype c)
756 ** Changed the meaning of ctype_isBool - evs 2000-07-24
757 ** The old meaning was very convoluted!
760 ** c == CTX_BOOL - its a direct bool
761 ** c is a user/abstract type matching the bool name
762 ** (should never occur?)
765 if (ctype_isDirectBool (c)) {
767 } else if (ctype_isUA (c)) {
768 return ctype_isUserBool (c);
775 ctype_isBool (ctype c)
778 ** Changed the meaning of ctype_isBool - evs 2000-07-24
779 ** The old meaning was very convoluted!
782 ** its a manifest bool
783 ** +boolint and ctype_isInt (c)
786 if (ctype_isManifestBool (c)) {
788 } else if (context_msgBoolInt ()) {
789 return ctype_isInt (c);
795 if (context_getFlag (FLG_ABSTRACTBOOL))
797 if (typeId_isInvalid (boolType))
799 boolType = usymtab_getTypeId (context_getBoolName ());
802 if (context_hasAccess (boolType))
804 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
805 || (context_msgBoolInt ()
807 || (c == CTX_CHAR && context_msgCharInt ()))))
812 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
813 || (context_msgBoolInt ()
814 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
819 ctype_isDirectBool (ctype c)
821 return (c == CTX_BOOL);
825 ctype_isReal (ctype c)
827 return (cprim_isAnyReal (ctype_toCprim (c)));
831 ctype_isFloat (ctype c)
833 return (c == ctype_float);
837 ctype_isDouble (ctype c)
839 return (c == ctype_double || c == ctype_ldouble);
843 ctype_isSigned (ctype c)
845 return (!ctype_isUnsigned (c));
849 ctype_isNumeric (ctype c)
851 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c)
852 /* evans 2001-10-05: added this: */
853 || ctype_isArbitraryIntegral (c));
860 ** work on actual type in current context
864 ctype_isRealNumeric (ctype c)
866 if (ctype_isPlain (c))
867 return (ctype_isNumeric (ctype_realType (c)));
868 if (ctype_isConj (c))
869 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
870 ctype_isRealNumeric (ctype_getConjB (c)));
876 ctype_isRealInt (ctype c)
878 if (ctype_isPlain (c))
879 return (ctype_isInt (ctype_realType (c)));
880 else if (ctype_isConj (c))
881 return (ctype_isRealInt (ctype_getConjA (c)) ||
882 ctype_isRealInt (ctype_getConjB (c)));
885 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
891 ctype_isRealVoid (ctype c)
893 if (ctype_isPlain (c))
895 return (ctype_isVoid (ctype_realType (c)));
897 else if (ctype_isConj (c))
899 return (ctype_isRealVoid (ctype_getConjA (c)) ||
900 ctype_isRealVoid (ctype_getConjB (c)));
909 ctype_isRealBool (ctype c)
911 if (ctype_isPlain (c))
913 return (ctype_isBool (ctype_realishType (c)));
915 else if (ctype_isConj (c))
917 return (ctype_isRealBool (ctype_getConjA (c)) ||
918 ctype_isRealBool (ctype_getConjB (c)));
927 ctype_isRealPointer (ctype c)
929 if (ctype_isConj (c))
930 return (ctype_isRealPointer (ctype_getConjA (c)) ||
931 ctype_isRealPointer (ctype_getConjB (c)));
932 return (ctype_isPointer (ctype_realType (c)));
936 ctype_isRealSU (ctype c)
938 if (ctype_isConj (c))
940 return (ctype_isRealSU (ctype_getConjA (c)) ||
941 ctype_isRealSU (ctype_getConjB (c)));
944 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
945 return (ctype_isStructorUnion (ctype_realType (c)));
949 ctype_isRealArray (ctype c)
951 if (ctype_isConj (c))
952 return (ctype_isRealArray (ctype_getConjA (c)) ||
953 ctype_isRealArray (ctype_getConjB (c)));
954 return (ctype_isArray (ctype_realType (c)));
958 ctype_isRealAP (ctype c)
960 if (ctype_isConj (c))
961 return (ctype_isRealAP (ctype_getConjA (c)) ||
962 ctype_isRealAP (ctype_getConjB (c)));
963 return (ctype_isAP (ctype_realType (c)));
967 ctype_isRealFunction (ctype c)
969 if (ctype_isConj (c))
970 return (ctype_isRealFunction (ctype_getConjA (c)) ||
971 ctype_isRealFunction (ctype_getConjB (c)));
972 return (ctype_isFunction (ctype_realType (c)));
976 ctype_isDirectInt (ctype c)
978 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
982 ** forceful predicates
984 ** take *ctype; if its a conjunct, and there is a match replace with match only.
985 ** if both match, still conjunct
989 ctype_isForcePred (ctype * c, bool (pred) (ctype))
991 /*drl bee: pbr */ if (ctype_isConj (*c))
993 ctype cbr = ctype_getConjA (*c);
995 /*drl bee: si*/ if ((*pred) (cbr))
997 if ((*pred) (ctype_getConjB (*c)))
1010 if ((*pred) (cbr = ctype_getConjB (*c)))
1018 return ((*pred) (*c));
1022 ctype_isForceRealNumeric (ctype * c)
1024 return (ctype_isForcePred (c, ctype_isRealNumeric));
1028 ctype_isForceRealInt (ctype * c)
1030 return (ctype_isForcePred (c, ctype_isRealInt));
1034 ctype_isForceRealBool (ctype * c)
1036 return (ctype_isForcePred (c, ctype_isRealBool));
1042 ** save int/char, int/bool, other random conjuncts
1046 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
1048 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
1052 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1060 return (ctype_makeExplicitConj (c1, c2));
1064 return (ctype_makeConj (c1, c2));
1070 ctype_makeExplicitConj (ctype c1, ctype c2)
1072 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1074 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1076 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1078 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1080 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1082 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1086 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1090 static ctype ic = ctype_unknown; /* int | char */
1091 static ctype ib = ctype_unknown; /* int | bool */
1092 static ctype ifl = ctype_unknown; /* int | float */
1093 static ctype ibf = ctype_unknown; /* int | bool | float */
1094 static ctype ibc = ctype_unknown; /* int | bool | char */
1095 static ctype iv = ctype_unknown; /* int | void * */
1096 static ctype ivf = ctype_unknown; /* int | void * | float */
1097 static ctype ivb = ctype_unknown; /* int | void * | bool */
1098 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1099 static ctype cuc = ctype_unknown; /* char | unsigned char */
1102 ctype_recordConj (ctype c)
1106 llassert (ctype_isConj (c));
1108 c1 = ctype_getConjA (c);
1109 c2 = ctype_getConjB (c);
1112 if (c2 == ctype_int && c1 != ctype_int)
1122 if (c1 == ctype_int)
1124 if (c2 == ctype_char)
1126 llassert (ic == ctype_unknown);
1129 else if (c2 == ctype_bool)
1131 llassert (ib == ctype_unknown);
1134 else if (c2 == ctype_float)
1136 llassert (ifl == ctype_unknown);
1139 else if (c2 == CTP_VOID)
1141 llassert (iv == ctype_unknown);
1149 else if (c1 == ib && ib != ctype_unknown)
1151 if (c2 == ctype_float)
1153 llassert (ibf == ctype_unknown);
1156 else if (c2 == ctype_char)
1158 llassert (ibc == ctype_unknown);
1168 if (c2 == ctype_bool)
1170 llassert (ivb == ctype_unknown);
1173 else if (c2 == ctype_float)
1175 llassert (ivf == ctype_unknown);
1185 if (c2 == ctype_bool)
1187 llassert (ivbf == ctype_unknown);
1193 if (c2 == ctype_float)
1195 llassert (ivbf == ctype_unknown);
1199 else if (c1 == ctype_char)
1201 if (c2 == ctype_uchar)
1203 llassert (cuc == ctype_unknown);
1215 ctype_makeConj (ctype c1, ctype c2)
1217 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1219 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1221 if (ctype_isUnknown (c1))
1225 else if (ctype_isUnknown (c2))
1229 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1231 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1232 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1234 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1236 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1237 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1241 if (ctype_isManifestBool (c1))
1246 if (ctype_isManifestBool (c2))
1251 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1253 c1 = ctype_voidPointer;
1256 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1258 c2 = ctype_voidPointer;
1262 ** Ouch, can't do this. unsigned, etc. modifiers might
1263 ** apply to wrong type!
1265 ** if (c2 == ctype_int && c1 != ctype_int)
1276 if (c1 == ctype_int)
1278 if (c2 == ctype_char)
1280 if (ic == ctype_unknown)
1282 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1287 else if (c2 == ctype_bool)
1289 if (ib == ctype_unknown)
1291 ib = cttable_addComplex
1292 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1297 else if (c2 == ctype_float)
1299 if (ifl == ctype_unknown)
1301 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1308 if (c2 == ctype_voidPointer)
1310 if (iv == ctype_unknown)
1312 iv = cttable_addComplex
1313 (ctbase_makeConj (ctype_int,
1322 else if (c1 == ib && ib != ctype_unknown)
1324 if (c2 == ctype_float)
1326 if (ibf == ctype_unknown)
1328 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1333 else if (c2 == ctype_char)
1335 if (ibc == ctype_unknown)
1337 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1349 if (c2 == ctype_bool)
1351 if (ivb == ctype_unknown)
1353 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1358 else if (c2 == ctype_float)
1360 if (ivf == ctype_unknown)
1362 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1374 if (c2 == ctype_bool)
1376 if (ivbf == ctype_unknown)
1378 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1386 if (c2 == ctype_float)
1388 if (ivbf == ctype_unknown)
1390 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1396 else if (c1 == ctype_char)
1398 if (c2 == ctype_uchar)
1400 if (cuc == ctype_unknown)
1402 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1414 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1420 ctype_isConj (ctype c)
1422 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1426 ctype_getConjA (ctype c)
1428 if (!ctype_isConj (c))
1429 llbuglit ("ctype_getConjA: not a conj");
1430 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1434 ctype_getConjB (ctype c)
1436 if (!ctype_isConj (c))
1437 llbuglit ("ctype_getConjB: not a conj");
1438 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1442 ctype_isExplicitConj (ctype c)
1444 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1447 /** << need to fix resolveConj >> **/
1450 ** structs and unions
1454 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1458 DPRINTF (("Creating a struct: %s / %s",
1459 n, uentryList_unparse (f)));
1461 ct = cttable_addComplex (ctbase_createStruct (n, f));
1462 DPRINTF (("ct: %s", ctype_unparse (ct)));
1467 ctype_getFields (ctype c)
1469 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1473 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1477 ret = cttable_addComplex (ctbase_createUnion (n, f));
1484 ** if ctype's are same, definite match.
1485 ** else, need to call ctbase_match.
1487 ** if necessary context can memoize matches
1491 quickMatch (ctype c1, ctype c2)
1500 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1504 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1506 if (quickMatch (c1, c2))
1511 if (ctype_isElips (c1) || ctype_isElips (c2))
1517 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1523 ctype_sameName (ctype c1, ctype c2)
1525 if (quickMatch (c1, c2))
1528 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1532 ctype_almostEqual (ctype c1, ctype c2)
1534 if (ctype_equal (c1, c2))
1540 if (ctype_isUnknown (c1))
1542 return ctype_isUnknown (c2);
1544 else if (ctype_isUnknown (c2))
1550 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1556 ctype_matchDef (ctype c1, ctype c2)
1558 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1560 if (quickMatch (c1, c2))
1563 if (ctype_isElips (c1))
1564 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1566 if (ctype_isElips (c2))
1568 return (ctype_isUnknown (c2));
1572 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1575 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1576 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1577 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1582 bool ctype_match (ctype c1, ctype c2)
1584 if (quickMatch (c1, c2))
1587 if (ctype_isElips (c1))
1588 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1590 if (ctype_isElips (c2))
1591 return (ctype_isUnknown (c2));
1593 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1597 ctype_forceMatch (ctype c1, ctype c2)
1599 if (quickMatch (c1, c2))
1602 if (ctype_isElips (c1))
1603 return (ctype_isElips (c2));
1605 if (ctype_isElips (c2))
1609 /* The call forceMatch may modify the observer params, but, we don't care. */
1610 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1615 ctype_matchArg (ctype c1, ctype c2)
1617 if (quickMatch (c1, c2))
1623 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1628 ** simple ctype_is operations.
1629 ** DO NOT use real type of c, only direct type.
1633 ** ctype_isVoidPointer
1639 ctype_isVoidPointer (ctype c)
1641 if (ctype_isComplex (c))
1643 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1645 if (ctype_isConj (c))
1647 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1648 ctype_isVoidPointer (ctype_getConjB (c)));
1652 return (c == ctype_voidPointer
1653 || (ctype_isRealPointer (c)
1654 && ctype_isVoid (ctype_baseArrayPtr (c))));
1661 ** true for C and LCL pointers
1665 ctype_isPointer (ctype c)
1667 if (ctype_isElips (c)) return FALSE;
1669 if (ctype_isComplex (c))
1671 ctbase ctb = ctype_getCtbaseSafe (c);
1672 bool res = ctbase_isPointer (ctb);
1678 bool res = ctentry_isPointer (ctype_getCtentry (c));
1687 ** true for C and LCL array's
1691 ctype_isArray (ctype c)
1693 if (ctype_isElips (c)) return FALSE;
1695 if (ctype_isComplex (c))
1696 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1698 return (ctentry_isArray (ctype_getCtentry (c)));
1701 bool ctype_isIncompleteArray (ctype c)
1703 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1706 bool ctype_isFixedArray (ctype c)
1708 if (ctype_isElips (c)) return FALSE;
1710 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
1714 ctype_isArrayPtr (ctype c)
1716 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1720 ctype_typeId (ctype c)
1722 return (ctbase_typeId (ctype_getCtbase (c)));
1726 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1728 llassert (! (ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1730 if (ctype_isUnknown (c))
1732 return message ("? %q", name);
1736 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1741 ctype_unparse (ctype c)
1743 if (ctype_isElips (c))
1745 return cstring_makeLiteralTemp ("...");
1747 else if (ctype_isMissingParamsMarker (c))
1749 return cstring_makeLiteralTemp ("-");
1751 else if (ctype_isUnknown (c))
1753 return cstring_makeLiteralTemp ("?");
1758 return (ctentry_doUnparse (ctype_getCtentry (c)));
1764 ctype_unparseSafe (ctype c)
1766 if (ctype_isElips (c))
1768 return cstring_makeLiteralTemp ("...");
1770 else if (ctype_isMissingParamsMarker (c))
1772 return cstring_makeLiteralTemp ("-");
1778 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1780 ctentry cte = ctype_getCtentry (c);
1782 if (cstring_isDefined (cte->unparse))
1784 return (cte->unparse);
1788 ret = message ("[%d]", (int) c);
1789 cstring_markOwned (ret);
1795 ctype_unparseDeep (ctype c)
1797 if (ctype_isElips (c))
1799 return cstring_makeLiteralTemp ("...");
1801 if (ctype_isMissingParamsMarker (c))
1803 return cstring_makeLiteralTemp ("-");
1806 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1810 ctype_undump (char **c)
1812 return ((ctype) reader_getInt (c)); /* check its valid? */
1816 ctype_dump (ctype c)
1818 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1822 /* Handle invalid types in a kludgey way. */
1823 return (message ("0"));
1828 cstring tname = usymtab_getTypeEntryName
1829 (usymtab_convertId (ctype_typeId (c)));
1831 if (cstring_equal (tname, context_getBoolName ()))
1833 cstring_free (tname);
1834 return (message ("%d", ctype_bool));
1837 cstring_free (tname);
1840 DPRINTF (("Returning: %d", c));
1841 return (message ("%d", c));
1845 ctype_getBaseType (ctype c)
1847 ctentry cte = ctype_getCtentry (c);
1849 switch (ctentry_getKind (cte))
1857 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1860 ctbase ctb = cte->ctbase;
1862 if (ctbase_isDefined (ctb))
1881 return (ctype_getBaseType (ctb->contents.base));
1883 return (ctype_getBaseType (ctb->contents.farray->base));
1884 case CT_CONJ: /* base type of A conj branch? */
1885 return (ctype_getBaseType (ctb->contents.conj->a));
1887 /*@noaccess ctbase@*/
1895 llbuglit ("ctype_newBase: bad case");
1897 llcontbuglit ("ctype_getBaseType: unreachable code");
1898 return ((ctype)NULL);
1902 ctype_adjustPointers (int np, ctype c)
1905 if (ctype_isFunction (c))
1907 c = ctype_makeParamsFunction
1908 (ctype_adjustPointers (np, ctype_getReturnType (c)),
1909 uentryList_copy (ctype_argsFunction (c)));
1913 /* fix this should not use getBaseType ??? */
1914 ctype cb = ctype_getBaseType (c);
1918 cb = ctype_makePointer (cb);
1921 c = ctype_newBase (c, cb);
1929 ctype_elist (ctype c)
1931 return (ctbase_elist (ctype_getCtbase (c)));
1935 ctype_isFirstVoid (ctype c)
1937 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
1941 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
1943 return (cttable_addComplex (ctbase_createEnum (tag, el)));
1947 ctype_isEnum (ctype c)
1949 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
1953 ctype_enumTag (ctype c)
1955 llassert (ctype_isEnum (c));
1957 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
1961 ctype_isStruct (ctype c)
1963 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
1967 ctype_isUnion (ctype c)
1969 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
1973 ctype_resolveNumerics (ctype c1, ctype c2)
1976 ** returns longest type of c1 and c2
1979 if (c1 == c2) return c1;
1981 c1 = ctype_realType (c1);
1982 c2 = ctype_realType (c2);
1984 if (ctype_isEnum (c1)) c1 = ctype_unknown;
1985 if (ctype_isEnum (c2)) c2 = ctype_int;
1987 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
1989 /* 2001-06-08: This fix provided by Jim Zelenka. */
1990 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
1991 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
1993 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
1994 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
1995 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
1996 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
1998 /* 2001-06-08: This fix provided by Jim Zelenka. */
1999 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
2001 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
2003 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
2004 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
2006 if (ctype_isKnown (c1)) return c1;
2011 ctype_isStructorUnion (ctype c)
2013 return (ctype_isStruct (c) || ctype_isUnion (c));
2017 ctype_fixArrayPtr (ctype c)
2019 if (ctype_isArray (c))
2021 return (ctype_makePointer (ctype_baseArrayPtr (c)));
2028 ** createUnnamedStruct/Union
2030 ** check if it corresponds to an existing LCL-specified unnamed struct
2031 ** otherwise, give it a new tag
2035 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
2037 ctype ret = usymtab_structFieldsType (f);
2039 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
2041 if (ctype_isDefined (ret))
2043 uentryList_free (f);
2048 cstring ft = fakeTag ();
2049 ctype ct = ctype_createStruct (cstring_copy (ft), f);
2050 uentry ue = uentry_makeStructTagLoc (ft, ct);
2052 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2053 ue = usymtab_supGlobalEntryReturn (ue);
2054 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2062 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2064 ctype ret = usymtab_unionFieldsType (f);
2066 if (ctype_isDefined (ret))
2068 uentryList_free (f);
2073 cstring ft = fakeTag ();
2074 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2075 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2077 usymtab_supGlobalEntry (ue);
2084 ctype_isUnnamedSU (ctype c)
2088 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2097 ctype_createForwardStruct (cstring n)
2099 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2100 ctype ct = usymtab_supForwardTypeEntry (ue);
2107 ctype_createForwardUnion (cstring n)
2109 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2110 ctype ct = usymtab_supForwardTypeEntry (ue);
2117 ctype_removePointers (ctype c)
2121 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2124 c = ctype_baseArrayPtr (c);
2125 llassert (c != oldc);
2131 bool ctype_isMutable (ctype t)
2135 return (uentry_isMutableDatatype
2136 (usymtab_getTypeEntry (ctype_typeId (t))));
2140 return (ctype_isPointer (ctype_realType (t)));
2141 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2145 bool ctype_isRefCounted (ctype t)
2149 return (uentry_isRefCountedDatatype
2150 (usymtab_getTypeEntry (ctype_typeId (t))));
2156 bool ctype_isVisiblySharable (ctype t)
2158 if (ctype_isUnknown (t)) return TRUE;
2160 if (ctype_isConj (t))
2162 return (ctype_isVisiblySharable (ctype_getConjA (t))
2163 || ctype_isVisiblySharable (ctype_getConjB (t)));
2166 if (ctype_isMutable (t))
2170 ctype rt = ctype_realType (t);
2178 return ctype_isVisiblySharable (rt);
2192 /* Replaced by ctype_isMutable (more sensible) */
2193 bool ctype_canAlias (ctype ct)
2195 /* can ct refer to memory locations?
2196 ** ==> a pointer or a mutable abstract type
2200 ctype tr = ctype_realType (ct);
2202 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2207 ** c1 is the dominant type; c2 is the modifier type
2209 ** eg. double + long int => long double
2212 ctype ctype_combine (ctype dominant, ctype modifier)
2214 DPRINTF (("Combine: %s + %s",
2215 ctype_unparse (dominant),
2216 ctype_unparse (modifier)));
2218 if (ctype_isConj (dominant))
2222 if (ctype_isExplicitConj (dominant))
2224 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2226 ctype_getConjB (dominant));
2230 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2232 ctype_getConjB (dominant));
2238 if (ctype_isUnknown (modifier))
2242 else if (ctype_isUnknown (dominant))
2248 if (ctype_isEnum (dominant)) dominant = ctype_int;
2249 if (ctype_isEnum (modifier)) modifier = ctype_int;
2251 if (modifier == ctype_uint)
2253 if (dominant == ctype_int) return ctype_uint;
2254 if (dominant == ctype_lint) return ctype_ulint;
2255 if (dominant == ctype_sint) return ctype_usint;
2256 if (dominant == ctype_char) return ctype_uchar;
2258 /* evs 2000-07-28: added this line */
2259 if (dominant == ctype_llint) return ctype_ullint;
2261 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2263 voptgenerror (FLG_DUPLICATEQUALS,
2264 message ("Duplicate unsigned qualifier"),
2271 voptgenerror (FLG_DUPLICATEQUALS,
2272 message ("Type qualifier unsigned used with %s",
2273 ctype_unparse (dominant)),
2279 else if (modifier == ctype_llint)
2281 if (dominant == ctype_int)
2286 voptgenerror (FLG_DUPLICATEQUALS,
2287 message ("Duplicate long qualifier on non-int"),
2290 else if (modifier == ctype_lint)
2292 if (dominant == ctype_int) return ctype_lint;
2293 if (dominant == ctype_uint) return ctype_ulint;
2294 if (dominant == ctype_double) return ctype_ldouble;
2296 if (dominant == ctype_lint || dominant == ctype_ulint
2297 || dominant == ctype_sint || dominant == ctype_usint
2298 || dominant == ctype_ldouble)
2300 if (dominant == ctype_lint)
2302 /* long long not supported by ANSI */
2307 if (dominant == ctype_ulint)
2309 /* unsigned long long not supported by ANSI */
2310 return ctype_ullint;
2314 if (dominant == ctype_sint || dominant == ctype_usint)
2316 if (!context_getFlag (FLG_IGNOREQUALS))
2318 llerrorlit (FLG_SYNTAX,
2319 "Contradictory long and short type qualifiers");
2324 voptgenerror (FLG_DUPLICATEQUALS,
2325 message ("Duplicate long qualifier"),
2332 else if (modifier == ctype_sint)
2334 if (dominant == ctype_int) return ctype_sint;
2335 if (dominant == ctype_uint) return ctype_usint;
2337 if (dominant == ctype_sint || dominant == ctype_usint)
2339 voptgenerror (FLG_DUPLICATEQUALS,
2340 message ("Duplicate short qualifier"),
2344 else if (dominant == ctype_lint)
2346 if (!context_getFlag (FLG_IGNOREQUALS))
2348 llerrorlit (FLG_SYNTAX,
2349 "Contradictory long and short type qualifiers");
2355 else if (dominant == ctype_llint)
2357 if (!context_getFlag (FLG_IGNOREQUALS))
2359 llerrorlit (FLG_SYNTAX,
2360 "Contradictory long long and short type qualifiers");
2368 if (!context_getFlag (FLG_IGNOREQUALS))
2370 llerror (FLG_SYNTAX,
2371 message ("Type qualifier short used with %s",
2372 ctype_unparse (dominant)));
2378 else if (modifier == ctype_ulint)
2380 if (dominant == ctype_int) return modifier;
2382 if (dominant == ctype_lint || dominant == ctype_ulint)
2384 voptgenerror (FLG_DUPLICATEQUALS,
2385 message ("Duplicate long qualifier"),
2391 if (dominant == ctype_uint || dominant == ctype_usint)
2393 voptgenerror (FLG_DUPLICATEQUALS,
2394 message ("Duplicate unsigned qualifier"),
2400 if (dominant == ctype_sint || dominant == ctype_usint)
2402 if (!context_getFlag (FLG_IGNOREQUALS))
2404 llerrorlit (FLG_SYNTAX,
2405 "Contradictory long and short type qualifiers");
2411 if (!context_getFlag (FLG_IGNOREQUALS))
2413 llerror (FLG_SYNTAX,
2414 message ("Type qualifiers unsigned long used with %s",
2415 ctype_unparse (dominant)));
2420 else if (modifier == ctype_usint)
2422 if (dominant == ctype_int) return modifier;
2424 if (dominant == ctype_sint || dominant == ctype_usint)
2426 voptgenerror (FLG_DUPLICATEQUALS,
2427 message ("Duplicate short qualifier"),
2432 if (dominant == ctype_uint)
2434 voptgenerror (FLG_DUPLICATEQUALS,
2435 message ("Duplicate unsigned qualifier"),
2441 if (dominant == ctype_lint || dominant == ctype_ulint
2442 || dominant == ctype_llint)
2444 if (!context_getFlag (FLG_IGNOREQUALS))
2446 llerrorlit (FLG_SYNTAX,
2447 "Contradictory long and short type qualifiers");
2453 if (!context_getFlag (FLG_IGNOREQUALS))
2455 llerror (FLG_SYNTAX,
2456 message ("Type qualifiers unsigned short used with %s",
2457 ctype_unparse (dominant)));
2471 ctype ctype_resolve (ctype c)
2473 if (ctype_isUnknown (c)) return ctype_int;
2477 ctype ctype_fromQual (qual q)
2479 if (qual_isSigned (q)) return ctype_int;
2480 if (qual_isUnsigned (q)) return ctype_uint;
2481 if (qual_isLong (q)) return ctype_lint;
2482 if (qual_isShort (q)) return ctype_sint;
2484 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2485 return ctype_unknown;
2489 ctype_isAnyFloat (ctype c)
2491 return (cprim_isAnyReal (ctype_toCprim (c)));
2495 ctype_isUnsigned (ctype c)
2497 if (ctype_isConj (c))
2498 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2499 ctype_isUnsigned (ctype_getConjB (c)));
2501 return (c == ctype_uint || c == ctype_uchar
2502 || c == ctype_usint || c == ctype_ulint
2503 || c == ctype_ullint
2504 || c == ctype_unsignedintegral);
2509 ctype_isLongLong (ctype c)
2511 if (ctype_isConj (c))
2512 return (ctype_isLongLong (ctype_getConjA (c)) ||
2513 ctype_isLongLong (ctype_getConjB (c)));
2515 return (c == ctype_llint || c == ctype_ullint);
2520 ctype_isLong (ctype c)
2522 if (ctype_isConj (c))
2523 return (ctype_isLong (ctype_getConjA (c)) ||
2524 ctype_isLong (ctype_getConjB (c)));
2526 return (c == ctype_lint || c == ctype_ulint);
2530 ctype_isShort (ctype c)
2532 if (ctype_isConj (c))
2533 return (ctype_isShort (ctype_getConjA (c)) ||
2534 ctype_isShort (ctype_getConjB (c)));
2536 return (c == ctype_sint || c == ctype_usint);
2540 ctype_isStackAllocated (ctype c)
2542 ctype ct = ctype_realType (c);
2544 if (ctype_isConj (ct))
2545 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2546 ctype_isStackAllocated (ctype_getConjB (ct)));
2548 return (ctype_isArray (c) || ctype_isSU (c));
2551 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2553 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2556 static bool ctype_isLonger (ctype c1, ctype c2)
2558 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2559 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2560 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2561 || (ctype_isLong (c1)
2562 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2563 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2567 ctype_widest (ctype c1, ctype c2)
2569 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2579 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2582 if (c >= 0 && c < cttab.size)
2584 return (cttab.entries[c]->ctbase);
2588 if (c == ctype_unknown)
2589 llbuglit ("ctype_getCtbase: ctype unknown");
2590 if (c == ctype_undefined)
2591 llbuglit ("ctype_getCtbase: ctype undefined");
2593 llbuglit ("ctype_getCtbase: ctype dne");
2594 if (c == ctype_elipsMarker)
2595 llbuglit ("ctype_getCtbase: elips marker");
2597 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2604 static /*@notnull@*/ /*@observer@*/ ctbase
2605 ctype_getCtbaseSafe (ctype c)
2607 ctbase res = ctype_getCtbase (c);
2609 llassert (ctbase_isDefined (res));
2618 ctype_getCtentry (ctype c)
2620 static /*@only@*/ ctentry errorEntry = NULL;
2622 if (cttab.size == 0)
2624 if (errorEntry == NULL)
2626 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2633 if (c >= CTK_PLAIN && c < cttab.size)
2635 return (cttab.entries[c]);
2637 else if (c == CTK_UNKNOWN)
2638 llcontbuglit ("ctype_getCtentry: ctype unknown");
2639 else if (c == CTK_INVALID)
2640 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2641 else if (c == CTK_DNE)
2642 llcontbuglit ("ctype_getCtentry: ctype dne");
2643 else if (c == CTK_ELIPS)
2644 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2645 else if (c == CTK_MISSINGPARAMS)
2646 llcontbuglit ("ctype_getCtentry: ctype missing params");
2648 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2650 return (cttab.entries[ctype_unknown]);
2655 /* requires that the type is an fixed array */
2656 /* return the size of the array */
2658 long int ctype_getArraySize (ctype c)
2661 ctentry cte = ctype_getCtentry (c);
2664 llassert (ctype_isFixedArray (c));
2665 llassert ((ctentry_getKind (cte) == CTK_COMPLEX) || (ctentry_getKind (cte) == CTK_ARRAY));
2668 size = ctbase_getArraySize (ctb);
2670 DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",