00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 # include "lclintMacros.nf"
00032 # include "basic.h"
00033 # include "structNames.h"
00034
00035 static void ctype_recordConj (ctype p_c);
00036
00037
00038
00039
00040
00041
00042 # include "ctbase.i"
00043
00044
00045
00046
00047
00048 # include "cttable.i"
00049
00050 static ctype ctype_getConjA (ctype p_c) ;
00051 static ctype ctype_getConjB (ctype p_c) ;
00052
00053 static bool ctype_isComplex (ctype c)
00054 {
00055 return (ctentry_isComplex (ctype_getCtentry(c)));
00056 }
00057
00058 static bool ctype_isPlain (ctype c)
00059 {
00060 return (ctentry_isPlain (ctype_getCtentry(c)));
00061 }
00062
00063 static bool ctype_isBroken (ctype c)
00064 {
00065
00066 if (c == CTK_DNE || c == CTK_INVALID || c == CTK_UNKNOWN)
00067 {
00068
00069 return TRUE;
00070 }
00071 else
00072 {
00073 ctentry cte = ctype_getCtentry (c);
00074
00075 return (ctentry_isBogus (cte));
00076 }
00077 }
00078
00079 ctkind
00080 ctkind_fromInt (int i)
00081 {
00082
00083 if (i < CTK_UNKNOWN || i > CTK_COMPLEX)
00084 {
00085 llcontbug (message ("ctkind_fromInt: out of range: %d", i));
00086 return CTK_INVALID;
00087 }
00088 return (ctkind) i;
00089
00090 }
00091
00092
00093
00094
00095
00096 void
00097 ctype_initTable ()
00098 {
00099 cttable_init ();
00100 }
00101
00102 void
00103 ctype_destroyMod ()
00104 {
00105 cttable_reset ();
00106 }
00107
00108 void
00109 ctype_loadTable (FILE *f)
00110 {
00111 cttable_load (f);
00112 }
00113
00114 void
00115 ctype_dumpTable (FILE *f)
00116 {
00117 DPRINTF (("Dumping cttable!"));
00118 cttable_dump (f);
00119 }
00120
00121 cstring
00122 ctype_unparseTable ()
00123 {
00124 return (cttable_unparse ());
00125 }
00126
00127 void
00128 ctype_printTable ()
00129 {
00130 cttable_print ();
00131 }
00132
00133 bool
00134 ctype_isUserBool (ctype ct)
00135 {
00136 if (ctype_isUA (ct))
00137 {
00138 return (usymtab_isBoolType (ctype_typeId (ct)));
00139 }
00140
00141 return (FALSE);
00142 }
00143
00144 ctype
00145 ctype_createUser (typeId u)
00146 {
00147
00148
00149 ctbase ct = ctbase_createUser (u);
00150 return (cttable_addFullSafe (ctentry_makeNew (CTK_PLAIN, ct)));
00151 }
00152
00153 ctype
00154 ctype_createAbstract (typeId u)
00155 {
00156
00157
00158 return (cttable_addFullSafe (ctentry_makeNew (CTK_PLAIN, ctbase_createAbstract (u))));
00159 }
00160
00161 int
00162 ctype_count (void)
00163 {
00164 return (cttab.size);
00165 }
00166
00167 ctype
00168 ctype_realType (ctype c)
00169 {
00170 ctype r = c;
00171
00172 if (ctype_isUA (c))
00173 {
00174 r = uentry_getRealType (usymtab_getTypeEntry (ctype_typeId (c)));
00175 }
00176
00177 if (ctype_isManifestBool (r))
00178 {
00179 if (context_canAccessBool ())
00180 {
00181 r = context_boolImplementationType ();
00182 }
00183 }
00184
00185 return r;
00186 }
00187
00188 bool
00189 ctype_isSimple (ctype c)
00190 {
00191 return (!(ctype_isPointer (c)
00192 || ctype_isArray (c)
00193 || ctype_isFunction (c)));
00194 }
00195
00196 ctype
00197 ctype_forceRealType (ctype c)
00198 {
00199 ctype r = c;
00200
00201 if (ctype_isUA (c))
00202 {
00203 r = uentry_getForceRealType (usymtab_getTypeEntry (ctype_typeId (c)));
00204 }
00205
00206 return r;
00207 }
00208
00209 ctype
00210 ctype_realishType (ctype c)
00211 {
00212 if (ctype_isUA (c))
00213 {
00214 if (ctype_isManifestBool (c))
00215 {
00216 return ctype_bool;
00217 }
00218 else
00219 {
00220 ctype r = uentry_getRealType (usymtab_getTypeEntry
00221 (ctype_typeId (c)));
00222 return (r);
00223 }
00224 }
00225
00226 return c;
00227 }
00228
00229 bool
00230 ctype_isUA (ctype c)
00231 {
00232 return (ctbase_isUA (ctype_getCtbase (c)));
00233 }
00234
00235 bool
00236 ctype_isUser (ctype c)
00237 {
00238 return (ctbase_isUser (ctype_getCtbase (c)));
00239 }
00240
00241 bool
00242 ctype_isAbstract (ctype c)
00243 {
00244 return ((ctype_isPlain (c) && ctbase_isAbstract (ctype_getCtbaseSafe (c))) ||
00245 (ctype_isConj (c) &&
00246 (ctype_isAbstract (ctype_getConjA (c))
00247 || ctype_isAbstract (ctype_getConjB (c)))));
00248 }
00249
00250 bool
00251 ctype_isRealAbstract (ctype c)
00252 {
00253 return (ctype_isAbstract (ctype_realType (c)) ||
00254 (ctype_isConj (c) &&
00255 (ctype_isRealAbstract (ctype_getConjA (c)) ||
00256 ctype_isRealAbstract (ctype_getConjB (c)))));
00257 }
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 ctype
00277 ctype_makePointer (ctype c)
00278 {
00279 if (c == ctype_char)
00280 {
00281 return ctype_string;
00282 }
00283 else if (c == ctype_void)
00284 {
00285 return ctype_voidPointer;
00286 }
00287 else
00288 {
00289 ctentry cte = ctype_getCtentry (c);
00290 ctype clp = ctentry_getPtr (cte);
00291
00292 if (clp == CTK_DNE)
00293 {
00294 ctype cnew = cttable_addDerived (CTK_PTR, ctbase_makePointer (c), c);
00295 ctentry_setPtr (cte, cnew);
00296 return (cnew);
00297 }
00298 else
00299 {
00300 return clp;
00301 }
00302 }
00303 }
00304
00305 ctype ctype_makeFixedArray (ctype c, long size)
00306 {
00307 return (cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c));
00308 }
00309
00310 ctype
00311 ctype_makeArray (ctype c)
00312 {
00313 ctentry cte = ctype_getCtentry (c);
00314 ctype clp = ctentry_getArray (cte);
00315
00316 if (clp == CTK_DNE)
00317 {
00318 ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
00319 ctentry_setArray (cte, cnew);
00320 return (cnew);
00321 }
00322 else
00323 return clp;
00324 }
00325
00326
00327
00328
00329
00330 ctype
00331 ctype_baseArrayPtr (ctype c)
00332 {
00333 ctentry cte = ctype_getCtentry (ctype_realType (c));
00334
00335 if (ctype_isConj (c))
00336 {
00337 if (ctype_isAP (ctype_getConjA (c)))
00338 {
00339 if (ctype_isAP (ctype_getConjB (c)))
00340 {
00341 return (ctype_makeConj (ctype_baseArrayPtr (ctype_getConjA (c)),
00342 ctype_baseArrayPtr (ctype_getConjB (c))));
00343 }
00344 else
00345 {
00346 return (ctype_baseArrayPtr (ctype_getConjA (c)));
00347 }
00348 }
00349 else
00350 {
00351 return (ctype_baseArrayPtr (ctype_getConjB (c)));
00352 }
00353 }
00354 else if (ctype_isInt (c))
00355 {
00356 return ctype_unknown;
00357 }
00358 else
00359 {
00360 ctype clp = ctentry_getBase (cte);
00361
00362 if (ctype_isBroken (clp))
00363 {
00364 llbuglit ("ctype_baseArrayPtr: bogus ctype");
00365 }
00366
00367 return clp;
00368 }
00369 }
00370
00371 ctype
00372 ctype_returnValue (ctype c)
00373 {
00374 return (ctbase_baseFunction (ctype_getCtbaseSafe (c)));
00375 }
00376
00377
00378
00379
00380
00381 uentryList
00382 ctype_argsFunction (ctype c)
00383 {
00384 return (ctbase_argsFunction (ctype_getCtbaseSafe (c)));
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394 ctype
00395 ctype_newBase (ctype c, ctype p)
00396 {
00397 return (ctbase_newBase (c, p));
00398 }
00399
00400 bool
00401 ctype_sameAltTypes (ctype c1, ctype c2)
00402 {
00403 ctype c1a, c2a;
00404 ctype c1b, c2b;
00405
00406 llassert (ctype_isConj (c1) && ctype_isConj (c2));
00407
00408 c1a = ctype_getConjA (c1);
00409 c2a = ctype_getConjA (c2);
00410
00411 c1b = ctype_getConjB (c1);
00412 c2b = ctype_getConjB (c2);
00413
00414 if (ctype_compare (c1a, c2a) == 0)
00415 {
00416 if (ctype_compare (c1b, c2b) == 0)
00417 {
00418 return TRUE;
00419 }
00420 else
00421 {
00422 if (ctype_isConj (c1b) && ctype_isConj (c2b))
00423 {
00424 return ctype_sameAltTypes (c1b, c2b);
00425 }
00426 else
00427 {
00428 return FALSE;
00429 }
00430 }
00431 }
00432 else
00433 {
00434 if (ctype_compare (c1a, c2b) == 0)
00435 {
00436 if (ctype_compare (c1b, c2a) == 0)
00437 {
00438 return TRUE;
00439 }
00440 else
00441 {
00442 if (ctype_isConj (c1b) && ctype_isConj (c2a))
00443 {
00444 return ctype_sameAltTypes (c1b, c2a);
00445 }
00446 else
00447 {
00448 return FALSE;
00449 }
00450 }
00451 }
00452 else
00453 {
00454 return FALSE;
00455 }
00456 }
00457 }
00458
00459 int
00460 ctype_compare (ctype c1, ctype c2)
00461 {
00462 ctentry ce1;
00463 ctentry ce2;
00464
00465
00466
00467 if (ctype_isElips (c1) || ctype_isElips (c2)
00468 || ctype_isMissingParamsMarker (c1) || ctype_isMissingParamsMarker (c2)) {
00469 return int_compare (c1, c2);
00470 }
00471
00472 ce1 = ctype_getCtentry (c1);
00473 ce2 = ctype_getCtentry (c2);
00474
00475 if (ctentry_isComplex (ce1))
00476 {
00477 if (ctentry_isComplex (ce2))
00478 {
00479 return (ctbase_compare (ctype_getCtbase (c1),
00480 ctype_getCtbase (c2), FALSE));
00481 }
00482 else
00483 {
00484 return 1;
00485 }
00486 }
00487 else if (ctentry_isComplex (ce2))
00488 {
00489 return -1;
00490 }
00491 else
00492 {
00493 return (int_compare (c1, c2));
00494 }
00495 }
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505 ctype
00506 ctype_makeParamsFunction (ctype base, uentryList p)
00507 {
00508 uentryList_fixImpParams (p);
00509 return (ctype_makeFunction (base, p));
00510 }
00511
00512 ctype
00513 ctype_makeNFParamsFunction (ctype base, uentryList p)
00514 {
00515 uentryList_fixImpParams (p);
00516 return (ctbase_makeNFFunction (base, p));
00517 }
00518
00519 ctype
00520 ctype_makeFunction (ctype base, uentryList p)
00521 {
00522 ctype ret;
00523 ret = ctbase_makeFunction (base, p);
00524 return (ret);
00525 }
00526
00527 ctype ctype_expectFunction (ctype c)
00528 {
00529
00530
00531 if (!ctype_isAP (c))
00532 {
00533 c = ctype_makePointer (c);
00534 }
00535
00536 return (cttable_addComplex (ctbase_expectFunction (c)));
00537 }
00538
00539
00540
00541
00542
00543 ctype ctype_makeRealFunction (ctype base, uentryList p)
00544 {
00545 return (cttable_addComplex (ctbase_makeRealFunction (base, p)));
00546 }
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558 bool
00559 ctype_isFunction (ctype c)
00560 {
00561 return (ctbase_isFunction (ctype_getCtbase (c)));
00562 }
00563
00564 bool
00565 ctype_isExpFcn (ctype c)
00566 {
00567 return (ctbase_isExpFcn (ctype_getCtbase (c)));
00568 }
00569
00570 bool
00571 ctype_isVoid (ctype c)
00572 {
00573 return (c == CTX_VOID);
00574 }
00575
00576 bool
00577 ctype_isArbitraryIntegral (ctype c)
00578 {
00579 ctype cr = ctype_realType (c);
00580
00581 return (cr == ctype_anyintegral || cr == ctype_unsignedintegral
00582 || cr == ctype_signedintegral);
00583 }
00584
00585 bool
00586 ctype_isUnsignedIntegral (ctype c)
00587 {
00588 ctype cr = ctype_realType (c);
00589
00590 return (cr == ctype_unsignedintegral);
00591 }
00592
00593 bool
00594 ctype_isSignedIntegral (ctype c)
00595 {
00596 ctype cr = ctype_realType (c);
00597
00598 return (cr == ctype_signedintegral);
00599 }
00600
00601 bool
00602 ctype_isInt (ctype c)
00603 {
00604 cprim cp = ctype_toCprim (c);
00605
00606 return (c == ctype_unknown || cprim_isAnyInt (cp)
00607 || (cprim_isAnyChar (cp) && context_msgCharInt ())
00608 || (c == ctype_bool && context_msgBoolInt ())
00609 || (ctype_isEnum (c) && context_msgEnumInt ()));
00610 }
00611
00612 bool
00613 ctype_isRegularInt (ctype c)
00614 {
00615 cprim cp = ctype_toCprim (c);
00616
00617 return (c == ctype_unknown
00618 || cprim_closeEnough (cprim_int, cp)
00619 || (cprim_isAnyChar (cp) && context_msgCharInt ())
00620 || (c == ctype_bool && context_msgBoolInt ())
00621 || (ctype_isEnum (c) && context_msgEnumInt ()));
00622 }
00623
00624 bool
00625 ctype_isString (ctype c)
00626 {
00627 return (c == ctype_string
00628 || (ctype_isPointer (c)
00629 && ctype_isChar (ctype_baseArrayPtr (c))));
00630 }
00631
00632 bool
00633 ctype_isChar (ctype c)
00634 {
00635 return ((c == ctype_unknown) || (cprim_isAnyChar (ctype_toCprim (c)))
00636 || (context_getFlag (FLG_CHARINT) && ctype_isInt (c)));
00637 }
00638
00639 bool
00640 ctype_isUnsignedChar (ctype c)
00641 {
00642 return ((c == ctype_unknown) || (cprim_isUnsignedChar (ctype_toCprim (c))));
00643 }
00644
00645 bool
00646 ctype_isSignedChar (ctype c)
00647 {
00648 return ((c == ctype_unknown) || (cprim_isSignedChar (ctype_toCprim (c))));
00649 }
00650
00651
00652
00653
00654
00655 bool
00656 ctype_isManifestBool (ctype c)
00657 {
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668 if (ctype_isDirectBool (c)) {
00669 return TRUE;
00670 } else if (ctype_isUA (c)) {
00671 return ctype_isUserBool (c);
00672 } else {
00673 return FALSE;
00674 }
00675 }
00676
00677 bool
00678 ctype_isBool (ctype c)
00679 {
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689 if (ctype_isManifestBool (c)) {
00690 return TRUE;
00691 } else if (context_msgBoolInt ()) {
00692 return ctype_isInt (c);
00693 } else {
00694 return FALSE;
00695 }
00696
00697 # if 0
00698 if (context_getFlag (FLG_ABSTRACTBOOL))
00699 {
00700 if (typeId_isInvalid (boolType))
00701 {
00702 boolType = usymtab_getTypeId (context_getBoolName ());
00703 }
00704
00705 if (context_hasAccess (boolType))
00706 {
00707 return (((c == CTX_UNKNOWN) || (c == CTX_BOOL)
00708 || (context_msgBoolInt ()
00709 && (c == CTX_INT
00710 || (c == CTX_CHAR && context_msgCharInt ()))))
00711 || ctype_isInt (c));
00712 }
00713 }
00714
00715 return ((c == CTX_UNKNOWN) || (c == CTX_BOOL)
00716 || (context_msgBoolInt ()
00717 && (c == CTX_INT || (c == CTX_CHAR && context_msgCharInt ()))));
00718 # endif
00719 }
00720
00721 bool
00722 ctype_isDirectBool (ctype c)
00723 {
00724 return (c == CTX_BOOL);
00725 }
00726
00727 bool
00728 ctype_isReal (ctype c)
00729 {
00730 return (cprim_isAnyReal (ctype_toCprim (c)));
00731 }
00732
00733 bool
00734 ctype_isFloat (ctype c)
00735 {
00736 return (c == ctype_float);
00737 }
00738
00739 bool
00740 ctype_isDouble (ctype c)
00741 {
00742 return (c == ctype_double || c == ctype_ldouble);
00743 }
00744
00745 bool
00746 ctype_isSigned (ctype c)
00747 {
00748 return (!ctype_isUnsigned (c));
00749 }
00750
00751 bool
00752 ctype_isNumeric (ctype c)
00753 {
00754 return (ctype_isInt (c) || ctype_isReal (c) || ctype_isEnum (c));
00755 }
00756
00757
00758
00759
00760
00761
00762
00763
00764 bool
00765 ctype_isRealNumeric (ctype c)
00766 {
00767 if (ctype_isPlain (c))
00768 return (ctype_isNumeric (ctype_realType (c)));
00769 if (ctype_isConj (c))
00770 return (ctype_isRealNumeric (ctype_getConjA (c)) ||
00771 ctype_isRealNumeric (ctype_getConjB (c)));
00772 else
00773 return FALSE;
00774 }
00775
00776 bool
00777 ctype_isRealInt (ctype c)
00778 {
00779 if (ctype_isPlain (c))
00780 return (ctype_isInt (ctype_realType (c)));
00781 else if (ctype_isConj (c))
00782 return (ctype_isRealInt (ctype_getConjA (c)) ||
00783 ctype_isRealInt (ctype_getConjB (c)));
00784 else
00785 {
00786 if (ctype_isEnum (c) && context_msgEnumInt ()) return TRUE;
00787 return FALSE;
00788 }
00789 }
00790
00791 bool
00792 ctype_isRealVoid (ctype c)
00793 {
00794 if (ctype_isPlain (c))
00795 {
00796 return (ctype_isVoid (ctype_realType (c)));
00797 }
00798 else if (ctype_isConj (c))
00799 {
00800 return (ctype_isRealVoid (ctype_getConjA (c)) ||
00801 ctype_isRealVoid (ctype_getConjB (c)));
00802 }
00803 else
00804 {
00805 return FALSE;
00806 }
00807 }
00808
00809 bool
00810 ctype_isRealBool (ctype c)
00811 {
00812 if (ctype_isPlain (c))
00813 {
00814 return (ctype_isBool (ctype_realishType (c)));
00815 }
00816 else if (ctype_isConj (c))
00817 {
00818 return (ctype_isRealBool (ctype_getConjA (c)) ||
00819 ctype_isRealBool (ctype_getConjB (c)));
00820 }
00821 else
00822 {
00823 return FALSE;
00824 }
00825 }
00826
00827 bool
00828 ctype_isRealPointer (ctype c)
00829 {
00830 if (ctype_isConj (c))
00831 return (ctype_isRealPointer (ctype_getConjA (c)) ||
00832 ctype_isRealPointer (ctype_getConjB (c)));
00833 return (ctype_isPointer (ctype_realType (c)));
00834 }
00835
00836 bool
00837 ctype_isRealSU (ctype c)
00838 {
00839 if (ctype_isConj (c))
00840 {
00841 return (ctype_isRealSU (ctype_getConjA (c)) ||
00842 ctype_isRealSU (ctype_getConjB (c)));
00843 }
00844 return (ctype_isStructorUnion (ctype_realType (c)));
00845 }
00846
00847 bool
00848 ctype_isRealArray (ctype c)
00849 {
00850 if (ctype_isConj (c))
00851 return (ctype_isRealArray (ctype_getConjA (c)) ||
00852 ctype_isRealArray (ctype_getConjB (c)));
00853 return (ctype_isArray (ctype_realType (c)));
00854 }
00855
00856 bool
00857 ctype_isRealAP (ctype c)
00858 {
00859 if (ctype_isConj (c))
00860 return (ctype_isRealAP (ctype_getConjA (c)) ||
00861 ctype_isRealAP (ctype_getConjB (c)));
00862 return (ctype_isAP (ctype_realType (c)));
00863 }
00864
00865 bool
00866 ctype_isRealFunction (ctype c)
00867 {
00868 if (ctype_isConj (c))
00869 return (ctype_isRealFunction (ctype_getConjA (c)) ||
00870 ctype_isRealFunction (ctype_getConjB (c)));
00871 return (ctype_isFunction (ctype_realType (c)));
00872 }
00873
00874 bool
00875 ctype_isDirectInt (ctype c)
00876 {
00877 return (c == CTX_INT || c == CTX_UINT || c == CTX_SINT || c == CTX_ULINT || c == CTX_USINT);
00878 }
00879
00880
00881
00882
00883
00884
00885
00886
00887 static bool
00888 ctype_isForcePred (ctype * c, bool (pred) (ctype))
00889 {
00890 if (ctype_isConj (*c))
00891 {
00892 ctype cbr = ctype_getConjA (*c);
00893
00894 if ((*pred) (cbr))
00895 {
00896 if ((*pred) (ctype_getConjB (*c)))
00897 {
00898 ;
00899 }
00900 else
00901 {
00902 *c = cbr;
00903 }
00904
00905 return TRUE;
00906 }
00907 else
00908 {
00909 if ((*pred) (cbr = ctype_getConjB (*c)))
00910 {
00911 *c = cbr;
00912 return TRUE;
00913 }
00914 }
00915 }
00916
00917 return ((*pred) (*c));
00918 }
00919
00920 bool
00921 ctype_isForceRealNumeric (ctype * c)
00922 {
00923 return (ctype_isForcePred (c, ctype_isRealNumeric));
00924 }
00925
00926 bool
00927 ctype_isForceRealInt (ctype * c)
00928 {
00929 return (ctype_isForcePred (c, ctype_isRealInt));
00930 }
00931
00932 bool
00933 ctype_isForceRealBool (ctype * c)
00934 {
00935 return (ctype_isForcePred (c, ctype_isRealBool));
00936 }
00937
00938
00939
00940
00941
00942
00943
00944 static ctype
00945 ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
00946 {
00947 if (ctype_isBogus (c1) || ctype_isUndefined (c1))
00948 {
00949 return c2;
00950 }
00951 else if (ctype_isBogus (c2) || ctype_isUndefined (c2))
00952 {
00953 return c1;
00954 }
00955 else
00956 {
00957 if (isExplicit)
00958 {
00959 return (ctype_makeExplicitConj (c1, c2));
00960 }
00961 else
00962 {
00963 return (ctype_makeConj (c1, c2));
00964 }
00965 }
00966 }
00967
00968 ctype
00969 ctype_makeExplicitConj (ctype c1, ctype c2)
00970 {
00971 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
00972 {
00973 ctype ret = ctype_makeExplicitConj (ctype_returnValue (c1), c2);
00974
00975 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
00976 }
00977 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
00978 {
00979 ctype ret = ctype_makeExplicitConj (c1, ctype_returnValue (c2));
00980
00981 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
00982 }
00983 else
00984 {
00985 return (cttable_addComplex (ctbase_makeConj (c1, c2, TRUE)));
00986 }
00987 }
00988
00989 static ctype ic = ctype_unknown;
00990 static ctype ib = ctype_unknown;
00991 static ctype ifl = ctype_unknown;
00992 static ctype ibf = ctype_unknown;
00993 static ctype ibc = ctype_unknown;
00994 static ctype iv = ctype_unknown;
00995 static ctype ivf = ctype_unknown;
00996 static ctype ivb = ctype_unknown;
00997 static ctype ivbf = ctype_unknown;
00998 static ctype cuc = ctype_unknown;
00999
01000 static void
01001 ctype_recordConj (ctype c)
01002 {
01003 ctype c1, c2;
01004
01005 llassert (ctype_isConj (c));
01006
01007 c1 = ctype_getConjA (c);
01008 c2 = ctype_getConjB (c);
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021 if (c1 == ctype_int)
01022 {
01023 if (c2 == ctype_char)
01024 {
01025 llassert (ic == ctype_unknown);
01026 ic = c;
01027 }
01028 else if (c2 == ctype_bool)
01029 {
01030 llassert (ib == ctype_unknown);
01031 ib = c;
01032 }
01033 else if (c2 == ctype_float)
01034 {
01035 llassert (ifl == ctype_unknown);
01036 ifl = c;
01037 }
01038 else if (c2 == CTP_VOID)
01039 {
01040 llassert (iv == ctype_unknown);
01041 iv = c;
01042 }
01043 else
01044 {
01045
01046 }
01047 }
01048 else if (c1 == ib && ib != ctype_unknown)
01049 {
01050 if (c2 == ctype_float)
01051 {
01052 llassert (ibf == ctype_unknown);
01053 ibf = c;
01054 }
01055 else if (c2 == ctype_char)
01056 {
01057 llassert (ibc == ctype_unknown);
01058 ibc = c;
01059 }
01060 else
01061 {
01062
01063 }
01064 }
01065 else if (c1 == iv)
01066 {
01067 if (c2 == ctype_bool)
01068 {
01069 llassert (ivb == ctype_unknown);
01070 ivb = c;
01071 }
01072 else if (c2 == ctype_float)
01073 {
01074 llassert (ivf == ctype_unknown);
01075 ivf = c;
01076 }
01077 else
01078 {
01079
01080 }
01081 }
01082 else if (c1 == ivf)
01083 {
01084 if (c2 == ctype_bool)
01085 {
01086 llassert (ivbf == ctype_unknown);
01087 ivbf = c;
01088 }
01089 }
01090 else if (c1 == ivb)
01091 {
01092 if (c2 == ctype_float)
01093 {
01094 llassert (ivbf == ctype_unknown);
01095 ivbf = c;
01096 }
01097 }
01098 else if (c1 == ctype_char)
01099 {
01100 if (c2 == ctype_uchar)
01101 {
01102 llassert (cuc == ctype_unknown);
01103
01104 cuc = c;
01105 }
01106 }
01107 else
01108 {
01109
01110 }
01111 }
01112
01113 ctype
01114 ctype_makeConj (ctype c1, ctype c2)
01115 {
01116
01117
01118 DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
01119
01120 if (ctype_isFunction (c1) && !ctype_isFunction (c2))
01121 {
01122 ctype ret = ctype_makeConj (ctype_returnValue (c1), c2);
01123 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c1)));
01124 }
01125 else if (ctype_isFunction (c2) && !ctype_isFunction (c1))
01126 {
01127 ctype ret = ctype_makeConj (c1, ctype_returnValue (c2));
01128 return ctype_makeFunction (ret, uentryList_copy (ctype_getParams (c2)));
01129 }
01130 else
01131 {
01132 if (ctype_isManifestBool (c1))
01133 {
01134 c1 = ctype_bool;
01135 }
01136
01137 if (ctype_isManifestBool (c2))
01138 {
01139 c2 = ctype_bool;
01140 }
01141
01142 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c1)))
01143 {
01144 c1 = ctype_voidPointer;
01145 }
01146
01147 if (ctbase_isVoidPointer (ctype_getCtbaseSafe (c2)))
01148 {
01149 c2 = ctype_voidPointer;
01150 }
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167 if (c1 == ctype_int)
01168 {
01169 if (c2 == ctype_char)
01170 {
01171 if (ic == ctype_unknown)
01172 {
01173 ic = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_char, FALSE));
01174 }
01175
01176 return ic;
01177 }
01178 else if (c2 == ctype_bool)
01179 {
01180 if (ib == ctype_unknown)
01181 {
01182 ib = cttable_addComplex
01183 (ctbase_makeConj (ctype_int, ctype_bool, FALSE));
01184 }
01185
01186 return ib;
01187 }
01188 else if (c2 == ctype_float)
01189 {
01190 if (ifl == ctype_unknown)
01191 {
01192 ifl = cttable_addComplex (ctbase_makeConj (ctype_int, ctype_float, FALSE));
01193 }
01194
01195 return ifl;
01196 }
01197 else
01198 {
01199 if (c2 == ctype_voidPointer)
01200 {
01201 if (iv == ctype_unknown)
01202 {
01203 iv = cttable_addComplex
01204 (ctbase_makeConj (ctype_int,
01205 ctype_voidPointer,
01206 FALSE));
01207 }
01208
01209 return iv;
01210 }
01211 }
01212 }
01213 else if (c1 == ib && ib != ctype_unknown)
01214 {
01215 if (c2 == ctype_float)
01216 {
01217 if (ibf == ctype_unknown)
01218 {
01219 ibf = cttable_addComplex (ctbase_makeConj (ib, ctype_float, FALSE));
01220 }
01221
01222 return ibf;
01223 }
01224 else if (c2 == ctype_char)
01225 {
01226 if (ibc == ctype_unknown)
01227 {
01228 ibc = cttable_addComplex (ctbase_makeConj (ib, ctype_char, FALSE));
01229 }
01230
01231 return ibc;
01232 }
01233 else
01234 {
01235 ;
01236 }
01237 }
01238 else if (c1 == iv)
01239 {
01240 if (c2 == ctype_bool)
01241 {
01242 if (ivb == ctype_unknown)
01243 {
01244 ivb = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
01245 }
01246
01247 return ivb;
01248 }
01249 else if (c2 == ctype_float)
01250 {
01251 if (ivf == ctype_unknown)
01252 {
01253 ivf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
01254 }
01255
01256 return ivf;
01257 }
01258 else
01259 {
01260 ;
01261 }
01262 }
01263 else if (c1 == ivf)
01264 {
01265 if (c2 == ctype_bool)
01266 {
01267 if (ivbf == ctype_unknown)
01268 {
01269 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
01270 }
01271
01272 return ivbf;
01273 }
01274 }
01275 else if (c1 == ivb)
01276 {
01277 if (c2 == ctype_float)
01278 {
01279 if (ivbf == ctype_unknown)
01280 {
01281 ivbf = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
01282 }
01283
01284 return ivbf;
01285 }
01286 }
01287 else if (c1 == ctype_char)
01288 {
01289 if (c2 == ctype_uchar)
01290 {
01291 if (cuc == ctype_unknown)
01292 {
01293 cuc = cttable_addComplex (ctbase_makeConj (c1, c2, FALSE));
01294 }
01295
01296 return cuc;
01297 }
01298 }
01299 else
01300 {
01301 ;
01302 }
01303
01304
01305 return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
01306 }
01307 }
01308
01309
01310 bool
01311 ctype_isConj (ctype c)
01312 {
01313 return (ctype_isComplex (c) && ctbase_isConj (ctype_getCtbase (c)));
01314 }
01315
01316 static ctype
01317 ctype_getConjA (ctype c)
01318 {
01319 if (!ctype_isConj (c))
01320 llbuglit ("ctype_getConjA: not a conj");
01321 return (ctbase_getConjA (ctype_getCtbaseSafe (c)));
01322 }
01323
01324 static ctype
01325 ctype_getConjB (ctype c)
01326 {
01327 if (!ctype_isConj (c))
01328 llbuglit ("ctype_getConjB: not a conj");
01329 return (ctbase_getConjB (ctype_getCtbaseSafe (c)));
01330 }
01331
01332 static bool
01333 ctype_isExplicitConj (ctype c)
01334 {
01335 return (ctype_isConj (c) && ctbase_isExplicitConj (ctype_getCtbaseSafe (c)));
01336 }
01337
01340
01341
01342
01343
01344 ctype
01345 ctype_createStruct ( cstring n, uentryList f)
01346 {
01347 ctype ct;
01348
01349 ct = cttable_addComplex (ctbase_createStruct (n, f));
01350 return (ct);
01351 }
01352
01353 uentryList
01354 ctype_getFields (ctype c)
01355 {
01356 return (ctbase_getuentryList (ctype_getCtbaseSafe (c)));
01357 }
01358
01359 ctype
01360 ctype_createUnion ( cstring n, uentryList f)
01361 {
01362 ctype ret;
01363
01364 ret = cttable_addComplex (ctbase_createUnion (n, f));
01365 return ret;
01366 }
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377 static bool
01378 quickMatch (ctype c1, ctype c2)
01379 {
01380 if (c1 == c2)
01381 return TRUE;
01382
01383 return FALSE;
01384 }
01385
01386 bool
01387 ctype_genMatch (ctype c1, ctype c2, bool force, bool arg, bool def, bool deep)
01388 {
01389 bool match;
01390
01391 DPRINTF (("Gen match: %s / %s arg: %s", ctype_unparse (c1), ctype_unparse (c2), bool_unparse (arg)));
01392
01393 if (quickMatch (c1, c2))
01394 {
01395 return TRUE;
01396 }
01397
01398 if (ctype_isElips (c1) || ctype_isElips (c2))
01399 {
01400 return FALSE;
01401 }
01402 else
01403 {
01404 match = ctbase_genMatch (ctype_getCtbase (c1), ctype_getCtbase (c2), force, arg, def, deep);
01405 return (match);
01406 }
01407 }
01408
01409 bool
01410 ctype_sameName (ctype c1, ctype c2)
01411 {
01412 if (quickMatch (c1, c2))
01413 return TRUE;
01414 else
01415 return (cstring_equal (ctype_unparse (c1), ctype_unparse (c2)));
01416 }
01417
01418 bool
01419 ctype_almostEqual (ctype c1, ctype c2)
01420 {
01421 if (ctype_equal (c1, c2))
01422 {
01423 return TRUE;
01424 }
01425 else
01426 {
01427 return (ctbase_almostEqual (ctype_getCtbase (c1), ctype_getCtbase (c2)));
01428 }
01429 }
01430
01431 bool
01432 ctype_matchDef (ctype c1, ctype c2)
01433 {
01434 if (quickMatch (c1, c2))
01435 return TRUE;
01436
01437 if (ctype_isElips (c1))
01438 return (ctype_isElips (c2) || ctype_isUnknown (c2));
01439
01440 if (ctype_isElips (c2))
01441 return (ctype_isUnknown (c2));
01442 else
01443 {
01444 bool oldrelax = context_getFlag (FLG_RELAXQUALS);
01445 bool res;
01446
01447 context_setFlagTemp (FLG_RELAXQUALS, FALSE);
01448 res = ctbase_matchDef (ctype_getCtbase (c1), ctype_getCtbase (c2));
01449 context_setFlagTemp (FLG_RELAXQUALS, oldrelax);
01450 return res;
01451 }
01452 }
01453
01454 bool ctype_match (ctype c1, ctype c2)
01455 {
01456 if (quickMatch (c1, c2))
01457 return TRUE;
01458
01459 if (ctype_isElips (c1))
01460 return (ctype_isElips (c2) || ctype_isUnknown (c2));
01461
01462 if (ctype_isElips (c2))
01463 return (ctype_isUnknown (c2));
01464
01465 return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2)));
01466 }
01467
01468 bool
01469 ctype_forceMatch (ctype c1, ctype c2)
01470 {
01471 if (quickMatch (c1, c2))
01472 return TRUE;
01473
01474 if (ctype_isElips (c1))
01475 return (ctype_isElips (c2));
01476
01477 if (ctype_isElips (c2))
01478 return FALSE;
01479
01480
01481
01482 return (ctbase_forceMatch (ctype_getCtbase (c1), ctype_getCtbase (c2)));
01483
01484 }
01485
01486 bool
01487 ctype_matchArg (ctype c1, ctype c2)
01488 {
01489 if (quickMatch (c1, c2))
01490 {
01491 return TRUE;
01492 }
01493 else
01494 {
01495 return (ctbase_matchArg (ctype_getCtbase (c1), ctype_getCtbase (c2)));
01496 }
01497 }
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510 bool
01511 ctype_isVoidPointer (ctype c)
01512 {
01513 if (ctype_isComplex (c))
01514 {
01515 return ctbase_isVoidPointer (ctype_getCtbaseSafe (c));
01516 }
01517 if (ctype_isConj (c))
01518 {
01519 return (ctype_isVoidPointer (ctype_getConjA (c)) ||
01520 ctype_isVoidPointer (ctype_getConjB (c)));
01521 }
01522 else
01523 {
01524 return (c == ctype_voidPointer
01525 || (ctype_isRealPointer (c)
01526 && ctype_isVoid (ctype_baseArrayPtr (c))));
01527 }
01528 }
01529
01530
01531
01532
01533
01534
01535
01536 bool
01537 ctype_isPointer (ctype c)
01538 {
01539 if (ctype_isElips (c)) return FALSE;
01540
01541 if (ctype_isComplex (c))
01542 {
01543 ctbase ctb = ctype_getCtbaseSafe (c);
01544 bool res = ctbase_isPointer (ctb);
01545
01546 return res;
01547 }
01548 else
01549 {
01550 bool res = ctentry_isPointer (ctype_getCtentry (c));
01551
01552 return res;
01553 }
01554 }
01555
01556
01557
01558
01559
01560
01561
01562 bool
01563 ctype_isArray (ctype c)
01564 {
01565 if (ctype_isElips (c)) return FALSE;
01566
01567 if (ctype_isComplex (c))
01568 return (ctbase_isEitherArray (ctype_getCtbaseSafe (c)));
01569 else
01570 return (ctentry_isArray (ctype_getCtentry (c)));
01571 }
01572
01573 bool ctype_isIncompleteArray (ctype c)
01574 {
01575 return (ctype_isArray (c) && !ctype_isFixedArray (c));
01576 }
01577
01578 bool ctype_isFixedArray (ctype c)
01579 {
01580 if (ctype_isElips (c)) return FALSE;
01581
01582 return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
01583 }
01584
01585 bool
01586 ctype_isArrayPtr (ctype c)
01587 {
01588 return ((ctype_isArray (c)) || (ctype_isPointer (c)));
01589 }
01590
01591 typeId
01592 ctype_typeId (ctype c)
01593 {
01594 return (ctbase_typeId (ctype_getCtbase (c)));
01595 }
01596
01597 cstring
01598 ctype_unparseDeclaration (ctype c, cstring name)
01599 {
01600 llassert (!(ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
01601 return (ctbase_unparseDeclaration (ctype_getCtbase (c), name));
01602 }
01603
01604 cstring
01605 ctype_unparse (ctype c)
01606 {
01607 if (ctype_isElips (c))
01608 {
01609 return cstring_makeLiteralTemp ("...");
01610 }
01611 else if (ctype_isMissingParamsMarker (c))
01612 {
01613 return cstring_makeLiteralTemp ("-");
01614 }
01615 else
01616 {
01617
01618 return (ctentry_doUnparse (ctype_getCtentry (c)));
01619
01620 }
01621 }
01622
01623 cstring
01624 ctype_unparseSafe (ctype c)
01625 {
01626 if (ctype_isElips (c))
01627 {
01628 return cstring_makeLiteralTemp ("...");
01629 }
01630 else if (ctype_isMissingParamsMarker (c))
01631 {
01632 return cstring_makeLiteralTemp ("-");
01633 }
01634 else
01635 {
01636 cstring ret;
01637
01638 if (c >= CTK_PLAIN && c < cttab.size)
01639 {
01640 ctentry cte = ctype_getCtentry (c);
01641
01642 if (cstring_isDefined (cte->unparse))
01643 {
01644 return (cte->unparse);
01645 }
01646 }
01647
01648 ret = message ("[%d]", (int) c);
01649 cstring_markOwned (ret);
01650 return ret;
01651 }
01652 }
01653
01654 cstring
01655 ctype_unparseDeep (ctype c)
01656 {
01657 if (ctype_isElips (c))
01658 {
01659 return cstring_makeLiteralTemp ("...");
01660 }
01661 if (ctype_isMissingParamsMarker (c))
01662 {
01663 return cstring_makeLiteralTemp ("-");
01664 }
01665
01666 return (ctentry_doUnparseDeep (ctype_getCtentry (c)));
01667 }
01668
01669 ctype
01670 ctype_undump (char **c)
01671 {
01672 return ((ctype) getInt (c));
01673 }
01674
01675 cstring
01676 ctype_dump (ctype c)
01677 {
01678 DPRINTF (("Ctype dump: %s", ctype_unparse (c)));
01679
01680 if (c < 0)
01681 {
01682
01683 return (message ("0"));
01684 }
01685
01686 if (ctype_isUA (c))
01687 {
01688 cstring tname = usymtab_getTypeEntryName
01689 (usymtab_convertId (ctype_typeId (c)));
01690
01691 if (cstring_equal (tname, context_getBoolName ()))
01692 {
01693 cstring_free (tname);
01694 return (message ("%d", ctype_bool));
01695 }
01696
01697 cstring_free (tname);
01698 }
01699
01700 DPRINTF (("Returning: %d", c));
01701 return (message ("%d", c));
01702 }
01703
01704 ctype
01705 ctype_getBaseType (ctype c)
01706 {
01707 ctentry cte = ctype_getCtentry (c);
01708
01709 switch (ctentry_getKind (cte))
01710 {
01711 case CTK_UNKNOWN:
01712 llcontbuglit ("ctype_getBaseType: unknown ctype"); break;
01713 case CTK_INVALID:
01714 llcontbuglit ("ctype_getBaseType: invalid ctype"); break;
01715 case CTK_PLAIN:
01716 return c;
01717 case CTK_PTR:
01718 case CTK_ARRAY:
01719 return (ctype_getBaseType (ctype_baseArrayPtr (c)));
01720 case CTK_COMPLEX:
01721 {
01722 ctbase ctb = cte->ctbase;
01723
01724 if (ctbase_isDefined (ctb))
01725 {
01726 switch (ctb->type)
01727 {
01728 case CT_UNKNOWN:
01729 case CT_PRIM:
01730 case CT_USER:
01731 case CT_ENUM:
01732 case CT_ENUMLIST:
01733 case CT_BOOL:
01734 case CT_ABST:
01735 case CT_FCN:
01736 case CT_STRUCT:
01737 case CT_UNION:
01738 case CT_EXPFCN:
01739 return c;
01740 case CT_PTR:
01741 case CT_ARRAY:
01742 return (ctype_getBaseType (ctb->contents.base));
01743 case CT_FIXEDARRAY:
01744 return (ctype_getBaseType (ctb->contents.farray->base));
01745 case CT_CONJ:
01746 return (ctype_getBaseType (ctb->contents.conj->a));
01747 }
01748 }
01749 else
01750 {
01751 return c;
01752 }
01753 }
01754 default:
01755 llbuglit ("ctype_newBase: bad case");
01756 }
01757 llcontbuglit ("ctype_getBaseType: unreachable code");
01758 return ((ctype)NULL);
01759 }
01760
01761 ctype
01762 ctype_adjustPointers (int np, ctype c)
01763 {
01764
01765 if (ctype_isFunction (c))
01766 {
01767 c = ctype_makeParamsFunction
01768 (ctype_adjustPointers (np, ctype_returnValue (c)),
01769 uentryList_copy (ctype_argsFunction (c)));
01770 }
01771 else
01772 {
01773
01774 ctype cb = ctype_getBaseType (c);
01775
01776 while (np > 0)
01777 {
01778 cb = ctype_makePointer (cb);
01779 np--;
01780 }
01781 c = ctype_newBase (c, cb);
01782 }
01783
01784 return (c);
01785 }
01786
01787
01788 enumNameList
01789 ctype_elist (ctype c)
01790 {
01791 return (ctbase_elist (ctype_getCtbase (c)));
01792 }
01793
01794 bool
01795 ctype_isFirstVoid (ctype c)
01796 {
01797 return (c == CTX_VOID || (ctype_isConj (c) && ctype_isFirstVoid (ctype_getConjA (c))));
01798 }
01799
01800 ctype
01801 ctype_createEnum ( cstring tag, enumNameList el)
01802 {
01803 return (cttable_addComplex (ctbase_createEnum (tag, el)));
01804 }
01805
01806 bool
01807 ctype_isEnum (ctype c)
01808 {
01809 return (ctype_isComplex (c) && ctbase_isEnum (ctype_getCtbase (c)));
01810 }
01811
01812 cstring
01813 ctype_enumTag (ctype c)
01814 {
01815 llassert (ctype_isEnum (c));
01816
01817 return (ctbase_enumTag (ctype_getCtbaseSafe (c)));
01818 }
01819
01820 bool
01821 ctype_isStruct (ctype c)
01822 {
01823 return (ctype_isComplex (c) && ctbase_isStruct (ctype_getCtbaseSafe (c)));
01824 }
01825
01826 bool
01827 ctype_isUnion (ctype c)
01828 {
01829 return (ctype_isComplex (c) && ctbase_isUnion (ctype_getCtbaseSafe (c)));
01830 }
01831
01832 ctype
01833 ctype_resolveNumerics (ctype c1, ctype c2)
01834 {
01835
01836
01837
01838
01839 if (c1 == c2) return c1;
01840
01841 c1 = ctype_realType (c1);
01842 c2 = ctype_realType (c2);
01843
01844 if (ctype_isEnum (c1)) c1 = ctype_unknown;
01845 if (ctype_isEnum (c2)) c2 = ctype_int;
01846
01847 if (c1 == ctype_ldouble || c2 == ctype_ldouble) return ctype_ldouble;
01848 if (c1 == ctype_ulint || c2 == ctype_ulint) return ctype_ulint;
01849 if (c1 == ctype_lint || c2 == ctype_lint) return ctype_lint;
01850 if (c1 == ctype_uint || c2 == ctype_uint) return ctype_uint;
01851 if (c1 == ctype_int || c2 == ctype_int) return ctype_int;
01852 if (c1 == ctype_sint || c2 == ctype_sint) return ctype_sint;
01853 if (c1 == ctype_uchar || c2 == ctype_uchar) return ctype_uchar;
01854 if (c1 == ctype_char || c2 == ctype_char) return ctype_char;
01855
01856 if (ctype_isKnown (c1)) return c1;
01857 else return c2;
01858 }
01859
01860 bool
01861 ctype_isStructorUnion (ctype c)
01862 {
01863 return (ctype_isStruct (c) || ctype_isUnion (c));
01864 }
01865
01866 ctype
01867 ctype_fixArrayPtr (ctype c)
01868 {
01869 if (ctype_isArray (c))
01870 {
01871 return (ctype_makePointer (ctype_baseArrayPtr (c)));
01872 }
01873 else
01874 return c;
01875 }
01876
01877
01878
01879
01880
01881
01882
01883
01884 ctype
01885 ctype_createUnnamedStruct ( uentryList f)
01886 {
01887 ctype ret = usymtab_structFieldsType (f);
01888
01889 if (ctype_isDefined (ret))
01890 {
01891 uentryList_free (f);
01892 return ret;
01893 }
01894 else
01895 {
01896 cstring ft = fakeTag ();
01897 ctype ct = ctype_createStruct (cstring_copy (ft), f);
01898 uentry ue = uentry_makeStructTagLoc (ft, ct);
01899
01900 usymtab_supGlobalEntry (ue);
01901
01902 cstring_free (ft);
01903 return (ct);
01904 }
01905 }
01906
01907 ctype
01908 ctype_createUnnamedUnion ( uentryList f)
01909 {
01910 ctype ret = usymtab_unionFieldsType (f);
01911
01912 if (ctype_isDefined (ret))
01913 {
01914 uentryList_free (f);
01915 return ret;
01916 }
01917 else
01918 {
01919 cstring ft = fakeTag ();
01920 ctype ct = ctype_createUnion (cstring_copy (ft), f);
01921 uentry ue = uentry_makeUnionTagLoc (ft, ct);
01922
01923 usymtab_supGlobalEntry (ue);
01924 cstring_free (ft);
01925 return (ct);
01926 }
01927 }
01928
01929 ctype
01930 ctype_createForwardStruct (cstring n)
01931 {
01932 uentry ue = uentry_makeStructTag (n, ctype_unknown, fileloc_undefined);
01933 ctype ct = usymtab_supForwardTypeEntry (ue);
01934
01935 cstring_free (n);
01936 return (ct);
01937 }
01938
01939 ctype
01940 ctype_createForwardUnion (cstring n)
01941 {
01942 uentry ue = uentry_makeUnionTag (n, ctype_unknown, fileloc_undefined);
01943 ctype ct = usymtab_supForwardTypeEntry (ue);
01944
01945 cstring_free (n);
01946 return (ct);
01947 }
01948
01949 ctype
01950 ctype_removePointers (ctype c)
01951 {
01952 ctype oldc;
01953
01954 while (ctype_isArrayPtr (c))
01955 {
01956 oldc = c;
01957 c = ctype_baseArrayPtr (c);
01958 llassert (c != oldc);
01959 }
01960
01961 return (c);
01962 }
01963
01964 bool ctype_isMutable (ctype t)
01965 {
01966 if (ctype_isUA (t))
01967 {
01968 return (uentry_isMutableDatatype
01969 (usymtab_getTypeEntry (ctype_typeId (t))));
01970 }
01971 else
01972 {
01973 return (ctype_isPointer (ctype_realType (t)));
01974 }
01975 }
01976
01977 bool ctype_isRefCounted (ctype t)
01978 {
01979 if (ctype_isUA (t))
01980 {
01981 return (uentry_isRefCountedDatatype
01982 (usymtab_getTypeEntry (ctype_typeId (t))));
01983 }
01984
01985 return FALSE;
01986 }
01987
01988 bool ctype_isVisiblySharable (ctype t)
01989 {
01990 if (ctype_isUnknown (t)) return TRUE;
01991
01992 if (ctype_isConj (t))
01993 {
01994 return (ctype_isVisiblySharable (ctype_getConjA (t))
01995 || ctype_isVisiblySharable (ctype_getConjB (t)));
01996 }
01997
01998 if (ctype_isMutable (t))
01999 {
02000 if (ctype_isUA (t))
02001 {
02002 ctype rt = ctype_realType (t);
02003
02004 if (rt == t)
02005 {
02006 return TRUE;
02007 }
02008 else
02009 {
02010 return ctype_isVisiblySharable (rt);
02011 }
02012 }
02013 else
02014 {
02015 return TRUE;
02016 }
02017 }
02018
02019 return FALSE;
02020 }
02021
02022 # if 0
02023
02024 bool ctype_canAlias (ctype ct)
02025 {
02026
02027
02028
02029
02030
02031 ctype tr = ctype_realType (ct);
02032
02033 return (ctype_isPointer (tr) || ctype_isMutable (ct) || ctype_isStructorUnion (tr));
02034 }
02035 # endif
02036
02037
02038
02039
02040
02041
02042
02043 ctype ctype_combine (ctype dominant, ctype modifier)
02044 {
02045 DPRINTF (("Combine: %s + %s",
02046 ctype_unparse (dominant),
02047 ctype_unparse (modifier)));
02048
02049 if (ctype_isConj (dominant))
02050 {
02051 ctype res;
02052
02053 if (ctype_isExplicitConj (dominant))
02054 {
02055 res = ctype_makeExplicitConj (ctype_combine (ctype_getConjA (dominant),
02056 modifier),
02057 ctype_getConjB (dominant));
02058 }
02059 else
02060 {
02061 res = ctype_makeConj (ctype_combine (ctype_getConjA (dominant),
02062 modifier),
02063 ctype_getConjB (dominant));
02064 }
02065
02066 return res;
02067 }
02068
02069 if (ctype_isUnknown (modifier))
02070 {
02071 return dominant;
02072 }
02073 else if (ctype_isUnknown (dominant))
02074 {
02075 return modifier;
02076 }
02077 else
02078 {
02079 if (ctype_isEnum (dominant)) dominant = ctype_int;
02080 if (ctype_isEnum (modifier)) modifier = ctype_int;
02081
02082 if (modifier == ctype_uint)
02083 {
02084 if (dominant == ctype_int) return ctype_uint;
02085 if (dominant == ctype_lint) return ctype_ulint;
02086 if (dominant == ctype_sint) return ctype_usint;
02087 if (dominant == ctype_char) return ctype_uchar;
02088 if ((dominant == ctype_uint) || dominant == ctype_uchar)
02089 {
02090 voptgenerror (FLG_DUPLICATEQUALS,
02091 message ("Duplicate unsigned qualifier"),
02092 g_currentloc);
02093
02094 return ctype_uint;
02095 }
02096 else
02097 {
02098 voptgenerror (FLG_DUPLICATEQUALS,
02099 message ("Type qualifier unsigned used with %s",
02100 ctype_unparse (dominant)),
02101 g_currentloc);
02102
02103 return dominant;
02104 }
02105 }
02106 else if (modifier == ctype_llint)
02107 {
02108 if (dominant == ctype_int)
02109 {
02110 return ctype_llint;
02111 }
02112
02113 voptgenerror (FLG_DUPLICATEQUALS,
02114 message ("Duplicate long qualifier on non-int"),
02115 g_currentloc);
02116 }
02117 else if (modifier == ctype_lint)
02118 {
02119 if (dominant == ctype_int) return ctype_lint;
02120 if (dominant == ctype_uint) return ctype_ulint;
02121 if (dominant == ctype_double) return ctype_ldouble;
02122
02123 if (dominant == ctype_lint || dominant == ctype_ulint
02124 || dominant == ctype_sint || dominant == ctype_usint
02125 || dominant == ctype_ldouble)
02126 {
02127 if (dominant == ctype_lint)
02128 {
02129
02130 return ctype_llint;
02131 }
02132
02133 if (dominant == ctype_sint || dominant == ctype_usint)
02134 {
02135 if (!context_getFlag (FLG_IGNOREQUALS))
02136 {
02137 llerrorlit (FLG_SYNTAX,
02138 "Contradictory long and short type qualifiers");
02139 }
02140 }
02141 else
02142 {
02143 voptgenerror (FLG_DUPLICATEQUALS,
02144 message ("Duplicate long qualifier"),
02145 g_currentloc);
02146 }
02147
02148 return ctype_lint;
02149 }
02150 }
02151 else if (modifier == ctype_sint)
02152 {
02153 if (dominant == ctype_int) return ctype_sint;
02154 if (dominant == ctype_uint) return ctype_usint;
02155
02156 if (dominant == ctype_sint || dominant == ctype_usint)
02157 {
02158 voptgenerror (FLG_DUPLICATEQUALS,
02159 message ("Duplicate short qualifier"),
02160 g_currentloc);
02161 return ctype_uint;
02162 }
02163 else if (dominant == ctype_lint)
02164 {
02165 if (!context_getFlag (FLG_IGNOREQUALS))
02166 {
02167 llerrorlit (FLG_SYNTAX,
02168 "Contradictory long and short type qualifiers");
02169 }
02170
02171 return dominant;
02172 }
02173 else
02174 {
02175 if (!context_getFlag (FLG_IGNOREQUALS))
02176 {
02177 llerror (FLG_SYNTAX,
02178 message ("Type qualifier short used with %s",
02179 ctype_unparse (dominant)));
02180 }
02181
02182 return dominant;
02183 }
02184 }
02185 else if (modifier == ctype_ulint)
02186 {
02187 if (dominant == ctype_int) return modifier;
02188
02189 if (dominant == ctype_lint || dominant == ctype_ulint)
02190 {
02191 voptgenerror (FLG_DUPLICATEQUALS,
02192 message ("Duplicate long qualifier"),
02193 g_currentloc);
02194
02195 return modifier;
02196 }
02197
02198 if (dominant == ctype_uint || dominant == ctype_usint)
02199 {
02200 voptgenerror (FLG_DUPLICATEQUALS,
02201 message ("Duplicate unsigned qualifier"),
02202 g_currentloc);
02203
02204 return modifier;
02205 }
02206
02207 if (dominant == ctype_sint || dominant == ctype_usint)
02208 {
02209 if (!context_getFlag (FLG_IGNOREQUALS))
02210 {
02211 llerrorlit (FLG_SYNTAX,
02212 "Contradictory long and short type qualifiers");
02213 }
02214
02215 return dominant;
02216 }
02217
02218 if (!context_getFlag (FLG_IGNOREQUALS))
02219 {
02220 llerror (FLG_SYNTAX,
02221 message ("Type qualifiers unsigned long used with %s",
02222 ctype_unparse (dominant)));
02223 }
02224
02225 return dominant;
02226 }
02227 else if (modifier == ctype_usint)
02228 {
02229 if (dominant == ctype_int) return modifier;
02230
02231 if (dominant == ctype_sint || dominant == ctype_usint)
02232 {
02233 voptgenerror (FLG_DUPLICATEQUALS,
02234 message ("Duplicate short qualifier"),
02235 g_currentloc);
02236 return modifier;
02237 }
02238
02239 if (dominant == ctype_uint)
02240 {
02241 voptgenerror (FLG_DUPLICATEQUALS,
02242 message ("Duplicate unsigned qualifier"),
02243 g_currentloc);
02244
02245 return modifier;
02246 }
02247
02248 if (dominant == ctype_lint || dominant == ctype_ulint
02249 || dominant == ctype_llint)
02250 {
02251 if (!context_getFlag (FLG_IGNOREQUALS))
02252 {
02253 llerrorlit (FLG_SYNTAX,
02254 "Contradictory long and short type qualifiers");
02255 }
02256
02257 return dominant;
02258 }
02259
02260 if (!context_getFlag (FLG_IGNOREQUALS))
02261 {
02262 llerror (FLG_SYNTAX,
02263 message ("Type qualifiers unsigned short used with %s",
02264 ctype_unparse (dominant)));
02265 }
02266
02267 return dominant;
02268 }
02269 else
02270 {
02271 ;
02272 }
02273
02274 return dominant;
02275 }
02276 }
02277
02278 ctype ctype_resolve (ctype c)
02279 {
02280 if (ctype_isUnknown (c)) return ctype_int;
02281 return c;
02282 }
02283
02284 ctype ctype_fromQual (qual q)
02285 {
02286 if (qual_isSigned (q)) return ctype_int;
02287 if (qual_isUnsigned (q)) return ctype_uint;
02288 if (qual_isLong (q)) return ctype_lint;
02289 if (qual_isShort (q)) return ctype_sint;
02290
02291 llcontbug (message ("ctype_fromQual: invalid qualifier: %s", qual_unparse (q)));
02292 return ctype_unknown;
02293 }
02294
02295 bool
02296 ctype_isAnyFloat (ctype c)
02297 {
02298 return (cprim_isAnyReal (ctype_toCprim (c)));
02299 }
02300
02301 bool
02302 ctype_isUnsigned (ctype c)
02303 {
02304 if (ctype_isConj (c))
02305 return (ctype_isUnsigned (ctype_getConjA (c)) ||
02306 ctype_isUnsigned (ctype_getConjB (c)));
02307
02308 return (c == ctype_uint || c == ctype_uchar
02309 || c == ctype_usint || c == ctype_ulint
02310 || c == ctype_unsignedintegral);
02311 }
02312
02313 static bool
02314 ctype_isLong (ctype c)
02315 {
02316 if (ctype_isConj (c))
02317 return (ctype_isLong (ctype_getConjA (c)) ||
02318 ctype_isLong (ctype_getConjB (c)));
02319
02320 return (c == ctype_lint || c == ctype_ulint);
02321 }
02322
02323 static bool
02324 ctype_isShort (ctype c)
02325 {
02326 if (ctype_isConj (c))
02327 return (ctype_isShort (ctype_getConjA (c)) ||
02328 ctype_isShort (ctype_getConjB (c)));
02329
02330 return (c == ctype_sint || c == ctype_usint);
02331 }
02332
02333 bool
02334 ctype_isStackAllocated (ctype c)
02335 {
02336 ctype ct = ctype_realType (c);
02337
02338 if (ctype_isConj (ct))
02339 return (ctype_isStackAllocated (ctype_getConjA (ct)) ||
02340 ctype_isStackAllocated (ctype_getConjB (ct)));
02341
02342 return (ctype_isArray (c) || ctype_isSU (c));
02343 }
02344
02345 static bool ctype_isMoreUnsigned (ctype c1, ctype c2)
02346 {
02347 return (ctype_isUnsigned (c1) && !ctype_isUnsigned (c2));
02348 }
02349
02350 static bool ctype_isLonger (ctype c1, ctype c2)
02351 {
02352 return ((ctype_isDouble (c1) && !ctype_isDouble (c2))
02353 || (ctype_isLong (c1) && !ctype_isLong (c2))
02354 || (ctype_isShort (c2) && !ctype_isShort (c1)));
02355 }
02356
02357 ctype
02358 ctype_widest (ctype c1, ctype c2)
02359 {
02360 if (ctype_isMoreUnsigned (c2, c1)
02361 || ctype_isLonger (c2, c1))
02362 {
02363 return c2;
02364 }
02365 else
02366 {
02367 return c1;
02368 }
02369 }