2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
27 ** This files implements three types: ctentry, cttable and ctype.
28 ** They should probably be separated soon.
31 # include "lclintMacros.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)
175 r = uentry_getRealType (usymtab_getTypeEntry (ctype_typeId (c)));
178 if (ctype_isManifestBool (r))
180 if (context_canAccessBool ())
182 r = context_boolImplementationType ();
190 ctype_isSimple (ctype c)
192 return (!(ctype_isPointer (c)
194 || ctype_isFunction (c)));
198 ctype_forceRealType (ctype c)
204 r = uentry_getForceRealType (usymtab_getTypeEntry (ctype_typeId (c)));
211 ctype_realishType (ctype c)
215 if (ctype_isManifestBool (c))
221 ctype r = uentry_getRealType (usymtab_getTypeEntry
233 return (!ctype_isUnknown (c) && ctbase_isUA (ctype_getCtbase (c)));
237 ctype_isUser (ctype c)
239 return (!ctype_isUnknown (c) && ctbase_isUser (ctype_getCtbase (c)));
243 ctype_isAbstract (ctype c)
245 return (!ctype_isUnknown (c)
246 && ((ctype_isPlain (c) && ctbase_isAbstract (ctype_getCtbaseSafe (c))) ||
248 (ctype_isAbstract (ctype_getConjA (c))
249 || ctype_isAbstract (ctype_getConjB (c))))));
253 ctype_isImmutableAbstract (ctype t)
255 return (ctype_isAbstract (t) && !ctype_isMutable (t));
259 ctype_isRealAbstract (ctype c)
261 return (ctype_isAbstract (ctype_realType (c)) ||
263 (ctype_isRealAbstract (ctype_getConjA (c)) ||
264 ctype_isRealAbstract (ctype_getConjB (c)))));
268 ** primitive creators
272 ** createPrim not necessary --- subsumed by ctype_int, etc.
276 ** ctbase_unknown --- removed argument
281 ** requires: if DerivedType (T) exists in cttable, then T->derivedType is it.
285 ctype_makePointer (ctype c)
291 else if (c == ctype_void)
293 return ctype_voidPointer;
297 ctentry cte = ctype_getCtentry (c);
298 ctype clp = ctentry_getPtr (cte);
300 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
302 ctype cnew = cttable_addDerived (CTK_PTR, ctbase_makePointer (c), c);
303 ctentry_setPtr (cte, cnew);
313 ctype ctype_makeFixedArray (ctype c, long size)
315 return (cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c));
319 ctype_makeArray (ctype c)
321 ctentry cte = ctype_getCtentry (c);
322 ctype clp = ctentry_getArray (cte);
324 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
326 ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
327 ctentry_setArray (cte, cnew);
335 ** requires c is a pointer of array
339 ctype_baseArrayPtr (ctype c)
341 ctentry cte = ctype_getCtentry (ctype_realType (c));
343 if (ctype_isConj (c))
345 if (ctype_isAP (ctype_getConjA (c)))
347 if (ctype_isAP (ctype_getConjB (c)))
349 return (ctype_makeConj (ctype_baseArrayPtr (ctype_getConjA (c)),
350 ctype_baseArrayPtr (ctype_getConjB (c))));
354 return (ctype_baseArrayPtr (ctype_getConjA (c)));
359 return (ctype_baseArrayPtr (ctype_getConjB (c)));
362 else if (ctype_isInt (c)) /* could be NULL */
364 return ctype_unknown;
368 ctype clp = ctentry_getBase (cte);
370 if (ctype_isBroken (clp))
372 llbuglit ("ctype_baseArrayPtr: bogus ctype");
380 ctype_getReturnType (ctype c)
382 if (ctype_isUnknown (c))
384 return ctype_unknown;
387 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
391 ** must be a shared pointer
394 /*@observer@*/ uentryList
395 ctype_argsFunction (ctype c)
397 if (ctype_isUnknown (c))
399 return uentryList_undefined;
402 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
406 ** Returns type with base type p and compound types from c.
408 ** i.e., c = char *[]; p = int
413 ctype_newBase (ctype c, ctype p)
415 return (ctbase_newBase (c, p));
419 ctype_sameAltTypes (ctype c1, ctype c2)
424 llassert (ctype_isConj (c1) && ctype_isConj (c2));
426 c1a = ctype_getConjA (c1);
427 c2a = ctype_getConjA (c2);
429 c1b = ctype_getConjB (c1);
430 c2b = ctype_getConjB (c2);
432 if (ctype_compare (c1a, c2a) == 0)
434 if (ctype_compare (c1b, c2b) == 0)
440 if (ctype_isConj (c1b) && ctype_isConj (c2b))
442 return ctype_sameAltTypes (c1b, c2b);
452 if (ctype_compare (c1a, c2b) == 0)
454 if (ctype_compare (c1b, c2a) == 0)
460 if (ctype_isConj (c1b) && ctype_isConj (c2a))
462 return ctype_sameAltTypes (c1b, c2a);
478 ctype_compare (ctype c1, ctype c2)
483 if (ctype_isUnknown (c1))
485 if (ctype_isUnknown (c2))
495 if (ctype_isUnknown (c2))
500 /* Can't get entries for special ctypes (elips marker) */
502 if (ctype_isElips (c1) || ctype_isElips (c2)
503 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
504 return int_compare (c1, c2);
507 ce1 = ctype_getCtentry (c1);
508 ce2 = ctype_getCtentry (c2);
510 if (ctentry_isComplex (ce1))
512 if (ctentry_isComplex (ce2))
514 return (ctbase_compare (ctype_getCtbase (c1),
515 ctype_getCtbase (c2), FALSE));
522 else if (ctentry_isComplex (ce2))
528 return (int_compare (c1, c2));
537 ** makeFunction: pointer to function returning base
541 ctype_makeParamsFunction (ctype base, /*@only@*/ uentryList p)
543 uentryList_fixImpParams (p);
544 return (ctype_makeFunction (base, p));
548 ctype_makeNFParamsFunction (ctype base, /*@only@*/ uentryList p)
550 uentryList_fixImpParams (p);
551 return (ctbase_makeNFFunction (base, p));
555 ctype_makeFunction (ctype base, /*@only@*/ uentryList p)
558 ret = ctbase_makeFunction (base, p);
562 ctype ctype_expectFunction (ctype c)
564 /* handle parenthesized declarations */
568 c = ctype_makePointer (c);
571 return (cttable_addComplex (ctbase_expectFunction (c)));
575 ** makeRealFunction: function returning base
578 ctype ctype_makeRawFunction (ctype base, uentryList p)
580 return (cttable_addComplex (ctbase_makeLiveFunction (base, p)));
588 **** this is very poorly defined
590 **** need to unify function/function pointer meaning
594 ctype_isFunction (ctype c)
596 if (ctype_isKnown (c) && ctype_isDefined (c))
598 return (ctbase_isFunction (ctype_getCtbase (c)));
607 ctype_isExpFcn (ctype c)
609 return (ctype_isKnown (c) && ctbase_isExpFcn (ctype_getCtbase (c)));
613 ctype_isVoid (ctype c)
615 return (c == CTX_VOID);
619 ctype_isArbitraryIntegral (ctype c)
621 ctype cr = ctype_realType (c);
623 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
624 || cr == ctype_signedintegral);
628 ctype_isUnsignedIntegral (ctype c)
630 ctype cr = ctype_realType (c);
632 return (cr == ctype_unsignedintegral);
636 ctype_isSignedIntegral (ctype c)
638 ctype cr = ctype_realType (c);
640 return (cr == ctype_signedintegral);
644 ctype_isInt (ctype c)
646 cprim cp = ctype_toCprim (c);
648 return (c == ctype_unknown || cprim_isAnyInt (cp)
649 || (cprim_isAnyChar (cp) && context_msgCharInt ())
650 || (c == ctype_bool && context_msgBoolInt ())
651 || (ctype_isEnum (c) && context_msgEnumInt ()));
655 ctype_isRegularInt (ctype c)
657 cprim cp = ctype_toCprim (c);
659 return (c == ctype_unknown
660 || cprim_closeEnough (cprim_int, cp)
661 || (cprim_isAnyChar (cp) && context_msgCharInt ())
662 || (c == ctype_bool && context_msgBoolInt ())
663 || (ctype_isEnum (c) && context_msgEnumInt ()));
667 ctype_isString (ctype c)
669 return (c == ctype_string
670 || (ctype_isPointer (c)
671 && ctype_isChar (ctype_baseArrayPtr (c))));
675 ctype_isChar (ctype c)
677 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
678 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
682 ctype_isUnsignedChar (ctype c)
684 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
688 ctype_isSignedChar (ctype c)
690 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
694 ** Returns true if c matches the name -booltype <bool>
698 ctype_isManifestBool (ctype c)
701 ** Changed the meaning of ctype_isBool - evs 2000-07-24
702 ** The old meaning was very convoluted!
705 ** c == CTX_BOOL - its a direct bool
706 ** c is a user/abstract type matching the bool name
707 ** (should never occur?)
710 if (ctype_isDirectBool (c)) {
712 } else if (ctype_isUA (c)) {
713 return ctype_isUserBool (c);
720 ctype_isBool (ctype c)
723 ** Changed the meaning of ctype_isBool - evs 2000-07-24
724 ** The old meaning was very convoluted!
727 ** its a manifest bool
728 ** +boolint and ctype_isInt (c)
731 if (ctype_isManifestBool (c)) {
733 } else if (context_msgBoolInt ()) {
734 return ctype_isInt (c);
740 if (context_getFlag (FLG_ABSTRACTBOOL))
742 if (typeId_isInvalid (boolType))
744 boolType = usymtab_getTypeId (context_getBoolName ());
747 if (context_hasAccess (boolType))
749 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
750 || (context_msgBoolInt ()
752 || (c == CTX_CHAR && context_msgCharInt ()))))
757 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
758 || (context_msgBoolInt ()
759 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
764 ctype_isDirectBool (ctype c)
766 return (c == CTX_BOOL);
770 ctype_isReal (ctype c)
772 return (cprim_isAnyReal (ctype_toCprim (c)));
776 ctype_isFloat (ctype c)
778 return (c == ctype_float);
782 ctype_isDouble (ctype c)
784 return (c == ctype_double || c == ctype_ldouble);
788 ctype_isSigned (ctype c)
790 return (!ctype_isUnsigned (c));
794 ctype_isNumeric (ctype c)
796 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c));
803 ** work on actual type in current context
807 ctype_isRealNumeric (ctype c)
809 if (ctype_isPlain (c))
810 return (ctype_isNumeric (ctype_realType (c)));
811 if (ctype_isConj (c))
812 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
813 ctype_isRealNumeric (ctype_getConjB (c)));
819 ctype_isRealInt (ctype c)
821 if (ctype_isPlain (c))
822 return (ctype_isInt (ctype_realType (c)));
823 else if (ctype_isConj (c))
824 return (ctype_isRealInt (ctype_getConjA (c)) ||
825 ctype_isRealInt (ctype_getConjB (c)));
828 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
834 ctype_isRealVoid (ctype c)
836 if (ctype_isPlain (c))
838 return (ctype_isVoid (ctype_realType (c)));
840 else if (ctype_isConj (c))
842 return (ctype_isRealVoid (ctype_getConjA (c)) ||
843 ctype_isRealVoid (ctype_getConjB (c)));
852 ctype_isRealBool (ctype c)
854 if (ctype_isPlain (c))
856 return (ctype_isBool (ctype_realishType (c)));
858 else if (ctype_isConj (c))
860 return (ctype_isRealBool (ctype_getConjA (c)) ||
861 ctype_isRealBool (ctype_getConjB (c)));
870 ctype_isRealPointer (ctype c)
872 if (ctype_isConj (c))
873 return (ctype_isRealPointer (ctype_getConjA (c)) ||
874 ctype_isRealPointer (ctype_getConjB (c)));
875 return (ctype_isPointer (ctype_realType (c)));
879 ctype_isRealSU (ctype c)
881 if (ctype_isConj (c))
883 return (ctype_isRealSU (ctype_getConjA (c)) ||
884 ctype_isRealSU (ctype_getConjB (c)));
887 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
888 return (ctype_isStructorUnion (ctype_realType (c)));
892 ctype_isRealArray (ctype c)
894 if (ctype_isConj (c))
895 return (ctype_isRealArray (ctype_getConjA (c)) ||
896 ctype_isRealArray (ctype_getConjB (c)));
897 return (ctype_isArray (ctype_realType (c)));
901 ctype_isRealAP (ctype c)
903 if (ctype_isConj (c))
904 return (ctype_isRealAP (ctype_getConjA (c)) ||
905 ctype_isRealAP (ctype_getConjB (c)));
906 return (ctype_isAP (ctype_realType (c)));
910 ctype_isRealFunction (ctype c)
912 if (ctype_isConj (c))
913 return (ctype_isRealFunction (ctype_getConjA (c)) ||
914 ctype_isRealFunction (ctype_getConjB (c)));
915 return (ctype_isFunction (ctype_realType (c)));
919 ctype_isDirectInt (ctype c)
921 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
925 ** forceful predicates
927 ** take *ctype; if its a conjunct, and there is a match replace with match only.
928 ** if both match, still conjunct
932 ctype_isForcePred (ctype * c, bool (pred) (ctype))
934 if (ctype_isConj (*c))
936 ctype cbr = ctype_getConjA (*c);
940 if ((*pred) (ctype_getConjB (*c)))
953 if ((*pred) (cbr = ctype_getConjB (*c)))
961 return ((*pred) (*c));
965 ctype_isForceRealNumeric (ctype * c)
967 return (ctype_isForcePred (c, ctype_isRealNumeric));
971 ctype_isForceRealInt (ctype * c)
973 return (ctype_isForcePred (c, ctype_isRealInt));
977 ctype_isForceRealBool (ctype * c)
979 return (ctype_isForcePred (c, ctype_isRealBool));
985 ** save int/char, int/bool, other random conjuncts
989 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
991 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
995 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1003 return (ctype_makeExplicitConj (c1, c2));
1007 return (ctype_makeConj (c1, c2));
1013 ctype_makeExplicitConj (ctype c1, ctype c2)
1015 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1017 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1019 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1021 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1023 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1025 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1029 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1033 static ctype ic = ctype_unknown; /* int | char */
1034 static ctype ib = ctype_unknown; /* int | bool */
1035 static ctype ifl = ctype_unknown; /* int | float */
1036 static ctype ibf = ctype_unknown; /* int | bool | float */
1037 static ctype ibc = ctype_unknown; /* int | bool | char */
1038 static ctype iv = ctype_unknown; /* int | void * */
1039 static ctype ivf = ctype_unknown; /* int | void * | float */
1040 static ctype ivb = ctype_unknown; /* int | void * | bool */
1041 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1042 static ctype cuc = ctype_unknown; /* char | unsigned char */
1045 ctype_recordConj (ctype c)
1049 llassert (ctype_isConj (c));
1051 c1 = ctype_getConjA (c);
1052 c2 = ctype_getConjB (c);
1055 if (c2 == ctype_int && c1 != ctype_int)
1065 if (c1 == ctype_int)
1067 if (c2 == ctype_char)
1069 llassert (ic == ctype_unknown);
1072 else if (c2 == ctype_bool)
1074 llassert (ib == ctype_unknown);
1077 else if (c2 == ctype_float)
1079 llassert (ifl == ctype_unknown);
1082 else if (c2 == CTP_VOID)
1084 llassert (iv == ctype_unknown);
1092 else if (c1 == ib && ib != ctype_unknown)
1094 if (c2 == ctype_float)
1096 llassert (ibf == ctype_unknown);
1099 else if (c2 == ctype_char)
1101 llassert (ibc == ctype_unknown);
1111 if (c2 == ctype_bool)
1113 llassert (ivb == ctype_unknown);
1116 else if (c2 == ctype_float)
1118 llassert (ivf == ctype_unknown);
1128 if (c2 == ctype_bool)
1130 llassert (ivbf == ctype_unknown);
1136 if (c2 == ctype_float)
1138 llassert (ivbf == ctype_unknown);
1142 else if (c1 == ctype_char)
1144 if (c2 == ctype_uchar)
1146 llassert (cuc == ctype_unknown);
1158 ctype_makeConj (ctype c1, ctype c2)
1160 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1162 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1164 if (ctype_isUnknown (c1))
1168 else if (ctype_isUnknown (c2))
1172 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1174 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1175 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1177 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1179 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1180 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1184 if (ctype_isManifestBool (c1))
1189 if (ctype_isManifestBool (c2))
1194 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1196 c1 = ctype_voidPointer;
1199 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1201 c2 = ctype_voidPointer;
1205 ** Ouch, can't do this. unsigned, etc. modifiers might
1206 ** apply to wrong type!
1208 ** if (c2 == ctype_int && c1 != ctype_int)
1219 if (c1 == ctype_int)
1221 if (c2 == ctype_char)
1223 if (ic == ctype_unknown)
1225 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1230 else if (c2 == ctype_bool)
1232 if (ib == ctype_unknown)
1234 ib = cttable_addComplex
1235 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1240 else if (c2 == ctype_float)
1242 if (ifl == ctype_unknown)
1244 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1251 if (c2 == ctype_voidPointer)
1253 if (iv == ctype_unknown)
1255 iv = cttable_addComplex
1256 (ctbase_makeConj (ctype_int,
1265 else if (c1 == ib && ib != ctype_unknown)
1267 if (c2 == ctype_float)
1269 if (ibf == ctype_unknown)
1271 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1276 else if (c2 == ctype_char)
1278 if (ibc == ctype_unknown)
1280 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1292 if (c2 == ctype_bool)
1294 if (ivb == ctype_unknown)
1296 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1301 else if (c2 == ctype_float)
1303 if (ivf == ctype_unknown)
1305 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1317 if (c2 == ctype_bool)
1319 if (ivbf == ctype_unknown)
1321 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1329 if (c2 == ctype_float)
1331 if (ivbf == ctype_unknown)
1333 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1339 else if (c1 == ctype_char)
1341 if (c2 == ctype_uchar)
1343 if (cuc == ctype_unknown)
1345 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1357 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1363 ctype_isConj (ctype c)
1365 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1369 ctype_getConjA (ctype c)
1371 if (!ctype_isConj (c))
1372 llbuglit ("ctype_getConjA: not a conj");
1373 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1377 ctype_getConjB (ctype c)
1379 if (!ctype_isConj (c))
1380 llbuglit ("ctype_getConjB: not a conj");
1381 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1385 ctype_isExplicitConj (ctype c)
1387 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1390 /** << need to fix resolveConj >> **/
1393 ** structs and unions
1397 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1401 DPRINTF (("Creating a struct: %s / %s",
1402 n, uentryList_unparse (f)));
1404 ct = cttable_addComplex (ctbase_createStruct (n, f));
1405 DPRINTF (("ct: %s", ctype_unparse (ct)));
1410 ctype_getFields (ctype c)
1412 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1416 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1420 ret = cttable_addComplex (ctbase_createUnion (n, f));
1427 ** if ctype's are same, definite match.
1428 ** else, need to call ctbase_match.
1430 ** if necessary context can memoize matches
1434 quickMatch (ctype c1, ctype c2)
1443 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1447 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1449 if (quickMatch (c1, c2))
1454 if (ctype_isElips (c1) || ctype_isElips (c2))
1460 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1466 ctype_sameName (ctype c1, ctype c2)
1468 if (quickMatch (c1, c2))
1471 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1475 ctype_almostEqual (ctype c1, ctype c2)
1477 if (ctype_equal (c1, c2))
1483 if (ctype_isUnknown (c1))
1485 return ctype_isUnknown (c2);
1487 else if (ctype_isUnknown (c2))
1493 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1499 ctype_matchDef (ctype c1, ctype c2)
1501 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1503 if (quickMatch (c1, c2))
1506 if (ctype_isElips (c1))
1507 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1509 if (ctype_isElips (c2))
1511 return (ctype_isUnknown (c2));
1515 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1518 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1519 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1520 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1525 bool ctype_match (ctype c1, ctype c2)
1527 if (quickMatch (c1, c2))
1530 if (ctype_isElips (c1))
1531 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1533 if (ctype_isElips (c2))
1534 return (ctype_isUnknown (c2));
1536 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1540 ctype_forceMatch (ctype c1, ctype c2)
1542 if (quickMatch (c1, c2))
1545 if (ctype_isElips (c1))
1546 return (ctype_isElips (c2));
1548 if (ctype_isElips (c2))
1552 /* The call forceMatch may modify the observer params, but, we don't care. */
1553 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1558 ctype_matchArg (ctype c1, ctype c2)
1560 if (quickMatch (c1, c2))
1566 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1571 ** simple ctype_is operations.
1572 ** DO NOT use real type of c, only direct type.
1576 ** ctype_isVoidPointer
1582 ctype_isVoidPointer (ctype c)
1584 if (ctype_isComplex (c))
1586 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1588 if (ctype_isConj (c))
1590 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1591 ctype_isVoidPointer (ctype_getConjB (c)));
1595 return (c == ctype_voidPointer
1596 || (ctype_isRealPointer (c)
1597 && ctype_isVoid (ctype_baseArrayPtr (c))));
1604 ** true for C and LCL pointers
1608 ctype_isPointer (ctype c)
1610 if (ctype_isElips (c)) return FALSE;
1612 if (ctype_isComplex (c))
1614 ctbase ctb = ctype_getCtbaseSafe (c);
1615 bool res = ctbase_isPointer (ctb);
1621 bool res = ctentry_isPointer (ctype_getCtentry (c));
1630 ** true for C and LCL array's
1634 ctype_isArray (ctype c)
1636 if (ctype_isElips (c)) return FALSE;
1638 if (ctype_isComplex (c))
1639 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1641 return (ctentry_isArray (ctype_getCtentry (c)));
1644 bool ctype_isIncompleteArray (ctype c)
1646 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1649 bool ctype_isFixedArray (ctype c)
1651 if (ctype_isElips (c)) return FALSE;
1653 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
1657 ctype_isArrayPtr (ctype c)
1659 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1663 ctype_typeId (ctype c)
1665 return (ctbase_typeId (ctype_getCtbase (c)));
1669 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1671 llassert (!(ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1673 if (ctype_isUnknown (c))
1675 return message ("? %q", name);
1679 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1684 ctype_unparse (ctype c)
1686 if (ctype_isElips (c))
1688 return cstring_makeLiteralTemp ("...");
1690 else if (ctype_isMissingParamsMarker (c))
1692 return cstring_makeLiteralTemp ("-");
1694 else if (ctype_isUnknown (c))
1696 return cstring_makeLiteralTemp ("?");
1701 return (ctentry_doUnparse (ctype_getCtentry (c)));
1707 ctype_unparseSafe (ctype c)
1709 if (ctype_isElips (c))
1711 return cstring_makeLiteralTemp ("...");
1713 else if (ctype_isMissingParamsMarker (c))
1715 return cstring_makeLiteralTemp ("-");
1721 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1723 ctentry cte = ctype_getCtentry (c);
1725 if (cstring_isDefined (cte->unparse))
1727 return (cte->unparse);
1731 ret = message ("[%d]", (int) c);
1732 cstring_markOwned (ret);
1738 ctype_unparseDeep (ctype c)
1740 if (ctype_isElips (c))
1742 return cstring_makeLiteralTemp ("...");
1744 if (ctype_isMissingParamsMarker (c))
1746 return cstring_makeLiteralTemp ("-");
1749 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1753 ctype_undump (char **c)
1755 return ((ctype) reader_getInt (c)); /* check its valid? */
1759 ctype_dump (ctype c)
1761 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1765 /* Handle invalid types in a kludgey way. */
1766 return (message ("0"));
1771 cstring tname = usymtab_getTypeEntryName
1772 (usymtab_convertId (ctype_typeId (c)));
1774 if (cstring_equal (tname, context_getBoolName ()))
1776 cstring_free (tname);
1777 return (message ("%d", ctype_bool));
1780 cstring_free (tname);
1783 DPRINTF (("Returning: %d", c));
1784 return (message ("%d", c));
1788 ctype_getBaseType (ctype c)
1790 ctentry cte = ctype_getCtentry (c);
1792 switch (ctentry_getKind (cte))
1800 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1803 ctbase ctb = cte->ctbase;
1805 if (ctbase_isDefined (ctb))
1824 return (ctype_getBaseType (ctb->contents.base));
1826 return (ctype_getBaseType (ctb->contents.farray->base));
1827 case CT_CONJ: /* base type of A conj branch? */
1828 return (ctype_getBaseType (ctb->contents.conj->a));
1830 /*@noaccess ctbase@*/
1838 llbuglit ("ctype_newBase: bad case");
1840 llcontbuglit ("ctype_getBaseType: unreachable code");
1841 return ((ctype)NULL);
1845 ctype_adjustPointers (int np, ctype c)
1848 if (ctype_isFunction (c))
1850 c = ctype_makeParamsFunction
1851 (ctype_adjustPointers (np, ctype_getReturnType (c)),
1852 uentryList_copy (ctype_argsFunction (c)));
1856 /* fix this should not use getBaseType ??? */
1857 ctype cb = ctype_getBaseType (c);
1861 cb = ctype_makePointer (cb);
1864 c = ctype_newBase (c, cb);
1872 ctype_elist (ctype c)
1874 return (ctbase_elist (ctype_getCtbase (c)));
1878 ctype_isFirstVoid (ctype c)
1880 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
1884 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
1886 return (cttable_addComplex (ctbase_createEnum (tag, el)));
1890 ctype_isEnum (ctype c)
1892 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
1896 ctype_enumTag (ctype c)
1898 llassert (ctype_isEnum (c));
1900 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
1904 ctype_isStruct (ctype c)
1906 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
1910 ctype_isUnion (ctype c)
1912 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
1916 ctype_resolveNumerics (ctype c1, ctype c2)
1919 ** returns longest type of c1 and c2
1922 if (c1 == c2) return c1;
1924 c1 = ctype_realType (c1);
1925 c2 = ctype_realType (c2);
1927 if (ctype_isEnum (c1)) c1 = ctype_unknown;
1928 if (ctype_isEnum (c2)) c2 = ctype_int;
1930 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
1932 /* 2001-06-08: This fix provided by Jim Zelenka. */
1933 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
1934 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
1936 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
1937 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
1938 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
1939 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
1941 /* 2001-06-08: This fix provided by Jim Zelenka. */
1942 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
1944 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
1946 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
1947 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
1949 if (ctype_isKnown (c1)) return c1;
1954 ctype_isStructorUnion (ctype c)
1956 return (ctype_isStruct (c) || ctype_isUnion (c));
1960 ctype_fixArrayPtr (ctype c)
1962 if (ctype_isArray (c))
1964 return (ctype_makePointer (ctype_baseArrayPtr (c)));
1971 ** createUnnamedStruct/Union
1973 ** check if it corresponds to an existing LCL-specified unnamed struct
1974 ** otherwise, give it a new tag
1978 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
1980 ctype ret = usymtab_structFieldsType (f);
1982 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
1984 if (ctype_isDefined (ret))
1986 uentryList_free (f);
1991 cstring ft = fakeTag ();
1992 ctype ct = ctype_createStruct (cstring_copy (ft), f);
1993 uentry ue = uentry_makeStructTagLoc (ft, ct);
1995 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
1996 ue = usymtab_supGlobalEntryReturn (ue);
1997 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2005 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2007 ctype ret = usymtab_unionFieldsType (f);
2009 if (ctype_isDefined (ret))
2011 uentryList_free (f);
2016 cstring ft = fakeTag ();
2017 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2018 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2020 usymtab_supGlobalEntry (ue);
2027 ctype_isUnnamedSU (ctype c)
2031 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2040 ctype_createForwardStruct (cstring n)
2042 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2043 ctype ct = usymtab_supForwardTypeEntry (ue);
2050 ctype_createForwardUnion (cstring n)
2052 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2053 ctype ct = usymtab_supForwardTypeEntry (ue);
2060 ctype_removePointers (ctype c)
2064 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2067 c = ctype_baseArrayPtr (c);
2068 llassert (c != oldc);
2074 bool ctype_isMutable (ctype t)
2078 return (uentry_isMutableDatatype
2079 (usymtab_getTypeEntry (ctype_typeId (t))));
2083 return (ctype_isPointer (ctype_realType (t)));
2084 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2088 bool ctype_isRefCounted (ctype t)
2092 return (uentry_isRefCountedDatatype
2093 (usymtab_getTypeEntry (ctype_typeId (t))));
2099 bool ctype_isVisiblySharable (ctype t)
2101 if (ctype_isUnknown (t)) return TRUE;
2103 if (ctype_isConj (t))
2105 return (ctype_isVisiblySharable (ctype_getConjA (t))
2106 || ctype_isVisiblySharable (ctype_getConjB (t)));
2109 if (ctype_isMutable (t))
2113 ctype rt = ctype_realType (t);
2121 return ctype_isVisiblySharable (rt);
2135 /* Replaced by ctype_isMutable (more sensible) */
2136 bool ctype_canAlias (ctype ct)
2138 /* can ct refer to memory locations?
2139 ** ==> a pointer or a mutable abstract type
2143 ctype tr = ctype_realType (ct);
2145 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2150 ** c1 is the dominant type; c2 is the modifier type
2152 ** eg. double + long int => long double
2155 ctype ctype_combine (ctype dominant, ctype modifier)
2157 DPRINTF (("Combine: %s + %s",
2158 ctype_unparse (dominant),
2159 ctype_unparse (modifier)));
2161 if (ctype_isConj (dominant))
2165 if (ctype_isExplicitConj (dominant))
2167 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2169 ctype_getConjB (dominant));
2173 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2175 ctype_getConjB (dominant));
2181 if (ctype_isUnknown (modifier))
2185 else if (ctype_isUnknown (dominant))
2191 if (ctype_isEnum (dominant)) dominant = ctype_int;
2192 if (ctype_isEnum (modifier)) modifier = ctype_int;
2194 if (modifier == ctype_uint)
2196 if (dominant == ctype_int) return ctype_uint;
2197 if (dominant == ctype_lint) return ctype_ulint;
2198 if (dominant == ctype_sint) return ctype_usint;
2199 if (dominant == ctype_char) return ctype_uchar;
2201 /* evs 2000-07-28: added this line */
2202 if (dominant == ctype_llint) return ctype_ullint;
2204 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2206 voptgenerror (FLG_DUPLICATEQUALS,
2207 message ("Duplicate unsigned qualifier"),
2214 voptgenerror (FLG_DUPLICATEQUALS,
2215 message ("Type qualifier unsigned used with %s",
2216 ctype_unparse (dominant)),
2222 else if (modifier == ctype_llint)
2224 if (dominant == ctype_int)
2229 voptgenerror (FLG_DUPLICATEQUALS,
2230 message ("Duplicate long qualifier on non-int"),
2233 else if (modifier == ctype_lint)
2235 if (dominant == ctype_int) return ctype_lint;
2236 if (dominant == ctype_uint) return ctype_ulint;
2237 if (dominant == ctype_double) return ctype_ldouble;
2239 if (dominant == ctype_lint || dominant == ctype_ulint
2240 || dominant == ctype_sint || dominant == ctype_usint
2241 || dominant == ctype_ldouble)
2243 if (dominant == ctype_lint)
2245 /* long long not supported by ANSI */
2250 if (dominant == ctype_ulint)
2252 /* unsigned long long not supported by ANSI */
2253 return ctype_ullint;
2257 if (dominant == ctype_sint || dominant == ctype_usint)
2259 if (!context_getFlag (FLG_IGNOREQUALS))
2261 llerrorlit (FLG_SYNTAX,
2262 "Contradictory long and short type qualifiers");
2267 voptgenerror (FLG_DUPLICATEQUALS,
2268 message ("Duplicate long qualifier"),
2275 else if (modifier == ctype_sint)
2277 if (dominant == ctype_int) return ctype_sint;
2278 if (dominant == ctype_uint) return ctype_usint;
2280 if (dominant == ctype_sint || dominant == ctype_usint)
2282 voptgenerror (FLG_DUPLICATEQUALS,
2283 message ("Duplicate short qualifier"),
2287 else if (dominant == ctype_lint)
2289 if (!context_getFlag (FLG_IGNOREQUALS))
2291 llerrorlit (FLG_SYNTAX,
2292 "Contradictory long and short type qualifiers");
2298 else if (dominant == ctype_llint)
2300 if (!context_getFlag (FLG_IGNOREQUALS))
2302 llerrorlit (FLG_SYNTAX,
2303 "Contradictory long long and short type qualifiers");
2311 if (!context_getFlag (FLG_IGNOREQUALS))
2313 llerror (FLG_SYNTAX,
2314 message ("Type qualifier short used with %s",
2315 ctype_unparse (dominant)));
2321 else if (modifier == ctype_ulint)
2323 if (dominant == ctype_int) return modifier;
2325 if (dominant == ctype_lint || dominant == ctype_ulint)
2327 voptgenerror (FLG_DUPLICATEQUALS,
2328 message ("Duplicate long qualifier"),
2334 if (dominant == ctype_uint || dominant == ctype_usint)
2336 voptgenerror (FLG_DUPLICATEQUALS,
2337 message ("Duplicate unsigned qualifier"),
2343 if (dominant == ctype_sint || dominant == ctype_usint)
2345 if (!context_getFlag (FLG_IGNOREQUALS))
2347 llerrorlit (FLG_SYNTAX,
2348 "Contradictory long and short type qualifiers");
2354 if (!context_getFlag (FLG_IGNOREQUALS))
2356 llerror (FLG_SYNTAX,
2357 message ("Type qualifiers unsigned long used with %s",
2358 ctype_unparse (dominant)));
2363 else if (modifier == ctype_usint)
2365 if (dominant == ctype_int) return modifier;
2367 if (dominant == ctype_sint || dominant == ctype_usint)
2369 voptgenerror (FLG_DUPLICATEQUALS,
2370 message ("Duplicate short qualifier"),
2375 if (dominant == ctype_uint)
2377 voptgenerror (FLG_DUPLICATEQUALS,
2378 message ("Duplicate unsigned qualifier"),
2384 if (dominant == ctype_lint || dominant == ctype_ulint
2385 || dominant == ctype_llint)
2387 if (!context_getFlag (FLG_IGNOREQUALS))
2389 llerrorlit (FLG_SYNTAX,
2390 "Contradictory long and short type qualifiers");
2396 if (!context_getFlag (FLG_IGNOREQUALS))
2398 llerror (FLG_SYNTAX,
2399 message ("Type qualifiers unsigned short used with %s",
2400 ctype_unparse (dominant)));
2414 ctype ctype_resolve (ctype c)
2416 if (ctype_isUnknown (c)) return ctype_int;
2420 ctype ctype_fromQual (qual q)
2422 if (qual_isSigned (q)) return ctype_int;
2423 if (qual_isUnsigned (q)) return ctype_uint;
2424 if (qual_isLong (q)) return ctype_lint;
2425 if (qual_isShort (q)) return ctype_sint;
2427 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2428 return ctype_unknown;
2432 ctype_isAnyFloat (ctype c)
2434 return (cprim_isAnyReal (ctype_toCprim (c)));
2438 ctype_isUnsigned (ctype c)
2440 if (ctype_isConj (c))
2441 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2442 ctype_isUnsigned (ctype_getConjB (c)));
2444 return (c == ctype_uint || c == ctype_uchar
2445 || c == ctype_usint || c == ctype_ulint
2446 || c == ctype_ullint
2447 || c == ctype_unsignedintegral);
2452 ctype_isLongLong (ctype c)
2454 if (ctype_isConj (c))
2455 return (ctype_isLongLong (ctype_getConjA (c)) ||
2456 ctype_isLongLong (ctype_getConjB (c)));
2458 return (c == ctype_llint || c == ctype_ullint);
2463 ctype_isLong (ctype c)
2465 if (ctype_isConj (c))
2466 return (ctype_isLong (ctype_getConjA (c)) ||
2467 ctype_isLong (ctype_getConjB (c)));
2469 return (c == ctype_lint || c == ctype_ulint);
2473 ctype_isShort (ctype c)
2475 if (ctype_isConj (c))
2476 return (ctype_isShort (ctype_getConjA (c)) ||
2477 ctype_isShort (ctype_getConjB (c)));
2479 return (c == ctype_sint || c == ctype_usint);
2483 ctype_isStackAllocated (ctype c)
2485 ctype ct = ctype_realType (c);
2487 if (ctype_isConj (ct))
2488 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2489 ctype_isStackAllocated (ctype_getConjB (ct)));
2491 return (ctype_isArray (c) || ctype_isSU (c));
2494 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2496 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2499 static bool ctype_isLonger (ctype c1, ctype c2)
2501 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2502 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2503 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2504 || (ctype_isLong (c1)
2505 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2506 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2510 ctype_widest (ctype c1, ctype c2)
2512 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2522 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2525 if (c >= 0 && c < cttab.size)
2527 return (cttab.entries[c]->ctbase);
2531 if (c == ctype_unknown)
2532 llbuglit ("ctype_getCtbase: ctype unknown");
2533 if (c == ctype_undefined)
2534 llbuglit ("ctype_getCtbase: ctype undefined");
2536 llbuglit ("ctype_getCtbase: ctype dne");
2537 if (c == ctype_elipsMarker)
2538 llbuglit ("ctype_getCtbase: elips marker");
2540 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2547 static /*@notnull@*/ /*@observer@*/ ctbase
2548 ctype_getCtbaseSafe (ctype c)
2550 ctbase res = ctype_getCtbase (c);
2552 llassert (ctbase_isDefined (res));
2561 ctype_getCtentry (ctype c)
2563 static /*@only@*/ ctentry errorEntry = NULL;
2565 if (cttab.size == 0)
2567 if (errorEntry == NULL)
2569 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2576 if (c >= CTK_PLAIN && c < cttab.size)
2578 return (cttab.entries[c]);
2580 else if (c == CTK_UNKNOWN)
2581 llcontbuglit ("ctype_getCtentry: ctype unknown");
2582 else if (c == CTK_INVALID)
2583 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2584 else if (c == CTK_DNE)
2585 llcontbuglit ("ctype_getCtentry: ctype dne");
2586 else if (c == CTK_ELIPS)
2587 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2588 else if (c == CTK_MISSINGPARAMS)
2589 llcontbuglit ("ctype_getCtentry: ctype missing params");
2591 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2593 return (cttab.entries[ctype_unknown]);
2598 /* requires that the type is an fixed array */
2599 /* return the size of the array */
2601 long int ctype_getArraySize (ctype c)
2604 ctentry cte = ctype_getCtentry (c);
2606 llassert ( (ctentry_getKind (cte) == CTK_COMPLEX) || (ctentry_getKind(cte) == CTK_ARRAY) );
2610 size = ctbase_getArraySize (ctb);
2612 DPRINTF(( message("ctype_getArraySize: got fixed array size of %d ", (int)size) ));