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)
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));
808 ** work on actual type in current context
812 ctype_isRealNumeric (ctype c)
814 if (ctype_isPlain (c))
815 return (ctype_isNumeric (ctype_realType (c)));
816 if (ctype_isConj (c))
817 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
818 ctype_isRealNumeric (ctype_getConjB (c)));
824 ctype_isRealInt (ctype c)
826 if (ctype_isPlain (c))
827 return (ctype_isInt (ctype_realType (c)));
828 else if (ctype_isConj (c))
829 return (ctype_isRealInt (ctype_getConjA (c)) ||
830 ctype_isRealInt (ctype_getConjB (c)));
833 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
839 ctype_isRealVoid (ctype c)
841 if (ctype_isPlain (c))
843 return (ctype_isVoid (ctype_realType (c)));
845 else if (ctype_isConj (c))
847 return (ctype_isRealVoid (ctype_getConjA (c)) ||
848 ctype_isRealVoid (ctype_getConjB (c)));
857 ctype_isRealBool (ctype c)
859 if (ctype_isPlain (c))
861 return (ctype_isBool (ctype_realishType (c)));
863 else if (ctype_isConj (c))
865 return (ctype_isRealBool (ctype_getConjA (c)) ||
866 ctype_isRealBool (ctype_getConjB (c)));
875 ctype_isRealPointer (ctype c)
877 if (ctype_isConj (c))
878 return (ctype_isRealPointer (ctype_getConjA (c)) ||
879 ctype_isRealPointer (ctype_getConjB (c)));
880 return (ctype_isPointer (ctype_realType (c)));
884 ctype_isRealSU (ctype c)
886 if (ctype_isConj (c))
888 return (ctype_isRealSU (ctype_getConjA (c)) ||
889 ctype_isRealSU (ctype_getConjB (c)));
892 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
893 return (ctype_isStructorUnion (ctype_realType (c)));
897 ctype_isRealArray (ctype c)
899 if (ctype_isConj (c))
900 return (ctype_isRealArray (ctype_getConjA (c)) ||
901 ctype_isRealArray (ctype_getConjB (c)));
902 return (ctype_isArray (ctype_realType (c)));
906 ctype_isRealAP (ctype c)
908 if (ctype_isConj (c))
909 return (ctype_isRealAP (ctype_getConjA (c)) ||
910 ctype_isRealAP (ctype_getConjB (c)));
911 return (ctype_isAP (ctype_realType (c)));
915 ctype_isRealFunction (ctype c)
917 if (ctype_isConj (c))
918 return (ctype_isRealFunction (ctype_getConjA (c)) ||
919 ctype_isRealFunction (ctype_getConjB (c)));
920 return (ctype_isFunction (ctype_realType (c)));
924 ctype_isDirectInt (ctype c)
926 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
930 ** forceful predicates
932 ** take *ctype; if its a conjunct, and there is a match replace with match only.
933 ** if both match, still conjunct
937 ctype_isForcePred (ctype * c, bool (pred) (ctype))
939 if (ctype_isConj (*c))
941 ctype cbr = ctype_getConjA (*c);
945 if ((*pred) (ctype_getConjB (*c)))
958 if ((*pred) (cbr = ctype_getConjB (*c)))
966 return ((*pred) (*c));
970 ctype_isForceRealNumeric (ctype * c)
972 return (ctype_isForcePred (c, ctype_isRealNumeric));
976 ctype_isForceRealInt (ctype * c)
978 return (ctype_isForcePred (c, ctype_isRealInt));
982 ctype_isForceRealBool (ctype * c)
984 return (ctype_isForcePred (c, ctype_isRealBool));
990 ** save int/char, int/bool, other random conjuncts
994 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
996 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
1000 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1008 return (ctype_makeExplicitConj (c1, c2));
1012 return (ctype_makeConj (c1, c2));
1018 ctype_makeExplicitConj (ctype c1, ctype c2)
1020 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1022 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1024 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1026 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1028 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1030 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1034 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1038 static ctype ic = ctype_unknown; /* int | char */
1039 static ctype ib = ctype_unknown; /* int | bool */
1040 static ctype ifl = ctype_unknown; /* int | float */
1041 static ctype ibf = ctype_unknown; /* int | bool | float */
1042 static ctype ibc = ctype_unknown; /* int | bool | char */
1043 static ctype iv = ctype_unknown; /* int | void * */
1044 static ctype ivf = ctype_unknown; /* int | void * | float */
1045 static ctype ivb = ctype_unknown; /* int | void * | bool */
1046 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1047 static ctype cuc = ctype_unknown; /* char | unsigned char */
1050 ctype_recordConj (ctype c)
1054 llassert (ctype_isConj (c));
1056 c1 = ctype_getConjA (c);
1057 c2 = ctype_getConjB (c);
1060 if (c2 == ctype_int && c1 != ctype_int)
1070 if (c1 == ctype_int)
1072 if (c2 == ctype_char)
1074 llassert (ic == ctype_unknown);
1077 else if (c2 == ctype_bool)
1079 llassert (ib == ctype_unknown);
1082 else if (c2 == ctype_float)
1084 llassert (ifl == ctype_unknown);
1087 else if (c2 == CTP_VOID)
1089 llassert (iv == ctype_unknown);
1097 else if (c1 == ib && ib != ctype_unknown)
1099 if (c2 == ctype_float)
1101 llassert (ibf == ctype_unknown);
1104 else if (c2 == ctype_char)
1106 llassert (ibc == ctype_unknown);
1116 if (c2 == ctype_bool)
1118 llassert (ivb == ctype_unknown);
1121 else if (c2 == ctype_float)
1123 llassert (ivf == ctype_unknown);
1133 if (c2 == ctype_bool)
1135 llassert (ivbf == ctype_unknown);
1141 if (c2 == ctype_float)
1143 llassert (ivbf == ctype_unknown);
1147 else if (c1 == ctype_char)
1149 if (c2 == ctype_uchar)
1151 llassert (cuc == ctype_unknown);
1163 ctype_makeConj (ctype c1, ctype c2)
1165 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1167 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1169 if (ctype_isUnknown (c1))
1173 else if (ctype_isUnknown (c2))
1177 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1179 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1180 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1182 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1184 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1185 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1189 if (ctype_isManifestBool (c1))
1194 if (ctype_isManifestBool (c2))
1199 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1201 c1 = ctype_voidPointer;
1204 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1206 c2 = ctype_voidPointer;
1210 ** Ouch, can't do this. unsigned, etc. modifiers might
1211 ** apply to wrong type!
1213 ** if (c2 == ctype_int && c1 != ctype_int)
1224 if (c1 == ctype_int)
1226 if (c2 == ctype_char)
1228 if (ic == ctype_unknown)
1230 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1235 else if (c2 == ctype_bool)
1237 if (ib == ctype_unknown)
1239 ib = cttable_addComplex
1240 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1245 else if (c2 == ctype_float)
1247 if (ifl == ctype_unknown)
1249 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1256 if (c2 == ctype_voidPointer)
1258 if (iv == ctype_unknown)
1260 iv = cttable_addComplex
1261 (ctbase_makeConj (ctype_int,
1270 else if (c1 == ib && ib != ctype_unknown)
1272 if (c2 == ctype_float)
1274 if (ibf == ctype_unknown)
1276 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1281 else if (c2 == ctype_char)
1283 if (ibc == ctype_unknown)
1285 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1297 if (c2 == ctype_bool)
1299 if (ivb == ctype_unknown)
1301 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1306 else if (c2 == ctype_float)
1308 if (ivf == ctype_unknown)
1310 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1322 if (c2 == ctype_bool)
1324 if (ivbf == ctype_unknown)
1326 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1334 if (c2 == ctype_float)
1336 if (ivbf == ctype_unknown)
1338 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1344 else if (c1 == ctype_char)
1346 if (c2 == ctype_uchar)
1348 if (cuc == ctype_unknown)
1350 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1362 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1368 ctype_isConj (ctype c)
1370 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1374 ctype_getConjA (ctype c)
1376 if (!ctype_isConj (c))
1377 llbuglit ("ctype_getConjA: not a conj");
1378 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1382 ctype_getConjB (ctype c)
1384 if (!ctype_isConj (c))
1385 llbuglit ("ctype_getConjB: not a conj");
1386 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1390 ctype_isExplicitConj (ctype c)
1392 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1395 /** << need to fix resolveConj >> **/
1398 ** structs and unions
1402 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1406 DPRINTF (("Creating a struct: %s / %s",
1407 n, uentryList_unparse (f)));
1409 ct = cttable_addComplex (ctbase_createStruct (n, f));
1410 DPRINTF (("ct: %s", ctype_unparse (ct)));
1415 ctype_getFields (ctype c)
1417 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1421 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1425 ret = cttable_addComplex (ctbase_createUnion (n, f));
1432 ** if ctype's are same, definite match.
1433 ** else, need to call ctbase_match.
1435 ** if necessary context can memoize matches
1439 quickMatch (ctype c1, ctype c2)
1448 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1452 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1454 if (quickMatch (c1, c2))
1459 if (ctype_isElips (c1) || ctype_isElips (c2))
1465 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1471 ctype_sameName (ctype c1, ctype c2)
1473 if (quickMatch (c1, c2))
1476 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1480 ctype_almostEqual (ctype c1, ctype c2)
1482 if (ctype_equal (c1, c2))
1488 if (ctype_isUnknown (c1))
1490 return ctype_isUnknown (c2);
1492 else if (ctype_isUnknown (c2))
1498 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1504 ctype_matchDef (ctype c1, ctype c2)
1506 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1508 if (quickMatch (c1, c2))
1511 if (ctype_isElips (c1))
1512 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1514 if (ctype_isElips (c2))
1516 return (ctype_isUnknown (c2));
1520 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1523 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1524 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1525 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1530 bool ctype_match (ctype c1, ctype c2)
1532 if (quickMatch (c1, c2))
1535 if (ctype_isElips (c1))
1536 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1538 if (ctype_isElips (c2))
1539 return (ctype_isUnknown (c2));
1541 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1545 ctype_forceMatch (ctype c1, ctype c2)
1547 if (quickMatch (c1, c2))
1550 if (ctype_isElips (c1))
1551 return (ctype_isElips (c2));
1553 if (ctype_isElips (c2))
1557 /* The call forceMatch may modify the observer params, but, we don't care. */
1558 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1563 ctype_matchArg (ctype c1, ctype c2)
1565 if (quickMatch (c1, c2))
1571 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1576 ** simple ctype_is operations.
1577 ** DO NOT use real type of c, only direct type.
1581 ** ctype_isVoidPointer
1587 ctype_isVoidPointer (ctype c)
1589 if (ctype_isComplex (c))
1591 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1593 if (ctype_isConj (c))
1595 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1596 ctype_isVoidPointer (ctype_getConjB (c)));
1600 return (c == ctype_voidPointer
1601 || (ctype_isRealPointer (c)
1602 && ctype_isVoid (ctype_baseArrayPtr (c))));
1609 ** true for C and LCL pointers
1613 ctype_isPointer (ctype c)
1615 if (ctype_isElips (c)) return FALSE;
1617 if (ctype_isComplex (c))
1619 ctbase ctb = ctype_getCtbaseSafe (c);
1620 bool res = ctbase_isPointer (ctb);
1626 bool res = ctentry_isPointer (ctype_getCtentry (c));
1635 ** true for C and LCL array's
1639 ctype_isArray (ctype c)
1641 if (ctype_isElips (c)) return FALSE;
1643 if (ctype_isComplex (c))
1644 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1646 return (ctentry_isArray (ctype_getCtentry (c)));
1649 bool ctype_isIncompleteArray (ctype c)
1651 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1654 bool ctype_isFixedArray (ctype c)
1656 if (ctype_isElips (c)) return FALSE;
1658 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
1662 ctype_isArrayPtr (ctype c)
1664 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1668 ctype_typeId (ctype c)
1670 return (ctbase_typeId (ctype_getCtbase (c)));
1674 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1676 llassert (!(ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1678 if (ctype_isUnknown (c))
1680 return message ("? %q", name);
1684 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1689 ctype_unparse (ctype c)
1691 if (ctype_isElips (c))
1693 return cstring_makeLiteralTemp ("...");
1695 else if (ctype_isMissingParamsMarker (c))
1697 return cstring_makeLiteralTemp ("-");
1699 else if (ctype_isUnknown (c))
1701 return cstring_makeLiteralTemp ("?");
1706 return (ctentry_doUnparse (ctype_getCtentry (c)));
1712 ctype_unparseSafe (ctype c)
1714 if (ctype_isElips (c))
1716 return cstring_makeLiteralTemp ("...");
1718 else if (ctype_isMissingParamsMarker (c))
1720 return cstring_makeLiteralTemp ("-");
1726 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1728 ctentry cte = ctype_getCtentry (c);
1730 if (cstring_isDefined (cte->unparse))
1732 return (cte->unparse);
1736 ret = message ("[%d]", (int) c);
1737 cstring_markOwned (ret);
1743 ctype_unparseDeep (ctype c)
1745 if (ctype_isElips (c))
1747 return cstring_makeLiteralTemp ("...");
1749 if (ctype_isMissingParamsMarker (c))
1751 return cstring_makeLiteralTemp ("-");
1754 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1758 ctype_undump (char **c)
1760 return ((ctype) reader_getInt (c)); /* check its valid? */
1764 ctype_dump (ctype c)
1766 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1770 /* Handle invalid types in a kludgey way. */
1771 return (message ("0"));
1776 cstring tname = usymtab_getTypeEntryName
1777 (usymtab_convertId (ctype_typeId (c)));
1779 if (cstring_equal (tname, context_getBoolName ()))
1781 cstring_free (tname);
1782 return (message ("%d", ctype_bool));
1785 cstring_free (tname);
1788 DPRINTF (("Returning: %d", c));
1789 return (message ("%d", c));
1793 ctype_getBaseType (ctype c)
1795 ctentry cte = ctype_getCtentry (c);
1797 switch (ctentry_getKind (cte))
1805 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1808 ctbase ctb = cte->ctbase;
1810 if (ctbase_isDefined (ctb))
1829 return (ctype_getBaseType (ctb->contents.base));
1831 return (ctype_getBaseType (ctb->contents.farray->base));
1832 case CT_CONJ: /* base type of A conj branch? */
1833 return (ctype_getBaseType (ctb->contents.conj->a));
1835 /*@noaccess ctbase@*/
1843 llbuglit ("ctype_newBase: bad case");
1845 llcontbuglit ("ctype_getBaseType: unreachable code");
1846 return ((ctype)NULL);
1850 ctype_adjustPointers (int np, ctype c)
1853 if (ctype_isFunction (c))
1855 c = ctype_makeParamsFunction
1856 (ctype_adjustPointers (np, ctype_getReturnType (c)),
1857 uentryList_copy (ctype_argsFunction (c)));
1861 /* fix this should not use getBaseType ??? */
1862 ctype cb = ctype_getBaseType (c);
1866 cb = ctype_makePointer (cb);
1869 c = ctype_newBase (c, cb);
1877 ctype_elist (ctype c)
1879 return (ctbase_elist (ctype_getCtbase (c)));
1883 ctype_isFirstVoid (ctype c)
1885 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
1889 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
1891 return (cttable_addComplex (ctbase_createEnum (tag, el)));
1895 ctype_isEnum (ctype c)
1897 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
1901 ctype_enumTag (ctype c)
1903 llassert (ctype_isEnum (c));
1905 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
1909 ctype_isStruct (ctype c)
1911 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
1915 ctype_isUnion (ctype c)
1917 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
1921 ctype_resolveNumerics (ctype c1, ctype c2)
1924 ** returns longest type of c1 and c2
1927 if (c1 == c2) return c1;
1929 c1 = ctype_realType (c1);
1930 c2 = ctype_realType (c2);
1932 if (ctype_isEnum (c1)) c1 = ctype_unknown;
1933 if (ctype_isEnum (c2)) c2 = ctype_int;
1935 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
1937 /* 2001-06-08: This fix provided by Jim Zelenka. */
1938 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
1939 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
1941 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
1942 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
1943 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
1944 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
1946 /* 2001-06-08: This fix provided by Jim Zelenka. */
1947 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
1949 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
1951 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
1952 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
1954 if (ctype_isKnown (c1)) return c1;
1959 ctype_isStructorUnion (ctype c)
1961 return (ctype_isStruct (c) || ctype_isUnion (c));
1965 ctype_fixArrayPtr (ctype c)
1967 if (ctype_isArray (c))
1969 return (ctype_makePointer (ctype_baseArrayPtr (c)));
1976 ** createUnnamedStruct/Union
1978 ** check if it corresponds to an existing LCL-specified unnamed struct
1979 ** otherwise, give it a new tag
1983 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
1985 ctype ret = usymtab_structFieldsType (f);
1987 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
1989 if (ctype_isDefined (ret))
1991 uentryList_free (f);
1996 cstring ft = fakeTag ();
1997 ctype ct = ctype_createStruct (cstring_copy (ft), f);
1998 uentry ue = uentry_makeStructTagLoc (ft, ct);
2000 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2001 ue = usymtab_supGlobalEntryReturn (ue);
2002 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2010 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2012 ctype ret = usymtab_unionFieldsType (f);
2014 if (ctype_isDefined (ret))
2016 uentryList_free (f);
2021 cstring ft = fakeTag ();
2022 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2023 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2025 usymtab_supGlobalEntry (ue);
2032 ctype_isUnnamedSU (ctype c)
2036 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2045 ctype_createForwardStruct (cstring n)
2047 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2048 ctype ct = usymtab_supForwardTypeEntry (ue);
2055 ctype_createForwardUnion (cstring n)
2057 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2058 ctype ct = usymtab_supForwardTypeEntry (ue);
2065 ctype_removePointers (ctype c)
2069 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2072 c = ctype_baseArrayPtr (c);
2073 llassert (c != oldc);
2079 bool ctype_isMutable (ctype t)
2083 return (uentry_isMutableDatatype
2084 (usymtab_getTypeEntry (ctype_typeId (t))));
2088 return (ctype_isPointer (ctype_realType (t)));
2089 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2093 bool ctype_isRefCounted (ctype t)
2097 return (uentry_isRefCountedDatatype
2098 (usymtab_getTypeEntry (ctype_typeId (t))));
2104 bool ctype_isVisiblySharable (ctype t)
2106 if (ctype_isUnknown (t)) return TRUE;
2108 if (ctype_isConj (t))
2110 return (ctype_isVisiblySharable (ctype_getConjA (t))
2111 || ctype_isVisiblySharable (ctype_getConjB (t)));
2114 if (ctype_isMutable (t))
2118 ctype rt = ctype_realType (t);
2126 return ctype_isVisiblySharable (rt);
2140 /* Replaced by ctype_isMutable (more sensible) */
2141 bool ctype_canAlias (ctype ct)
2143 /* can ct refer to memory locations?
2144 ** ==> a pointer or a mutable abstract type
2148 ctype tr = ctype_realType (ct);
2150 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2155 ** c1 is the dominant type; c2 is the modifier type
2157 ** eg. double + long int => long double
2160 ctype ctype_combine (ctype dominant, ctype modifier)
2162 DPRINTF (("Combine: %s + %s",
2163 ctype_unparse (dominant),
2164 ctype_unparse (modifier)));
2166 if (ctype_isConj (dominant))
2170 if (ctype_isExplicitConj (dominant))
2172 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2174 ctype_getConjB (dominant));
2178 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2180 ctype_getConjB (dominant));
2186 if (ctype_isUnknown (modifier))
2190 else if (ctype_isUnknown (dominant))
2196 if (ctype_isEnum (dominant)) dominant = ctype_int;
2197 if (ctype_isEnum (modifier)) modifier = ctype_int;
2199 if (modifier == ctype_uint)
2201 if (dominant == ctype_int) return ctype_uint;
2202 if (dominant == ctype_lint) return ctype_ulint;
2203 if (dominant == ctype_sint) return ctype_usint;
2204 if (dominant == ctype_char) return ctype_uchar;
2206 /* evs 2000-07-28: added this line */
2207 if (dominant == ctype_llint) return ctype_ullint;
2209 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2211 voptgenerror (FLG_DUPLICATEQUALS,
2212 message ("Duplicate unsigned qualifier"),
2219 voptgenerror (FLG_DUPLICATEQUALS,
2220 message ("Type qualifier unsigned used with %s",
2221 ctype_unparse (dominant)),
2227 else if (modifier == ctype_llint)
2229 if (dominant == ctype_int)
2234 voptgenerror (FLG_DUPLICATEQUALS,
2235 message ("Duplicate long qualifier on non-int"),
2238 else if (modifier == ctype_lint)
2240 if (dominant == ctype_int) return ctype_lint;
2241 if (dominant == ctype_uint) return ctype_ulint;
2242 if (dominant == ctype_double) return ctype_ldouble;
2244 if (dominant == ctype_lint || dominant == ctype_ulint
2245 || dominant == ctype_sint || dominant == ctype_usint
2246 || dominant == ctype_ldouble)
2248 if (dominant == ctype_lint)
2250 /* long long not supported by ANSI */
2255 if (dominant == ctype_ulint)
2257 /* unsigned long long not supported by ANSI */
2258 return ctype_ullint;
2262 if (dominant == ctype_sint || dominant == ctype_usint)
2264 if (!context_getFlag (FLG_IGNOREQUALS))
2266 llerrorlit (FLG_SYNTAX,
2267 "Contradictory long and short type qualifiers");
2272 voptgenerror (FLG_DUPLICATEQUALS,
2273 message ("Duplicate long qualifier"),
2280 else if (modifier == ctype_sint)
2282 if (dominant == ctype_int) return ctype_sint;
2283 if (dominant == ctype_uint) return ctype_usint;
2285 if (dominant == ctype_sint || dominant == ctype_usint)
2287 voptgenerror (FLG_DUPLICATEQUALS,
2288 message ("Duplicate short qualifier"),
2292 else if (dominant == ctype_lint)
2294 if (!context_getFlag (FLG_IGNOREQUALS))
2296 llerrorlit (FLG_SYNTAX,
2297 "Contradictory long and short type qualifiers");
2303 else if (dominant == ctype_llint)
2305 if (!context_getFlag (FLG_IGNOREQUALS))
2307 llerrorlit (FLG_SYNTAX,
2308 "Contradictory long long and short type qualifiers");
2316 if (!context_getFlag (FLG_IGNOREQUALS))
2318 llerror (FLG_SYNTAX,
2319 message ("Type qualifier short used with %s",
2320 ctype_unparse (dominant)));
2326 else if (modifier == ctype_ulint)
2328 if (dominant == ctype_int) return modifier;
2330 if (dominant == ctype_lint || dominant == ctype_ulint)
2332 voptgenerror (FLG_DUPLICATEQUALS,
2333 message ("Duplicate long qualifier"),
2339 if (dominant == ctype_uint || dominant == ctype_usint)
2341 voptgenerror (FLG_DUPLICATEQUALS,
2342 message ("Duplicate unsigned qualifier"),
2348 if (dominant == ctype_sint || dominant == ctype_usint)
2350 if (!context_getFlag (FLG_IGNOREQUALS))
2352 llerrorlit (FLG_SYNTAX,
2353 "Contradictory long and short type qualifiers");
2359 if (!context_getFlag (FLG_IGNOREQUALS))
2361 llerror (FLG_SYNTAX,
2362 message ("Type qualifiers unsigned long used with %s",
2363 ctype_unparse (dominant)));
2368 else if (modifier == ctype_usint)
2370 if (dominant == ctype_int) return modifier;
2372 if (dominant == ctype_sint || dominant == ctype_usint)
2374 voptgenerror (FLG_DUPLICATEQUALS,
2375 message ("Duplicate short qualifier"),
2380 if (dominant == ctype_uint)
2382 voptgenerror (FLG_DUPLICATEQUALS,
2383 message ("Duplicate unsigned qualifier"),
2389 if (dominant == ctype_lint || dominant == ctype_ulint
2390 || dominant == ctype_llint)
2392 if (!context_getFlag (FLG_IGNOREQUALS))
2394 llerrorlit (FLG_SYNTAX,
2395 "Contradictory long and short type qualifiers");
2401 if (!context_getFlag (FLG_IGNOREQUALS))
2403 llerror (FLG_SYNTAX,
2404 message ("Type qualifiers unsigned short used with %s",
2405 ctype_unparse (dominant)));
2419 ctype ctype_resolve (ctype c)
2421 if (ctype_isUnknown (c)) return ctype_int;
2425 ctype ctype_fromQual (qual q)
2427 if (qual_isSigned (q)) return ctype_int;
2428 if (qual_isUnsigned (q)) return ctype_uint;
2429 if (qual_isLong (q)) return ctype_lint;
2430 if (qual_isShort (q)) return ctype_sint;
2432 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2433 return ctype_unknown;
2437 ctype_isAnyFloat (ctype c)
2439 return (cprim_isAnyReal (ctype_toCprim (c)));
2443 ctype_isUnsigned (ctype c)
2445 if (ctype_isConj (c))
2446 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2447 ctype_isUnsigned (ctype_getConjB (c)));
2449 return (c == ctype_uint || c == ctype_uchar
2450 || c == ctype_usint || c == ctype_ulint
2451 || c == ctype_ullint
2452 || c == ctype_unsignedintegral);
2457 ctype_isLongLong (ctype c)
2459 if (ctype_isConj (c))
2460 return (ctype_isLongLong (ctype_getConjA (c)) ||
2461 ctype_isLongLong (ctype_getConjB (c)));
2463 return (c == ctype_llint || c == ctype_ullint);
2468 ctype_isLong (ctype c)
2470 if (ctype_isConj (c))
2471 return (ctype_isLong (ctype_getConjA (c)) ||
2472 ctype_isLong (ctype_getConjB (c)));
2474 return (c == ctype_lint || c == ctype_ulint);
2478 ctype_isShort (ctype c)
2480 if (ctype_isConj (c))
2481 return (ctype_isShort (ctype_getConjA (c)) ||
2482 ctype_isShort (ctype_getConjB (c)));
2484 return (c == ctype_sint || c == ctype_usint);
2488 ctype_isStackAllocated (ctype c)
2490 ctype ct = ctype_realType (c);
2492 if (ctype_isConj (ct))
2493 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2494 ctype_isStackAllocated (ctype_getConjB (ct)));
2496 return (ctype_isArray (c) || ctype_isSU (c));
2499 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2501 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2504 static bool ctype_isLonger (ctype c1, ctype c2)
2506 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2507 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2508 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2509 || (ctype_isLong (c1)
2510 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2511 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2515 ctype_widest (ctype c1, ctype c2)
2517 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2527 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2530 if (c >= 0 && c < cttab.size)
2532 return (cttab.entries[c]->ctbase);
2536 if (c == ctype_unknown)
2537 llbuglit ("ctype_getCtbase: ctype unknown");
2538 if (c == ctype_undefined)
2539 llbuglit ("ctype_getCtbase: ctype undefined");
2541 llbuglit ("ctype_getCtbase: ctype dne");
2542 if (c == ctype_elipsMarker)
2543 llbuglit ("ctype_getCtbase: elips marker");
2545 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2552 static /*@notnull@*/ /*@observer@*/ ctbase
2553 ctype_getCtbaseSafe (ctype c)
2555 ctbase res = ctype_getCtbase (c);
2557 llassert (ctbase_isDefined (res));
2566 ctype_getCtentry (ctype c)
2568 static /*@only@*/ ctentry errorEntry = NULL;
2570 if (cttab.size == 0)
2572 if (errorEntry == NULL)
2574 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2581 if (c >= CTK_PLAIN && c < cttab.size)
2583 return (cttab.entries[c]);
2585 else if (c == CTK_UNKNOWN)
2586 llcontbuglit ("ctype_getCtentry: ctype unknown");
2587 else if (c == CTK_INVALID)
2588 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2589 else if (c == CTK_DNE)
2590 llcontbuglit ("ctype_getCtentry: ctype dne");
2591 else if (c == CTK_ELIPS)
2592 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2593 else if (c == CTK_MISSINGPARAMS)
2594 llcontbuglit ("ctype_getCtentry: ctype missing params");
2596 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2598 return (cttab.entries[ctype_unknown]);
2603 /* requires that the type is an fixed array */
2604 /* return the size of the array */
2606 long int ctype_getArraySize (ctype c)
2609 ctentry cte = ctype_getCtentry (c);
2611 llassert ( (ctentry_getKind (cte) == CTK_COMPLEX) || (ctentry_getKind(cte) == CTK_ARRAY) );
2615 size = ctbase_getArraySize (ctb);
2617 DPRINTF(( message("ctype_getArraySize: got fixed array size of %d ", (int)size) ));