2 ** Splint - 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://www.splint.org
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)
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");
385 ctype_getReturnType (ctype c)
387 if (ctype_isUnknown (c))
389 return ctype_unknown;
392 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
396 ** must be a shared pointer
399 /*@observer@*/ uentryList
400 ctype_argsFunction (ctype c)
402 if (ctype_isUnknown (c))
404 return uentryList_undefined;
407 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
411 ** Returns type with base type p and compound types from c.
413 ** i.e., c = char *[]; p = int
418 ctype_newBase (ctype c, ctype p)
420 return (ctbase_newBase (c, p));
424 ctype_sameAltTypes (ctype c1, ctype c2)
429 llassert (ctype_isConj (c1) && ctype_isConj (c2));
431 c1a = ctype_getConjA (c1);
432 c2a = ctype_getConjA (c2);
434 c1b = ctype_getConjB (c1);
435 c2b = ctype_getConjB (c2);
437 if (ctype_compare (c1a, c2a) == 0)
439 if (ctype_compare (c1b, c2b) == 0)
445 if (ctype_isConj (c1b) && ctype_isConj (c2b))
447 return ctype_sameAltTypes (c1b, c2b);
457 if (ctype_compare (c1a, c2b) == 0)
459 if (ctype_compare (c1b, c2a) == 0)
465 if (ctype_isConj (c1b) && ctype_isConj (c2a))
467 return ctype_sameAltTypes (c1b, c2a);
483 ctype_compare (ctype c1, ctype c2)
488 if (ctype_isUnknown (c1))
490 if (ctype_isUnknown (c2))
500 if (ctype_isUnknown (c2))
505 /* Can't get entries for special ctypes (elips marker) */
507 if (ctype_isElips (c1) || ctype_isElips (c2)
508 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
509 return int_compare (c1, c2);
512 ce1 = ctype_getCtentry (c1);
513 ce2 = ctype_getCtentry (c2);
515 if (ctentry_isComplex (ce1))
517 if (ctentry_isComplex (ce2))
519 return (ctbase_compare (ctype_getCtbase (c1),
520 ctype_getCtbase (c2), FALSE));
527 else if (ctentry_isComplex (ce2))
533 return (int_compare (c1, c2));
542 ** makeFunction: pointer to function returning base
546 ctype_makeParamsFunction (ctype base, /*@only@*/ uentryList p)
548 uentryList_fixImpParams (p);
549 return (ctype_makeFunction (base, p));
553 ctype_makeNFParamsFunction (ctype base, /*@only@*/ uentryList p)
555 uentryList_fixImpParams (p);
556 return (ctbase_makeNFFunction (base, p));
560 ctype_makeFunction (ctype base, /*@only@*/ uentryList p)
563 ret = ctbase_makeFunction (base, p);
567 ctype ctype_expectFunction (ctype c)
569 /* handle parenthesized declarations */
573 c = ctype_makePointer (c);
576 return (cttable_addComplex (ctbase_expectFunction (c)));
580 ** makeRealFunction: function returning base
583 ctype ctype_makeRawFunction (ctype base, uentryList p)
585 return (cttable_addComplex (ctbase_makeLiveFunction (base, p)));
593 **** this is very poorly defined
595 **** need to unify function/function pointer meaning
599 ctype_isFunction (ctype c)
601 if (ctype_isKnown (c) && ctype_isDefined (c))
603 return (ctbase_isFunction (ctype_getCtbase (c)));
612 ctype_isExpFcn (ctype c)
614 return (ctype_isKnown (c) && ctbase_isExpFcn (ctype_getCtbase (c)));
618 ctype_isVoid (ctype c)
620 return (c == CTX_VOID);
624 ctype_isArbitraryIntegral (ctype c)
626 ctype cr = ctype_realType (c);
628 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
629 || cr == ctype_signedintegral);
633 ctype_isUnsignedIntegral (ctype c)
635 ctype cr = ctype_realType (c);
637 return (cr == ctype_unsignedintegral);
641 ctype_isSignedIntegral (ctype c)
643 ctype cr = ctype_realType (c);
645 return (cr == ctype_signedintegral);
649 ctype_isInt (ctype c)
651 cprim cp = ctype_toCprim (c);
653 return (c == ctype_unknown || cprim_isAnyInt (cp)
654 || (cprim_isAnyChar (cp) && context_msgCharInt ())
655 || (c == ctype_bool && context_msgBoolInt ())
656 || (ctype_isEnum (c) && context_msgEnumInt ()));
660 ctype_isRegularInt (ctype c)
662 cprim cp = ctype_toCprim (c);
664 return (c == ctype_unknown
665 || cprim_closeEnough (cprim_int, cp)
666 || (cprim_isAnyChar (cp) && context_msgCharInt ())
667 || (c == ctype_bool && context_msgBoolInt ())
668 || (ctype_isEnum (c) && context_msgEnumInt ()));
672 ctype_isString (ctype c)
674 return (c == ctype_string
675 || (ctype_isPointer (c)
676 && ctype_isChar (ctype_baseArrayPtr (c))));
680 ctype_isChar (ctype c)
682 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
683 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
687 ctype_isUnsignedChar (ctype c)
689 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
693 ctype_isSignedChar (ctype c)
695 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
699 ** Returns true if c matches the name -booltype <bool>
703 ctype_isManifestBool (ctype c)
706 ** Changed the meaning of ctype_isBool - evs 2000-07-24
707 ** The old meaning was very convoluted!
710 ** c == CTX_BOOL - its a direct bool
711 ** c is a user/abstract type matching the bool name
712 ** (should never occur?)
715 if (ctype_isDirectBool (c)) {
717 } else if (ctype_isUA (c)) {
718 return ctype_isUserBool (c);
725 ctype_isBool (ctype c)
728 ** Changed the meaning of ctype_isBool - evs 2000-07-24
729 ** The old meaning was very convoluted!
732 ** its a manifest bool
733 ** +boolint and ctype_isInt (c)
736 if (ctype_isManifestBool (c)) {
738 } else if (context_msgBoolInt ()) {
739 return ctype_isInt (c);
745 if (context_getFlag (FLG_ABSTRACTBOOL))
747 if (typeId_isInvalid (boolType))
749 boolType = usymtab_getTypeId (context_getBoolName ());
752 if (context_hasAccess (boolType))
754 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
755 || (context_msgBoolInt ()
757 || (c == CTX_CHAR && context_msgCharInt ()))))
762 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
763 || (context_msgBoolInt ()
764 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
769 ctype_isDirectBool (ctype c)
771 return (c == CTX_BOOL);
775 ctype_isReal (ctype c)
777 return (cprim_isAnyReal (ctype_toCprim (c)));
781 ctype_isFloat (ctype c)
783 return (c == ctype_float);
787 ctype_isDouble (ctype c)
789 return (c == ctype_double || c == ctype_ldouble);
793 ctype_isSigned (ctype c)
795 return (!ctype_isUnsigned (c));
799 ctype_isNumeric (ctype c)
801 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c)
802 /* evans 2001-10-05: added this: */
803 || ctype_isArbitraryIntegral (c));
810 ** work on actual type in current context
814 ctype_isRealNumeric (ctype c)
816 if (ctype_isPlain (c))
817 return (ctype_isNumeric (ctype_realType (c)));
818 if (ctype_isConj (c))
819 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
820 ctype_isRealNumeric (ctype_getConjB (c)));
826 ctype_isRealInt (ctype c)
828 if (ctype_isPlain (c))
829 return (ctype_isInt (ctype_realType (c)));
830 else if (ctype_isConj (c))
831 return (ctype_isRealInt (ctype_getConjA (c)) ||
832 ctype_isRealInt (ctype_getConjB (c)));
835 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
841 ctype_isRealVoid (ctype c)
843 if (ctype_isPlain (c))
845 return (ctype_isVoid (ctype_realType (c)));
847 else if (ctype_isConj (c))
849 return (ctype_isRealVoid (ctype_getConjA (c)) ||
850 ctype_isRealVoid (ctype_getConjB (c)));
859 ctype_isRealBool (ctype c)
861 if (ctype_isPlain (c))
863 return (ctype_isBool (ctype_realishType (c)));
865 else if (ctype_isConj (c))
867 return (ctype_isRealBool (ctype_getConjA (c)) ||
868 ctype_isRealBool (ctype_getConjB (c)));
877 ctype_isRealPointer (ctype c)
879 if (ctype_isConj (c))
880 return (ctype_isRealPointer (ctype_getConjA (c)) ||
881 ctype_isRealPointer (ctype_getConjB (c)));
882 return (ctype_isPointer (ctype_realType (c)));
886 ctype_isRealSU (ctype c)
888 if (ctype_isConj (c))
890 return (ctype_isRealSU (ctype_getConjA (c)) ||
891 ctype_isRealSU (ctype_getConjB (c)));
894 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
895 return (ctype_isStructorUnion (ctype_realType (c)));
899 ctype_isRealArray (ctype c)
901 if (ctype_isConj (c))
902 return (ctype_isRealArray (ctype_getConjA (c)) ||
903 ctype_isRealArray (ctype_getConjB (c)));
904 return (ctype_isArray (ctype_realType (c)));
908 ctype_isRealAP (ctype c)
910 if (ctype_isConj (c))
911 return (ctype_isRealAP (ctype_getConjA (c)) ||
912 ctype_isRealAP (ctype_getConjB (c)));
913 return (ctype_isAP (ctype_realType (c)));
917 ctype_isRealFunction (ctype c)
919 if (ctype_isConj (c))
920 return (ctype_isRealFunction (ctype_getConjA (c)) ||
921 ctype_isRealFunction (ctype_getConjB (c)));
922 return (ctype_isFunction (ctype_realType (c)));
926 ctype_isDirectInt (ctype c)
928 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
932 ** forceful predicates
934 ** take *ctype; if its a conjunct, and there is a match replace with match only.
935 ** if both match, still conjunct
939 ctype_isForcePred (ctype * c, bool (pred) (ctype))
941 if (ctype_isConj (*c))
943 ctype cbr = ctype_getConjA (*c);
947 if ((*pred) (ctype_getConjB (*c)))
960 if ((*pred) (cbr = ctype_getConjB (*c)))
968 return ((*pred) (*c));
972 ctype_isForceRealNumeric (ctype * c)
974 return (ctype_isForcePred (c, ctype_isRealNumeric));
978 ctype_isForceRealInt (ctype * c)
980 return (ctype_isForcePred (c, ctype_isRealInt));
984 ctype_isForceRealBool (ctype * c)
986 return (ctype_isForcePred (c, ctype_isRealBool));
992 ** save int/char, int/bool, other random conjuncts
996 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
998 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
1002 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1010 return (ctype_makeExplicitConj (c1, c2));
1014 return (ctype_makeConj (c1, c2));
1020 ctype_makeExplicitConj (ctype c1, ctype c2)
1022 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1024 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1026 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1028 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1030 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1032 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1036 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1040 static ctype ic = ctype_unknown; /* int | char */
1041 static ctype ib = ctype_unknown; /* int | bool */
1042 static ctype ifl = ctype_unknown; /* int | float */
1043 static ctype ibf = ctype_unknown; /* int | bool | float */
1044 static ctype ibc = ctype_unknown; /* int | bool | char */
1045 static ctype iv = ctype_unknown; /* int | void * */
1046 static ctype ivf = ctype_unknown; /* int | void * | float */
1047 static ctype ivb = ctype_unknown; /* int | void * | bool */
1048 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1049 static ctype cuc = ctype_unknown; /* char | unsigned char */
1052 ctype_recordConj (ctype c)
1056 llassert (ctype_isConj (c));
1058 c1 = ctype_getConjA (c);
1059 c2 = ctype_getConjB (c);
1062 if (c2 == ctype_int && c1 != ctype_int)
1072 if (c1 == ctype_int)
1074 if (c2 == ctype_char)
1076 llassert (ic == ctype_unknown);
1079 else if (c2 == ctype_bool)
1081 llassert (ib == ctype_unknown);
1084 else if (c2 == ctype_float)
1086 llassert (ifl == ctype_unknown);
1089 else if (c2 == CTP_VOID)
1091 llassert (iv == ctype_unknown);
1099 else if (c1 == ib && ib != ctype_unknown)
1101 if (c2 == ctype_float)
1103 llassert (ibf == ctype_unknown);
1106 else if (c2 == ctype_char)
1108 llassert (ibc == ctype_unknown);
1118 if (c2 == ctype_bool)
1120 llassert (ivb == ctype_unknown);
1123 else if (c2 == ctype_float)
1125 llassert (ivf == ctype_unknown);
1135 if (c2 == ctype_bool)
1137 llassert (ivbf == ctype_unknown);
1143 if (c2 == ctype_float)
1145 llassert (ivbf == ctype_unknown);
1149 else if (c1 == ctype_char)
1151 if (c2 == ctype_uchar)
1153 llassert (cuc == ctype_unknown);
1165 ctype_makeConj (ctype c1, ctype c2)
1167 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1169 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1171 if (ctype_isUnknown (c1))
1175 else if (ctype_isUnknown (c2))
1179 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1181 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1182 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1184 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1186 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1187 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1191 if (ctype_isManifestBool (c1))
1196 if (ctype_isManifestBool (c2))
1201 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1203 c1 = ctype_voidPointer;
1206 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1208 c2 = ctype_voidPointer;
1212 ** Ouch, can't do this. unsigned, etc. modifiers might
1213 ** apply to wrong type!
1215 ** if (c2 == ctype_int && c1 != ctype_int)
1226 if (c1 == ctype_int)
1228 if (c2 == ctype_char)
1230 if (ic == ctype_unknown)
1232 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1237 else if (c2 == ctype_bool)
1239 if (ib == ctype_unknown)
1241 ib = cttable_addComplex
1242 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1247 else if (c2 == ctype_float)
1249 if (ifl == ctype_unknown)
1251 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1258 if (c2 == ctype_voidPointer)
1260 if (iv == ctype_unknown)
1262 iv = cttable_addComplex
1263 (ctbase_makeConj (ctype_int,
1272 else if (c1 == ib && ib != ctype_unknown)
1274 if (c2 == ctype_float)
1276 if (ibf == ctype_unknown)
1278 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1283 else if (c2 == ctype_char)
1285 if (ibc == ctype_unknown)
1287 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1299 if (c2 == ctype_bool)
1301 if (ivb == ctype_unknown)
1303 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1308 else if (c2 == ctype_float)
1310 if (ivf == ctype_unknown)
1312 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1324 if (c2 == ctype_bool)
1326 if (ivbf == ctype_unknown)
1328 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1336 if (c2 == ctype_float)
1338 if (ivbf == ctype_unknown)
1340 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1346 else if (c1 == ctype_char)
1348 if (c2 == ctype_uchar)
1350 if (cuc == ctype_unknown)
1352 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1364 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1370 ctype_isConj (ctype c)
1372 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1376 ctype_getConjA (ctype c)
1378 if (!ctype_isConj (c))
1379 llbuglit ("ctype_getConjA: not a conj");
1380 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1384 ctype_getConjB (ctype c)
1386 if (!ctype_isConj (c))
1387 llbuglit ("ctype_getConjB: not a conj");
1388 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1392 ctype_isExplicitConj (ctype c)
1394 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1397 /** << need to fix resolveConj >> **/
1400 ** structs and unions
1404 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1408 DPRINTF (("Creating a struct: %s / %s",
1409 n, uentryList_unparse (f)));
1411 ct = cttable_addComplex (ctbase_createStruct (n, f));
1412 DPRINTF (("ct: %s", ctype_unparse (ct)));
1417 ctype_getFields (ctype c)
1419 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1423 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1427 ret = cttable_addComplex (ctbase_createUnion (n, f));
1434 ** if ctype's are same, definite match.
1435 ** else, need to call ctbase_match.
1437 ** if necessary context can memoize matches
1441 quickMatch (ctype c1, ctype c2)
1450 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1454 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1456 if (quickMatch (c1, c2))
1461 if (ctype_isElips (c1) || ctype_isElips (c2))
1467 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1473 ctype_sameName (ctype c1, ctype c2)
1475 if (quickMatch (c1, c2))
1478 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1482 ctype_almostEqual (ctype c1, ctype c2)
1484 if (ctype_equal (c1, c2))
1490 if (ctype_isUnknown (c1))
1492 return ctype_isUnknown (c2);
1494 else if (ctype_isUnknown (c2))
1500 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1506 ctype_matchDef (ctype c1, ctype c2)
1508 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1510 if (quickMatch (c1, c2))
1513 if (ctype_isElips (c1))
1514 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1516 if (ctype_isElips (c2))
1518 return (ctype_isUnknown (c2));
1522 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1525 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1526 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1527 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1532 bool ctype_match (ctype c1, ctype c2)
1534 if (quickMatch (c1, c2))
1537 if (ctype_isElips (c1))
1538 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1540 if (ctype_isElips (c2))
1541 return (ctype_isUnknown (c2));
1543 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1547 ctype_forceMatch (ctype c1, ctype c2)
1549 if (quickMatch (c1, c2))
1552 if (ctype_isElips (c1))
1553 return (ctype_isElips (c2));
1555 if (ctype_isElips (c2))
1559 /* The call forceMatch may modify the observer params, but, we don't care. */
1560 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1565 ctype_matchArg (ctype c1, ctype c2)
1567 if (quickMatch (c1, c2))
1573 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1578 ** simple ctype_is operations.
1579 ** DO NOT use real type of c, only direct type.
1583 ** ctype_isVoidPointer
1589 ctype_isVoidPointer (ctype c)
1591 if (ctype_isComplex (c))
1593 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1595 if (ctype_isConj (c))
1597 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1598 ctype_isVoidPointer (ctype_getConjB (c)));
1602 return (c == ctype_voidPointer
1603 || (ctype_isRealPointer (c)
1604 && ctype_isVoid (ctype_baseArrayPtr (c))));
1611 ** true for C and LCL pointers
1615 ctype_isPointer (ctype c)
1617 if (ctype_isElips (c)) return FALSE;
1619 if (ctype_isComplex (c))
1621 ctbase ctb = ctype_getCtbaseSafe (c);
1622 bool res = ctbase_isPointer (ctb);
1628 bool res = ctentry_isPointer (ctype_getCtentry (c));
1637 ** true for C and LCL array's
1641 ctype_isArray (ctype c)
1643 if (ctype_isElips (c)) return FALSE;
1645 if (ctype_isComplex (c))
1646 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1648 return (ctentry_isArray (ctype_getCtentry (c)));
1651 bool ctype_isIncompleteArray (ctype c)
1653 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1656 bool ctype_isFixedArray (ctype c)
1658 if (ctype_isElips (c)) return FALSE;
1660 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
1664 ctype_isArrayPtr (ctype c)
1666 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1670 ctype_typeId (ctype c)
1672 return (ctbase_typeId (ctype_getCtbase (c)));
1676 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1678 llassert (!(ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1680 if (ctype_isUnknown (c))
1682 return message ("? %q", name);
1686 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1691 ctype_unparse (ctype c)
1693 if (ctype_isElips (c))
1695 return cstring_makeLiteralTemp ("...");
1697 else if (ctype_isMissingParamsMarker (c))
1699 return cstring_makeLiteralTemp ("-");
1701 else if (ctype_isUnknown (c))
1703 return cstring_makeLiteralTemp ("?");
1708 return (ctentry_doUnparse (ctype_getCtentry (c)));
1714 ctype_unparseSafe (ctype c)
1716 if (ctype_isElips (c))
1718 return cstring_makeLiteralTemp ("...");
1720 else if (ctype_isMissingParamsMarker (c))
1722 return cstring_makeLiteralTemp ("-");
1728 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1730 ctentry cte = ctype_getCtentry (c);
1732 if (cstring_isDefined (cte->unparse))
1734 return (cte->unparse);
1738 ret = message ("[%d]", (int) c);
1739 cstring_markOwned (ret);
1745 ctype_unparseDeep (ctype c)
1747 if (ctype_isElips (c))
1749 return cstring_makeLiteralTemp ("...");
1751 if (ctype_isMissingParamsMarker (c))
1753 return cstring_makeLiteralTemp ("-");
1756 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1760 ctype_undump (char **c)
1762 return ((ctype) reader_getInt (c)); /* check its valid? */
1766 ctype_dump (ctype c)
1768 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1772 /* Handle invalid types in a kludgey way. */
1773 return (message ("0"));
1778 cstring tname = usymtab_getTypeEntryName
1779 (usymtab_convertId (ctype_typeId (c)));
1781 if (cstring_equal (tname, context_getBoolName ()))
1783 cstring_free (tname);
1784 return (message ("%d", ctype_bool));
1787 cstring_free (tname);
1790 DPRINTF (("Returning: %d", c));
1791 return (message ("%d", c));
1795 ctype_getBaseType (ctype c)
1797 ctentry cte = ctype_getCtentry (c);
1799 switch (ctentry_getKind (cte))
1807 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1810 ctbase ctb = cte->ctbase;
1812 if (ctbase_isDefined (ctb))
1831 return (ctype_getBaseType (ctb->contents.base));
1833 return (ctype_getBaseType (ctb->contents.farray->base));
1834 case CT_CONJ: /* base type of A conj branch? */
1835 return (ctype_getBaseType (ctb->contents.conj->a));
1837 /*@noaccess ctbase@*/
1845 llbuglit ("ctype_newBase: bad case");
1847 llcontbuglit ("ctype_getBaseType: unreachable code");
1848 return ((ctype)NULL);
1852 ctype_adjustPointers (int np, ctype c)
1855 if (ctype_isFunction (c))
1857 c = ctype_makeParamsFunction
1858 (ctype_adjustPointers (np, ctype_getReturnType (c)),
1859 uentryList_copy (ctype_argsFunction (c)));
1863 /* fix this should not use getBaseType ??? */
1864 ctype cb = ctype_getBaseType (c);
1868 cb = ctype_makePointer (cb);
1871 c = ctype_newBase (c, cb);
1879 ctype_elist (ctype c)
1881 return (ctbase_elist (ctype_getCtbase (c)));
1885 ctype_isFirstVoid (ctype c)
1887 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
1891 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
1893 return (cttable_addComplex (ctbase_createEnum (tag, el)));
1897 ctype_isEnum (ctype c)
1899 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
1903 ctype_enumTag (ctype c)
1905 llassert (ctype_isEnum (c));
1907 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
1911 ctype_isStruct (ctype c)
1913 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
1917 ctype_isUnion (ctype c)
1919 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
1923 ctype_resolveNumerics (ctype c1, ctype c2)
1926 ** returns longest type of c1 and c2
1929 if (c1 == c2) return c1;
1931 c1 = ctype_realType (c1);
1932 c2 = ctype_realType (c2);
1934 if (ctype_isEnum (c1)) c1 = ctype_unknown;
1935 if (ctype_isEnum (c2)) c2 = ctype_int;
1937 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
1939 /* 2001-06-08: This fix provided by Jim Zelenka. */
1940 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
1941 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
1943 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
1944 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
1945 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
1946 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
1948 /* 2001-06-08: This fix provided by Jim Zelenka. */
1949 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
1951 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
1953 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
1954 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
1956 if (ctype_isKnown (c1)) return c1;
1961 ctype_isStructorUnion (ctype c)
1963 return (ctype_isStruct (c) || ctype_isUnion (c));
1967 ctype_fixArrayPtr (ctype c)
1969 if (ctype_isArray (c))
1971 return (ctype_makePointer (ctype_baseArrayPtr (c)));
1978 ** createUnnamedStruct/Union
1980 ** check if it corresponds to an existing LCL-specified unnamed struct
1981 ** otherwise, give it a new tag
1985 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
1987 ctype ret = usymtab_structFieldsType (f);
1989 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
1991 if (ctype_isDefined (ret))
1993 uentryList_free (f);
1998 cstring ft = fakeTag ();
1999 ctype ct = ctype_createStruct (cstring_copy (ft), f);
2000 uentry ue = uentry_makeStructTagLoc (ft, ct);
2002 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2003 ue = usymtab_supGlobalEntryReturn (ue);
2004 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2012 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2014 ctype ret = usymtab_unionFieldsType (f);
2016 if (ctype_isDefined (ret))
2018 uentryList_free (f);
2023 cstring ft = fakeTag ();
2024 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2025 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2027 usymtab_supGlobalEntry (ue);
2034 ctype_isUnnamedSU (ctype c)
2038 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2047 ctype_createForwardStruct (cstring n)
2049 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2050 ctype ct = usymtab_supForwardTypeEntry (ue);
2057 ctype_createForwardUnion (cstring n)
2059 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2060 ctype ct = usymtab_supForwardTypeEntry (ue);
2067 ctype_removePointers (ctype c)
2071 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2074 c = ctype_baseArrayPtr (c);
2075 llassert (c != oldc);
2081 bool ctype_isMutable (ctype t)
2085 return (uentry_isMutableDatatype
2086 (usymtab_getTypeEntry (ctype_typeId (t))));
2090 return (ctype_isPointer (ctype_realType (t)));
2091 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2095 bool ctype_isRefCounted (ctype t)
2099 return (uentry_isRefCountedDatatype
2100 (usymtab_getTypeEntry (ctype_typeId (t))));
2106 bool ctype_isVisiblySharable (ctype t)
2108 if (ctype_isUnknown (t)) return TRUE;
2110 if (ctype_isConj (t))
2112 return (ctype_isVisiblySharable (ctype_getConjA (t))
2113 || ctype_isVisiblySharable (ctype_getConjB (t)));
2116 if (ctype_isMutable (t))
2120 ctype rt = ctype_realType (t);
2128 return ctype_isVisiblySharable (rt);
2142 /* Replaced by ctype_isMutable (more sensible) */
2143 bool ctype_canAlias (ctype ct)
2145 /* can ct refer to memory locations?
2146 ** ==> a pointer or a mutable abstract type
2150 ctype tr = ctype_realType (ct);
2152 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2157 ** c1 is the dominant type; c2 is the modifier type
2159 ** eg. double + long int => long double
2162 ctype ctype_combine (ctype dominant, ctype modifier)
2164 DPRINTF (("Combine: %s + %s",
2165 ctype_unparse (dominant),
2166 ctype_unparse (modifier)));
2168 if (ctype_isConj (dominant))
2172 if (ctype_isExplicitConj (dominant))
2174 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2176 ctype_getConjB (dominant));
2180 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2182 ctype_getConjB (dominant));
2188 if (ctype_isUnknown (modifier))
2192 else if (ctype_isUnknown (dominant))
2198 if (ctype_isEnum (dominant)) dominant = ctype_int;
2199 if (ctype_isEnum (modifier)) modifier = ctype_int;
2201 if (modifier == ctype_uint)
2203 if (dominant == ctype_int) return ctype_uint;
2204 if (dominant == ctype_lint) return ctype_ulint;
2205 if (dominant == ctype_sint) return ctype_usint;
2206 if (dominant == ctype_char) return ctype_uchar;
2208 /* evs 2000-07-28: added this line */
2209 if (dominant == ctype_llint) return ctype_ullint;
2211 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2213 voptgenerror (FLG_DUPLICATEQUALS,
2214 message ("Duplicate unsigned qualifier"),
2221 voptgenerror (FLG_DUPLICATEQUALS,
2222 message ("Type qualifier unsigned used with %s",
2223 ctype_unparse (dominant)),
2229 else if (modifier == ctype_llint)
2231 if (dominant == ctype_int)
2236 voptgenerror (FLG_DUPLICATEQUALS,
2237 message ("Duplicate long qualifier on non-int"),
2240 else if (modifier == ctype_lint)
2242 if (dominant == ctype_int) return ctype_lint;
2243 if (dominant == ctype_uint) return ctype_ulint;
2244 if (dominant == ctype_double) return ctype_ldouble;
2246 if (dominant == ctype_lint || dominant == ctype_ulint
2247 || dominant == ctype_sint || dominant == ctype_usint
2248 || dominant == ctype_ldouble)
2250 if (dominant == ctype_lint)
2252 /* long long not supported by ANSI */
2257 if (dominant == ctype_ulint)
2259 /* unsigned long long not supported by ANSI */
2260 return ctype_ullint;
2264 if (dominant == ctype_sint || dominant == ctype_usint)
2266 if (!context_getFlag (FLG_IGNOREQUALS))
2268 llerrorlit (FLG_SYNTAX,
2269 "Contradictory long and short type qualifiers");
2274 voptgenerror (FLG_DUPLICATEQUALS,
2275 message ("Duplicate long qualifier"),
2282 else if (modifier == ctype_sint)
2284 if (dominant == ctype_int) return ctype_sint;
2285 if (dominant == ctype_uint) return ctype_usint;
2287 if (dominant == ctype_sint || dominant == ctype_usint)
2289 voptgenerror (FLG_DUPLICATEQUALS,
2290 message ("Duplicate short qualifier"),
2294 else if (dominant == ctype_lint)
2296 if (!context_getFlag (FLG_IGNOREQUALS))
2298 llerrorlit (FLG_SYNTAX,
2299 "Contradictory long and short type qualifiers");
2305 else if (dominant == ctype_llint)
2307 if (!context_getFlag (FLG_IGNOREQUALS))
2309 llerrorlit (FLG_SYNTAX,
2310 "Contradictory long long and short type qualifiers");
2318 if (!context_getFlag (FLG_IGNOREQUALS))
2320 llerror (FLG_SYNTAX,
2321 message ("Type qualifier short used with %s",
2322 ctype_unparse (dominant)));
2328 else if (modifier == ctype_ulint)
2330 if (dominant == ctype_int) return modifier;
2332 if (dominant == ctype_lint || dominant == ctype_ulint)
2334 voptgenerror (FLG_DUPLICATEQUALS,
2335 message ("Duplicate long qualifier"),
2341 if (dominant == ctype_uint || dominant == ctype_usint)
2343 voptgenerror (FLG_DUPLICATEQUALS,
2344 message ("Duplicate unsigned qualifier"),
2350 if (dominant == ctype_sint || dominant == ctype_usint)
2352 if (!context_getFlag (FLG_IGNOREQUALS))
2354 llerrorlit (FLG_SYNTAX,
2355 "Contradictory long and short type qualifiers");
2361 if (!context_getFlag (FLG_IGNOREQUALS))
2363 llerror (FLG_SYNTAX,
2364 message ("Type qualifiers unsigned long used with %s",
2365 ctype_unparse (dominant)));
2370 else if (modifier == ctype_usint)
2372 if (dominant == ctype_int) return modifier;
2374 if (dominant == ctype_sint || dominant == ctype_usint)
2376 voptgenerror (FLG_DUPLICATEQUALS,
2377 message ("Duplicate short qualifier"),
2382 if (dominant == ctype_uint)
2384 voptgenerror (FLG_DUPLICATEQUALS,
2385 message ("Duplicate unsigned qualifier"),
2391 if (dominant == ctype_lint || dominant == ctype_ulint
2392 || dominant == ctype_llint)
2394 if (!context_getFlag (FLG_IGNOREQUALS))
2396 llerrorlit (FLG_SYNTAX,
2397 "Contradictory long and short type qualifiers");
2403 if (!context_getFlag (FLG_IGNOREQUALS))
2405 llerror (FLG_SYNTAX,
2406 message ("Type qualifiers unsigned short used with %s",
2407 ctype_unparse (dominant)));
2421 ctype ctype_resolve (ctype c)
2423 if (ctype_isUnknown (c)) return ctype_int;
2427 ctype ctype_fromQual (qual q)
2429 if (qual_isSigned (q)) return ctype_int;
2430 if (qual_isUnsigned (q)) return ctype_uint;
2431 if (qual_isLong (q)) return ctype_lint;
2432 if (qual_isShort (q)) return ctype_sint;
2434 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2435 return ctype_unknown;
2439 ctype_isAnyFloat (ctype c)
2441 return (cprim_isAnyReal (ctype_toCprim (c)));
2445 ctype_isUnsigned (ctype c)
2447 if (ctype_isConj (c))
2448 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2449 ctype_isUnsigned (ctype_getConjB (c)));
2451 return (c == ctype_uint || c == ctype_uchar
2452 || c == ctype_usint || c == ctype_ulint
2453 || c == ctype_ullint
2454 || c == ctype_unsignedintegral);
2459 ctype_isLongLong (ctype c)
2461 if (ctype_isConj (c))
2462 return (ctype_isLongLong (ctype_getConjA (c)) ||
2463 ctype_isLongLong (ctype_getConjB (c)));
2465 return (c == ctype_llint || c == ctype_ullint);
2470 ctype_isLong (ctype c)
2472 if (ctype_isConj (c))
2473 return (ctype_isLong (ctype_getConjA (c)) ||
2474 ctype_isLong (ctype_getConjB (c)));
2476 return (c == ctype_lint || c == ctype_ulint);
2480 ctype_isShort (ctype c)
2482 if (ctype_isConj (c))
2483 return (ctype_isShort (ctype_getConjA (c)) ||
2484 ctype_isShort (ctype_getConjB (c)));
2486 return (c == ctype_sint || c == ctype_usint);
2490 ctype_isStackAllocated (ctype c)
2492 ctype ct = ctype_realType (c);
2494 if (ctype_isConj (ct))
2495 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2496 ctype_isStackAllocated (ctype_getConjB (ct)));
2498 return (ctype_isArray (c) || ctype_isSU (c));
2501 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2503 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2506 static bool ctype_isLonger (ctype c1, ctype c2)
2508 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2509 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2510 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2511 || (ctype_isLong (c1)
2512 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2513 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2517 ctype_widest (ctype c1, ctype c2)
2519 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2529 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2532 if (c >= 0 && c < cttab.size)
2534 return (cttab.entries[c]->ctbase);
2538 if (c == ctype_unknown)
2539 llbuglit ("ctype_getCtbase: ctype unknown");
2540 if (c == ctype_undefined)
2541 llbuglit ("ctype_getCtbase: ctype undefined");
2543 llbuglit ("ctype_getCtbase: ctype dne");
2544 if (c == ctype_elipsMarker)
2545 llbuglit ("ctype_getCtbase: elips marker");
2547 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2554 static /*@notnull@*/ /*@observer@*/ ctbase
2555 ctype_getCtbaseSafe (ctype c)
2557 ctbase res = ctype_getCtbase (c);
2559 llassert (ctbase_isDefined (res));
2568 ctype_getCtentry (ctype c)
2570 static /*@only@*/ ctentry errorEntry = NULL;
2572 if (cttab.size == 0)
2574 if (errorEntry == NULL)
2576 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2583 if (c >= CTK_PLAIN && c < cttab.size)
2585 return (cttab.entries[c]);
2587 else if (c == CTK_UNKNOWN)
2588 llcontbuglit ("ctype_getCtentry: ctype unknown");
2589 else if (c == CTK_INVALID)
2590 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2591 else if (c == CTK_DNE)
2592 llcontbuglit ("ctype_getCtentry: ctype dne");
2593 else if (c == CTK_ELIPS)
2594 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2595 else if (c == CTK_MISSINGPARAMS)
2596 llcontbuglit ("ctype_getCtentry: ctype missing params");
2598 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2600 return (cttab.entries[ctype_unknown]);
2605 /* requires that the type is an fixed array */
2606 /* return the size of the array */
2608 long int ctype_getArraySize (ctype c)
2611 ctentry cte = ctype_getCtentry (c);
2614 llassert (ctype_isFixedArray (c));
2615 llassert ((ctentry_getKind (cte) == CTK_COMPLEX) || (ctentry_getKind(cte) == CTK_ARRAY));
2618 size = ctbase_getArraySize (ctb);
2620 DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",