2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
27 ** This files implements three types: ctentry, cttable and ctype.
28 ** They should probably be separated soon.
31 # include "splintMacros.nf"
33 # include "structNames.h"
35 static void ctype_recordConj (ctype p_c);
50 static ctype ctype_getConjA (ctype p_c) /*@*/ ;
51 static ctype ctype_getConjB (ctype p_c) /*@*/ ;
53 static bool ctype_isComplex (ctype c)
55 return (ctentry_isComplex (ctype_getCtentry (c)));
58 static bool ctype_isPlain (ctype c)
60 return (ctentry_isPlain (ctype_getCtentry (c)));
63 static bool ctype_isBroken (ctype c)
66 if (c == CTK_DNE || c == CTK_INVALID || c == CTK_UNKNOWN)
73 ctentry cte = ctype_getCtentry (c);
75 return (ctentry_isBogus (cte));
80 ctkind_fromInt (int i)
83 if (i < CTK_UNKNOWN || i > CTK_COMPLEX)
85 llcontbug (message ("ctkind_fromInt: out of range: %d", i));
109 ctype_loadTable (FILE *f)
111 DPRINTF (("Loading cttable!"));
116 ctype_dumpTable (FILE *f)
118 DPRINTF (("Dumping cttable!"));
123 ctype_unparseTable ()
125 return (cttable_unparse ());
135 ctype_isUserBool (ctype ct)
139 return (usymtab_isBoolType (ctype_typeId (ct)));
146 ctype_createUser (typeId u)
148 /* requires: ctype_createUser (u) is never called more than once for any u. */
150 ctbase ct = ctbase_createUser (u);
151 return (cttable_addFullSafe (ctentry_makeNew (CTK_PLAIN, ct)));
155 ctype_createAbstract (typeId u)
157 /* requires: ctype_createAbstract (u) is never called more than once for any u. */
158 /* [ tested by cttable_addFullSafe, not really required ] */
160 return (cttable_addFullSafe (ctentry_makeNew (CTK_PLAIN, ctbase_createAbstract (u))));
170 ctype_realType (ctype c)
174 if (ctype_isElips (c) || ctype_isMissingParamsMarker (c))
181 r = uentry_getRealType (usymtab_getTypeEntry (ctype_typeId (c)));
184 if (ctype_isManifestBool (r))
186 if (context_canAccessBool ())
188 r = context_boolImplementationType ();
196 ctype_isSimple (ctype c)
198 return (! (ctype_isPointer (c)
200 || ctype_isFunction (c)));
204 ctype_forceRealType (ctype c)
210 r = uentry_getForceRealType (usymtab_getTypeEntry (ctype_typeId (c)));
217 ctype_realishType (ctype c)
221 if (ctype_isManifestBool (c))
227 ctype r = uentry_getRealType (usymtab_getTypeEntry
239 return (!ctype_isUnknown (c) && ctbase_isUA (ctype_getCtbase (c)));
243 ctype_isUser (ctype c)
245 return (!ctype_isUnknown (c) && ctbase_isUser (ctype_getCtbase (c)));
249 ctype_isAbstract (ctype c)
251 return (!ctype_isUnknown (c)
252 && ((ctype_isPlain (c) && ctbase_isAbstract (ctype_getCtbaseSafe (c))) ||
254 (ctype_isAbstract (ctype_getConjA (c))
255 || ctype_isAbstract (ctype_getConjB (c))))));
259 ctype_isImmutableAbstract (ctype t)
261 return (ctype_isAbstract (t) && !ctype_isMutable (t));
265 ctype_isRealAbstract (ctype c)
267 return (ctype_isAbstract (ctype_realType (c)) ||
269 (ctype_isRealAbstract (ctype_getConjA (c)) ||
270 ctype_isRealAbstract (ctype_getConjB (c)))));
274 ** primitive creators
278 ** createPrim not necessary --- subsumed by ctype_int, etc.
282 ** ctbase_unknown --- removed argument
287 ** requires: if DerivedType (T) exists in cttable, then T->derivedType is it.
291 ctype_makePointer (ctype c)
297 else if (c == ctype_void)
299 return ctype_voidPointer;
303 ctentry cte = ctype_getCtentry (c);
304 ctype clp = ctentry_getPtr (cte);
306 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
308 ctype cnew = cttable_addDerived (CTK_PTR, ctbase_makePointer (c), c);
309 ctentry_setPtr (cte, cnew);
319 ctype ctype_makeFixedArray (ctype c, size_t size)
322 res = cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c);
326 ctype ctype_makeInnerFixedArray (ctype c, size_t size)
330 if (ctype_isFixedArray (c))
332 ctype cb = ctype_baseArrayPtr (c);
333 size_t osize = ctype_getArraySize (c);
335 res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size), osize);
337 else if (ctype_isArray (c))
339 ctype cb = ctype_baseArrayPtr (c);
341 res = ctype_makeArray (ctype_makeInnerFixedArray (cb, size));
345 res = ctype_makeFixedArray (c, size);
348 DPRINTF (("Make inner fixed array: %s", ctype_unparse (res)));
352 ctype ctype_makeInnerArray (ctype c)
356 DPRINTF (("Make inner array: %s", ctype_unparse (c)));
358 if (ctype_isFixedArray (c))
360 ctype cb = ctype_baseArrayPtr (c);
361 size_t osize = ctype_getArraySize (c);
363 res = ctype_makeFixedArray (ctype_makeInnerArray (cb), osize);
367 res = ctype_makeArray (c);
370 DPRINTF (("Make inner array: %s", ctype_unparse (res)));
375 ctype_makeArray (ctype c)
377 ctentry cte = ctype_getCtentry (c);
378 ctype clp = ctentry_getArray (cte);
380 DPRINTF (("Make array: %s", ctype_unparse (c)));
382 if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
384 ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
385 ctentry_setArray (cte, cnew);
395 ** requires c is a pointer of array
399 ctype_baseArrayPtr (ctype c)
401 ctentry cte = ctype_getCtentry (ctype_realType (c));
403 if (ctype_isConj (c))
405 if (ctype_isAP (ctype_getConjA (c)))
407 if (ctype_isAP (ctype_getConjB (c)))
409 return (ctype_makeConj (ctype_baseArrayPtr (ctype_getConjA (c)),
410 ctype_baseArrayPtr (ctype_getConjB (c))));
414 return (ctype_baseArrayPtr (ctype_getConjA (c)));
419 return (ctype_baseArrayPtr (ctype_getConjB (c)));
422 else if (ctype_isInt (c)) /* could be NULL */
424 return ctype_unknown;
428 ctype clp = ctentry_getBase (cte);
430 if (ctype_isBroken (clp))
432 llbuglit ("ctype_baseArrayPtr: bogus ctype");
444 ctype_makeWideString ()
446 static ctype res = ctype_unknown;
448 if (ctype_isUnknown (res))
452 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
454 wchart = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t")));
461 res = ctype_makePointer (wchart);
468 ctype_isWideString (ctype c)
470 if (ctype_isPointer (c))
472 ctype ct = ctype_baseArrayPtr (c);
474 if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
476 return (ct == uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t"))));
490 ctype_getReturnType (ctype c)
492 if (ctype_isUnknown (c))
494 return ctype_unknown;
497 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
501 ** must be a shared pointer
504 /*@observer@*/ uentryList
505 ctype_argsFunction (ctype c)
507 if (ctype_isUnknown (c))
509 return uentryList_undefined;
512 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
516 ** Returns type with base type p and compound types from c.
518 ** i.e., c = char *[]; p = int
523 ctype_newBase (ctype c, ctype p)
525 return (ctbase_newBase (c, p));
529 ctype_sameAltTypes (ctype c1, ctype c2)
534 llassert (ctype_isConj (c1) && ctype_isConj (c2));
536 c1a = ctype_getConjA (c1);
537 c2a = ctype_getConjA (c2);
539 c1b = ctype_getConjB (c1);
540 c2b = ctype_getConjB (c2);
542 if (ctype_compare (c1a, c2a) == 0)
544 if (ctype_compare (c1b, c2b) == 0)
550 if (ctype_isConj (c1b) && ctype_isConj (c2b))
552 return ctype_sameAltTypes (c1b, c2b);
562 if (ctype_compare (c1a, c2b) == 0)
564 if (ctype_compare (c1b, c2a) == 0)
570 if (ctype_isConj (c1b) && ctype_isConj (c2a))
572 return ctype_sameAltTypes (c1b, c2a);
588 ctype_compare (ctype c1, ctype c2)
593 if (ctype_isUnknown (c1))
595 if (ctype_isUnknown (c2))
605 if (ctype_isUnknown (c2))
610 /* Can't get entries for special ctypes (elips marker) */
612 if (ctype_isElips (c1) || ctype_isElips (c2)
613 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
614 return int_compare (c1, c2);
617 ce1 = ctype_getCtentry (c1);
618 ce2 = ctype_getCtentry (c2);
620 if (ctentry_isComplex (ce1))
622 if (ctentry_isComplex (ce2))
624 return (ctbase_compare (ctype_getCtbase (c1),
625 ctype_getCtbase (c2), FALSE));
632 else if (ctentry_isComplex (ce2))
638 return (int_compare (c1, c2));
647 ** makeFunction: pointer to function returning base
651 ctype_makeParamsFunction (ctype base, /*@only@*/ uentryList p)
653 uentryList_fixImpParams (p);
654 return (ctype_makeFunction (base, p));
658 ctype_makeNFParamsFunction (ctype base, /*@only@*/ uentryList p)
660 uentryList_fixImpParams (p);
661 return (ctbase_makeNFFunction (base, p));
665 ctype_makeFunction (ctype base, /*@only@*/ uentryList p)
668 ret = ctbase_makeFunction (base, p);
672 ctype ctype_expectFunction (ctype c)
674 /* handle parenthesized declarations */
678 c = ctype_makePointer (c);
681 return (cttable_addComplex (ctbase_expectFunction (c)));
684 ctype ctype_dontExpectFunction (ctype c)
686 ctbase ctb = ctype_getCtbase (c);
691 c = ctype_makePointer (c);
695 return (ctbase_getExpectFunction (ctb));
699 ** makeRealFunction: function returning base
702 ctype ctype_makeRawFunction (ctype base, uentryList p)
704 return (cttable_addComplex (ctbase_makeLiveFunction (base, p)));
712 **** this is very poorly defined
714 **** need to unify function/function pointer meaning
718 ctype_isFunction (ctype c)
720 if (ctype_isKnown (c) && ctype_isDefined (c))
722 return (ctbase_isFunction (ctype_getCtbase (c)));
731 ctype_isExpFcn (ctype c)
733 return (ctype_isKnown (c) && ctbase_isExpFcn (ctype_getCtbase (c)));
737 ctype_isVoid (ctype c)
739 return (c == CTX_VOID);
743 ctype_isArbitraryIntegral (ctype c)
745 ctype cr = ctype_realType (c);
747 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
748 || cr == ctype_signedintegral);
752 ctype_isUnsignedIntegral (ctype c)
754 ctype cr = ctype_realType (c);
756 return (cr == ctype_unsignedintegral);
760 ctype_isSignedIntegral (ctype c)
762 ctype cr = ctype_realType (c);
764 return (cr == ctype_signedintegral);
768 ctype_isInt (ctype c)
770 cprim cp = ctype_toCprim (c);
772 return (c == ctype_unknown || cprim_isAnyInt (cp)
773 || (cprim_isAnyChar (cp) && context_msgCharInt ())
774 || (c == ctype_bool && context_msgBoolInt ())
775 || (ctype_isEnum (c) && context_msgEnumInt ()));
779 ctype_isRegularInt (ctype c)
781 cprim cp = ctype_toCprim (c);
783 return (c == ctype_unknown
784 || cprim_closeEnough (cprim_int, cp)
785 || (cprim_isAnyChar (cp) && context_msgCharInt ())
786 || (c == ctype_bool && context_msgBoolInt ())
787 || (ctype_isEnum (c) && context_msgEnumInt ()));
791 ctype_isString (ctype c)
793 return (c == ctype_string
794 || (ctype_isPointer (c)
795 && ctype_isChar (ctype_baseArrayPtr (c))));
799 ctype_isChar (ctype c)
801 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
802 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
806 ctype_isUnsignedChar (ctype c)
808 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
812 ctype_isSignedChar (ctype c)
814 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
818 ** Returns true if c matches the name -booltype <bool>
822 ctype_isManifestBool (ctype c)
825 ** Changed the meaning of ctype_isBool - evs 2000-07-24
826 ** The old meaning was very convoluted!
829 ** c == CTX_BOOL - its a direct bool
830 ** c is a user/abstract type matching the bool name
831 ** (should never occur?)
834 if (ctype_isDirectBool (c)) {
836 } else if (ctype_isUA (c)) {
837 return ctype_isUserBool (c);
844 ctype_isBool (ctype c)
847 ** Changed the meaning of ctype_isBool - evs 2000-07-24
848 ** The old meaning was very convoluted!
851 ** its a manifest bool
852 ** +boolint and ctype_isInt (c)
855 if (ctype_isManifestBool (c)) {
857 } else if (context_msgBoolInt ()) {
858 return ctype_isInt (c);
864 if (context_getFlag (FLG_ABSTRACTBOOL))
866 if (typeId_isInvalid (boolType))
868 boolType = usymtab_getTypeId (context_getBoolName ());
871 if (context_hasAccess (boolType))
873 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
874 || (context_msgBoolInt ()
876 || (c == CTX_CHAR && context_msgCharInt ()))))
881 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
882 || (context_msgBoolInt ()
883 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
888 ctype_isDirectBool (ctype c)
890 return (c == CTX_BOOL);
894 ctype_isReal (ctype c)
896 return (cprim_isAnyReal (ctype_toCprim (c)));
900 ctype_isFloat (ctype c)
902 return (c == ctype_float);
906 ctype_isDouble (ctype c)
908 return (c == ctype_double || c == ctype_ldouble);
912 ctype_isSigned (ctype c)
914 return (!ctype_isUnsigned (c));
918 ctype_isNumeric (ctype c)
920 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c)
921 /* evans 2001-10-05: added this: */
922 || ctype_isArbitraryIntegral (c));
929 ** work on actual type in current context
933 ctype_isRealNumeric (ctype c)
935 if (ctype_isPlain (c))
936 return (ctype_isNumeric (ctype_realType (c)));
937 if (ctype_isConj (c))
938 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
939 ctype_isRealNumeric (ctype_getConjB (c)));
945 ctype_isRealInt (ctype c)
947 if (ctype_isPlain (c))
948 return (ctype_isInt (ctype_realType (c)));
949 else if (ctype_isConj (c))
950 return (ctype_isRealInt (ctype_getConjA (c)) ||
951 ctype_isRealInt (ctype_getConjB (c)));
954 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
960 ctype_isRealVoid (ctype c)
962 if (ctype_isPlain (c))
964 return (ctype_isVoid (ctype_realType (c)));
966 else if (ctype_isConj (c))
968 return (ctype_isRealVoid (ctype_getConjA (c)) ||
969 ctype_isRealVoid (ctype_getConjB (c)));
978 ctype_isRealBool (ctype c)
980 if (ctype_isPlain (c))
982 return (ctype_isBool (ctype_realishType (c)));
984 else if (ctype_isConj (c))
986 return (ctype_isRealBool (ctype_getConjA (c)) ||
987 ctype_isRealBool (ctype_getConjB (c)));
996 ctype_isRealPointer (ctype c)
998 if (ctype_isConj (c))
999 return (ctype_isRealPointer (ctype_getConjA (c)) ||
1000 ctype_isRealPointer (ctype_getConjB (c)));
1001 return (ctype_isPointer (ctype_realType (c)));
1005 ctype_isRealSU (ctype c)
1007 if (ctype_isConj (c))
1009 return (ctype_isRealSU (ctype_getConjA (c)) ||
1010 ctype_isRealSU (ctype_getConjB (c)));
1013 DPRINTF (("Real su: %s / %s", ctype_unparse (c), ctype_unparse (ctype_realType (c))));
1014 return (ctype_isStructorUnion (ctype_realType (c)));
1018 ctype_isRealArray (ctype c)
1020 if (ctype_isConj (c))
1021 return (ctype_isRealArray (ctype_getConjA (c)) ||
1022 ctype_isRealArray (ctype_getConjB (c)));
1023 return (ctype_isArray (ctype_realType (c)));
1027 ctype_isRealAP (ctype c)
1029 if (ctype_isConj (c))
1030 return (ctype_isRealAP (ctype_getConjA (c)) ||
1031 ctype_isRealAP (ctype_getConjB (c)));
1032 return (ctype_isAP (ctype_realType (c)));
1036 ctype_isRealFunction (ctype c)
1038 if (ctype_isConj (c))
1039 return (ctype_isRealFunction (ctype_getConjA (c)) ||
1040 ctype_isRealFunction (ctype_getConjB (c)));
1041 return (ctype_isFunction (ctype_realType (c)));
1045 ctype_isDirectInt (ctype c)
1047 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
1051 ** forceful predicates
1053 ** take *ctype; if its a conjunct, and there is a match replace with match only.
1054 ** if both match, still conjunct
1058 ctype_isForcePred (ctype * c, bool (pred) (ctype))
1060 /*drl bee: pbr */ if (ctype_isConj (*c))
1062 ctype cbr = ctype_getConjA (*c);
1064 /*drl bee: si*/ if ((*pred) (cbr))
1066 if ((*pred) (ctype_getConjB (*c)))
1079 if ((*pred) (cbr = ctype_getConjB (*c)))
1087 return ((*pred) (*c));
1091 ctype_isForceRealNumeric (ctype * c)
1093 return (ctype_isForcePred (c, ctype_isRealNumeric));
1097 ctype_isForceRealInt (ctype * c)
1099 return (ctype_isForcePred (c, ctype_isRealInt));
1103 ctype_isForceRealBool (ctype * c)
1105 return (ctype_isForcePred (c, ctype_isRealBool));
1111 ** save int/char, int/bool, other random conjuncts
1115 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
1117 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
1121 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
1129 return (ctype_makeExplicitConj (c1, c2));
1133 return (ctype_makeConj (c1, c2));
1139 ctype_makeExplicitConj (ctype c1, ctype c2)
1141 if (ctype_isAnytype (c1) || ctype_isAnytype (c2))
1143 return ctype_makeAnytype ();
1145 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1147 ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
1149 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1151 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1153 ctype ret = ctype_makeExplicitConj (c1, ctype_getReturnType (c2));
1155 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1159 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
1163 static ctype ic = ctype_unknown; /* int | char */
1164 static ctype ib = ctype_unknown; /* int | bool */
1165 static ctype ifl = ctype_unknown; /* int | float */
1166 static ctype ibf = ctype_unknown; /* int | bool | float */
1167 static ctype ibc = ctype_unknown; /* int | bool | char */
1168 static ctype iv = ctype_unknown; /* int | void * */
1169 static ctype ivf = ctype_unknown; /* int | void * | float */
1170 static ctype ivb = ctype_unknown; /* int | void * | bool */
1171 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
1172 static ctype cuc = ctype_unknown; /* char | unsigned char */
1174 static ctype cany = ctype_unknown;
1177 ctype_makeAnytype ()
1179 if (cany == ctype_unknown)
1181 cany = ctype_makeConj (ctype_unknown, ctype_dne);
1182 llassert (ctype_isAnytype (cany));
1185 DPRINTF (("make anytype: %s", ctype_unparse (cany)));
1190 ctype_isAnytype (ctype c)
1196 ctype_recordConj (ctype c)
1200 llassert (ctype_isConj (c));
1202 c1 = ctype_getConjA (c);
1203 c2 = ctype_getConjB (c);
1206 if (c2 == ctype_int && c1 != ctype_int)
1216 if (c1 == ctype_int)
1218 if (c2 == ctype_char)
1220 llassert (ic == ctype_unknown);
1223 else if (c2 == ctype_bool)
1225 llassert (ib == ctype_unknown);
1228 else if (c2 == ctype_float)
1230 llassert (ifl == ctype_unknown);
1233 else if (c2 == CTP_VOID)
1235 llassert (iv == ctype_unknown);
1243 else if (c1 == ib && ib != ctype_unknown)
1245 if (c2 == ctype_float)
1247 llassert (ibf == ctype_unknown);
1250 else if (c2 == ctype_char)
1252 llassert (ibc == ctype_unknown);
1262 if (c2 == ctype_bool)
1264 llassert (ivb == ctype_unknown);
1267 else if (c2 == ctype_float)
1269 llassert (ivf == ctype_unknown);
1279 if (c2 == ctype_bool)
1281 llassert (ivbf == ctype_unknown);
1287 if (c2 == ctype_float)
1289 llassert (ivbf == ctype_unknown);
1293 else if (c1 == ctype_char)
1295 if (c2 == ctype_uchar)
1297 llassert (cuc == ctype_unknown);
1309 ctype_makeConj (ctype c1, ctype c2)
1311 /* no: can have unsigned long @alt long@: llassert (c1 != c2); */
1313 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1315 if (ctype_isAnytype (c1))
1319 else if (ctype_isAnytype (c2))
1323 else if (ctype_isUnknown (c1))
1327 else if (ctype_isUnknown (c2))
1331 else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
1333 ctype ret = ctype_makeConj (ctype_getReturnType (c1), c2);
1334 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
1336 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
1338 ctype ret = ctype_makeConj (c1, ctype_getReturnType (c2));
1339 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
1343 if (ctype_isManifestBool (c1))
1348 if (ctype_isManifestBool (c2))
1353 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
1355 c1 = ctype_voidPointer;
1358 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
1360 c2 = ctype_voidPointer;
1364 ** Ouch, can't do this. unsigned, etc. modifiers might
1365 ** apply to wrong type!
1367 ** if (c2 == ctype_int && c1 != ctype_int)
1378 if (c1 == ctype_int)
1380 if (c2 == ctype_char)
1382 if (ic == ctype_unknown)
1384 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
1389 else if (c2 == ctype_bool)
1391 if (ib == ctype_unknown)
1393 ib = cttable_addComplex
1394 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
1399 else if (c2 == ctype_float)
1401 if (ifl == ctype_unknown)
1403 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
1410 if (c2 == ctype_voidPointer)
1412 if (iv == ctype_unknown)
1414 iv = cttable_addComplex
1415 (ctbase_makeConj (ctype_int,
1424 else if (c1 == ib && ib != ctype_unknown)
1426 if (c2 == ctype_float)
1428 if (ibf == ctype_unknown)
1430 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
1435 else if (c2 == ctype_char)
1437 if (ibc == ctype_unknown)
1439 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
1451 if (c2 == ctype_bool)
1453 if (ivb == ctype_unknown)
1455 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1460 else if (c2 == ctype_float)
1462 if (ivf == ctype_unknown)
1464 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1476 if (c2 == ctype_bool)
1478 if (ivbf == ctype_unknown)
1480 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1488 if (c2 == ctype_float)
1490 if (ivbf == ctype_unknown)
1492 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1498 else if (c1 == ctype_char)
1500 if (c2 == ctype_uchar)
1502 if (cuc == ctype_unknown)
1504 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
1515 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
1521 ctype_isConj (ctype c)
1523 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
1527 ctype_getConjA (ctype c)
1529 if (!ctype_isConj (c))
1530 llbuglit ("ctype_getConjA: not a conj");
1531 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
1535 ctype_getConjB (ctype c)
1537 if (!ctype_isConj (c))
1538 llbuglit ("ctype_getConjB: not a conj");
1539 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
1543 ctype_isExplicitConj (ctype c)
1545 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
1548 /** << need to fix resolveConj >> **/
1551 ** structs and unions
1555 ctype_createStruct (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1559 DPRINTF (("Creating a struct: %s / %s",
1560 n, uentryList_unparse (f)));
1562 ct = cttable_addComplex (ctbase_createStruct (n, f));
1563 DPRINTF (("ct: %s", ctype_unparse (ct)));
1568 ctype_getFields (ctype c)
1570 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
1574 ctype_createUnion (/*@only@*/ cstring n, /*@only@*/ uentryList f)
1578 ret = cttable_addComplex (ctbase_createUnion (n, f));
1585 ** if ctype's are same, definite match.
1586 ** else, need to call ctbase_match.
1588 ** if necessary context can memoize matches
1592 quickMatch (ctype c1, ctype c2)
1601 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
1605 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
1607 if (quickMatch (c1, c2))
1612 if (ctype_isElips (c1) || ctype_isElips (c2))
1618 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
1624 ctype_sameName (ctype c1, ctype c2)
1626 if (quickMatch (c1, c2))
1629 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
1633 ctype_almostEqual (ctype c1, ctype c2)
1635 if (ctype_equal (c1, c2))
1641 if (ctype_isUnknown (c1))
1643 return ctype_isUnknown (c2);
1645 else if (ctype_isUnknown (c2))
1651 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1657 ctype_matchDef (ctype c1, ctype c2)
1659 DPRINTF (("Match def: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
1661 if (quickMatch (c1, c2))
1664 if (ctype_isElips (c1))
1665 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1667 if (ctype_isElips (c2))
1669 return (ctype_isUnknown (c2));
1673 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
1676 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
1677 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
1678 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
1683 bool ctype_match (ctype c1, ctype c2)
1685 if (quickMatch (c1, c2))
1688 if (ctype_isElips (c1))
1689 return (ctype_isElips (c2) || ctype_isUnknown (c2));
1691 if (ctype_isElips (c2))
1692 return (ctype_isUnknown (c2));
1694 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1698 ctype_forceMatch (ctype c1, ctype c2)
1700 if (quickMatch (c1, c2))
1703 if (ctype_isElips (c1))
1704 return (ctype_isElips (c2));
1706 if (ctype_isElips (c2))
1710 /* The call forceMatch may modify the observer params, but, we don't care. */
1711 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1716 ctype_matchArg (ctype c1, ctype c2)
1718 if (quickMatch (c1, c2))
1724 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
1729 ** simple ctype_is operations.
1730 ** DO NOT use real type of c, only direct type.
1734 ** ctype_isVoidPointer
1740 ctype_isVoidPointer (ctype c)
1742 if (ctype_isComplex (c))
1744 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
1746 if (ctype_isConj (c))
1748 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
1749 ctype_isVoidPointer (ctype_getConjB (c)));
1753 return (c == ctype_voidPointer
1754 || (ctype_isRealPointer (c)
1755 && ctype_isVoid (ctype_baseArrayPtr (c))));
1762 ** true for C and LCL pointers
1766 ctype_isPointer (ctype c)
1768 if (ctype_isElips (c)) return FALSE;
1770 if (ctype_isComplex (c))
1772 ctbase ctb = ctype_getCtbaseSafe (c);
1773 bool res = ctbase_isPointer (ctb);
1779 bool res = ctentry_isPointer (ctype_getCtentry (c));
1788 ** true for C and LCL array's
1792 ctype_isArray (ctype c)
1794 if (ctype_isElips (c)) return FALSE;
1796 if (ctype_isComplex (c))
1797 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
1799 return (ctentry_isArray (ctype_getCtentry (c)));
1802 bool ctype_isIncompleteArray (ctype c)
1804 return (ctype_isArray (c) && !ctype_isFixedArray (c));
1808 ctype_isArrayPtr (ctype c)
1810 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
1814 ctype_typeId (ctype c)
1816 return (ctbase_typeId (ctype_getCtbase (c)));
1820 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
1822 llassert (!(ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
1824 if (ctype_isUnknown (c))
1826 return message ("? %q", name);
1830 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
1835 ctype_unparse (ctype c)
1837 if (ctype_isElips (c))
1839 return cstring_makeLiteralTemp ("...");
1841 else if (ctype_isMissingParamsMarker (c))
1843 return cstring_makeLiteralTemp ("-");
1845 else if (ctype_isAnytype (c))
1847 return cstring_makeLiteralTemp ("<any>");
1849 else if (ctype_isUnknown (c))
1851 return cstring_makeLiteralTemp ("?");
1856 return (ctentry_doUnparse (ctype_getCtentry (c)));
1862 ctype_unparseSafe (ctype c)
1864 if (ctype_isElips (c))
1866 return cstring_makeLiteralTemp ("...");
1868 else if (ctype_isMissingParamsMarker (c))
1870 return cstring_makeLiteralTemp ("-");
1876 if /*@+enumint@*/ (c >= CTK_PLAIN && c < cttab.size) /*@=enumint@*/
1878 ctentry cte = ctype_getCtentry (c);
1880 if (cstring_isDefined (cte->unparse))
1882 return (cte->unparse);
1886 ret = message ("[%d]", (int) c);
1887 cstring_markOwned (ret);
1893 ctype_unparseDeep (ctype c)
1895 if (ctype_isElips (c))
1897 return cstring_makeLiteralTemp ("...");
1899 if (ctype_isMissingParamsMarker (c))
1901 return cstring_makeLiteralTemp ("-");
1904 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
1908 ctype_undump (char **c)
1910 return ((ctype) reader_getInt (c)); /* check its valid? */
1914 ctype_dump (ctype c)
1916 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
1920 /* Handle invalid types in a kludgey way. */
1921 return (message ("0"));
1926 cstring tname = usymtab_getTypeEntryName
1927 (usymtab_convertId (ctype_typeId (c)));
1929 if (cstring_equal (tname, context_getBoolName ()))
1931 cstring_free (tname);
1932 return (message ("%d", ctype_bool));
1935 cstring_free (tname);
1938 DPRINTF (("Returning: %d", c));
1939 return (message ("%d", c));
1943 ctype_getBaseType (ctype c)
1945 ctentry cte = ctype_getCtentry (c);
1947 switch (ctentry_getKind (cte))
1955 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
1958 ctbase ctb = cte->ctbase;
1960 if (ctbase_isDefined (ctb))
1979 return (ctype_getBaseType (ctb->contents.base));
1981 return (ctype_getBaseType (ctb->contents.farray->base));
1982 case CT_CONJ: /* base type of A conj branch? */
1983 return (ctype_getBaseType (ctb->contents.conj->a));
1985 /*@noaccess ctbase@*/
1993 llbuglit ("ctype_newBase: bad case");
1995 llcontbuglit ("ctype_getBaseType: unreachable code");
1996 return ((ctype)NULL);
2000 ctype_adjustPointers (int np, ctype c)
2003 if (ctype_isFunction (c))
2005 c = ctype_makeParamsFunction
2006 (ctype_adjustPointers (np, ctype_getReturnType (c)),
2007 uentryList_copy (ctype_argsFunction (c)));
2011 /* fix this should not use getBaseType ??? */
2012 ctype cb = ctype_getBaseType (c);
2016 cb = ctype_makePointer (cb);
2019 c = ctype_newBase (c, cb);
2027 ctype_elist (ctype c)
2029 return (ctbase_elist (ctype_getCtbase (c)));
2033 ctype_isFirstVoid (ctype c)
2035 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
2039 ctype_createEnum (/*@keep@*/ cstring tag, /*@keep@*/ enumNameList el)
2041 return (cttable_addComplex (ctbase_createEnum (tag, el)));
2045 ctype_isEnum (ctype c)
2047 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
2051 ctype_enumTag (ctype c)
2053 llassert (ctype_isEnum (c));
2055 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
2059 ctype_isStruct (ctype c)
2061 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
2065 ctype_isUnion (ctype c)
2067 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
2071 ctype_resolveNumerics (ctype c1, ctype c2)
2074 ** returns longest type of c1 and c2
2077 if (c1 == c2) return c1;
2079 c1 = ctype_realType (c1);
2080 c2 = ctype_realType (c2);
2082 if (ctype_isEnum (c1)) c1 = ctype_unknown;
2083 if (ctype_isEnum (c2)) c2 = ctype_int;
2085 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
2087 /* 2001-06-08: This fix provided by Jim Zelenka. */
2088 if (c1 == ctype_llint || c2 == ctype_llint) return ctype_llint;
2089 if (c1 == ctype_ullint || c2 == ctype_ullint) return ctype_ullint;
2091 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
2092 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
2093 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
2094 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
2096 /* 2001-06-08: This fix provided by Jim Zelenka. */
2097 if (c1 == ctype_usint || c2 == ctype_usint) return ctype_usint;
2099 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
2101 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
2102 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
2104 if (ctype_isKnown (c1)) return c1;
2109 ctype_isStructorUnion (ctype c)
2111 return (ctype_isStruct (c) || ctype_isUnion (c));
2115 ctype_fixArrayPtr (ctype c)
2117 if (ctype_isArray (c))
2119 return (ctype_makePointer (ctype_baseArrayPtr (c)));
2126 ** createUnnamedStruct/Union
2128 ** check if it corresponds to an existing LCL-specified unnamed struct
2129 ** otherwise, give it a new tag
2133 ctype_createUnnamedStruct (/*@only@*/ uentryList f)
2135 ctype ret = usymtab_structFieldsType (f);
2137 DPRINTF (("unnamed struct: %s", ctype_unparse (ret)));
2139 if (ctype_isDefined (ret))
2141 uentryList_free (f);
2146 cstring ft = fakeTag ();
2147 ctype ct = ctype_createStruct (cstring_copy (ft), f);
2148 uentry ue = uentry_makeStructTagLoc (ft, ct);
2150 DPRINTF (("Unnamed struct: %s", uentry_unparseFull (ue)));
2151 ue = usymtab_supGlobalEntryReturn (ue);
2152 DPRINTF (("After Unnamed struct: %s", uentry_unparseFull (ue)));
2160 ctype_createUnnamedUnion (/*@only@*/ uentryList f)
2162 ctype ret = usymtab_unionFieldsType (f);
2164 if (ctype_isDefined (ret))
2166 uentryList_free (f);
2171 cstring ft = fakeTag ();
2172 ctype ct = ctype_createUnion (cstring_copy (ft), f);
2173 uentry ue = uentry_makeUnionTagLoc (ft, ct);
2175 usymtab_supGlobalEntry (ue);
2182 ctype_isUnnamedSU (ctype c)
2186 return ctbase_isUnnamedSU (ctype_getCtbase (c));
2195 ctype_createForwardStruct (cstring n)
2197 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
2198 ctype ct = usymtab_supForwardTypeEntry (ue);
2205 ctype_createForwardUnion (cstring n)
2207 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
2208 ctype ct = usymtab_supForwardTypeEntry (ue);
2215 ctype_removePointers (ctype c)
2219 while (ctype_isKnown (c) && ctype_isArrayPtr (c))
2222 c = ctype_baseArrayPtr (c);
2223 llassert (c != oldc);
2229 bool ctype_isMutable (ctype t)
2233 return (uentry_isMutableDatatype
2234 (usymtab_getTypeEntry (ctype_typeId (t))));
2238 return (ctype_isPointer (ctype_realType (t)));
2239 /*!! || ctype_isStructorUnion (ctype_realType (t))); */
2243 bool ctype_isRefCounted (ctype t)
2247 return (uentry_isRefCountedDatatype
2248 (usymtab_getTypeEntry (ctype_typeId (t))));
2254 bool ctype_isVisiblySharable (ctype t)
2256 if (ctype_isUnknown (t)) return TRUE;
2258 if (ctype_isConj (t))
2260 return (ctype_isVisiblySharable (ctype_getConjA (t))
2261 || ctype_isVisiblySharable (ctype_getConjB (t)));
2264 if (ctype_isMutable (t))
2268 ctype rt = ctype_realType (t);
2276 return ctype_isVisiblySharable (rt);
2290 /* Replaced by ctype_isMutable (more sensible) */
2291 bool ctype_canAlias (ctype ct)
2293 /* can ct refer to memory locations?
2294 ** ==> a pointer or a mutable abstract type
2298 ctype tr = ctype_realType (ct);
2300 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
2305 ** c1 is the dominant type; c2 is the modifier type
2307 ** eg. double + long int => long double
2310 ctype ctype_combine (ctype dominant, ctype modifier)
2312 DPRINTF (("Combine: %s + %s",
2313 ctype_unparse (dominant),
2314 ctype_unparse (modifier)));
2316 if (ctype_isConj (dominant))
2320 if (ctype_isExplicitConj (dominant))
2322 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
2324 ctype_getConjB (dominant));
2328 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
2330 ctype_getConjB (dominant));
2336 if (ctype_isUnknown (modifier))
2340 else if (ctype_isUnknown (dominant))
2346 if (ctype_isEnum (dominant)) dominant = ctype_int;
2347 if (ctype_isEnum (modifier)) modifier = ctype_int;
2349 if (modifier == ctype_uint)
2351 if (dominant == ctype_int) return ctype_uint;
2352 if (dominant == ctype_lint) return ctype_ulint;
2353 if (dominant == ctype_sint) return ctype_usint;
2354 if (dominant == ctype_char) return ctype_uchar;
2356 /* evs 2000-07-28: added this line */
2357 if (dominant == ctype_llint) return ctype_ullint;
2359 if ((dominant == ctype_uint) || dominant == ctype_uchar)
2361 voptgenerror (FLG_DUPLICATEQUALS,
2362 message ("Duplicate unsigned qualifier"),
2369 voptgenerror (FLG_DUPLICATEQUALS,
2370 message ("Type qualifier unsigned used with %s",
2371 ctype_unparse (dominant)),
2377 else if (modifier == ctype_llint)
2379 if (dominant == ctype_int)
2384 voptgenerror (FLG_DUPLICATEQUALS,
2385 message ("Duplicate long qualifier on non-int"),
2388 else if (modifier == ctype_lint)
2390 if (dominant == ctype_int) return ctype_lint;
2391 if (dominant == ctype_uint) return ctype_ulint;
2392 if (dominant == ctype_double) return ctype_ldouble;
2394 if (dominant == ctype_lint || dominant == ctype_ulint
2395 || dominant == ctype_sint || dominant == ctype_usint
2396 || dominant == ctype_ldouble)
2398 if (dominant == ctype_lint)
2400 /* long long not supported by ANSI */
2405 if (dominant == ctype_ulint)
2407 /* unsigned long long not supported by ANSI */
2408 return ctype_ullint;
2412 if (dominant == ctype_sint || dominant == ctype_usint)
2414 if (!context_getFlag (FLG_IGNOREQUALS))
2416 llerrorlit (FLG_SYNTAX,
2417 "Contradictory long and short type qualifiers");
2422 voptgenerror (FLG_DUPLICATEQUALS,
2423 message ("Duplicate long qualifier"),
2430 else if (modifier == ctype_sint)
2432 if (dominant == ctype_int) return ctype_sint;
2433 if (dominant == ctype_uint) return ctype_usint;
2435 if (dominant == ctype_sint || dominant == ctype_usint)
2437 voptgenerror (FLG_DUPLICATEQUALS,
2438 message ("Duplicate short qualifier"),
2442 else if (dominant == ctype_lint)
2444 if (!context_getFlag (FLG_IGNOREQUALS))
2446 llerrorlit (FLG_SYNTAX,
2447 "Contradictory long and short type qualifiers");
2453 else if (dominant == ctype_llint)
2455 if (!context_getFlag (FLG_IGNOREQUALS))
2457 llerrorlit (FLG_SYNTAX,
2458 "Contradictory long long and short type qualifiers");
2466 if (!context_getFlag (FLG_IGNOREQUALS))
2468 llerror (FLG_SYNTAX,
2469 message ("Type qualifier short used with %s",
2470 ctype_unparse (dominant)));
2476 else if (modifier == ctype_ulint)
2478 if (dominant == ctype_int) return modifier;
2480 if (dominant == ctype_lint || dominant == ctype_ulint)
2482 voptgenerror (FLG_DUPLICATEQUALS,
2483 message ("Duplicate long qualifier"),
2489 if (dominant == ctype_uint || dominant == ctype_usint)
2491 voptgenerror (FLG_DUPLICATEQUALS,
2492 message ("Duplicate unsigned qualifier"),
2498 if (dominant == ctype_sint || dominant == ctype_usint)
2500 if (!context_getFlag (FLG_IGNOREQUALS))
2502 llerrorlit (FLG_SYNTAX,
2503 "Contradictory long and short type qualifiers");
2509 if (!context_getFlag (FLG_IGNOREQUALS))
2511 llerror (FLG_SYNTAX,
2512 message ("Type qualifiers unsigned long used with %s",
2513 ctype_unparse (dominant)));
2518 else if (modifier == ctype_usint)
2520 if (dominant == ctype_int) return modifier;
2522 if (dominant == ctype_sint || dominant == ctype_usint)
2524 voptgenerror (FLG_DUPLICATEQUALS,
2525 message ("Duplicate short qualifier"),
2530 if (dominant == ctype_uint)
2532 voptgenerror (FLG_DUPLICATEQUALS,
2533 message ("Duplicate unsigned qualifier"),
2539 if (dominant == ctype_lint || dominant == ctype_ulint
2540 || dominant == ctype_llint)
2542 if (!context_getFlag (FLG_IGNOREQUALS))
2544 llerrorlit (FLG_SYNTAX,
2545 "Contradictory long and short type qualifiers");
2551 if (!context_getFlag (FLG_IGNOREQUALS))
2553 llerror (FLG_SYNTAX,
2554 message ("Type qualifiers unsigned short used with %s",
2555 ctype_unparse (dominant)));
2569 ctype ctype_resolve (ctype c)
2571 if (ctype_isUnknown (c) && !ctype_isAnytype (c))
2573 DPRINTF (("Resolving to int: %s", ctype_unparse (c)));
2580 ctype ctype_fromQual (qual q)
2582 if (qual_isSigned (q)) return ctype_int;
2583 if (qual_isUnsigned (q)) return ctype_uint;
2584 if (qual_isLong (q)) return ctype_lint;
2585 if (qual_isShort (q)) return ctype_sint;
2587 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
2588 return ctype_unknown;
2592 ctype_isAnyFloat (ctype c)
2594 return (cprim_isAnyReal (ctype_toCprim (c)));
2598 ctype_isUnsigned (ctype c)
2600 if (ctype_isConj (c))
2601 return (ctype_isUnsigned (ctype_getConjA (c)) ||
2602 ctype_isUnsigned (ctype_getConjB (c)));
2604 return (c == ctype_uint || c == ctype_uchar
2605 || c == ctype_usint || c == ctype_ulint
2606 || c == ctype_ullint
2607 || c == ctype_unsignedintegral);
2612 ctype_isLongLong (ctype c)
2614 if (ctype_isConj (c))
2615 return (ctype_isLongLong (ctype_getConjA (c)) ||
2616 ctype_isLongLong (ctype_getConjB (c)));
2618 return (c == ctype_llint || c == ctype_ullint);
2623 ctype_isLong (ctype c)
2625 if (ctype_isConj (c))
2626 return (ctype_isLong (ctype_getConjA (c)) ||
2627 ctype_isLong (ctype_getConjB (c)));
2629 return (c == ctype_lint || c == ctype_ulint);
2633 ctype_isShort (ctype c)
2635 if (ctype_isConj (c))
2636 return (ctype_isShort (ctype_getConjA (c)) ||
2637 ctype_isShort (ctype_getConjB (c)));
2639 return (c == ctype_sint || c == ctype_usint);
2643 ctype_isStackAllocated (ctype c)
2645 ctype ct = ctype_realType (c);
2647 if (ctype_isConj (ct))
2648 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
2649 ctype_isStackAllocated (ctype_getConjB (ct)));
2651 return (ctype_isArray (c) || ctype_isSU (c));
2654 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
2656 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
2659 static bool ctype_isLonger (ctype c1, ctype c2)
2661 /* 2001-06-10: Fix for long long's provided by Jim Zelenka */
2662 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
2663 || (ctype_isLongLong (c1) && !ctype_isLongLong (c2))
2664 || (ctype_isLong (c1)
2665 && (!ctype_isLong (c2)) && (!ctype_isLongLong (c2)))
2666 || (ctype_isShort (c2) && !ctype_isShort (c1)));
2670 ctype_widest (ctype c1, ctype c2)
2672 if (ctype_isMoreUnsigned (c2, c1) || ctype_isLonger (c2, c1))
2682 static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
2685 if (c >= 0 && c < cttab.size)
2687 return (cttab.entries[c]->ctbase);
2691 if (c == ctype_unknown)
2692 llbuglit ("ctype_getCtbase: ctype unknown");
2693 if (c == ctype_undefined)
2694 llbuglit ("ctype_getCtbase: ctype undefined");
2696 llbuglit ("ctype_getCtbase: ctype dne");
2697 if (c == ctype_elipsMarker)
2698 llbuglit ("ctype_getCtbase: elips marker");
2700 llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
2707 static /*@notnull@*/ /*@observer@*/ ctbase
2708 ctype_getCtbaseSafe (ctype c)
2710 ctbase res = ctype_getCtbase (c);
2712 llassert (ctbase_isDefined (res));
2721 ctype_getCtentry (ctype c)
2723 static /*@only@*/ ctentry errorEntry = NULL;
2725 if (cttab.size == 0)
2727 if (errorEntry == NULL)
2729 errorEntry = ctentry_makeNew (CTK_UNKNOWN, ctbase_undefined);
2736 if (c >= CTK_PLAIN && c < cttab.size)
2738 return (cttab.entries[c]);
2740 else if (c == CTK_UNKNOWN)
2741 llcontbuglit ("ctype_getCtentry: ctype unknown");
2742 else if (c == CTK_INVALID)
2743 llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
2744 else if (c == CTK_DNE)
2745 llcontbuglit ("ctype_getCtentry: ctype dne");
2746 else if (c == CTK_ELIPS)
2747 llcontbuglit ("ctype_getCtentry: ctype elipsis");
2748 else if (c == CTK_MISSINGPARAMS)
2749 llcontbuglit ("ctype_getCtentry: ctype missing params");
2751 llbug (message ("ctype_getCtentry: ctype out of range: %d", c));
2753 return (cttab.entries[ctype_unknown]);
2758 bool ctype_isFixedArray (ctype c)
2760 if (ctype_isElips (c)) return FALSE;
2762 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
2767 /* requires that the type is an fixed array */
2768 /* return the size of the array */
2770 size_t ctype_getArraySize (ctype c)
2776 llassert (ctype_isFixedArray (c));
2778 ctb = ctype_getCtbaseSafe(c);
2779 size = ctbase_getArraySize (ctb);
2781 DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",