| File: | src/tform.c |
| Warning: | line 5499, column 9 Value stored to 'tfit' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* Some issues: |
| 2 | 1. Rep == Record(c: Cross(T: TFormSubType, T)) |
| 3 | |
| 4 | import from Rep |
| 5 | anyTForm(T: TFormSubType, t: T): % == per [pair(T, t)] |
| 6 | |
| 7 | local unwrap(atf: %): (T: TFormSubType, t: T) == |
| 8 | pp: Cross(T: TFormSubType, t: T) == rep(atf).c |
| 9 | pp |
| 10 | |
| 11 | local pair(T: TFormSubType, t: T): (T1: TFormSubType, t: T1) == (T, t) |
| 12 | |
| 13 | -- local functions aren't needed |
| 14 | |
| 15 | 2. Rep == Foo -> Bar |
| 16 | maps are not equal to defined constants |
| 17 | */ |
| 18 | |
| 19 | /***************************************************************************** |
| 20 | * |
| 21 | * tform.c: Type forms. |
| 22 | * |
| 23 | * Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org). |
| 24 | * |
| 25 | ****************************************************************************/ |
| 26 | |
| 27 | #include "ablogic.h" |
| 28 | #include "abpretty.h" |
| 29 | #include "absub.h" |
| 30 | #include "archive.h" |
| 31 | #include "axlobs.h" |
| 32 | #include "bigint.h" |
| 33 | #include "comsg.h" |
| 34 | #include "debug.h" |
| 35 | #include "fint.h" |
| 36 | #include "format.h" |
| 37 | #include "freevar.h" |
| 38 | #include "lib.h" |
| 39 | #include "sefo.h" |
| 40 | #include "spesym.h" |
| 41 | #include "stab.h" |
| 42 | #include "store.h" |
| 43 | #include "strops.h" |
| 44 | #include "symbol.h" |
| 45 | #include "symeset.h" |
| 46 | #include "tconst.h" |
| 47 | #include "tfcond.h" |
| 48 | #include "tfsat.h" |
| 49 | #include "ti_sef.h" |
| 50 | #include "ti_top.h" |
| 51 | #include "tinfer.h" |
| 52 | #include "tposs.h" |
| 53 | #include "tqual.h" |
| 54 | #include "ttable.h" |
| 55 | #include "util.h" |
| 56 | |
| 57 | Bool tfDebug = false((int) 0); |
| 58 | Bool tfExprDebug = false((int) 0); |
| 59 | Bool tfCrossDebug = false((int) 0); |
| 60 | Bool tfFloatDebug = false((int) 0); |
| 61 | Bool tfHasDebug = false((int) 0); |
| 62 | Bool tfHashDebug = false((int) 0); |
| 63 | Bool tfImportDebug = false((int) 0); |
| 64 | Bool tfMapDebug = false((int) 0); |
| 65 | Bool tfMultiDebug = false((int) 0); |
| 66 | Bool tfCatDebug = false((int) 0); |
| 67 | Bool tfWithDebug = false((int) 0); |
| 68 | Bool tfCascadeDebug = false((int) 0); |
| 69 | Bool tfParentDebug = false((int) 0); |
| 70 | Bool symeRefreshDebug = false((int) 0); |
| 71 | |
| 72 | #define tfDEBUGif (!tfDebug) { } else afprintf DEBUG_IF(tf)if (!tfDebug) { } else afprintf |
| 73 | #define tfExprDEBUGif (!tfExprDebug) { } else afprintf DEBUG_IF(tfExpr)if (!tfExprDebug) { } else afprintf |
| 74 | #define tfCrossDEBUGif (!tfCrossDebug) { } else afprintf DEBUG_IF(tfCross)if (!tfCrossDebug) { } else afprintf |
| 75 | #define tfFloatDEBUGif (!tfFloatDebug) { } else afprintf DEBUG_IF(tfFloat)if (!tfFloatDebug) { } else afprintf |
| 76 | #define tfHasDEBUGif (!tfHasDebug) { } else afprintf DEBUG_IF(tfHas)if (!tfHasDebug) { } else afprintf |
| 77 | #define tfHashDEBUGif (!tfHashDebug) { } else afprintf DEBUG_IF(tfHash)if (!tfHashDebug) { } else afprintf |
| 78 | #define tfImportDEBUGif (!tfImportDebug) { } else afprintf DEBUG_IF(tfImport)if (!tfImportDebug) { } else afprintf |
| 79 | #define tfMapDEBUGif (!tfMapDebug) { } else afprintf DEBUG_IF(tfMap)if (!tfMapDebug) { } else afprintf |
| 80 | #define tfMultiDEBUGif (!tfMultiDebug) { } else afprintf DEBUG_IF(tfMulti)if (!tfMultiDebug) { } else afprintf |
| 81 | #define tfCatDEBUGif (!tfCatDebug) { } else afprintf DEBUG_IF(tfCat)if (!tfCatDebug) { } else afprintf |
| 82 | #define tfWithDEBUGif (!tfWithDebug) { } else afprintf DEBUG_IF(tfWith)if (!tfWithDebug) { } else afprintf |
| 83 | #define tfCascadeDEBUGif (!tfCascadeDebug) { } else afprintf DEBUG_IF(tfCascade)if (!tfCascadeDebug) { } else afprintf |
| 84 | #define tfParentDEBUGif (!tfParentDebug) { } else afprintf DEBUG_IF(tfParent)if (!tfParentDebug) { } else afprintf |
| 85 | #define symeRefreshDEBUGif (!symeRefreshDebug) { } else afprintf DEBUG_IF(symeRefresh)if (!symeRefreshDebug) { } else afprintf |
| 86 | |
| 87 | #define TFormBuiltinSefo |
| 88 | #undef UseTypeVariables |
| 89 | |
| 90 | |
| 91 | /* |
| 92 | * tfMaxBaseSearchDepth defines the number of times that a tform |
| 93 | * can be expanded by tfDefineeType1() before we give up: it should |
| 94 | * never be reached. Make sure that it is large enough for all normal |
| 95 | * tforms to be completely expanded yet small enough to prevent bad |
| 96 | * tforms from killing performance. Use -Wcheck to see if we ever |
| 97 | * reach the limit. |
| 98 | * |
| 99 | * !!! To do: this ought to be a command-line switch. |
| 100 | */ |
| 101 | int tfMaxBaseSearchDepth = 20; |
| 102 | |
| 103 | |
| 104 | SymeList |
| 105 | tfSetSymesFn(TForm tf, SymeList sl) |
| 106 | { |
| 107 | tf->symes = sl; |
| 108 | return sl; |
| 109 | } |
| 110 | |
| 111 | /****************************************************************************** |
| 112 | * |
| 113 | * :: Local operations |
| 114 | * |
| 115 | *****************************************************************************/ |
| 116 | |
| 117 | /* |
| 118 | * Type form constructors. |
| 119 | */ |
| 120 | localstatic TForm tfNewSymbol (TFormTag); |
| 121 | localstatic TForm tfNewSyntax (AbSyn); |
| 122 | localstatic TForm tfNewNode (TFormTag, Length, ...); |
| 123 | localstatic TForm tfNewBuiltin (TForm, Symbol); |
| 124 | |
| 125 | /* |
| 126 | * Type form syntax. |
| 127 | */ |
| 128 | localstatic void tfSetExpr (TForm, AbSyn); |
| 129 | localstatic AbSyn tfToAbSyn0 (TForm, Bool); |
| 130 | |
| 131 | localstatic Bool tfOwnsExpr (TForm); |
| 132 | localstatic AbSyn tfDisownExpr (TForm, Bool); |
| 133 | localstatic void tfPendingFrSyntaxMap (Stab, AbSyn, TForm); |
| 134 | localstatic void tfPendingFrSyntaxDefine (Stab, AbSyn, TForm); |
| 135 | localstatic void tfp0FoamType (TForm); |
| 136 | |
| 137 | localstatic Bool tfMeaningEqual (Sefo, Sefo); |
| 138 | |
| 139 | /* |
| 140 | * Type form floating. |
| 141 | */ |
| 142 | /*local ULong tfOuterDepth (Stab, TForm);*/ |
| 143 | /*local ULong abOuterDepth (Stab, AbSyn);*/ |
| 144 | |
| 145 | /* |
| 146 | * Type form representational symes. |
| 147 | */ |
| 148 | localstatic Syme tfNewRepSyme (Stab, Symbol, TForm, Hash); |
| 149 | localstatic SymeList tfSymesFrDeclare (Sefo); |
| 150 | localstatic SymeList tfSymesFrCross (TForm); |
| 151 | localstatic SymeList tfSymesFrMulti (TForm); |
| 152 | localstatic SymeList tfSymesFrMap (TForm); |
| 153 | localstatic SymeList tfSymesFrEnum (Stab, TForm, Sefo); |
| 154 | localstatic void tfCheckDenseArgs (TForm, Sefo); |
| 155 | localstatic SymeList tfSymesFrRawRecord (Stab, TForm, Sefo); |
| 156 | localstatic SymeList tfSymesFrRecord (Stab, TForm, Sefo); |
| 157 | localstatic SymeList tfSymesFrUnion (Stab, TForm, Sefo); |
| 158 | localstatic SymeList tfSymesFrTrailingArray (Stab, TForm, Sefo); |
| 159 | localstatic SymeList tfSymesFrAdd (Sefo); |
| 160 | localstatic SymeList tfSymesFrDefault (Sefo); |
| 161 | |
| 162 | localstatic AbSyn tfSymesToAdd (SymeList); |
| 163 | |
| 164 | localstatic void tfGetExportError (TForm, String); |
| 165 | |
| 166 | localstatic TForm tfCatExportsPendingFrWith(Sefo); |
| 167 | localstatic Bool tfHasSymesFrDefault (Sefo); |
| 168 | |
| 169 | localstatic SymeList tfGetCatSelfFrWith (Sefo); |
| 170 | |
| 171 | localstatic Syme symeListFindExport (SymeList, Syme, SymeList); |
| 172 | localstatic void tfJoinExports (Syme, Syme); |
| 173 | localstatic Bool tfJoinExportToList (SymeList, SymeList, Syme, |
| 174 | Sefo); |
| 175 | localstatic SymeList tfMeetExportLists (SymeList, SymeList, SymeList, |
| 176 | Sefo); |
| 177 | |
| 178 | localstatic SymeList tfAddDomExports (TForm, SymeList); |
| 179 | localstatic SymeList tfAddCatExports (TForm, SymeList); |
| 180 | localstatic SymeList tfAddThdExports (TForm, SymeList); |
| 181 | localstatic SymeList tfAddHasExports (TForm, TForm); |
| 182 | |
| 183 | localstatic SymeList tfGetCatExportsFrParents(SymeList); |
| 184 | localstatic SymeList tfGetCatExportsCond (SymeList, SefoList, Bool); |
| 185 | localstatic SymeList tfGetCatExportsFilterTable(SymeTSet, SymeList); |
| 186 | |
| 187 | localstatic SymeList tfGetCatExportsFrWith (TForm); |
| 188 | localstatic SymeList tfGetCatExportsFrIf (TForm); |
| 189 | localstatic SymeList tfGetCatExportsFrJoin (TForm); |
| 190 | localstatic SymeList tfGetCatExportsFrMeet (TForm); |
| 191 | |
| 192 | localstatic Syme tfGetBuiltinSyme (TForm, Symbol); |
| 193 | |
| 194 | localstatic SymeList tfGetThdConstants (TForm); |
| 195 | localstatic SymeList tfGetCatConstantsFrWith (Sefo); |
| 196 | |
| 197 | localstatic TQualList tfGetCascadesFrStab (Stab); |
| 198 | localstatic TQualList tfGetCatCascadesFrWith (TForm); |
| 199 | localstatic TQualList tfGetCascadesFrTrailingArray(TForm tf); |
| 200 | |
| 201 | localstatic TForm tfIsIdempotent (TForm); |
| 202 | localstatic void tfForwardIdempotent (TForm, TForm); |
| 203 | localstatic void tfExtendFinishTwins (Stab, Syme); |
| 204 | |
| 205 | /****************************************************************************** |
| 206 | * |
| 207 | * :: Type imports and exports |
| 208 | * |
| 209 | *****************************************************************************/ |
| 210 | |
| 211 | localstatic void tfSetDomImports (TForm, SymeSet); |
| 212 | localstatic void tfSetDomExports (TForm, SymeList); |
| 213 | |
| 214 | localstatic SymeSet tfStabCreateDomImportSet(Stab stab, TForm tf); |
| 215 | /****************************************************************************** |
| 216 | * |
| 217 | * :: Debugging facilities |
| 218 | * |
| 219 | *****************************************************************************/ |
| 220 | |
| 221 | /* |
| 222 | * Debugging function designed to fully expand a tform so that |
| 223 | * there aren't any TF_Subst or TF_Follow nodes and that all |
| 224 | * symes have been triggered. |
| 225 | */ |
| 226 | TForm |
| 227 | tfFollowFully(TForm tf) |
| 228 | { |
| 229 | int i; |
| 230 | |
| 231 | tf = tfFollowFn(tf); |
| 232 | |
| 233 | if (tf) { |
| 234 | for (i = 0;i < tfArgc(tf)((tf)->argc); i++) |
| 235 | tfArgv(tf)((tf)->argv)[i] = tfFollowFully(tfArgv(tf)((tf)->argv)[i]); |
| 236 | } |
| 237 | |
| 238 | return tf; |
| 239 | } |
| 240 | |
| 241 | void |
| 242 | tformDump(TForm tf) |
| 243 | { |
| 244 | /* Display the origin of tforms */ |
| 245 | if (tfHasExpr(tf)((tf)->__absyn != 0)) |
| 246 | { |
| 247 | AbSyn expr = tfGetExpr(tf)((tf)->__absyn); |
| 248 | |
| 249 | (void)tfPrintDb(tf); |
| 250 | spstackPrintDb(expr->abHdr.pos); |
| 251 | fnewline(dbOut); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /****************************************************************************** |
| 256 | * |
| 257 | * :: Basic operations |
| 258 | * |
| 259 | *****************************************************************************/ |
| 260 | |
| 261 | /* |
| 262 | * Type form constructors. |
| 263 | */ |
| 264 | |
| 265 | |
| 266 | /* For breakpoints */ |
| 267 | localstatic void tfBreak(TForm tf); |
| 268 | static TForm tfBreakVal; |
| 269 | |
| 270 | TForm |
| 271 | tfNewEmpty(TFormTag tag, Length argc) |
| 272 | { |
| 273 | TForm tf; |
| 274 | Length i; |
| 275 | |
| 276 | tf = (TForm) stoAlloc((unsigned)OB_TForm(14 + 8), sizeof(*tf)+argc*sizeof(tf)); |
| 277 | |
| 278 | tf->tag = tag; |
| 279 | tf->ownSyntax = false((int) 0); |
| 280 | tf->hasSelf = false((int) 0); |
| 281 | tf->hasSelfSelf = false((int) 0); |
| 282 | tf->hasCascades = false((int) 0); |
| 283 | tf->raw = FOAM_LIMIT; |
| 284 | tf->hash = 0; |
| 285 | tf->__absyn = 0; |
| 286 | tf->intStepNo = intStepNo; |
| 287 | |
| 288 | tf->argc = argc; |
| 289 | tf->argv = (argc ? (TForm *) (tf + 1) : NULL((void*)0)); |
| 290 | |
| 291 | tf->stab = NULL((void*)0); |
| 292 | tf->self = listNil(Syme)((SymeList) 0); |
| 293 | tf->selfself = listNil(Syme)((SymeList) 0); |
| 294 | tf->parents = listNil(Syme)((SymeList) 0); |
| 295 | tf->symes = listNil(Syme)((SymeList) 0); |
| 296 | |
| 297 | tf->domExports = listNil(Syme)((SymeList) 0); |
| 298 | tf->catExports = listNil(Syme)((SymeList) 0); |
| 299 | tf->thdExports = listNil(Syme)((SymeList) 0); |
| 300 | tf->domExportNames = NULL((void*)0); |
| 301 | |
| 302 | tf->domImports = NULL((void*)0); |
| 303 | |
| 304 | tf->consts = listNil(TConst)((TConstList) 0); |
| 305 | tf->queries = listNil(TForm)((TFormList) 0); |
| 306 | tf->cascades = listNil(TQual)((TQualList) 0); |
| 307 | |
| 308 | tf->conditions = NULL((void*)0);; |
| 309 | |
| 310 | tf->sigma = NULL((void*)0); |
| 311 | tf->fv = NULL((void*)0); |
| 312 | tf->rho = NULL((void*)0); |
| 313 | |
| 314 | tf->__mark = 0; |
| 315 | tf->parent = NULL((void*)0); |
| 316 | tf->libNum = TYPE_NUMBER_UNASSIGNED(0x7FFFFFFF); |
| 317 | |
| 318 | tf->tests = listNil(Sefo)((SefoList) 0); |
| 319 | |
| 320 | for (i = 0; i < argc; i += 1) tf->argv[i] = 0; |
| 321 | |
| 322 | tfSetTForm(tf)(((tf)->state)=TF_State_TForm); |
| 323 | tfp0FoamType(tf); |
| 324 | |
| 325 | tfBreak(tf); |
| 326 | |
| 327 | return tf; |
| 328 | } |
| 329 | |
| 330 | localstatic void |
| 331 | tfBreak(TForm tf) |
| 332 | { |
| 333 | if (tf == tfBreakVal) { |
| 334 | printf("breakpoint"); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | localstatic TForm |
| 339 | tfNewSymbol(TFormTag tag) |
| 340 | { |
| 341 | TForm tf = tfNewEmpty(tag, int0((int) 0)); |
| 342 | tfToAbSyn(tf); |
| 343 | tfSetMeaning(tf)(((tf)->state)=TF_State_Meaning); |
| 344 | return tf; |
| 345 | } |
| 346 | |
| 347 | TForm |
| 348 | tfNewAbSyn(TFormTag tag, AbSyn ab) |
| 349 | { |
| 350 | TForm tf = tfNewEmpty(tag, int0((int) 0)); |
| 351 | tfSetExpr(tf, ab); |
| 352 | return tf; |
| 353 | } |
| 354 | |
| 355 | localstatic TForm |
| 356 | tfNewSyntax(AbSyn ab) |
| 357 | { |
| 358 | /* we leave one slot for TF_Forward transmogrification */ |
| 359 | TForm tf = tfNewEmpty(TF_Syntax, 1); |
| 360 | tfSetPending(tf)(((tf)->state)=TF_State_Pending); |
| 361 | tfSetExpr(tf, ab); |
| 362 | tf->argc = 0; |
| 363 | return tf; |
| 364 | } |
| 365 | |
| 366 | localstatic TForm |
| 367 | tfNewNode(TFormTag tag, Length argc, ...) |
| 368 | { |
| 369 | TForm tf; |
| 370 | Length i; |
| 371 | va_list argp; |
| 372 | |
| 373 | tf = tfNewEmpty(tag, argc); |
| 374 | |
| 375 | va_start(argp, argc)__builtin_va_start(argp, argc); |
| 376 | for (i = 0; i < argc; i += 1) |
| 377 | tfArgv(tf)((tf)->argv)[i] = va_arg(argp, TForm)__builtin_va_arg(argp, TForm); |
| 378 | va_end(argp)__builtin_va_end(argp); |
| 379 | |
| 380 | return tf; |
| 381 | } |
| 382 | |
| 383 | localstatic TForm |
| 384 | tfNewBuiltin(TForm tf, Symbol sym) |
| 385 | { |
| 386 | Syme syme = tfGetBuiltinSyme(tf, sym); |
| 387 | return syme ? tfFrSyme(stabGlobal(), syme) : tfUnknown; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * Basic TForm operations. |
| 392 | */ |
| 393 | |
| 394 | void |
| 395 | tfInitBasicTypes(TForm tf) |
| 396 | { |
| 397 | static Bool isInit = false((int) 0); |
| 398 | |
| 399 | if (isInit) return; |
| 400 | |
| 401 | tfBoolean = tfNewBuiltin(tf, ssymBoolean); |
| 402 | tfTextWriter = tfNewBuiltin(tf, ssymTextWriter); |
| 403 | tfMachineInteger= tfNewBuiltin(tf, ssymMachineInteger); |
| 404 | |
| 405 | isInit = true1; |
| 406 | } |
| 407 | |
| 408 | void |
| 409 | tfInit(void) |
| 410 | { |
| 411 | static Bool isInit = false((int) 0); |
| 412 | int i; |
| 413 | |
| 414 | if (isInit) return; |
| 415 | |
| 416 | abUnknown = abNewBlank(sposNone, symIntern("?"))abNew(AB_Blank, sposNone,1, symProbe("?", 1 | 2)); |
| 417 | |
| 418 | tfUnknown = tfNewSymbol(TF_Unknown); |
| 419 | tfExit = tfNewSymbol(TF_Exit); |
| 420 | tfTest = tfNewSymbol(TF_Test); |
| 421 | tfLiteral = tfNewSymbol(TF_Literal); |
| 422 | tfType = tfNewSymbol(TF_Type); |
| 423 | tfCategory = tfNewSymbol(TF_Category); |
| 424 | |
| 425 | tfDomain = tfWith(tfNone()tfMulti(0), tfNone()tfMulti(0)); |
| 426 | tfTypeTuple = tfTuple(tfType); |
| 427 | |
| 428 | tfBoolean = tfUnknown; |
| 429 | tfTextWriter = tfUnknown; |
| 430 | tfMachineInteger = tfUnknown; |
| 431 | |
| 432 | for (i = TF_START; i < TF_LIMIT; i++) |
| 433 | tformInfo(i)tformInfoTable[(int)(i) - (int)TF_START].hash = strHash(tformInfo(i)tformInfoTable[(int)(i) - (int)TF_START].str); |
| 434 | |
| 435 | /* syme.c checks */ |
| 436 | |
| 437 | for (i=SYME_FIELD_START; i<SYME_FIELD_LIMIT; i++) |
| 438 | assert(symeFieldInfo[i].tag == i)do { if (!(symeFieldInfo[i].tag == i)) _do_assert(("symeFieldInfo[i].tag == i" ),"tform.c",438); } while (0); |
| 439 | |
| 440 | isInit = true1; |
| 441 | } |
| 442 | |
| 443 | |
| 444 | void |
| 445 | tfFree(TForm tf) |
| 446 | { |
| 447 | if (tfOwnsExpr(tf)) abFree(tfGetExpr(tf)((tf)->__absyn)); |
| 448 | |
| 449 | listFree(Syme)(Syme_listPointer->Free)(tf->symes); |
| 450 | listFree(Syme)(Syme_listPointer->Free)(tf->self); |
| 451 | |
| 452 | /* A type form does not own its domExports. */ |
| 453 | symeSetFree(tf->domImports); |
| 454 | |
| 455 | stoFree((Pointer) tf); |
| 456 | } |
| 457 | |
| 458 | int |
| 459 | tfPrint(FILE *fout, TForm tf) |
| 460 | { |
| 461 | return tformPrint(fout, tf); |
| 462 | } |
| 463 | |
| 464 | int |
| 465 | tfPrintDb(TForm tf) |
| 466 | { |
| 467 | int rc = tformPrint(dbOut, tf); |
| 468 | fnewline(dbOut); |
| 469 | return rc; |
| 470 | } |
| 471 | |
| 472 | Bool |
| 473 | tfEqual(TForm t1, TForm t2) |
| 474 | { |
| 475 | return tformEqual(t1, t2); |
| 476 | } |
| 477 | |
| 478 | #define tfHashArg(h, hi){ h ^= (h << 8); h += (hi) + 200041; h &= 0x3FFFFFFF ; } { \ |
| 479 | h ^= (h << 8); \ |
| 480 | h += (hi) + 200041; \ |
| 481 | h &= 0x3FFFFFFF; \ |
| 482 | } |
| 483 | |
| 484 | Hash |
| 485 | tfHash(TForm tf) |
| 486 | { |
| 487 | Hash h = 0; |
| 488 | Length i; |
| 489 | SymeList symes; |
| 490 | static int serial = 0; |
| 491 | int this = serial++; |
| 492 | |
| 493 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 494 | tfHashDEBUGif (!tfHashDebug) { } else afprintf(dbOut, "(hash %d %pTForm\n", this, tf); |
| 495 | if (!tfIsDefine(tf)(((tf)->tag) == TF_Define)) |
| 496 | tf = tfDefineeType(tf); |
| 497 | |
| 498 | if (tfIsSym(tf)( (((tf)->tag)) < TF_SYM_LIMIT)) |
| 499 | h = 0; |
| 500 | else if (tfIsAbSyn(tf)( TF_ABSYN_START <= (((tf)->tag)) && (((tf)-> tag)) < TF_ABSYN_LIMIT)) { |
| 501 | h = abHashModDeclares(tfGetExpr(tf)((tf)->__absyn)); |
| 502 | } |
| 503 | else if (tfIsDefine(tf)(((tf)->tag) == TF_Define)) { |
| 504 | tfHashArg(h, tfHash(tfDefineeType(tf))){ h ^= (h << 8); h += (tfHash(tfDefineeType(tf))) + 200041 ; h &= 0x3FFFFFFF; }; |
| 505 | tfHashArg(h, tfHash(tfDefineVal(tf))){ h ^= (h << 8); h += (tfHash(tfFollowArg(tf, 1))) + 200041 ; h &= 0x3FFFFFFF; }; |
| 506 | } |
| 507 | else if (tfIsNode(tf)( TF_NODE_START <= (((tf)->tag)) && (((tf)-> tag)) < TF_NODE_LIMIT)) { |
| 508 | for (h = 0, i = 0; i < tfArgc(tf)((tf)->argc); i += 1) { |
| 509 | tfHashArg(h, tfHash(tfArgv(tf)[i])){ h ^= (h << 8); h += (tfHash(((tf)->argv)[i])) + 200041 ; h &= 0x3FFFFFFF; }; |
| 510 | } |
| 511 | } |
| 512 | else |
| 513 | bugBadCase(tfTag(tf))bug("Bad case %d (line %d in file %s).", (int) ((tf)->tag) , 513, "tform.c"); |
| 514 | |
| 515 | if (tfTagHasSymes(tfTag(tf)((tf)->tag))) { |
| 516 | for (symes = tfSymes(tf)((tf)->symes); symes; symes = cdr(symes)((symes)->rest)) |
| 517 | tfHashArg(h, strHash(symeString(car(symes)))){ h ^= (h << 8); h += (strHash(((((((symes)->first)) ->id))->str))) + 200041; h &= 0x3FFFFFFF; }; |
| 518 | } |
| 519 | |
| 520 | h += tformInfo(tfTag(tf))tformInfoTable[(int)(((tf)->tag)) - (int)TF_START].hash + 200063; |
| 521 | h &= 0x3FFFFFFF; |
| 522 | tfHashDEBUGif (!tfHashDebug) { } else afprintf(dbOut, " hash %d = %d)\n", this, h); |
| 523 | return h; |
| 524 | } |
| 525 | |
| 526 | TForm |
| 527 | tfFrSyme(Stab stab, Syme syme) |
| 528 | { |
| 529 | return tfFullFrAbSyn(stab, abFrSyme(syme)); |
| 530 | } |
| 531 | |
| 532 | TForm |
| 533 | tfFrSelf(Stab stab, TForm tf) |
| 534 | { |
| 535 | return tfFrSyme(stab, car(tfDefSelf(stab, tf))((tfDefSelf(stab, tf))->first)); |
| 536 | } |
| 537 | |
| 538 | void tfTestPush(TForm tf, Sefo sf) |
| 539 | { |
| 540 | tf->tests = listCons(Sefo)(Sefo_listPointer->Cons)(sf, tf->tests); |
| 541 | } |
| 542 | |
| 543 | void tfTestPop(TForm tf, Sefo sf) |
| 544 | { |
| 545 | assert(car(tf->tests) == sf)do { if (!(((tf->tests)->first) == sf)) _do_assert(("car(tf->tests) == sf" ),"tform.c",545); } while (0); |
| 546 | tf->tests = cdr(tf->tests)((tf->tests)->rest); |
| 547 | } |
| 548 | |
| 549 | Bool tfTestSeen(TForm tf, Sefo sf) |
| 550 | { |
| 551 | SefoList ll = tf->tests; |
| 552 | for (; ll != listNil(Sefo)((SefoList) 0); ll = cdr(ll)((ll)->rest)) { |
| 553 | if (sf == car(ll)((ll)->first)) { |
| 554 | return true1; |
| 555 | } |
| 556 | } |
| 557 | return false((int) 0); |
| 558 | } |
| 559 | |
| 560 | |
| 561 | /***************************************************************************** |
| 562 | * |
| 563 | * :: Declarations for tfPending |
| 564 | * |
| 565 | ****************************************************************************/ |
| 566 | |
| 567 | localstatic Syme tfp0SpecialSyme (Stab, Syme syme, Symbol, Bool); |
| 568 | localstatic Syme tfp0IdSyme (Stab, Syme, Symbol); |
| 569 | localstatic Syme tfp0OpSyme (Stab, Syme, Symbol, Length); |
| 570 | localstatic TForm tfp0IdTForm (Symbol); |
| 571 | localstatic TForm tfp0OpTForm (Symbol, Length); |
| 572 | |
| 573 | localstatic TForm tfp0General (Stab, AbSyn); |
| 574 | localstatic TForm tfp0Float (Stab, AbSyn); |
| 575 | |
| 576 | localstatic TForm tfpNothing (Stab, AbSyn); |
| 577 | localstatic TForm tfpBlank (Stab, AbSyn); |
| 578 | localstatic TForm tfpId (Stab, AbSyn); |
| 579 | localstatic TForm tfpDeclare (Stab, AbSyn); |
| 580 | localstatic TForm tfpDefine (Stab, AbSyn); |
| 581 | localstatic TForm tfpAssign (Stab, AbSyn); |
| 582 | localstatic TForm tfpComma (Stab, AbSyn); |
| 583 | localstatic TForm tfpAdd (Stab, AbSyn); |
| 584 | localstatic TForm tfpWith (Stab, AbSyn); |
| 585 | localstatic TForm tfpIf (Stab, AbSyn); |
| 586 | localstatic TForm tfpExcept (Stab, AbSyn); |
| 587 | localstatic TForm tfpApply (Stab, AbSyn); |
| 588 | |
| 589 | /***************************************************************************** |
| 590 | * |
| 591 | * :: tfPending |
| 592 | * |
| 593 | ****************************************************************************/ |
| 594 | localstatic AbSynList tfpConditions; |
| 595 | |
| 596 | TForm |
| 597 | tfPending(Stab stab, AbSyn ab) |
| 598 | { |
| 599 | TForm tf; |
| 600 | static int serialNo = 0, depthNo = 0; |
| 601 | int serialThis; |
| 602 | |
| 603 | serialNo += 1; |
| 604 | depthNo += 1; |
| 605 | serialThis = serialNo; |
| 606 | tfExprDEBUGif (!tfExprDebug) { } else afprintf(dbOut, "%*s(tfPending %d= %pAbSyn\n", |
| 607 | depthNo, "", serialThis, ab); |
| 608 | |
| 609 | |
| 610 | /* The stab is used to look up meanings for ids without them. */ |
| 611 | |
| 612 | if (abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0)) |
| 613 | stab = abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0); |
| 614 | |
| 615 | switch (abTag(ab)((ab)->abHdr.tag)) { |
| 616 | case AB_Nothing: tf = tfpNothing (stab, ab); break; |
| 617 | case AB_Blank: tf = tfpBlank (stab, ab); break; |
| 618 | case AB_Id: tf = tfpId (stab, ab); break; |
| 619 | case AB_Declare: tf = tfpDeclare (stab, ab); break; |
| 620 | case AB_Define: tf = tfpDefine (stab, ab); break; |
| 621 | case AB_Assign: tf = tfpAssign (stab, ab); break; |
| 622 | case AB_Comma: tf = tfpComma (stab, ab); break; |
| 623 | case AB_Add: tf = tfpAdd (stab, ab); break; |
| 624 | case AB_With: tf = tfpWith (stab, ab); break; |
| 625 | case AB_If: tf = tfpIf (stab, ab); break; |
| 626 | case AB_Apply: tf = tfpApply (stab, ab); break; |
| 627 | case AB_Except: tf = tfpExcept (stab, ab); break; |
| 628 | default: tf = tfp0General(stab, ab); break; |
| 629 | } |
| 630 | |
| 631 | tfExprDEBUGif (!tfExprDebug) { } else afprintf(dbOut, "%*s %d %pTForm)\n", depthNo, "", serialThis, tf); |
| 632 | depthNo -= 1; |
| 633 | |
| 634 | tfSetExpr(tf, ab); |
| 635 | tfSetPending(tf)(((tf)->state)=TF_State_Pending); |
| 636 | return tf; |
| 637 | } |
| 638 | |
| 639 | Syme |
| 640 | tfpOpSyme(Stab stab, Symbol sym, Length argc) |
| 641 | { |
| 642 | return tfp0OpSyme(stab, NULL((void*)0), sym, argc); |
| 643 | } |
| 644 | |
| 645 | /***************************************************************************** |
| 646 | * |
| 647 | * :: tfPending helper functions |
| 648 | * |
| 649 | ****************************************************************************/ |
| 650 | |
| 651 | localstatic TForm tf0MapRetFrPending(Stab stab, TForm tf); |
| 652 | |
| 653 | localstatic Syme |
| 654 | tfp0SpecialSyme(Stab stab, Syme syme, Symbol sym, Bool op) |
| 655 | { |
| 656 | TForm tf; |
| 657 | SymeList sl; |
| 658 | |
| 659 | if (syme != NULL((void*)0)) { |
| 660 | tf = symeType(syme); |
| 661 | if (op) { |
| 662 | tf = tf0MapRetFrPending(stab, tf); |
| 663 | } |
| 664 | if (tf && tfSatType(tf)) |
| 665 | return syme; |
| 666 | } |
| 667 | |
| 668 | for (sl = stabGetMeanings(stab, NULL((void*)0), sym); sl; sl = cdr(sl)((sl)->rest)) { |
| 669 | Syme syme = car(sl)((sl)->first); |
| 670 | |
| 671 | /*!! Need to check some condition to ensure this syme |
| 672 | *!! is really special. This one doesn't do it. |
| 673 | if (!symeTop(syme)) |
| 674 | continue; |
| 675 | */ |
| 676 | |
| 677 | tf = symeType(syme); |
| 678 | if (op) { |
| 679 | tf = tf0MapRetFrPending(stab, tf); |
| 680 | } |
| 681 | |
| 682 | if (tf && tfSatType(tf)) |
| 683 | return syme; |
| 684 | } |
| 685 | |
| 686 | return NULL((void*)0); |
| 687 | } |
| 688 | |
| 689 | localstatic TForm |
| 690 | tf0MapRetFrPending(Stab stab, TForm tf) |
| 691 | { |
| 692 | tf = tfFollowOnly(tf); |
| 693 | |
| 694 | if (tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap ))) |
| 695 | tf = tfMapRet(tf)tfFollowArg(tf, 1); |
| 696 | else if (tfIsMapSyntax(tf)((((tf)->tag) == TF_Syntax) && (((((((tf)->__absyn ))->abHdr.tag == (AB_Apply)) && (((((((tf)->__absyn ))->abApply.op))->abHdr.tag == (AB_Id)) && (((( ((tf)->__absyn))->abApply.op))->abId.sym)==(ssymArrow ))) && (((((tf)->__absyn))->abHdr.argc)-1) == 2 ) || ((((((tf)->__absyn))->abHdr.tag == (AB_Apply)) && (((((((tf)->__absyn))->abApply.op))->abHdr.tag == ( AB_Id)) && ((((((tf)->__absyn))->abApply.op))-> abId.sym)==(ssymPackedArrow))) && (((((tf)->__absyn ))->abHdr.argc)-1) == 2)))) { |
| 697 | AbSyn ab = tfGetExpr(tf)((tf)->__absyn); |
| 698 | tf = tfSyntaxFrAbSyn(stab, abApplyArg(ab, 1)((ab)->abApply.argv[1])); |
| 699 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 700 | } |
| 701 | else |
| 702 | return NULL((void*)0); |
| 703 | |
| 704 | return tf; |
| 705 | } |
| 706 | |
| 707 | Syme |
| 708 | tfpIdSyme(Stab stab, Symbol sym) |
| 709 | { |
| 710 | return tfp0IdSyme(stab, NULL((void*)0), sym); |
| 711 | } |
| 712 | |
| 713 | localstatic Syme |
| 714 | tfp0IdSyme(Stab stab, Syme syme, Symbol sym) |
| 715 | { |
| 716 | Syme rsyme = 0; |
| 717 | |
| 718 | if ((sym == ssymExit) || |
| 719 | (sym == ssymType) || |
| 720 | (sym == ssymCategory) || |
| 721 | (sym == ssymTest) || |
| 722 | (sym == ssymLiteral)) |
| 723 | rsyme = tfp0SpecialSyme(stab, syme, sym, false((int) 0)); |
| 724 | |
| 725 | return rsyme; |
| 726 | } |
| 727 | |
| 728 | localstatic Syme |
| 729 | tfp0OpSyme(Stab stab, Syme syme, Symbol sym, Length argc) |
| 730 | { |
| 731 | Syme rsyme = 0; |
| 732 | |
| 733 | if ((argc == 2 && sym == ssymArrow) || |
| 734 | (argc == 2 && sym == ssymPackedArrow) || |
| 735 | (argc == 1 && sym == ssymTuple) || |
| 736 | (argc == 1 && sym == ssymGenerator) || |
| 737 | (argc == 1 && sym == ssymXGenerator) || |
| 738 | (argc == 1 && sym == ssymReference) || |
| 739 | (argc == 1 && sym == ssymRaw) || |
| 740 | |
| 741 | (sym == ssymCross) || |
| 742 | (sym == ssymEnum) || |
| 743 | (sym == ssymRawRecord) || |
| 744 | (sym == ssymRecord) || |
| 745 | (sym == ssymTrailingArray) || |
| 746 | (sym == ssymUnion) || |
| 747 | (sym == ssymMeet) || |
| 748 | (sym == ssymJoin)) |
| 749 | rsyme = tfp0SpecialSyme(stab, syme, sym, true1); |
| 750 | |
| 751 | return rsyme; |
| 752 | } |
| 753 | |
| 754 | localstatic TForm |
| 755 | tfp0IdTForm(Symbol sym) |
| 756 | { |
| 757 | TForm tf = NULL((void*)0); |
| 758 | |
| 759 | if (sym == ssymExit) tf = tfExit; |
| 760 | else if (sym == ssymType) tf = tfType; |
| 761 | else if (sym == ssymCategory) tf = tfThird(listNil(Syme)((SymeList) 0)); |
| 762 | else if (sym == ssymTest) tf = tfTest; |
| 763 | else if (sym == ssymLiteral) tf = tfLiteral; |
| 764 | |
| 765 | return tf; |
| 766 | } |
| 767 | |
| 768 | localstatic TForm |
| 769 | tfp0OpTForm(Symbol sym, Length argc) |
| 770 | { |
| 771 | TFormTag tag = TF_General; |
| 772 | TForm tf; |
| 773 | |
| 774 | if (sym == ssymArrow) tag = TF_Map; |
| 775 | else if (sym == ssymPackedArrow) tag = TF_PackedMap; |
| 776 | else if (sym == ssymTuple) tag = TF_Tuple; |
| 777 | else if (sym == ssymGenerator) tag = TF_Generator; |
| 778 | else if (sym == ssymXGenerator) tag = TF_XGenerator; |
| 779 | else if (sym == ssymReference) tag = TF_Reference; |
| 780 | else if (sym == ssymRaw) tag = TF_Raw; |
| 781 | |
| 782 | else if (sym == ssymCross) tag = TF_Cross; |
| 783 | else if (sym == ssymEnum) tag = TF_Enumerate; |
| 784 | else if (sym == ssymRecord) tag = TF_Record; |
| 785 | else if (sym == ssymRawRecord) tag = TF_RawRecord; |
| 786 | else if (sym == ssymTrailingArray) tag = TF_TrailingArray; |
| 787 | else if (sym == ssymUnion) tag = TF_Union; |
| 788 | else if (sym == ssymJoin) tag = TF_Join; |
| 789 | else if (sym == ssymMeet) tag = TF_Meet; |
| 790 | |
| 791 | tf = tfNewEmpty(tag, argc); |
| 792 | return tf; |
| 793 | } |
| 794 | |
| 795 | localstatic TForm |
| 796 | tfp0General(Stab stab, AbSyn ab) |
| 797 | { |
| 798 | return tfNewAbSyn(TF_General, ab); |
| 799 | } |
| 800 | |
| 801 | localstatic TForm |
| 802 | tfp0Float(Stab stab, AbSyn ab) |
| 803 | { |
| 804 | TForm tf, ntf; |
| 805 | Stab nstab; |
| 806 | |
| 807 | tf = tfSyntaxFrAbSyn(stab, ab); |
| 808 | if (tfIsSyntax(tf)(((tf)->tag) == TF_Syntax)) |
| 809 | tfMergeConditions(tf, stab, |
| 810 | tfpConditions == listNil(AbSyn)((AbSynList) 0) |
| 811 | ? NULL((void*)0) : tfCondEltNew(stab, tfpConditions)); |
| 812 | |
| 813 | nstab = tfFloat(stab, tf); |
| 814 | |
| 815 | if (nstab == NULL((void*)0)) |
| 816 | return tfPendingFrSyntax(stab, ab, tf); |
| 817 | |
| 818 | ntf = tiTopFns()->typeInferTForm(nstab, tf); |
| 819 | tfTransferSemantics(ntf, tf); |
| 820 | |
| 821 | |
| 822 | return tf; |
| 823 | } |
| 824 | |
| 825 | localstatic void |
| 826 | tfp0FoamType(TForm tf) |
| 827 | { |
| 828 | FoamTag tag = FOAM_LIMIT; |
| 829 | |
| 830 | switch (tfTag(tf)((tf)->tag)) { |
| 831 | case TF_With: |
| 832 | tag = FOAM_Word; |
| 833 | break; |
| 834 | case TF_Map: |
| 835 | tag = FOAM_Clos; |
| 836 | break; |
| 837 | case TF_PackedMap: |
| 838 | tag = FOAM_Clos; |
| 839 | break; |
| 840 | case TF_Generator: |
| 841 | tag = FOAM_Clos; |
| 842 | break; |
| 843 | case TF_Multiple: |
| 844 | tag = FOAM_NOp; |
| 845 | break; |
| 846 | case TF_RawRecord: |
| 847 | tag = FOAM_RRec; |
| 848 | break; |
| 849 | case TF_Record: |
| 850 | tag = FOAM_Rec; |
| 851 | break; |
| 852 | case TF_Reference: |
| 853 | tag = FOAM_Clos; |
| 854 | break; |
| 855 | case TF_Cross: |
| 856 | tag = FOAM_Word; |
| 857 | break; |
| 858 | case TF_Tuple: |
| 859 | tag = FOAM_Word; |
| 860 | break; |
| 861 | case TF_TrailingArray: |
| 862 | tag = FOAM_TR; |
| 863 | break; |
| 864 | default: |
| 865 | break; |
| 866 | } |
| 867 | |
| 868 | tfFoamType(tf)((tf)->raw) = tag; |
| 869 | } |
| 870 | |
| 871 | /***************************************************************************** |
| 872 | * |
| 873 | * :: tfPending cases |
| 874 | * |
| 875 | ****************************************************************************/ |
| 876 | localstatic Bool tfSymesEqModExtends(Syme syme1, Syme syme2); |
| 877 | |
| 878 | localstatic TForm |
| 879 | tfpNothing(Stab stab, AbSyn ab) |
| 880 | { |
| 881 | return tfNone()tfMulti(0); |
| 882 | } |
| 883 | |
| 884 | localstatic TForm |
| 885 | tfpBlank(Stab stab, AbSyn ab) |
| 886 | { |
| 887 | TForm tf; |
| 888 | |
| 889 | #ifdef UseTypeVariables |
| 890 | tf = tfNewNode(TF_Variable, 1, tfUnknown); |
| 891 | #else |
| 892 | tf = tfUnknown; |
| 893 | #endif |
| 894 | |
| 895 | return tf; |
| 896 | } |
| 897 | |
| 898 | localstatic TForm |
| 899 | tfpId(Stab stab, AbSyn ab) |
| 900 | { |
| 901 | Symbol sym = ab->abId.sym; |
| 902 | Syme syme, absyme; |
| 903 | TForm tf; |
| 904 | |
| 905 | tf = abTForm(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->tform : 0); |
| 906 | if (abIsTheId(ab, ssymCategory)(((ab)->abHdr.tag == (AB_Id)) && ((ab)->abId.sym )==(ssymCategory)) && tf && tfIsDefine(tf)(((tf)->tag) == TF_Define)) { |
| 907 | TForm tfc = tfDeclareType(tfDefineDecl(tf))tfFollowArg(tfFollowArg(tf, 0), 0); |
| 908 | TForm tfw = tfDefineVal(tf)tfFollowArg(tf, 1); |
| 909 | if (tfIsSyntax(tfw)(((tfw)->tag) == TF_Syntax)) |
| 910 | tfw = tfPendingFrSyntax(stab, tfGetExpr(tfw)((tfw)->__absyn), tfw); |
| 911 | if (tfIsSyntax(tfc)(((tfc)->tag) == TF_Syntax)) |
| 912 | tfForwardFrSyntax(tfc, tfThirdFrTForm(tfw)); |
| 913 | tfFollow(tfc)((tfc) = tfFollowFn(tfc)); |
| 914 | tfSetPending(tfc)(((tfc)->state)=TF_State_Pending); |
| 915 | return tfc; |
| 916 | } |
| 917 | |
| 918 | absyme = abSyme(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->syme : 0); |
| 919 | syme = tfp0IdSyme(stab, absyme, sym); |
| 920 | |
| 921 | if (! syme) |
| 922 | /* This sym is not one of the known special type syms. */ |
| 923 | tf = tfp0General(stab, ab); |
| 924 | |
| 925 | else if (absyme && symeOriginal(absyme) == symeOriginal(syme)) |
| 926 | /* This syme is one of the known special type symes. */ |
| 927 | tf = tfp0IdTForm(sym); |
| 928 | |
| 929 | else if (!absyme && listMemq(Syme)(Syme_listPointer->Memq)(stabGetMeanings(stab, NULL((void*)0), sym), syme)) |
| 930 | /* This ab could be one of the known special type forms. */ |
| 931 | /* Don't try to do any type inference here. */ |
| 932 | tf = tfp0IdTForm(sym); |
| 933 | |
| 934 | else |
| 935 | /* This ab is not one of the known special type forms. */ |
| 936 | tf = tfp0General(stab, ab); |
| 937 | |
| 938 | if (sym == ssymBoolean && tfBoolean == tfUnknown) |
| 939 | tfBoolean = tf; |
| 940 | if (sym == ssymTextWriter && tfTextWriter == tfUnknown) |
| 941 | tfTextWriter = tf; |
| 942 | if (sym == ssymMachineInteger && tfMachineInteger == tfUnknown) |
| 943 | tfMachineInteger = tf; |
| 944 | |
| 945 | return tf; |
| 946 | } |
| 947 | |
| 948 | localstatic TForm |
| 949 | tfpDeclare(Stab stab, AbSyn ab) |
| 950 | { |
| 951 | TForm tf; |
| 952 | |
| 953 | tf = tfNewNode(TF_Declare, 1, tfp0Float(stab, ab->abDeclare.type)); |
| 954 | |
| 955 | return tf; |
| 956 | } |
| 957 | |
| 958 | localstatic TForm |
| 959 | tfpDefine(Stab stab, AbSyn ab) |
| 960 | { |
| 961 | AbSyn lhs, rhs; |
| 962 | TForm tfl, tfr; |
| 963 | |
| 964 | lhs = ab->abDefine.lhs; |
| 965 | rhs = ab->abDefine.rhs; |
| 966 | if (abTag(lhs)((lhs)->abHdr.tag) != AB_Declare) |
| 967 | lhs = abNewDeclare(abPos(ab), lhs, abNewNothing(abPos(ab)))abNew(AB_Declare, (spstackFirst((ab)->abHdr.pos)),2, lhs,abNew (AB_Nothing, (spstackFirst((ab)->abHdr.pos)),0 )); |
| 968 | |
| 969 | tfl = tfp0Float(stab, lhs); |
| 970 | tfr = tfSyntaxFrAbSyn(stab, rhs); |
| 971 | |
| 972 | return tfNewNode(TF_Define, 2, tfl, tfr); |
| 973 | } |
| 974 | |
| 975 | localstatic TForm |
| 976 | tfpAssign(Stab stab, AbSyn ab) |
| 977 | { |
| 978 | AbSyn lhs, rhs; |
| 979 | TForm tfl, tfr; |
| 980 | |
| 981 | lhs = ab->abAssign.lhs; |
| 982 | rhs = ab->abAssign.rhs; |
| 983 | if (abTag(lhs)((lhs)->abHdr.tag) != AB_Declare) |
| 984 | lhs = abNewDeclare(abPos(ab), lhs, abNewNothing(abPos(ab)))abNew(AB_Declare, (spstackFirst((ab)->abHdr.pos)),2, lhs,abNew (AB_Nothing, (spstackFirst((ab)->abHdr.pos)),0 )); |
| 985 | |
| 986 | tfl = tfp0Float(stab, lhs); |
| 987 | tfr = tfSyntaxFrAbSyn(stab, rhs); |
| 988 | |
| 989 | return tfNewNode(TF_Assign, 2, tfl, tfr); |
| 990 | } |
| 991 | |
| 992 | localstatic TForm |
| 993 | tfpComma(Stab stab, AbSyn ab) |
| 994 | { |
| 995 | TForm tf; |
| 996 | Length i, argc; |
| 997 | |
| 998 | argc = abArgc(ab)((ab)->abHdr.argc); |
| 999 | if (argc == 1) |
| 1000 | tf = tfp0Float(stab, abArgv(ab)((ab)->abGen.data.argv)[0]); |
| 1001 | else { |
| 1002 | tf = tfNewEmpty(TF_Multiple, argc); |
| 1003 | for (i = 0; i < argc; i += 1) |
| 1004 | tfArgv(tf)((tf)->argv)[i] = tfp0Float(stab, abArgv(ab)((ab)->abGen.data.argv)[i]); |
| 1005 | } |
| 1006 | |
| 1007 | return tf; |
| 1008 | } |
| 1009 | |
| 1010 | localstatic TForm |
| 1011 | tfpAdd(Stab stab, AbSyn ab) |
| 1012 | { |
| 1013 | TForm tf; |
| 1014 | |
| 1015 | tf = tfNewNode(TF_Add, 1, tfp0Float(stab, ab->abAdd.base)); |
| 1016 | |
| 1017 | return tf; |
| 1018 | } |
| 1019 | |
| 1020 | localstatic TForm |
| 1021 | tfpWith(Stab stab, AbSyn ab) |
| 1022 | { |
| 1023 | TForm tf; |
| 1024 | |
| 1025 | tf = tfNewNode(TF_With, 2, |
| 1026 | tfp0Float(stab, ab->abWith.base), |
| 1027 | tfp0Float(stab, ab->abWith.within)); |
| 1028 | |
| 1029 | return tf; |
| 1030 | } |
| 1031 | |
| 1032 | localstatic TForm |
| 1033 | tfpExcept(Stab stab, AbSyn ab) |
| 1034 | { |
| 1035 | TForm tf; |
| 1036 | |
| 1037 | tf = tfNewNode(TF_Except, 2, |
| 1038 | tfp0Float(stab, ab->abExcept.type), |
| 1039 | tfp0Float(stab, ab->abExcept.except)); |
| 1040 | |
| 1041 | return tf; |
| 1042 | } |
| 1043 | |
| 1044 | localstatic TForm |
| 1045 | tfpIf(Stab stab, AbSyn ab) |
| 1046 | { |
| 1047 | TForm test, thenAlt, elseAlt; |
| 1048 | TForm tf; |
| 1049 | |
| 1050 | test = tfp0Float(stab, ab->abIf.test); |
| 1051 | |
| 1052 | tfpConditions = listCons(AbSyn)(AbSyn_listPointer->Cons)(ab->abIf.test, tfpConditions); |
| 1053 | thenAlt = tfp0Float(stab, ab->abIf.thenAlt); |
| 1054 | tfpConditions = cdr(tfpConditions)((tfpConditions)->rest); |
| 1055 | |
| 1056 | elseAlt = tfp0Float(stab, ab->abIf.elseAlt); |
| 1057 | |
| 1058 | tf = tfNewNode(TF_If, 3, test, thenAlt, elseAlt); |
| 1059 | |
| 1060 | return tf; |
| 1061 | } |
| 1062 | |
| 1063 | localstatic TForm |
| 1064 | tfpApply(Stab stab, AbSyn ab) |
| 1065 | { |
| 1066 | AbSyn op; |
| 1067 | Symbol sym; |
| 1068 | Length i, argc; |
| 1069 | Syme syme; |
| 1070 | Syme opSyme; |
| 1071 | TForm tf; |
| 1072 | |
| 1073 | op = abApplyOp(ab)((ab)->abApply.op); |
| 1074 | if (abTag(op)((op)->abHdr.tag) != AB_Id) |
| 1075 | return tfp0General(stab, ab); |
| 1076 | |
| 1077 | sym = op->abId.sym; |
| 1078 | argc = abApplyArgc(ab)(((ab)->abHdr.argc)-1); |
| 1079 | opSyme = abSyme(op)((op)->abHdr.seman ? (op)->abHdr.seman->syme : 0); |
| 1080 | |
| 1081 | syme = tfp0OpSyme(stab, opSyme, sym, argc); |
| 1082 | |
| 1083 | if (syme == NULL((void*)0)) |
| 1084 | /* This op is not one of the known special tform ops. */ |
| 1085 | tf = tfp0General(stab, ab); |
| 1086 | |
| 1087 | else if (abSyme(op)((op)->abHdr.seman ? (op)->abHdr.seman->syme : 0) |
| 1088 | && tfSymesEqModExtends(symeOriginal(abSyme(op)((op)->abHdr.seman ? (op)->abHdr.seman->syme : 0)), |
| 1089 | symeOriginal(syme))) { |
| 1090 | /* This syme is one of the known special tform ops. */ |
| 1091 | tf = tfp0OpTForm(sym, argc); |
| 1092 | for (i = 0; i < argc; i += 1) |
| 1093 | tfArgv(tf)((tf)->argv)[i] = tfp0Float(stab, abApplyArg(ab, i)((ab)->abApply.argv[i])); |
| 1094 | } |
| 1095 | |
| 1096 | else if (abSyme(op)((op)->abHdr.seman ? (op)->abHdr.seman->syme : 0) == NULL((void*)0) && |
| 1097 | listMemq(Syme)(Syme_listPointer->Memq)(stabGetMeanings(stab, NULL((void*)0), sym), syme)) { |
| 1098 | /* This op could be one of the known special tform ops. */ |
| 1099 | /* Don't try to do any type inference here. */ |
| 1100 | tf = tfp0OpTForm(sym, argc); |
| 1101 | for (i = 0; i < argc; i += 1) |
| 1102 | tfArgv(tf)((tf)->argv)[i] = tfp0Float(stab, abApplyArg(ab, i)((ab)->abApply.argv[i])); |
| 1103 | } |
| 1104 | |
| 1105 | else |
| 1106 | /* This op is not one of the known special tforms ops. */ |
| 1107 | tf = tfp0General(stab, ab); |
| 1108 | |
| 1109 | return tf; |
| 1110 | } |
| 1111 | |
| 1112 | /* |
| 1113 | * tfPending may have to avoid symeEqual, as we might not |
| 1114 | * yet know enough about types. NB: There might be a better |
| 1115 | * test for this case (where we get an extended meaning in |
| 1116 | * the above fn). |
| 1117 | */ |
| 1118 | localstatic Bool |
| 1119 | tfSymesEqModExtends(Syme syme1, Syme syme2) |
| 1120 | { |
| 1121 | SymeList exts; |
| 1122 | |
| 1123 | if (syme1 == syme2) |
| 1124 | return true1; |
| 1125 | if (symeIsExtend(syme2)(((((syme2)->kind == SYME_Trigger ? libGetAllSymes((syme2) ->lib) : ((void*)0)), (syme2))->kind) == SYME_Extend)) { |
| 1126 | for (exts = symeExtendee(syme2); exts ; exts = cdr(exts)((exts)->rest)) { |
| 1127 | if (tfSymesEqModExtends(car(exts)((exts)->first), syme1)) |
| 1128 | return true1; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | if (!symeIsExtend(syme1)(((((syme1)->kind == SYME_Trigger ? libGetAllSymes((syme1) ->lib) : ((void*)0)), (syme1))->kind) == SYME_Extend)) |
| 1133 | return false((int) 0); |
| 1134 | |
| 1135 | for (exts = symeExtendee(syme1); exts ; exts = cdr(exts)((exts)->rest)) { |
| 1136 | if (tfSymesEqModExtends(car(exts)((exts)->first), syme2)) |
| 1137 | return true1; |
| 1138 | } |
| 1139 | return false((int) 0); |
| 1140 | } |
| 1141 | |
| 1142 | /***************************************************************************** |
| 1143 | * |
| 1144 | * :: Declarations for tfMeaning |
| 1145 | * |
| 1146 | ****************************************************************************/ |
| 1147 | |
| 1148 | localstatic TForm tfm0General (Stab, AbSyn, TForm); |
| 1149 | localstatic TForm tfm0Args (Stab, TForm); |
| 1150 | localstatic void tfm0FoamType (TForm); |
| 1151 | |
| 1152 | localstatic TForm tfmNothing (Stab, AbSyn, TForm); |
| 1153 | localstatic TForm tfmBlank (Stab, AbSyn, TForm); |
| 1154 | localstatic TForm tfmId (Stab, AbSyn, TForm); |
| 1155 | localstatic TForm tfmDeclare (Stab, AbSyn, TForm); |
| 1156 | localstatic TForm tfmDefine (Stab, AbSyn, TForm); |
| 1157 | localstatic TForm tfmAssign (Stab, AbSyn, TForm); |
| 1158 | localstatic TForm tfmComma (Stab, AbSyn, TForm); |
| 1159 | localstatic TForm tfmAdd (Stab, AbSyn, TForm); |
| 1160 | localstatic TForm tfmWith (Stab, AbSyn, TForm); |
| 1161 | localstatic TForm tfmIf (Stab, AbSyn, TForm); |
| 1162 | localstatic TForm tfmApply (Stab, AbSyn, TForm); |
| 1163 | localstatic TForm tfmExcept (Stab, AbSyn, TForm); |
| 1164 | |
| 1165 | /***************************************************************************** |
| 1166 | * |
| 1167 | * :: tfMeaning |
| 1168 | * |
| 1169 | ****************************************************************************/ |
| 1170 | |
| 1171 | TForm |
| 1172 | tfMeaning(Stab stab, AbSyn ab, TForm tf) |
| 1173 | { |
| 1174 | static int serialNo = 0, depthNo = 0; |
| 1175 | int serialThis; |
| 1176 | |
| 1177 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 1178 | |
| 1179 | assert(!tfIsSyntax(tf))do { if (!(!(((tf)->tag) == TF_Syntax))) _do_assert(("!tfIsSyntax(tf)" ),"tform.c",1179); } while (0); |
| 1180 | if (tfIsMeaning(tf)(((tf)->state)>=TF_State_Meaning)) |
| 1181 | return tf; |
| 1182 | tfSetMeaning(tf)(((tf)->state)=TF_State_Meaning); |
| 1183 | |
| 1184 | if (!abIsSefo(ab)(((ab)->abHdr.state) == AB_State_HasUnique)) { |
| 1185 | tfm0Args(stab, tf); |
| 1186 | tfGetSymes(stab, tf, ab); |
| 1187 | tfCheckConsts(tf); |
| 1188 | return tf; |
| 1189 | } |
| 1190 | if (!abIsSefo(tfGetExpr(tf))(((((tf)->__absyn))->abHdr.state) == AB_State_HasUnique )) |
| 1191 | abTransferSemantics(ab, tfGetExpr(tf)((tf)->__absyn)); |
| 1192 | |
| 1193 | serialNo += 1; |
| 1194 | depthNo += 1; |
| 1195 | serialThis = serialNo; |
| 1196 | if (DEBUG(tfExpr)tfExprDebug) { |
| 1197 | fprintf(dbOut, "->tfm: %*s%d= ", depthNo, "", serialThis); |
| 1198 | abPrettyPrint(dbOut, ab); |
| 1199 | fnewline(dbOut); |
| 1200 | } |
| 1201 | |
| 1202 | /* The stab is used to look up meanings for ids without them. */ |
| 1203 | if (abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0)) |
| 1204 | stab = abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0); |
| 1205 | |
| 1206 | switch (abTag(ab)((ab)->abHdr.tag)) { |
| 1207 | case AB_Nothing: tf = tfmNothing (stab, ab, tf); break; |
| 1208 | case AB_Blank: tf = tfmBlank (stab, ab, tf); break; |
| 1209 | case AB_Id: tf = tfmId (stab, ab, tf); break; |
| 1210 | case AB_Declare: tf = tfmDeclare (stab, ab, tf); break; |
| 1211 | case AB_Define: tf = tfmDefine (stab, ab, tf); break; |
| 1212 | case AB_Assign: tf = tfmAssign (stab, ab, tf); break; |
| 1213 | case AB_Comma: tf = tfmComma (stab, ab, tf); break; |
| 1214 | case AB_Add: tf = tfmAdd (stab, ab, tf); break; |
| 1215 | case AB_With: tf = tfmWith (stab, ab, tf); break; |
| 1216 | case AB_If: tf = tfmIf (stab, ab, tf); break; |
| 1217 | case AB_Apply: tf = tfmApply (stab, ab, tf); break; |
| 1218 | case AB_Except: tf = tfmExcept (stab, ab, tf); break; |
| 1219 | default: tf = tfm0General(stab, ab, tf); break; |
| 1220 | } |
| 1221 | |
| 1222 | tfCheckConsts(tf); |
| 1223 | tfm0FoamType(tf); |
| 1224 | |
| 1225 | if (DEBUG(tfExpr)tfExprDebug) { |
| 1226 | fprintf(dbOut, "<-tfm: %*s%d= ", depthNo, "", serialThis); |
| 1227 | tfPrint(dbOut, tf); |
| 1228 | fnewline(dbOut); |
| 1229 | } |
| 1230 | depthNo -= 1; |
| 1231 | |
| 1232 | return tf; |
| 1233 | } |
| 1234 | |
| 1235 | void |
| 1236 | tfSetMeaningArgs(TForm tf) |
| 1237 | { |
| 1238 | Length i; |
| 1239 | |
| 1240 | tfSetMeaning(tf)(((tf)->state)=TF_State_Meaning); |
| 1241 | for (i = 0; i < tfArgc(tf)((tf)->argc); i += 1) |
| 1242 | if (!tfIsMeaning(tfFollowArg(tf, i))(((tfFollowArg(tf, i))->state)>=TF_State_Meaning)) |
| 1243 | tfSetTForm(tf)(((tf)->state)=TF_State_TForm); |
| 1244 | } |
| 1245 | |
| 1246 | /***************************************************************************** |
| 1247 | * |
| 1248 | * :: tfMeaning helper functions |
| 1249 | * |
| 1250 | ****************************************************************************/ |
| 1251 | |
| 1252 | localstatic TForm |
| 1253 | tfm0General(Stab stab, AbSyn ab, TForm tf) |
| 1254 | { |
| 1255 | return tf; |
| 1256 | } |
| 1257 | |
| 1258 | localstatic TForm |
| 1259 | tfm0Args(Stab stab, TForm tf) |
| 1260 | { |
| 1261 | Length i, argc = tfArgc(tf)((tf)->argc); |
| 1262 | |
| 1263 | for (i = 0; i < argc; i += 1) { |
| 1264 | TForm tfarg = tfArgv(tf)((tf)->argv)[i]; |
| 1265 | tfMeaning(stab, tfGetExpr(tfarg)((tfarg)->__absyn), tfarg); |
| 1266 | } |
| 1267 | |
| 1268 | return tf; |
| 1269 | } |
| 1270 | |
| 1271 | localstatic void |
| 1272 | tfm0FoamType(TForm tf) |
| 1273 | { |
| 1274 | AbSyn ab; |
| 1275 | Syme syme; |
| 1276 | TForm ntf; |
| 1277 | Bool chk = false((int) 0); |
| 1278 | Symbol sym; |
| 1279 | FoamTag tag = FOAM_LIMIT; |
| 1280 | |
| 1281 | ab = tfGetExpr(tf)((tf)->__absyn); |
| 1282 | if (ab == NULL((void*)0)) return; |
| 1283 | |
| 1284 | syme = abSyme(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->syme : 0); |
| 1285 | if (syme == NULL((void*)0)) return; |
| 1286 | |
| 1287 | switch (symeKind(syme)((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind)) { |
| 1288 | case SYME_Export: |
| 1289 | ntf = tfDefineeType(symeType(syme)); |
| 1290 | chk = tfIsType(ntf)(((ntf)->tag) == TF_Type); |
| 1291 | break; |
| 1292 | case SYME_Import: |
| 1293 | ntf = tfDefineeType(symeExporter(syme)); |
| 1294 | chk = tfIsTheId(ntf, ssymMachine)(((((ntf)->tag) == TF_General) && ((((ntf)->__absyn ))->abHdr.tag) == AB_Id) && (((ntf)->__absyn)-> abId.sym) == (ssymMachine)) || tfIsTheId(ntf, ssymBasic)(((((ntf)->tag) == TF_General) && ((((ntf)->__absyn ))->abHdr.tag) == AB_Id) && (((ntf)->__absyn)-> abId.sym) == (ssymBasic)); |
| 1295 | break; |
| 1296 | default: |
| 1297 | break; |
| 1298 | } |
| 1299 | |
| 1300 | if (chk == false((int) 0)) return; |
| 1301 | sym = symeId(syme)((syme)->id); |
| 1302 | |
| 1303 | if (sym == ssymBool) tag = FOAM_Bool; |
| 1304 | else if (sym == ssymByte) tag = FOAM_Byte; |
| 1305 | else if (sym == ssymHInt) tag = FOAM_HInt; |
| 1306 | else if (sym == ssymSInt) tag = FOAM_SInt; |
| 1307 | else if (sym == ssymBInt) tag = FOAM_BInt; |
| 1308 | else if (sym == ssymChar) tag = FOAM_Char; |
| 1309 | else if (sym == ssymSFlo) tag = FOAM_SFlo; |
| 1310 | else if (sym == ssymDFlo) tag = FOAM_DFlo; |
| 1311 | else if (sym == ssymNil) tag = FOAM_Nil; |
| 1312 | else if (sym == ssymPtr) tag = FOAM_Ptr; |
| 1313 | else if (sym == ssymArr) tag = FOAM_Arr; |
| 1314 | tfFoamType(tf)((tf)->raw) = tag; |
| 1315 | } |
| 1316 | |
| 1317 | /***************************************************************************** |
| 1318 | * |
| 1319 | * :: tfMeaning cases |
| 1320 | * |
| 1321 | ****************************************************************************/ |
| 1322 | |
| 1323 | localstatic TForm |
| 1324 | tfmNothing(Stab stab, AbSyn ab, TForm tf) |
| 1325 | { |
| 1326 | assert(tfIsNone(tf))do { if (!(((((tf)->tag) == TF_Multiple) && tfMultiArgc (tf) == 0))) _do_assert(("tfIsNone(tf)"),"tform.c",1326); } while (0); |
| 1327 | return tfm0General(stab, ab, tf); |
| 1328 | } |
| 1329 | |
| 1330 | localstatic TForm |
| 1331 | tfmBlank(Stab stab, AbSyn ab, TForm tf) |
| 1332 | { |
| 1333 | #ifdef UseTypeVariables |
| 1334 | assert(tfIsVariable(tf))do { if (!((((tf)->tag) == TF_Variable))) _do_assert(("tfIsVariable(tf)" ),"tform.c",1334); } while (0); |
| 1335 | #else |
| 1336 | assert(tfIsUnknown(tf))do { if (!((((tf)->tag) == TF_Unknown))) _do_assert(("tfIsUnknown(tf)" ),"tform.c",1336); } while (0); |
| 1337 | #endif |
| 1338 | |
| 1339 | return tfm0General(stab, ab, tf); |
| 1340 | } |
| 1341 | |
| 1342 | localstatic TForm |
| 1343 | tfmId(Stab stab, AbSyn ab, TForm tf) |
| 1344 | { |
| 1345 | Syme syme = abSyme(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->syme : 0); |
| 1346 | |
| 1347 | /*!! assert(syme); */ |
| 1348 | if (!syme) return tf; |
| 1349 | |
| 1350 | if (symeIsLibrary(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Library) || symeIsArchive(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Archive)) |
| 1351 | tfSetSymes(tf, listCons(Syme)(syme, listNil(Syme)))((tf)->symes = ((Syme_listPointer->Cons)(syme, ((SymeList ) 0)))); |
| 1352 | |
| 1353 | return tf; |
| 1354 | } |
| 1355 | |
| 1356 | localstatic TForm |
| 1357 | tfmDeclare(Stab stab, AbSyn ab, TForm tf) |
| 1358 | { |
| 1359 | assert(tfIsDeclare(tf))do { if (!((((tf)->tag) == TF_Declare))) _do_assert(("tfIsDeclare(tf)" ),"tform.c",1359); } while (0); |
| 1360 | tfMeaning(stab, ab->abDeclare.type, tfDeclareType(tf)tfFollowArg(tf, 0)); |
| 1361 | tfSetSymes(tf, tfSymesFrDeclare(ab))((tf)->symes = (tfSymesFrDeclare(ab))); |
| 1362 | return tf; |
| 1363 | } |
| 1364 | |
| 1365 | localstatic TForm |
| 1366 | tfmDefine(Stab stab, AbSyn ab, TForm tf) |
| 1367 | { |
| 1368 | AbSyn lhs, rhs; |
| 1369 | TForm tfl, tfr; |
| 1370 | |
| 1371 | lhs = ab->abDefine.lhs; |
| 1372 | rhs = ab->abDefine.rhs; |
| 1373 | |
| 1374 | tfl = tfArgv(tf)((tf)->argv)[0]; |
| 1375 | tfr = tfArgv(tf)((tf)->argv)[1]; |
| 1376 | |
| 1377 | assert(tfIsDefine(tf))do { if (!((((tf)->tag) == TF_Define))) _do_assert(("tfIsDefine(tf)" ),"tform.c",1377); } while (0); |
| 1378 | if (abTag(lhs)((lhs)->abHdr.tag) != AB_Declare) |
| 1379 | lhs = tfGetExpr(tfl)((tfl)->__absyn); |
| 1380 | |
| 1381 | tfMeaning(stab, lhs, tfl); |
| 1382 | if (tfIsSyntax(tfr)(((tfr)->tag) == TF_Syntax)) { |
| 1383 | if (tfSatType(tfl)) |
| 1384 | tfForwardFrSyntax(tfr, tfp0Float(stab, rhs)); |
| 1385 | else |
| 1386 | tfForwardFrSyntax(tfr, tfNewAbSyn(TF_General, rhs)); |
| 1387 | } |
| 1388 | tfMeaning(stab, rhs, tfr); |
| 1389 | |
| 1390 | return tf; |
| 1391 | } |
| 1392 | |
| 1393 | localstatic TForm |
| 1394 | tfmAssign(Stab stab, AbSyn ab, TForm tf) |
| 1395 | { |
| 1396 | AbSyn lhs, rhs; |
| 1397 | TForm tfl, tfr; |
| 1398 | |
| 1399 | lhs = ab->abDefine.lhs; |
| 1400 | rhs = ab->abDefine.rhs; |
| 1401 | |
| 1402 | tfl = tfArgv(tf)((tf)->argv)[0]; |
| 1403 | tfr = tfArgv(tf)((tf)->argv)[1]; |
| 1404 | |
| 1405 | assert(tfIsAssign(tf))do { if (!((((tf)->tag) == TF_Assign))) _do_assert(("tfIsAssign(tf)" ),"tform.c",1405); } while (0); |
| 1406 | if (abTag(lhs)((lhs)->abHdr.tag) != AB_Declare) |
| 1407 | lhs = tfGetExpr(tfl)((tfl)->__absyn); |
| 1408 | |
| 1409 | tfMeaning(stab, lhs, tfl); |
| 1410 | if (tfIsSyntax(tfr)(((tfr)->tag) == TF_Syntax)) { |
| 1411 | if (tfSatType(tfl)) |
| 1412 | tfForwardFrSyntax(tfr, tfp0Float(stab, rhs)); |
| 1413 | else |
| 1414 | tfForwardFrSyntax(tfr, tfNewAbSyn(TF_General, rhs)); |
| 1415 | } |
| 1416 | tfMeaning(stab, rhs, tfr); |
| 1417 | |
| 1418 | return tf; |
| 1419 | } |
| 1420 | |
| 1421 | localstatic TForm |
| 1422 | tfmComma(Stab stab, AbSyn ab, TForm tf) |
| 1423 | { |
| 1424 | Length i, argc; |
| 1425 | |
| 1426 | argc = abArgc(ab)((ab)->abHdr.argc); |
| 1427 | if (argc == 1) { |
| 1428 | tfSetTForm(tf)(((tf)->state)=TF_State_TForm); |
| 1429 | tfMeaning(stab, abArgv(ab)((ab)->abGen.data.argv)[0], tf); |
| 1430 | } |
| 1431 | else { |
| 1432 | assert(tfIsMulti(tf) && argc == tfMultiArgc(tf))do { if (!((((tf)->tag) == TF_Multiple) && argc == tfMultiArgc(tf))) _do_assert(("tfIsMulti(tf) && argc == tfMultiArgc(tf)" ),"tform.c",1432); } while (0); |
| 1433 | for (i = 0; i < argc; i += 1) |
| 1434 | tfMeaning(stab, abArgv(ab)((ab)->abGen.data.argv)[i], tfArgv(tf)((tf)->argv)[i]); |
| 1435 | tfSetSymes(tf, tfSymesFrMulti(tf))((tf)->symes = (tfSymesFrMulti(tf))); |
| 1436 | } |
| 1437 | |
| 1438 | return tf; |
| 1439 | } |
| 1440 | |
| 1441 | localstatic TForm |
| 1442 | tfmAdd(Stab stab, AbSyn ab, TForm tf) |
| 1443 | { |
| 1444 | assert(tfIsAdd(tf))do { if (!((((tf)->tag) == TF_Add))) _do_assert(("tfIsAdd(tf)" ),"tform.c",1444); } while (0); |
| 1445 | |
| 1446 | tfMeaning(stab, ab->abAdd.base, tfAddBase(tf)tfFollowArg(tf, 0)); |
| 1447 | tfSetSymes(tf, tfSymesFrAdd(ab))((tf)->symes = (tfSymesFrAdd(ab))); |
| 1448 | tfGetSelf(stab, tf); |
| 1449 | |
| 1450 | return tf; |
| 1451 | } |
| 1452 | |
| 1453 | localstatic TForm |
| 1454 | tfmWith(Stab stab, AbSyn ab, TForm tf) |
| 1455 | { |
| 1456 | assert(tfIsWith(tf))do { if (!((((tf)->tag) == TF_With))) _do_assert(("tfIsWith(tf)" ),"tform.c",1456); } while (0); |
| 1457 | |
| 1458 | tfMeaning(stab, ab->abWith.base, tfWithBase(tf)tfFollowArg(tf, 0)); |
| 1459 | tfMeaning(stab, ab->abWith.within, tfWithWithin(tf)tfFollowArg(tf, 1)); |
| 1460 | tfGetSelf(stab, tf); |
| 1461 | |
| 1462 | return tf; |
| 1463 | } |
| 1464 | |
| 1465 | localstatic TForm |
| 1466 | tfmExcept(Stab stab, AbSyn ab, TForm tf) |
| 1467 | { |
| 1468 | assert(tfIsExcept(tf))do { if (!((((tf)->tag) == TF_Except))) _do_assert(("tfIsExcept(tf)" ),"tform.c",1468); } while (0); |
| 1469 | |
| 1470 | tfMeaning(stab, ab->abExcept.type, tfExceptType(tf)tfFollowArg(tf, 0)); |
| 1471 | tfMeaning(stab, ab->abExcept.except, tfExceptExcept(tf)tfFollowArg(tf, 1)); |
| 1472 | |
| 1473 | return tf; |
| 1474 | } |
| 1475 | |
| 1476 | localstatic TForm |
| 1477 | tfmIf(Stab stab, AbSyn ab, TForm tf) |
| 1478 | { |
| 1479 | assert(tfIsIf(tf))do { if (!((((tf)->tag) == TF_If))) _do_assert(("tfIsIf(tf)" ),"tform.c",1479); } while (0); |
| 1480 | |
| 1481 | tfMeaning(stab, ab->abIf.test, tfIfTest(tf)tfFollowArg(tf, 0)); |
| 1482 | tfMeaning(stab, ab->abIf.thenAlt, tfIfThen(tf)tfFollowArg(tf, 1)); |
| 1483 | tfMeaning(stab, ab->abIf.elseAlt, tfIfElse(tf)tfFollowArg(tf, 2)); |
| 1484 | tfGetSelf(stab, tf); |
| 1485 | |
| 1486 | return tf; |
| 1487 | } |
| 1488 | |
| 1489 | localstatic TForm |
| 1490 | tfmApply(Stab stab, AbSyn ab, TForm tf) |
| 1491 | { |
| 1492 | if (!tfIsGeneral(tf)(((tf)->tag) == TF_General)) { |
| 1493 | Length i, argc = abApplyArgc(ab)(((ab)->abHdr.argc)-1); |
| 1494 | assert(argc == tfArgc(tf))do { if (!(argc == ((tf)->argc))) _do_assert(("argc == tfArgc(tf)" ),"tform.c",1494); } while (0); |
| 1495 | for (i = 0; i < argc; i += 1) |
| 1496 | tfMeaning(stab, abApplyArg(ab, i)((ab)->abApply.argv[i]), tfArgv(tf)((tf)->argv)[i]); |
| 1497 | } |
| 1498 | |
| 1499 | tfGetSymes(stab, tf, ab); |
| 1500 | |
| 1501 | return tf; |
| 1502 | } |
| 1503 | |
| 1504 | void |
| 1505 | tfGetSymes(Stab stab, TForm tf, AbSyn ab) |
| 1506 | { |
| 1507 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 1508 | assert(ab)do { if (!(ab)) _do_assert(("ab"),"tform.c",1508); } while (0 ); |
| 1509 | |
| 1510 | switch (tfTag(tf)((tf)->tag)) { |
| 1511 | case TF_Map: |
| 1512 | case TF_PackedMap: |
| 1513 | symes = tfSymesFrMap(tf); |
| 1514 | break; |
| 1515 | case TF_Cross: |
| 1516 | symes = tfSymesFrCross(tf); |
| 1517 | break; |
| 1518 | case TF_Enumerate: |
| 1519 | symes = tfSymesFrEnum(stab, tf, ab); |
| 1520 | break; |
| 1521 | case TF_RawRecord: |
| 1522 | symes = tfSymesFrRawRecord(stab, tf, ab); |
| 1523 | break; |
| 1524 | case TF_Record: |
| 1525 | symes = tfSymesFrRecord(stab, tf, ab); |
| 1526 | break; |
| 1527 | case TF_TrailingArray: |
| 1528 | symes = tfSymesFrTrailingArray(stab, tf, ab); |
| 1529 | break; |
| 1530 | case TF_Union: |
| 1531 | symes = tfSymesFrUnion(stab, tf, ab); |
| 1532 | break; |
| 1533 | default: |
| 1534 | break; |
| 1535 | } |
| 1536 | |
| 1537 | tfSetSymes(tf, symes)((tf)->symes = (symes)); |
| 1538 | } |
| 1539 | |
| 1540 | /****************************************************************************** |
| 1541 | * |
| 1542 | * :: tfToAbSyn |
| 1543 | * |
| 1544 | *****************************************************************************/ |
| 1545 | |
| 1546 | AbSyn |
| 1547 | tfToAbSyn(TForm tf) |
| 1548 | { |
| 1549 | return tfToAbSyn0(tf, false((int) 0)); |
| 1550 | } |
| 1551 | |
| 1552 | AbSyn |
| 1553 | tfToAbSynPretty(TForm tf) |
| 1554 | { |
| 1555 | return tfToAbSyn0(tf, true1); |
| 1556 | } |
| 1557 | |
| 1558 | localstatic AbSyn |
| 1559 | tfToAbSyn0(TForm tf, Bool pretty) |
| 1560 | { |
| 1561 | AbSyn ab; |
| 1562 | Syme syme; |
| 1563 | Length i; |
| 1564 | |
| 1565 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 1566 | |
| 1567 | if (tfHasExpr(tf)((tf)->__absyn != 0) && !pretty) |
| 1568 | return tfGetExpr(tf)((tf)->__absyn); |
| 1569 | |
| 1570 | if (DEBUG(tfExpr)tfExprDebug) { |
| 1571 | fprintf(dbOut, "tfToAbSyn -> "); |
| 1572 | tfPrint(dbOut, tf); |
| 1573 | fnewline(dbOut); |
| 1574 | } |
| 1575 | |
| 1576 | switch (tfTag(tf)((tf)->tag)) { |
| 1577 | case TF_Unknown: |
| 1578 | ab = abUnknown; |
| 1579 | break; |
| 1580 | case TF_Exit: |
| 1581 | ab = abNewId(sposNone, ssymExit)abNew(AB_Id, sposNone,1, ssymExit); |
| 1582 | break; |
| 1583 | case TF_Literal: |
| 1584 | ab = abNewId(sposNone, ssymLiteral)abNew(AB_Id, sposNone,1, ssymLiteral); |
| 1585 | break; |
| 1586 | case TF_Test: |
| 1587 | ab = abNewId(sposNone, ssymTest)abNew(AB_Id, sposNone,1, ssymTest); |
| 1588 | break; |
| 1589 | case TF_Type: |
| 1590 | ab = abNewId(sposNone, ssymType)abNew(AB_Id, sposNone,1, ssymType); |
| 1591 | break; |
| 1592 | case TF_Category: |
| 1593 | ab = abNewId(sposNone, ssymCategory)abNew(AB_Id, sposNone,1, ssymCategory); |
| 1594 | break; |
| 1595 | |
| 1596 | case TF_Syntax: |
| 1597 | ab = tfGetExpr(tf)((tf)->__absyn); |
| 1598 | break; |
| 1599 | case TF_General: |
| 1600 | ab = tfGetExpr(tf)((tf)->__absyn); |
| 1601 | break; |
| 1602 | |
| 1603 | case TF_Add: |
| 1604 | ab = abNewAdd(sposNone,abNew(AB_Add, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty ),tfSymesToAdd(((tf)->symes))) |
| 1605 | tfDisownExpr(tfAddBase(tf), pretty),abNew(AB_Add, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty ),tfSymesToAdd(((tf)->symes))) |
| 1606 | tfSymesToAdd(tfSymes(tf)))abNew(AB_Add, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty ),tfSymesToAdd(((tf)->symes))); |
| 1607 | break; |
| 1608 | case TF_Assign: |
| 1609 | ab = abNewAssign(sposNone,abNew(AB_Assign, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg(tf, 1), pretty)) |
| 1610 | tfDisownExpr(tfAssignDecl(tf), pretty),abNew(AB_Assign, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg(tf, 1), pretty)) |
| 1611 | tfDisownExpr(tfAssignVal(tf), pretty))abNew(AB_Assign, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg(tf, 1), pretty)); |
| 1612 | break; |
| 1613 | case TF_Cross: |
| 1614 | ab = abNewEmpty(AB_Apply, tfArgc(tf)((tf)->argc) + 1); |
| 1615 | abApplyOp(ab)((ab)->abApply.op) = abNewId(sposNone, ssymCross)abNew(AB_Id, sposNone,1, ssymCross); |
| 1616 | for (i = 0; i < tfArgc(tf)((tf)->argc); i += 1 ) |
| 1617 | abSetApplyArg(ab, i,((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))) |
| 1618 | tfDisownExpr(tfArgv(tf)[i], pretty))((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))); |
| 1619 | break; |
| 1620 | case TF_Declare: |
| 1621 | syme = tfDeclareSyme(tf); |
| 1622 | if (syme) |
| 1623 | ab = abFrSyme(syme); |
| 1624 | else |
| 1625 | ab = abNewNothing(sposNone)abNew(AB_Nothing, sposNone,0 ); |
| 1626 | ab = abNewDeclare(sposNone, ab,abNew(AB_Declare, sposNone,2, ab,tfDisownExpr(tfFollowArg(tf, 0), pretty)) |
| 1627 | tfDisownExpr(tfDeclareType(tf), pretty))abNew(AB_Declare, sposNone,2, ab,tfDisownExpr(tfFollowArg(tf, 0), pretty)); |
| 1628 | break; |
| 1629 | case TF_Define: |
| 1630 | ab = abNewDefine(sposNone,abNew(AB_Define, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg(tf, 1), pretty)) |
| 1631 | tfDisownExpr(tfDefineDecl(tf), pretty),abNew(AB_Define, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg(tf, 1), pretty)) |
| 1632 | tfDisownExpr(tfDefineVal(tf), pretty))abNew(AB_Define, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg(tf, 1), pretty)); |
| 1633 | break; |
| 1634 | case TF_Enumerate: |
| 1635 | ab = abNewEmpty(AB_Apply, tfArgc(tf)((tf)->argc) + 1); |
| 1636 | abApplyOp(ab)((ab)->abApply.op) = abNewId(sposNone, ssymEnum)abNew(AB_Id, sposNone,1, ssymEnum); |
| 1637 | for (i = 0; i < tfArgc(tf)((tf)->argc); i += 1 ) |
| 1638 | abSetApplyArg(ab, i,((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))) |
| 1639 | tfDisownExpr(tfArgv(tf)[i], pretty))((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))); |
| 1640 | break; |
| 1641 | case TF_Generator: |
| 1642 | ab = abNewApply1(sposNone, abNewId(sposNone, ssymGenerator),abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymGenerator ),tfDisownExpr(tfFollowArg(tf, 0), pretty)) |
| 1643 | tfDisownExpr(tfGeneratorArg(tf), pretty))abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymGenerator ),tfDisownExpr(tfFollowArg(tf, 0), pretty)); |
| 1644 | break; |
| 1645 | case TF_If: |
| 1646 | ab = abNewIf(sposNone,abNew(AB_If, sposNone,3, tfDisownExpr(tfFollowArg(tf, 0), pretty ),tfDisownExpr(tfFollowArg(tf, 1), pretty),tfDisownExpr(tfFollowArg (tf, 2), pretty)) |
| 1647 | tfDisownExpr(tfIfTest(tf), pretty),abNew(AB_If, sposNone,3, tfDisownExpr(tfFollowArg(tf, 0), pretty ),tfDisownExpr(tfFollowArg(tf, 1), pretty),tfDisownExpr(tfFollowArg (tf, 2), pretty)) |
| 1648 | tfDisownExpr(tfIfThen(tf), pretty),abNew(AB_If, sposNone,3, tfDisownExpr(tfFollowArg(tf, 0), pretty ),tfDisownExpr(tfFollowArg(tf, 1), pretty),tfDisownExpr(tfFollowArg (tf, 2), pretty)) |
| 1649 | tfDisownExpr(tfIfElse(tf), pretty))abNew(AB_If, sposNone,3, tfDisownExpr(tfFollowArg(tf, 0), pretty ),tfDisownExpr(tfFollowArg(tf, 1), pretty),tfDisownExpr(tfFollowArg (tf, 2), pretty)); |
| 1650 | break; |
| 1651 | case TF_Join: |
| 1652 | ab = abNewEmpty(AB_Apply, tfArgc(tf)((tf)->argc) + 1); |
| 1653 | abApplyOp(ab)((ab)->abApply.op) = abNewId(sposNone, ssymJoin)abNew(AB_Id, sposNone,1, ssymJoin); |
| 1654 | for (i = 0; i < tfArgc(tf)((tf)->argc); i += 1 ) |
| 1655 | abSetApplyArg(ab, i,((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))) |
| 1656 | tfDisownExpr(tfArgv(tf)[i], pretty))((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))); |
| 1657 | break; |
| 1658 | case TF_Map: |
| 1659 | ab = abNewApply2(sposNone, abNewId(sposNone, ssymArrow),abNew(AB_Apply, sposNone,3, abNew(AB_Id, sposNone,1, ssymArrow ),tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg (tf, 1), pretty)) |
| 1660 | tfDisownExpr(tfMapArg(tf), pretty),abNew(AB_Apply, sposNone,3, abNew(AB_Id, sposNone,1, ssymArrow ),tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg (tf, 1), pretty)) |
| 1661 | tfDisownExpr(tfMapRet(tf), pretty))abNew(AB_Apply, sposNone,3, abNew(AB_Id, sposNone,1, ssymArrow ),tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg (tf, 1), pretty)); |
| 1662 | break; |
| 1663 | case TF_Meet: |
| 1664 | ab = abNewEmpty(AB_Apply, tfArgc(tf)((tf)->argc) + 1); |
| 1665 | abApplyOp(ab)((ab)->abApply.op) = abNewId(sposNone, ssymMeet)abNew(AB_Id, sposNone,1, ssymMeet); |
| 1666 | for (i = 0; i < tfArgc(tf)((tf)->argc); i += 1 ) |
| 1667 | abSetApplyArg(ab, i,((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))) |
| 1668 | tfDisownExpr(tfArgv(tf)[i], pretty))((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))); |
| 1669 | break; |
| 1670 | case TF_Multiple: |
| 1671 | ab = abNewEmpty(AB_Comma, tfArgc(tf)((tf)->argc)); |
| 1672 | for (i = 0; i < tfArgc(tf)((tf)->argc); i += 1 ) |
| 1673 | abArgv(ab)((ab)->abGen.data.argv)[i] = tfDisownExpr(tfArgv(tf)((tf)->argv)[i], pretty); |
| 1674 | break; |
| 1675 | case TF_PackedMap: |
| 1676 | ab = abNewApply2(sposNone, abNewId(sposNone, ssymPackedArrow),abNew(AB_Apply, sposNone,3, abNew(AB_Id, sposNone,1, ssymPackedArrow ),tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg (tf, 1), pretty)) |
| 1677 | tfDisownExpr(tfMapArg(tf), pretty),abNew(AB_Apply, sposNone,3, abNew(AB_Id, sposNone,1, ssymPackedArrow ),tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg (tf, 1), pretty)) |
| 1678 | tfDisownExpr(tfMapRet(tf), pretty))abNew(AB_Apply, sposNone,3, abNew(AB_Id, sposNone,1, ssymPackedArrow ),tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg (tf, 1), pretty)); |
| 1679 | break; |
| 1680 | case TF_Raw: |
| 1681 | ab = abNewApply1(sposNone, abNewId(sposNone, ssymRaw),abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymRaw) ,tfDisownExpr(tfFollowArg(tf, 0), pretty)) |
| 1682 | tfDisownExpr(tfRawArg(tf), pretty))abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymRaw) ,tfDisownExpr(tfFollowArg(tf, 0), pretty)); |
| 1683 | break; |
| 1684 | case TF_RawRecord: |
| 1685 | ab = abNewEmpty(AB_Apply, tfArgc(tf)((tf)->argc) + 1); |
| 1686 | abApplyOp(ab)((ab)->abApply.op) = abNewId(sposNone, ssymRawRecord)abNew(AB_Id, sposNone,1, ssymRawRecord); |
| 1687 | for (i = 0; i < tfArgc(tf)((tf)->argc); i += 1 ) |
| 1688 | abSetApplyArg(ab, i,((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))) |
| 1689 | tfDisownExpr(tfArgv(tf)[i], pretty))((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))); |
| 1690 | break; |
| 1691 | case TF_Record: |
| 1692 | ab = abNewEmpty(AB_Apply, tfArgc(tf)((tf)->argc) + 1); |
| 1693 | abApplyOp(ab)((ab)->abApply.op) = abNewId(sposNone, ssymRecord)abNew(AB_Id, sposNone,1, ssymRecord); |
| 1694 | for (i = 0; i < tfArgc(tf)((tf)->argc); i += 1 ) |
| 1695 | abSetApplyArg(ab, i,((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))) |
| 1696 | tfDisownExpr(tfArgv(tf)[i], pretty))((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))); |
| 1697 | break; |
| 1698 | case TF_Reference: |
| 1699 | ab = abNewApply1(sposNone, abNewId(sposNone, ssymReference),abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymReference ),tfDisownExpr(tfFollowArg(tf, 0), pretty)) |
| 1700 | tfDisownExpr(tfReferenceArg(tf), pretty))abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymReference ),tfDisownExpr(tfFollowArg(tf, 0), pretty)); |
| 1701 | break; |
| 1702 | case TF_TrailingArray: |
| 1703 | ab = abNewApply2(sposNone, abNewId(sposNone, ssymTrailingArray),abNew(AB_Apply, sposNone,3, abNew(AB_Id, sposNone,1, ssymTrailingArray ),tfDisownExpr(((tf)->argv)[0], pretty),tfDisownExpr(((tf) ->argv)[1], pretty)) |
| 1704 | tfDisownExpr(tfArgv(tf)[0], pretty),abNew(AB_Apply, sposNone,3, abNew(AB_Id, sposNone,1, ssymTrailingArray ),tfDisownExpr(((tf)->argv)[0], pretty),tfDisownExpr(((tf) ->argv)[1], pretty)) |
| 1705 | tfDisownExpr(tfArgv(tf)[1], pretty))abNew(AB_Apply, sposNone,3, abNew(AB_Id, sposNone,1, ssymTrailingArray ),tfDisownExpr(((tf)->argv)[0], pretty),tfDisownExpr(((tf) ->argv)[1], pretty)); |
| 1706 | break; |
| 1707 | case TF_Third: |
| 1708 | ab = tfDisownExpr(tfThirdRestrictions(tf)tfFollowArg(tf, 0), pretty); |
| 1709 | if (pretty) |
| 1710 | ab = abNewDefine(sposNone,abNew(AB_Define, sposNone,2, abNew(AB_Id, sposNone,1, ssymCategory ),ab) |
| 1711 | abNewId(sposNone, ssymCategory), ab)abNew(AB_Define, sposNone,2, abNew(AB_Id, sposNone,1, ssymCategory ),ab); |
| 1712 | else |
| 1713 | ab = abNewApply1(sposNone,abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymThird ),ab) |
| 1714 | abNewId(sposNone, ssymThird), ab)abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymThird ),ab); |
| 1715 | break; |
| 1716 | case TF_Tuple: |
| 1717 | ab = abNewApply1(sposNone, abNewId(sposNone, ssymTuple),abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymTuple ),tfDisownExpr(tfFollowArg(tf, 0), pretty)) |
| 1718 | tfDisownExpr(tfTupleArg(tf), pretty))abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymTuple ),tfDisownExpr(tfFollowArg(tf, 0), pretty)); |
| 1719 | break; |
| 1720 | case TF_Union: |
| 1721 | ab = abNewEmpty(AB_Apply, tfArgc(tf)((tf)->argc) + 1); |
| 1722 | abApplyOp(ab)((ab)->abApply.op) = abNewId(sposNone, ssymUnion)abNew(AB_Id, sposNone,1, ssymUnion); |
| 1723 | for (i = 0; i < tfArgc(tf)((tf)->argc); i += 1 ) |
| 1724 | abSetApplyArg(ab, i,((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))) |
| 1725 | tfDisownExpr(tfArgv(tf)[i], pretty))((ab)->abApply.argv[i] = (tfDisownExpr(((tf)->argv)[i], pretty))); |
| 1726 | break; |
| 1727 | case TF_Variable: |
| 1728 | ab = abNewBlank(sposNone, ssymVariable)abNew(AB_Blank, sposNone,1, ssymVariable); |
| 1729 | break; |
| 1730 | case TF_With: { |
| 1731 | AbSyn abbase, abwith; |
| 1732 | |
| 1733 | if (tfIsNone(tfWithBase(tf))((((tfFollowArg(tf, 0))->tag) == TF_Multiple) && tfMultiArgc (tfFollowArg(tf, 0)) == 0)) |
| 1734 | abbase = abNewNothing(sposNone)abNew(AB_Nothing, sposNone,0 ); |
| 1735 | else |
| 1736 | abbase = tfDisownExpr(tfWithBase(tf)tfFollowArg(tf, 0), pretty); |
| 1737 | |
| 1738 | if (pretty && tfUseCatExports(tf)(((((tfFollowArg(tf, 0))->tag) == TF_Multiple) && tfMultiArgc (tfFollowArg(tf, 0)) == 0) && ((((tfFollowArg(tf, 1)) ->tag) == TF_Multiple) && tfMultiArgc(tfFollowArg( tf, 1)) == 0))) |
| 1739 | abwith = tfSymesToWith(tfGetCatExports(tf)); |
| 1740 | else if (tfIsNone(tfWithWithin(tf))((((tfFollowArg(tf, 1))->tag) == TF_Multiple) && tfMultiArgc (tfFollowArg(tf, 1)) == 0)) |
| 1741 | abwith = abNewNothing(sposNone)abNew(AB_Nothing, sposNone,0 ); |
| 1742 | else |
| 1743 | abwith = tfDisownExpr(tfWithWithin(tf)tfFollowArg(tf, 1), pretty); |
| 1744 | |
| 1745 | ab = abNewWith(sposNone, abbase, abwith)abNew(AB_With, sposNone,2, abbase,abwith); |
| 1746 | break; |
| 1747 | } |
| 1748 | case TF_XGenerator: |
| 1749 | ab = abNewApply1(sposNone, abNewId(sposNone, ssymXGenerator),abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymXGenerator ),tfDisownExpr(tfFollowArg(tf, 0), pretty)) |
| 1750 | tfDisownExpr(tfGeneratorArg(tf), pretty))abNew(AB_Apply, sposNone,2, abNew(AB_Id, sposNone,1, ssymXGenerator ),tfDisownExpr(tfFollowArg(tf, 0), pretty)); |
| 1751 | break; |
| 1752 | case TF_Except: |
| 1753 | ab = abNewExcept(sposNone,abNew(AB_Except, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg(tf, 1), pretty)) |
| 1754 | tfDisownExpr(tfExceptType(tf), pretty),abNew(AB_Except, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg(tf, 1), pretty)) |
| 1755 | tfDisownExpr(tfExceptExcept(tf), pretty))abNew(AB_Except, sposNone,2, tfDisownExpr(tfFollowArg(tf, 0), pretty),tfDisownExpr(tfFollowArg(tf, 1), pretty)); |
| 1756 | break; |
| 1757 | |
| 1758 | default: |
| 1759 | bugBadCase(tfTag(tf))bug("Bad case %d (line %d in file %s).", (int) ((tf)->tag) , 1759, "tform.c"); |
| 1760 | NotReached(ab = abNewNothing(sposNone)){(void)bug("Not supposed to reach line %d in file: %s\n",1760 , "tform.c");}; |
| 1761 | } |
| 1762 | |
| 1763 | if (DEBUG(tfExpr)tfExprDebug) { |
| 1764 | fprintf(dbOut, "tfToAbSyn <- "); |
| 1765 | abPrettyPrintClippedIn(dbOut, ab, 65, 1); |
| 1766 | fnewline(dbOut); |
| 1767 | } |
| 1768 | |
| 1769 | if (!pretty) { |
| 1770 | tfSetExpr(tf, ab); |
| 1771 | tfOwnExpr(tf); |
| 1772 | } |
| 1773 | return ab; |
| 1774 | } |
| 1775 | |
| 1776 | /****************************************************************************** |
| 1777 | * |
| 1778 | * :: Type form syntax. |
| 1779 | * |
| 1780 | *****************************************************************************/ |
| 1781 | |
| 1782 | localstatic void |
| 1783 | tfSetExpr(TForm tf, AbSyn ab) |
| 1784 | { |
| 1785 | if (!tfHasExpr(tf)((tf)->__absyn != 0)) |
| 1786 | tf->__absyn = ab; |
| 1787 | |
| 1788 | if (!abTForm(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->tform : 0)) |
| 1789 | abSetTForm(ab, tf); |
| 1790 | |
| 1791 | return; |
| 1792 | } |
| 1793 | |
| 1794 | localstatic Bool |
| 1795 | tfOwnsExpr(TForm tf) |
| 1796 | { |
| 1797 | return tf->ownSyntax; |
| 1798 | } |
| 1799 | |
| 1800 | /* |
| 1801 | * tfOwnExpr assumes that tfExpr(tf) was just constructed |
| 1802 | * from newly created abstract syntax nodes. |
| 1803 | */ |
| 1804 | void |
| 1805 | tfOwnExpr(TForm tf) |
| 1806 | { |
| 1807 | tf->ownSyntax = true1; |
| 1808 | return; |
| 1809 | } |
| 1810 | |
| 1811 | /* Release any ownership interest that tf has in ab. */ |
| 1812 | void |
| 1813 | tfReleaseExpr(TForm tf, AbSyn ab) |
| 1814 | { |
| 1815 | if (tf->__absyn == ab) { |
| 1816 | tf->__absyn = 0; |
| 1817 | tf->ownSyntax = false((int) 0); |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | /* |
| 1822 | * Return an abstract syntax tree which the caller |
| 1823 | * is allowed/required to free. |
| 1824 | */ |
| 1825 | localstatic AbSyn |
| 1826 | tfDisownExpr(TForm tf, Bool pretty) |
| 1827 | { |
| 1828 | AbSyn ab = tfToAbSyn0(tf, pretty); |
| 1829 | |
| 1830 | if (DEBUG(tfExpr)tfExprDebug) { |
| 1831 | fprintf(dbOut, "tfDisownExpr -> "); |
| 1832 | tfPrint(dbOut, tf); |
| 1833 | fnewline(dbOut); |
| 1834 | abPrettyPrintClippedIn(dbOut, ab, 65, 1); |
| 1835 | fnewline(dbOut); |
| 1836 | } |
| 1837 | |
| 1838 | if (!pretty) { |
| 1839 | if (!tfOwnsExpr(tf)) ab = sefoCopy(ab); |
| 1840 | tf->ownSyntax = false((int) 0); |
| 1841 | } |
| 1842 | return ab; |
| 1843 | } |
| 1844 | |
| 1845 | /* Transfer the type form semantics from ntf to tf. */ |
| 1846 | void |
| 1847 | tfTransferSemantics(TForm ntf, TForm tf) |
| 1848 | { |
| 1849 | if (!abIsSefo(tfGetExpr(tf))(((((tf)->__absyn))->abHdr.state) == AB_State_HasUnique ) && |
| 1850 | abIsSefo(tfGetExpr(ntf))(((((ntf)->__absyn))->abHdr.state) == AB_State_HasUnique ) && !tfIsUnknown(tfTUnique(ntf))(((((((ntf)->__absyn))->abHdr.type.unique))->tag) == TF_Unknown)) { |
| 1851 | abTransferSemantics(tfGetExpr(ntf)((ntf)->__absyn), tfGetExpr(tf)((tf)->__absyn)); |
| 1852 | tfCopyState(tf, ntf)(((tf)->state) = ((ntf)->state)); |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | /****************************************************************************** |
| 1857 | * |
| 1858 | * :: Type form construction path. |
| 1859 | * |
| 1860 | *****************************************************************************/ |
| 1861 | |
| 1862 | /* |
| 1863 | * Create a syntactic tform. |
| 1864 | */ |
| 1865 | TForm |
| 1866 | tfSyntaxFrAbSyn(Stab stab, AbSyn ab) |
| 1867 | { |
| 1868 | Stab nstab = (abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0) ? abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0) : stab); |
| 1869 | TForm tf, tfret; |
| 1870 | |
| 1871 | if ((tf = abTForm(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->tform : 0)) != NULL((void*)0)) |
| 1872 | return tf; |
| 1873 | |
| 1874 | if (abIsTheId(ab, ssymCategory)(((ab)->abHdr.tag == (AB_Id)) && ((ab)->abId.sym )==(ssymCategory))) |
| 1875 | return tfCategory; |
| 1876 | |
| 1877 | if (abIsId(ab)((ab)->abHdr.tag == (AB_Id)) && abSyme(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->syme : 0) && symeIsParam(abSyme(ab))(((((((ab)->abHdr.seman ? (ab)->abHdr.seman->syme : 0 ))->kind == SYME_Trigger ? libGetAllSymes((((ab)->abHdr .seman ? (ab)->abHdr.seman->syme : 0))->lib) : ((void *)0)), (((ab)->abHdr.seman ? (ab)->abHdr.seman->syme : 0)))->kind) == SYME_Param)) { |
| 1878 | Stab rstab = stabFindLevel(stab, abSyme(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->syme : 0)); |
| 1879 | stab = rstab; |
| 1880 | |
| 1881 | } |
| 1882 | if ((tf = stabGetTForm(stab, ab, NULL((void*)0))) != NULL((void*)0)) |
| 1883 | return tf; |
| 1884 | |
| 1885 | if (abIsAnyMap(ab)(((((ab)->abHdr.tag == (AB_Apply)) && (((((ab)-> abApply.op))->abHdr.tag == (AB_Id)) && ((((ab)-> abApply.op))->abId.sym)==(ssymArrow))) && (((ab)-> abHdr.argc)-1) == 2) || ((((ab)->abHdr.tag == (AB_Apply)) && (((((ab)->abApply.op))->abHdr.tag == (AB_Id)) && ((((ab)->abApply.op))->abId.sym)==(ssymPackedArrow))) && (((ab)->abHdr.argc)-1) == 2))) { |
| 1886 | tfret = tfSyntaxFrAbSyn(nstab, abMapRet(ab)((ab)->abApply.argv[1])); |
| 1887 | tf = tfSyntaxMap(nstab, ab, tfret); |
| 1888 | } |
| 1889 | else |
| 1890 | tf = tfNewSyntax(ab); |
| 1891 | |
| 1892 | stabDefTForm(stab, tf); |
| 1893 | |
| 1894 | return tf; |
| 1895 | } |
| 1896 | |
| 1897 | /* |
| 1898 | * Create a map type form with syntactic parts. |
| 1899 | */ |
| 1900 | TForm |
| 1901 | tfSyntaxMap(Stab stab, AbSyn map, TForm tfret) |
| 1902 | { |
| 1903 | AbSyn ab, abarg = abMapArg(map)((map)->abApply.argv[0]); |
| 1904 | Length i, argc = abArgc(abarg)((abarg)->abHdr.argc); |
| 1905 | TForm tf, tfarg; |
| 1906 | |
| 1907 | if (abTag(abarg)((abarg)->abHdr.tag) == AB_Comma && argc != 1) { |
| 1908 | tfarg = tfNewEmpty(TF_Multiple, argc); |
| 1909 | for (i = 0; i < argc; i += 1) |
| 1910 | tfArgv(tfarg)((tfarg)->argv)[i] = |
| 1911 | tfSyntaxFrAbSyn(stab, abArgv(abarg)((abarg)->abGen.data.argv)[i]); |
| 1912 | abSetPos(tfExpr(tfarg), abPos(abarg))((tfToAbSyn(tfarg))->abHdr.pos=spstackSetFirst ((tfToAbSyn (tfarg))->abHdr.pos,((spstackFirst((abarg)->abHdr.pos)) ))); |
| 1913 | } |
| 1914 | else |
| 1915 | tfarg = tfSyntaxFrAbSyn(stab, abarg); |
| 1916 | |
| 1917 | tf = tfAnyMap(tfarg, tfret, abIsPackedMap(map)((((map)->abHdr.tag == (AB_Apply)) && (((((map)-> abApply.op))->abHdr.tag == (AB_Id)) && ((((map)-> abApply.op))->abId.sym)==(ssymPackedArrow))) && (( (map)->abHdr.argc)-1) == 2)); |
| 1918 | ab = tfExpr(tf)tfToAbSyn(tf); |
| 1919 | |
| 1920 | tfSetPending(tf)(((tf)->state)=TF_State_Pending); |
| 1921 | abSetTForm(map, tf); |
| 1922 | abTransferSemantics(map, ab); |
| 1923 | |
| 1924 | abSetPos(ab, abPos(map))((ab)->abHdr.pos=spstackSetFirst ((ab)->abHdr.pos,((spstackFirst ((map)->abHdr.pos))))); |
| 1925 | abSetPos(abApplyOp(ab), abPos(abApplyOp(map)))((((ab)->abApply.op))->abHdr.pos=spstackSetFirst ((((ab )->abApply.op))->abHdr.pos,((spstackFirst((((map)->abApply .op))->abHdr.pos))))); |
| 1926 | |
| 1927 | return tf; |
| 1928 | } |
| 1929 | |
| 1930 | void |
| 1931 | tfSyntaxConditions(Stab stab, TForm tf, TfCondElt conditions) |
| 1932 | { |
| 1933 | int i; |
| 1934 | if (DEBUG(tf)tfDebug) { |
| 1935 | if (conditions != NULL((void*)0)) |
| 1936 | afprintf(dbOut, "Adding Condition: %pTForm - %pAbSynList %d\n", |
| 1937 | tf, conditions->list, |
| 1938 | tfIsSyntax(tf)(((tf)->tag) == TF_Syntax) || tfIsMap(tf)(((tf)->tag) == TF_Map) || tfIsEmptyMulti(tf)((((tf)->tag) == TF_Multiple) && tfMultiArgc(tf) == 0) || tfIsWith(tf)(((tf)->tag) == TF_With)); |
| 1939 | } |
| 1940 | |
| 1941 | if (!tfIsMeaning(tf)(((tf)->state)>=TF_State_Meaning)) |
| 1942 | tfMergeConditions(tf, stab, conditions); |
| 1943 | |
| 1944 | for (i=0; i<tfArgc(tf)((tf)->argc); i++) { |
| 1945 | tfSyntaxConditions(stab, tfArgv(tf)((tf)->argv)[i], conditions); |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | |
| 1950 | /* |
| 1951 | * Create a define type form with syntactic parts. |
| 1952 | */ |
| 1953 | TForm |
| 1954 | tfSyntaxDefine(Stab stab, AbSyn lhs, AbSyn rhs) |
| 1955 | { |
| 1956 | TForm tf, tflhs, tfrhs; |
| 1957 | AbSyn ab; |
| 1958 | |
| 1959 | if (abHasTag(rhs, AB_Label)((rhs)->abHdr.tag == (AB_Label))) |
| 1960 | rhs = rhs->abLabel.expr; |
| 1961 | |
| 1962 | tflhs = tfNewNode(TF_Declare, 1, tfNewSyntax(lhs)); |
| 1963 | tfrhs = tfNewSyntax(rhs); |
| 1964 | tf = tfNewNode(TF_Define, 2, tflhs, tfrhs); |
| 1965 | |
| 1966 | ab = tfExpr(tf)tfToAbSyn(tf); |
| 1967 | |
| 1968 | abTransferSemantics(lhs, ab->abDefine.lhs); |
| 1969 | abTransferSemantics(rhs, ab->abDefine.rhs); |
| 1970 | |
| 1971 | tfSetPending(tf)(((tf)->state)=TF_State_Pending); |
| 1972 | abSetTForm(lhs, tf); |
| 1973 | |
| 1974 | stabDefTForm(stab, tf); |
| 1975 | |
| 1976 | return tf; |
| 1977 | } |
| 1978 | |
| 1979 | TForm |
| 1980 | tfSyntaxDefineMap(Stab stab, AbSyn ab, AbSyn rhs) |
| 1981 | { |
| 1982 | Stab nstab = (abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0) ? abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0) : stab); |
| 1983 | TForm tf, tfret; |
| 1984 | |
| 1985 | assert(abIsAnyLambda(rhs))do { if (!((((rhs)->abHdr.tag == (AB_Lambda)) || ((rhs)-> abHdr.tag == (AB_PLambda))))) _do_assert(("abIsAnyLambda(rhs)" ),"tform.c",1985); } while (0); |
| 1986 | |
| 1987 | tfret = tfSyntaxDefine(nstab, abMapRet(ab)((ab)->abApply.argv[1]), rhs->abLambda.body); |
| 1988 | tf = tfSyntaxMap(nstab, ab, tfret); |
| 1989 | |
| 1990 | stabDefTForm(stab, tf); |
| 1991 | |
| 1992 | return tf; |
| 1993 | } |
| 1994 | |
| 1995 | /* |
| 1996 | * Create a template type form for an extension. |
| 1997 | */ |
| 1998 | TForm |
| 1999 | tfSyntaxExtend(Stab stab, AbSyn id, AbSyn type) |
| 2000 | { |
| 2001 | Stab nstab = (abStab(type)((type)->abHdr.seman ? (type)->abHdr.seman->stab : 0 ) ? abStab(type)((type)->abHdr.seman ? (type)->abHdr.seman->stab : 0 ) : stab); |
| 2002 | TForm tf; |
| 2003 | |
| 2004 | if (abIsAnyMap(type)(((((type)->abHdr.tag == (AB_Apply)) && (((((type) ->abApply.op))->abHdr.tag == (AB_Id)) && ((((type )->abApply.op))->abId.sym)==(ssymArrow))) && (( (type)->abHdr.argc)-1) == 2) || ((((type)->abHdr.tag == (AB_Apply)) && (((((type)->abApply.op))->abHdr .tag == (AB_Id)) && ((((type)->abApply.op))->abId .sym)==(ssymPackedArrow))) && (((type)->abHdr.argc )-1) == 2))) { |
| 2005 | tf = tfSyntaxExtendMap(nstab, type, tfUnknown); |
| 2006 | tfSetStab(tf, nstab)((tf)->stab = (nstab)); |
| 2007 | } |
| 2008 | else |
| 2009 | tf = tfUnknown; |
| 2010 | |
| 2011 | return tfDeclare(id, tf); |
| 2012 | } |
| 2013 | |
| 2014 | TForm |
| 2015 | tfSyntaxExtendMap(Stab stab, AbSyn map, TForm tfret) |
| 2016 | { |
| 2017 | AbSyn abarg = abMapArg(map)((map)->abApply.argv[0]); |
| 2018 | Length i, argc = abArgc(abarg)((abarg)->abHdr.argc); |
| 2019 | TForm tfarg; |
| 2020 | |
| 2021 | if (abTag(abarg)((abarg)->abHdr.tag) == AB_Comma && argc != 1) { |
| 2022 | tfarg = tfNewEmpty(TF_Multiple, argc); |
| 2023 | for (i = 0; i < argc; i += 1) { |
| 2024 | AbSyn id = abDefineeId(abarg->abComma.argv[i]); |
| 2025 | tfArgv(tfarg)((tfarg)->argv)[i] = tfDeclare(id, tfUnknown); |
| 2026 | } |
| 2027 | } |
| 2028 | else { |
| 2029 | AbSyn id = abDefineeId(abarg); |
| 2030 | tfarg = tfDeclare(id, tfUnknown); |
| 2031 | } |
| 2032 | |
| 2033 | return tfAnyMap(tfarg, tfret, abIsPackedMap(map)((((map)->abHdr.tag == (AB_Apply)) && (((((map)-> abApply.op))->abHdr.tag == (AB_Id)) && ((((map)-> abApply.op))->abId.sym)==(ssymPackedArrow))) && (( (map)->abHdr.argc)-1) == 2)); |
| 2034 | } |
| 2035 | |
| 2036 | /* |
| 2037 | * Create non-forwarding tform from type analysed abstract syntax. |
| 2038 | */ |
| 2039 | TForm |
| 2040 | tfFullFrAbSyn(Stab stab, Sefo sefo) |
| 2041 | { |
| 2042 | TForm tf; |
| 2043 | |
| 2044 | if ((tf = abTForm(sefo)((sefo)->abHdr.seman ? (sefo)->abHdr.seman->tform : 0 )) != NULL((void*)0)) |
| 2045 | return tfMeaningFrSyntax(stab, sefo, tf); |
| 2046 | |
| 2047 | else if ((tf = stabGetTForm(stab, sefo, NULL((void*)0))) != NULL((void*)0)) |
| 2048 | return tfMeaningFrSyntax(stab, sefo, tf); |
| 2049 | |
| 2050 | if (abStab(sefo)((sefo)->abHdr.seman ? (sefo)->abHdr.seman->stab : 0 )) |
| 2051 | stab = abStab(sefo)((sefo)->abHdr.seman ? (sefo)->abHdr.seman->stab : 0 ); |
| 2052 | |
| 2053 | tf = tfMeaning(stab, sefo, tfPending(stab, sefo)); |
| 2054 | stabDefTForm(stab, tf); |
| 2055 | |
| 2056 | return tf; |
| 2057 | } |
| 2058 | |
| 2059 | /* |
| 2060 | * Create a forwarding tform from a syntax tform. |
| 2061 | * The new tform may be a full tform or a pending tform. |
| 2062 | */ |
| 2063 | TForm |
| 2064 | tfForwardFrSyntax(TForm otf, TForm ntf) |
| 2065 | { |
| 2066 | if (!tfIsSyntax(otf)(((otf)->tag) == TF_Syntax)) return otf; |
| 2067 | assert(otf != ntf)do { if (!(otf != ntf)) _do_assert(("otf != ntf"),"tform.c",2067 ); } while (0); |
| 2068 | assert(!tfIsForward(ntf))do { if (!(!(((ntf)->tag) == TF_Forward))) _do_assert(("!tfIsForward(ntf)" ),"tform.c",2068); } while (0); |
| 2069 | |
| 2070 | otf->tag = TF_Forward; |
| 2071 | otf->argc = 1; |
| 2072 | otf->argv[0] = ntf; |
| 2073 | |
| 2074 | tfCopyQueries (ntf, otf); /* queries (ntf) := queries (otf) */ |
| 2075 | tfCopyState (otf, ntf)(((otf)->state) = ((ntf)->state)); /* state (otf) := state (ntf) */ |
| 2076 | tfCopySelf (ntf, otf); /* self (ntf) := self (otf) */ |
| 2077 | tcMove (ntf, otf); /* const (ntf) := const (otf) */ |
| 2078 | |
| 2079 | return otf; |
| 2080 | } |
| 2081 | |
| 2082 | /* |
| 2083 | * Create a pending tform from a syntax tform. |
| 2084 | */ |
| 2085 | TForm |
| 2086 | tfPendingFrSyntax(Stab stab, AbSyn ab, TForm tf) |
| 2087 | { |
| 2088 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 2089 | |
| 2090 | if (tfIsSyntax(tf)(((tf)->tag) == TF_Syntax)) { |
| 2091 | TForm tfp = tfPending(stab, ab); |
| 2092 | /* This test is probably too weak */ |
| 2093 | if (!tfIsId(tfp)((((tfp)->tag) == TF_General) && ((((tfp)->__absyn ))->abHdr.tag) == AB_Id)) |
| 2094 | tfSetConditions(tfFollowOnly(tfp), tfConditions(tf))(tfFollowOnly(tfp)->conditions = (tfConditions(tf))); |
| 2095 | tfForwardFrSyntax(tf, tfFollowOnly(tfp)); |
| 2096 | } |
| 2097 | else if (tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap ))) { |
| 2098 | assert(abIsAnyMap(ab))do { if (!((((((ab)->abHdr.tag == (AB_Apply)) && ( ((((ab)->abApply.op))->abHdr.tag == (AB_Id)) && ((((ab)->abApply.op))->abId.sym)==(ssymArrow))) && (((ab)->abHdr.argc)-1) == 2) || ((((ab)->abHdr.tag == ( AB_Apply)) && (((((ab)->abApply.op))->abHdr.tag == (AB_Id)) && ((((ab)->abApply.op))->abId.sym )==(ssymPackedArrow))) && (((ab)->abHdr.argc)-1) == 2)))) _do_assert(("abIsAnyMap(ab)"),"tform.c",2098); } while (0); |
| 2099 | tfPendingFrSyntaxMap(stab, ab, tf); |
| 2100 | } |
| 2101 | |
| 2102 | else if (tfIsDefine(tf)(((tf)->tag) == TF_Define) && abHasTag(ab, AB_Define)((ab)->abHdr.tag == (AB_Define))) |
| 2103 | tfPendingFrSyntaxDefine(stab, ab, tf); |
| 2104 | |
| 2105 | return tf; |
| 2106 | } |
| 2107 | |
| 2108 | localstatic void |
| 2109 | tfPendingFrSyntaxMap(Stab stab, AbSyn ab, TForm tf) |
| 2110 | { |
| 2111 | AbSyn abarg = abMapArg(ab)((ab)->abApply.argv[0]); |
| 2112 | AbSyn abret = abMapRet(ab)((ab)->abApply.argv[1]); |
| 2113 | TForm tfarg = tfMapArg(tf)tfFollowArg(tf, 0); |
| 2114 | TForm tfret = tfMapRet(tf)tfFollowArg(tf, 1); |
| 2115 | Length i; |
| 2116 | |
| 2117 | if (tfIsMulti(tfarg)(((tfarg)->tag) == TF_Multiple)) |
| 2118 | for (i = 0; i < tfArgc(tfarg)((tfarg)->argc); i += 1) { |
| 2119 | TForm tfi = tfFollowArg(tfarg, i); |
| 2120 | AbSyn abi = abArgv(abarg)((abarg)->abGen.data.argv)[i]; |
| 2121 | tfPendingFrSyntax(stab, abi, tfi); |
| 2122 | } |
| 2123 | |
| 2124 | if (abTag(abarg)((abarg)->abHdr.tag) == AB_Comma && abArgc(abarg)((abarg)->abHdr.argc) == 1) |
| 2125 | abarg = abArgv(abarg)((abarg)->abGen.data.argv)[0]; |
| 2126 | |
| 2127 | tfPendingFrSyntax(stab, abarg, tfarg); |
| 2128 | tfPendingFrSyntax(stab, abret, tfret); |
| 2129 | } |
| 2130 | |
| 2131 | localstatic void |
| 2132 | tfPendingFrSyntaxDefine(Stab stab, AbSyn ab, TForm tf) |
| 2133 | { |
| 2134 | AbSyn abdec = abDefineDecl(ab)((ab)->abDefine.lhs); |
| 2135 | AbSyn abval = abDefineVal(ab)((ab)->abDefine.rhs); |
| 2136 | TForm tfdec = tfDefineDecl(tf)tfFollowArg(tf, 0); |
| 2137 | TForm tfval = tfDefineVal(tf)tfFollowArg(tf, 1); |
| 2138 | |
| 2139 | tfPendingFrSyntax(stab, abdec, tfdec); |
| 2140 | tfPendingFrSyntax(stab, abval, tfval); |
| 2141 | } |
| 2142 | |
| 2143 | /* |
| 2144 | * Create a meaningful tform from a syntax tform. |
| 2145 | */ |
| 2146 | TForm |
| 2147 | tfMeaningFrSyntax(Stab stab, Sefo sefo, TForm tf) |
| 2148 | { |
| 2149 | TForm ntf, stf; |
| 2150 | |
| 2151 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 2152 | |
| 2153 | if (!abIsSefo(sefo)(((sefo)->abHdr.state) == AB_State_HasUnique)) |
| 2154 | return tf; |
| 2155 | |
| 2156 | stf = abTForm(sefo)((sefo)->abHdr.seman ? (sefo)->abHdr.seman->tform : 0 ); |
| 2157 | tfFollow(stf)((stf) = tfFollowFn(stf)); |
| 2158 | |
| 2159 | /* Convert syntax tforms to pending tforms. */ |
| 2160 | if (tfIsSyntax(tf)(((tf)->tag) == TF_Syntax)) |
| 2161 | ntf = tfPending(stab, sefo); |
| 2162 | |
| 2163 | /* Avoid using pending tforms which don't have semantics. */ |
| 2164 | else if (tfIsPending(tf)(((tf)->state)==TF_State_Pending) && !abIsSefo(tfGetExpr(tf))(((((tf)->__absyn))->abHdr.state) == AB_State_HasUnique )) |
| 2165 | ntf = tfPending(stab, sefo); |
| 2166 | |
| 2167 | /* Avoid using tforms with different semantics. */ |
| 2168 | else if (tfIsMeaning(tf)(((tf)->state)>=TF_State_Meaning) && tf != stf && |
| 2169 | !tfMeaningEqual(sefo, tfGetExpr(tf)((tf)->__absyn))) |
| 2170 | ntf = tfPending(stab, sefo); |
| 2171 | |
| 2172 | /* Convert pending tforms to meaningful tforms. */ |
| 2173 | else |
| 2174 | ntf = tf; |
| 2175 | |
| 2176 | ntf = tfMeaning(stab, sefo, ntf); |
| 2177 | |
| 2178 | if (tfIsSyntax(tf)(((tf)->tag) == TF_Syntax)) |
| 2179 | tfForwardFrSyntax(tf, ntf); |
| 2180 | |
| 2181 | return ntf; |
| 2182 | } |
| 2183 | |
| 2184 | /* Quickie version of sefoEqual since we can't use sefoEqual |
| 2185 | * inside tfMeaningFrSyntax. |
| 2186 | */ |
| 2187 | localstatic Bool |
| 2188 | tfMeaningEqual(Sefo sefo1, Sefo sefo2) |
| 2189 | { |
| 2190 | Bool result; |
| 2191 | |
| 2192 | if (sefo1 == sefo2) |
| 2193 | result = true1; |
| 2194 | |
| 2195 | else if (!sefo1 || !sefo2) |
| 2196 | result = false((int) 0); |
| 2197 | |
| 2198 | else if (abTag(sefo1)((sefo1)->abHdr.tag) != abTag(sefo2)((sefo2)->abHdr.tag)) |
| 2199 | result = false((int) 0); |
| 2200 | else if (abIsLeaf(sefo1)(((sefo1)->abHdr.tag) < AB_NODE_START)) |
| 2201 | result = abSyme(sefo1)((sefo1)->abHdr.seman ? (sefo1)->abHdr.seman->syme : 0) == abSyme(sefo2)((sefo2)->abHdr.seman ? (sefo2)->abHdr.seman->syme : 0); |
| 2202 | |
| 2203 | else |
| 2204 | result = false((int) 0); |
| 2205 | |
| 2206 | return result; |
| 2207 | } |
| 2208 | |
| 2209 | /****************************************************************************** |
| 2210 | * |
| 2211 | * :: Type form floating. |
| 2212 | * |
| 2213 | *****************************************************************************/ |
| 2214 | |
| 2215 | /* |
| 2216 | * Float a type form to its natural level. Return 0 if floating |
| 2217 | * not done. |
| 2218 | */ |
| 2219 | Stab |
| 2220 | tfFloat(Stab stab, TForm tf) |
| 2221 | { |
| 2222 | ULong odepth, ndepth; |
| 2223 | TForm outerTf = NULL((void*)0); |
| 2224 | |
| 2225 | if (!tfIsSyntax(tf)(((tf)->tag) == TF_Syntax)) |
| 2226 | return NULL((void*)0); |
| 2227 | |
| 2228 | odepth = stabLevelNo(stab)(((stab)->first)->lexicalLevel); |
| 2229 | ndepth = tfOuterDepth(stab, tf); |
| 2230 | if (ndepth >= odepth) { |
| 2231 | /* No floating needed - clean up conditions */ |
| 2232 | tfFloatConditions(stab, tf); |
| 2233 | return NULL((void*)0); |
| 2234 | } |
| 2235 | while (stabLevelNo(stab)(((stab)->first)->lexicalLevel) > ndepth) { |
| 2236 | stab = cdr(stab)((stab)->rest); |
| 2237 | outerTf = stabGetTForm(stab, tfGetExpr(tf)((tf)->__absyn), NULL((void*)0)); |
| 2238 | if (outerTf && tfQueries(outerTf)((outerTf)->queries)) break; |
| 2239 | } |
| 2240 | |
| 2241 | if (! outerTf) { |
| 2242 | outerTf = tfNewSyntax(tfGetExpr(tf)((tf)->__absyn)); |
| 2243 | tfSetConditions(outerTf, tfFloatConditions(stab, tf))(outerTf->conditions = (tfFloatConditions(stab, tf))); |
| 2244 | stabDefTForm(stab, outerTf); |
| 2245 | } |
| 2246 | |
| 2247 | if (tf == outerTf) |
| 2248 | return NULL((void*)0); |
| 2249 | |
| 2250 | if (DEBUG(tfFloat)tfFloatDebug) { |
| 2251 | fprintf(dbOut, "Floating from stab level %lu to level %lu.", |
| 2252 | odepth, ndepth); |
| 2253 | findent += 2; |
| 2254 | fnewline(dbOut); |
| 2255 | fprintf(dbOut,"Inner tform = "); |
| 2256 | tfPrint(dbOut, tf); |
| 2257 | fnewline(dbOut); |
| 2258 | fprintf(dbOut,"Outer tform = "); |
| 2259 | tfPrint(dbOut, outerTf); |
| 2260 | findent -= 2; |
| 2261 | fnewline(dbOut); |
| 2262 | } |
| 2263 | outerTf = tfFollowOnly(outerTf); |
| 2264 | tf = tfForwardFrSyntax(tf, outerTf); |
| 2265 | tf->conditions = NULL((void*)0); |
| 2266 | |
| 2267 | return stab; |
| 2268 | } |
| 2269 | |
| 2270 | /* |
| 2271 | * Compute the outermost symbol table depth for which the interpretation |
| 2272 | * of tf is known to be the same as it is in stab. |
| 2273 | */ |
| 2274 | ULong |
| 2275 | tfOuterDepth(Stab stab, TForm tf) |
| 2276 | { |
| 2277 | ULong depth; |
| 2278 | TFormList hl; |
| 2279 | |
| 2280 | depth = abOuterDepth(stab, tfGetExpr(tf)((tf)->__absyn)); |
| 2281 | for (hl = tfQueries(tf)((tf)->queries); hl; hl = cdr(hl)((hl)->rest)) { |
| 2282 | ULong d = tfOuterDepth(stab, car(hl)((hl)->first)); |
| 2283 | if (d > depth) depth = d; |
| 2284 | } |
| 2285 | |
| 2286 | return depth; |
| 2287 | } |
| 2288 | |
| 2289 | /* |
| 2290 | * Compute the outermost symbol table depth for which the interpretation |
| 2291 | * of ab is known to be the same as it is in stab. |
| 2292 | */ |
| 2293 | localstatic ULong abOuterDepth0 (Stab stab, Stab istab, AbSyn ab); |
| 2294 | |
| 2295 | ULong |
| 2296 | abOuterDepth(Stab stab, AbSyn ab) |
| 2297 | { |
| 2298 | return abOuterDepth0(stab, stab, ab); |
| 2299 | } |
| 2300 | |
| 2301 | localstatic ULong |
| 2302 | abOuterDepth0(Stab stab, Stab istab, AbSyn ab) |
| 2303 | { |
| 2304 | SymeList sl; |
| 2305 | ULong depth; |
| 2306 | Symbol sym; |
| 2307 | Length i; |
| 2308 | |
| 2309 | if (abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0)) |
| 2310 | istab = abStab(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->stab : 0); |
| 2311 | |
| 2312 | switch (abTag(ab)((ab)->abHdr.tag)) { |
| 2313 | case AB_LitInteger: |
| 2314 | sym = ssymTheInteger; |
| 2315 | goto handle_id; |
| 2316 | break; |
| 2317 | case AB_LitString: |
| 2318 | sym = ssymTheString; |
| 2319 | goto handle_id; |
| 2320 | break; |
| 2321 | case AB_LitFloat: |
| 2322 | sym = ssymTheFloat; |
| 2323 | goto handle_id; |
| 2324 | break; |
| 2325 | case AB_Id: { |
| 2326 | sym = ab->abId.sym; |
| 2327 | |
| 2328 | /* Do not float the symbol Category. */ |
| 2329 | handle_id: |
| 2330 | if (sym == ssymCategory) |
| 2331 | return stabLevelNo(stab)(((stab)->first)->lexicalLevel); |
| 2332 | |
| 2333 | /* Do not float symbols with no meanings. */ |
| 2334 | sl = stabGetMeanings(istab, NULL((void*)0), sym); |
| 2335 | if (sl == listNil(Syme)((SymeList) 0)) |
| 2336 | return stabLevelNo(stab)(((stab)->first)->lexicalLevel); |
| 2337 | |
| 2338 | depth = 0; |
| 2339 | for (; sl; sl = cdr(sl)((sl)->rest)) { |
| 2340 | Syme syme = car(sl)((sl)->first); |
| 2341 | ULong d = symeDefLevelNo(syme)(symeDefLevel(syme)->lexicalLevel); |
| 2342 | |
| 2343 | /* Ignore locally defined symbol meanings */ |
| 2344 | if (d > stabLevelNo(stab)(((stab)->first)->lexicalLevel)) { |
| 2345 | d = 0; |
| 2346 | } |
| 2347 | /* Do not float to stabGlobal. */ |
| 2348 | /* Do not float to a level where sym is assigned. */ |
| 2349 | /* Do not float to a level where sym is extended. */ |
| 2350 | /* Do not float if a type is not yet analyzed. */ |
| 2351 | /* Except if is `%', then just wing it... */ |
| 2352 | else if (sym == ssymSelf) |
| 2353 | ; |
| 2354 | else if (d == 0 || |
| 2355 | symeIsLexVar(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_LexVar) || |
| 2356 | symeIsExtend(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Extend) || |
| 2357 | (!symeIsImport(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Import) && |
| 2358 | (tfIsUnknown(symeType(syme))(((symeType(syme))->tag) == TF_Unknown) || |
| 2359 | tfIsSyntax(symeType(syme))(((symeType(syme))->tag) == TF_Syntax)))) |
| 2360 | d += 1; |
| 2361 | if (d > depth) depth = d; |
| 2362 | } |
| 2363 | |
| 2364 | /* Do not float to a level where sym is extended. */ |
| 2365 | for (; stab; stab = cdr(stab)((stab)->rest)) { |
| 2366 | ULong d = car(stab)((stab)->first)->lexicalLevel + 1; |
| 2367 | sl = car(stab)((stab)->first)->extendSymes; |
| 2368 | for (; d > depth && sl; sl = cdr(sl)((sl)->rest)) { |
| 2369 | Syme syme = car(sl)((sl)->first); |
| 2370 | if (symeIsExtend(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Extend) && symeId(syme)((syme)->id) == sym) |
| 2371 | depth = d; |
| 2372 | } |
| 2373 | } |
| 2374 | if (DEBUG(tfFloat)tfFloatDebug) { |
| 2375 | Buffer buf = bufNew(); |
| 2376 | bufPrintf(buf, "AbSyn: %s [%pAbSyn] %d\n", symString(sym)((sym)->str), ab, depth); |
| 2377 | fprintf(dbOut, "%s", bufLiberate(buf)); |
| 2378 | } |
| 2379 | break; |
| 2380 | } |
| 2381 | case AB_PretendTo: |
| 2382 | case AB_Declare: |
| 2383 | case AB_Apply: |
| 2384 | case AB_Comma: |
| 2385 | case AB_With: |
| 2386 | case AB_Has: |
| 2387 | case AB_RestrictTo: |
| 2388 | case AB_And: |
| 2389 | case AB_Or: |
| 2390 | case AB_If: |
| 2391 | case AB_Test: |
| 2392 | depth = 1; |
| 2393 | for (i = 0; i < abArgc(ab)((ab)->abHdr.argc); i += 1) { |
| 2394 | ULong d = abOuterDepth0(stab, istab, abArgv(ab)((ab)->abGen.data.argv)[i]); |
| 2395 | if (d > depth) depth = d; |
| 2396 | } |
| 2397 | break; |
| 2398 | default: |
| 2399 | depth = stabLevelNo(stab)(((stab)->first)->lexicalLevel); |
| 2400 | break; |
| 2401 | } |
| 2402 | |
| 2403 | assert(depth > 0 || stab != istab)do { if (!(depth > 0 || stab != istab)) _do_assert(("depth > 0 || stab != istab" ),"tform.c",2403); } while (0); |
| 2404 | return depth; |
| 2405 | } |
| 2406 | |
| 2407 | |
| 2408 | /****************************************************************************** |
| 2409 | * |
| 2410 | * :: Type form semantics. |
| 2411 | * |
| 2412 | *****************************************************************************/ |
| 2413 | |
| 2414 | /****************************************************************************** |
| 2415 | * |
| 2416 | * :: Type form has questions. |
| 2417 | * |
| 2418 | *****************************************************************************/ |
| 2419 | |
| 2420 | TFormList |
| 2421 | tfCopyQueries(TForm to, TForm from) |
| 2422 | { |
| 2423 | if (tfQueries(from)((from)->queries) == listNil(TForm)((TFormList) 0)) |
| 2424 | return tfQueries(to)((to)->queries); |
| 2425 | |
| 2426 | /* |
| 2427 | * No sense in duplicating queries. In fact we ought to do better |
| 2428 | * than this and compute the set union of both sets of queries. |
| 2429 | * That way we don't duplicate them. |
| 2430 | */ |
| 2431 | if (tfQueries(from)((from)->queries) == tfQueries(to)((to)->queries)) |
| 2432 | return tfQueries(to)((to)->queries); |
| 2433 | |
| 2434 | tfSetQueries(to, listConcat(TForm)(tfQueries(from), tfQueries(to)))(((to)->queries) = ((TForm_listPointer->Concat)(((from) ->queries), ((to)->queries)))); |
| 2435 | |
| 2436 | if (tfHasSelf(to)((to)->hasSelf)) /* Ooops: see stabIsImportedTForm */ |
| 2437 | tfHasSelf(to)((to)->hasSelf) = false((int) 0); |
| 2438 | if (tfDomExports(to)) |
| 2439 | tfSetDomExports(to, listNil(Syme)((SymeList) 0)); |
| 2440 | if (tfDomImports(to)) { |
| 2441 | symeSetFree(tfDomImports(to)); |
| 2442 | tfSetDomImports(to, NULL((void*)0)); |
| 2443 | } |
| 2444 | |
| 2445 | return tfQueries(to)((to)->queries); |
| 2446 | } |
| 2447 | |
| 2448 | TForm |
| 2449 | tfAddQuery(TForm tf, TForm cat) |
| 2450 | { |
| 2451 | tfDEBUGif (!tfDebug) { } else afprintf(dbOut, "Adding query %pTForm %pTForm\n", tf, cat); |
| 2452 | tfSetQueries(tf, listCons(TForm)(cat, tfQueries(tf)))(((tf)->queries) = ((TForm_listPointer->Cons)(cat, ((tf )->queries)))); |
| 2453 | return cat; |
| 2454 | } |
| 2455 | |
| 2456 | /****************************************************************************** |
| 2457 | * |
| 2458 | * :: Type form sefo accessors. |
| 2459 | * |
| 2460 | *****************************************************************************/ |
| 2461 | |
| 2462 | TForm |
| 2463 | abGetCategory(AbSyn ab) |
| 2464 | { |
| 2465 | TForm cat = tfUnknown; |
| 2466 | |
| 2467 | if (abState(ab)((ab)->abHdr.state) == AB_State_HasUnique) |
| 2468 | cat = abTUnique(ab)((ab)->abHdr.type.unique); |
| 2469 | |
| 2470 | else if (abState(ab)((ab)->abHdr.state) == AB_State_HasPoss && tpossIsUnique(abTPoss(ab)((ab)->abHdr.type.poss))) |
| 2471 | cat = tpossUnique(abTPoss(ab)((ab)->abHdr.type.poss)); |
| 2472 | |
| 2473 | else if (abTag(ab)((ab)->abHdr.tag) == AB_Id && abSyme(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->syme : 0)) |
| 2474 | cat = symeType(abSyme(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->syme : 0)); |
| 2475 | |
| 2476 | else if (abTForm(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->tform : 0)) |
| 2477 | cat = tfGetCategory(abTForm(ab)((ab)->abHdr.seman ? (ab)->abHdr.seman->tform : 0)); |
| 2478 | |
| 2479 | else if (tiTopFns()->tiCanSefo(ab)) { |
| 2480 | tiTopFns()->tiSefo(stabFile(), ab); |
| 2481 | if (abState(ab)((ab)->abHdr.state) == AB_State_HasUnique) |
| 2482 | cat = abTUnique(ab)((ab)->abHdr.type.unique); |
| 2483 | } |
| 2484 | |
| 2485 | return cat; |
| 2486 | } |
| 2487 | |
| 2488 | SymeList |
| 2489 | abGetCatExports(Sefo cat) |
| 2490 | { |
| 2491 | if (abIsNotNothing(cat)!((cat)->abHdr.tag == (AB_Nothing)) && abState(cat)((cat)->abHdr.state) == AB_State_HasUnique) |
| 2492 | return tfGetThdExports(abTUnique(cat)((cat)->abHdr.type.unique)); |
| 2493 | else |
| 2494 | return listNil(Syme)((SymeList) 0); |
| 2495 | } |
| 2496 | |
| 2497 | SymeList |
| 2498 | abGetCatSelf(Sefo cat) |
| 2499 | { |
| 2500 | if (abIsNotNothing(cat)!((cat)->abHdr.tag == (AB_Nothing)) && abState(cat)((cat)->abHdr.state) == AB_State_HasUnique) |
| 2501 | return tfGetThdSelf(abTUnique(cat)((cat)->abHdr.type.unique)); |
| 2502 | else |
| 2503 | return listNil(Syme)((SymeList) 0); |
| 2504 | } |
| 2505 | |
| 2506 | /****************************************************************************** |
| 2507 | * |
| 2508 | * :: Type form symbol table. |
| 2509 | * |
| 2510 | *****************************************************************************/ |
| 2511 | |
| 2512 | Stab |
| 2513 | tfDefStab(Stab stab, TForm tf) |
| 2514 | { |
| 2515 | Stab nstab = NULL((void*)0); |
| 2516 | |
| 2517 | if (tfStab(tf)((tf)->stab)) |
| 2518 | return tfStab(tf)((tf)->stab); |
| 2519 | |
| 2520 | if (tfHasExpr(tf)((tf)->__absyn != 0)) { |
| 2521 | nstab = abStab(tfGetExpr(tf))((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->stab : 0); |
| 2522 | if (nstab == NULL((void*)0)) { |
| 2523 | nstab = stabPushLevel(stab, sposNone, long0((long) 0)); |
| 2524 | abSetStab(tfGetExpr(tf)((tf)->__absyn), nstab); |
| 2525 | } |
| 2526 | } |
| 2527 | else |
| 2528 | nstab = stabPushLevel(stab, sposNone, long0((long) 0)); |
| 2529 | |
| 2530 | tfSetStab(tf, nstab)((tf)->stab = (nstab)); |
| 2531 | return nstab; |
| 2532 | } |
| 2533 | |
| 2534 | Stab |
| 2535 | tfGetStab(TForm tf) |
| 2536 | { |
| 2537 | Stab stab = NULL((void*)0); |
| 2538 | |
| 2539 | if (tfStab(tf)((tf)->stab)) |
| 2540 | return tfStab(tf)((tf)->stab); |
| 2541 | |
| 2542 | if (tfHasExpr(tf)((tf)->__absyn != 0)) |
| 2543 | stab = abStab(tfGetExpr(tf))((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->stab : 0); |
| 2544 | |
| 2545 | tfSetStab(tf, stab)((tf)->stab = (stab)); |
| 2546 | return stab; |
| 2547 | } |
| 2548 | |
| 2549 | /****************************************************************************** |
| 2550 | * |
| 2551 | * :: Type form category. |
| 2552 | * |
| 2553 | *****************************************************************************/ |
| 2554 | |
| 2555 | /* |
| 2556 | * Anything that might have a later extend.... |
| 2557 | */ |
| 2558 | |
| 2559 | #define tfp0IsSpecialTag(tag)((tag) == TF_Tuple || (tag) == TF_Record || (tag) == TF_RawRecord || (tag) == TF_Reference || (tag) == TF_Generator || (tag) == TF_Union || (tag) == TF_TrailingArray || (tag) == TF_Enumerate ) \ |
| 2560 | ((tag) == TF_Tuple || (tag) == TF_Record \ |
| 2561 | || (tag) == TF_RawRecord || (tag) == TF_Reference \ |
| 2562 | || (tag) == TF_Generator || (tag) == TF_Union \ |
| 2563 | || (tag) == TF_TrailingArray || (tag) == TF_Enumerate) |
| 2564 | |
| 2565 | TForm |
| 2566 | tfGetCategory(TForm tf) |
| 2567 | { |
| 2568 | TForm cat = tfUnknown; |
| 2569 | |
| 2570 | if (tfHasUnique(tf)(((tf)->__absyn != 0) && ((((tf)->__absyn))-> abHdr.state) == AB_State_HasUnique) && !tfIsUnknown(tfTUnique(tf))(((((((tf)->__absyn))->abHdr.type.unique))->tag) == TF_Unknown )) |
| 2571 | cat = tfTUnique(tf)((((tf)->__absyn))->abHdr.type.unique); |
| 2572 | |
| 2573 | else if (tfHasPoss(tf)(((tf)->__absyn != 0) && ((((tf)->__absyn))-> abHdr.state) == AB_State_HasPoss) && tpossIsUnique(tfTPoss(tf)((((tf)->__absyn))->abHdr.type.poss))) |
| 2574 | cat = tpossUnique(tfTPoss(tf)((((tf)->__absyn))->abHdr.type.poss)); |
| 2575 | |
| 2576 | else if (tfIsId(tf)((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Id) && tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0)) |
| 2577 | cat = symeType(tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0)); |
| 2578 | |
| 2579 | else if (tfNeedsSefo(tf)((tf)->state == TF_State_NeedsSefo)) { |
| 2580 | tiTopFns()->tiTfSefo(stabFile(), tf); |
| 2581 | cat = tfGetCategory(tf); |
| 2582 | } |
| 2583 | |
| 2584 | #ifdef TFormBuiltinSefo |
| 2585 | else if (tfIsSym(tf)( (((tf)->tag)) < TF_SYM_LIMIT) && abSyme(tfExpr(tf))((tfToAbSyn(tf))->abHdr.seman ? (tfToAbSyn(tf))->abHdr. seman->syme : 0)) |
| 2586 | cat = symeType(tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0)); |
| 2587 | |
| 2588 | #endif |
| 2589 | else if (tfp0IsSpecialTag(tfTag(tf))((((tf)->tag)) == TF_Tuple || (((tf)->tag)) == TF_Record || (((tf)->tag)) == TF_RawRecord || (((tf)->tag)) == TF_Reference || (((tf)->tag)) == TF_Generator || (((tf)->tag)) == TF_Union || (((tf)->tag)) == TF_TrailingArray || (((tf)->tag)) == TF_Enumerate) && tiTopFns()->tiCanSefo(tfExpr(tf)tfToAbSyn(tf))) { |
| 2590 | tiTopFns()->tiSefo(stabFile(), tfExpr(tf)tfToAbSyn(tf)); |
| 2591 | if (tfHasUnique(tf)(((tf)->__absyn != 0) && ((((tf)->__absyn))-> abHdr.state) == AB_State_HasUnique)) |
| 2592 | cat = tfTUnique(tf)((((tf)->__absyn))->abHdr.type.unique); |
| 2593 | } |
| 2594 | |
| 2595 | if (tfIsDefine(cat)(((cat)->tag) == TF_Define) && tfDefineVal(cat)tfFollowArg(cat, 1) == tf) |
| 2596 | cat = tfDefineDecl(cat)tfFollowArg(cat, 0); |
| 2597 | |
| 2598 | return cat; |
| 2599 | } |
| 2600 | |
| 2601 | /****************************************************************************** |
| 2602 | * |
| 2603 | * :: Type form symbol meanings for self. |
| 2604 | * |
| 2605 | *****************************************************************************/ |
| 2606 | |
| 2607 | SymeList |
| 2608 | tfCopySelf(TForm to, TForm from) |
| 2609 | { |
| 2610 | if (!tfHasSelf(to)((to)->hasSelf) && tfSelf(to)((to)->self) == listNil(Syme)((SymeList) 0)) { |
| 2611 | tfSetSelf(to, listCopy(Syme)(tfSelf(from)))((to)->self = ((Syme_listPointer->Copy)(((from)->self )))); |
| 2612 | tfHasSelf(to)((to)->hasSelf) = tfHasSelf(from)((from)->hasSelf); |
| 2613 | } |
| 2614 | |
| 2615 | return tfSelf(to)((to)->self); |
| 2616 | } |
| 2617 | |
| 2618 | SymeList |
| 2619 | tfAddSelf(TForm tf, SymeList self2) |
| 2620 | { |
| 2621 | SymeList self1 = tfSelf(tf)((tf)->self); |
| 2622 | SymeList result = listNil(Syme)((SymeList) 0); |
| 2623 | |
| 2624 | for (; self2; self2 = cdr(self2)((self2)->rest)) |
| 2625 | if (!symeListMember(car(self2)((self2)->first), self1, symeEq)) |
| 2626 | result = listCons(Syme)(Syme_listPointer->Cons)(car(self2)((self2)->first), result); |
| 2627 | |
| 2628 | result = listNConcat(Syme)(Syme_listPointer->NConcat)(self1, listNReverse(Syme)(Syme_listPointer->NReverse)(result)); |
| 2629 | tfSetSelf(tf, result)((tf)->self = (result)); |
| 2630 | |
| 2631 | return result; |
| 2632 | } |
| 2633 | |
| 2634 | SymeList |
| 2635 | tfUnionSelf(TForm tf, SymeList self2) |
| 2636 | { |
| 2637 | return tfAddSelf(tf, self2); |
| 2638 | } |
| 2639 | |
| 2640 | SymeList |
| 2641 | tfGetSelfFrStab(Stab stab) |
| 2642 | { |
| 2643 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 2644 | Syme syme = stabGetSelf(stab); |
| 2645 | |
| 2646 | if (syme) symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 2647 | |
| 2648 | return symes; |
| 2649 | } |
| 2650 | |
| 2651 | SymeList |
| 2652 | tfGetSelf(Stab stab, TForm tf) |
| 2653 | { |
| 2654 | return tfSetSelf(tf, tfGetSelfFrStab(stab))((tf)->self = (tfGetSelfFrStab(stab))); |
| 2655 | } |
| 2656 | |
| 2657 | SymeList |
| 2658 | tfDefSelf(Stab stab, TForm tf) |
| 2659 | { |
| 2660 | SymeList symes; |
| 2661 | Syme syme; |
| 2662 | TForm ntf; |
| 2663 | |
| 2664 | if (tfSelf(tf)((tf)->self) || tfGetSelf(stab, tf)) |
| 2665 | return tfSelf(tf)((tf)->self); |
| 2666 | |
| 2667 | ntf = tfDefineOfType(tf); |
| 2668 | stab = tfDefStab(stab, tf); |
| 2669 | syme = stabDefLexVar(stab, ssymSelf, ntf); |
| 2670 | stabSetSubstable(stab)(((stab)->first)->isSubstable=1); |
| 2671 | |
| 2672 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, listNil(Syme)((SymeList) 0)); |
| 2673 | tfSetSelf(tf, symes)((tf)->self = (symes)); |
| 2674 | return symes; |
| 2675 | } |
| 2676 | |
| 2677 | /* |
| 2678 | * Called on a domain to get the symbol meaning(s) for %. |
| 2679 | */ |
| 2680 | SymeList |
| 2681 | tfGetDomSelf(TForm tf) |
| 2682 | { |
| 2683 | TForm cat; |
| 2684 | TFormList hl; |
| 2685 | |
| 2686 | tf = tfDefineeType(tf); |
| 2687 | |
| 2688 | if (tfHasSelf(tf)((tf)->hasSelf) && tfIsId(tf)((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Id) && symeExtension(tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0))) { |
| 2689 | return tfGetDomSelf(tfFrSyme(stabFile(), symeExtensionFull(tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0)))); |
| 2690 | } |
| 2691 | |
| 2692 | if (tfHasSelf(tf)((tf)->hasSelf)) |
| 2693 | return tfSelf(tf)((tf)->self); |
| 2694 | |
| 2695 | cat = tfGetCategory(tf); |
| 2696 | if (tfIsUnknown(cat)(((cat)->tag) == TF_Unknown)) |
| 2697 | return tfSelf(tf)((tf)->self); |
| 2698 | if (!tfIsAdd(tf)(((tf)->tag) == TF_Add) && !tfHasCatExports(cat)) |
| 2699 | return tfSelf(tf)((tf)->self); |
| 2700 | |
| 2701 | if (DEBUG(tfImport)tfImportDebug) { |
| 2702 | fprintf(dbOut, "(tfGetDomSelf: from "); |
| 2703 | tfPrint(dbOut, tf); |
| 2704 | fnewline(dbOut); |
| 2705 | } |
| 2706 | |
| 2707 | if (tfIsArchive(tf) || tfIsLibrary(tf)) |
| 2708 | tfAddSelf(tf, listNil(Syme)((SymeList) 0)); |
| 2709 | else if (tfIsAdd(tf)(((tf)->tag) == TF_Add) && tfGetStab(tf)) |
| 2710 | tfAddSelf(tf, tfGetSelfFrStab(tfGetStab(tf))); |
| 2711 | else |
| 2712 | tfAddSelf(tf, tfGetCatSelf(cat)); |
| 2713 | |
| 2714 | for (hl = tfQueries(tf)((tf)->queries); hl; hl = cdr(hl)((hl)->rest)) |
| 2715 | tfAddSelf(tf, tfGetCatSelf(car(hl)((hl)->first))); |
| 2716 | |
| 2717 | tfImportDEBUGif (!tfImportDebug) { } else afprintf(dbOut, ")\n"); |
| 2718 | |
| 2719 | tfHasSelf(tf)((tf)->hasSelf) = true1; |
| 2720 | return tfSelf(tf)((tf)->self); |
| 2721 | } |
| 2722 | |
| 2723 | /* |
| 2724 | * Called on a category to get the symbol meaning(s) for %. |
| 2725 | */ |
| 2726 | SymeList |
| 2727 | tfGetCatSelf(TForm cat) |
| 2728 | { |
| 2729 | tfFollow(cat)((cat) = tfFollowFn(cat)); |
| 2730 | |
| 2731 | if (tfIsDefine(cat)(((cat)->tag) == TF_Define)) { |
| 2732 | if (tfHasSelf(cat)((cat)->hasSelf) || !tfHasCatExports(cat)) |
| 2733 | return tfSelf(cat)((cat)->self); |
| 2734 | |
| 2735 | tfAddSelf(cat, tfGetDomSelf(tfDefineVal(cat)tfFollowArg(cat, 1))); |
| 2736 | tfAddSelf(cat, tfGetCatSelf(tfDefineeType(cat))); |
| 2737 | |
| 2738 | tfHasSelf(cat)((cat)->hasSelf) = true1; |
| 2739 | return tfSelf(cat)((cat)->self); |
| 2740 | } |
| 2741 | |
| 2742 | cat = tfDefineeType(cat); |
| 2743 | |
| 2744 | if (tfHasSelf(cat)((cat)->hasSelf)) |
| 2745 | return tfSelf(cat)((cat)->self); |
| 2746 | |
| 2747 | if (!tfHasCatExports(cat)) |
| 2748 | return tfSelf(cat)((cat)->self); |
| 2749 | |
| 2750 | if (tfIsUnknown(cat)(((cat)->tag) == TF_Unknown) || tfIsNone(cat)((((cat)->tag) == TF_Multiple) && tfMultiArgc(cat) == 0)) |
| 2751 | return tfSelf(cat)((cat)->self); |
| 2752 | |
| 2753 | if (DEBUG(tfCat)tfCatDebug) { |
| 2754 | fprintf(dbOut, "(tfGetCatSelf: from "); |
| 2755 | tfPrint(dbOut, cat); |
| 2756 | fnewline(dbOut); |
| 2757 | } |
| 2758 | |
| 2759 | if (tfIsWith(cat)(((cat)->tag) == TF_With)) { |
| 2760 | TForm tfb = tfWithBase(cat)tfFollowArg(cat, 0); |
| 2761 | TForm tfw = tfWithWithin(cat)tfFollowArg(cat, 1); |
| 2762 | SymeList wself; |
| 2763 | |
| 2764 | tfAddSelf(cat, tfGetCatSelf(tfb)); |
| 2765 | |
| 2766 | tfFollow(tfw)((tfw) = tfFollowFn(tfw)); |
| 2767 | if (tfHasSelf(tfw)((tfw)->hasSelf)) |
| 2768 | wself = tfSelf(tfw)((tfw)->self); |
| 2769 | |
| 2770 | else if (tfIsDeclare(tfw)(((tfw)->tag) == TF_Declare)) |
| 2771 | wself = listNil(Syme)((SymeList) 0); |
| 2772 | |
| 2773 | else if (tfHasExpr(tfw)((tfw)->__absyn != 0)) |
| 2774 | wself = tfGetCatSelfFrWith(tfGetExpr(tfw)((tfw)->__absyn)); |
| 2775 | else |
| 2776 | wself = tfGetCatSelf(tfw); |
| 2777 | |
| 2778 | tfAddSelf(tfw, wself); |
| 2779 | |
| 2780 | tfHasSelf(tfw)((tfw)->hasSelf) = true1; |
| 2781 | |
| 2782 | if (tfHasExpr(cat)((cat)->__absyn != 0)) |
| 2783 | tfAddSelf(cat, abSelf(tfGetExpr(cat))((((cat)->__absyn))->abHdr.seman ? (((cat)->__absyn) )->abHdr.seman->self : 0)); |
| 2784 | |
| 2785 | tfAddSelf(cat, wself); |
| 2786 | } |
| 2787 | |
| 2788 | else if (tfIsIf(cat)(((cat)->tag) == TF_If)) { |
| 2789 | tfAddSelf(cat, tfGetCatSelf(tfIfThen(cat)tfFollowArg(cat, 1))); |
| 2790 | tfAddSelf(cat, tfGetCatSelf(tfIfElse(cat)tfFollowArg(cat, 2))); |
| 2791 | } |
| 2792 | |
| 2793 | else if (tfIsJoin(cat)(((cat)->tag) == TF_Join) || tfIsMeet(cat)(((cat)->tag) == TF_Meet)) { |
| 2794 | Length i, argc = tfArgc(cat)((cat)->argc); |
| 2795 | for (i = 0; i < argc; i += 1) |
| 2796 | tfAddSelf(cat, tfGetCatSelf(tfFollowArg(cat, i))); |
| 2797 | } |
| 2798 | |
| 2799 | else |
| 2800 | tfAddSelf(cat, tfGetThdSelf(tfGetCategory(cat))); |
| 2801 | |
| 2802 | if (DEBUG(tfCat)tfCatDebug) { |
| 2803 | fprintf(dbOut, ")\n"); |
| 2804 | fnewline(dbOut); |
| 2805 | } |
| 2806 | |
| 2807 | tfHasSelf(cat)((cat)->hasSelf) = true1; |
| 2808 | return tfSelf(cat)((cat)->self); |
| 2809 | } |
| 2810 | |
| 2811 | /* |
| 2812 | * Called on a third-order type to get the symbol meaning(s) for %. |
| 2813 | */ |
| 2814 | SymeList |
| 2815 | tfGetThdSelf(TForm thd) |
| 2816 | { |
| 2817 | thd = tfDefineeType(thd); |
| 2818 | |
| 2819 | if (tfHasSelf(thd)((thd)->hasSelf)) |
| 2820 | return tfSelf(thd)((thd)->self); |
| 2821 | |
| 2822 | if (!tfHasThdExports(thd)) |
| 2823 | return tfSelf(thd)((thd)->self); |
| 2824 | |
| 2825 | if (tfIsThird(thd)(((thd)->tag) == TF_Third)) |
| 2826 | tfAddSelf(thd, tfGetCatSelf(tfThirdRestrictions(thd)tfFollowArg(thd, 0))); |
| 2827 | |
| 2828 | tfHasSelf(thd)((thd)->hasSelf) = true1; |
| 2829 | return tfSelf(thd)((thd)->self); |
| 2830 | } |
| 2831 | |
| 2832 | /* |
| 2833 | * tfGet...Self helper functions. |
| 2834 | */ |
| 2835 | |
| 2836 | localstatic SymeList |
| 2837 | tfGetCatSelfFrWith(Sefo sefo) |
| 2838 | { |
| 2839 | SymeList csymes, symes; |
| 2840 | Length i, argc; |
| 2841 | Sefo *argv; |
| 2842 | TForm cat; |
| 2843 | |
| 2844 | AB_SEQ_ITER(sefo, argc, argv){ switch (((sefo)->abHdr.tag)) { case AB_Nothing: argc = 0 ; argv = 0; break; case AB_Sequence: argc = ((sefo)->abHdr .argc); argv = ((sefo)->abGen.data.argv); break; default: argc = 1; argv = &sefo; break; }; }; |
| 2845 | |
| 2846 | symes = listNil(Syme)((SymeList) 0); |
| 2847 | for (i = 0; i < argc; i++) { |
| 2848 | Sefo id = abDefineeIdOrElse(argv[i], NULL((void*)0)); |
| 2849 | |
| 2850 | if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Nothing) |
| 2851 | continue; |
| 2852 | |
| 2853 | /* Defaults package. */ |
| 2854 | else if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Default) |
| 2855 | continue; |
| 2856 | /* Explicit declaration. */ |
| 2857 | else if (id && abTag(argv[i])((argv[i])->abHdr.tag) != AB_Id) |
| 2858 | continue; |
| 2859 | |
| 2860 | /* Category expression. */ |
| 2861 | else if (!tfIsUnknown(cat = abGetCategory(argv[i]))(((cat = abGetCategory(argv[i]))->tag) == TF_Unknown) && |
| 2862 | tfSatCat(cat)) { |
| 2863 | csymes = tfGetThdSelf(cat); |
| 2864 | symes = symeListUnion(symes, csymes, symeEq); |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | return symes; |
| 2869 | } |
| 2870 | |
| 2871 | /****************************************************************************** |
| 2872 | * |
| 2873 | * :: Type form parent symes. |
| 2874 | * |
| 2875 | *****************************************************************************/ |
| 2876 | |
| 2877 | localstatic SymeList tfGetCatParentsFrWith (TForm); |
| 2878 | localstatic SymeList tfGetCatParentsFrIf (TForm); |
| 2879 | localstatic SymeList tfGetCatParentsFrJoin (TForm); |
| 2880 | localstatic SymeList tfGetCatParentsFrInner (TForm); |
| 2881 | |
| 2882 | localstatic SymeList abGetCatParents (Sefo); |
| 2883 | |
| 2884 | localstatic void tfValidateDomExports(TForm tf); |
| 2885 | localstatic void tfValidateDomExportsParam(TForm tf); |
| 2886 | localstatic void tfValidateDomImports(TForm tf); |
| 2887 | localstatic void tfValidateDomImportsParam(TForm tf); |
| 2888 | localstatic void tfValidateCheckConstInfo(TForm tf, SymeList symes, String type); |
| 2889 | |
| 2890 | /* |
| 2891 | * Called on a semantic category form to get the symbol meaning for %% |
| 2892 | * to serve as a representation of all of the exports of the category. |
| 2893 | */ |
| 2894 | SymeList |
| 2895 | abGetCatSelfSelf(Sefo sefo) |
| 2896 | { |
| 2897 | TForm thd; |
| 2898 | AbSub sigma; |
| 2899 | SymeList symes; |
| 2900 | |
| 2901 | if (!tfIsUnknown(thd = abGetCategory(sefo))(((thd = abGetCategory(sefo))->tag) == TF_Unknown)) |
| 2902 | return tfGetThdSelfSelf(thd); |
| 2903 | |
| 2904 | else if (abHasTag(sefo, AB_Id)((sefo)->abHdr.tag == (AB_Id))) |
| 2905 | thd = symeType(abSyme(sefo)((sefo)->abHdr.seman ? (sefo)->abHdr.seman->syme : 0 )); |
| 2906 | |
| 2907 | /*!! We really should handle curried categories. */ |
| 2908 | else if (abHasTag(sefo, AB_Apply)((sefo)->abHdr.tag == (AB_Apply))) { |
| 2909 | TForm tf = symeType(abSyme(abApplyOp(sefo))((((sefo)->abApply.op))->abHdr.seman ? (((sefo)->abApply .op))->abHdr.seman->syme : 0)); |
| 2910 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 2911 | assert(tfIsAnyMap(tf))do { if (!(((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )))) _do_assert(("tfIsAnyMap(tf)"),"tform.c",2911); } while ( 0); |
| 2912 | thd = tfMapRet(tf)tfFollowArg(tf, 1); |
| 2913 | } |
| 2914 | |
| 2915 | else |
| 2916 | return listNil(Syme)((SymeList) 0); |
| 2917 | |
| 2918 | sigma = tfSatSubList(sefo); |
| 2919 | /*!! assert(sigma); */ |
| 2920 | if (sigma == NULL((void*)0)) return listNil(Syme)((SymeList) 0); |
| 2921 | |
| 2922 | symes = symeListSubstSigma(sigma, tfGetThdSelfSelf(thd)); |
| 2923 | absFree(sigma); |
| 2924 | return symes; |
| 2925 | } |
| 2926 | |
| 2927 | /* |
| 2928 | * Called on a category to get the symbol meaning for %% |
| 2929 | * to serve as a representation of all of the exports of the category. |
| 2930 | */ |
| 2931 | SymeList |
| 2932 | tfGetCatSelfSelf(TForm cat) |
| 2933 | { |
| 2934 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 2935 | |
| 2936 | cat = tfDefineeType(cat); |
| 2937 | |
| 2938 | if (tfHasSelfSelf(cat)((cat)->hasSelfSelf) || |
| 2939 | tfIsUnknown(cat)(((cat)->tag) == TF_Unknown) || tfIsNone(cat)((((cat)->tag) == TF_Multiple) && tfMultiArgc(cat) == 0)) |
| 2940 | return tfSelfSelf(cat)((cat)->selfself); |
| 2941 | |
| 2942 | if (tfIsId(cat)((((cat)->tag) == TF_General) && ((((cat)->__absyn ))->abHdr.tag) == AB_Id) || tfIsApply(cat)((((cat)->tag) == TF_General) && ((((cat)->__absyn ))->abHdr.tag) == AB_Apply)) { |
| 2943 | if (tfHasUnique(cat)(((cat)->__absyn != 0) && ((((cat)->__absyn))-> abHdr.state) == AB_State_HasUnique) && !tfIsUnknown(tfTUnique(cat))(((((((cat)->__absyn))->abHdr.type.unique))->tag) == TF_Unknown)) |
| 2944 | symes = abGetCatSelfSelf(tfGetExpr(cat)((cat)->__absyn)); |
| 2945 | else if (tfIsGeneral(cat)(((cat)->tag) == TF_General) && tiTopFns()->tiCanSefo(tfGetExpr(cat)((cat)->__absyn))) { |
| 2946 | tiTopFns()->tiSefo(stabFile(), tfGetExpr(cat)((cat)->__absyn)); |
| 2947 | symes = abGetCatSelfSelf(tfGetExpr(cat)((cat)->__absyn)); |
| 2948 | } |
| 2949 | else |
| 2950 | /* Don't cache if semantics may come later. */ |
| 2951 | return symes; |
| 2952 | } |
| 2953 | |
| 2954 | tfHasSelfSelf(cat)((cat)->hasSelfSelf) = true1; |
| 2955 | tfSelfSelf(cat)((cat)->selfself) = symes; |
| 2956 | tfAuditExportList(symes); |
| 2957 | return symes; |
| 2958 | } |
| 2959 | |
| 2960 | /* |
| 2961 | * Called on a third-order type to get the symbol meaning for %% |
| 2962 | * to serve as a representation of all of the exports of the third-order type. |
| 2963 | */ |
| 2964 | SymeList |
| 2965 | tfGetThdSelfSelf(TForm thd) |
| 2966 | { |
| 2967 | SymeList symes; |
| 2968 | |
| 2969 | thd = tfDefineeType(thd); |
| 2970 | |
| 2971 | if (tfHasSelfSelf(thd)((thd)->hasSelfSelf) || tfNeedsSefo(thd)((thd)->state == TF_State_NeedsSefo) || |
| 2972 | tfIsUnknown(thd)(((thd)->tag) == TF_Unknown) || tfIsNone(thd)((((thd)->tag) == TF_Multiple) && tfMultiArgc(thd) == 0)) |
| 2973 | return tfSelfSelf(thd)((thd)->selfself); |
| 2974 | |
| 2975 | if (tfIsThird(thd)(((thd)->tag) == TF_Third)) |
| 2976 | symes = listCopy(Syme)(Syme_listPointer->Copy)(tfSymes(thd)((thd)->symes)); |
| 2977 | else |
| 2978 | symes = listNil(Syme)((SymeList) 0); |
| 2979 | |
| 2980 | tfHasSelfSelf(thd)((thd)->hasSelfSelf) = true1; |
| 2981 | tfSelfSelf(thd)((thd)->selfself) = symes; |
| 2982 | tfAuditExportList(symes); |
| 2983 | return symes; |
| 2984 | } |
| 2985 | |
| 2986 | /* |
| 2987 | * Called on a category to get the symbol meanings which serve as |
| 2988 | * 'parents' of all of the exports of the category. |
| 2989 | */ |
| 2990 | SymeList |
| 2991 | tfGetCatParents(TForm cat, Bool top) |
| 2992 | { |
| 2993 | SymeList symes; |
| 2994 | |
| 2995 | tfFollow(cat)((cat) = tfFollowFn(cat)); |
| 2996 | if (tfIsDefineOfType(cat)) |
| 2997 | return tfGetCatParents(tfGetCategory(tfDefineVal(cat)tfFollowArg(cat, 1)), top); |
| 2998 | |
| 2999 | cat = tfDefineeType(cat); |
| 3000 | |
| 3001 | if (tfCatExports(cat) || tfIsUnknown(cat)(((cat)->tag) == TF_Unknown) || tfIsNone(cat)((((cat)->tag) == TF_Multiple) && tfMultiArgc(cat) == 0)) |
| 3002 | symes = listCopy(Syme)(Syme_listPointer->Copy)(tfCatExports(cat)); |
| 3003 | |
| 3004 | else if (tfIsWith(cat)(((cat)->tag) == TF_With) && tfUseCatExports(cat)(((((tfFollowArg(cat, 0))->tag) == TF_Multiple) && tfMultiArgc(tfFollowArg(cat, 0)) == 0) && ((((tfFollowArg (cat, 1))->tag) == TF_Multiple) && tfMultiArgc(tfFollowArg (cat, 1)) == 0))) |
| 3005 | symes = listCopy(Syme)(Syme_listPointer->Copy)(tfParents(cat)((cat)->parents)); |
| 3006 | |
| 3007 | else if (!tfHasCatExports(cat)) |
| 3008 | symes = tfCatExports(cat); |
| 3009 | |
| 3010 | else if (tfIsWith(cat)(((cat)->tag) == TF_With)) |
| 3011 | symes = tfGetCatParentsFrWith(cat); |
| 3012 | |
| 3013 | else if (tfIsIf(cat)(((cat)->tag) == TF_If)) |
| 3014 | symes = tfGetCatParentsFrIf(cat); |
| 3015 | |
| 3016 | else if (tfIsJoin(cat)(((cat)->tag) == TF_Join)) |
| 3017 | symes = tfGetCatParentsFrJoin(cat); |
| 3018 | |
| 3019 | else if (tfIsMeet(cat)(((cat)->tag) == TF_Meet)) |
| 3020 | symes = tfGetCatExportsFrMeet(cat); |
| 3021 | |
| 3022 | else if (top) |
| 3023 | symes = tfGetThdParents(tfGetCategory(cat)); |
| 3024 | |
| 3025 | else if (tfIsDeclare(cat)(((cat)->tag) == TF_Declare)) |
| 3026 | symes = listCopy(Syme)(Syme_listPointer->Copy)(tfSymes(cat)((cat)->symes)); |
| 3027 | |
| 3028 | else |
| 3029 | symes = listCopy(Syme)(Syme_listPointer->Copy)(tfGetCatSelfSelf(cat)); |
| 3030 | |
| 3031 | tfAuditExportList(symes); |
| 3032 | return symes; |
| 3033 | } |
| 3034 | |
| 3035 | /* |
| 3036 | * Called on a third-order type to get the symbol meanings which serve as |
| 3037 | * 'parents' of all of the exports of the third-order type. |
| 3038 | */ |
| 3039 | SymeList |
| 3040 | tfGetThdParents(TForm thd) |
| 3041 | { |
| 3042 | SymeList symes; |
| 3043 | |
| 3044 | thd = tfDefineeType(thd); |
| 3045 | |
| 3046 | if (tfThdExports(thd) || tfIsUnknown(thd)(((thd)->tag) == TF_Unknown) || tfIsNone(thd)((((thd)->tag) == TF_Multiple) && tfMultiArgc(thd) == 0)) |
| 3047 | symes = listCopy(Syme)(Syme_listPointer->Copy)(tfThdExports(thd)); |
| 3048 | |
| 3049 | else if (tfIsThird(thd)(((thd)->tag) == TF_Third) && tfUseThdExports(thd)(((((tfFollowArg(thd, 0))->tag) == TF_Multiple) && tfMultiArgc(tfFollowArg(thd, 0)) == 0))) |
| 3050 | symes = listCopy(Syme)(Syme_listPointer->Copy)(tfParents(thd)((thd)->parents)); |
| 3051 | |
| 3052 | else if (tfIsThird(thd)(((thd)->tag) == TF_Third)) |
| 3053 | symes = tfGetCatParents(tfThirdRestrictions(thd)tfFollowArg(thd, 0), false((int) 0)); |
| 3054 | |
| 3055 | else |
| 3056 | symes = listNil(Syme)((SymeList) 0); |
| 3057 | |
| 3058 | tfAuditExportList(symes); |
| 3059 | return symes; |
| 3060 | } |
| 3061 | |
| 3062 | /* |
| 3063 | * tfGet...Parents helper functions. |
| 3064 | */ |
| 3065 | |
| 3066 | localstatic SymeList |
| 3067 | tfGetCatParentsFrWith(TForm cat) |
| 3068 | { |
| 3069 | TForm tfb = tfWithBase(cat)tfFollowArg(cat, 0); |
| 3070 | TForm tfw = tfWithWithin(cat)tfFollowArg(cat, 1); |
| 3071 | SymeList bsymes, wsymes; |
| 3072 | |
| 3073 | bsymes = tfGetCatParents(tfb, false((int) 0)); |
| 3074 | |
| 3075 | tfFollow(tfw)((tfw) = tfFollowFn(tfw)); |
| 3076 | wsymes = tfGetCatParentsFrInner(tfw); |
| 3077 | |
| 3078 | return listNConcat(Syme)(Syme_listPointer->NConcat)(bsymes, wsymes); |
| 3079 | } |
| 3080 | |
| 3081 | localstatic SymeList |
| 3082 | abGetCatParents(Sefo sefo) |
| 3083 | { |
| 3084 | SymeList xsymes, isymes, dsymes, csymes, symes; |
| 3085 | Length i, argc; |
| 3086 | Sefo *argv; |
| 3087 | Sefo id; |
| 3088 | TForm cat; |
| 3089 | |
| 3090 | AB_SEQ_ITER(sefo, argc, argv){ switch (((sefo)->abHdr.tag)) { case AB_Nothing: argc = 0 ; argv = 0; break; case AB_Sequence: argc = ((sefo)->abHdr .argc); argv = ((sefo)->abGen.data.argv); break; default: argc = 1; argv = &sefo; break; }; }; |
| 3091 | |
| 3092 | xsymes = isymes = dsymes = listNil(Syme)((SymeList) 0); |
| 3093 | for (i = 0; i < argc; i++) { |
| 3094 | id = abDefineeIdOrElse(argv[i], NULL((void*)0)); |
| 3095 | |
| 3096 | if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Nothing) |
| 3097 | continue; |
| 3098 | |
| 3099 | /* Defaults package. */ |
| 3100 | else if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Default) { |
| 3101 | AbSyn def = argv[i]->abDefault.body; |
| 3102 | symes = tfSymesFrDefault(def); |
| 3103 | dsymes = listNConcat(Syme)(Syme_listPointer->NConcat)(symes, dsymes); |
| 3104 | } |
| 3105 | |
| 3106 | /* Explicit declaration. */ |
| 3107 | else if (id && abTag(argv[i])((argv[i])->abHdr.tag) != AB_Id) { |
| 3108 | assert(abSyme(id))do { if (!(((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0))) _do_assert(("abSyme(id)"),"tform.c",3108); } while (0 ); |
| 3109 | xsymes = listCons(Syme)(Syme_listPointer->Cons)(abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0), xsymes); |
| 3110 | } |
| 3111 | /* Category expression. */ |
| 3112 | else if (!tfIsUnknown(cat = abGetCategory(argv[i]))(((cat = abGetCategory(argv[i]))->tag) == TF_Unknown)) { |
| 3113 | csymes = listCopy(Syme)(Syme_listPointer->Copy)(tfGetThdSelfSelf(cat)); |
| 3114 | if (csymes == listNil(Syme)((SymeList) 0)) |
| 3115 | csymes = tfGetThdParents(cat); |
| 3116 | if (csymes == listNil(Syme)((SymeList) 0)) |
| 3117 | csymes = tfGetThdExports(cat); |
| 3118 | isymes = listNConcat(Syme)(Syme_listPointer->NConcat)(isymes, csymes); |
| 3119 | } |
| 3120 | } |
| 3121 | |
| 3122 | /* Mark the symes which have a default implementation. */ |
| 3123 | dsymes = listNReverse(Syme)(Syme_listPointer->NReverse)(dsymes); |
| 3124 | for (; dsymes; dsymes = listFreeCons(Syme)(Syme_listPointer->FreeCons)(dsymes)) { |
| 3125 | Syme dsyme = car(dsymes)((dsymes)->first); |
| 3126 | Syme xsyme = NULL((void*)0); |
| 3127 | |
| 3128 | /* If the default is one of our exports, just mark it. */ |
| 3129 | for (symes = xsymes; !xsyme && symes; symes = cdr(symes)((symes)->rest)) |
| 3130 | if (symeEqual(car(symes)((symes)->first), dsyme)) { |
| 3131 | xsyme = car(symes)((symes)->first); |
| 3132 | symeSetDefault(xsyme)(((((xsyme)->kind == SYME_Trigger ? libGetAllSymes((xsyme) ->lib) : ((void*)0)), (xsyme))->bits) |= (0x0080)); |
| 3133 | symeSetSrcPos(xsyme, symeSrcPos(dsyme))(symeSetFieldVal = ((AInt) (((SrcPos) (SYFI_SrcPos < (8 * sizeof (int)) && !(((((dsyme)->kind == SYME_Trigger ? libGetAllSymes ((dsyme)->lib) : ((void*)0)), (dsyme))->hasmask) & ( 1 << (SYFI_SrcPos))) ? (symeFieldInfo[SYFI_SrcPos].def) : (((((dsyme)->kind == SYME_Trigger ? libGetAllSymes((dsyme )->lib) : ((void*)0)), (dsyme))->locmask) & (1 << (SYFI_SrcPos))) ? ((((((dsyme)->kind == SYME_Trigger ? libGetAllSymes ((dsyme)->lib) : ((void*)0)), (dsyme))->locmask) & ( 1 << (SYFI_SrcPos))) ? ((dsyme)->fieldv)[symeIndex(dsyme ,SYFI_SrcPos)] : (symeFieldInfo[SYFI_SrcPos].def)) : symeGetFieldFn (dsyme,SYFI_SrcPos))))), (((((xsyme)->kind == SYME_Trigger ? libGetAllSymes((xsyme)->lib) : ((void*)0)), (xsyme))-> locmask) & (1 << (SYFI_SrcPos))) ? (((xsyme)->fieldv )[symeIndex(xsyme,SYFI_SrcPos)] = (symeSetFieldVal)) : !((xsyme )->full) && symeSetFieldVal == (symeFieldInfo[SYFI_SrcPos ].def) ? symeSetFieldVal : symeSetFieldFn(xsyme,SYFI_SrcPos,symeSetFieldVal )); |
| 3134 | } |
| 3135 | |
| 3136 | /* If the default is inherited, use the default syme. */ |
| 3137 | if (xsyme == NULL((void*)0)) { |
| 3138 | xsymes = listCons(Syme)(Syme_listPointer->Cons)(dsyme, xsymes); |
| 3139 | symeSetDefault(dsyme)(((((dsyme)->kind == SYME_Trigger ? libGetAllSymes((dsyme) ->lib) : ((void*)0)), (dsyme))->bits) |= (0x0080)); |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | xsymes = listNReverse(Syme)(Syme_listPointer->NReverse)(xsymes); |
| 3144 | return listNConcat(Syme)(Syme_listPointer->NConcat)(isymes, xsymes); |
| 3145 | } |
| 3146 | |
| 3147 | localstatic SymeList |
| 3148 | tfGetCatParentsFrIf(TForm cat) |
| 3149 | { |
| 3150 | SymeList tsymes, esymes, symes = listNil(Syme)((SymeList) 0); |
| 3151 | Sefo cond; |
| 3152 | |
| 3153 | if (tfParents(cat)((cat)->parents)) |
| 3154 | return listCopy(Syme)(Syme_listPointer->Copy)(tfParents(cat)((cat)->parents)); |
| 3155 | cond = tfIfCond(cat)tfToAbSyn(tfFollowArg(cat, 0)); |
| 3156 | |
| 3157 | if (abState(cond)((cond)->abHdr.state) != AB_State_HasUnique) { |
| 3158 | /* This is seriously not nice, as calling |
| 3159 | * tiSefo will be expensive here |
| 3160 | */ |
| 3161 | tiTopFns()->tiSefo(stabFile(), cond); |
| 3162 | } |
| 3163 | |
| 3164 | tsymes = tfGetCatParentsFrInner(tfIfThen(cat)tfFollowArg(cat, 1)); |
| 3165 | tsymes = symeListAddCondition(tsymes, cond, true1); |
| 3166 | |
| 3167 | esymes = tfGetCatParentsFrInner(tfIfElse(cat)tfFollowArg(cat, 2)); |
| 3168 | esymes = listCopy(Syme)(Syme_listPointer->Copy)(esymes); |
| 3169 | symes = listNConcat(Syme)(Syme_listPointer->NConcat)(tsymes, esymes); |
| 3170 | tfSetParents(cat, listCopy(Syme)(symes))((cat)->parents = ((Syme_listPointer->Copy)(symes))); |
| 3171 | return symes; |
| 3172 | } |
| 3173 | |
| 3174 | localstatic SymeList |
| 3175 | tfGetCatParentsFrJoin(TForm cat) |
| 3176 | { |
| 3177 | SymeList nsymes, symes = listNil(Syme)((SymeList) 0); |
| 3178 | Length i; |
| 3179 | |
| 3180 | for (i = 0; i < tfJoinArgc(cat)((cat)->argc); i += 1) { |
| 3181 | nsymes = tfGetCatParents(tfJoinArgN(cat, i)tfFollowArg(cat, i), false((int) 0)); |
| 3182 | symes = listNConcat(Syme)(Syme_listPointer->NConcat)(symes, nsymes); |
| 3183 | } |
| 3184 | |
| 3185 | return symes; |
| 3186 | } |
| 3187 | |
| 3188 | /* |
| 3189 | * This handles the case where the TForm could be |
| 3190 | * a declaration (or sequence of) |
| 3191 | */ |
| 3192 | localstatic SymeList |
| 3193 | tfGetCatParentsFrInner(TForm cat) |
| 3194 | { |
| 3195 | SymeList symes; |
| 3196 | |
| 3197 | if (tfIsDeclare(cat)(((cat)->tag) == TF_Declare)) |
| 3198 | symes = listCopy(Syme)(Syme_listPointer->Copy)(tfSymes(cat)((cat)->symes)); |
| 3199 | else if (tfHasExpr(cat)((cat)->__absyn != 0)) |
| 3200 | symes = abGetCatParents(tfGetExpr(cat)((cat)->__absyn)); |
| 3201 | else |
| 3202 | symes = tfGetCatParents(cat, false((int) 0)); |
| 3203 | |
| 3204 | return symes; |
| 3205 | } |
| 3206 | /****************************************************************************** |
| 3207 | * |
| 3208 | * :: Type form predicates to determine if the exports can be computed. |
| 3209 | * |
| 3210 | *****************************************************************************/ |
| 3211 | |
| 3212 | void |
| 3213 | tfAuditExportList(SymeList symes) |
| 3214 | { |
| 3215 | for (; symes; symes = cdr(symes)((symes)->rest)) |
| 3216 | if (!symeIsExport(car(symes))(((((((symes)->first))->kind == SYME_Trigger ? libGetAllSymes ((((symes)->first))->lib) : ((void*)0)), (((symes)-> first)))->kind) == SYME_Export) && !symeIsExtend(car(symes))(((((((symes)->first))->kind == SYME_Trigger ? libGetAllSymes ((((symes)->first))->lib) : ((void*)0)), (((symes)-> first)))->kind) == SYME_Extend)) |
| 3217 | bug("tfAuditExportList"); |
| 3218 | } |
| 3219 | |
| 3220 | localstatic void |
| 3221 | tfGetExportError(TForm tf, String order) |
| 3222 | { |
| 3223 | if (DEBUG(tf)tfDebug) { |
| 3224 | fprintf(dbOut, "No semantics for %s: ", order); |
| 3225 | tfPrint(dbOut, tf); |
| 3226 | fnewline(dbOut); |
| 3227 | } |
| 3228 | /* "Implementation restriction: |
| 3229 | import from %s before its exports could be determined." */ |
| 3230 | /* comsgWarning(tfExpr(tf), ALDOR_W_TinEarlyImport, order); */ |
| 3231 | } |
| 3232 | |
| 3233 | /* |
| 3234 | * There's a few cases where we stamp a real const number on symes from categories. |
| 3235 | * This leads to incorrect inlining later on. While the underlying bug isn't fixed, |
| 3236 | * the code below provides a workaround. |
| 3237 | */ |
| 3238 | localstatic void |
| 3239 | tfValidateDomExports(TForm tf) |
| 3240 | { |
| 3241 | Syme syme; |
| 3242 | |
| 3243 | tfAuditExportList(tfDomExports(tf)); |
| 3244 | |
| 3245 | if (!tfIsId(tf)((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Id)) |
| 3246 | return; |
| 3247 | syme = tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0); |
| 3248 | if (syme && symeIsParam(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Param)) { |
| 3249 | tfValidateDomExportsParam(tf); |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | localstatic void |
| 3254 | tfValidateDomImports(TForm tf) |
| 3255 | { |
| 3256 | Syme syme; |
| 3257 | |
| 3258 | if (!tfIsId(tf)((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Id)) |
| 3259 | return; |
| 3260 | syme = tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0); |
| 3261 | if (syme && symeIsParam(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Param)) { |
| 3262 | tfValidateDomImportsParam(tf); |
| 3263 | } |
| 3264 | } |
| 3265 | |
| 3266 | localstatic void |
| 3267 | tfValidateDomExportsParam(TForm tf) |
| 3268 | { |
| 3269 | tfValidateCheckConstInfo(tf, tfDomExports(tf), "exports"); |
| 3270 | } |
| 3271 | |
| 3272 | localstatic void |
| 3273 | tfValidateDomImportsParam(TForm tf) |
| 3274 | { |
| 3275 | if (tfDomImports(tf)) |
| 3276 | tfValidateCheckConstInfo(tf, symeSetList(tfDomImports(tf)), "imports"); |
| 3277 | } |
| 3278 | |
| 3279 | localstatic void |
| 3280 | tfValidateCheckConstInfo(TForm tf, SymeList symes, String type) |
| 3281 | { |
| 3282 | while (symes != listNil(Syme)((SymeList) 0)) { |
| 3283 | Syme syme = car(symes)((symes)->first); |
| 3284 | symes = cdr(symes)((symes)->rest); |
| 3285 | |
| 3286 | if (symeConstNum(syme)(((AInt) (SYFI_ConstInfo < (8 * sizeof(int)) && !( ((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->hasmask) & (1 << (SYFI_ConstInfo ))) ? (symeFieldInfo[SYFI_ConstInfo].def) : (((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)->lib) : ((void*)0 )), (syme))->locmask) & (1 << (SYFI_ConstInfo))) ? ((((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme )->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_ConstInfo))) ? ((syme)->fieldv)[symeIndex(syme,SYFI_ConstInfo )] : (symeFieldInfo[SYFI_ConstInfo].def)) : symeGetFieldFn(syme ,SYFI_ConstInfo))) & 0xFFFF) != SYME_NUMBER_UNASSIGNED(0x7FFF)) { |
| 3287 | /* Code here patches a bug where there should not be a const here |
| 3288 | afprintf(dbOut, "Type: %s Syme %s.%d %pSyme %pTForm\n", |
| 3289 | type, |
| 3290 | libToStringShort(symeConstLib(syme)), symeConstNum(syme), |
| 3291 | syme, tf); |
| 3292 | bugWarning("Syme with const num found in parameterised domain %s", |
| 3293 | abPretty(tfExpr(tf))); |
| 3294 | */ |
| 3295 | symeSetConstLib(syme, NULL((void*)0)); |
| 3296 | symeSetConstNum(syme, SYME_NUMBER_UNASSIGNED(0x7FFF)); |
| 3297 | } |
| 3298 | |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | Bool |
| 3303 | tfHasCatExports(TForm cat) |
| 3304 | { |
| 3305 | return tfCatExportsPending(cat) == NULL((void*)0); |
| 3306 | } |
| 3307 | |
| 3308 | Bool |
| 3309 | tfHasThdExports(TForm thd) |
| 3310 | { |
| 3311 | return tfThdExportsPending(thd) == NULL((void*)0); |
| 3312 | } |
| 3313 | |
| 3314 | Bool |
| 3315 | tfHasCatExportsFrWith(Sefo sefo) |
| 3316 | { |
| 3317 | return tfCatExportsPendingFrWith(sefo) == NULL((void*)0); |
| 3318 | } |
| 3319 | |
| 3320 | TForm |
| 3321 | tfCatExportsPending(TForm cat) |
| 3322 | { |
| 3323 | TForm pending; |
| 3324 | |
| 3325 | cat = tfDefineeTypeSubst(cat); |
| 3326 | |
| 3327 | if (tfCatExports(cat)) |
| 3328 | return NULL((void*)0); |
| 3329 | |
| 3330 | if (tfIsUnknown(cat)(((cat)->tag) == TF_Unknown) || tfIsNone(cat)((((cat)->tag) == TF_Multiple) && tfMultiArgc(cat) == 0)) |
| 3331 | return NULL((void*)0); |
| 3332 | |
| 3333 | if (!tfIsMeaning(cat)(((cat)->state)>=TF_State_Meaning)) { |
| 3334 | assert(tfIsPending(cat))do { if (!((((cat)->state)==TF_State_Pending))) _do_assert (("tfIsPending(cat)"),"tform.c",3334); } while (0); |
| 3335 | return cat; |
| 3336 | } |
| 3337 | |
| 3338 | if (tfIsWith(cat)(((cat)->tag) == TF_With)) { |
| 3339 | TForm tfb = tfWithBase(cat)tfFollowArg(cat, 0); |
| 3340 | TForm tfw = tfWithWithin(cat)tfFollowArg(cat, 1); |
| 3341 | |
| 3342 | pending = tfCatExportsPending(tfb); |
| 3343 | if (pending) return pending; |
| 3344 | |
| 3345 | tfFollow(tfw)((tfw) = tfFollowFn(tfw)); |
| 3346 | if (tfCatExports(tfw)) |
| 3347 | pending = NULL((void*)0); |
| 3348 | else if (tfIsDeclare(tfw)(((tfw)->tag) == TF_Declare)) |
| 3349 | pending = (tfSymes(tfw)((tfw)->symes) ? NULL((void*)0) : tfUnknown); |
| 3350 | else if (tfHasExpr(tfw)((tfw)->__absyn != 0)) |
| 3351 | pending = tfCatExportsPendingFrWith(tfGetExpr(tfw)((tfw)->__absyn)); |
| 3352 | else |
| 3353 | pending = tfCatExportsPending(tfw); |
| 3354 | |
| 3355 | if (pending && tfIsUnknown(pending)(((pending)->tag) == TF_Unknown)) { |
| 3356 | assert(tfIsPending(tfw))do { if (!((((tfw)->state)==TF_State_Pending))) _do_assert (("tfIsPending(tfw)"),"tform.c",3356); } while (0); |
| 3357 | return tfw; |
| 3358 | } |
| 3359 | if (pending) return pending; |
| 3360 | |
| 3361 | return NULL((void*)0); |
| 3362 | } |
| 3363 | |
| 3364 | else if (tfIsIf(cat)(((cat)->tag) == TF_If)) { |
| 3365 | pending = tfCatExportsPending(tfIfThen(cat)tfFollowArg(cat, 1)); |
| 3366 | if (pending) return pending; |
| 3367 | |
| 3368 | pending = tfCatExportsPending(tfIfElse(cat)tfFollowArg(cat, 2)); |
| 3369 | if (pending) return pending; |
| 3370 | |
| 3371 | return NULL((void*)0); |
| 3372 | } |
| 3373 | |
| 3374 | else if (tfIsJoin(cat)(((cat)->tag) == TF_Join) || tfIsMeet(cat)(((cat)->tag) == TF_Meet)) { |
| 3375 | Length i, argc = tfArgc(cat)((cat)->argc); |
| 3376 | |
| 3377 | for (i = 0; i < argc; i += 1) { |
| 3378 | pending = tfCatExportsPending(tfFollowArg(cat, i)); |
| 3379 | if (pending) return pending; |
| 3380 | } |
| 3381 | |
| 3382 | return NULL((void*)0); |
| 3383 | } |
| 3384 | |
| 3385 | else |
| 3386 | return tfThdExportsPending(tfGetCategory(cat)); |
| 3387 | } |
| 3388 | |
| 3389 | localstatic TForm |
| 3390 | tfCatExportsPendingFrWith(Sefo sefo) |
| 3391 | { |
| 3392 | Length i, argc; |
| 3393 | Sefo *argv; |
| 3394 | TForm pending; |
| 3395 | |
| 3396 | AB_SEQ_ITER(sefo, argc, argv){ switch (((sefo)->abHdr.tag)) { case AB_Nothing: argc = 0 ; argv = 0; break; case AB_Sequence: argc = ((sefo)->abHdr .argc); argv = ((sefo)->abGen.data.argv); break; default: argc = 1; argv = &sefo; break; }; }; |
| 3397 | |
| 3398 | for (i = 0; i < argc; i += 1) { |
| 3399 | AbSyn id = abDefineeIdOrElse(argv[i], NULL((void*)0)); |
| 3400 | |
| 3401 | if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Nothing) |
| 3402 | continue; |
| 3403 | |
| 3404 | /* Defaults package. */ |
| 3405 | else if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Default) { |
| 3406 | AbSyn def = argv[i]->abDefault.body; |
| 3407 | if (!tfHasSymesFrDefault(def)) |
| 3408 | return tfUnknown; |
| 3409 | } |
| 3410 | |
| 3411 | /* Explicit declaration. */ |
| 3412 | else if (id && abTag(argv[i])((argv[i])->abHdr.tag) != AB_Id) { |
| 3413 | if (!abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0)) |
| 3414 | return tfUnknown; |
| 3415 | } |
| 3416 | |
| 3417 | /* Category expression. */ |
| 3418 | else if (abState(argv[i])((argv[i])->abHdr.state) == AB_State_HasUnique && |
| 3419 | tfSatCat(abTUnique(argv[i])((argv[i])->abHdr.type.unique))) { |
| 3420 | pending = tfThdExportsPending(abTUnique(argv[i])((argv[i])->abHdr.type.unique)); |
| 3421 | if (pending) return pending; |
| 3422 | } |
| 3423 | } |
| 3424 | |
| 3425 | return NULL((void*)0); |
| 3426 | } |
| 3427 | |
| 3428 | localstatic Bool |
| 3429 | tfHasSymesFrDefault(Sefo sefo) |
| 3430 | { |
| 3431 | Length i, argc; |
| 3432 | Sefo *argv; |
| 3433 | Sefo id; |
| 3434 | |
| 3435 | switch (abTag(sefo)((sefo)->abHdr.tag)) { |
| 3436 | case AB_Nothing: |
| 3437 | argc = 0; |
| 3438 | argv = 0; |
| 3439 | break; |
| 3440 | case AB_If: |
| 3441 | argc = 2; |
| 3442 | argv = &sefo->abIf.thenAlt; |
| 3443 | break; |
| 3444 | case AB_Sequence: |
| 3445 | argc = abArgc(sefo)((sefo)->abHdr.argc); |
| 3446 | argv = abArgv(sefo)((sefo)->abGen.data.argv); |
| 3447 | break; |
| 3448 | default: |
| 3449 | id = abDefineeIdOrElse(sefo, NULL((void*)0)); |
| 3450 | if (id && !abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0)) return false((int) 0); |
| 3451 | return true1; |
| 3452 | } |
| 3453 | |
| 3454 | for (i = 0; i < argc; i += 1) { |
| 3455 | if (!tfHasSymesFrDefault(argv[i])) |
| 3456 | return false((int) 0); |
| 3457 | } |
| 3458 | |
| 3459 | return true1; |
| 3460 | } |
| 3461 | |
| 3462 | |
| 3463 | #define tfTUniqueOrZero(tf)(((tf)->__absyn != 0) ? ((((tf)->__absyn))->abHdr.type .unique) : ((void*)0)) (tfHasExpr(tf)((tf)->__absyn != 0) ? abTUnique(tfGetExpr(tf))((((tf)->__absyn))->abHdr.type.unique) : NULL((void*)0)) |
| 3464 | |
| 3465 | TForm |
| 3466 | tfThdExportsPending(TForm thd) |
| 3467 | { |
| 3468 | TForm inthd = thd; |
| 3469 | /* in bad case we come in here with a Define or a Declare (in the case of == Bug) */ |
| 3470 | thd = tfDefineeTypeSubst(thd); |
| 3471 | if (tfThdExports(thd)) |
| 3472 | return NULL((void*)0); |
| 3473 | |
| 3474 | if (tfIsUnknown(thd)(((thd)->tag) == TF_Unknown) || tfIsNone(thd)((((thd)->tag) == TF_Multiple) && tfMultiArgc(thd) == 0)) |
| 3475 | return NULL((void*)0); |
| 3476 | |
| 3477 | if (!tfIsMeaning(thd)(((thd)->state)>=TF_State_Meaning)) { |
| 3478 | assert(tfIsPending(thd))do { if (!((((thd)->state)==TF_State_Pending))) _do_assert (("tfIsPending(thd)"),"tform.c",3478); } while (0); |
| 3479 | return thd; |
| 3480 | } |
| 3481 | |
| 3482 | if (tfIsThird(thd)(((thd)->tag) == TF_Third)) { |
| 3483 | /* in bad case thd is now a Third whose argv[0] is the rhs of the category */ |
| 3484 | if tfIsJoin(tfThirdRestrictions(thd))(((tfFollowArg(thd, 0))->tag) == TF_Join) { |
| 3485 | /* if it is a Join, thd->argv[0]->argv[0..] are the arguments argn of the Join |
| 3486 | and argn->__absyn->abHdr.type.unique would be their Defines |
| 3487 | We will loop indefinitely if one of these Defines is the original. |
| 3488 | */ |
| 3489 | Length i, all; |
| 3490 | TForm candidate; |
| 3491 | all = tfJoinArgc(tfThirdRestrictions(thd))((tfFollowArg(thd, 0))->argc); |
| 3492 | for (i=0 ; i < all ; i+=1) { |
| 3493 | candidate = tfTUniqueOrZero(tfJoinArgv(tfThirdRestrictions(thd))[i])(((((tfFollowArg(thd, 0))->argv)[i])->__absyn != 0) ? ( (((((tfFollowArg(thd, 0))->argv)[i])->__absyn))->abHdr .type.unique) : ((void*)0)); |
| 3494 | if (candidate == inthd) { |
| 3495 | fprintf(stderrstderr,"Oops - circular category definition\n"); |
| 3496 | fflush(stderrstderr); |
| 3497 | abPrintDb(inthd->__absyn); |
| 3498 | exit(1); |
| 3499 | } |
| 3500 | } /* for */ |
| 3501 | return tfCatExportsPending(tfThirdRestrictions(thd)tfFollowArg(thd, 0)); |
| 3502 | |
| 3503 | } /* if Join */ |
| 3504 | else if tfIsWith(tfThirdRestrictions(thd))(((tfFollowArg(thd, 0))->tag) == TF_With){ |
| 3505 | /* if it is a With, thd->argv[0]->argv[1..] are the arguments argn of the With |
| 3506 | and argn->__absyn->abHdr.type.unique would be their Defines |
| 3507 | We will loop indefinitely if one of these Defines is the original. |
| 3508 | */ |
| 3509 | Length i; |
| 3510 | TForm candidate; |
| 3511 | for (i=0 ; i < tfArgc(tfThirdRestrictions(thd))((tfFollowArg(thd, 0))->argc) ; i+=1) { |
| 3512 | candidate = tfTUniqueOrZero(tfArgv(tfThirdRestrictions(thd))[i])(((((tfFollowArg(thd, 0))->argv)[i])->__absyn != 0) ? ( (((((tfFollowArg(thd, 0))->argv)[i])->__absyn))->abHdr .type.unique) : ((void*)0)); |
| 3513 | if (candidate == inthd) { |
| 3514 | fprintf(stderrstderr,"Oops - circular category definition\n"); |
| 3515 | fflush(stderrstderr); |
| 3516 | abPrintDb(inthd->__absyn); |
| 3517 | exit(1); |
| 3518 | } |
| 3519 | } |
| 3520 | } |
| 3521 | else if tfIsGeneral(tfThirdRestrictions(thd))(((tfFollowArg(thd, 0))->tag) == TF_General){ |
| 3522 | /* if it is a General we need to check circularity in case inthd is a Declare |
| 3523 | */ |
| 3524 | if ( tfIsDeclare(inthd)(((inthd)->tag) == TF_Declare) && |
| 3525 | (tfTUniqueOrZero(tfThirdRestrictions(thd))(((tfFollowArg(thd, 0))->__absyn != 0) ? ((((tfFollowArg(thd , 0))->__absyn))->abHdr.type.unique) : ((void*)0))->argv[0] == inthd) && |
| 3526 | (tfTUniqueOrZero(tfThirdRestrictions(thd))(((tfFollowArg(thd, 0))->__absyn != 0) ? ((((tfFollowArg(thd , 0))->__absyn))->abHdr.type.unique) : ((void*)0))->argv[1] == thd->argv[0])) { |
| 3527 | fprintf(stderrstderr,"Oops - circular category definition\n"); |
| 3528 | fflush(stderrstderr); |
| 3529 | abPrintDb(inthd->__absyn); |
| 3530 | exit(1); |
| 3531 | |
| 3532 | } |
| 3533 | } |
| 3534 | return tfCatExportsPending(tfThirdRestrictions(thd)tfFollowArg(thd, 0)); |
| 3535 | } |
| 3536 | |
| 3537 | else |
| 3538 | return NULL((void*)0); |
| 3539 | } |
| 3540 | |
| 3541 | /****************************************************************************** |
| 3542 | * |
| 3543 | * :: Type form exported symes. |
| 3544 | * |
| 3545 | *****************************************************************************/ |
| 3546 | |
| 3547 | /* Find the syme in symes corresponding to syme. Return NULL on failure. */ |
| 3548 | localstatic Syme |
| 3549 | symeListFindExport(SymeList mods, Syme syme1, SymeList symes) |
| 3550 | { |
| 3551 | Syme syme = NULL((void*)0); |
| 3552 | |
| 3553 | for (; !syme && symes; symes = cdr(symes)((symes)->rest)) { |
| 3554 | Syme syme2 = car(symes)((symes)->first); |
| 3555 | |
| 3556 | if (symeEqualModConditions(mods, syme1, syme2)) |
| 3557 | syme = syme2; |
| 3558 | } |
| 3559 | |
| 3560 | return syme; |
| 3561 | } |
| 3562 | |
| 3563 | /* Incorporate default/constant number/condition info from syme2 into syme1. */ |
| 3564 | localstatic void |
| 3565 | tfJoinExports(Syme syme1, Syme syme2) |
| 3566 | { |
| 3567 | if (!symeHasDefault(syme1)(((((syme1)->kind == SYME_Trigger ? libGetAllSymes((syme1) ->lib) : ((void*)0)), (syme1))->bits) & (0x0080)) && symeHasDefault(syme2)(((((syme2)->kind == SYME_Trigger ? libGetAllSymes((syme2) ->lib) : ((void*)0)), (syme2))->bits) & (0x0080))) { |
| 3568 | symeSetDefault(syme1)(((((syme1)->kind == SYME_Trigger ? libGetAllSymes((syme1) ->lib) : ((void*)0)), (syme1))->bits) |= (0x0080)); |
| 3569 | symeTransferImplInfo(syme1, syme2); |
| 3570 | } |
| 3571 | |
| 3572 | if (symeCondition(syme1) && |
| 3573 | !symeCondition(syme2)) |
| 3574 | symeSetCondition(syme1, listNil(Sefo)((SefoList) 0)); |
| 3575 | } |
| 3576 | |
| 3577 | localstatic Bool |
| 3578 | tfJoinExportToList(SymeList mods, SymeList symes, Syme syme2, Sefo cond) |
| 3579 | { |
| 3580 | Bool merge = false((int) 0); |
| 3581 | |
| 3582 | for (; !merge && symes; symes = cdr(symes)((symes)->rest)) { |
| 3583 | Syme syme1 = car(symes)((symes)->first); |
| 3584 | |
| 3585 | /* Decide if the two meanings can be merged into one. */ |
| 3586 | if (!symeEqualModConditions(mods, syme1, syme2)) |
| 3587 | merge = false((int) 0); |
| 3588 | |
| 3589 | else if (!symeCondition(syme1)) |
| 3590 | merge = true1; |
| 3591 | |
| 3592 | else if (symeCondition(syme2)) |
| 3593 | merge = sefoListEqualMod(mods, symeCondition(syme1), |
| 3594 | symeCondition(syme2)); |
| 3595 | else |
| 3596 | merge = (cond == NULL((void*)0)); |
| 3597 | |
| 3598 | if (merge) { |
| 3599 | tfJoinExports(syme1, syme2); |
| 3600 | symeAddTwin(syme1, syme2); |
| 3601 | } |
| 3602 | } |
| 3603 | return merge; |
| 3604 | } |
| 3605 | |
| 3606 | SymeList |
| 3607 | tfJoinExportLists(SymeList mods, SymeList symes1, SymeList symes2, Sefo cond) |
| 3608 | { |
| 3609 | SymeList result = symes1, next, lst; |
| 3610 | Table symesByName = tblNew((TblHashFun) symHashFn, (TblEqFun) symEqual); |
| 3611 | |
| 3612 | for (lst = symes1; lst; lst = cdr(lst)((lst)->rest)) { |
| 3613 | Syme syme = car(lst)((lst)->first); |
| 3614 | SymeList sl = (SymeList) tblElt(symesByName, symeId(syme)((syme)->id), listNil(Syme)((SymeList) 0)); |
| 3615 | tblSetElt(symesByName, symeId(syme)((syme)->id), listCons(Syme)(Syme_listPointer->Cons)(syme, sl)); |
| 3616 | } |
| 3617 | |
| 3618 | for (; symes2; symes2 = cdr(symes2)((symes2)->rest)) { |
| 3619 | Syme syme2 = car(symes2)((symes2)->first); |
| 3620 | SymeList namedSymes = tblElt(symesByName, symeId(syme2)((syme2)->id), listNil(Syme)((SymeList) 0)); |
| 3621 | |
| 3622 | if (!tfJoinExportToList(mods, namedSymes, syme2, cond)) { |
| 3623 | Syme syme1 = symeCopy(syme2); |
| 3624 | if (cond) symeAddCondition(syme1, cond, true1); |
| 3625 | next = listCons(Syme)(Syme_listPointer->Cons)(syme1, listNil(Syme)((SymeList) 0)); |
| 3626 | result = listNConcat(Syme)(Syme_listPointer->NConcat)(result, next); |
| 3627 | symeAddTwin(syme1, syme2); |
| 3628 | tblSetElt(symesByName, symeId(syme2)((syme2)->id), listCons(Syme)(Syme_listPointer->Cons)(syme1, namedSymes)); |
| 3629 | } |
| 3630 | } |
| 3631 | tblFreeDeeply(symesByName, NULL((void*)0), (TblFreeEltFun) listFree(Syme)(Syme_listPointer->Free)); |
| 3632 | return result; |
| 3633 | } |
| 3634 | |
| 3635 | localstatic SymeList |
| 3636 | tfMeetExportLists(SymeList mods, SymeList symes1, SymeList symes2, Sefo cond) |
| 3637 | { |
| 3638 | SymeList result = listNil(Syme)((SymeList) 0); |
| 3639 | |
| 3640 | for (; symes1; symes1 = cdr(symes1)((symes1)->rest)) { |
| 3641 | Syme syme1 = car(symes1)((symes1)->first); |
| 3642 | Syme syme2 = symeListFindExport(mods, syme1, symes2); |
| 3643 | |
| 3644 | if (syme2) { |
| 3645 | /*!! Combine default/const num./condition info. */; |
| 3646 | if (cond) symeAddCondition(syme1, cond, true1); |
| 3647 | result = listCons(Syme)(Syme_listPointer->Cons)(syme1, result); |
| 3648 | } |
| 3649 | } |
| 3650 | |
| 3651 | result = listNReverse(Syme)(Syme_listPointer->NReverse)(result); |
| 3652 | return result; |
| 3653 | } |
| 3654 | |
| 3655 | localstatic SymeList |
| 3656 | tfAddDomExports(TForm tf, SymeList symes) |
| 3657 | { |
| 3658 | SymeList nsymes; |
| 3659 | SymeList mods = tfGetDomSelf(tf); |
| 3660 | |
| 3661 | nsymes = tfJoinExportLists(mods, tfDomExports(tf), symes, NULL((void*)0)); |
| 3662 | |
| 3663 | tfSetDomExports(tf, nsymes); |
| 3664 | |
| 3665 | return nsymes; |
| 3666 | } |
| 3667 | |
| 3668 | localstatic SymeList |
| 3669 | tfAddCatExports(TForm tf, SymeList symes) |
| 3670 | { |
| 3671 | SymeList nsymes; |
| 3672 | SymeList mods = tfGetCatSelf(tf); |
| 3673 | |
| 3674 | nsymes = tfJoinExportLists(mods, tfCatExports(tf), symes, NULL((void*)0)); |
| 3675 | |
| 3676 | tfSetCatExports(tf, nsymes); |
| 3677 | |
| 3678 | return nsymes; |
| 3679 | } |
| 3680 | |
| 3681 | localstatic SymeList |
| 3682 | tfAddThdExports(TForm tf, SymeList symes) |
| 3683 | { |
| 3684 | SymeList nsymes; |
| 3685 | SymeList mods = tfGetThdSelf(tf); |
| 3686 | |
| 3687 | nsymes = tfJoinExportLists(mods, tfThdExports(tf), symes, NULL((void*)0)); |
| 3688 | |
| 3689 | tfSetThdExports(tf, nsymes); |
| 3690 | |
| 3691 | return nsymes; |
| 3692 | } |
| 3693 | |
| 3694 | localstatic SymeList |
| 3695 | tfAddHasExports(TForm tf, TForm cat) |
| 3696 | { |
| 3697 | Sefo cond = NULL((void*)0); |
| 3698 | SymeList nsymes; |
| 3699 | SymeList mods = tfGetDomSelf(tf); |
| 3700 | |
| 3701 | cat = tfDefineeType(cat); |
| 3702 | if (tfHasExpr(tf)((tf)->__absyn != 0) && tfHasExpr(cat)((cat)->__absyn != 0)) |
| 3703 | cond = abNewHas(sposNone, tfGetExpr(tf), tfGetExpr(cat))abNew(AB_Has, sposNone,2, ((tf)->__absyn),((cat)->__absyn )); |
| 3704 | |
| 3705 | nsymes = tfGetCatExports(cat); |
| 3706 | nsymes = tfJoinExportLists(mods, tfDomExports(tf), nsymes, cond); |
| 3707 | |
| 3708 | tfSetDomExports(tf, nsymes); |
| 3709 | |
| 3710 | return nsymes; |
| 3711 | } |
| 3712 | |
| 3713 | /* |
| 3714 | * tfMangleSymes(tf, cat, exports, symes) takes the type "tf", |
| 3715 | * its category "cat", a list of category exports "exports" |
| 3716 | * from the category of "cat" and a list of domain exports |
| 3717 | * "symes" from the add body of "cat". The implementation |
| 3718 | * details from "symes" are transferred into "exports". |
| 3719 | * |
| 3720 | * Note that the symes in "exports" are modified in-place. |
| 3721 | */ |
| 3722 | SymeList |
| 3723 | tfMangleSymes(TForm tf, TForm cat, SymeList esymes, SymeList symes) |
| 3724 | { |
| 3725 | SymeList sl, exports = esymes; |
| 3726 | SymeList mods = tfGetDomSelf(tf); |
| 3727 | |
| 3728 | |
| 3729 | /* Stop if we have nothing to do */ |
| 3730 | if (!symes || !exports) return esymes; |
| 3731 | |
| 3732 | |
| 3733 | /* Add in self from the category (??? needed ???) */ |
| 3734 | mods = listNConcat(Syme)(Syme_listPointer->NConcat)(mods, listCopy(Syme)(Syme_listPointer->Copy)(tfGetCatSelf(cat))); |
| 3735 | |
| 3736 | |
| 3737 | /* Shift defnNum and constNum from symes into tfDomExports(tf) */ |
| 3738 | for (;exports; exports = cdr(exports)((exports)->rest)) |
| 3739 | { |
| 3740 | Syme syme = car(exports)((exports)->first); |
| 3741 | TForm stf = symeType(syme); |
| 3742 | int cnum = symeConstNum(syme)(((AInt) (SYFI_ConstInfo < (8 * sizeof(int)) && !( ((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->hasmask) & (1 << (SYFI_ConstInfo ))) ? (symeFieldInfo[SYFI_ConstInfo].def) : (((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)->lib) : ((void*)0 )), (syme))->locmask) & (1 << (SYFI_ConstInfo))) ? ((((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme )->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_ConstInfo))) ? ((syme)->fieldv)[symeIndex(syme,SYFI_ConstInfo )] : (symeFieldInfo[SYFI_ConstInfo].def)) : symeGetFieldFn(syme ,SYFI_ConstInfo))) & 0xFFFF); |
| 3743 | |
| 3744 | |
| 3745 | /* Skip symes that aren't exports */ |
| 3746 | if (!symeIsExport(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Export)) |
| 3747 | continue; |
| 3748 | |
| 3749 | |
| 3750 | /* Skip symes that are okay */ |
| 3751 | if (cnum != SYME_NUMBER_UNASSIGNED(0x7FFF)) |
| 3752 | continue; |
| 3753 | |
| 3754 | |
| 3755 | /* Search for this syme in symes */ |
| 3756 | for (sl = symes;sl;sl = cdr(sl)((sl)->rest)) |
| 3757 | { |
| 3758 | Syme csyme = car(sl)((sl)->first); |
| 3759 | TForm cstf = symeType(csyme); |
| 3760 | int ccnum = symeConstNum(csyme)(((AInt) (SYFI_ConstInfo < (8 * sizeof(int)) && !( ((((csyme)->kind == SYME_Trigger ? libGetAllSymes((csyme)-> lib) : ((void*)0)), (csyme))->hasmask) & (1 << ( SYFI_ConstInfo))) ? (symeFieldInfo[SYFI_ConstInfo].def) : ((( ((csyme)->kind == SYME_Trigger ? libGetAllSymes((csyme)-> lib) : ((void*)0)), (csyme))->locmask) & (1 << ( SYFI_ConstInfo))) ? ((((((csyme)->kind == SYME_Trigger ? libGetAllSymes ((csyme)->lib) : ((void*)0)), (csyme))->locmask) & ( 1 << (SYFI_ConstInfo))) ? ((csyme)->fieldv)[symeIndex (csyme,SYFI_ConstInfo)] : (symeFieldInfo[SYFI_ConstInfo].def) ) : symeGetFieldFn(csyme,SYFI_ConstInfo))) & 0xFFFF); |
| 3761 | int cdnum = symeDefnNum(csyme)((int) (SYFI_DefnNum < (8 * sizeof(int)) && !((((( csyme)->kind == SYME_Trigger ? libGetAllSymes((csyme)-> lib) : ((void*)0)), (csyme))->hasmask) & (1 << ( SYFI_DefnNum))) ? (symeFieldInfo[SYFI_DefnNum].def) : (((((csyme )->kind == SYME_Trigger ? libGetAllSymes((csyme)->lib) : ((void*)0)), (csyme))->locmask) & (1 << (SYFI_DefnNum ))) ? ((((((csyme)->kind == SYME_Trigger ? libGetAllSymes( (csyme)->lib) : ((void*)0)), (csyme))->locmask) & ( 1 << (SYFI_DefnNum))) ? ((csyme)->fieldv)[symeIndex( csyme,SYFI_DefnNum)] : (symeFieldInfo[SYFI_DefnNum].def)) : symeGetFieldFn (csyme,SYFI_DefnNum))); |
| 3762 | |
| 3763 | |
| 3764 | /* Skip symes that aren't exports */ |
| 3765 | if (!symeIsExport(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Export)) |
| 3766 | continue; |
| 3767 | |
| 3768 | |
| 3769 | /* Skip symes with no defn or const number */ |
| 3770 | if (!cdnum && (ccnum == SYME_NUMBER_UNASSIGNED(0x7FFF))) |
| 3771 | continue; |
| 3772 | |
| 3773 | |
| 3774 | /* Do the names match? */ |
| 3775 | if (symeId(syme)((syme)->id) != symeId(csyme)((csyme)->id)) |
| 3776 | continue; |
| 3777 | |
| 3778 | |
| 3779 | /* Do the types match? */ |
| 3780 | if (!tformEqualMod(mods, stf, cstf)) |
| 3781 | continue; |
| 3782 | |
| 3783 | |
| 3784 | /* DEBUGGING */ |
| 3785 | tfImportDEBUGif (!tfImportDebug) { } else afprintf(dbOut, "\t* %d --> %d, %d --> %d [%s]\n", |
| 3786 | symeDefnNum(syme)((int) (SYFI_DefnNum < (8 * sizeof(int)) && !((((( syme)->kind == SYME_Trigger ? libGetAllSymes((syme)->lib ) : ((void*)0)), (syme))->hasmask) & (1 << (SYFI_DefnNum ))) ? (symeFieldInfo[SYFI_DefnNum].def) : (((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)->lib) : ((void*)0 )), (syme))->locmask) & (1 << (SYFI_DefnNum))) ? ((((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme) ->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_DefnNum))) ? ((syme)->fieldv)[symeIndex(syme,SYFI_DefnNum )] : (symeFieldInfo[SYFI_DefnNum].def)) : symeGetFieldFn(syme ,SYFI_DefnNum))), |
| 3787 | symeDefnNum(csyme)((int) (SYFI_DefnNum < (8 * sizeof(int)) && !((((( csyme)->kind == SYME_Trigger ? libGetAllSymes((csyme)-> lib) : ((void*)0)), (csyme))->hasmask) & (1 << ( SYFI_DefnNum))) ? (symeFieldInfo[SYFI_DefnNum].def) : (((((csyme )->kind == SYME_Trigger ? libGetAllSymes((csyme)->lib) : ((void*)0)), (csyme))->locmask) & (1 << (SYFI_DefnNum ))) ? ((((((csyme)->kind == SYME_Trigger ? libGetAllSymes( (csyme)->lib) : ((void*)0)), (csyme))->locmask) & ( 1 << (SYFI_DefnNum))) ? ((csyme)->fieldv)[symeIndex( csyme,SYFI_DefnNum)] : (symeFieldInfo[SYFI_DefnNum].def)) : symeGetFieldFn (csyme,SYFI_DefnNum))), |
| 3788 | symeConstNum(syme)(((AInt) (SYFI_ConstInfo < (8 * sizeof(int)) && !( ((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->hasmask) & (1 << (SYFI_ConstInfo ))) ? (symeFieldInfo[SYFI_ConstInfo].def) : (((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)->lib) : ((void*)0 )), (syme))->locmask) & (1 << (SYFI_ConstInfo))) ? ((((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme )->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_ConstInfo))) ? ((syme)->fieldv)[symeIndex(syme,SYFI_ConstInfo )] : (symeFieldInfo[SYFI_ConstInfo].def)) : symeGetFieldFn(syme ,SYFI_ConstInfo))) & 0xFFFF), |
| 3789 | symeConstNum(csyme)(((AInt) (SYFI_ConstInfo < (8 * sizeof(int)) && !( ((((csyme)->kind == SYME_Trigger ? libGetAllSymes((csyme)-> lib) : ((void*)0)), (csyme))->hasmask) & (1 << ( SYFI_ConstInfo))) ? (symeFieldInfo[SYFI_ConstInfo].def) : ((( ((csyme)->kind == SYME_Trigger ? libGetAllSymes((csyme)-> lib) : ((void*)0)), (csyme))->locmask) & (1 << ( SYFI_ConstInfo))) ? ((((((csyme)->kind == SYME_Trigger ? libGetAllSymes ((csyme)->lib) : ((void*)0)), (csyme))->locmask) & ( 1 << (SYFI_ConstInfo))) ? ((csyme)->fieldv)[symeIndex (csyme,SYFI_ConstInfo)] : (symeFieldInfo[SYFI_ConstInfo].def) ) : symeGetFieldFn(csyme,SYFI_ConstInfo))) & 0xFFFF), |
| 3790 | symePretty(syme)); |
| 3791 | |
| 3792 | |
| 3793 | /* Transfer implementation details */ |
| 3794 | symeTransferImplInfo(syme, csyme); |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | |
| 3799 | /* Return a copy of the modified symes */ |
| 3800 | return esymes; |
| 3801 | } |
| 3802 | |
| 3803 | SymbolTSet |
| 3804 | tfGetDomExportNames(TForm tf) |
| 3805 | { |
| 3806 | SymeList exports; |
| 3807 | SymbolTSet symbols; |
| 3808 | |
| 3809 | if (tfDomExportNames(tf)) |
| 3810 | return tfDomExportNames(tf); |
| 3811 | |
| 3812 | exports = tfGetDomExports(tf); |
| 3813 | |
| 3814 | symbols = tsetCreate(Symbol)(Symbol_tsetPointer->Create)(); |
| 3815 | |
| 3816 | while (exports != listNil(Syme)((SymeList) 0)) { |
| 3817 | tsetAdd(Symbol)(Symbol_tsetPointer->Add)(symbols, symeId(car(exports))((((exports)->first))->id)); |
| 3818 | exports = cdr(exports)((exports)->rest); |
| 3819 | } |
| 3820 | |
| 3821 | return symbols; |
| 3822 | } |
| 3823 | |
| 3824 | /* |
| 3825 | * Called on a domain to get the symbol meanings which are |
| 3826 | * exported from the domain. |
| 3827 | */ |
| 3828 | SymeList |
| 3829 | tfGetDomExports(TForm tf) |
| 3830 | { |
| 3831 | TFormList hl; |
| 3832 | |
| 3833 | tf = tfDefineeType(tf); |
| 3834 | |
| 3835 | tf = tfIgnoreExceptions(tf); |
| 3836 | |
| 3837 | if (tfHasSelf(tf)((tf)->hasSelf) && tfIsId(tf)((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Id) && symeExtension(tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0))) { |
| 3838 | return tfGetDomExports(tfFrSyme(stabFile(), symeExtensionFull(tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0)))); |
| 3839 | } |
| 3840 | |
| 3841 | if (tfDomExports(tf) || tfIsUnknown(tf)(((tf)->tag) == TF_Unknown) || tfIsNone(tf)((((tf)->tag) == TF_Multiple) && tfMultiArgc(tf) == 0)) |
| 3842 | return tfDomExports(tf); |
| 3843 | |
| 3844 | if (!tfIsMeaning(tf)(((tf)->state)>=TF_State_Meaning)) { |
| 3845 | tfGetExportError(tf, "domain"); |
| 3846 | return tfDomExports(tf); |
| 3847 | } |
| 3848 | |
| 3849 | if (DEBUG(tfImport)tfImportDebug) { |
| 3850 | fprintf(dbOut, "(tfGetDomExports: from "); |
| 3851 | tfPrint(dbOut, tf); |
| 3852 | fnewline(dbOut); |
| 3853 | } |
| 3854 | |
| 3855 | /* |
| 3856 | * Collect the domain exports from the type form. |
| 3857 | */ |
| 3858 | if (tfIsNotDomain(tf)((((tf)->tag) == TF_Type) || (((tf)->tag) == TF_With) || ((((tf)->tag) == TF_Syntax) && ((((tf)->__absyn ))->abHdr.tag == (AB_With))) || (((tf)->tag) == TF_Join ) || (((tf)->tag) == TF_If) || (((tf)->tag) == TF_Third ))) |
| 3859 | tfSetDomExports(tf, listNil(Syme)((SymeList) 0)); |
| 3860 | |
| 3861 | else if (tfIsAdd(tf)(((tf)->tag) == TF_Add)) |
| 3862 | tfSetDomExports(tf, tfSymes(tf)((tf)->symes)); |
| 3863 | |
| 3864 | else if (tfIsSym(tf)( (((tf)->tag)) < TF_SYM_LIMIT) || tfIsSyntax(tf)(((tf)->tag) == TF_Syntax)) |
| 3865 | tfSetDomExports(tf, listNil(Syme)((SymeList) 0)); |
| 3866 | |
| 3867 | else if (tfIsLibrary(tf)) |
| 3868 | tfSetDomExports(tf, libGetSymes(tfLibraryLib(tf))); |
| 3869 | |
| 3870 | else if (tfIsArchive(tf)) |
| 3871 | tfSetDomExports(tf, arGetSymes(tfArchiveAr(tf))); |
| 3872 | |
| 3873 | else { |
| 3874 | SymeList exps, vexps; |
| 3875 | TForm cat, val = (TForm)NULL((void*)0); |
| 3876 | if (tfIsEnum(tf)(((tf)->tag) == TF_Enumerate) || tfIsRecord(tf)(((tf)->tag) == TF_Record) || tfIsRawRecord(tf)(((tf)->tag) == TF_RawRecord) || |
| 3877 | tfIsTrailingArray(tf)(((tf)->tag) == TF_TrailingArray) || tfIsUnion(tf)(((tf)->tag) == TF_Union)) |
| 3878 | tfSetDomExports(tf, listCopy(Syme)(Syme_listPointer->Copy)(tfSymes(tf)((tf)->symes))); |
| 3879 | tfGetDomSelf(tf); |
| 3880 | cat = tfGetCategory(tf); |
| 3881 | tfFollow(cat)((cat) = tfFollowFn(cat)); |
| 3882 | |
| 3883 | assert(tfIsDefine(cat) ? (tfDefineVal(cat) != tf) : true)do { if (!((((cat)->tag) == TF_Define) ? (tfFollowArg(cat, 1) != tf) : 1)) _do_assert(("tfIsDefine(cat) ? (tfDefineVal(cat) != tf) : true" ),"tform.c",3883); } while (0); |
| 3884 | |
| 3885 | exps = tfGetCatExports(cat); |
| 3886 | if (tfIsDefine(cat)(((cat)->tag) == TF_Define)) |
| 3887 | val = tfDefineVal(cat)tfFollowArg(cat, 1); |
| 3888 | |
| 3889 | if (DEBUG(symeRefresh)symeRefreshDebug) { |
| 3890 | if (val && !tfIsAdd(val)(((val)->tag) == TF_Add)) { |
| 3891 | (void)fprintf(dbOut, "\n-------- (not add)\n"); |
| 3892 | (void)tfPrintDb(val); |
| 3893 | } |
| 3894 | } |
| 3895 | |
| 3896 | if (val && tfIsAdd(val)(((val)->tag) == TF_Add)) { |
| 3897 | vexps = tfGetDomExports(val); |
| 3898 | exps = tfMangleSymes(tf, cat, exps, vexps); |
| 3899 | } |
| 3900 | tfAddDomExports(tf, exps); |
| 3901 | tfGetDomCascades(tf); |
| 3902 | } |
| 3903 | |
| 3904 | /* |
| 3905 | * Collect the conditional exports from the has questions. |
| 3906 | */ |
| 3907 | for (hl = tfQueries(tf)((tf)->queries); hl; hl = cdr(hl)((hl)->rest)) |
| 3908 | tfAddHasExports(tf, car(hl)((hl)->first)); |
| 3909 | |
| 3910 | tfImportDEBUGif (!tfImportDebug) { } else afprintf(dbOut, ")\n"); |
| 3911 | |
| 3912 | tfValidateDomExports(tf); |
| 3913 | return tfDomExports(tf); |
| 3914 | } |
| 3915 | |
| 3916 | /* |
| 3917 | * Called on a category to get the symbol meanings which are |
| 3918 | * exported by domains of this category. |
| 3919 | */ |
| 3920 | SymeList |
| 3921 | tfGetCatExports(TForm cat) |
| 3922 | { |
| 3923 | static int count = 0; |
| 3924 | int serialThis = count++; |
| 3925 | tfFollow(cat)((cat) = tfFollowFn(cat)); |
| 3926 | if (tfIsDefineOfType(cat)) |
| 3927 | return tfGetDomExports(tfDefineVal(cat)tfFollowArg(cat, 1)); |
| 3928 | |
| 3929 | cat = tfDefineeType(cat); |
| 3930 | |
| 3931 | if (tfCatExports(cat) || tfIsUnknown(cat)(((cat)->tag) == TF_Unknown) || tfIsNone(cat)((((cat)->tag) == TF_Multiple) && tfMultiArgc(cat) == 0) || |
| 3932 | !tfHasCatExports(cat)) |
| 3933 | return tfCatExports(cat); |
| 3934 | |
| 3935 | if (!tfIsMeaning(cat)(((cat)->state)>=TF_State_Meaning)) { |
| 3936 | tfGetExportError(cat, "category"); |
| 3937 | return tfCatExports(cat); |
| 3938 | } |
| 3939 | |
| 3940 | if (DEBUG(tfCat)tfCatDebug) { |
| 3941 | afprintf(dbOut, "(tfGetCatExports:%d: from %pTForm\n", serialThis, cat); |
| 3942 | } |
| 3943 | |
| 3944 | tfGetCatSelf(cat); |
| 3945 | tfGetCatCascades(cat); |
| 3946 | |
| 3947 | if (tfIsWith(cat)(((cat)->tag) == TF_With) && tfUseCatExports(cat)(((((tfFollowArg(cat, 0))->tag) == TF_Multiple) && tfMultiArgc(tfFollowArg(cat, 0)) == 0) && ((((tfFollowArg (cat, 1))->tag) == TF_Multiple) && tfMultiArgc(tfFollowArg (cat, 1)) == 0))) |
| 3948 | tfAddCatExports(cat,tfGetCatExportsFrParents(tfParents(cat)((cat)->parents))); |
| 3949 | |
| 3950 | else if (tfIsWith(cat)(((cat)->tag) == TF_With)) |
| 3951 | tfGetCatExportsFrWith(cat); |
| 3952 | |
| 3953 | else if (tfIsIf(cat)(((cat)->tag) == TF_If)) |
| 3954 | tfGetCatExportsFrIf(cat); |
| 3955 | |
| 3956 | else if (tfIsJoin(cat)(((cat)->tag) == TF_Join)) |
| 3957 | tfGetCatExportsFrJoin(cat); |
| 3958 | |
| 3959 | else if (tfIsMeet(cat)(((cat)->tag) == TF_Meet)) |
| 3960 | tfGetCatExportsFrMeet(cat); |
| 3961 | |
| 3962 | else |
| 3963 | tfAddCatExports(cat, tfGetThdExports(tfGetCategory(cat))); |
| 3964 | |
| 3965 | if (DEBUG(tfCat)tfCatDebug) { |
| 3966 | SymeList symes = tfCatExports(cat); |
| 3967 | if (symes) { |
| 3968 | int n = 0; |
| 3969 | afprintf(dbOut, " Exports for %pTForm: [\n", cat); |
| 3970 | while (symes != listNil(Syme)((SymeList) 0)) { |
| 3971 | Syme syme = car(symes)((symes)->first); |
| 3972 | symes = cdr(symes)((symes)->rest); |
| 3973 | |
| 3974 | afprintf(dbOut, |
| 3975 | "%d %s %s %pAbSynList\n", n, symeString(syme)((((syme)->id))->str), symeHasDefault(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->bits) & (0x0080)) ? "DEF" : "NO", |
| 3976 | symeCondition(syme)); |
| 3977 | afprintf(dbOut, |
| 3978 | "%d %s: %pTForm\n", n, symeString(syme)((((syme)->id))->str), symeType(syme)); |
| 3979 | n++; |
| 3980 | } |
| 3981 | afprintf(dbOut, " ]\n", cat); |
| 3982 | } |
| 3983 | } |
| 3984 | |
| 3985 | tfCatDEBUGif (!tfCatDebug) { } else afprintf(dbOut, " %d)\n", serialThis); |
| 3986 | |
| 3987 | tfAuditExportList(tfCatExports(cat)); |
| 3988 | return tfCatExports(cat); |
| 3989 | } |
| 3990 | |
| 3991 | /* |
| 3992 | * Called on the type of a category to get the symbol meanings which are |
| 3993 | * exported by domains of this category. |
| 3994 | */ |
| 3995 | SymeList |
| 3996 | tfGetThdExports(TForm thd) |
| 3997 | { |
| 3998 | thd = tfDefineeType(thd); |
| 3999 | |
| 4000 | if (tfThdExports(thd) || tfIsUnknown(thd)(((thd)->tag) == TF_Unknown) || tfIsNone(thd)((((thd)->tag) == TF_Multiple) && tfMultiArgc(thd) == 0) || |
| 4001 | !tfHasThdExports(thd)) |
| 4002 | return tfThdExports(thd); |
| 4003 | |
| 4004 | if (!tfIsMeaning(thd)(((thd)->state)>=TF_State_Meaning)) { |
| 4005 | tfGetExportError(thd, "third-order type"); |
| 4006 | return tfThdExports(thd); |
| 4007 | } |
| 4008 | |
| 4009 | if (DEBUG(tfCat)tfCatDebug) { |
| 4010 | fprintf(dbOut, "(tfGetThdExports: from "); |
| 4011 | tfPrint(dbOut, thd); |
| 4012 | fnewline(dbOut); |
| 4013 | } |
| 4014 | |
| 4015 | tfGetThdSelf(thd); |
| 4016 | tfGetThdCascades(thd); |
| 4017 | |
| 4018 | if (tfIsThird(thd)(((thd)->tag) == TF_Third) && tfUseThdExports(thd)(((((tfFollowArg(thd, 0))->tag) == TF_Multiple) && tfMultiArgc(tfFollowArg(thd, 0)) == 0))) { |
| 4019 | tfAddThdExports(thd,tfGetCatExportsFrParents(tfParents(thd)((thd)->parents))); |
| 4020 | tfAddThdExports(thd,tfSymes(thd)((thd)->symes)); |
| 4021 | } |
| 4022 | |
| 4023 | else if (tfIsThird(thd)(((thd)->tag) == TF_Third)) { |
| 4024 | tfAddThdExports(thd,tfGetCatExports(tfThirdRestrictions(thd)tfFollowArg(thd, 0))); |
| 4025 | tfAddThdExports(thd,tfSymes(thd)((thd)->symes)); |
| 4026 | } |
| 4027 | |
| 4028 | tfCatDEBUGif (!tfCatDebug) { } else afprintf(dbOut, ")\n"); |
| 4029 | |
| 4030 | tfAuditExportList(tfThdExports(thd)); |
| 4031 | return tfThdExports(thd); |
| 4032 | } |
| 4033 | |
| 4034 | /* |
| 4035 | * tfGet...Exports helper functions. |
| 4036 | */ |
| 4037 | |
| 4038 | localstatic SymeList |
| 4039 | tfGetCatExportsFrParents(SymeList symes) |
| 4040 | { |
| 4041 | static int count = 0; |
| 4042 | SymeTSet oldTbl = tsetCreateCustom(Syme)(Syme_tsetPointer->CreateCustom)(symeHashFn, symeEqual); |
| 4043 | SymeList nsymes; |
| 4044 | SymeList queue = listCopy(Syme)(Syme_listPointer->Copy)(symes); |
| 4045 | SymeList xsymes = listNil(Syme)((SymeList) 0); |
| 4046 | SefoList cond; |
| 4047 | |
| 4048 | while (queue) { |
| 4049 | int serialThis = count++; |
| 4050 | Syme syme = car(queue)((queue)->first); |
| 4051 | SymeList cell = queue; |
| 4052 | queue = cdr(queue)((queue)->rest); |
| 4053 | |
| 4054 | /* Move syme to xsymes. */ |
| 4055 | setcdr(cell, xsymes)((cell)->rest = (xsymes)); |
| 4056 | xsymes = cell; |
| 4057 | |
| 4058 | if (!symeIsSelfSelf(syme)(((syme)->id) == ssymSelfSelf)) continue; |
| 4059 | |
| 4060 | if (DEBUG(tfParent)tfParentDebug) { |
| 4061 | afprintf(dbOut, "(tfCatExports:%d: expanding %pTForm %pAbSynList\n", |
| 4062 | serialThis, |
| 4063 | symeType(syme), symeCondition(syme)); |
| 4064 | } |
| 4065 | |
| 4066 | nsymes = tfGetCatParents(symeType(syme), true1); |
| 4067 | cond = symeCondition(syme); |
| 4068 | if (cond) nsymes = tfGetCatExportsCond(nsymes, cond, true1); |
| 4069 | |
| 4070 | if (DEBUG(tfParent)tfParentDebug) { |
| 4071 | afprintf(dbOut, "tfCatExports:%d: into %pSymeList)\n", serialThis, nsymes); |
| 4072 | } |
| 4073 | |
| 4074 | nsymes = tfGetCatExportsFilterTable(oldTbl, nsymes); |
| 4075 | tsetAddAll(Syme)(Syme_tsetPointer->AddAll)(oldTbl, nsymes); |
| 4076 | queue = listNConcat(Syme)(Syme_listPointer->NConcat)(listCopy(Syme)(Syme_listPointer->Copy)(nsymes), queue); |
| 4077 | } |
| 4078 | tsetFree(Syme)(Syme_tsetPointer->Free)(oldTbl); |
| 4079 | |
| 4080 | return listNReverse(Syme)(Syme_listPointer->NReverse)(xsymes); |
| 4081 | } |
| 4082 | |
| 4083 | localstatic SymeList |
| 4084 | tfGetCatExportsCond(SymeList symes0, SefoList conds0, Bool pos) |
| 4085 | { |
| 4086 | SymeList symes, nsymes = listNil(Syme)((SymeList) 0); |
| 4087 | SefoList conds; |
| 4088 | SefoList reversedConds0 = listReverse(Sefo)(Sefo_listPointer->Reverse)(conds0); |
| 4089 | |
| 4090 | /* Reverse conditions so that any dependency in evaluation is preserved. |
| 4091 | * For example S has Ring and X has Algebra S |
| 4092 | */ |
| 4093 | for (symes = symes0; symes; symes = cdr(symes)((symes)->rest)) { |
| 4094 | Syme syme = car(symes)((symes)->first); |
| 4095 | Syme nsyme; |
| 4096 | if (listContainsAllq(Sefo)(Sefo_listPointer->ContainsAllq)(symeCondition(syme), conds0)) { |
| 4097 | nsymes = listCons(Syme)(Syme_listPointer->Cons)(syme, nsymes); |
| 4098 | } |
| 4099 | else { |
| 4100 | nsyme = symeCopy(syme); |
| 4101 | for (conds = reversedConds0; conds; conds = cdr(conds)((conds)->rest)) { |
| 4102 | symeAddCondition(nsyme, car(conds)((conds)->first), pos); |
| 4103 | } |
| 4104 | nsymes = listCons(Syme)(Syme_listPointer->Cons)(nsyme, nsymes); |
| 4105 | } |
| 4106 | } |
| 4107 | listFree(Sefo)(Sefo_listPointer->Free)(reversedConds0); |
| 4108 | |
| 4109 | return listNReverse(Syme)(Syme_listPointer->NReverse)(nsymes); |
| 4110 | } |
| 4111 | |
| 4112 | localstatic SymeList |
| 4113 | tfGetCatExportsFilterTable(SymeTSet oldTbl, SymeList nsymes) |
| 4114 | { |
| 4115 | SymeList symes, rsymes = listNil(Syme)((SymeList) 0); |
| 4116 | |
| 4117 | /* Remove symes for %% which have been seen before. */ |
| 4118 | for (symes = nsymes; symes; symes = cdr(symes)((symes)->rest)) |
| 4119 | if (!(symeIsSelfSelf(car(symes))(((((symes)->first))->id) == ssymSelfSelf) && |
| 4120 | tsetMember(Syme)(Syme_tsetPointer->Member)(oldTbl, car(symes)((symes)->first)))) |
| 4121 | rsymes = listCons(Syme)(Syme_listPointer->Cons)(car(symes)((symes)->first), rsymes); |
| 4122 | |
| 4123 | listFree(Syme)(Syme_listPointer->Free)(nsymes); |
| 4124 | return listNReverse(Syme)(Syme_listPointer->NReverse)(rsymes); |
| 4125 | } |
| 4126 | |
| 4127 | localstatic SymeList |
| 4128 | tfGetCatExportsFrWith(TForm cat) |
| 4129 | { |
| 4130 | TForm tfb = tfWithBase(cat)tfFollowArg(cat, 0); |
| 4131 | TForm tfw = tfWithWithin(cat)tfFollowArg(cat, 1); |
| 4132 | SymeList bsymes, wsymes; |
| 4133 | |
| 4134 | bsymes = tfGetCatExports(tfb); |
| 4135 | |
| 4136 | tfFollow(tfw)((tfw) = tfFollowFn(tfw)); |
| 4137 | if (tfCatExports(tfw)) |
| 4138 | wsymes = tfCatExports(tfw); |
| 4139 | |
| 4140 | else if (tfIsDeclare(tfw)(((tfw)->tag) == TF_Declare)) |
| 4141 | wsymes = tfSymes(tfw)((tfw)->symes); |
| 4142 | |
| 4143 | else if (tfHasExpr(tfw)((tfw)->__absyn != 0)) |
| 4144 | wsymes = tfGetCatImportsFrWith(tfGetExpr(tfw)((tfw)->__absyn), bsymes); |
| 4145 | |
| 4146 | else |
| 4147 | wsymes = tfGetCatExports(tfw); |
| 4148 | |
| 4149 | tfSetCatExports(tfw, wsymes); |
| 4150 | |
| 4151 | tfAddCatExports(cat, bsymes); |
| 4152 | tfAddCatExports(cat, wsymes); |
| 4153 | |
| 4154 | return tfCatExports(cat); |
| 4155 | } |
| 4156 | |
| 4157 | localstatic SymeList |
| 4158 | tfGetCatExportsFrIf(TForm cat) |
| 4159 | { |
| 4160 | SymeList tsymes, esymes, symes = listNil(Syme)((SymeList) 0); |
| 4161 | SymeList mods = tfGetCatSelf(cat); |
| 4162 | Sefo cond; |
| 4163 | |
| 4164 | tfFollow(cat->argv[0])((cat->argv[0]) = tfFollowFn(cat->argv[0])); |
| 4165 | |
| 4166 | if (tfNeedsSefo(cat->argv[0])((cat->argv[0])->state == TF_State_NeedsSefo)) |
| 4167 | tiTopFns()->tiTfSefo(stabFile(), cat->argv[0]); |
| 4168 | |
| 4169 | cond = tfIfCond(cat)tfToAbSyn(tfFollowArg(cat, 0)); |
| 4170 | tsymes = tfGetCatExports(tfIfThen(cat)tfFollowArg(cat, 1)); |
| 4171 | symes = tfJoinExportLists(mods, symes, tsymes, cond); |
| 4172 | |
| 4173 | cond = abNewNot(sposNone, cond)abNew(AB_Not, sposNone,1, cond); |
| 4174 | esymes = tfGetCatExports(tfIfElse(cat)tfFollowArg(cat, 2)); |
| 4175 | symes = tfJoinExportLists(mods, symes, esymes, cond); |
| 4176 | |
| 4177 | tfSetCatExports(cat, symes); |
| 4178 | |
| 4179 | return symes; |
| 4180 | } |
| 4181 | |
| 4182 | localstatic SymeList |
| 4183 | tfGetCatExportsFrJoin(TForm cat) |
| 4184 | { |
| 4185 | SymeList nsymes, symes = tfCatExports(cat); |
| 4186 | SymeList mods = tfGetCatSelf(cat); |
| 4187 | Length i; |
| 4188 | |
| 4189 | for (i = 0; i < tfJoinArgc(cat)((cat)->argc); i += 1) { |
| 4190 | nsymes = tfGetCatExports(tfJoinArgN(cat, i)tfFollowArg(cat, i)); |
| 4191 | symes = tfJoinExportLists(mods, symes, nsymes, NULL((void*)0)); |
| 4192 | } |
| 4193 | |
| 4194 | tfSetCatExports(cat, symes); |
| 4195 | |
| 4196 | return symes; |
| 4197 | } |
| 4198 | |
| 4199 | localstatic SymeList |
| 4200 | tfGetCatExportsFrMeet(TForm cat) |
| 4201 | { |
| 4202 | SymeList nsymes, symes = tfCatExports(cat); |
| 4203 | SymeList mods = tfGetCatSelf(cat); |
| 4204 | Length i; |
| 4205 | |
| 4206 | nsymes = tfGetCatExports(tfMeetArgN(cat, int0)tfFollowArg(cat, ((int) 0))); |
| 4207 | symes = tfJoinExportLists(mods, symes, nsymes, NULL((void*)0)); |
| 4208 | for (i = 1; i < tfMeetArgc(cat)((cat)->argc); i += 1) { |
| 4209 | nsymes = tfGetCatExports(tfMeetArgN(cat, i)tfFollowArg(cat, i)); |
| 4210 | symes = tfMeetExportLists(mods, symes, nsymes, NULL((void*)0)); |
| 4211 | } |
| 4212 | |
| 4213 | tfSetCatExports(cat, symes); |
| 4214 | |
| 4215 | return symes; |
| 4216 | } |
| 4217 | |
| 4218 | /****************************************************************************** |
| 4219 | * |
| 4220 | * :: Type form imported symes. |
| 4221 | * |
| 4222 | *****************************************************************************/ |
| 4223 | |
| 4224 | Syme |
| 4225 | tfHasDomExportMod(TForm tf, SymeList mods, Symbol sym, TForm type) |
| 4226 | { |
| 4227 | SymeList sl; |
| 4228 | |
| 4229 | for (sl = tfGetDomExports(tf); sl; sl = cdr(sl)((sl)->rest)) { |
| 4230 | Syme syme = car(sl)((sl)->first); |
| 4231 | if (symeId(syme)((syme)->id) != sym) continue; |
| 4232 | if (!tformEqualMod(mods, symeType(syme), type)) continue; |
| 4233 | return syme; |
| 4234 | } |
| 4235 | return NULL((void*)0); |
| 4236 | } |
| 4237 | |
| 4238 | Syme |
| 4239 | tfHasDomImport(TForm tf, Symbol sym, TForm type) |
| 4240 | { |
| 4241 | SymeList sl; |
| 4242 | |
| 4243 | for (sl = tfGetDomImportsByName(tf, sym); sl; sl = cdr(sl)((sl)->rest)) { |
| 4244 | Syme syme = car(sl)((sl)->first); |
| 4245 | assert(symeId(syme) == sym)do { if (!(((syme)->id) == sym)) _do_assert(("symeId(syme) == sym" ),"tform.c",4245); } while (0); |
| 4246 | if (tformEqual(symeType(syme), type)) |
| 4247 | return syme; |
| 4248 | } |
| 4249 | return NULL((void*)0); |
| 4250 | } |
| 4251 | |
| 4252 | localstatic Syme |
| 4253 | tfGetBuiltinSyme(TForm tf, Symbol sym) |
| 4254 | { |
| 4255 | SymeList symes; |
| 4256 | Syme syme0 = NULL((void*)0); |
| 4257 | |
| 4258 | assert(tfDomImports(tf))do { if (!(tfDomImports(tf))) _do_assert(("tfDomImports(tf)") ,"tform.c",4258); } while (0); |
| 4259 | for (symes = symeSetList(tfDomImports(tf)); symes; symes = cdr(symes)((symes)->rest)) { |
| 4260 | Syme syme = car(symes)((symes)->first); |
| 4261 | if (symeId(syme)((syme)->id) == sym) |
| 4262 | syme0 = syme; |
| 4263 | } |
| 4264 | return syme0; |
| 4265 | } |
| 4266 | |
| 4267 | /****************************************************************************** |
| 4268 | * |
| 4269 | * :: Type imports and exports |
| 4270 | * |
| 4271 | *****************************************************************************/ |
| 4272 | |
| 4273 | extern SymeSet |
| 4274 | tfDomImports(TForm tf) |
| 4275 | { |
| 4276 | return tf->domImports; |
| 4277 | } |
| 4278 | |
| 4279 | extern void |
| 4280 | tfSetDomImports(TForm tf, SymeSet symeSet) |
| 4281 | { |
| 4282 | tf->domImports = symeSet; |
| 4283 | } |
| 4284 | |
| 4285 | extern SymeList |
| 4286 | tfDomExports(TForm tf) |
| 4287 | { |
| 4288 | return tf->domExports; |
| 4289 | } |
| 4290 | |
| 4291 | extern void |
| 4292 | tfSetDomExports(TForm tf, SymeList symeList) |
| 4293 | { |
| 4294 | tf->domExports = symeList; |
| 4295 | } |
| 4296 | |
| 4297 | extern SymbolTSet |
| 4298 | tfDomExportNames(TForm tf) |
| 4299 | { |
| 4300 | return tf->domExportNames; |
| 4301 | } |
| 4302 | |
| 4303 | extern void |
| 4304 | tfSetDomExportNames(TForm tf, SymbolTSet symbols) |
| 4305 | { |
| 4306 | tf->domExportNames = symbols; |
| 4307 | } |
| 4308 | |
| 4309 | extern SymeList |
| 4310 | tfCatExports(TForm tf) |
| 4311 | { |
| 4312 | return tf->catExports; |
| 4313 | } |
| 4314 | |
| 4315 | extern void |
| 4316 | tfSetCatExports(TForm tf, SymeList symeList) |
| 4317 | { |
| 4318 | tf->catExports = symeList; |
| 4319 | } |
| 4320 | |
| 4321 | extern SymeList |
| 4322 | tfThdExports(TForm tf) |
| 4323 | { |
| 4324 | return tf->thdExports; |
| 4325 | } |
| 4326 | |
| 4327 | extern void |
| 4328 | tfSetThdExports(TForm tf, SymeList symeList) |
| 4329 | { |
| 4330 | tf->thdExports = symeList; |
| 4331 | } |
| 4332 | |
| 4333 | |
| 4334 | /* |
| 4335 | * Called on a domain to get the symbol meanings to include |
| 4336 | * in the current scope. Use this in preference to the older |
| 4337 | * tfGetDomImports() to reduce the chance of polluting the |
| 4338 | * top-level stab for the current file. |
| 4339 | */ |
| 4340 | |
| 4341 | localstatic Bool |
| 4342 | tfImportsPending(TForm tf) |
| 4343 | { |
| 4344 | return symeSetList(tfDomImports(tf)) == listNil(Syme)((SymeList) 0); |
| 4345 | } |
| 4346 | |
| 4347 | SymeList |
| 4348 | tfStabGetDomImports(Stab stab, TForm tf) |
| 4349 | { |
| 4350 | return symeSetList(tfStabGetDomImportSet(stab, tf)); |
| 4351 | } |
| 4352 | |
| 4353 | SymeSet |
| 4354 | tfStabGetDomImportSet(Stab stab, TForm tf) |
| 4355 | { |
| 4356 | tf = tfDefineeType(tf); |
| 4357 | |
| 4358 | tf = tfIgnoreExceptions(tf); |
| 4359 | |
| 4360 | if (tfDomImports(tf) && !tfImportsPending(tf)) |
| 4361 | return tfDomImports(tf); |
| 4362 | if (tfDomImports(tf)) { |
| 4363 | symeSetFree(tfDomImports(tf)); |
| 4364 | tfSetDomImports(tf, NULL((void*)0)); |
| 4365 | } |
| 4366 | tfStabCreateDomImportSet(stab, tf); |
| 4367 | |
| 4368 | return tfDomImports(tf); |
| 4369 | } |
| 4370 | |
| 4371 | localstatic SymeSet |
| 4372 | tfStabCreateDomImportSet(Stab stab, TForm tf) |
| 4373 | { |
| 4374 | static int count = 0; |
| 4375 | int serialThis = count++; |
| 4376 | SymeSet symeSet; |
| 4377 | SymeList xsymes, symes; |
| 4378 | |
| 4379 | if (DEBUG(tfImport)tfImportDebug) { |
| 4380 | afprintf(dbOut, "(tfStabGetDomImports:%d: from %pTForm\n", serialThis, tf); |
| 4381 | } |
| 4382 | |
| 4383 | xsymes = tfGetDomExports(tf); |
| 4384 | |
| 4385 | symes = symeListSubstSelf(stab, tf, xsymes); |
| 4386 | |
| 4387 | if (tfConditions(tf) != NULL((void*)0)) { |
| 4388 | SymeList sl = symes; |
| 4389 | while (sl != listNil(Syme)((SymeList) 0)) { |
| 4390 | Syme syme = car(sl)((sl)->first); |
| 4391 | TForm symeTf = symeType(syme); |
| 4392 | tfDEBUGif (!tfDebug) { } else afprintf(dbOut, "%d: Setting imported condition %s %pTForm\n", |
| 4393 | serialThis, symeString(syme)((((syme)->id))->str), symeTf); |
| 4394 | tfSetConditions(symeTf, tfConditions(tf))(symeTf->conditions = (tfConditions(tf))); |
| 4395 | symeSetConditionContext(syme, tfConditionalAbSyn(tf))(symeSetFieldVal = ((AInt) (tfConditionalAbSyn(tf))), (((((syme )->kind == SYME_Trigger ? libGetAllSymes((syme)->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_ConditionContext ))) ? (((syme)->fieldv)[symeIndex(syme,SYFI_ConditionContext )] = (symeSetFieldVal)) : !((syme)->full) && symeSetFieldVal == (symeFieldInfo[SYFI_ConditionContext].def) ? symeSetFieldVal : symeSetFieldFn(syme,SYFI_ConditionContext,symeSetFieldVal) ); |
| 4396 | sl = cdr(sl)((sl)->rest); |
| 4397 | } |
| 4398 | |
| 4399 | } |
| 4400 | |
| 4401 | symes = symeListCheckCondition(symes); |
| 4402 | |
| 4403 | symeSet = symeSetFrSymes(symes); |
| 4404 | |
| 4405 | tfSetDomImports(tf, symeSet); |
| 4406 | |
| 4407 | if (tfIsBasicLib(tf)) |
| 4408 | tfInitBasicTypes(tf); |
| 4409 | |
| 4410 | if (DEBUG(tfImport)tfImportDebug) { |
| 4411 | symeListPrintDb(symes); |
| 4412 | fprintf(dbOut, " %d)\n", serialThis); |
| 4413 | tfPrint(dbOut, tf); |
| 4414 | fnewline(dbOut); |
| 4415 | } |
| 4416 | |
| 4417 | tfValidateDomImports(tf); |
| 4418 | |
| 4419 | return symeSet; |
| 4420 | } |
| 4421 | |
| 4422 | /* |
| 4423 | * Called on a domain to get the symbol meanings to include |
| 4424 | * in the current scope. This may cause tforms to be imported |
| 4425 | * into stabFile() which can cause grief (e.g. bug1192) so |
| 4426 | * use tfStabGetDomImports() if you have a localised stab. |
| 4427 | */ |
| 4428 | SymeList |
| 4429 | tfGetDomImports(TForm tf) |
| 4430 | { |
| 4431 | /* |
| 4432 | * This use of stabFile() is extremely unfortunate because it |
| 4433 | * associates the tform with the top-level of the file being |
| 4434 | * compiled. This allows inner symbols to escape their stab |
| 4435 | * levels and jump directly to the top. |
| 4436 | */ |
| 4437 | return symeSetList(tfStabGetDomImportSet(stabFile(), tf)); |
| 4438 | } |
| 4439 | |
| 4440 | SymeSet |
| 4441 | tfGetDomImportSet(TForm tf) |
| 4442 | { |
| 4443 | /* |
| 4444 | * This use of stabFile() is extremely unfortunate because it |
| 4445 | * associates the tform with the top-level of the file being |
| 4446 | * compiled. This allows inner symbols to escape their stab |
| 4447 | * levels and jump directly to the top. |
| 4448 | */ |
| 4449 | return tfStabGetDomImportSet(stabFile(), tf); |
| 4450 | } |
| 4451 | |
| 4452 | SymeList |
| 4453 | tfGetDomImportsByName(TForm tf, Symbol sym) |
| 4454 | { |
| 4455 | return tfStabGetDomImportsByName(stabFile(), tf, sym); |
| 4456 | } |
| 4457 | |
| 4458 | SymeList |
| 4459 | tfStabGetDomImportsByName(Stab stab, TForm tf, Symbol sym) |
| 4460 | { |
| 4461 | return symeSetSymesForSymbol(tfStabGetDomImportSet(stab, tf), sym); |
| 4462 | } |
| 4463 | |
| 4464 | SymeList |
| 4465 | tfGetCatImportsFrWith(Sefo sefo, SymeList bsymes) |
| 4466 | { |
| 4467 | SymeList xsymes, isymes, dsymes, csymes, symes; |
| 4468 | Length i, argc; |
| 4469 | Sefo *argv; |
| 4470 | Sefo id; |
| 4471 | TForm cat; |
| 4472 | |
| 4473 | /*!! assert(tfHasCatExportsFrWith(sefo)); */ |
| 4474 | |
| 4475 | AB_SEQ_ITER(sefo, argc, argv){ switch (((sefo)->abHdr.tag)) { case AB_Nothing: argc = 0 ; argv = 0; break; case AB_Sequence: argc = ((sefo)->abHdr .argc); argv = ((sefo)->abGen.data.argv); break; default: argc = 1; argv = &sefo; break; }; }; |
| 4476 | |
| 4477 | xsymes = isymes = dsymes = listNil(Syme)((SymeList) 0); |
| 4478 | for (i = 0; i < argc; i++) { |
| 4479 | id = abDefineeIdOrElse(argv[i], NULL((void*)0)); |
| 4480 | |
| 4481 | if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Nothing) |
| 4482 | continue; |
| 4483 | |
| 4484 | /* Defaults package. */ |
| 4485 | else if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Default) { |
| 4486 | AbSyn def = argv[i]->abDefault.body; |
| 4487 | symes = tfSymesFrDefault(def); |
| 4488 | dsymes = listNConcat(Syme)(Syme_listPointer->NConcat)(symes, dsymes); |
| 4489 | } |
| 4490 | |
| 4491 | /* Explicit declaration. */ |
| 4492 | else if (id && abTag(argv[i])((argv[i])->abHdr.tag) != AB_Id) { |
| 4493 | assert(abSyme(id))do { if (!(((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0))) _do_assert(("abSyme(id)"),"tform.c",4493); } while (0 ); |
| 4494 | if (symeIsExport(abSyme(id))(((((((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0 ))->kind == SYME_Trigger ? libGetAllSymes((((id)->abHdr .seman ? (id)->abHdr.seman->syme : 0))->lib) : ((void *)0)), (((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0)))->kind) == SYME_Export)) |
| 4495 | xsymes = listCons(Syme)(Syme_listPointer->Cons)(abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0), xsymes); |
| 4496 | } |
| 4497 | |
| 4498 | /* Category expression. */ |
| 4499 | else if (!tfIsUnknown(cat = abGetCategory(argv[i]))(((cat = abGetCategory(argv[i]))->tag) == TF_Unknown) && |
| 4500 | tfSatCat(cat)) { |
| 4501 | csymes = tfGetThdExports(cat); |
| 4502 | isymes = symeListUnion(isymes, csymes, symeEqual); |
| 4503 | } |
| 4504 | } |
| 4505 | |
| 4506 | /* Mark the symes which have a default implementation. */ |
| 4507 | dsymes = listNReverse(Syme)(Syme_listPointer->NReverse)(dsymes); |
| 4508 | for (; dsymes; dsymes = listFreeCons(Syme)(Syme_listPointer->FreeCons)(dsymes)) { |
| 4509 | Syme dsyme = car(dsymes)((dsymes)->first); |
| 4510 | Syme xsyme = NULL((void*)0); |
| 4511 | |
| 4512 | /* If the default is one of our exports, just mark it. */ |
| 4513 | for (symes = xsymes; !xsyme && symes; symes = cdr(symes)((symes)->rest)) |
| 4514 | if (symeEqual(car(symes)((symes)->first), dsyme)) { |
| 4515 | xsyme = car(symes)((symes)->first); |
| 4516 | symeSetDefault(xsyme)(((((xsyme)->kind == SYME_Trigger ? libGetAllSymes((xsyme) ->lib) : ((void*)0)), (xsyme))->bits) |= (0x0080)); |
| 4517 | symeSetSrcPos(xsyme, symeSrcPos(dsyme))(symeSetFieldVal = ((AInt) (((SrcPos) (SYFI_SrcPos < (8 * sizeof (int)) && !(((((dsyme)->kind == SYME_Trigger ? libGetAllSymes ((dsyme)->lib) : ((void*)0)), (dsyme))->hasmask) & ( 1 << (SYFI_SrcPos))) ? (symeFieldInfo[SYFI_SrcPos].def) : (((((dsyme)->kind == SYME_Trigger ? libGetAllSymes((dsyme )->lib) : ((void*)0)), (dsyme))->locmask) & (1 << (SYFI_SrcPos))) ? ((((((dsyme)->kind == SYME_Trigger ? libGetAllSymes ((dsyme)->lib) : ((void*)0)), (dsyme))->locmask) & ( 1 << (SYFI_SrcPos))) ? ((dsyme)->fieldv)[symeIndex(dsyme ,SYFI_SrcPos)] : (symeFieldInfo[SYFI_SrcPos].def)) : symeGetFieldFn (dsyme,SYFI_SrcPos))))), (((((xsyme)->kind == SYME_Trigger ? libGetAllSymes((xsyme)->lib) : ((void*)0)), (xsyme))-> locmask) & (1 << (SYFI_SrcPos))) ? (((xsyme)->fieldv )[symeIndex(xsyme,SYFI_SrcPos)] = (symeSetFieldVal)) : !((xsyme )->full) && symeSetFieldVal == (symeFieldInfo[SYFI_SrcPos ].def) ? symeSetFieldVal : symeSetFieldFn(xsyme,SYFI_SrcPos,symeSetFieldVal )); |
| 4518 | } |
| 4519 | |
| 4520 | /* If the default is inherited, use the default syme. */ |
| 4521 | if (xsyme == NULL((void*)0)) { |
| 4522 | xsymes = listCons(Syme)(Syme_listPointer->Cons)(dsyme, xsymes); |
| 4523 | symeSetDefault(dsyme)(((((dsyme)->kind == SYME_Trigger ? libGetAllSymes((dsyme) ->lib) : ((void*)0)), (dsyme))->bits) |= (0x0080)); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | xsymes = listNReverse(Syme)(Syme_listPointer->NReverse)(xsymes); |
| 4528 | return symeListUnion(isymes, xsymes, symeEqual); |
| 4529 | } |
| 4530 | |
| 4531 | /****************************************************************************** |
| 4532 | * |
| 4533 | * :: Type form constant definitions. |
| 4534 | * |
| 4535 | *****************************************************************************/ |
| 4536 | |
| 4537 | SymeList |
| 4538 | tfGetDomConstants(TForm tf) |
| 4539 | { |
| 4540 | tf = tfDefineeType(tf); |
| 4541 | |
| 4542 | return tfGetCatConstants(tfGetCategory(tf)); |
| 4543 | } |
| 4544 | |
| 4545 | SymeList |
| 4546 | tfGetCatConstants(TForm cat) |
| 4547 | { |
| 4548 | SymeList symes; |
| 4549 | |
| 4550 | tfFollow(cat)((cat) = tfFollowFn(cat)); |
| 4551 | if (tfIsDefine(cat)(((cat)->tag) == TF_Define)) { |
| 4552 | if (tfIsDefineOfType(cat)) |
| 4553 | return tfGetDomConstants(tfDefineVal(cat)tfFollowArg(cat, 1)); |
| 4554 | cat = tfDefineVal(cat)tfFollowArg(cat, 1); |
| 4555 | tfFollow(cat)((cat) = tfFollowFn(cat)); |
| 4556 | return tfSymes(cat)((cat)->symes); |
| 4557 | } |
| 4558 | |
| 4559 | cat = tfDefineeType(cat); |
| 4560 | |
| 4561 | if (tfIsUnknown(cat)(((cat)->tag) == TF_Unknown) || tfIsNone(cat)((((cat)->tag) == TF_Multiple) && tfMultiArgc(cat) == 0)) |
| 4562 | symes = listNil(Syme)((SymeList) 0); |
| 4563 | |
| 4564 | else if (tfIsWith(cat)(((cat)->tag) == TF_With)) { |
| 4565 | TForm tfb = tfWithBase(cat)tfFollowArg(cat, 0); |
| 4566 | TForm tfw = tfWithWithin(cat)tfFollowArg(cat, 1); |
| 4567 | SymeList bsymes, wsymes; |
| 4568 | |
| 4569 | bsymes = tfGetCatConstants(tfb); |
| 4570 | |
| 4571 | /*!! tfCatExports will find the constant numbers from any |
| 4572 | *!! defaults in the with, but not from any categories. |
| 4573 | *!! We could save the constant symes in the tform. |
| 4574 | */ |
| 4575 | tfFollow(tfw)((tfw) = tfFollowFn(tfw)); |
| 4576 | if (tfCatExports(tfw)) |
| 4577 | wsymes = tfCatExports(tfw); |
| 4578 | |
| 4579 | else if (tfIsDeclare(tfw)(((tfw)->tag) == TF_Declare)) |
| 4580 | wsymes = tfSymes(tfw)((tfw)->symes); |
| 4581 | |
| 4582 | else if (tfHasExpr(tfw)((tfw)->__absyn != 0)) |
| 4583 | wsymes = tfGetCatConstantsFrWith(tfGetExpr(tfw)((tfw)->__absyn)); |
| 4584 | |
| 4585 | else |
| 4586 | wsymes = tfGetCatConstants(tfw); |
| 4587 | |
| 4588 | symes = symeListUnion(bsymes, wsymes, symeEq); |
| 4589 | } |
| 4590 | |
| 4591 | else if (tfIsIf(cat)(((cat)->tag) == TF_If)) |
| 4592 | symes = listNConcat(Syme)(Syme_listPointer->NConcat)(tfGetCatConstants(tfIfThen(cat)tfFollowArg(cat, 1)), |
| 4593 | tfGetCatConstants(tfIfElse(cat)tfFollowArg(cat, 2))); |
| 4594 | |
| 4595 | else if (tfIsJoin(cat)(((cat)->tag) == TF_Join) || tfIsMeet(cat)(((cat)->tag) == TF_Meet)) { |
| 4596 | Length i, argc = tfArgc(cat)((cat)->argc); |
| 4597 | SymeList nsymes; |
| 4598 | |
| 4599 | symes = listNil(Syme)((SymeList) 0); |
| 4600 | for (i = 0; i < argc; i += 1) { |
| 4601 | nsymes = tfGetCatConstants(tfFollowArg(cat, i)); |
| 4602 | symes = symeListUnion(symes, nsymes, symeEq); |
| 4603 | } |
| 4604 | } |
| 4605 | |
| 4606 | else |
| 4607 | symes = tfGetThdConstants(tfGetCategory(cat)); |
| 4608 | |
| 4609 | return symes; |
| 4610 | } |
| 4611 | |
| 4612 | localstatic SymeList |
| 4613 | tfGetThdConstants(TForm thd) |
| 4614 | { |
| 4615 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 4616 | |
| 4617 | thd = tfDefineeType(thd); |
| 4618 | |
| 4619 | if (tfIsThird(thd)(((thd)->tag) == TF_Third)) |
| 4620 | symes = tfGetCatConstants(tfThirdRestrictions(thd)tfFollowArg(thd, 0)); |
| 4621 | |
| 4622 | return symes; |
| 4623 | } |
| 4624 | |
| 4625 | /* |
| 4626 | * tfGetCatConstants helper functions. |
| 4627 | */ |
| 4628 | |
| 4629 | localstatic SymeList |
| 4630 | tfGetCatConstantsFrWith(Sefo sefo) |
| 4631 | { |
| 4632 | SymeList csymes, symes = listNil(Syme)((SymeList) 0); |
| 4633 | Length i, argc; |
| 4634 | Sefo *argv; |
| 4635 | |
| 4636 | AB_SEQ_ITER(sefo, argc, argv){ switch (((sefo)->abHdr.tag)) { case AB_Nothing: argc = 0 ; argv = 0; break; case AB_Sequence: argc = ((sefo)->abHdr .argc); argv = ((sefo)->abGen.data.argv); break; default: argc = 1; argv = &sefo; break; }; }; |
| 4637 | |
| 4638 | for (i = 0; i < argc; i++) { |
| 4639 | Sefo id = abDefineeIdOrElse(argv[i], NULL((void*)0)); |
| 4640 | |
| 4641 | if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Nothing) |
| 4642 | continue; |
| 4643 | |
| 4644 | /* Defaults package. */ |
| 4645 | else if (abTag(argv[i])((argv[i])->abHdr.tag) == AB_Default) |
| 4646 | continue; |
| 4647 | |
| 4648 | /* Explicit declaration. */ |
| 4649 | else if (id && abTag(argv[i])((argv[i])->abHdr.tag) != AB_Id) |
| 4650 | continue; |
| 4651 | |
| 4652 | /* Category expression. */ |
| 4653 | else if (abState(argv[i])((argv[i])->abHdr.state) == AB_State_HasUnique && |
| 4654 | tfSatCat(abTUnique(argv[i])((argv[i])->abHdr.type.unique))) { |
| 4655 | csymes = tfGetThdConstants(abTUnique(argv[i])((argv[i])->abHdr.type.unique)); |
| 4656 | symes = listNConcat(Syme)(Syme_listPointer->NConcat)(csymes, symes); |
| 4657 | } |
| 4658 | } |
| 4659 | |
| 4660 | return symes; |
| 4661 | } |
| 4662 | |
| 4663 | /****************************************************************************** |
| 4664 | * |
| 4665 | * :: Type form cascaded imports. |
| 4666 | * |
| 4667 | *****************************************************************************/ |
| 4668 | |
| 4669 | /* |
| 4670 | * Called on a domain to get the cascaded imports which are supplied |
| 4671 | * by the domain. |
| 4672 | */ |
| 4673 | TQualList |
| 4674 | tfGetDomCascades(TForm tf) |
| 4675 | { |
| 4676 | TForm cat; |
| 4677 | TQualList ql; |
| 4678 | |
| 4679 | tf = tfDefineeType(tf); |
| 4680 | |
| 4681 | if (tfHasCascades(tf)((tf)->hasCascades)) |
| 4682 | return tfCascades(tf)((tf)->cascades); |
| 4683 | |
| 4684 | if (tfIsUnknown(tf)(((tf)->tag) == TF_Unknown) || tfIsNone(tf)((((tf)->tag) == TF_Multiple) && tfMultiArgc(tf) == 0)) |
| 4685 | return listNil(TQual)((TQualList) 0); |
| 4686 | |
| 4687 | if (!tfIsMeaning(tf)(((tf)->state)>=TF_State_Meaning)) { |
| 4688 | tfGetExportError(tf, "domain"); |
| 4689 | return listNil(TQual)((TQualList) 0); |
| 4690 | } |
| 4691 | |
| 4692 | cat = tfGetCategory(tf); |
| 4693 | if (tfIsUnknown(cat)(((cat)->tag) == TF_Unknown)) |
| 4694 | return listNil(TQual)((TQualList) 0); |
| 4695 | if (!tfHasCatExports(cat)) |
| 4696 | return listNil(TQual)((TQualList) 0); |
| 4697 | |
| 4698 | if (DEBUG(tfCascade)tfCascadeDebug) { |
| 4699 | fprintf(dbOut, "tfGetDomCascades: from "); |
| 4700 | tfPrint(dbOut, tf); |
| 4701 | findent += 2; |
| 4702 | fnewline(dbOut); |
| 4703 | } |
| 4704 | |
| 4705 | /* |
| 4706 | * Collect the domain cascades from the type form. |
| 4707 | */ |
| 4708 | if (tfIsNotDomain(tf)((((tf)->tag) == TF_Type) || (((tf)->tag) == TF_With) || ((((tf)->tag) == TF_Syntax) && ((((tf)->__absyn ))->abHdr.tag == (AB_With))) || (((tf)->tag) == TF_Join ) || (((tf)->tag) == TF_If) || (((tf)->tag) == TF_Third ))) |
| 4709 | ql = listNil(TQual)((TQualList) 0); |
| 4710 | |
| 4711 | else if (tfIsRecord(tf)(((tf)->tag) == TF_Record) || tfIsRawRecord(tf)(((tf)->tag) == TF_RawRecord) || tfIsUnion(tf)(((tf)->tag) == TF_Union)) |
| 4712 | ql = tqListFrArgs(tfGetStab(tf), tfArgv(tf)((tf)->argv), tfArgc(tf)((tf)->argc)); |
| 4713 | else if (tfIsTrailingArray(tf)(((tf)->tag) == TF_TrailingArray)) |
| 4714 | ql = tfGetCascadesFrTrailingArray(tf); |
| 4715 | else if (tfIsSym(tf)( (((tf)->tag)) < TF_SYM_LIMIT) || tfIsSyntax(tf)(((tf)->tag) == TF_Syntax) || tfIsAdd(tf)(((tf)->tag) == TF_Add)) |
| 4716 | ql = listNil(TQual)((TQualList) 0); |
| 4717 | |
| 4718 | /*!! Perhaps this can be expanded later. */ |
| 4719 | else if (tfIsLibrary(tf) || tfIsArchive(tf)) |
| 4720 | ql = listNil(TQual)((TQualList) 0); |
| 4721 | else |
| 4722 | ql = listCopy(TQual)(TQual_listPointer->Copy)(tfGetCatCascades(tfGetCategory(tf))); |
| 4723 | |
| 4724 | if (DEBUG(tfCascade)tfCascadeDebug) { |
| 4725 | fprintf(dbOut, "domain cascades:"); |
| 4726 | fnewline(dbOut); |
| 4727 | listPrint(TQual)(TQual_listPointer->Print)(dbOut, ql, tqPrint); |
| 4728 | findent -= 2; |
| 4729 | fnewline(dbOut); |
| 4730 | } |
| 4731 | |
| 4732 | tfHasCascades(tf)((tf)->hasCascades) = true1; |
| 4733 | tfSetCascades(tf, ql)(((tf)->cascades) = (ql)); |
| 4734 | return ql; |
| 4735 | } |
| 4736 | |
| 4737 | /* |
| 4738 | * Called on a category to get the cascaded imports which are supplied |
| 4739 | * by the category. |
| 4740 | */ |
| 4741 | TQualList |
| 4742 | tfGetCatCascades(TForm cat) |
| 4743 | { |
| 4744 | TQualList ql; |
| 4745 | |
| 4746 | tfFollow(cat)((cat) = tfFollowFn(cat)); |
| 4747 | |
| 4748 | if (tfIsDefine(cat)(((cat)->tag) == TF_Define)) { |
| 4749 | TQualList ql2; |
| 4750 | |
| 4751 | if (tfHasCascades(cat)((cat)->hasCascades) || !tfIsMeaning(cat)(((cat)->state)>=TF_State_Meaning)) |
| 4752 | return tfCascades(cat)((cat)->cascades); |
| 4753 | |
| 4754 | ql = listCopy(TQual)(TQual_listPointer->Copy) |
| 4755 | (tfGetDomCascades(tfDefineVal(cat)tfFollowArg(cat, 1))); |
| 4756 | |
| 4757 | ql2 = listCopy(TQual)(TQual_listPointer->Copy) |
| 4758 | (tfGetCatCascades(tfDefineeType(cat))); |
| 4759 | ql = listNConcat(TQual)(TQual_listPointer->NConcat)(ql, ql2); |
| 4760 | |
| 4761 | tfHasCascades(cat)((cat)->hasCascades) = true1; |
| 4762 | tfSetCascades(cat, ql)(((cat)->cascades) = (ql)); |
| 4763 | return ql; |
| 4764 | } |
| 4765 | |
| 4766 | cat = tfDefineeType(cat); |
| 4767 | |
| 4768 | if (tfHasCascades(cat)((cat)->hasCascades)) |
| 4769 | return tfCascades(cat)((cat)->cascades); |
| 4770 | |
| 4771 | if (tfIsUnknown(cat)(((cat)->tag) == TF_Unknown) || tfIsNone(cat)((((cat)->tag) == TF_Multiple) && tfMultiArgc(cat) == 0)) |
| 4772 | return listNil(TQual)((TQualList) 0); |
| 4773 | |
| 4774 | if (!tfIsMeaning(cat)(((cat)->state)>=TF_State_Meaning)) { |
| 4775 | tfGetExportError(cat, "category"); |
| 4776 | return listNil(TQual)((TQualList) 0); |
| 4777 | } |
| 4778 | |
| 4779 | if (DEBUG(tfCat)tfCatDebug) { |
| 4780 | fprintf(dbOut, "(tfGetCatCascades: from "); |
| 4781 | tfPrint(dbOut, cat); |
| 4782 | fnewline(dbOut); |
| 4783 | } |
| 4784 | |
| 4785 | if (tfIsWith(cat)(((cat)->tag) == TF_With)) |
| 4786 | ql = tfGetCatCascadesFrWith(cat); |
| 4787 | |
| 4788 | else if (tfIsIf(cat)(((cat)->tag) == TF_If)) { |
| 4789 | TQualList ql1, ql2; |
| 4790 | |
| 4791 | ql1 = listCopy(TQual)(TQual_listPointer->Copy)(tfGetCatCascades(tfIfThen(cat)tfFollowArg(cat, 1))); |
| 4792 | ql2 = listCopy(TQual)(TQual_listPointer->Copy)(tfGetCatCascades(tfIfElse(cat)tfFollowArg(cat, 2))); |
| 4793 | ql = listNConcat(TQual)(TQual_listPointer->NConcat)(ql1, ql2); |
| 4794 | } |
| 4795 | |
| 4796 | else if (tfIsJoin(cat)(((cat)->tag) == TF_Join) || tfIsMeet(cat)(((cat)->tag) == TF_Meet)) { |
| 4797 | Length i, argc = tfArgc(cat)((cat)->argc); |
| 4798 | TQualList nql; |
| 4799 | |
| 4800 | ql = listNil(TQual)((TQualList) 0); |
| 4801 | for (i = 0; i < argc; i += 1) { |
| 4802 | nql = tfGetCatCascades(tfFollowArg(cat, i)); |
| 4803 | ql = listNConcat(TQual)(TQual_listPointer->NConcat)(ql, listCopy(TQual)(TQual_listPointer->Copy)(nql)); |
| 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | else |
| 4808 | ql = listCopy(TQual)(TQual_listPointer->Copy)(tfGetThdCascades(tfGetCategory(cat))); |
| 4809 | |
| 4810 | tfCatDEBUGif (!tfCatDebug) { } else afprintf(dbOut, ")\n"); |
| 4811 | |
| 4812 | tfHasCascades(cat)((cat)->hasCascades) = true1; |
| 4813 | tfSetCascades(cat, ql)(((cat)->cascades) = (ql)); |
| 4814 | return ql; |
| 4815 | } |
| 4816 | |
| 4817 | /* |
| 4818 | * Called on a third-order type to get the cascaded imports which are supplied |
| 4819 | * by the third-order type. |
| 4820 | */ |
| 4821 | TQualList |
| 4822 | tfGetThdCascades(TForm thd) |
| 4823 | { |
| 4824 | TQualList ql; |
| 4825 | |
| 4826 | thd = tfDefineeType(thd); |
| 4827 | |
| 4828 | if (tfHasCascades(thd)((thd)->hasCascades)) |
| 4829 | return tfCascades(thd)((thd)->cascades); |
| 4830 | |
| 4831 | if (tfIsUnknown(thd)(((thd)->tag) == TF_Unknown) || tfIsNone(thd)((((thd)->tag) == TF_Multiple) && tfMultiArgc(thd) == 0)) |
| 4832 | return listNil(TQual)((TQualList) 0); |
| 4833 | |
| 4834 | if (DEBUG(tfCat)tfCatDebug) { |
| 4835 | fprintf(dbOut, "(tfGetThdCascades: from "); |
| 4836 | tfPrint(dbOut, thd); |
| 4837 | fnewline(dbOut); |
| 4838 | } |
| 4839 | |
| 4840 | if (tfIsThird(thd)(((thd)->tag) == TF_Third)) { |
| 4841 | ql = tfGetCatCascades(tfThirdRestrictions(thd)tfFollowArg(thd, 0)); |
| 4842 | ql = listCopy(TQual)(TQual_listPointer->Copy)(ql); |
| 4843 | } |
| 4844 | |
| 4845 | else |
| 4846 | ql = listNil(TQual)((TQualList) 0); |
| 4847 | |
| 4848 | tfCatDEBUGif (!tfCatDebug) { } else afprintf(dbOut, ")\n"); |
| 4849 | |
| 4850 | tfHasCascades(thd)((thd)->hasCascades) = true1; |
| 4851 | tfSetCascades(thd, ql)(((thd)->cascades) = (ql)); |
| 4852 | return ql; |
| 4853 | } |
| 4854 | |
| 4855 | /* |
| 4856 | * tfGet...Cascades helper functions. |
| 4857 | */ |
| 4858 | |
| 4859 | localstatic TQualList |
| 4860 | tfGetCascadesFrStab(Stab stab) |
| 4861 | { |
| 4862 | TFormUsesList tful; |
| 4863 | TQualList ql = listNil(TQual)((TQualList) 0); |
| 4864 | |
| 4865 | for (tful = car(stab)((stab)->first)->tformsUsed.list; tful; tful = cdr(tful)((tful)->rest)) { |
| 4866 | TFormUses tfu = car(tful)((tful)->first); |
| 4867 | if (tfu->exports) ql = listCons(TQual)(TQual_listPointer->Cons)(tfu->exports, ql); |
| 4868 | } |
| 4869 | |
| 4870 | return ql; |
| 4871 | } |
| 4872 | |
| 4873 | localstatic TQualList |
| 4874 | tfGetCatCascadesFrWith(TForm cat) |
| 4875 | { |
| 4876 | TForm tfb = tfWithBase(cat)tfFollowArg(cat, 0); |
| 4877 | TForm tfw = tfWithWithin(cat)tfFollowArg(cat, 1); |
| 4878 | TQualList bql, wql, ql; |
| 4879 | |
| 4880 | bql = tfGetCatCascades(tfb); |
| 4881 | |
| 4882 | if (tfCascades(tfw)((tfw)->cascades)) |
| 4883 | wql = tfCascades(tfw)((tfw)->cascades); |
| 4884 | |
| 4885 | else if (tfGetStab(cat)) |
| 4886 | wql = tfGetCascadesFrStab(tfGetStab(cat)); |
| 4887 | |
| 4888 | else |
| 4889 | wql = tfGetCatCascades(tfw); |
| 4890 | |
| 4891 | ql = listNConcat(TQual)(TQual_listPointer->NConcat)(listCopy(TQual)(TQual_listPointer->Copy)(bql), listCopy(TQual)(TQual_listPointer->Copy)(wql)); |
| 4892 | |
| 4893 | return ql; |
| 4894 | } |
| 4895 | |
| 4896 | |
| 4897 | localstatic TQualList |
| 4898 | tfGetCascadesFrTrailingArray(TForm tf) |
| 4899 | { |
| 4900 | TQualList ql = listNil(TQual)((TQualList) 0); |
| 4901 | TForm atf, itf, *tfv; |
| 4902 | Stab stab; |
| 4903 | Length tfc; |
| 4904 | |
| 4905 | if (tfArgc(tf)((tf)->argc) != 2) return listNil(TQual)((TQualList) 0); |
| 4906 | stab = tfGetStab(tf); |
| 4907 | |
| 4908 | itf = tfTrailingIArg(tf)tfFollowArg(tf,((int) 0)); |
| 4909 | atf = tfTrailingAArg(tf)tfFollowArg(tf,1); |
| 4910 | |
| 4911 | tfv = tfIsMulti(itf)(((itf)->tag) == TF_Multiple) ? tfMultiArgv(itf)((itf)->argv): &itf; |
| 4912 | tfc = tfIsMulti(itf)(((itf)->tag) == TF_Multiple) ? tfMultiArgc(itf): 1; |
| 4913 | ql = listNConcat(TQual)(TQual_listPointer->NConcat)(ql, tqListFrArgs(stab, tfv, tfc)); |
| 4914 | |
| 4915 | tfv = tfIsMulti(atf)(((atf)->tag) == TF_Multiple) ? tfMultiArgv(atf)((atf)->argv): &atf; |
| 4916 | tfc = tfIsMulti(atf)(((atf)->tag) == TF_Multiple) ? tfMultiArgc(atf): 1; |
| 4917 | ql = listNConcat(TQual)(TQual_listPointer->NConcat)(ql, tqListFrArgs(stab, tfv, tfc)); |
| 4918 | |
| 4919 | return ql; |
| 4920 | } |
| 4921 | |
| 4922 | |
| 4923 | /****************************************************************************** |
| 4924 | * |
| 4925 | * :: Type form representational symes. |
| 4926 | * |
| 4927 | *****************************************************************************/ |
| 4928 | |
| 4929 | localstatic SymeList tfSymesFrDepGroup(Stab, TForm, TForm, SymeList); |
| 4930 | |
| 4931 | Bool |
| 4932 | tfTagHasSymes(TFormTag tag) |
| 4933 | { |
| 4934 | switch (tag) { |
| 4935 | case TF_Declare: |
| 4936 | case TF_Cross: |
| 4937 | case TF_Map: |
| 4938 | case TF_PackedMap: |
| 4939 | case TF_Multiple: |
| 4940 | case TF_Enumerate: |
| 4941 | case TF_RawRecord: |
| 4942 | case TF_Record: |
| 4943 | case TF_TrailingArray: |
| 4944 | case TF_Union: |
| 4945 | case TF_Add: |
| 4946 | case TF_Third: |
| 4947 | return true1; |
| 4948 | default: |
| 4949 | return false((int) 0); |
| 4950 | } |
| 4951 | } |
| 4952 | |
| 4953 | Bool |
| 4954 | tfSymeInducesDependency(Syme syme, TForm tf) |
| 4955 | { |
| 4956 | Stab stab = tfGetStab(tf); |
| 4957 | Bool result = false((int) 0); |
| 4958 | |
| 4959 | if (stab && symeDefLevel(syme) == car(stab)((stab)->first)) |
| 4960 | result = !symeUnused(syme)(((UShort) ((((((syme)->kind == SYME_Trigger ? libGetAllSymes ((syme)->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_UsedDepth))) ? ((syme)->fieldv)[symeIndex( syme,SYFI_UsedDepth)] : (symeFieldInfo[SYFI_UsedDepth].def))) == (0x7FFF)) || tfIsCategoryMap(tf); |
| 4961 | |
| 4962 | tfMapDEBUGif (!tfMapDebug) { } else afprintf(dbOut, "tformSymeInducesDependency: %s %pSyme %pTForm\n", boolToString(result)((result) ? "true" : "false"), |
| 4963 | syme, tf); |
| 4964 | tfMapDEBUGif (!tfMapDebug) { } else afprintf(dbOut, "tformSymeInducesDependency: %pSyme Lvl %s unused: %s catMap %s\n", |
| 4965 | syme, |
| 4966 | boolToString(stab && symeDefLevel(syme) == car(stab))((stab && symeDefLevel(syme) == ((stab)->first)) ? "true" : "false"), |
| 4967 | boolToString(symeUnused(syme))(((((UShort) ((((((syme)->kind == SYME_Trigger ? libGetAllSymes ((syme)->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_UsedDepth))) ? ((syme)->fieldv)[symeIndex( syme,SYFI_UsedDepth)] : (symeFieldInfo[SYFI_UsedDepth].def))) == (0x7FFF))) ? "true" : "false"), |
| 4968 | boolToString(tfIsCategoryMap(tf))((tfIsCategoryMap(tf)) ? "true" : "false")); |
| 4969 | |
| 4970 | return result; |
| 4971 | } |
| 4972 | |
| 4973 | /* |
| 4974 | * Functions to extract representational symes |
| 4975 | * from fully-analysed abstract syntax. |
| 4976 | */ |
| 4977 | |
| 4978 | localstatic Syme |
| 4979 | tfNewRepSyme(Stab stab, Symbol sym, TForm tf, Hash code) |
| 4980 | { |
| 4981 | Syme syme = symeNewExport(sym, tf, car(stab)((stab)->first)); |
| 4982 | symeSetSpecial(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->bits) |= (0x0002)); |
| 4983 | symeAddHash(syme, code); |
| 4984 | return syme; |
| 4985 | } |
| 4986 | |
| 4987 | localstatic SymeList |
| 4988 | tfSymesFrDeclare(Sefo sefo) |
| 4989 | { |
| 4990 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 4991 | Sefo id = abDefineeIdOrElse(sefo, NULL((void*)0)); |
| 4992 | Syme syme = id ? abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0) : NULL((void*)0); |
| 4993 | |
| 4994 | if (syme) symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 4995 | return symes; |
| 4996 | } |
| 4997 | |
| 4998 | localstatic SymeList |
| 4999 | tfSymesFrCross(TForm tf) |
| 5000 | { |
| 5001 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 5002 | Length i, argc = tfArgc(tf)((tf)->argc); |
| 5003 | |
| 5004 | if (DEBUG(tfCross)tfCrossDebug) { |
| 5005 | fprintf(dbOut, "tfSymesFrCross:"); |
| 5006 | fnewline(dbOut); |
| 5007 | fprintf(dbOut, " tf:"); |
| 5008 | tfPrint(dbOut, tf); |
| 5009 | fnewline(dbOut); |
| 5010 | } |
| 5011 | |
| 5012 | for (i = 0; i < argc; i += 1) { |
| 5013 | TForm tfi = tfCrossArgN(tf, i)tfFollowArg(tf, i); |
| 5014 | Syme syme = tfDefineeSyme(tfi); |
| 5015 | |
| 5016 | if (syme != 0 && tfSymeInducesDependency(syme, tf)) |
| 5017 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5018 | } |
| 5019 | symes = listNReverse(Syme)(Syme_listPointer->NReverse)(symes); |
| 5020 | |
| 5021 | if (DEBUG(tfCross)tfCrossDebug) { |
| 5022 | fprintf(dbOut, " symes:"); |
| 5023 | fnewline(dbOut); |
| 5024 | listPrint(Syme)(Syme_listPointer->Print)(dbOut, symes, symePrint); |
| 5025 | fnewline(dbOut); |
| 5026 | } |
| 5027 | |
| 5028 | return symes; |
| 5029 | } |
| 5030 | |
| 5031 | localstatic SymeList |
| 5032 | tfSymesFrMulti(TForm tf) |
| 5033 | { |
| 5034 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 5035 | Length i, argc = tfArgc(tf)((tf)->argc); |
| 5036 | |
| 5037 | if (DEBUG(tfMulti)tfMultiDebug) { |
| 5038 | fprintf(dbOut, "tfSymesFrMulti:"); |
| 5039 | fnewline(dbOut); |
| 5040 | fprintf(dbOut, " tf:"); |
| 5041 | tfPrint(dbOut, tf); |
| 5042 | fnewline(dbOut); |
| 5043 | } |
| 5044 | |
| 5045 | for (i = 0; i < argc; i += 1) { |
| 5046 | TForm tfi = tfMultiArgN(tf, i)tfFollowArg(tf, i); |
| 5047 | Syme syme = tfDefineeSyme(tfi); |
| 5048 | |
| 5049 | if (syme != 0 && tfSymeInducesDependency(syme, tf)) |
| 5050 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5051 | } |
| 5052 | symes = listNReverse(Syme)(Syme_listPointer->NReverse)(symes); |
| 5053 | |
| 5054 | if (DEBUG(tfMulti)tfMultiDebug) { |
| 5055 | fprintf(dbOut, " symes:"); |
| 5056 | fnewline(dbOut); |
| 5057 | listPrint(Syme)(Syme_listPointer->Print)(dbOut, symes, symePrint); |
| 5058 | fnewline(dbOut); |
| 5059 | } |
| 5060 | |
| 5061 | return symes; |
| 5062 | } |
| 5063 | |
| 5064 | localstatic SymeList |
| 5065 | tfSymesFrMap(TForm tf) |
| 5066 | { |
| 5067 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 5068 | Length i, argc = tfMapArgc(tf); |
| 5069 | |
| 5070 | if (DEBUG(tfMap)tfMapDebug) { |
| 5071 | fprintf(dbOut, "tfSymesFrMap:"); |
| 5072 | fnewline(dbOut); |
| 5073 | fprintf(dbOut, " tf:"); |
| 5074 | tfPrint(dbOut, tf); |
| 5075 | fnewline(dbOut); |
| 5076 | } |
| 5077 | |
| 5078 | for (i = 0; i < argc; i += 1) { |
| 5079 | TForm tfi = tfMapArgN(tf, i); |
| 5080 | Syme syme = tfDefineeSyme(tfi); |
| 5081 | |
| 5082 | if (syme != 0 && tfSymeInducesDependency(syme, tf)) |
| 5083 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5084 | } |
| 5085 | symes = listNReverse(Syme)(Syme_listPointer->NReverse)(symes); |
| 5086 | |
| 5087 | if (DEBUG(tfMap)tfMapDebug) { |
| 5088 | fprintf(dbOut, " symes:"); |
| 5089 | fnewline(dbOut); |
| 5090 | listPrint(Syme)(Syme_listPointer->Print)(dbOut, symes, symePrint); |
| 5091 | fnewline(dbOut); |
| 5092 | } |
| 5093 | |
| 5094 | return symes; |
| 5095 | } |
| 5096 | |
| 5097 | localstatic SymeList |
| 5098 | tfSymesFrEnum(Stab stab, TForm tf, Sefo sefo) |
| 5099 | { |
| 5100 | Syme syme; |
| 5101 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 5102 | Length i, argc = abApplyArgc(sefo)(((sefo)->abHdr.argc)-1); |
| 5103 | TForm me = tfFrSelf(stab, tf); |
| 5104 | TForm tfm; |
| 5105 | Hash code = abHash(sefo); |
| 5106 | |
| 5107 | /* |
| 5108 | * = : (me, me) -> Boolean |
| 5109 | * ~= : (me, me) -> Boolean |
| 5110 | */ |
| 5111 | |
| 5112 | /* |
| 5113 | * An unfixed compiler bug means that parts of Salli programs |
| 5114 | * (and thus libAldor) are tinfered with (tfBoolean == tfUnknown). |
| 5115 | * The correct fix is to ensure that tfBoolean has been imported |
| 5116 | * into every scope that needs it before we get this far. |
| 5117 | */ |
| 5118 | tfm = tfMulti(2, me, me); |
| 5119 | if (tfBoolean == tfUnknown) comsgFatal(sefo, ALDOR_F_BugNoBoolean367); |
| 5120 | tfm = tfMap(tfm, tfBoolean); |
| 5121 | |
| 5122 | syme = tfNewRepSyme(stab, ssymEquals, tfm, code); |
| 5123 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5124 | |
| 5125 | syme = tfNewRepSyme(stab, ssymNotEquals, tfm, code); |
| 5126 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5127 | |
| 5128 | for (i = 0; i < argc; i += 1) { |
| 5129 | Sefo argi = abDefineeIdOrElse(abApplyArg(sefo, i)((sefo)->abApply.argv[i]), NULL((void*)0)); |
| 5130 | |
| 5131 | if (! argi) continue; |
| 5132 | assert(abTag(argi) == AB_Id)do { if (!(((argi)->abHdr.tag) == AB_Id)) _do_assert(("abTag(argi) == AB_Id" ),"tform.c",5132); } while (0); |
| 5133 | |
| 5134 | /* |
| 5135 | * ni : E |
| 5136 | */ |
| 5137 | syme = tfNewRepSyme(stab, argi->abId.sym, me, code); |
| 5138 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5139 | } |
| 5140 | symes = listNReverse(Syme)(Syme_listPointer->NReverse)(symes); |
| 5141 | |
| 5142 | stabSetSubstable(stab)(((stab)->first)->isSubstable=1); |
| 5143 | return symes; |
| 5144 | } |
| 5145 | |
| 5146 | localstatic void |
| 5147 | tfCheckDenseArgs(TForm tf, Sefo sefo) |
| 5148 | { |
| 5149 | Length i; |
| 5150 | Length argc = abApplyArgc(sefo)(((sefo)->abHdr.argc)-1); |
| 5151 | |
| 5152 | for (i = 0;i < argc; i++) |
| 5153 | { |
| 5154 | TForm tfarg = tfArgv(tf)((tf)->argv)[i]; |
| 5155 | Sefo argi = abDefineeIdOrElse(abApplyArg(sefo, i)((sefo)->abApply.argv[i]), NULL((void*)0)); |
| 5156 | |
| 5157 | if (!tfDomHasImplicit(tfarg)) |
| 5158 | { |
| 5159 | String cat = symString(ssymImplPAOps)((ssymImplPAOps)->str); |
| 5160 | comsgError(argi, ALDOR_E_TinPackedNotSat189, cat); |
| 5161 | } |
| 5162 | } |
| 5163 | } |
| 5164 | |
| 5165 | localstatic SymeList |
| 5166 | tfSymesFrRawRecord(Stab stab, TForm tf, Sefo sefo) |
| 5167 | { |
| 5168 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 5169 | Syme syme; |
| 5170 | Length i, argc = abApplyArgc(sefo)(((sefo)->abHdr.argc)-1); |
| 5171 | TForm tfc, tfm, me = tfFrSelf(stab, tf); |
| 5172 | Hash code = abHash(sefo); |
| 5173 | |
| 5174 | /* |
| 5175 | * First ensure that all types have DenseStorageCategory. |
| 5176 | * We ought to do this in libraries with the definition |
| 5177 | * of RawRecord() but we also do it here for safety. The |
| 5178 | * sting in the tail is that we never want to check the |
| 5179 | * initial definition `RawRecord(T:Tuple Type): ...'. |
| 5180 | */ |
| 5181 | if ((argc != 1) || !tfIsTypeTuple(tfCatFrDom(tfArgv(tf)((tf)->argv)[0]))) |
| 5182 | tfCheckDenseArgs(tf, sefo); |
| 5183 | |
| 5184 | /* |
| 5185 | * [ ... ]: (T1, T2, ... TN) -> % |
| 5186 | * rawrecord: (T1, T2, ... TN) -> % |
| 5187 | * explode: % -> (T1, T2, ... TN) |
| 5188 | * dispose!: % -> () |
| 5189 | * apply: (%, Enumerate(ti:Type)) -> Ti |
| 5190 | * set!: (%, Enumerate(ti:Type), Ti) -> Ti |
| 5191 | */ |
| 5192 | |
| 5193 | |
| 5194 | /* Create the argument type for RawRecord: (t1:T1, ..., tN:TN) */ |
| 5195 | tfc = tfNewEmpty(TF_Multiple, argc); |
| 5196 | for (i = 0; i < argc; i += 1) tfc->argv[i] = tf->argv[i]; |
| 5197 | tfSetStab(tfc, abStab(sefo))((tfc)->stab = (((sefo)->abHdr.seman ? (sefo)->abHdr .seman->stab : 0))); |
| 5198 | tfSetSymes(tfc, tfSymesFrMulti(tfc))((tfc)->symes = (tfSymesFrMulti(tfc))); |
| 5199 | tfSetStab(tfc, NULL)((tfc)->stab = (((void*)0))); |
| 5200 | |
| 5201 | |
| 5202 | /* Now create the type: (t1:T1, ..., tN:TN) -> % */ |
| 5203 | tfm = tfMap(tfc, me); |
| 5204 | tfSetStab(tfm, abStab(sefo))((tfm)->stab = (((sefo)->abHdr.seman ? (sefo)->abHdr .seman->stab : 0))); |
| 5205 | tfSetSymes(tfm, tfSymesFrMap(tfm))((tfm)->symes = (tfSymesFrMap(tfm))); |
| 5206 | tfSetStab(tfm, NULL)((tfm)->stab = (((void*)0))); |
| 5207 | |
| 5208 | tfSetSymes(tf, tfSymes(tfm))((tf)->symes = (((tfm)->symes))); |
| 5209 | |
| 5210 | |
| 5211 | /* [ ... ] */ |
| 5212 | syme = tfNewRepSyme(stab, ssymBracket, tfm, code); |
| 5213 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5214 | |
| 5215 | |
| 5216 | /* rawrecord( ... ) */ |
| 5217 | syme = tfNewRepSyme(stab, ssymTheRawRecord, tfm, code); |
| 5218 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5219 | |
| 5220 | |
| 5221 | /* Reverse map: % -> (T1, T2, ..., TN) */ |
| 5222 | tfm = tfMap(me, tfc); |
| 5223 | |
| 5224 | |
| 5225 | /* explode: % -> (T1, T2, ..., TN) */ |
| 5226 | syme = tfNewRepSyme(stab, ssymTheExplode, tfm, code); |
| 5227 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5228 | |
| 5229 | |
| 5230 | /* Void map: % -> () */ |
| 5231 | tfc = tfMulti(int0((int) 0)); |
| 5232 | tfm = tfMap(me, tfc); |
| 5233 | |
| 5234 | |
| 5235 | /* dispose!: % -> () */ |
| 5236 | syme = tfNewRepSyme(stab, ssymTheDispose, tfm, code); |
| 5237 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5238 | |
| 5239 | |
| 5240 | /* Create the `apply' and `set!' exports */ |
| 5241 | for (i = 0; i < argc; i += 1) { |
| 5242 | TForm tfi = tf->argv[i]; |
| 5243 | TForm tfit = tfDefineeType(tfi); |
| 5244 | Syme si = tfDefineeSyme(tfi); |
| 5245 | Sefo argi = abDefineeIdOrElse(abApplyArg(sefo, i)((sefo)->abApply.argv[i]), NULL((void*)0)); |
| 5246 | TForm tfe; |
| 5247 | |
| 5248 | if (!si || !argi) continue; |
| 5249 | assert(abTag(argi) == AB_Id)do { if (!(((argi)->abHdr.tag) == AB_Id)) _do_assert(("abTag(argi) == AB_Id" ),"tform.c",5249); } while (0); |
| 5250 | |
| 5251 | /* apply: (%, Enumerate(ti: Type)) -> Ti */ |
| 5252 | tfe = tfEnum(stab, argi); |
| 5253 | tfm = tfMap(tfMulti(2, me, tfe), tfi); |
| 5254 | syme = tfNewRepSyme(stab, ssymApply, tfm, code); |
| 5255 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5256 | |
| 5257 | /* set!: (%, Enumerate(ti: Type), Ti) -> Ti */ |
| 5258 | if (!listMemq(Syme)(Syme_listPointer->Memq)(tfSymes(tf)((tf)->symes), si)) { |
| 5259 | tfm = tfMap(tfMulti(3, me, tfe, tfi), tfi); |
| 5260 | syme = tfNewRepSyme(stab, ssymSetBang, tfm, code); |
| 5261 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5262 | } |
| 5263 | } |
| 5264 | |
| 5265 | symes = tfSymesFrDepGroup(stab, me, tfc, symes); |
| 5266 | symes = listNReverse(Syme)(Syme_listPointer->NReverse)(symes); |
| 5267 | |
| 5268 | stabSetSubstable(stab)(((stab)->first)->isSubstable=1); |
| 5269 | return symes; |
| 5270 | } |
| 5271 | |
| 5272 | localstatic SymeList |
| 5273 | tfSymesFrRecord(Stab stab, TForm tf, Sefo sefo) |
| 5274 | { |
| 5275 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 5276 | Syme syme; |
| 5277 | Length i, argc = abApplyArgc(sefo)(((sefo)->abHdr.argc)-1); |
| 5278 | TForm tfc, tfm, me = tfFrSelf(stab, tf); |
| 5279 | Hash code = abHash(sefo); |
| 5280 | |
| 5281 | /* |
| 5282 | * [ ]: (A1, ..., AN) -> me |
| 5283 | * record: (A1, ..., AN) -> me |
| 5284 | * explode: me -> (A1, ..., AN) |
| 5285 | * dispose!: me -> () |
| 5286 | */ |
| 5287 | |
| 5288 | tfc = tfNewEmpty(TF_Multiple, argc); |
| 5289 | for (i = 0; i < argc; i += 1) tfc->argv[i] = tf->argv[i]; |
| 5290 | tfSetStab(tfc, abStab(sefo))((tfc)->stab = (((sefo)->abHdr.seman ? (sefo)->abHdr .seman->stab : 0))); |
| 5291 | tfSetSymes(tfc, tfSymesFrMulti(tfc))((tfc)->symes = (tfSymesFrMulti(tfc))); |
| 5292 | tfSetStab(tfc, NULL)((tfc)->stab = (((void*)0))); |
| 5293 | |
| 5294 | tfm = tfMap(tfc, me); |
| 5295 | tfSetStab(tfm, abStab(sefo))((tfm)->stab = (((sefo)->abHdr.seman ? (sefo)->abHdr .seman->stab : 0))); |
| 5296 | tfSetSymes(tfm, tfSymesFrMap(tfm))((tfm)->symes = (tfSymesFrMap(tfm))); |
| 5297 | tfSetStab(tfm, NULL)((tfm)->stab = (((void*)0))); |
| 5298 | |
| 5299 | tfSetSymes(tf, tfSymes(tfm))((tf)->symes = (((tfm)->symes))); |
| 5300 | |
| 5301 | syme = tfNewRepSyme(stab, ssymBracket, tfm, code); |
| 5302 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5303 | |
| 5304 | syme = tfNewRepSyme(stab, ssymTheRecord, tfm, code); |
| 5305 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5306 | |
| 5307 | tfm = tfMap(me, tfc); |
| 5308 | |
| 5309 | syme = tfNewRepSyme(stab, ssymTheExplode, tfm, code); |
| 5310 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5311 | |
| 5312 | tfc = tfMulti(int0((int) 0)); |
| 5313 | tfm = tfMap(me, tfc); |
| 5314 | |
| 5315 | syme = tfNewRepSyme(stab, ssymTheDispose, tfm, code); |
| 5316 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5317 | |
| 5318 | for (i = 0; i < argc; i += 1) { |
| 5319 | TForm tfi = tf->argv[i]; |
| 5320 | TForm tfit = tfDefineeType(tfi); |
| 5321 | Syme si = tfDefineeSyme(tfi); |
| 5322 | Sefo argi = abDefineeIdOrElse(abApplyArg(sefo, i)((sefo)->abApply.argv[i]), NULL((void*)0)); |
| 5323 | TForm tfe; |
| 5324 | |
| 5325 | if (!si || !argi) continue; |
| 5326 | assert(abTag(argi) == AB_Id)do { if (!(((argi)->abHdr.tag) == AB_Id)) _do_assert(("abTag(argi) == AB_Id" ),"tform.c",5326); } while (0); |
| 5327 | |
| 5328 | /* |
| 5329 | * apply: (me, Enumerate(ni: Type)) -> Ai |
| 5330 | * set!: (me, Enumerate(ni: Type), Ai) -> Ai |
| 5331 | */ |
| 5332 | |
| 5333 | tfe = tfEnum(stab, argi); |
| 5334 | |
| 5335 | tfm = tfMap(tfMulti(2, me, tfe), tfi); |
| 5336 | syme = tfNewRepSyme(stab, ssymApply, tfm, code); |
| 5337 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5338 | |
| 5339 | if (!listMemq(Syme)(Syme_listPointer->Memq)(tfSymes(tf)((tf)->symes), si)) { |
| 5340 | tfm = tfMap(tfMulti(3, me, tfe, tfi), tfi); |
| 5341 | syme = tfNewRepSyme(stab, ssymSetBang, tfm, code); |
| 5342 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | symes = tfSymesFrDepGroup(stab, me, tfc, symes); |
| 5347 | symes = listNReverse(Syme)(Syme_listPointer->NReverse)(symes); |
| 5348 | |
| 5349 | stabSetSubstable(stab)(((stab)->first)->isSubstable=1); |
| 5350 | return symes; |
| 5351 | } |
| 5352 | |
| 5353 | localstatic SymeList |
| 5354 | tfSymesFrDepGroup(Stab stab, TForm me, TForm tfc, SymeList symes) |
| 5355 | { |
| 5356 | return symes; |
| 5357 | } |
| 5358 | |
| 5359 | localstatic SymeList |
| 5360 | tfSymesFrTrailingArray(Stab stab, TForm tf, Sefo sefo) |
| 5361 | { |
| 5362 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 5363 | Syme syme; |
| 5364 | Length i, iargc, aargc; |
| 5365 | TForm me = tfFrSelf(stab, tf); |
| 5366 | TForm atf, itf, tfc, tfm; |
| 5367 | Sefo isefo, asefo; |
| 5368 | Hash code = abHash(sefo); |
| 5369 | |
| 5370 | /* We might have an invalid TForm here... */ |
| 5371 | if (tfArgc(tf)((tf)->argc) != 2) return listNil(Syme)((SymeList) 0); |
| 5372 | |
| 5373 | /* |
| 5374 | * TrailingArray((i1: I1, i2: I2..., IN), (A1,A2,...AN)) |
| 5375 | * [ ]: (I1, ..., IN) -> Tuple Cross A -> me |
| 5376 | * trailingArray: (A1, ..., AN) -> Tuple Cross A -> me |
| 5377 | * dispose!: me -> () |
| 5378 | */ |
| 5379 | |
| 5380 | itf = tfTrailingIArg(tf)tfFollowArg(tf,((int) 0)); |
| 5381 | atf = tfTrailingAArg(tf)tfFollowArg(tf,1); |
| 5382 | aargc = tfAsMultiArgc(atf); |
| 5383 | iargc = tfAsMultiArgc(itf); |
| 5384 | |
| 5385 | isefo = abApplyArg(sefo, int0)((sefo)->abApply.argv[((int) 0)]); |
| 5386 | asefo = abApplyArg(sefo, 1)((sefo)->abApply.argv[1]); |
| 5387 | |
| 5388 | if (!tfIsMulti(itf)(((itf)->tag) == TF_Multiple)) itf = tfMulti(1, itf); |
| 5389 | if (!tfIsMulti(atf)(((atf)->tag) == TF_Multiple)) atf = tfMulti(1, atf); |
| 5390 | tfc = tfNewEmpty(TF_Multiple, 3); |
| 5391 | tfc->argv[0] = tfMachineInteger; |
| 5392 | tfc->argv[1] = tfCrossFrMulti(itf); |
| 5393 | tfc->argv[2] = tfCrossFrMulti(atf); |
| 5394 | tfSetStab(tfc, abStab(sefo))((tfc)->stab = (((sefo)->abHdr.seman ? (sefo)->abHdr .seman->stab : 0))); |
| 5395 | tfSetSymes(tfc, tfSymesFrMulti(tfc))((tfc)->symes = (tfSymesFrMulti(tfc))); |
| 5396 | tfSetStab(tfc, NULL)((tfc)->stab = (((void*)0))); |
| 5397 | |
| 5398 | tfm = tfMap(tfc, me); |
| 5399 | tfSetStab(tfm, abStab(sefo))((tfm)->stab = (((sefo)->abHdr.seman ? (sefo)->abHdr .seman->stab : 0))); |
| 5400 | tfSetSymes(tfm, tfSymesFrMap(tfm))((tfm)->symes = (tfSymesFrMap(tfm))); |
| 5401 | tfSetStab(tfm, NULL)((tfm)->stab = (((void*)0))); |
| 5402 | |
| 5403 | syme = tfNewRepSyme(stab, ssymTheTrailingArray, tfm, code); |
| 5404 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5405 | |
| 5406 | syme = tfNewRepSyme(stab, ssymBracket, tfm, code); |
| 5407 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5408 | |
| 5409 | tfc = tfMulti(int0((int) 0)); |
| 5410 | tfm = tfMap(me, tfc); |
| 5411 | |
| 5412 | syme = tfNewRepSyme(stab, ssymTheDispose, tfm, code); |
| 5413 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5414 | |
| 5415 | for (i = 0; i < iargc; i += 1) { |
| 5416 | TForm tfi = tfAsMultiArgN(itf, iargc, i); |
| 5417 | Syme si = tfDefineeSyme(tfi); |
| 5418 | Sefo argi = abDefineeIdOrElse(abArgvAs(AB_Comma, isefo)(((isefo)->abHdr.tag == (AB_Comma)) ? ((isefo)->abGen.data .argv) : &(isefo))[i], NULL((void*)0)); |
| 5419 | TForm tfe; |
| 5420 | |
| 5421 | if (!si || !argi) continue; |
| 5422 | assert(abTag(argi) == AB_Id)do { if (!(((argi)->abHdr.tag) == AB_Id)) _do_assert(("abTag(argi) == AB_Id" ),"tform.c",5422); } while (0); |
| 5423 | |
| 5424 | /* |
| 5425 | * apply: (me, 'ni') -> Ii |
| 5426 | * set!: (me, 'ni', Ii) -> Ii |
| 5427 | */ |
| 5428 | |
| 5429 | tfe = tfEnum(stab, argi); |
| 5430 | |
| 5431 | tfm = tfMap(tfMulti(2, me, tfe), tfi); |
| 5432 | syme = tfNewRepSyme(stab, ssymApply, tfm, code); |
| 5433 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5434 | |
| 5435 | if (!listMemq(Syme)(Syme_listPointer->Memq)(tfSymes(tf)((tf)->symes), si)) { |
| 5436 | tfm = tfMap(tfMulti(3, me, tfe, tfi), tfi); |
| 5437 | syme = tfNewRepSyme(stab, ssymSetBang, tfm, code); |
| 5438 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5439 | } |
| 5440 | |
| 5441 | } |
| 5442 | |
| 5443 | for (i = 0; i < aargc; i++) { |
| 5444 | TForm tfi = tfAsMultiArgN(atf, aargc, i); |
| 5445 | Syme si = tfDefineeSyme(tfi); |
| 5446 | Sefo argi = abDefineeIdOrElse(abArgvAs(AB_Comma, asefo)(((asefo)->abHdr.tag == (AB_Comma)) ? ((asefo)->abGen.data .argv) : &(asefo))[i], NULL((void*)0)); |
| 5447 | TForm tfe; |
| 5448 | |
| 5449 | if (!si || !argi) continue; |
| 5450 | assert(abTag(argi) == AB_Id)do { if (!(((argi)->abHdr.tag) == AB_Id)) _do_assert(("abTag(argi) == AB_Id" ),"tform.c",5450); } while (0); |
| 5451 | /* |
| 5452 | * apply: (me, MachineInteger, 'ni') -> Ai |
| 5453 | * set!: (me, MachineInteger, 'ni', Ii) -> Ai |
| 5454 | */ |
| 5455 | tfe = tfEnum(stab, argi); |
| 5456 | |
| 5457 | tfm = tfMap(tfMulti(3, me, tfMachineInteger, tfe), tfi); |
| 5458 | syme = tfNewRepSyme(stab, ssymApply, tfm, code); |
| 5459 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5460 | |
| 5461 | if (!listMemq(Syme)(Syme_listPointer->Memq)(tfSymes(tf)((tf)->symes), si)) { |
| 5462 | tfm = tfMap(tfMulti(4, me, tfMachineInteger, tfe, tfi), tfi); |
| 5463 | syme = tfNewRepSyme(stab, ssymSetBang, tfm, code); |
| 5464 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5465 | } |
| 5466 | } |
| 5467 | |
| 5468 | symes = listNReverse(Syme)(Syme_listPointer->NReverse)(symes); |
| 5469 | |
| 5470 | stabSetSubstable(stab)(((stab)->first)->isSubstable=1); |
| 5471 | #if 0 |
| 5472 | tfPrintDb(tf); |
| 5473 | abPrintDb(sefo); |
| 5474 | symeListPrintDb(symes); |
| 5475 | #endif |
| 5476 | return symes; |
| 5477 | } |
| 5478 | |
| 5479 | localstatic SymeList |
| 5480 | tfSymesFrUnion(Stab stab, TForm tf, Sefo sefo) |
| 5481 | { |
| 5482 | Syme syme; |
| 5483 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 5484 | Length i, argc = abApplyArgc(sefo)(((sefo)->abHdr.argc)-1); |
| 5485 | TForm me = tfFrSelf(stab, tf), tfm, tfc; |
| 5486 | Hash code = abHash(sefo); |
| 5487 | |
| 5488 | /* |
| 5489 | * dispose!: me -> () |
| 5490 | */ |
| 5491 | tfc = tfMulti(int0((int) 0)); |
| 5492 | tfm = tfMap(me, tfc); |
| 5493 | |
| 5494 | syme = tfNewRepSyme(stab, ssymTheDispose, tfm, code); |
| 5495 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5496 | |
| 5497 | for (i = 0; i < argc; i += 1) { |
| 5498 | TForm tfi = tf->argv[i]; |
| 5499 | TForm tfit = tfDefineeType(tfi); |
Value stored to 'tfit' during its initialization is never read | |
| 5500 | Sefo argi = abDefineeIdOrElse(abApplyArg(sefo, i)((sefo)->abApply.argv[i]), NULL((void*)0)); |
| 5501 | TForm tfe; |
| 5502 | TForm tfc; |
| 5503 | Syme prmi, vali; |
| 5504 | String pname; |
| 5505 | if (! argi) continue; |
| 5506 | assert(abTag(argi) == AB_Id)do { if (!(((argi)->abHdr.tag) == AB_Id)) _do_assert(("abTag(argi) == AB_Id" ),"tform.c",5506); } while (0); |
| 5507 | |
| 5508 | /* |
| 5509 | * [ ]: Ai -> me |
| 5510 | * union: Ai -> me |
| 5511 | */ |
| 5512 | tfe = tfEnum(stab, argi); |
| 5513 | pname = strPrintf("!%s", argi->abId.sym->str); |
| 5514 | prmi = symeNewParam(symIntern(pname)symProbe(pname, 1 | 2), tfe, car(stab)((stab)->first)); |
| 5515 | strFree(pname); |
| 5516 | vali = symeNewImport(argi->abId.sym, tfe, car(stab)((stab)->first), |
| 5517 | tfe); |
| 5518 | symeSetSpecial(vali)(((((vali)->kind == SYME_Trigger ? libGetAllSymes((vali)-> lib) : ((void*)0)), (vali))->bits) |= (0x0002)); |
| 5519 | tfc = tfDeclare(abFrSyme(prmi), tfe); |
| 5520 | tfc = tfDefine(tfc, abFrSyme(vali)); |
| 5521 | tfc = tfMulti(2, tfi, tfc); |
| 5522 | tfm = tfMap(tfc, me); |
| 5523 | syme = tfNewRepSyme(stab, ssymBracket, tfm, code); |
| 5524 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5525 | |
| 5526 | syme = tfNewRepSyme(stab, ssymTheUnion, tfm, code); |
| 5527 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5528 | |
| 5529 | /* |
| 5530 | * case: (me, Enumerate(ni: Type)) -> Boolean |
| 5531 | * apply: (me, Enumerate(ni: Type)) -> Ai |
| 5532 | * set!: (me, Enumerate(ni: Type), Ai) -> Ai |
| 5533 | */ |
| 5534 | tfe = tfEnum(stab, argi); |
| 5535 | tfc = tfMulti(2, me, tfe); |
| 5536 | |
| 5537 | /* |
| 5538 | * An unfixed compiler bug means that parts of Salli |
| 5539 | * programs (and thus libAldor) are tinfered with |
| 5540 | * (tfBoolean == tfUnknown). The correct fix is to |
| 5541 | * ensure that tfBoolean has been imported into every |
| 5542 | * scope that needs it before we get this far. |
| 5543 | */ |
| 5544 | if (tfBoolean == tfUnknown) |
| 5545 | comsgFatal(sefo, ALDOR_F_BugNoBoolean367); |
| 5546 | tfm = tfMap(tfc, tfBoolean); |
| 5547 | syme = tfNewRepSyme(stab, ssymTheCase, tfm, code); |
| 5548 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5549 | |
| 5550 | tfm = tfMap(tfc, tfi); |
| 5551 | syme = tfNewRepSyme(stab, ssymApply, tfm, code); |
| 5552 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5553 | |
| 5554 | tfm = tfMap(tfMulti(3, me, tfe, tfi), tfi); |
| 5555 | syme = tfNewRepSyme(stab, ssymSetBang, tfm, code); |
| 5556 | symes = listCons(Syme)(Syme_listPointer->Cons)(syme, symes); |
| 5557 | } |
| 5558 | |
| 5559 | symes = listNReverse(Syme)(Syme_listPointer->NReverse)(symes); |
| 5560 | |
| 5561 | stabSetSubstable(stab)(((stab)->first)->isSubstable=1); |
| 5562 | return symes; |
| 5563 | } |
| 5564 | |
| 5565 | localstatic SymeList |
| 5566 | tfSymesFrAdd(Sefo sefo) |
| 5567 | { |
| 5568 | assert(abStab(sefo))do { if (!(((sefo)->abHdr.seman ? (sefo)->abHdr.seman-> stab : 0))) _do_assert(("abStab(sefo)"),"tform.c",5568); } while (0); |
| 5569 | return stabGetExportedSymes(abStab(sefo)((sefo)->abHdr.seman ? (sefo)->abHdr.seman->stab : 0 )); |
| 5570 | } |
| 5571 | |
| 5572 | Bool |
| 5573 | tfHasPrint(Stab stab, TForm tf) |
| 5574 | { |
| 5575 | TForm tfm; |
| 5576 | TForm me = tfFrSelf(stab, tf); |
| 5577 | SymeList mods = tfGetDomSelf(tf); |
| 5578 | Syme thePrint; |
| 5579 | |
| 5580 | tfm = tfMap(tfMulti(2, tfTextWriter, me), tfTextWriter); |
| 5581 | thePrint = tfHasDomExportMod(tf, mods, ssymPrint, tfm); |
| 5582 | |
| 5583 | return thePrint != NULL((void*)0); |
| 5584 | } |
| 5585 | |
| 5586 | /* tfSymesFrDefault handles conditionals spectacularly badly. |
| 5587 | * It isn't clear how to modify tfGetCat{Exports,Parents}FrWith |
| 5588 | * to do the right thing, even if we manage to remember what the |
| 5589 | * conditions are. Modifying the meanings in place is probably |
| 5590 | * doomed. |
| 5591 | */ |
| 5592 | |
| 5593 | localstatic SymeList |
| 5594 | tfSymesFrDefault(Sefo sefo) |
| 5595 | { |
| 5596 | SymeList symes = listNil(Syme)((SymeList) 0); |
| 5597 | Length i, argc; |
| 5598 | Sefo *argv; |
| 5599 | Sefo id; |
| 5600 | |
| 5601 | switch (abTag(sefo)((sefo)->abHdr.tag)) { |
| 5602 | case AB_Nothing: |
| 5603 | argc = 0; |
| 5604 | argv = 0; |
| 5605 | break; |
| 5606 | case AB_Sequence: |
| 5607 | argc = abArgc(sefo)((sefo)->abHdr.argc); |
| 5608 | argv = abArgv(sefo)((sefo)->abGen.data.argv); |
| 5609 | break; |
| 5610 | case AB_If: |
| 5611 | argc = 2; |
| 5612 | argv = &sefo->abIf.thenAlt; |
| 5613 | break; |
| 5614 | default: |
| 5615 | id = abDefineeIdOrElse(sefo, NULL((void*)0)); |
| 5616 | assert(id == NULL || abSyme(id))do { if (!(id == ((void*)0) || ((id)->abHdr.seman ? (id)-> abHdr.seman->syme : 0))) _do_assert(("id == NULL || abSyme(id)" ),"tform.c",5616); } while (0); |
| 5617 | if (id && abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0) && symeIsExport(abSyme(id))(((((((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0 ))->kind == SYME_Trigger ? libGetAllSymes((((id)->abHdr .seman ? (id)->abHdr.seman->syme : 0))->lib) : ((void *)0)), (((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0)))->kind) == SYME_Export)) |
| 5618 | symes = listCons(Syme)(Syme_listPointer->Cons)(abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0), symes); |
| 5619 | return symes; |
| 5620 | } |
| 5621 | |
| 5622 | symes = listNil(Syme)((SymeList) 0); |
| 5623 | for (i = 0; i < argc; i += 1) { |
| 5624 | symes = listNConcat(Syme)(Syme_listPointer->NConcat)(tfSymesFrDefault(argv[i]), symes); |
| 5625 | } |
| 5626 | |
| 5627 | return symes; |
| 5628 | } |
| 5629 | |
| 5630 | |
| 5631 | /* |
| 5632 | * Functions to construct abstract syntax from representational symes. |
| 5633 | */ |
| 5634 | |
| 5635 | localstatic AbSyn |
| 5636 | tfSymesToAdd(SymeList symes) |
| 5637 | { |
| 5638 | /*!!*/ |
| 5639 | return abNewNothing(sposNone)abNew(AB_Nothing, sposNone,0 ); |
| 5640 | } |
| 5641 | |
| 5642 | AbSyn |
| 5643 | tfSymesToWith(SymeList symes) |
| 5644 | { |
| 5645 | AbSyn ab; |
| 5646 | AbSynList decls; |
| 5647 | Length argc; |
| 5648 | |
| 5649 | decls = listNil(AbSyn)((AbSynList) 0); |
| 5650 | for ( ; symes; symes = cdr(symes)((symes)->rest)) { |
| 5651 | Syme syme = car(symes)((symes)->first); |
| 5652 | AbSyn id, type, decl; |
| 5653 | |
| 5654 | id = abFrSyme(syme); |
| 5655 | type = sefoCopy(tfExpr(symeType(syme))tfToAbSyn(symeType(syme))); |
| 5656 | |
| 5657 | decl = abNewDeclare(sposNone, id, type)abNew(AB_Declare, sposNone,2, id,type); |
| 5658 | decls = listCons(AbSyn)(AbSyn_listPointer->Cons)(decl, decls); |
| 5659 | } |
| 5660 | |
| 5661 | argc = listLength(AbSyn)(AbSyn_listPointer->_Length)(decls); |
| 5662 | switch (argc) { |
| 5663 | case 0: |
| 5664 | ab = abNewNothing(sposNone)abNew(AB_Nothing, sposNone,0 ); |
| 5665 | break; |
| 5666 | case 1: |
| 5667 | ab = car(decls)((decls)->first); |
| 5668 | break; |
| 5669 | default: |
| 5670 | ab = abNewSequenceL(sposNone, listNReverse(AbSyn)(decls))abNewOfList(AB_Sequence,sposNone,(AbSyn_listPointer->NReverse )(decls)); |
| 5671 | break; |
| 5672 | } |
| 5673 | |
| 5674 | listFree(AbSyn)(AbSyn_listPointer->Free)(decls); |
| 5675 | return ab; |
| 5676 | } |
| 5677 | |
| 5678 | AbSyn |
| 5679 | tfWithFrAdd(AbSyn ab) |
| 5680 | { |
| 5681 | return tfSymesToWith(listNReverse(Syme)(Syme_listPointer->NReverse)(tfSymesFrAdd(ab))); |
| 5682 | } |
| 5683 | |
| 5684 | |
| 5685 | /****************************************************************************** |
| 5686 | * |
| 5687 | * :: Specific import/export selection |
| 5688 | * |
| 5689 | *****************************************************************************/ |
| 5690 | |
| 5691 | /* |
| 5692 | * Select an import from an exporter. Wonder if tformEqualMod works? |
| 5693 | */ |
| 5694 | Syme |
| 5695 | tfGetDomImport(TForm tf, String name, Bool (*tfCheck)(TForm)) |
| 5696 | { |
| 5697 | Syme result = tfGetDomExport(tf, name, tfCheck); |
| 5698 | |
| 5699 | /* Did we find the export? */ |
| 5700 | if (result) |
| 5701 | { |
| 5702 | SymeList symes; |
| 5703 | |
| 5704 | /* Convert the export into an import */ |
| 5705 | symes = listSingleton(Syme)(Syme_listPointer->Singleton)(result); |
| 5706 | symes = symeListSubstSelf(stabFile(), tf, symes); |
| 5707 | result = car(symes)((symes)->first); |
| 5708 | } |
| 5709 | |
| 5710 | |
| 5711 | /* Return the export (or nothing) */ |
| 5712 | return result; |
| 5713 | } |
| 5714 | |
| 5715 | /* |
| 5716 | * Select an export from an exporter. Wonder if tformEqualMod works? |
| 5717 | */ |
| 5718 | Syme |
| 5719 | tfGetDomExport(TForm tf, String name, Bool (*tfCheck)(TForm)) |
| 5720 | { |
| 5721 | Syme op = (Syme)NULL((void*)0); |
| 5722 | SymeList symes = tfGetDomExports(tf); |
| 5723 | |
| 5724 | |
| 5725 | /* Search for the specified export */ |
| 5726 | for (;!op && symes; symes = cdr(symes)((symes)->rest)) |
| 5727 | { |
| 5728 | Syme syme = car(symes)((symes)->first); |
| 5729 | |
| 5730 | |
| 5731 | /* Does this export have the correct name? */ |
| 5732 | if (!strEqual(name, symeString(syme)((((syme)->id))->str))) continue; |
| 5733 | |
| 5734 | |
| 5735 | /* Check the type */ |
| 5736 | if (!tfCheck(symeType(syme))) continue; |
| 5737 | |
| 5738 | |
| 5739 | /* Found it (assume type is correct) */ |
| 5740 | op = syme; |
| 5741 | } |
| 5742 | |
| 5743 | |
| 5744 | /* Return the export (or nothing) */ |
| 5745 | return op; |
| 5746 | } |
| 5747 | |
| 5748 | |
| 5749 | /****************************************************************************** |
| 5750 | * |
| 5751 | * :: Special type forms |
| 5752 | * |
| 5753 | *****************************************************************************/ |
| 5754 | |
| 5755 | /* |
| 5756 | * Type form utility functions |
| 5757 | */ |
| 5758 | |
| 5759 | /* Find the symbol in a Declare/Define/Assign type form. */ |
| 5760 | Symbol |
| 5761 | tfDefineeSymbol(TForm tf) |
| 5762 | { |
| 5763 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 5764 | |
| 5765 | while (tfTag(tf)((tf)->tag) != TF_Declare) { |
| 5766 | switch (tfTag(tf)((tf)->tag)) { |
| 5767 | case TF_Assign: |
| 5768 | tf = tfAssignDecl(tf)tfFollowArg(tf, 0); |
| 5769 | break; |
| 5770 | case TF_Define: |
| 5771 | tf = tfDefineDecl(tf)tfFollowArg(tf, 0); |
| 5772 | break; |
| 5773 | case TF_Multiple: |
| 5774 | if (tfMultiArgc(tf) == 1) { |
| 5775 | tf = tfMultiArgN(tf, int0)tfFollowArg(tf, ((int) 0)); |
| 5776 | break; |
| 5777 | } |
| 5778 | /* fall through */ |
| 5779 | default: |
| 5780 | return NULL((void*)0); |
| 5781 | } |
| 5782 | tf = tfFollowSubst(tf); |
| 5783 | } |
| 5784 | return tfDeclareId(tf); |
| 5785 | } |
| 5786 | |
| 5787 | /* Find the syme in a Declare/Define/Assign type form. */ |
| 5788 | Syme |
| 5789 | tfDefineeSyme(TForm tf) |
| 5790 | { |
| 5791 | tf = tfFollowOnly(tf); |
| 5792 | |
| 5793 | while (tfTag(tf)((tf)->tag) != TF_Declare) |
| 5794 | switch (tfTag(tf)((tf)->tag)) { |
| 5795 | case TF_Syntax: { |
| 5796 | AbSyn id = abDefineeIdOrElse(tfExpr(tf)tfToAbSyn(tf), NULL((void*)0)); |
| 5797 | if (id && abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0)) |
| 5798 | return abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0); |
| 5799 | else |
| 5800 | return NULL((void*)0); |
| 5801 | break; |
| 5802 | } |
| 5803 | case TF_Subst: |
| 5804 | if (tfDefineeSyme(tfSubstArg(tf)tfFollowArg(tf, 0))) |
| 5805 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 5806 | else |
| 5807 | return NULL((void*)0); |
| 5808 | break; |
| 5809 | case TF_Assign: |
| 5810 | tf = tfAssignDecl(tf)tfFollowArg(tf, 0); |
| 5811 | break; |
| 5812 | case TF_Define: |
| 5813 | tf = tfDefineDecl(tf)tfFollowArg(tf, 0); |
| 5814 | break; |
| 5815 | case TF_Multiple: |
| 5816 | if (tfMultiArgc(tf) == 1) |
| 5817 | tf = tfMultiArgN(tf, int0)tfFollowArg(tf, ((int) 0)); |
| 5818 | else |
| 5819 | return NULL((void*)0); |
| 5820 | break; |
| 5821 | default: |
| 5822 | return NULL((void*)0); |
| 5823 | } |
| 5824 | |
| 5825 | return tfDeclareSyme(tf); |
| 5826 | } |
| 5827 | |
| 5828 | /* Find the type in a Declare/Define/Assign type form. */ |
| 5829 | localstatic TForm |
| 5830 | tfDefineeType0(TForm tf, Bool subst) |
| 5831 | { |
| 5832 | Bool done = false((int) 0); |
| 5833 | |
| 5834 | while (!done) { |
| 5835 | if (subst) |
| 5836 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 5837 | else |
| 5838 | tf = tfFollowSubst(tf); |
| 5839 | |
| 5840 | switch (tfTag(tf)((tf)->tag)) { |
| 5841 | case TF_Declare: |
| 5842 | tf = tfDeclareType(tf)tfFollowArg(tf, 0); |
| 5843 | break; |
| 5844 | case TF_Assign: |
| 5845 | tf = tfAssignDecl(tf)tfFollowArg(tf, 0); |
| 5846 | break; |
| 5847 | case TF_Define: |
| 5848 | if (tfIsDefineOfType(tf)) { |
| 5849 | TForm cat = tfGetCategory(tfDefineVal(tf)tfFollowArg(tf, 1)); |
| 5850 | if (tfIsUnknown(cat)(((cat)->tag) == TF_Unknown)) |
| 5851 | tf = tfDefineDecl(tf)tfFollowArg(tf, 0); |
| 5852 | else |
| 5853 | tf = cat; |
| 5854 | } |
| 5855 | else |
| 5856 | tf = tfDefineDecl(tf)tfFollowArg(tf, 0); |
| 5857 | break; |
| 5858 | default: |
| 5859 | done = true1; |
| 5860 | break; |
| 5861 | } |
| 5862 | } |
| 5863 | |
| 5864 | return tf; |
| 5865 | } |
| 5866 | |
| 5867 | /* |
| 5868 | * Walk down the definitions/declares/assigns to get the base type. |
| 5869 | * This is essentially a function to compute the normal-form of tf |
| 5870 | * when this is possible. Unfortunately some type definitions cause |
| 5871 | * us to expand a type to the same tform and we end up looping. To |
| 5872 | * prevent this we keep a list of all expansions and check that we |
| 5873 | * haven't come across this one before. Since it is most likely that |
| 5874 | * the previous tform will be the same as the current one we trace |
| 5875 | * backwards towards the original tform. |
| 5876 | * |
| 5877 | * One further twist - we don't want to expand % so we stop as soon |
| 5878 | * as we come across it. We might also want to stop at %% but they |
| 5879 | * are quite a rare beast. |
| 5880 | * |
| 5881 | * Yet another twist - we may not want to replace definitions with |
| 5882 | * the original `add' expression: if `notAdd' is true then we stop |
| 5883 | * before replacing a tform with an add expression. Might want to |
| 5884 | * extend this later for `with'. |
| 5885 | * |
| 5886 | * Problem - we don't want to replace definitions whose type is not |
| 5887 | * known with their value as we lose information. |
| 5888 | */ |
| 5889 | localstatic TForm |
| 5890 | tfDefineeType1(TForm tf, Bool subst, Bool notAdd) |
| 5891 | { |
| 5892 | Length depth = 0; |
| 5893 | Bool done = false((int) 0); |
| 5894 | TFormList seen = listNil(TForm)((TFormList) 0); |
| 5895 | TFormList tfs; |
| 5896 | |
| 5897 | |
| 5898 | /* Continually expand tf */ |
| 5899 | while (!done) |
| 5900 | { |
| 5901 | /* Stop this time unless there is a reason not to */ |
| 5902 | done = true1; |
| 5903 | |
| 5904 | |
| 5905 | /* Be brutal ... */ |
| 5906 | tf = tfDefineeType0(tf, subst); |
| 5907 | |
| 5908 | |
| 5909 | /* We don't expand % */ |
| 5910 | if (tfIsSelf(tf)(((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Id) && (((tf)->__absyn)-> abId.sym) == (ssymSelf))) break; |
| 5911 | |
| 5912 | |
| 5913 | /* Check previous tforms in case of cycles */ |
| 5914 | for (tfs = seen;tfs;tfs = cdr(tfs)((tfs)->rest)) |
| 5915 | { |
| 5916 | /* Have we seen this tform before? */ |
| 5917 | if (tfEqual(car(tfs)((tfs)->first), tf)) |
| 5918 | goto byeBye; /* Yes */ |
| 5919 | } |
| 5920 | |
| 5921 | |
| 5922 | /* No - are we in too deep? */ |
| 5923 | if (depth > tfMaxBaseSearchDepth) |
| 5924 | { |
| 5925 | bugWarning("tfDefineeType1: too deep"); |
| 5926 | break; /* Yes */ |
| 5927 | } |
| 5928 | |
| 5929 | |
| 5930 | /* No - push tform onto the list of tforms seen */ |
| 5931 | seen = listCons(TForm)(TForm_listPointer->Cons)(tf, seen); |
| 5932 | depth++; |
| 5933 | |
| 5934 | |
| 5935 | /* See if we can expand further */ |
| 5936 | if (tfIsAbSyn(tf)( TF_ABSYN_START <= (((tf)->tag)) && (((tf)-> tag)) < TF_ABSYN_LIMIT)) |
| 5937 | { |
| 5938 | TForm tfn = (TForm) NULL((void*)0); |
| 5939 | Sefo sefo = tfGetExpr(tf)((tf)->__absyn); |
| 5940 | TForm cat = abGetCategory(sefo); |
| 5941 | |
| 5942 | |
| 5943 | /* Did we get anything useful? */ |
| 5944 | switch (tfTag(cat)((cat)->tag)) |
| 5945 | { |
| 5946 | case TF_Assign: |
| 5947 | tfn = tfAssignVal(cat)tfFollowArg(cat, 1); |
| 5948 | done = false((int) 0); /* Not finished yet */ |
| 5949 | break; |
| 5950 | case TF_Define: |
| 5951 | tfn = tfDefineVal(cat)tfFollowArg(cat, 1); |
| 5952 | done = false((int) 0); /* Not finished yet */ |
| 5953 | break; |
| 5954 | default: |
| 5955 | /* Finished */ |
| 5956 | break; |
| 5957 | } |
| 5958 | |
| 5959 | |
| 5960 | /* We must tread carefully again */ |
| 5961 | if (!done) |
| 5962 | { |
| 5963 | /* Must have something to replace */ |
| 5964 | if (!tfn) |
| 5965 | { |
| 5966 | done = true1; |
| 5967 | continue; |
| 5968 | } |
| 5969 | |
| 5970 | |
| 5971 | /* Can't replace with add unless OK'd */ |
| 5972 | if (notAdd && (tfTag(tfn)((tfn)->tag) == TF_Add)) |
| 5973 | { |
| 5974 | done = true1; |
| 5975 | continue; |
| 5976 | } |
| 5977 | |
| 5978 | |
| 5979 | /* Special tforms are fine */ |
| 5980 | if (!tfIsAbSyn(tfn)( TF_ABSYN_START <= (((tfn)->tag)) && (((tfn)-> tag)) < TF_ABSYN_LIMIT)) |
| 5981 | { |
| 5982 | /* Do the replacement */ |
| 5983 | tf = tfn; |
| 5984 | continue; |
| 5985 | } |
| 5986 | |
| 5987 | |
| 5988 | /* Get the absyn */ |
| 5989 | sefo = tfGetExpr(tfn)((tfn)->__absyn); |
| 5990 | |
| 5991 | |
| 5992 | /* Don't replace if it is a sequence */ |
| 5993 | if (!abHasTag(sefo, AB_Sequence)((sefo)->abHdr.tag == (AB_Sequence))) |
| 5994 | tf = tfn; |
| 5995 | else |
| 5996 | done = true1; |
| 5997 | } |
| 5998 | } |
| 5999 | } |
| 6000 | |
| 6001 | |
| 6002 | /* Common exit-point */ |
| 6003 | byeBye: |
| 6004 | listFree(TForm)(TForm_listPointer->Free)(seen); |
| 6005 | return tf; |
| 6006 | } |
| 6007 | |
| 6008 | TForm |
| 6009 | tfDefineeType(TForm tf) |
| 6010 | { |
| 6011 | return tfDefineeType0(tf, true1); |
| 6012 | } |
| 6013 | |
| 6014 | TForm |
| 6015 | tfDefineeTypeSubst(TForm tf) |
| 6016 | { |
| 6017 | return tfDefineeType0(tf, false((int) 0)); |
| 6018 | } |
| 6019 | |
| 6020 | TForm |
| 6021 | tfDefineeBaseType(TForm tf) |
| 6022 | { |
| 6023 | /* Normalise tf if possible */ |
| 6024 | extern Bool stabDumbImport(void); |
| 6025 | return tfDefineeType1(tf, true1, !stabDumbImport()); /* true); */ |
| 6026 | } |
| 6027 | |
| 6028 | /* |
| 6029 | * Same as tfDefineeType but if it can be expanded |
| 6030 | * further then we do so. |
| 6031 | */ |
| 6032 | TForm |
| 6033 | tfDefineeMaybeType(TForm tf) |
| 6034 | { |
| 6035 | /* Deal with delta-equality */ |
| 6036 | if (tfIsAbSynTag(tfTag(tf))( TF_ABSYN_START <= (((tf)->tag)) && (((tf)-> tag)) < TF_ABSYN_LIMIT)) |
| 6037 | tf = tfDefineeBaseType(tf); |
| 6038 | return tf; |
| 6039 | } |
| 6040 | |
| 6041 | /* |
| 6042 | * Type form symbols |
| 6043 | */ |
| 6044 | |
| 6045 | /* These are initialized in tfInit(). */ |
| 6046 | AbSyn abUnknown; |
| 6047 | TForm tfUnknown; |
| 6048 | TForm tfExit; |
| 6049 | TForm tfLiteral; |
| 6050 | TForm tfTest; |
| 6051 | TForm tfType; |
| 6052 | TForm tfTypeTuple; |
| 6053 | TForm tfCategory; |
| 6054 | TForm tfDomain; |
| 6055 | TForm tfBoolean; |
| 6056 | TForm tfTextWriter; |
| 6057 | TForm tfMachineInteger; |
| 6058 | |
| 6059 | /* Is tf the type of a domain? */ |
| 6060 | Bool |
| 6061 | tfIsDomainType(TForm tf) |
| 6062 | { |
| 6063 | if (tfIsSyntax(tf)(((tf)->tag) == TF_Syntax)) |
| 6064 | return abHasTag(tfGetExpr(tf), AB_With)((((tf)->__absyn))->abHdr.tag == (AB_With)); |
| 6065 | |
| 6066 | if (tfIsDefine(tf)(((tf)->tag) == TF_Define) && tfIsDeclare(tfDefineDecl(tf))(((tfFollowArg(tf, 0))->tag) == TF_Declare)) |
| 6067 | return tfIsWith(tfDeclareType(tfDefineDecl(tf)))(((tfFollowArg(tfFollowArg(tf, 0), 0))->tag) == TF_With); |
| 6068 | |
| 6069 | if (tfIsJoin(tf)(((tf)->tag) == TF_Join)) |
| 6070 | return true1; |
| 6071 | |
| 6072 | if (tfIsCategoryType(tfGetCategory(tf))) |
| 6073 | return true1; |
| 6074 | return false((int) 0); |
| 6075 | } |
| 6076 | |
| 6077 | /* Is tf the type of a domain constructor? */ |
| 6078 | Bool |
| 6079 | tfIsDomainMap(TForm tf) |
| 6080 | { |
| 6081 | if (tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap ))) |
| 6082 | return tfIsDomainMap(tfMapRet(tf)tfFollowArg(tf, 1)); |
| 6083 | else |
| 6084 | return tfIsDomainType(tf); |
| 6085 | } |
| 6086 | |
| 6087 | /* Is tf the type of a category? */ |
| 6088 | Bool |
| 6089 | tfIsCategoryType(TForm tf) |
| 6090 | { |
| 6091 | AbSyn ab = NULL((void*)0); |
| 6092 | |
| 6093 | tf = tfFollowSubst(tf); |
| 6094 | |
| 6095 | if (tfIsDefine(tf)(((tf)->tag) == TF_Define) && tfIsDeclare(tfDefineDecl(tf))(((tfFollowArg(tf, 0))->tag) == TF_Declare)) |
| 6096 | return tfIsCategoryType(tfDeclareType(tfDefineDecl(tf))tfFollowArg(tfFollowArg(tf, 0), 0)); |
| 6097 | |
| 6098 | if (tfIsCategory(tf)(((tf)->tag) == TF_Category) || tfIsThird(tf)(((tf)->tag) == TF_Third)) |
| 6099 | return true1; |
| 6100 | |
| 6101 | if (tfIsSyntax(tf)(((tf)->tag) == TF_Syntax)) |
| 6102 | ab = tfGetExpr(tf)((tf)->__absyn); |
| 6103 | |
| 6104 | return ab && abIsTheId(ab, ssymCategory)(((ab)->abHdr.tag == (AB_Id)) && ((ab)->abId.sym )==(ssymCategory)); |
| 6105 | } |
| 6106 | |
| 6107 | /* Is tf the type of a category constructor? */ |
| 6108 | Bool |
| 6109 | tfIsCategoryMap(TForm tf) |
| 6110 | { |
| 6111 | if (tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap ))) |
| 6112 | return tfIsCategoryMap(tfMapRet(tf)tfFollowArg(tf, 1)); |
| 6113 | else |
| 6114 | return tfIsCategoryType(tf); |
| 6115 | } |
| 6116 | |
| 6117 | /* |
| 6118 | * tfBoolean |
| 6119 | */ |
| 6120 | |
| 6121 | Bool |
| 6122 | tfIsBooleanFn(TForm tf) |
| 6123 | { |
| 6124 | /* |
| 6125 | * An unfixed compiler bug means that parts of Salli |
| 6126 | * programs (and thus libAldor) are tinfered with |
| 6127 | * (tfBoolean == tfUnknown). The correct fix is to |
| 6128 | * ensure that tfBoolean has been imported into every |
| 6129 | * scope that needs it before we get this far. |
| 6130 | */ |
| 6131 | AbSyn ab = tfGetExpr(tf)((tf)->__absyn); |
| 6132 | if (tfBoolean == tfUnknown) comsgFatal(ab, ALDOR_F_BugNoBoolean367); |
| 6133 | return tfSatisfies(tf, tfBoolean); |
| 6134 | } |
| 6135 | |
| 6136 | /* |
| 6137 | * tfLibrary |
| 6138 | */ |
| 6139 | |
| 6140 | TForm |
| 6141 | tfLibrary(Syme syme) |
| 6142 | { |
| 6143 | TForm tf; |
| 6144 | assert(symeIsLibrary(syme))do { if (!((((((syme)->kind == SYME_Trigger ? libGetAllSymes ((syme)->lib) : ((void*)0)), (syme))->kind) == SYME_Library ))) _do_assert(("symeIsLibrary(syme)"),"tform.c",6144); } while (0); |
| 6145 | tf = tfFrSyme(stabFile(), syme); |
| 6146 | if (tfSymes(tf)((tf)->symes) == listNil(Syme)((SymeList) 0)) |
| 6147 | tfSetSymes(tf, listCons(Syme)(syme, listNil(Syme)))((tf)->symes = ((Syme_listPointer->Cons)(syme, ((SymeList ) 0)))); |
| 6148 | return tf; |
| 6149 | } |
| 6150 | |
| 6151 | TForm |
| 6152 | tfGetLibrary(Syme syme) |
| 6153 | { |
| 6154 | Syme osyme = stabGetLibrary(symeId(syme)((syme)->id)); |
| 6155 | if (osyme && libEqual(symeLibrary(osyme)((Lib) (SYFI_Library < (8 * sizeof(int)) && !((((( osyme)->kind == SYME_Trigger ? libGetAllSymes((osyme)-> lib) : ((void*)0)), (osyme))->hasmask) & (1 << ( SYFI_Library))) ? (symeFieldInfo[SYFI_Library].def) : (((((osyme )->kind == SYME_Trigger ? libGetAllSymes((osyme)->lib) : ((void*)0)), (osyme))->locmask) & (1 << (SYFI_Library ))) ? ((((((osyme)->kind == SYME_Trigger ? libGetAllSymes( (osyme)->lib) : ((void*)0)), (osyme))->locmask) & ( 1 << (SYFI_Library))) ? ((osyme)->fieldv)[symeIndex( osyme,SYFI_Library)] : (symeFieldInfo[SYFI_Library].def)) : symeGetFieldFn (osyme,SYFI_Library))), symeLibrary(syme)((Lib) (SYFI_Library < (8 * sizeof(int)) && !((((( syme)->kind == SYME_Trigger ? libGetAllSymes((syme)->lib ) : ((void*)0)), (syme))->hasmask) & (1 << (SYFI_Library ))) ? (symeFieldInfo[SYFI_Library].def) : (((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)->lib) : ((void*)0 )), (syme))->locmask) & (1 << (SYFI_Library))) ? ((((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme) ->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_Library))) ? ((syme)->fieldv)[symeIndex(syme,SYFI_Library )] : (symeFieldInfo[SYFI_Library].def)) : symeGetFieldFn(syme ,SYFI_Library))))) |
| 6156 | syme = osyme; |
| 6157 | return tfLibrary(syme); |
| 6158 | } |
| 6159 | |
| 6160 | Bool |
| 6161 | tfIsLibrary(TForm tf) |
| 6162 | { |
| 6163 | tfFollowSubst(tf); |
| 6164 | return (tfSymes(tf)((tf)->symes) != listNil(Syme)((SymeList) 0)) && |
| 6165 | (symeIsLibrary(car(tfSymes(tf)))(((((((((tf)->symes))->first))->kind == SYME_Trigger ? libGetAllSymes((((((tf)->symes))->first))->lib) : ((void*)0)), (((((tf)->symes))->first)))->kind) == SYME_Library )); |
| 6166 | } |
| 6167 | |
| 6168 | Bool |
| 6169 | tfIsBasicLib(TForm tf) |
| 6170 | { |
| 6171 | if (tfIsLibrary(tf)) |
| 6172 | return libIsBasicLib(tfLibraryLib(tf)); |
| 6173 | else if (tfIsArchive(tf)) |
| 6174 | return arHasBasicLib(tfArchiveAr(tf)); |
| 6175 | else |
| 6176 | return false((int) 0); |
| 6177 | } |
| 6178 | |
| 6179 | Syme |
| 6180 | tfLibrarySyme(TForm tf) |
| 6181 | { |
| 6182 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6183 | return car(tfSymes(tf))((((tf)->symes))->first); |
| 6184 | } |
| 6185 | |
| 6186 | Lib |
| 6187 | tfLibraryLib(TForm tf) |
| 6188 | { |
| 6189 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6190 | return symeLibrary(tfLibrarySyme(tf))((Lib) (SYFI_Library < (8 * sizeof(int)) && !((((( tfLibrarySyme(tf))->kind == SYME_Trigger ? libGetAllSymes( (tfLibrarySyme(tf))->lib) : ((void*)0)), (tfLibrarySyme(tf )))->hasmask) & (1 << (SYFI_Library))) ? (symeFieldInfo [SYFI_Library].def) : (((((tfLibrarySyme(tf))->kind == SYME_Trigger ? libGetAllSymes((tfLibrarySyme(tf))->lib) : ((void*)0)), (tfLibrarySyme(tf)))->locmask) & (1 << (SYFI_Library ))) ? ((((((tfLibrarySyme(tf))->kind == SYME_Trigger ? libGetAllSymes ((tfLibrarySyme(tf))->lib) : ((void*)0)), (tfLibrarySyme(tf )))->locmask) & (1 << (SYFI_Library))) ? ((tfLibrarySyme (tf))->fieldv)[symeIndex(tfLibrarySyme(tf),SYFI_Library)] : (symeFieldInfo[SYFI_Library].def)) : symeGetFieldFn(tfLibrarySyme (tf),SYFI_Library))); |
| 6191 | } |
| 6192 | |
| 6193 | String |
| 6194 | tfLibraryName(TForm tf) |
| 6195 | { |
| 6196 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6197 | return libGetFileId(tfLibraryLib(tf)); |
| 6198 | } |
| 6199 | |
| 6200 | /* |
| 6201 | * tfArchive |
| 6202 | */ |
| 6203 | |
| 6204 | TForm |
| 6205 | tfArchive(Syme syme) |
| 6206 | { |
| 6207 | TForm tf; |
| 6208 | assert(symeIsArchive(syme))do { if (!((((((syme)->kind == SYME_Trigger ? libGetAllSymes ((syme)->lib) : ((void*)0)), (syme))->kind) == SYME_Archive ))) _do_assert(("symeIsArchive(syme)"),"tform.c",6208); } while (0); |
| 6209 | tf = tfFrSyme(stabFile(), syme); |
| 6210 | if (tfSymes(tf)((tf)->symes) == listNil(Syme)((SymeList) 0)) |
| 6211 | tfSetSymes(tf, listCons(Syme)(syme, listNil(Syme)))((tf)->symes = ((Syme_listPointer->Cons)(syme, ((SymeList ) 0)))); |
| 6212 | return tf; |
| 6213 | } |
| 6214 | |
| 6215 | TForm |
| 6216 | tfGetArchive(Syme syme) |
| 6217 | { |
| 6218 | Syme osyme = stabGetArchive(symeId(syme)((syme)->id)); |
| 6219 | if (osyme && arEqual(symeArchive(osyme)((Archive) (SYFI_Archive < (8 * sizeof(int)) && !( ((((osyme)->kind == SYME_Trigger ? libGetAllSymes((osyme)-> lib) : ((void*)0)), (osyme))->hasmask) & (1 << ( SYFI_Archive))) ? (symeFieldInfo[SYFI_Archive].def) : (((((osyme )->kind == SYME_Trigger ? libGetAllSymes((osyme)->lib) : ((void*)0)), (osyme))->locmask) & (1 << (SYFI_Archive ))) ? ((((((osyme)->kind == SYME_Trigger ? libGetAllSymes( (osyme)->lib) : ((void*)0)), (osyme))->locmask) & ( 1 << (SYFI_Archive))) ? ((osyme)->fieldv)[symeIndex( osyme,SYFI_Archive)] : (symeFieldInfo[SYFI_Archive].def)) : symeGetFieldFn (osyme,SYFI_Archive))), symeArchive(syme)((Archive) (SYFI_Archive < (8 * sizeof(int)) && !( ((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->hasmask) & (1 << (SYFI_Archive ))) ? (symeFieldInfo[SYFI_Archive].def) : (((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)->lib) : ((void*)0 )), (syme))->locmask) & (1 << (SYFI_Archive))) ? ((((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme) ->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_Archive))) ? ((syme)->fieldv)[symeIndex(syme,SYFI_Archive )] : (symeFieldInfo[SYFI_Archive].def)) : symeGetFieldFn(syme ,SYFI_Archive))))) |
| 6220 | syme = osyme; |
| 6221 | return tfArchive(syme); |
| 6222 | } |
| 6223 | |
| 6224 | Bool |
| 6225 | tfIsArchive(TForm tf) |
| 6226 | { |
| 6227 | tfFollowSubst(tf); |
| 6228 | return (tfSymes(tf)((tf)->symes) != listNil(Syme)((SymeList) 0)) && |
| 6229 | (symeIsArchive(car(tfSymes(tf)))(((((((((tf)->symes))->first))->kind == SYME_Trigger ? libGetAllSymes((((((tf)->symes))->first))->lib) : ((void*)0)), (((((tf)->symes))->first)))->kind) == SYME_Archive )); |
| 6230 | } |
| 6231 | |
| 6232 | Syme |
| 6233 | tfArchiveSyme(TForm tf) |
| 6234 | { |
| 6235 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6236 | return car(tfSymes(tf))((((tf)->symes))->first); |
| 6237 | } |
| 6238 | |
| 6239 | Archive |
| 6240 | tfArchiveAr(TForm tf) |
| 6241 | { |
| 6242 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6243 | return symeArchive(tfArchiveSyme(tf))((Archive) (SYFI_Archive < (8 * sizeof(int)) && !( ((((tfArchiveSyme(tf))->kind == SYME_Trigger ? libGetAllSymes ((tfArchiveSyme(tf))->lib) : ((void*)0)), (tfArchiveSyme(tf )))->hasmask) & (1 << (SYFI_Archive))) ? (symeFieldInfo [SYFI_Archive].def) : (((((tfArchiveSyme(tf))->kind == SYME_Trigger ? libGetAllSymes((tfArchiveSyme(tf))->lib) : ((void*)0)), (tfArchiveSyme(tf)))->locmask) & (1 << (SYFI_Archive ))) ? ((((((tfArchiveSyme(tf))->kind == SYME_Trigger ? libGetAllSymes ((tfArchiveSyme(tf))->lib) : ((void*)0)), (tfArchiveSyme(tf )))->locmask) & (1 << (SYFI_Archive))) ? ((tfArchiveSyme (tf))->fieldv)[symeIndex(tfArchiveSyme(tf),SYFI_Archive)] : (symeFieldInfo[SYFI_Archive].def)) : symeGetFieldFn(tfArchiveSyme (tf),SYFI_Archive))); |
| 6244 | } |
| 6245 | |
| 6246 | TForm |
| 6247 | tfArchiveLib(TForm tf, Syme syme) |
| 6248 | { |
| 6249 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6250 | return tfLibrary(arLibrarySyme(tfArchiveAr(tf), syme)); |
| 6251 | } |
| 6252 | |
| 6253 | /* |
| 6254 | * tfDeclare |
| 6255 | */ |
| 6256 | |
| 6257 | TForm |
| 6258 | tfDeclare(AbSyn id, TForm tf) |
| 6259 | { |
| 6260 | TForm new; |
| 6261 | |
| 6262 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6263 | |
| 6264 | new = tfNewNode(TF_Declare, 1, tf); |
| 6265 | tfSetSymes(new, tfSymesFrDeclare(id))((new)->symes = (tfSymesFrDeclare(id))); |
| 6266 | tfSetMeaningArgs(new); |
| 6267 | |
| 6268 | return new; |
| 6269 | } |
| 6270 | |
| 6271 | Symbol |
| 6272 | tfDeclareId(TForm tf) |
| 6273 | { |
| 6274 | Syme syme; |
| 6275 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6276 | syme = tfDeclareSyme(tf); |
| 6277 | return syme ? symeId(syme)((syme)->id) : NULL((void*)0); |
| 6278 | } |
| 6279 | |
| 6280 | Syme |
| 6281 | tfDeclareSyme(TForm tf) |
| 6282 | { |
| 6283 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6284 | return tfSymes(tf)((tf)->symes) ? car(tfSymes(tf))((((tf)->symes))->first) : NULL((void*)0); |
| 6285 | } |
| 6286 | |
| 6287 | /* |
| 6288 | * tfDefine |
| 6289 | */ |
| 6290 | |
| 6291 | TForm |
| 6292 | tfDefine(TForm tf, AbSyn val) |
| 6293 | { |
| 6294 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6295 | return tfNewNode(TF_Define, 2, tf, tfNewAbSyn(TF_General, val)); |
| 6296 | } |
| 6297 | |
| 6298 | TForm |
| 6299 | tfDefineOfType(TForm tf) |
| 6300 | { |
| 6301 | TForm ntf; |
| 6302 | |
| 6303 | ntf = tfNewNode(TF_Declare, 1, tfType); |
| 6304 | tfSetMeaningArgs(ntf); |
| 6305 | |
| 6306 | ntf = tfNewNode(TF_Define, 2, ntf, tf); |
| 6307 | tfSetMeaningArgs(ntf); |
| 6308 | |
| 6309 | return ntf; |
| 6310 | } |
| 6311 | |
| 6312 | Bool |
| 6313 | tfIsDefineOfType(TForm tf) |
| 6314 | { |
| 6315 | Bool result = false((int) 0); |
| 6316 | |
| 6317 | if (tfIsDefine(tf)(((tf)->tag) == TF_Define) && tfIsDeclare(tfDefineDecl(tf))(((tfFollowArg(tf, 0))->tag) == TF_Declare)) { |
| 6318 | tf = tfDeclareType(tfDefineDecl(tf))tfFollowArg(tfFollowArg(tf, 0), 0); |
| 6319 | result = tfIsType(tf)(((tf)->tag) == TF_Type) || tfIsUnknown(tf)(((tf)->tag) == TF_Unknown); |
| 6320 | } |
| 6321 | |
| 6322 | return result; |
| 6323 | } |
| 6324 | |
| 6325 | Bool |
| 6326 | tfIsDefinedType(TForm tf) |
| 6327 | { |
| 6328 | TForm cat; |
| 6329 | TForm tf2 = tfDefineeTypeSubst(tf); |
| 6330 | /* !!Maybe a bit strong. |
| 6331 | * What it should do is return true |
| 6332 | * for uses of garbage types like Foo == zzz(x)(y); |
| 6333 | * This function is performance critical because |
| 6334 | * of the call from tformEqual0. Consequently, |
| 6335 | * it shouldn't call tfGetCategory or symeType |
| 6336 | * if at all possible |
| 6337 | */ |
| 6338 | if (!tfIsGeneral(tf2)(((tf2)->tag) == TF_General)) |
| 6339 | return false((int) 0); |
| 6340 | |
| 6341 | if (tfIsSelf(tf)(((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Id) && (((tf)->__absyn)-> abId.sym) == (ssymSelf)) && tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0)) |
| 6342 | cat = symeType(tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0)); |
| 6343 | else |
| 6344 | cat = tfGetCategory(tf); |
| 6345 | |
| 6346 | return tfIsDefineOfType(cat); |
| 6347 | } |
| 6348 | |
| 6349 | TForm |
| 6350 | tfDefinedVal(TForm tf) |
| 6351 | { |
| 6352 | TForm cat; |
| 6353 | |
| 6354 | if (tfIsSelf(tf)(((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Id) && (((tf)->__absyn)-> abId.sym) == (ssymSelf)) && tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0)) |
| 6355 | cat = symeType(tfIdSyme(tf)((((tf)->__absyn))->abHdr.seman ? (((tf)->__absyn))-> abHdr.seman->syme : 0)); |
| 6356 | else |
| 6357 | cat = tfGetCategory(tf); |
| 6358 | |
| 6359 | return tfDefineVal(cat)tfFollowArg(cat, 1); |
| 6360 | } |
| 6361 | |
| 6362 | /* |
| 6363 | * tfAssign |
| 6364 | */ |
| 6365 | |
| 6366 | TForm |
| 6367 | tfAssign(TForm tf, AbSyn val) |
| 6368 | { |
| 6369 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6370 | return tfNewNode(TF_Assign, 2, tf, tfNewAbSyn(TF_General, val)); |
| 6371 | } |
| 6372 | |
| 6373 | |
| 6374 | /* |
| 6375 | * tfMap |
| 6376 | */ |
| 6377 | |
| 6378 | TForm |
| 6379 | tfAnyMap(TForm arg, TForm ret, Bool packed) |
| 6380 | { |
| 6381 | if (packed) |
| 6382 | return tfPackedMap(arg, ret); |
| 6383 | else |
| 6384 | return tfMap(arg, ret); |
| 6385 | } |
| 6386 | |
| 6387 | TForm |
| 6388 | tfMap(TForm arg, TForm ret) |
| 6389 | { |
| 6390 | TForm tf; |
| 6391 | tfFollow(arg)((arg) = tfFollowFn(arg)); |
| 6392 | tfFollow(ret)((ret) = tfFollowFn(ret)); |
| 6393 | tf = tfNewNode(TF_Map, 2, arg, ret); |
| 6394 | tfSetSymes(tf, tfSymesFrMap(tf))((tf)->symes = (tfSymesFrMap(tf))); |
| 6395 | return tf; |
| 6396 | } |
| 6397 | |
| 6398 | TForm |
| 6399 | tfPackedMap(TForm arg, TForm ret) |
| 6400 | { |
| 6401 | TForm tf; |
| 6402 | tfFollow(arg)((arg) = tfFollowFn(arg)); |
| 6403 | tfFollow(ret)((ret) = tfFollowFn(ret)); |
| 6404 | tf = tfNewNode(TF_PackedMap, 2, arg, ret); |
| 6405 | tfSetSymes(tf, tfSymesFrMap(tf))((tf)->symes = (tfSymesFrMap(tf))); |
| 6406 | return tf; |
| 6407 | } |
| 6408 | |
| 6409 | Bool |
| 6410 | tfIsDependentMap(TForm tf) |
| 6411 | { |
| 6412 | Bool result; |
| 6413 | |
| 6414 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6415 | |
| 6416 | if (tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && !tfSymes(tf)((tf)->symes)) |
| 6417 | tfSetSymes(tf, tfSymesFrMap(tf))((tf)->symes = (tfSymesFrMap(tf))); |
| 6418 | |
| 6419 | result = tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && tfSymes(tf)((tf)->symes) != listNil(Syme)((SymeList) 0); |
| 6420 | |
| 6421 | if (DEBUG(tfMap)tfMapDebug) { |
| 6422 | fprintf(dbOut, "tfIsDependentMap: %s\n tf:", |
| 6423 | boolToString(result)((result) ? "true" : "false")); |
| 6424 | tfPrint(dbOut, tf); |
| 6425 | fnewline(dbOut); |
| 6426 | } |
| 6427 | |
| 6428 | return result; |
| 6429 | } |
| 6430 | |
| 6431 | /* Return true if the map has default values for arguments. */ |
| 6432 | Bool |
| 6433 | tfMapHasDefaults(TForm tf) |
| 6434 | { |
| 6435 | Bool result = false((int) 0); |
| 6436 | Length i; |
| 6437 | |
| 6438 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6439 | assert(tfIsAnyMap(tf))do { if (!(((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )))) _do_assert(("tfIsAnyMap(tf)"),"tform.c",6439); } while ( 0); |
| 6440 | |
| 6441 | for (i = 0; i < tfMapArgc(tf); i++) |
| 6442 | if (tfIsDefine(tfMapArgN(tf, i))(((tfMapArgN(tf, i))->tag) == TF_Define)) |
| 6443 | result = true1; |
| 6444 | |
| 6445 | return result; |
| 6446 | } |
| 6447 | |
| 6448 | Length |
| 6449 | tfMapArgc(TForm tf) |
| 6450 | { |
| 6451 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6452 | return tfAsMultiArgc(tfMapArg(tf)tfFollowArg(tf, 0)); |
| 6453 | } |
| 6454 | |
| 6455 | /* Return the type of the nth argument value of a map of type tf. */ |
| 6456 | TForm |
| 6457 | tfMapArgN(TForm tf, Length n) |
| 6458 | { |
| 6459 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6460 | return tfAsMultiArgN(tfMapArg(tf)tfFollowArg(tf, 0), tfMapArgc(tf), n); |
| 6461 | } |
| 6462 | |
| 6463 | SymeList |
| 6464 | tfMapArgSymes(TForm tf) |
| 6465 | { |
| 6466 | SymeList sl = listNil(Syme)((SymeList) 0); |
| 6467 | int i; |
| 6468 | |
| 6469 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6470 | assert(tfIsMap(tf))do { if (!((((tf)->tag) == TF_Map))) _do_assert(("tfIsMap(tf)" ),"tform.c",6470); } while (0); |
| 6471 | |
| 6472 | for (i=0; i<tfMapArgc(tf); i++) { |
| 6473 | TForm argTf = tfMapArgN(tf, i); |
| 6474 | if (tfIsDeclare(argTf)(((argTf)->tag) == TF_Declare)) |
| 6475 | sl = listCons(Syme)(Syme_listPointer->Cons)(tfDeclareSyme(argTf), sl); |
| 6476 | else |
| 6477 | sl = listCons(Syme)(Syme_listPointer->Cons)(NULL((void*)0), sl); |
| 6478 | } |
| 6479 | return listNReverse(Syme)(Syme_listPointer->NReverse)(sl); |
| 6480 | } |
| 6481 | |
| 6482 | |
| 6483 | /* Return the type of the nth argument value of a map of type tf |
| 6484 | * in an application with argc arguments. |
| 6485 | */ |
| 6486 | TForm |
| 6487 | tfMapMultiArgN(TForm tf, Length argc, Length n) |
| 6488 | { |
| 6489 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6490 | return tfAsMultiArgN(tfMapArg(tf)tfFollowArg(tf, 0), argc, n); |
| 6491 | } |
| 6492 | |
| 6493 | /* Return the embedding necessary to pass argc arguments |
| 6494 | * to a map of type tf. |
| 6495 | */ |
| 6496 | AbEmbed |
| 6497 | tfMapMultiArgEmbed(TForm tf, Length argc) |
| 6498 | { |
| 6499 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6500 | return tfAsMultiEmbed(tfMapArg(tf)tfFollowArg(tf, 0), argc); |
| 6501 | } |
| 6502 | |
| 6503 | Length |
| 6504 | tfMapRetc(TForm tf) |
| 6505 | { |
| 6506 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6507 | return tfAsMultiArgc(tfIgnoreExceptions(tfMapRet(tf)tfFollowArg(tf, 1))); |
| 6508 | } |
| 6509 | |
| 6510 | /* Return the type of the nth return value of a map of type tf. */ |
| 6511 | TForm |
| 6512 | tfMapRetN(TForm tf, Length n) |
| 6513 | { |
| 6514 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6515 | return tfAsMultiArgN(tfMapRet(tf)tfFollowArg(tf, 1), tfMapRetc(tf), n); |
| 6516 | } |
| 6517 | |
| 6518 | /* Return the type of the nth return value of a map of type tf |
| 6519 | * in an application with argc arguments. |
| 6520 | */ |
| 6521 | TForm |
| 6522 | tfMapMultiRetN(TForm tf, Length argc, Length n) |
| 6523 | { |
| 6524 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6525 | return tfAsMultiArgN(tfMapRet(tf)tfFollowArg(tf, 1), argc, n); |
| 6526 | } |
| 6527 | |
| 6528 | /* Return the embedding necessary to return argc arguments |
| 6529 | * from a map of type tf. |
| 6530 | */ |
| 6531 | AbEmbed |
| 6532 | tfMapMultiRetEmbed(TForm tf, Length argc) |
| 6533 | { |
| 6534 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6535 | return tfAsMultiEmbed(tfMapRet(tf)tfFollowArg(tf, 1), argc); |
| 6536 | } |
| 6537 | |
| 6538 | /* |
| 6539 | * tfCross |
| 6540 | */ |
| 6541 | |
| 6542 | TForm |
| 6543 | tfCross(Length argc, ...) |
| 6544 | { |
| 6545 | TForm tf; |
| 6546 | Length i; |
| 6547 | va_list argp; |
| 6548 | |
| 6549 | tf = tfNewEmpty(TF_Cross, argc); |
| 6550 | |
| 6551 | va_start(argp, argc)__builtin_va_start(argp, argc); |
| 6552 | for (i = 0; i < argc; i += 1) |
| 6553 | tfArgv(tf)((tf)->argv)[i] = va_arg(argp, TForm)__builtin_va_arg(argp, TForm); |
| 6554 | va_end(argp)__builtin_va_end(argp); |
| 6555 | |
| 6556 | tfSetSymes(tf, tfSymesFrCross(tf))((tf)->symes = (tfSymesFrCross(tf))); |
| 6557 | |
| 6558 | return tf; |
| 6559 | } |
| 6560 | |
| 6561 | TForm |
| 6562 | tfCrossFrList(TFormList tfl) |
| 6563 | { |
| 6564 | TForm tf; |
| 6565 | Length i, argc = listLength(TForm)(TForm_listPointer->_Length)(tfl); |
| 6566 | |
| 6567 | tf = tfNewEmpty(TF_Cross, argc); |
| 6568 | |
| 6569 | for (i = 0; tfl; i += 1, tfl = cdr(tfl)((tfl)->rest)) |
| 6570 | tfArgv(tf)((tf)->argv)[i] = car(tfl)((tfl)->first); |
| 6571 | |
| 6572 | tfSetSymes(tf, tfSymesFrCross(tf))((tf)->symes = (tfSymesFrCross(tf))); |
| 6573 | |
| 6574 | return tf; |
| 6575 | } |
| 6576 | |
| 6577 | TForm |
| 6578 | tfCrossFrMulti(TForm tfm) |
| 6579 | { |
| 6580 | TForm tf; |
| 6581 | Length i, argc = tfMultiArgc(tfm); |
| 6582 | |
| 6583 | tf = tfNewEmpty(TF_Cross, argc); |
| 6584 | |
| 6585 | for (i = 0; i < argc; i++) |
| 6586 | tfArgv(tf)((tf)->argv)[i] = tfArgv(tfm)((tfm)->argv)[i]; |
| 6587 | |
| 6588 | tfSetSymes(tf, tfSymesFrCross(tf))((tf)->symes = (tfSymesFrCross(tf))); |
| 6589 | |
| 6590 | return tf; |
| 6591 | } |
| 6592 | |
| 6593 | Bool |
| 6594 | tfIsDependentCross(TForm tf) |
| 6595 | { |
| 6596 | Bool result; |
| 6597 | |
| 6598 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6599 | |
| 6600 | if (tfIsCross(tf)(((tf)->tag) == TF_Cross) && !tfSymes(tf)((tf)->symes)) |
| 6601 | tfSetSymes(tf, tfSymesFrCross(tf))((tf)->symes = (tfSymesFrCross(tf))); |
| 6602 | |
| 6603 | result = tfIsCross(tf)(((tf)->tag) == TF_Cross) && tfSymes(tf)((tf)->symes) != listNil(Syme)((SymeList) 0); |
| 6604 | |
| 6605 | if (DEBUG(tfCross)tfCrossDebug) { |
| 6606 | fprintf(dbOut, "tfIsDependentCross: %s\n tf:", |
| 6607 | boolToString(result)((result) ? "true" : "false")); |
| 6608 | tfPrint(dbOut, tf); |
| 6609 | fnewline(dbOut); |
| 6610 | } |
| 6611 | |
| 6612 | return result; |
| 6613 | } |
| 6614 | |
| 6615 | Length |
| 6616 | tfCrossArgc(TForm tf) |
| 6617 | { |
| 6618 | assert(tfIsCross(tf))do { if (!((((tf)->tag) == TF_Cross))) _do_assert(("tfIsCross(tf)" ),"tform.c",6618); } while (0); |
| 6619 | return tfArgc(tf)((tf)->argc); |
| 6620 | } |
| 6621 | |
| 6622 | /* |
| 6623 | * tfMultiple |
| 6624 | */ |
| 6625 | |
| 6626 | localstatic void |
| 6627 | tfMultiAfter(TForm tf) |
| 6628 | { |
| 6629 | tfSetMeaningArgs(tf); |
| 6630 | tfSetSymes(tf, tfSymesFrMulti(tf))((tf)->symes = (tfSymesFrMulti(tf))); |
| 6631 | if (tfArgc(tf)((tf)->argc) == 0) tfToAbSyn(tf); |
| 6632 | } |
| 6633 | |
| 6634 | TForm |
| 6635 | tfMulti(Length argc, ...) |
| 6636 | { |
| 6637 | TForm tf; |
| 6638 | Length i; |
| 6639 | va_list argp; |
| 6640 | |
| 6641 | tf = tfNewEmpty(TF_Multiple, argc); |
| 6642 | |
| 6643 | va_start(argp, argc)__builtin_va_start(argp, argc); |
| 6644 | for (i = 0; i < argc; i += 1) |
| 6645 | tfArgv(tf)((tf)->argv)[i] = va_arg(argp, TForm)__builtin_va_arg(argp, TForm); |
| 6646 | va_end(argp)__builtin_va_end(argp); |
| 6647 | |
| 6648 | tfMultiAfter(tf); |
| 6649 | return tf; |
| 6650 | } |
| 6651 | |
| 6652 | Bool |
| 6653 | tfIsDependentMulti(TForm tf) |
| 6654 | { |
| 6655 | Bool result; |
| 6656 | |
| 6657 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6658 | |
| 6659 | if (tfIsMulti(tf)(((tf)->tag) == TF_Multiple) && !tfSymes(tf)((tf)->symes)) |
| 6660 | tfSetSymes(tf, tfSymesFrMulti(tf))((tf)->symes = (tfSymesFrMulti(tf))); |
| 6661 | |
| 6662 | result = tfIsMulti(tf)(((tf)->tag) == TF_Multiple) && tfSymes(tf)((tf)->symes) != listNil(Syme)((SymeList) 0); |
| 6663 | |
| 6664 | if (DEBUG(tfMulti)tfMultiDebug) { |
| 6665 | fprintf(dbOut, "tfIsDependentMulti: %s\n tf:", |
| 6666 | boolToString(result)((result) ? "true" : "false")); |
| 6667 | tfPrint(dbOut, tf); |
| 6668 | fnewline(dbOut); |
| 6669 | } |
| 6670 | |
| 6671 | return result; |
| 6672 | } |
| 6673 | |
| 6674 | TForm |
| 6675 | tfMultiFrList(TFormList tfl) |
| 6676 | { |
| 6677 | TForm tf; |
| 6678 | Length i, argc = listLength(TForm)(TForm_listPointer->_Length)(tfl); |
| 6679 | |
| 6680 | tf = tfNewEmpty(TF_Multiple, argc); |
| 6681 | |
| 6682 | for (i = 0; tfl; i += 1, tfl = cdr(tfl)((tfl)->rest)) |
| 6683 | tfArgv(tf)((tf)->argv)[i] = car(tfl)((tfl)->first); |
| 6684 | |
| 6685 | tfMultiAfter(tf); |
| 6686 | return tf; |
| 6687 | } |
| 6688 | |
| 6689 | TForm |
| 6690 | tfMultiFrTUnique(Sefo sefo) |
| 6691 | { |
| 6692 | TForm tf; |
| 6693 | Length i, argc = abArgc(sefo)((sefo)->abHdr.argc); |
| 6694 | |
| 6695 | tf = tfNewEmpty(TF_Multiple, argc); |
| 6696 | |
| 6697 | for (i = 0; i < argc; i += 1) |
| 6698 | tfArgv(tf)((tf)->argv)[i] = abTUnique(abArgv(sefo)[i])((((sefo)->abGen.data.argv)[i])->abHdr.type.unique); |
| 6699 | |
| 6700 | tfMultiAfter(tf); |
| 6701 | return tf; |
| 6702 | } |
| 6703 | |
| 6704 | Length |
| 6705 | tfMultiArgc(TForm tf) |
| 6706 | { |
| 6707 | assert(tfIsMulti(tf))do { if (!((((tf)->tag) == TF_Multiple))) _do_assert(("tfIsMulti(tf)" ),"tform.c",6707); } while (0); |
| 6708 | return tfArgc(tf)((tf)->argc); |
| 6709 | } |
| 6710 | |
| 6711 | Bool |
| 6712 | tfMultiHasDefaults(TForm tf) |
| 6713 | { |
| 6714 | Bool result = false((int) 0); |
| 6715 | Length i; |
| 6716 | |
| 6717 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6718 | |
| 6719 | if (!tfIsMulti(tf)(((tf)->tag) == TF_Multiple)) |
| 6720 | return tfIsDefine(tf)(((tf)->tag) == TF_Define); |
| 6721 | |
| 6722 | for (i = 0; i < tfMultiArgc(tf); i++) { |
| 6723 | TForm tfi = tfFollowSubst(tfMultiArgN(tf,i)tfFollowArg(tf, i)); |
| 6724 | if (tfIsDefine(tfi)(((tfi)->tag) == TF_Define)) |
| 6725 | result = true1; |
| 6726 | } |
| 6727 | return result; |
| 6728 | } |
| 6729 | |
| 6730 | AbEmbed |
| 6731 | tfAsMultiEmbed(TForm tf, Length argc) |
| 6732 | { |
| 6733 | AbEmbed result = AB_Embed_Fail((AbEmbed) 0); |
| 6734 | TForm ntf; |
| 6735 | |
| 6736 | ntf = tfDefineeType(tf); |
| 6737 | tf = tfFollowOnly(tf); |
| 6738 | |
| 6739 | if (tfIsMulti(ntf)(((ntf)->tag) == TF_Multiple) && |
| 6740 | (tfMultiArgc(ntf) == argc || |
| 6741 | (tfMultiArgc(ntf) > argc && tfMultiHasDefaults(ntf)))) |
| 6742 | result = AB_Embed_Identity(((AbEmbed) 1) << 0); |
| 6743 | |
| 6744 | else if (argc == 1) |
| 6745 | result = AB_Embed_Identity(((AbEmbed) 1) << 0); |
| 6746 | |
| 6747 | else if (tfIsTuple(ntf)(((ntf)->tag) == TF_Tuple)) |
| 6748 | result = AB_Embed_ApplyMultiToTuple(((AbEmbed) 1) << 12); |
| 6749 | |
| 6750 | else if (tfIsCross(ntf)(((ntf)->tag) == TF_Cross) && tfCrossArgc(ntf) == argc) |
| 6751 | result = AB_Embed_ApplyMultiToCross(((AbEmbed) 1) << 13); |
| 6752 | else if (argc == 0 && tfIsDefine(tf)(((tf)->tag) == TF_Define)) |
| 6753 | return AB_Embed_Identity(((AbEmbed) 1) << 0); |
| 6754 | |
| 6755 | return result; |
| 6756 | } |
| 6757 | |
| 6758 | Length |
| 6759 | tfAsMultiArgc(TForm tf) |
| 6760 | { |
| 6761 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 6762 | return (tfIsMulti(tf)(((tf)->tag) == TF_Multiple) ? tfMultiArgc(tf) : 1); |
| 6763 | } |
| 6764 | |
| 6765 | TForm |
| 6766 | tfAsMultiArgN(TForm tf, Length argc, Length n) |
| 6767 | { |
| 6768 | TForm result = 0; |
| 6769 | TForm ntf; |
| 6770 | |
| 6771 | assert(n < argc)do { if (!(n < argc)) _do_assert(("n < argc"),"tform.c" ,6771); } while (0); |
| 6772 | ntf = tfDefineeType(tf); |
| 6773 | |
| 6774 | if (tfIsMulti(ntf)(((ntf)->tag) == TF_Multiple) && tfMultiArgc(ntf) == argc) |
| 6775 | result = tfMultiArgN(ntf, n)tfFollowArg(ntf, n); |
| 6776 | |
| 6777 | else if (argc == 1) |
| 6778 | result = tf; |
| 6779 | |
| 6780 | else if (tfIsTuple(ntf)(((ntf)->tag) == TF_Tuple)) |
| 6781 | result = tfTupleArg(ntf)tfFollowArg(ntf, 0); |
| 6782 | |
| 6783 | else if (tfIsCross(ntf)(((ntf)->tag) == TF_Cross) && tfCrossArgc(ntf) == argc) |
| 6784 | result = tfCrossArgN(ntf, n)tfFollowArg(ntf, n); |
| 6785 | |
| 6786 | assert(result)do { if (!(result)) _do_assert(("result"),"tform.c",6786); } while (0); |
| 6787 | return result; |
| 6788 | } |
| 6789 | |
| 6790 | #define abIsDefineKeyword(ab)(((ab)->abHdr.tag == (AB_Define)) && ((((ab)->abDefine .lhs))->abHdr.tag == (AB_Id))) \ |
| 6791 | (abHasTag(ab, AB_Define)((ab)->abHdr.tag == (AB_Define)) && abHasTag(abDefineDecl(ab), AB_Id)((((ab)->abDefine.lhs))->abHdr.tag == (AB_Id))) |
| 6792 | |
| 6793 | AbSyn |
| 6794 | tfAsMultiSelectArg(AbSyn ab, Length argc, Length n, AbSynGetter argf, |
| 6795 | TForm tfi, Bool * def, Length * pos) |
| 6796 | { |
| 6797 | AbSyn abpos, abkey, abi; |
| 6798 | Symbol name; |
| 6799 | Length i; |
| 6800 | |
| 6801 | /* ?? tfFollowSubst */ |
| 6802 | tfFollow(tfi)((tfi) = tfFollowFn(tfi)); |
| 6803 | /* Find the keyword name. */ |
| 6804 | name = tfDefineeSymbol(tfi); |
| 6805 | |
| 6806 | /* Find the positional argument. */ |
| 6807 | abpos = (n < argc) ? argf(ab, n) : NULL((void*)0); |
| 6808 | *pos = n; |
| 6809 | |
| 6810 | /* If abpos is a define, assume its a keyword, not positional. |
| 6811 | * But if tfi doesn't have a keyword (if name == NULL), |
| 6812 | * treat a define as positional so we can type check |
| 6813 | * 'Record(x: Integer == 0)' correctly. |
| 6814 | */ |
| 6815 | if (name && abpos && abIsDefineKeyword(abpos)(((abpos)->abHdr.tag == (AB_Define)) && ((((abpos) ->abDefine.lhs))->abHdr.tag == (AB_Id)))) |
| 6816 | abpos = NULL((void*)0); |
| 6817 | |
| 6818 | /* Find the keyword argument. */ |
| 6819 | abkey = NULL((void*)0); |
| 6820 | for (i = 0; name && !abkey && i < argc; i += 1) { |
| 6821 | AbSyn ak = argf(ab, i); |
| 6822 | if (abIsDefineKeyword(ak)(((ak)->abHdr.tag == (AB_Define)) && ((((ak)->abDefine .lhs))->abHdr.tag == (AB_Id))) && |
| 6823 | abIsTheId(abDefineeId(ak), name)(((abDefineeId(ak))->abHdr.tag == (AB_Id)) && ((abDefineeId (ak))->abId.sym)==(name))) { |
| 6824 | abkey = ak; |
| 6825 | *pos = i; |
| 6826 | } |
| 6827 | } |
| 6828 | |
| 6829 | /* Select the argument to use. */ |
| 6830 | *def = false((int) 0); |
| 6831 | if (abpos && abkey) |
| 6832 | abi = NULL((void*)0); |
| 6833 | |
| 6834 | else if (abpos) |
| 6835 | abi = abpos; |
| 6836 | |
| 6837 | else if (abkey) |
| 6838 | abi = abkey->abDefine.rhs; |
| 6839 | |
| 6840 | else if (tfIsDefine(tfi)(((tfi)->tag) == TF_Define)) { |
| 6841 | /*abi = tfGetExpr(tfDefineVal(tfi));*/ |
| 6842 | abi = tfExpr(tfDefineVal(tfi))tfToAbSyn(tfFollowArg(tfi, 1)); |
| 6843 | *def = true1; |
| 6844 | } |
| 6845 | else |
| 6846 | abi = NULL((void*)0); |
| 6847 | |
| 6848 | return abi; |
| 6849 | } |
| 6850 | |
| 6851 | /* |
| 6852 | * Grab the ith argument from a flat absyn, |
| 6853 | */ |
| 6854 | AbSyn |
| 6855 | tfMapSelectArg(TForm opTf, AbSyn ab, Length i) |
| 6856 | { |
| 6857 | Length ai; |
| 6858 | Bool def; |
| 6859 | TForm tfi = tfMapArgN(opTf, i); |
| 6860 | AbSyn abi = tfAsMultiSelectArg(ab, |
| 6861 | abApplyArgc(ab)(((ab)->abHdr.argc)-1), i, |
| 6862 | abApplyArgf, tfi, &def, &ai); |
| 6863 | |
| 6864 | if (abTag(abi)((abi)->abHdr.tag) == AB_Define) |
| 6865 | abi = abi->abDefine.rhs; |
| 6866 | |
| 6867 | return abi; |
| 6868 | } |
| 6869 | |
| 6870 | /* |
| 6871 | * tfTuple |
| 6872 | */ |
| 6873 | |
| 6874 | TForm |
| 6875 | tfTuple(TForm arg) |
| 6876 | { |
| 6877 | TForm tf = tfNewNode(TF_Tuple, 1, arg); |
| 6878 | tfSetMeaningArgs(tf); |
| 6879 | return tf; |
| 6880 | } |
| 6881 | |
| 6882 | /* |
| 6883 | * tfEnumerate |
| 6884 | */ |
| 6885 | |
| 6886 | TForm |
| 6887 | tfEnum(Stab stab, AbSyn id) |
| 6888 | { |
| 6889 | TForm tf = tfNewNode(TF_Enumerate, 1, tfDeclare(id, tfType)); |
| 6890 | AbSyn ab = tfExpr(tf)tfToAbSyn(tf); |
| 6891 | TForm ntf; |
| 6892 | |
| 6893 | if ((ntf = stabGetTForm(stab, ab, NULL((void*)0))) != NULL((void*)0)) |
| 6894 | return ntf; |
| 6895 | |
| 6896 | tfSetSymes(tf, tfSymesFrEnum(stab, tf, ab))((tf)->symes = (tfSymesFrEnum(stab, tf, ab))); |
| 6897 | tfSetMeaningArgs(tf); |
| 6898 | |
| 6899 | stabDefTForm(stab, tf); |
| 6900 | return tf; |
| 6901 | } |
| 6902 | |
| 6903 | Length |
| 6904 | tfEnumArgc(TForm tf) |
| 6905 | { |
| 6906 | assert(tfIsEnum(tf))do { if (!((((tf)->tag) == TF_Enumerate))) _do_assert(("tfIsEnum(tf)" ),"tform.c",6906); } while (0); |
| 6907 | return tfArgc(tf)((tf)->argc); |
| 6908 | } |
| 6909 | |
| 6910 | Symbol |
| 6911 | tfEnumId(TForm tf, Length n) |
| 6912 | { |
| 6913 | TForm tfi; |
| 6914 | |
| 6915 | assert(tfIsEnum(tf))do { if (!((((tf)->tag) == TF_Enumerate))) _do_assert(("tfIsEnum(tf)" ),"tform.c",6915); } while (0); |
| 6916 | tfi = tfEnumArgN(tf, n)tfFollowArg(tf, n); |
| 6917 | |
| 6918 | if (tfIsDeclare(tfi)(((tfi)->tag) == TF_Declare)) |
| 6919 | return tfDeclareId(tfi); |
| 6920 | else if (tfIsId(tfi)((((tfi)->tag) == TF_General) && ((((tfi)->__absyn ))->abHdr.tag) == AB_Id)) |
| 6921 | return tfIdSym(tfi)(((tfi)->__absyn)->abId.sym); |
| 6922 | else |
| 6923 | return NULL((void*)0); |
| 6924 | } |
| 6925 | |
| 6926 | Symbol |
| 6927 | tfCompoundId(TForm tf, Length n) |
| 6928 | { |
| 6929 | TForm tfi = tfFollow(tfArgv(tf)[n])((((tf)->argv)[n]) = tfFollowFn(((tf)->argv)[n])); |
| 6930 | |
| 6931 | if (tfIsDeclare(tfi)(((tfi)->tag) == TF_Declare)) |
| 6932 | return tfDeclareId(tfi); |
| 6933 | else if (tfIsId(tfi)((((tfi)->tag) == TF_General) && ((((tfi)->__absyn ))->abHdr.tag) == AB_Id)) |
| 6934 | return tfIdSym(tfi)(((tfi)->__absyn)->abId.sym); |
| 6935 | else |
| 6936 | return NULL((void*)0); |
| 6937 | } |
| 6938 | |
| 6939 | /* |
| 6940 | * tfRawRecord |
| 6941 | */ |
| 6942 | Length |
| 6943 | tfRawRecordArgc(TForm tf) |
| 6944 | { |
| 6945 | assert(tfIsRawRecord(tf))do { if (!((((tf)->tag) == TF_RawRecord))) _do_assert(("tfIsRawRecord(tf)" ),"tform.c",6945); } while (0); |
| 6946 | return tfArgc(tf)((tf)->argc); |
| 6947 | } |
| 6948 | |
| 6949 | /* |
| 6950 | * tfRecord |
| 6951 | */ |
| 6952 | |
| 6953 | Length |
| 6954 | tfRecordArgc(TForm tf) |
| 6955 | { |
| 6956 | assert(tfIsRecord(tf))do { if (!((((tf)->tag) == TF_Record))) _do_assert(("tfIsRecord(tf)" ),"tform.c",6956); } while (0); |
| 6957 | return tfArgc(tf)((tf)->argc); |
| 6958 | } |
| 6959 | |
| 6960 | /* |
| 6961 | * tfTrailingArray |
| 6962 | */ |
| 6963 | |
| 6964 | Length |
| 6965 | tfTrailingArrayIArgc(TForm tf) |
| 6966 | { |
| 6967 | assert(tfIsTrailingArray(tf))do { if (!((((tf)->tag) == TF_TrailingArray))) _do_assert( ("tfIsTrailingArray(tf)"),"tform.c",6967); } while (0); |
| 6968 | return tfArgc(tf)((tf)->argc); |
| 6969 | } |
| 6970 | |
| 6971 | Length |
| 6972 | tfTrailingArrayAArgc(TForm tf) |
| 6973 | { |
| 6974 | assert(tfIsTrailingArray(tf))do { if (!((((tf)->tag) == TF_TrailingArray))) _do_assert( ("tfIsTrailingArray(tf)"),"tform.c",6974); } while (0); |
| 6975 | return tfArgc(tf)((tf)->argc); |
| 6976 | } |
| 6977 | |
| 6978 | TForm |
| 6979 | tfTrailingArrayIArgN(TForm tf, Length n) |
| 6980 | { |
| 6981 | assert(tfIsTrailingArray(tf))do { if (!((((tf)->tag) == TF_TrailingArray))) _do_assert( ("tfIsTrailingArray(tf)"),"tform.c",6981); } while (0); |
| 6982 | bug("tfTrailingArrayIArgN: aargh"); |
| 6983 | return tfFollowArg(tf, n); |
| 6984 | } |
| 6985 | |
| 6986 | TForm |
| 6987 | tfTrailingArrayAArgN(TForm tf, Length n) |
| 6988 | { |
| 6989 | assert(tfIsTrailingArray(tf))do { if (!((((tf)->tag) == TF_TrailingArray))) _do_assert( ("tfIsTrailingArray(tf)"),"tform.c",6989); } while (0); |
| 6990 | bug("tfTrailingArrayAArgN: aargh"); |
| 6991 | return tfFollowArg(tf, n); |
| 6992 | } |
| 6993 | |
| 6994 | /* |
| 6995 | * tfUnion |
| 6996 | */ |
| 6997 | |
| 6998 | Length |
| 6999 | tfUnionArgc(TForm tf) |
| 7000 | { |
| 7001 | assert(tfIsUnion(tf))do { if (!((((tf)->tag) == TF_Union))) _do_assert(("tfIsUnion(tf)" ),"tform.c",7001); } while (0); |
| 7002 | return tfArgc(tf)((tf)->argc); |
| 7003 | } |
| 7004 | |
| 7005 | /* |
| 7006 | * tfWith |
| 7007 | */ |
| 7008 | |
| 7009 | TForm |
| 7010 | tfWith(TForm base, TForm body) |
| 7011 | { |
| 7012 | TForm tf = tfNewNode(TF_With, 2, base, body); |
| 7013 | tfSetMeaningArgs(tf); |
| 7014 | return tf; |
| 7015 | } |
| 7016 | |
| 7017 | TForm |
| 7018 | tfWithFrSymes(SymeList symes) |
| 7019 | { |
| 7020 | TForm tf; |
| 7021 | tf = tfNewNode(TF_With, 2, tfNone()tfMulti(0), tfNone()tfMulti(0)); |
| 7022 | tfSetCatExports(tf, symes); |
| 7023 | tfSetMeaning(tf)(((tf)->state)=TF_State_Meaning); |
| 7024 | return tf; |
| 7025 | } |
| 7026 | |
| 7027 | TForm |
| 7028 | tfWithFrAbSyn(AbSyn absyn) |
| 7029 | { |
| 7030 | TForm tf; |
| 7031 | tf = tfWithFrSymes(listNReverse(Syme)(Syme_listPointer->NReverse)(tfSymesFrAdd(absyn))); |
| 7032 | tfAddSelf(tf, tfGetSelfFrStab(abStab(absyn)((absyn)->abHdr.seman ? (absyn)->abHdr.seman->stab : 0))); |
| 7033 | return tf; |
| 7034 | } |
| 7035 | |
| 7036 | /* |
| 7037 | * tfThird |
| 7038 | */ |
| 7039 | |
| 7040 | TForm |
| 7041 | tfThirdFrTForm(TForm tfw) |
| 7042 | { |
| 7043 | TForm tf; |
| 7044 | tf = tfNewNode(TF_Third, 1, tfw); |
| 7045 | return tf; |
| 7046 | } |
| 7047 | |
| 7048 | TForm |
| 7049 | tfThird(SymeList symes) |
| 7050 | { |
| 7051 | TForm tf; |
| 7052 | tf = tfNewNode(TF_Third, 1, tfNone()tfMulti(0)); |
| 7053 | tfSetThdExports(tf, symes); |
| 7054 | tfSetMeaning(tf)(((tf)->state)=TF_State_Meaning); |
| 7055 | return tf; |
| 7056 | } |
| 7057 | |
| 7058 | /* |
| 7059 | * tfGenerator |
| 7060 | */ |
| 7061 | |
| 7062 | TForm |
| 7063 | tfGenerator(TForm arg) |
| 7064 | { |
| 7065 | TForm tf = tfNewNode(TF_Generator, 1, arg); |
| 7066 | tfSetMeaningArgs(tf); |
| 7067 | return tf; |
| 7068 | } |
| 7069 | |
| 7070 | Bool |
| 7071 | tfIsGeneratorFn(TForm tf) |
| 7072 | { |
| 7073 | tf = tfFollowSubst(tf); |
| 7074 | return tfIsGenerator(tf)(((tf)->tag) == TF_Generator); |
| 7075 | } |
| 7076 | |
| 7077 | Bool |
| 7078 | tfIsXGeneratorFn(TForm tf) |
| 7079 | { |
| 7080 | tf = tfFollowSubst(tf); |
| 7081 | return tfIsXGenerator(tf)(((tf)->tag) == TF_XGenerator); |
| 7082 | } |
| 7083 | |
| 7084 | /* |
| 7085 | * tfReference |
| 7086 | */ |
| 7087 | |
| 7088 | TForm |
| 7089 | tfReference(TForm arg) |
| 7090 | { |
| 7091 | TForm tf = tfNewNode(TF_Reference, 1, arg); |
| 7092 | tfSetMeaningArgs(tf); |
| 7093 | return tf; |
| 7094 | } |
| 7095 | |
| 7096 | Bool |
| 7097 | tfIsReferenceFn(TForm tf) |
| 7098 | { |
| 7099 | tf = tfFollowSubst(tf); |
| 7100 | return tfIsReference(tf)(((tf)->tag) == TF_Reference); |
| 7101 | } |
| 7102 | |
| 7103 | /* |
| 7104 | * tfSubst |
| 7105 | */ |
| 7106 | |
| 7107 | static int TFSubstCount = 0; |
| 7108 | |
| 7109 | TForm |
| 7110 | tfSubst(AbSub sigma, TForm arg) |
| 7111 | { |
| 7112 | TForm tf = tfNewNode(TF_Subst, 1, arg); |
| 7113 | tfSubstSigma(tf)((tf)->sigma) = absRefer(sigma); |
| 7114 | tfSetMeaningArgs(tf); |
| 7115 | TFSubstCount += 1; |
| 7116 | return tf; |
| 7117 | } |
| 7118 | |
| 7119 | TForm |
| 7120 | tfSubstPush(TForm tf) |
| 7121 | { |
| 7122 | AbSub sigma; |
| 7123 | |
| 7124 | assert(tfIsSubst(tf))do { if (!((((tf)->tag) == TF_Subst))) _do_assert(("tfIsSubst(tf)" ),"tform.c",7124); } while (0); |
| 7125 | assert(tf->sigma)do { if (!(tf->sigma)) _do_assert(("tf->sigma"),"tform.c" ,7125); } while (0); |
| 7126 | |
| 7127 | sigma = absRefer(tf->sigma); |
| 7128 | absClrLazy(sigma)((sigma)->lazy = ((int) 0)); |
| 7129 | |
| 7130 | tf->argv[0] = tformSubst(sigma, tf->argv[0]); |
| 7131 | |
| 7132 | absSetLazy(sigma)((sigma)->lazy = 1); |
| 7133 | absFree(sigma); |
| 7134 | |
| 7135 | if (tf->sigma) { |
| 7136 | tf->sigma = NULL((void*)0); |
| 7137 | tf->tag = TF_Forward; |
| 7138 | absFree(sigma); |
| 7139 | } |
| 7140 | if (tfConditions(tf) != NULL((void*)0)) { |
| 7141 | tfDEBUGif (!tfDebug) { } else afprintf(dbOut, "SubstPushCond: %pTForm %pAbSynList\n", |
| 7142 | tf->argv[0], tfConditionalAbSyn(tf)); |
| 7143 | tfSetConditions(tf->argv[0], tfConditions(tf))(tf->argv[0]->conditions = (tfConditions(tf))); |
| 7144 | } |
| 7145 | |
| 7146 | assert(tf->argv[0] != tf)do { if (!(tf->argv[0] != tf)) _do_assert(("tf->argv[0] != tf" ),"tform.c",7146); } while (0); |
| 7147 | return tf->argv[0]; |
| 7148 | } |
| 7149 | |
| 7150 | /* |
| 7151 | * tfTrigger |
| 7152 | */ |
| 7153 | |
| 7154 | TForm |
| 7155 | tfTrigger(Syme syme) |
| 7156 | { |
| 7157 | TForm tf = tfNewEmpty(TF_Trigger, 1); |
| 7158 | tfSetSymes(tf, listCons(Syme)(syme, listNil(Syme)))((tf)->symes = ((Syme_listPointer->Cons)(syme, ((SymeList ) 0)))); |
| 7159 | return tf; |
| 7160 | } |
| 7161 | |
| 7162 | Lib |
| 7163 | tfTriggerLib(TForm tf) |
| 7164 | { |
| 7165 | assert(tfIsTrigger(tf))do { if (!((((tf)->tag) == TF_Trigger))) _do_assert(("tfIsTrigger(tf)" ),"tform.c",7165); } while (0); |
| 7166 | assert(tfSymes(tf))do { if (!(((tf)->symes))) _do_assert(("tfSymes(tf)"),"tform.c" ,7166); } while (0); |
| 7167 | return symeLib(car(tfSymes(tf)))((((((tf)->symes))->first))->lib); |
| 7168 | } |
| 7169 | |
| 7170 | TForm |
| 7171 | tfForwardFrTrigger(TForm otf, TForm ntf) |
| 7172 | { |
| 7173 | assert(tfIsTrigger(otf))do { if (!((((otf)->tag) == TF_Trigger))) _do_assert(("tfIsTrigger(otf)" ),"tform.c",7173); } while (0); |
| 7174 | assert(otf != ntf)do { if (!(otf != ntf)) _do_assert(("otf != ntf"),"tform.c",7174 ); } while (0); |
| 7175 | |
| 7176 | otf->tag = TF_Forward; |
| 7177 | otf->argc = 1; |
| 7178 | otf->argv[0] = ntf; |
| 7179 | |
| 7180 | return otf; |
| 7181 | } |
| 7182 | |
| 7183 | /* |
| 7184 | * tfFollow |
| 7185 | */ |
| 7186 | |
| 7187 | #if 0 |
| 7188 | /* Debugging code for tfFollowFn. */ |
| 7189 | |
| 7190 | static int TFFollowFrom = TFF_Other; |
| 7191 | static int TFFollowCount[TFF_Limit]; |
| 7192 | |
| 7193 | void |
| 7194 | tfFollowInit(void) |
| 7195 | { |
| 7196 | int i; |
| 7197 | for (i = 0; i < TFF_Limit; i += 1) |
| 7198 | TFFollowCount[i] = 0; |
| 7199 | } |
| 7200 | |
| 7201 | void |
| 7202 | tfFollowFini(void) |
| 7203 | { |
| 7204 | int i; |
| 7205 | |
| 7206 | fprintf(dbOut, "calls to tfSubst: %d\n", TFSubstCount); |
| 7207 | fprintf(dbOut, "calls to tfSubstPush from:"); |
| 7208 | fnewline(dbOut); |
| 7209 | |
| 7210 | for (i = 0; i < TFF_Limit; i += 1) |
| 7211 | fprintf(dbOut, "%d\t%d\n", i, TFFollowCount[i]); |
| 7212 | } |
| 7213 | |
| 7214 | void |
| 7215 | tfFollowFrom(int loc) |
| 7216 | { |
| 7217 | TFFollowFrom = loc; |
| 7218 | } |
| 7219 | #endif |
| 7220 | |
| 7221 | TForm |
| 7222 | tfFollowOnly(TForm tf) |
| 7223 | { |
| 7224 | Bool done = (tf == NULL((void*)0)); |
| 7225 | |
| 7226 | while (!done) { |
| 7227 | if (tfIsForward(tf)(((tf)->tag) == TF_Forward)) |
| 7228 | tf = tf->argv[0]; |
| 7229 | else if (tfIsTrigger(tf)(((tf)->tag) == TF_Trigger)) |
| 7230 | libGetAllSymes(tfTriggerLib(tf)); |
| 7231 | else |
| 7232 | done = true1; |
| 7233 | } |
| 7234 | return tf; |
| 7235 | } |
| 7236 | |
| 7237 | TForm |
| 7238 | tfFollowSubst(TForm tf) |
| 7239 | { |
| 7240 | Bool done = (tf == NULL((void*)0)); |
| 7241 | |
| 7242 | while (!done) { |
| 7243 | if (tfIsForward(tf)(((tf)->tag) == TF_Forward)) |
| 7244 | tf = tf->argv[0]; |
| 7245 | else if (tfIsSubst(tf)(((tf)->tag) == TF_Subst)) |
| 7246 | tf = tf->argv[0]; |
| 7247 | else if (tfIsTrigger(tf)(((tf)->tag) == TF_Trigger)) |
| 7248 | libGetAllSymes(tfTriggerLib(tf)); |
| 7249 | else |
| 7250 | done = true1; |
| 7251 | } |
| 7252 | return tf; |
| 7253 | } |
| 7254 | |
| 7255 | TForm |
| 7256 | tfFollowFn(TForm tf) |
| 7257 | { |
| 7258 | Bool done = (tf == NULL((void*)0)); |
| 7259 | |
| 7260 | while (!done) { |
| 7261 | if (tfIsForward(tf)(((tf)->tag) == TF_Forward)) |
| 7262 | tf = tf->argv[0]; |
| 7263 | else if (tfIsSubst(tf)(((tf)->tag) == TF_Subst)) |
| 7264 | tf = tfSubstPush(tf); |
| 7265 | else if (tfIsTrigger(tf)(((tf)->tag) == TF_Trigger)) |
| 7266 | libGetAllSymes(tfTriggerLib(tf)); |
| 7267 | else |
| 7268 | done = true1; |
| 7269 | } |
| 7270 | return tf; |
| 7271 | } |
| 7272 | |
| 7273 | TForm |
| 7274 | tfFollowArg(TForm tf, Length i) |
| 7275 | { |
| 7276 | assert(!tfIsForward(tf))do { if (!(!(((tf)->tag) == TF_Forward))) _do_assert(("!tfIsForward(tf)" ),"tform.c",7276); } while (0); |
| 7277 | if (i < tfArgc(tf)((tf)->argc)) { |
| 7278 | tfArgv(tf)((tf)->argv)[i] = tfFollowOnly(tfArgv(tf)((tf)->argv)[i]); |
| 7279 | return tfArgv(tf)((tf)->argv)[i]; |
| 7280 | } |
| 7281 | else |
| 7282 | return NULL((void*)0); |
| 7283 | } |
| 7284 | |
| 7285 | /* |
| 7286 | * tfRaw |
| 7287 | */ |
| 7288 | |
| 7289 | localstatic Bool |
| 7290 | tfIsRawMap(TForm tf) |
| 7291 | { |
| 7292 | return tfIsMap(tf)(((tf)->tag) == TF_Map) && tfMapArgc(tf) == 1 && |
| 7293 | tfIsSelf(tfDefineeType(tfMapArgN(tf, int0)))(((((tfDefineeType(tfMapArgN(tf, ((int) 0))))->tag) == TF_General ) && ((((tfDefineeType(tfMapArgN(tf, ((int) 0))))-> __absyn))->abHdr.tag) == AB_Id) && (((tfDefineeType (tfMapArgN(tf, ((int) 0))))->__absyn)->abId.sym) == (ssymSelf )); |
| 7294 | } |
| 7295 | |
| 7296 | TForm |
| 7297 | tfRawType(TForm tf) |
| 7298 | { |
| 7299 | SymeList sl; |
| 7300 | |
| 7301 | for (sl = tfGetDomExports(tf); sl; sl = cdr(sl)((sl)->rest)) { |
| 7302 | Syme syme = car(sl)((sl)->first); |
| 7303 | if (symeId(syme)((syme)->id) == symIntern("RawType")symProbe("RawType", 1 | 2) && |
| 7304 | tfIsRawMap(symeType(syme))) |
| 7305 | return tfMapRet(symeType(syme))tfFollowArg(symeType(syme), 1); |
| 7306 | } |
| 7307 | return tf; |
| 7308 | } |
| 7309 | |
| 7310 | /* |
| 7311 | * tfVariable |
| 7312 | */ |
| 7313 | |
| 7314 | TForm |
| 7315 | tfSetVariable(TForm var, TForm val) |
| 7316 | { |
| 7317 | assert(tfIsVariable(var))do { if (!((((var)->tag) == TF_Variable))) _do_assert(("tfIsVariable(var)" ),"tform.c",7317); } while (0); |
| 7318 | var->tag = TF_Forward; |
| 7319 | var->argv[0] = val; |
| 7320 | return var; |
| 7321 | } |
| 7322 | |
| 7323 | /* |
| 7324 | * tfIf |
| 7325 | */ |
| 7326 | |
| 7327 | TForm |
| 7328 | tfIf(TForm test, TForm thenAlt, TForm elseAlt) |
| 7329 | { |
| 7330 | TForm tf; |
| 7331 | tfFollow(test)((test) = tfFollowFn(test)); |
| 7332 | tfFollow(thenAlt)((thenAlt) = tfFollowFn(thenAlt)); |
| 7333 | tfFollow(elseAlt)((elseAlt) = tfFollowFn(elseAlt)); |
| 7334 | tf = tfNewNode(TF_If, 3, test, thenAlt, elseAlt); |
| 7335 | return tf; |
| 7336 | } |
| 7337 | |
| 7338 | /* |
| 7339 | * tfJoin |
| 7340 | */ |
| 7341 | |
| 7342 | TForm |
| 7343 | tfJoin(Length argc, ...) |
| 7344 | { |
| 7345 | TForm tf; |
| 7346 | Length i; |
| 7347 | va_list argp; |
| 7348 | |
| 7349 | tf = tfNewEmpty(TF_Join, argc); |
| 7350 | |
| 7351 | va_start(argp, argc)__builtin_va_start(argp, argc); |
| 7352 | for (i = 0; i < argc; i += 1) |
| 7353 | tfArgv(tf)((tf)->argv)[i] = va_arg(argp, TForm)__builtin_va_arg(argp, TForm); |
| 7354 | va_end(argp)__builtin_va_end(argp); |
| 7355 | |
| 7356 | return tf; |
| 7357 | } |
| 7358 | |
| 7359 | TForm |
| 7360 | tfJoinFrList(TFormList tl0) |
| 7361 | { |
| 7362 | Length i, j, argc; |
| 7363 | TFormList tl; |
| 7364 | TForm tf; |
| 7365 | |
| 7366 | for (tl = tl0, argc = 0; tl; tl = cdr(tl)((tl)->rest)) |
| 7367 | argc += tfIsJoin(car(tl))(((((tl)->first))->tag) == TF_Join) ? tfJoinArgc(car(tl))((((tl)->first))->argc) : 1; |
| 7368 | |
| 7369 | tf = tfNewEmpty(TF_Join, argc); |
| 7370 | for (tl = tl0, i = 0; tl; tl = cdr(tl)((tl)->rest)) |
| 7371 | if (tfIsJoin(car(tl))(((((tl)->first))->tag) == TF_Join)) |
| 7372 | for (j = 0; j < tfJoinArgc(car(tl))((((tl)->first))->argc); j += 1) |
| 7373 | tfArgv(tf)((tf)->argv)[i++] = tfArgv(car(tl))((((tl)->first))->argv)[j]; |
| 7374 | else |
| 7375 | tfArgv(tf)((tf)->argv)[i++] = car(tl)((tl)->first); |
| 7376 | |
| 7377 | tfSetMeaningArgs(tf); |
| 7378 | assert(tfIsMeaning(tf))do { if (!((((tf)->state)>=TF_State_Meaning))) _do_assert (("tfIsMeaning(tf)"),"tform.c",7378); } while (0); |
| 7379 | |
| 7380 | return tf; |
| 7381 | } |
| 7382 | |
| 7383 | /* |
| 7384 | * tfMeet |
| 7385 | */ |
| 7386 | |
| 7387 | TForm |
| 7388 | tfMeet(Length argc, ...) |
| 7389 | { |
| 7390 | TForm tf; |
| 7391 | Length i; |
| 7392 | va_list argp; |
| 7393 | |
| 7394 | tf = tfNewEmpty(TF_Meet, argc); |
| 7395 | |
| 7396 | va_start(argp, argc)__builtin_va_start(argp, argc); |
| 7397 | for (i = 0; i < argc; i += 1) |
| 7398 | tfArgv(tf)((tf)->argv)[i] = va_arg(argp, TForm)__builtin_va_arg(argp, TForm); |
| 7399 | va_end(argp)__builtin_va_end(argp); |
| 7400 | |
| 7401 | return tf; |
| 7402 | } |
| 7403 | |
| 7404 | /* |
| 7405 | * tfHas |
| 7406 | */ |
| 7407 | |
| 7408 | AbSyn |
| 7409 | abHas(Syme syme, TForm tf) |
| 7410 | { |
| 7411 | return abNewHas(sposNone, abFrSyme(syme), tfExpr(tfDefineeType(tf)))abNew(AB_Has, sposNone,2, abFrSyme(syme),tfToAbSyn(tfDefineeType (tf))); |
| 7412 | } |
| 7413 | |
| 7414 | TForm |
| 7415 | tfHas(Syme syme, TForm tf) |
| 7416 | { |
| 7417 | return tfNewAbSyn(TF_General, abHas(syme, tf)); |
| 7418 | } |
| 7419 | |
| 7420 | /* |
| 7421 | * tfExcept |
| 7422 | */ |
| 7423 | |
| 7424 | TForm |
| 7425 | tfExcept(TForm t, TForm e) |
| 7426 | { |
| 7427 | TForm tf; |
| 7428 | tf = tfNewNode(TF_Except, 2, t, e); |
| 7429 | tfSetMeaningArgs(tf); |
| 7430 | return tf; |
| 7431 | } |
| 7432 | |
| 7433 | TForm |
| 7434 | tfIgnoreExceptions(TForm tf) |
| 7435 | { |
| 7436 | tf = tfFollowOnly(tf); |
| 7437 | if (tfIsExcept(tf)(((tf)->tag) == TF_Except)) |
| 7438 | return tfExceptType(tf)tfFollowArg(tf, 0); |
| 7439 | |
| 7440 | return tf; |
| 7441 | } |
| 7442 | |
| 7443 | /* |
| 7444 | * tfExtend |
| 7445 | */ |
| 7446 | |
| 7447 | localstatic TForm tfJoinFlatten (TForm tf); |
| 7448 | |
| 7449 | Bool |
| 7450 | tfIsExtendTemplate(TForm tf) |
| 7451 | { |
| 7452 | if (tfIsDeclare(tf)(((tf)->tag) == TF_Declare)) |
| 7453 | tf = tfDeclareType(tf)tfFollowArg(tf, 0); |
| 7454 | |
| 7455 | return tfIsUnknown(tf)(((tf)->tag) == TF_Unknown) || tfIsUnknownMap(tf)(((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && (((tfFollowArg(tf, 1))->tag) == TF_Unknown)); |
| 7456 | } |
| 7457 | |
| 7458 | Bool |
| 7459 | tfCanExtend(TForm tf, TForm tmpl) |
| 7460 | { |
| 7461 | Bool result; |
| 7462 | |
| 7463 | if (tfIsDeclare(tmpl)(((tmpl)->tag) == TF_Declare)) |
| 7464 | tmpl = tfDeclareType(tmpl)tfFollowArg(tmpl, 0); |
| 7465 | |
| 7466 | if (tfIsAnyMap(tmpl)((((tmpl)->tag) == TF_Map) || (((tmpl)->tag) == TF_PackedMap ))) |
| 7467 | result = tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && tfMapArgc(tf) == tfMapArgc(tmpl); |
| 7468 | |
| 7469 | else |
| 7470 | result = !tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )); |
| 7471 | |
| 7472 | return result; |
| 7473 | } |
| 7474 | |
| 7475 | TForm |
| 7476 | tfExtendEmpty(TForm tmpl, Length argc) |
| 7477 | { |
| 7478 | TForm tf; |
| 7479 | |
| 7480 | if (tfIsDeclare(tmpl)(((tmpl)->tag) == TF_Declare)) |
| 7481 | tmpl = tfDeclareType(tmpl)tfFollowArg(tmpl, 0); |
| 7482 | |
| 7483 | if (tfIsAnyMap(tmpl)((((tmpl)->tag) == TF_Map) || (((tmpl)->tag) == TF_PackedMap ))) { |
| 7484 | Length i, targc = tfMapArgc(tmpl); |
| 7485 | TForm tfarg, tfret; |
| 7486 | |
| 7487 | if (targc == 1) |
| 7488 | tfarg = tfNewEmpty(TF_Meet, argc); |
| 7489 | else { |
| 7490 | tfarg = tfNewEmpty(TF_Multiple, targc); |
| 7491 | for (i = 0; i < targc; i += 1) |
| 7492 | tfArgv(tfarg)((tfarg)->argv)[i] = tfNewEmpty(TF_Meet, argc); |
| 7493 | } |
| 7494 | tfret = tfNewEmpty(TF_Join, argc); |
| 7495 | tf = tfAnyMap(tfarg, tfret, tfIsPackedMap(tmpl)(((tmpl)->tag) == TF_PackedMap)); |
| 7496 | tfSetStab(tf, tfStab(tmpl))((tf)->stab = (((tmpl)->stab))); |
| 7497 | } |
| 7498 | else |
| 7499 | tf = tfNewEmpty(TF_Join, argc); |
| 7500 | |
| 7501 | return tf; |
| 7502 | } |
| 7503 | |
| 7504 | Length |
| 7505 | tfExtendNext(TForm tf) |
| 7506 | { |
| 7507 | Length i; |
| 7508 | |
| 7509 | if (tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap ))) tf = tfMapRet(tf)tfFollowArg(tf, 1); |
| 7510 | |
| 7511 | for (i = 0; i < tfArgc(tf)((tf)->argc) && tfArgv(tf)((tf)->argv)[i]; i += 1) ; |
| 7512 | |
| 7513 | return i; |
| 7514 | } |
| 7515 | |
| 7516 | #define tfExtendCheck(tag,tf,i)(((tf)->tag) == (tag) && (i) < ((tf)->argc) && ((tf)->argv)[i] == ((void*)0)) \ |
| 7517 | (tfTag(tf)((tf)->tag) == (tag) && (i) < tfArgc(tf)((tf)->argc) && tfArgv(tf)((tf)->argv)[i] == NULL((void*)0)) |
| 7518 | |
| 7519 | void |
| 7520 | tfExtendFill(TForm tf, Length i, TForm ext) |
| 7521 | { |
| 7522 | if (tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap ))) { |
| 7523 | Length j; |
| 7524 | |
| 7525 | assert(tfIsAnyMap(ext))do { if (!(((((ext)->tag) == TF_Map) || (((ext)->tag) == TF_PackedMap)))) _do_assert(("tfIsAnyMap(ext)"),"tform.c",7525 ); } while (0); |
| 7526 | assert(tfMapArgc(tf) == tfMapArgc(ext))do { if (!(tfMapArgc(tf) == tfMapArgc(ext))) _do_assert(("tfMapArgc(tf) == tfMapArgc(ext)" ),"tform.c",7526); } while (0); |
| 7527 | |
| 7528 | /* Fill the arg types w/ the arg types from the extendees. */ |
| 7529 | for (j = 0; j < tfMapArgc(tf); j += 1) { |
| 7530 | TForm tfj = tfMapArgN(tf, j); |
| 7531 | assert(tfExtendCheck(TF_Meet, tfj, i))do { if (!((((tfj)->tag) == (TF_Meet) && (i) < ( (tfj)->argc) && ((tfj)->argv)[i] == ((void*)0)) )) _do_assert(("tfExtendCheck(TF_Meet, tfj, i)"),"tform.c",7531 ); } while (0); |
| 7532 | tfArgv(tfj)((tfj)->argv)[i] = tfMapArgN(ext, j); |
| 7533 | } |
| 7534 | |
| 7535 | /* Fill the ret types w/ the ret types from the extendees. */ |
| 7536 | assert(tfExtendCheck(TF_Join, tfMapRet(tf), i))do { if (!((((tfFollowArg(tf, 1))->tag) == (TF_Join) && (i) < ((tfFollowArg(tf, 1))->argc) && ((tfFollowArg (tf, 1))->argv)[i] == ((void*)0)))) _do_assert(("tfExtendCheck(TF_Join, tfMapRet(tf), i)" ),"tform.c",7536); } while (0); |
| 7537 | tfArgv(tfMapRet(tf))((tfFollowArg(tf, 1))->argv)[i] = tfMapRet(ext)tfFollowArg(ext, 1); |
| 7538 | } |
| 7539 | else { |
| 7540 | assert(tfExtendCheck(TF_Join, tf, i))do { if (!((((tf)->tag) == (TF_Join) && (i) < ( (tf)->argc) && ((tf)->argv)[i] == ((void*)0)))) _do_assert(("tfExtendCheck(TF_Join, tf, i)"),"tform.c",7540) ; } while (0); |
| 7541 | tfArgv(tf)((tf)->argv)[i] = ext; |
| 7542 | } |
| 7543 | } |
| 7544 | |
| 7545 | TForm |
| 7546 | tfExtendeeSubst(Stab stab, TForm tf, TForm tmpl) |
| 7547 | { |
| 7548 | Length i; |
| 7549 | AbSub sigma; |
| 7550 | |
| 7551 | if (tfIsDeclare(tmpl)(((tmpl)->tag) == TF_Declare)) |
| 7552 | tmpl = tfDeclareType(tmpl)tfFollowArg(tmpl, 0); |
| 7553 | assert(tfIsAnyMap(tf) && tfIsAnyMap(tmpl) &&do { if (!(((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && ((((tmpl)->tag) == TF_Map) || (((tmpl)->tag ) == TF_PackedMap)) && tfMapArgc(tf) == tfMapArgc(tmpl ))) _do_assert(("tfIsAnyMap(tf) && tfIsAnyMap(tmpl) && tfMapArgc(tf) == tfMapArgc(tmpl)" ),"tform.c",7554); } while (0) |
| 7554 | tfMapArgc(tf) == tfMapArgc(tmpl))do { if (!(((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && ((((tmpl)->tag) == TF_Map) || (((tmpl)->tag ) == TF_PackedMap)) && tfMapArgc(tf) == tfMapArgc(tmpl ))) _do_assert(("tfIsAnyMap(tf) && tfIsAnyMap(tmpl) && tfMapArgc(tf) == tfMapArgc(tmpl)" ),"tform.c",7554); } while (0); |
| 7555 | |
| 7556 | /* Replace old parameter symes with new symes for the extendee. */ |
| 7557 | sigma = absNew(stab); |
| 7558 | for (i = 0; i < tfMapArgc(tf); i += 1) { |
| 7559 | Syme osyme = tfDefineeSyme(tfMapArgN(tf, i)); |
| 7560 | Syme nsyme = tfDefineeSyme(tfMapArgN(tmpl, i)); |
| 7561 | |
| 7562 | assert(osyme && nsyme)do { if (!(osyme && nsyme)) _do_assert(("osyme && nsyme" ),"tform.c",7562); } while (0); |
| 7563 | sigma = absExtend(osyme, abFrSyme(nsyme), sigma); |
| 7564 | } |
| 7565 | |
| 7566 | tf = tformSubstSigma(sigma, tfMapRet(tf)tfFollowArg(tf, 1)); |
| 7567 | tmpl = tfMapRet(tmpl)tfFollowArg(tmpl, 1); |
| 7568 | absFree(sigma); |
| 7569 | |
| 7570 | if (tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap ))) |
| 7571 | tf = tfExtendeeSubst(stab, tf, tmpl); |
| 7572 | |
| 7573 | return tf; |
| 7574 | } |
| 7575 | |
| 7576 | void |
| 7577 | tfExtendSubst(Stab stab, TForm tf) |
| 7578 | { |
| 7579 | Length i, j; |
| 7580 | TForm tfarg, tfret, ntf, ntfret; |
| 7581 | AbSub sigma; |
| 7582 | SymeList symes; |
| 7583 | |
| 7584 | if (!tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap ))) |
| 7585 | return; |
| 7586 | |
| 7587 | tfarg = tfMapArg(tf)tfFollowArg(tf, 0); |
| 7588 | tfret = tfMapRet(tf)tfFollowArg(tf, 1); |
| 7589 | |
| 7590 | assert(tfIsJoin(tfret) && tfJoinArgc(tfret) > 0)do { if (!((((tfret)->tag) == TF_Join) && ((tfret) ->argc) > 0)) _do_assert(("tfIsJoin(tfret) && tfJoinArgc(tfret) > 0" ),"tform.c",7590); } while (0); |
| 7591 | |
| 7592 | /* Replace old parameter symes with new symes for the extension. */ |
| 7593 | assert(tfStab(tf))do { if (!(((tf)->stab))) _do_assert(("tfStab(tf)"),"tform.c" ,7593); } while (0); |
| 7594 | sigma = absNew(tfStab(tf)((tf)->stab)); |
| 7595 | symes = listNil(Syme)((SymeList) 0); |
| 7596 | for (j = 0; j < tfMapArgc(tf); j += 1) { |
| 7597 | TForm tfj = tfMapArgN(tf, j); |
| 7598 | Syme osyme = NULL((void*)0), nsyme; |
| 7599 | AbSyn ab; |
| 7600 | |
| 7601 | assert(tfIsMeet(tfj) && tfMeetArgc(tfj) > 1)do { if (!((((tfj)->tag) == TF_Meet) && ((tfj)-> argc) > 1)) _do_assert(("tfIsMeet(tfj) && tfMeetArgc(tfj) > 1" ),"tform.c",7601); } while (0); |
| 7602 | |
| 7603 | /* Create the new param syme from an extension param syme. */ |
| 7604 | for (i = 1; !osyme && i < tfMeetArgc(tfj)((tfj)->argc); i += 1) |
| 7605 | osyme = tfDefineeSyme(tfMeetArgv(tfj)((tfj)->argv)[i]); |
| 7606 | assert(osyme)do { if (!(osyme)) _do_assert(("osyme"),"tform.c",7606); } while (0); |
| 7607 | symeType(osyme); |
| 7608 | nsyme = symeCopy(osyme); |
| 7609 | symeSetLib(nsyme, NULL((void*)0)); |
| 7610 | symeSetHash(nsyme, (Hash) 0)(((nsyme)->hash) = ((Hash) 0)); |
| 7611 | ab = abFrSyme(nsyme); |
| 7612 | |
| 7613 | for (i = 0; i < tfMeetArgc(tfj)((tfj)->argc); i += 1) { |
| 7614 | TForm tfi = tfMeetArgv(tfj)((tfj)->argv)[i]; |
| 7615 | Syme syme = tfDefineeSyme(tfi); |
| 7616 | |
| 7617 | if (syme) { |
| 7618 | symeAddTwin(nsyme, syme); |
| 7619 | sigma = absExtend(syme, ab, sigma); |
| 7620 | } |
| 7621 | } |
| 7622 | |
| 7623 | symes = listCons(Syme)(Syme_listPointer->Cons)(nsyme, symes); |
| 7624 | } |
| 7625 | symes = listNReverse(Syme)(Syme_listPointer->NReverse)(symes); |
| 7626 | tfSetSymes(tf, symes)((tf)->symes = (symes)); |
| 7627 | |
| 7628 | ntf = tformSubstSigma(sigma, tf); |
| 7629 | absFree(sigma); |
| 7630 | |
| 7631 | /* Replace old types with new types for the extension. */ |
| 7632 | tfFollow(ntf)((ntf) = tfFollowFn(ntf)); |
| 7633 | assert(tfIsAnyMap(ntf))do { if (!(((((ntf)->tag) == TF_Map) || (((ntf)->tag) == TF_PackedMap)))) _do_assert(("tfIsAnyMap(ntf)"),"tform.c",7633 ); } while (0); |
| 7634 | for (j = 0; j < tfMapArgc(tf); j += 1) { |
| 7635 | TForm otfj = tfMapArgN(tf, j); |
| 7636 | TForm ntfj = tfMapArgN(ntf, j); |
| 7637 | |
| 7638 | tfFollow(ntfj)((ntfj) = tfFollowFn(ntfj)); |
| 7639 | assert(tfIsMeet(ntfj) && tfMeetArgc(ntfj) == tfMeetArgc(otfj))do { if (!((((ntfj)->tag) == TF_Meet) && ((ntfj)-> argc) == ((otfj)->argc))) _do_assert(("tfIsMeet(ntfj) && tfMeetArgc(ntfj) == tfMeetArgc(otfj)" ),"tform.c",7639); } while (0); |
| 7640 | |
| 7641 | for (i = 0; i < tfMeetArgc(otfj)((otfj)->argc); i += 1) |
| 7642 | tfMeetArgv(otfj)((otfj)->argv)[i] = tfMeetArgv(ntfj)((ntfj)->argv)[i]; |
| 7643 | tfSetFVars(otfj, NULL)(((otfj)->fv) = (((void*)0))); |
| 7644 | } |
| 7645 | |
| 7646 | ntfret = tfMapRet(ntf)tfFollowArg(ntf, 1); |
| 7647 | tfFollow(ntfret)((ntfret) = tfFollowFn(ntfret)); |
| 7648 | assert(tfIsJoin(ntfret) && tfJoinArgc(ntfret) == tfJoinArgc(tfret))do { if (!((((ntfret)->tag) == TF_Join) && ((ntfret )->argc) == ((tfret)->argc))) _do_assert(("tfIsJoin(ntfret) && tfJoinArgc(ntfret) == tfJoinArgc(tfret)" ),"tform.c",7648); } while (0); |
| 7649 | |
| 7650 | for (i = 0; i < tfJoinArgc(tfret)((tfret)->argc); i += 1) |
| 7651 | tfJoinArgv(tfret)((tfret)->argv)[i] = tfJoinArgv(ntfret)((ntfret)->argv)[i]; |
| 7652 | tfSetFVars(tfret, NULL)(((tfret)->fv) = (((void*)0))); |
| 7653 | tfSetFVars(tf, NULL)(((tf)->fv) = (((void*)0))); |
| 7654 | } |
| 7655 | |
| 7656 | localstatic TForm |
| 7657 | tfIsIdempotent(TForm tf) |
| 7658 | { |
| 7659 | TForm tf0 = NULL((void*)0), tf1 = NULL((void*)0); |
| 7660 | Length i, argc; |
| 7661 | |
| 7662 | assert(tfIsJoin(tf) || tfIsMeet(tf))do { if (!((((tf)->tag) == TF_Join) || (((tf)->tag) == TF_Meet ))) _do_assert(("tfIsJoin(tf) || tfIsMeet(tf)"),"tform.c",7662 ); } while (0); |
| 7663 | |
| 7664 | argc = tfArgc(tf)((tf)->argc); |
| 7665 | |
| 7666 | for (i = 0; !tf1 && i < argc; i += 1) { |
| 7667 | TForm tfi = tfArgv(tf)((tf)->argv)[i]; |
| 7668 | if (tf0 == NULL((void*)0)) |
| 7669 | tf0 = tfi; |
| 7670 | else if (!tformEqual(tf0, tfi)) |
| 7671 | tf1 = tfi; |
| 7672 | } |
| 7673 | |
| 7674 | if (tf0 == NULL((void*)0)) |
| 7675 | return tfArgv(tf)((tf)->argv)[0]; |
| 7676 | else if (tf1 == NULL((void*)0)) |
| 7677 | return tf0; |
| 7678 | else |
| 7679 | return NULL((void*)0); |
| 7680 | } |
| 7681 | |
| 7682 | localstatic void |
| 7683 | tfForwardIdempotent(TForm tf, TForm ntf) |
| 7684 | { |
| 7685 | assert(tfIsJoin(tf) || tfIsMeet(tf))do { if (!((((tf)->tag) == TF_Join) || (((tf)->tag) == TF_Meet ))) _do_assert(("tfIsJoin(tf) || tfIsMeet(tf)"),"tform.c",7685 ); } while (0); |
| 7686 | |
| 7687 | tf->tag = TF_Forward; |
| 7688 | tf->argc = 1; |
| 7689 | tf->argv[0] = ntf; |
| 7690 | } |
| 7691 | |
| 7692 | void |
| 7693 | tfExtendFinish(TForm tf) |
| 7694 | { |
| 7695 | Length i, j; |
| 7696 | TForm tfarg, tfret, ntfj; |
| 7697 | SymeList symes; |
| 7698 | |
| 7699 | if (!tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap ))) { |
| 7700 | Stab stab = NULL((void*)0); |
| 7701 | |
| 7702 | assert(tfIsJoin(tf) && tfJoinArgc(tf) > 0)do { if (!((((tf)->tag) == TF_Join) && ((tf)->argc ) > 0)) _do_assert(("tfIsJoin(tf) && tfJoinArgc(tf) > 0" ),"tform.c",7702); } while (0); |
| 7703 | for (j = tfJoinArgc(tf)((tf)->argc); !stab && j > 0; ) { |
| 7704 | TForm tfj = tfJoinArgN(tf, --j)tfFollowArg(tf, --j); |
| 7705 | stab = tfGetStab(tfDefineeType(tfj)); |
| 7706 | if (!stab && tfIsDefine(tfj)(((tfj)->tag) == TF_Define)) |
| 7707 | stab = tfGetStab(tfDefineVal(tfj)tfFollowArg(tfj, 1)); |
| 7708 | } |
| 7709 | if (!stab) stab = stabFile(); |
| 7710 | |
| 7711 | tf = tfJoinFlatten(tf); |
| 7712 | tfSetMeaning(tf)(((tf)->state)=TF_State_Meaning); |
| 7713 | for (symes = tfGetCatExports(tf); symes; symes = cdr(symes)((symes)->rest)) |
| 7714 | tfExtendFinishTwins(stab, car(symes)((symes)->first)); |
| 7715 | return; |
| 7716 | } |
| 7717 | |
| 7718 | tfarg = tfMapArg(tf)tfFollowArg(tf, 0); |
| 7719 | tfret = tfMapRet(tf)tfFollowArg(tf, 1); |
| 7720 | |
| 7721 | assert(tfIsJoin(tfret) && tfJoinArgc(tfret) > 0)do { if (!((((tfret)->tag) == TF_Join) && ((tfret) ->argc) > 0)) _do_assert(("tfIsJoin(tfret) && tfJoinArgc(tfret) > 0" ),"tform.c",7721); } while (0); |
| 7722 | |
| 7723 | for (j = tfMapArgc(tf); j > 0; ) { |
| 7724 | TForm tfj = tfMapArgN(tf, --j); |
| 7725 | Syme syme = NULL((void*)0); |
| 7726 | Length argc; |
| 7727 | |
| 7728 | assert(tfIsMeet(tfj) && tfMeetArgc(tfj) > 0)do { if (!((((tfj)->tag) == TF_Meet) && ((tfj)-> argc) > 0)) _do_assert(("tfIsMeet(tfj) && tfMeetArgc(tfj) > 0" ),"tform.c",7728); } while (0); |
| 7729 | argc = tfMeetArgc(tfj)((tfj)->argc); |
| 7730 | |
| 7731 | /* If all args are the same, forward to the first. */ |
| 7732 | if ((ntfj = tfIsIdempotent(tfj)) != NULL((void*)0)) { |
| 7733 | tfForwardIdempotent(tfj, ntfj); |
| 7734 | tfSetMeaning(tfj)(((tfj)->state)=TF_State_Meaning); |
| 7735 | continue; |
| 7736 | } |
| 7737 | |
| 7738 | /* Otherwise conditionalize the ret types. */ |
| 7739 | for (i = 0; !syme && i < argc; i += 1) |
| 7740 | syme = tfDefineeSyme(tfMeetArgv(tfj)((tfj)->argv)[i]); |
| 7741 | assert(syme)do { if (!(syme)) _do_assert(("syme"),"tform.c",7741); } while (0); |
| 7742 | for (i = 0; i < tfJoinArgc(tfret)((tfret)->argc); i += 1) { |
| 7743 | TForm tfi = tfJoinArgv(tfret)((tfret)->argv)[i]; |
| 7744 | TForm ifi = tfMeetArgv(tfj)((tfj)->argv)[i]; |
| 7745 | ifi = tfDefineeType(ifi); |
| 7746 | if (tfIsType(ifi)(((ifi)->tag) == TF_Type)) |
| 7747 | ifi = tfi; |
| 7748 | else |
| 7749 | ifi = tfIf(tfHas(syme, ifi), tfi, tfNone()tfMulti(0)); |
| 7750 | tfJoinArgv(tfret)((tfret)->argv)[i] = ifi; |
| 7751 | tfSetMeaning(ifi)(((ifi)->state)=TF_State_Meaning); |
| 7752 | } |
| 7753 | |
| 7754 | /* ... and commute Meet v. Declare. */ |
| 7755 | ntfj = tfNewEmpty(TF_Meet, argc); |
| 7756 | for (i = 0; i < argc; i += 1) |
| 7757 | tfArgv(ntfj)((ntfj)->argv)[i] = tfDefineeType(tfMeetArgv(tfj)((tfj)->argv)[i]); |
| 7758 | tfSetMeaning(ntfj)(((ntfj)->state)=TF_State_Meaning); |
| 7759 | symeSetUsedDeeply(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->bits) |= (0x0004)); |
| 7760 | ntfj = tfDeclare(abFrSyme(syme), ntfj); |
| 7761 | tfForwardIdempotent(tfj, ntfj); |
| 7762 | tfSetMeaning(tfj)(((tfj)->state)=TF_State_Meaning); |
| 7763 | } |
| 7764 | |
| 7765 | tfret = tfJoinFlatten(tfret); |
| 7766 | |
| 7767 | if ((ntfj = tfIsIdempotent(tfret)) != NULL((void*)0)) |
| 7768 | tfForwardIdempotent(tfret, ntfj); |
| 7769 | |
| 7770 | tfSetMeaning(tfarg)(((tfarg)->state)=TF_State_Meaning); |
| 7771 | tfSetMeaning(tfret)(((tfret)->state)=TF_State_Meaning); |
| 7772 | tfSetMeaning(tf)(((tf)->state)=TF_State_Meaning); |
| 7773 | |
| 7774 | assert(tfStab(tf))do { if (!(((tf)->stab))) _do_assert(("tfStab(tf)"),"tform.c" ,7774); } while (0); |
| 7775 | for (symes = tfGetCatExports(tfret); symes; symes = cdr(symes)((symes)->rest)) |
| 7776 | tfExtendFinishTwins(tfStab(tf)((tf)->stab), car(symes)((symes)->first)); |
| 7777 | } |
| 7778 | |
| 7779 | localstatic void |
| 7780 | tfExtendFinishTwins(Stab stab, Syme syme) |
| 7781 | { |
| 7782 | SymeList symes = symeTwins(syme); |
| 7783 | |
| 7784 | if (syme == symeOriginal(syme)) return; |
| 7785 | if (symeIsLazy(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->bits) & (0x0001))) symeType(syme); |
| 7786 | |
| 7787 | if (!symeIsSelfSelf(syme)(((syme)->id) == ssymSelfSelf)) { |
| 7788 | symeSetLib(syme, NULL((void*)0)); |
| 7789 | symeSetHash(syme, (Hash) 0)(((syme)->hash) = ((Hash) 0)); |
| 7790 | symeSetDefLevel(syme, car(stab)((stab)->first)); |
| 7791 | } |
| 7792 | for (; symes; symes = cdr(symes)((symes)->rest)) { |
| 7793 | Syme twin = car(symes)((symes)->first); |
| 7794 | if (twin != syme) tfExtendFinishTwins(stab, twin); |
| 7795 | } |
| 7796 | } |
| 7797 | |
| 7798 | localstatic TForm |
| 7799 | tfJoinFlatten(TForm tf) |
| 7800 | { |
| 7801 | TForm tf2; |
| 7802 | int argc, i, ii, j; |
| 7803 | |
| 7804 | for (i=0, argc=0; i<tfJoinArgc(tf)((tf)->argc); i++) |
| 7805 | argc += tfIsJoin(tfJoinArgv(tf)[i])(((((tf)->argv)[i])->tag) == TF_Join) ? tfJoinArgc(tfJoinArgv(tf)[i])((((tf)->argv)[i])->argc) : 1; |
| 7806 | |
| 7807 | if (argc == i) |
| 7808 | return tf; |
| 7809 | |
| 7810 | tf2 = tfNewEmpty(TF_Join, argc); |
| 7811 | for (i=0, j=0; i<tfJoinArgc(tf)((tf)->argc); i++) { |
| 7812 | TForm tfi = tfJoinArgv(tf)((tf)->argv)[i]; |
| 7813 | if (!tfIsJoin(tfi)(((tfi)->tag) == TF_Join)) |
| 7814 | tfJoinArgv(tf2)((tf2)->argv)[j++] = tfi; |
| 7815 | else |
| 7816 | for (ii=0; ii<tfJoinArgc(tfi)((tfi)->argc); ii++) |
| 7817 | tfJoinArgv(tf2)((tf2)->argv)[j++] = tfJoinArgv(tfi)((tfi)->argv)[ii]; |
| 7818 | } |
| 7819 | /* Forward tf to tf2 */ |
| 7820 | tfTag(tf)((tf)->tag) = TF_Forward; |
| 7821 | tf->argc = 1; |
| 7822 | tf->argv[0] = tf2; |
| 7823 | return tf2; |
| 7824 | } |
| 7825 | |
| 7826 | |
| 7827 | /* |
| 7828 | * Given a symbol, return its unique tform or NULL if not possible. |
| 7829 | * This is really only applicable for types where we can be certain |
| 7830 | * of name uniqueness. |
| 7831 | */ |
| 7832 | TForm |
| 7833 | tfFrSymbol(Symbol sym) |
| 7834 | { |
| 7835 | /* Get the meanings for this symbol */ |
| 7836 | SymeList symes = stabGetMeanings(stabFile(), ablogFalse(), sym); |
| 7837 | |
| 7838 | |
| 7839 | /* There can only be one ... */ |
| 7840 | if (symes && !cdr(symes)((symes)->rest)) |
| 7841 | return tiTopFns()->tiGetTopLevelTForm(ablogTrue(), abFrSyme(car(symes)((symes)->first))); |
| 7842 | else |
| 7843 | return (TForm)NULL((void*)0); |
| 7844 | } |
| 7845 | |
| 7846 | |
| 7847 | /* |
| 7848 | * Return the tform for a functor symbol applied to an argument |
| 7849 | * This is really only applicable for types where we can be certain |
| 7850 | * of name uniqueness. |
| 7851 | */ |
| 7852 | TForm |
| 7853 | tfFrSymbolPair(Symbol functor, Symbol argument) |
| 7854 | { |
| 7855 | /* Get the meanings for these symbols */ |
| 7856 | SymeList fsymes = stabGetMeanings(stabFile(), ablogFalse(), functor); |
| 7857 | SymeList asymes = stabGetMeanings(stabFile(), ablogFalse(), argument); |
| 7858 | AbSyn op = abNewOfToken(AB_Id, tokId(sposNone, sposNone, functor)tokNew(sposNone, sposNone, TK_Id, functor)); |
| 7859 | AbSyn arg = abNewOfToken(AB_Id, tokId(sposNone, sposNone, argument)tokNew(sposNone, sposNone, TK_Id, argument)); |
| 7860 | AbSyn ab = abNewApply1(sposNone, op, arg)abNew(AB_Apply, sposNone,2, op,arg); |
| 7861 | |
| 7862 | |
| 7863 | /* |
| 7864 | * Construct a tform for the expression functor(arg). |
| 7865 | * If we can't find meanings for either the functor or the |
| 7866 | * argument symbols then they can't have been defined. We |
| 7867 | * won't return tforms for this pair otherwise the type |
| 7868 | * inference phase of tiGetTForm() below will scream. This |
| 7869 | * is to allow libraries to be defined which don't necessarily |
| 7870 | * have the requested value defined anywhere. |
| 7871 | */ |
| 7872 | if (!fsymes || !asymes) |
| 7873 | return tfUnknown; /* Please don't return (TForm)NULL */ |
| 7874 | else |
| 7875 | return tiTopFns()->tiGetTopLevelTForm(ablogTrue(), ab); |
| 7876 | } |
| 7877 | |
| 7878 | /***************************************************************************** |
| 7879 | * |
| 7880 | * :: Types of operations used in syntactic sugar |
| 7881 | * |
| 7882 | ****************************************************************************/ |
| 7883 | |
| 7884 | /* |
| 7885 | * LitOpType |
| 7886 | */ |
| 7887 | |
| 7888 | Bool |
| 7889 | tfIsLitOpType(TForm tf) |
| 7890 | { |
| 7891 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7892 | return tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && |
| 7893 | tfMapArgc(tf) == 1 && |
| 7894 | tfEqual(tfMapArgN(tf, int0((int) 0)), tfLiteral); |
| 7895 | } |
| 7896 | |
| 7897 | TForm |
| 7898 | tfLitOpTypeRet(TForm tf) |
| 7899 | { |
| 7900 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7901 | if (!tfIsLitOpType(tf)) |
| 7902 | bug("tfLitOpTypeRet: !tfIsLitOpType(tf)"); |
| 7903 | |
| 7904 | return tfMapRet(tf)tfFollowArg(tf, 1); |
| 7905 | } |
| 7906 | |
| 7907 | /* |
| 7908 | * TestOpType |
| 7909 | */ |
| 7910 | |
| 7911 | Bool |
| 7912 | tfIsTestOpType(TForm tf) |
| 7913 | { |
| 7914 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7915 | return tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && |
| 7916 | tfMapArgc(tf) == 1 && |
| 7917 | tfEqual(tfMapRet(tf)tfFollowArg(tf, 1), tfTest); |
| 7918 | } |
| 7919 | |
| 7920 | TForm |
| 7921 | tfTestOpTypeArg(TForm tf) |
| 7922 | { |
| 7923 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7924 | if (!tfIsTestOpType(tf)) |
| 7925 | bug("tfTestOpTypeArg: !tfIsTestOpType(tf)"); |
| 7926 | |
| 7927 | return tfMapArg(tf)tfFollowArg(tf, 0); |
| 7928 | } |
| 7929 | |
| 7930 | /* |
| 7931 | * GeneratorOpType |
| 7932 | */ |
| 7933 | |
| 7934 | Bool |
| 7935 | tfIsGeneratorOpType(TForm tf) |
| 7936 | { |
| 7937 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7938 | return tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && |
| 7939 | tfIsGenerator(tfMapRet(tf))(((tfFollowArg(tf, 1))->tag) == TF_Generator); |
| 7940 | } |
| 7941 | |
| 7942 | Bool |
| 7943 | tfIsXGeneratorOpType(TForm tf) |
| 7944 | { |
| 7945 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7946 | return tfIsAnyMap(tf)((((tf)->tag) == TF_Map) || (((tf)->tag) == TF_PackedMap )) && |
| 7947 | tfIsXGenerator(tfMapRet(tf))(((tfFollowArg(tf, 1))->tag) == TF_XGenerator); |
| 7948 | } |
| 7949 | |
| 7950 | TForm |
| 7951 | tfGeneratorOpTypeArg(TForm tf) |
| 7952 | { |
| 7953 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7954 | if (!tfIsGeneratorOpType(tf)) |
| 7955 | bug("tfGeneratorOpTypeArg: !tfIsGeneratorOpType(tf)"); |
| 7956 | |
| 7957 | return tfMapArg(tf)tfFollowArg(tf, 0); |
| 7958 | } |
| 7959 | |
| 7960 | TForm |
| 7961 | tfXGeneratorOpTypeArg(TForm tf) |
| 7962 | { |
| 7963 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7964 | if (!tfIsXGeneratorOpType(tf)) |
| 7965 | bug("tfXGeneratorOpTypeArg: !tfIsXGeneratorOpType(tf)"); |
| 7966 | |
| 7967 | return tfMapArg(tf)tfFollowArg(tf, 0); |
| 7968 | } |
| 7969 | |
| 7970 | TForm |
| 7971 | tfGeneratorOpTypeRet(TForm tf) |
| 7972 | { |
| 7973 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7974 | if (!tfIsGeneratorOpType(tf)) |
| 7975 | bug("tfGeneratorOpTypeRet: !tfIsGeneratorOpType(tf)"); |
| 7976 | |
| 7977 | return tfGeneratorArg(tfMapRet(tf))tfFollowArg(tfFollowArg(tf, 1), 0); |
| 7978 | } |
| 7979 | |
| 7980 | TForm |
| 7981 | tfXGeneratorOpTypeRet(TForm tf) |
| 7982 | { |
| 7983 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 7984 | if (!tfIsXGeneratorOpType(tf)) |
| 7985 | bug("tfXGeneratorOpTypeRet: !tfIsXGeneratorOpType(tf)"); |
| 7986 | |
| 7987 | return tfXGeneratorArg(tfMapRet(tf))tfFollowArg(tfFollowArg(tf, 1), 0); |
| 7988 | } |
| 7989 | |
| 7990 | TForm |
| 7991 | tfXGenerator(TForm arg) |
| 7992 | { |
| 7993 | TForm tf = tfNewNode(TF_XGenerator, 1, arg); |
| 7994 | tfSetMeaningArgs(tf); |
| 7995 | return tf; |
| 7996 | } |
| 7997 | |
| 7998 | TForm |
| 7999 | tfAnyGenerator(TfGenType type, TForm tf) |
| 8000 | { |
| 8001 | switch (type) { |
| 8002 | case TFG_Generator: |
| 8003 | return tfGenerator(tf); |
| 8004 | case TFG_XGenerator: |
| 8005 | return tfXGenerator(tf); |
| 8006 | default: |
| 8007 | assert(false)do { if (!(((int) 0))) _do_assert(("false"),"tform.c",8007); } while (0); |
| 8008 | } |
| 8009 | return NULL((void*)0); |
| 8010 | } |
| 8011 | |
| 8012 | Bool |
| 8013 | tfIsAnyGenerator(TForm tf) |
| 8014 | { |
| 8015 | return tfIsGenerator(tf)(((tf)->tag) == TF_Generator) |
| 8016 | || tfIsXGenerator(tf)(((tf)->tag) == TF_XGenerator); |
| 8017 | } |
| 8018 | |
| 8019 | TfGenType |
| 8020 | tfAnyGeneratorType(TForm tf) |
| 8021 | { |
| 8022 | assert(tfIsAnyGenerator(tf))do { if (!(tfIsAnyGenerator(tf))) _do_assert(("tfIsAnyGenerator(tf)" ),"tform.c",8022); } while (0); |
| 8023 | return tfIsGenerator(tf)(((tf)->tag) == TF_Generator) ? TFG_Generator : TFG_XGenerator; |
| 8024 | } |
| 8025 | |
| 8026 | TForm |
| 8027 | tfAnyGeneratorArg(TForm tf) |
| 8028 | { |
| 8029 | if (tfIsGenerator(tf)(((tf)->tag) == TF_Generator)) |
| 8030 | return tfGeneratorArg(tf)tfFollowArg(tf, 0); |
| 8031 | else if (tfIsXGenerator(tf)(((tf)->tag) == TF_XGenerator)) |
| 8032 | return tfXGeneratorArg(tf)tfFollowArg(tf, 0); |
| 8033 | else |
| 8034 | bug("tfIsGeneratorArg: Not reached"); |
| 8035 | } |
| 8036 | |
| 8037 | /* |
| 8038 | Usage |
| 8039 | */ |
| 8040 | |
| 8041 | Bool |
| 8042 | abUseIsDContext(AbSyn ab) |
| 8043 | { |
| 8044 | return abUse(ab)((ab)->abHdr.use) == AB_Use_NoValue || |
| 8045 | abUse(ab)((ab)->abHdr.use) == AB_Use_Type || |
| 8046 | abUse(ab)((ab)->abHdr.use) == AB_Use_Declaration; |
| 8047 | } |
| 8048 | |
| 8049 | Bool |
| 8050 | tfIsTypeTuple(TForm tf) |
| 8051 | { |
| 8052 | return tfIsTuple(tf)(((tf)->tag) == TF_Tuple) && tfIsType(tfTupleArg(tf))(((tfFollowArg(tf, 0))->tag) == TF_Type); |
| 8053 | } |
| 8054 | |
| 8055 | Bool |
| 8056 | tfIsCategoryContext(TForm tf, AbSyn ab) |
| 8057 | { |
| 8058 | if (tfIsUnknown(tf)(((tf)->tag) == TF_Unknown) || tfIsNone(tf)((((tf)->tag) == TF_Multiple) && tfMultiArgc(tf) == 0)) |
| 8059 | return false((int) 0); |
| 8060 | |
| 8061 | if (tfIsCategory(tf)(((tf)->tag) == TF_Category) || tfIsTypeTuple(tf)) |
| 8062 | return true1; |
| 8063 | |
| 8064 | if (abUseIsDContext(ab)) |
| 8065 | return tfSatCat(tf) || tfSatisfies(tf, tfTypeTuple); |
| 8066 | |
| 8067 | return false((int) 0); |
| 8068 | } |
| 8069 | |
| 8070 | Bool |
| 8071 | tfIsNoValueContext(TForm tf, AbSyn ab) |
| 8072 | { |
| 8073 | return abUseIsDContext(ab) || |
| 8074 | tfIsNone(tf)((((tf)->tag) == TF_Multiple) && tfMultiArgc(tf) == 0) || |
| 8075 | tfIsUnknown(tf)(((tf)->tag) == TF_Unknown); |
| 8076 | } |
| 8077 | |
| 8078 | /****************************************************************************** |
| 8079 | * |
| 8080 | * :: Implict category stuff |
| 8081 | * |
| 8082 | *****************************************************************************/ |
| 8083 | |
| 8084 | TForm tfImplPAOps = (TForm)NULL((void*)0); /* DenseStorageCategory */ |
| 8085 | |
| 8086 | void |
| 8087 | tfInitImplicit(void) |
| 8088 | { |
| 8089 | static Bool isInit = false((int) 0); |
| 8090 | |
| 8091 | if (isInit) return; |
| 8092 | |
| 8093 | |
| 8094 | /* Start with the easy one */ |
| 8095 | tfImplPAOps = tfFrSymbol(ssymImplPAOps); |
| 8096 | } |
| 8097 | |
| 8098 | |
| 8099 | TForm |
| 8100 | tfCatFrDom(TForm tf) |
| 8101 | { |
| 8102 | /* Walk past the declaration to get the type */ |
| 8103 | if (tfIsDeclare(tf)(((tf)->tag) == TF_Declare)) |
| 8104 | tf = tfDeclareType(tf)tfFollowArg(tf, 0); |
| 8105 | |
| 8106 | |
| 8107 | /* Do we have the absyn for this domain? */ |
| 8108 | if (!tfHasExpr(tf)((tf)->__absyn != 0)) |
| 8109 | return (TForm)NULL((void*)0); |
| 8110 | |
| 8111 | |
| 8112 | /* Return the category of this domain (if possible) */ |
| 8113 | return abGetCategory((AbSyn)tfGetExpr(tf)((tf)->__absyn)); |
| 8114 | } |
| 8115 | |
| 8116 | |
| 8117 | Bool |
| 8118 | tfDomHasImplicit(TForm tf) |
| 8119 | { |
| 8120 | TForm tfcat = tfCatFrDom(tf); |
| 8121 | |
| 8122 | |
| 8123 | /* Did we manage to get the category? */ |
| 8124 | if (!tfcat) return false((int) 0); |
| 8125 | |
| 8126 | |
| 8127 | /* Ensure that we have the necessary tforms available */ |
| 8128 | tfInitImplicit(); |
| 8129 | |
| 8130 | |
| 8131 | /* Paranoia - do we have the required tform? */ |
| 8132 | if (!tfImplPAOps || tfIsUnknown(tfImplPAOps)(((tfImplPAOps)->tag) == TF_Unknown)) return false((int) 0); |
| 8133 | |
| 8134 | |
| 8135 | /* Does this domain satisfy the category? */ |
| 8136 | return tfSatBit(tfSatHasMask(), tfcat, tfImplPAOps); |
| 8137 | } |
| 8138 | |
| 8139 | |
| 8140 | Bool |
| 8141 | tfCatHasImplicit(TForm tf) |
| 8142 | { |
| 8143 | /* Walk past the declaration to get the type */ |
| 8144 | if (tfIsDeclare(tf)(((tf)->tag) == TF_Declare)) |
| 8145 | tf = tfDeclareType(tf)tfFollowArg(tf, 0); |
| 8146 | |
| 8147 | |
| 8148 | /* Ensure that we have the necessary tforms available */ |
| 8149 | tfInitImplicit(); |
| 8150 | |
| 8151 | |
| 8152 | /* Paranoia - do we have the required tform? */ |
| 8153 | if (!tfImplPAOps || tfIsUnknown(tfImplPAOps)(((tfImplPAOps)->tag) == TF_Unknown)) return false((int) 0); |
| 8154 | |
| 8155 | |
| 8156 | /* Does this domain satisfy the category? */ |
| 8157 | return tfSatBit(tfSatHasMask(), tf, tfImplPAOps); |
| 8158 | } |
| 8159 | |
| 8160 | |
| 8161 | /* |
| 8162 | * If this syme is one of the correct exports then return it |
| 8163 | * otherwise return nothing. |
| 8164 | */ |
| 8165 | Syme |
| 8166 | tfImplicitExport(Stab stab, SymeList mods, Syme syme) |
| 8167 | { |
| 8168 | Syme nsyme = (Syme)NULL((void*)0); |
| 8169 | SymeList isymes; |
| 8170 | Symbol sym = symeId(syme)((syme)->id); |
| 8171 | TForm tf = symeType(syme); |
| 8172 | |
| 8173 | |
| 8174 | /* Ensure that the necessary tforms are available */ |
| 8175 | tfInitImplicit(); |
| 8176 | |
| 8177 | |
| 8178 | /* Paranoia - do we have the required tform? */ |
| 8179 | if (!tfImplPAOps || tfIsUnknown(tfImplPAOps)(((tfImplPAOps)->tag) == TF_Unknown)) return nsyme; |
| 8180 | |
| 8181 | |
| 8182 | /* Extract the symes that we are looking for */ |
| 8183 | isymes = tfGetCatExports(tfImplPAOps); |
| 8184 | |
| 8185 | |
| 8186 | /* Check to see if it is in the list */ |
| 8187 | for (; isymes; isymes = cdr(isymes)((isymes)->rest)) |
| 8188 | { |
| 8189 | Syme xsyme = car(isymes)((isymes)->first); |
| 8190 | |
| 8191 | if (symeId(xsyme)((xsyme)->id) != sym) continue; |
| 8192 | if (!tformEqualMod(mods, symeType(xsyme), tf)) continue; |
| 8193 | |
| 8194 | #if STAB_DEF_IMPLICIT |
| 8195 | syme = stabDefExport(stab, sym, tf, (Doc)NULL((void*)0)); |
| 8196 | #endif |
| 8197 | return syme; /* not xsyme ... */ |
| 8198 | } |
| 8199 | |
| 8200 | |
| 8201 | /* Not one of the implicit packed array operations */ |
| 8202 | return nsyme; |
| 8203 | } |
| 8204 | |
| 8205 | /********************************* |
| 8206 | * |
| 8207 | * :: Conditions |
| 8208 | * |
| 8209 | *********************************/ |
| 8210 | extern void |
| 8211 | tfMergeConditions(TForm tf, Stab stab, TfCondElt conditions) |
| 8212 | { |
| 8213 | if (DEBUG(tf)tfDebug) { |
| 8214 | if (conditions != NULL((void*)0)) |
| 8215 | afprintf(dbOut, "Merge condition %pAbSynList to %pTForm\n", |
| 8216 | conditions->list, tf); |
| 8217 | } |
| 8218 | tfSetConditions(tf, tfCondMerge(tfConditions(tf), stab, conditions))(tf->conditions = (tfCondMerge(tfConditions(tf), stab, conditions ))); |
| 8219 | } |
| 8220 | |
| 8221 | extern TfCond tfFloatConditions(Stab stab, TForm tf) |
| 8222 | { |
| 8223 | if (tfConditions(tf) != NULL((void*)0)) { |
| 8224 | TfCond cond = tfCondFloat(stab, tfConditions(tf)); |
| 8225 | tfSetConditions(tf, cond)(tf->conditions = (cond)); |
| 8226 | } |
| 8227 | |
| 8228 | return tfConditions(tf); |
| 8229 | } |
| 8230 | |
| 8231 | extern |
| 8232 | TfCond tfConditions(TForm tf) |
| 8233 | { |
| 8234 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 8235 | return tf->conditions; |
| 8236 | } |
| 8237 | |
| 8238 | |
| 8239 | AbSynList |
| 8240 | tfConditionalAbSyn(TForm tf) |
| 8241 | { |
| 8242 | if (tfConditions(tf) == NULL((void*)0)) |
| 8243 | return listNil(AbSyn)((AbSynList) 0); |
| 8244 | if (tfConditions(tf)->containsEmpty) |
| 8245 | return listNil(AbSyn)((AbSynList) 0); |
| 8246 | if (tfConditions(tf)->conditions == listNil(TfCondElt)((TfCondEltList) 0)) |
| 8247 | return listNil(AbSyn)((AbSynList) 0); |
| 8248 | |
| 8249 | if (DEBUG(tf)tfDebug) { |
| 8250 | TfCondEltList list; |
| 8251 | list = tfConditions(tf)->conditions; |
| 8252 | while (list != listNil(TfCondElt)((TfCondEltList) 0)) { |
| 8253 | afprintf(dbOut, "Condition: %pTForm %pAbSynList\n", tf, car(list)((list)->first)->list); |
| 8254 | list = cdr(list)((list)->rest); |
| 8255 | }; |
| 8256 | } |
| 8257 | return tfConditions(tf)->conditions->first->list; |
| 8258 | } |
| 8259 | |
| 8260 | Stab |
| 8261 | tfConditionalStab(TForm tf) |
| 8262 | { |
| 8263 | if (tfConditions(tf) == NULL((void*)0)) |
| 8264 | return NULL((void*)0); |
| 8265 | if (tfConditions(tf)->containsEmpty) |
| 8266 | return NULL((void*)0); |
| 8267 | |
| 8268 | return tfConditions(tf)->conditions->first->stab; |
| 8269 | } |
| 8270 | |
| 8271 | /****************************************************************************** |
| 8272 | * |
| 8273 | * :: Java |
| 8274 | * |
| 8275 | *****************************************************************************/ |
| 8276 | localstatic Bool tfCheckJavaImport(ErrorSet errors, TForm tf); |
| 8277 | localstatic Bool tfJavaCheckArg(ErrorSet errors, Stab stab, TForm self, TForm arg); |
| 8278 | localstatic Bool abCheckJavaImport(ErrorSet errors, AbSyn ab); |
| 8279 | localstatic Bool abCheckJavaImportId(ErrorSet errors, AbSyn id); |
| 8280 | localstatic Bool abIsJavaImportId(AbSyn id); |
| 8281 | localstatic Bool abIsJavaImportId(AbSyn id); |
| 8282 | |
| 8283 | Bool |
| 8284 | tfIsJavaImport(TForm tf) |
| 8285 | { |
| 8286 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 8287 | |
| 8288 | if (tfIsId(tf)((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Id)) |
| 8289 | return abIsJavaImportId(tfExpr(tf)tfToAbSyn(tf)); |
| 8290 | else if (tfIsApply(tf)((((tf)->tag) == TF_General) && ((((tf)->__absyn ))->abHdr.tag) == AB_Apply) && abIsId(tfExpr(tf)->abApply.op)((tfToAbSyn(tf)->abApply.op)->abHdr.tag == (AB_Id))) { |
| 8291 | return abIsJavaImportId(tfExpr(tf)tfToAbSyn(tf)->abApply.op); |
| 8292 | } |
| 8293 | return false((int) 0); |
| 8294 | } |
| 8295 | |
| 8296 | localstatic Bool |
| 8297 | abIsJavaImportId(AbSyn id) |
| 8298 | { |
| 8299 | Syme syme = abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0); |
| 8300 | if (syme == NULL((void*)0)) |
| 8301 | return false((int) 0); |
| 8302 | return symeIsForeign(syme)(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme)-> lib) : ((void*)0)), (syme))->kind) == SYME_Foreign) && symeForeign(syme)((ForeignOrigin) (SYFI_Foreign < (8 * sizeof(int)) && !(((((syme)->kind == SYME_Trigger ? libGetAllSymes((syme) ->lib) : ((void*)0)), (syme))->hasmask) & (1 << (SYFI_Foreign))) ? (symeFieldInfo[SYFI_Foreign].def) : ((((( syme)->kind == SYME_Trigger ? libGetAllSymes((syme)->lib ) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_Foreign ))) ? ((((((syme)->kind == SYME_Trigger ? libGetAllSymes(( syme)->lib) : ((void*)0)), (syme))->locmask) & (1 << (SYFI_Foreign))) ? ((syme)->fieldv)[symeIndex(syme,SYFI_Foreign )] : (symeFieldInfo[SYFI_Foreign].def)) : symeGetFieldFn(syme ,SYFI_Foreign)))->protocol == FOAM_Proto_Java; |
| 8303 | } |
| 8304 | |
| 8305 | localstatic Bool |
| 8306 | tfCheckJavaImport(ErrorSet errors, TForm tf) |
| 8307 | { |
| 8308 | Syme syme; |
| 8309 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 8310 | |
| 8311 | if (!tfIsGeneral(tf)(((tf)->tag) == TF_General)) |
| 8312 | return false((int) 0); |
| 8313 | |
| 8314 | return abCheckJavaImport(errors, tfExpr(tf)tfToAbSyn(tf)); |
| 8315 | } |
| 8316 | |
| 8317 | localstatic Bool |
| 8318 | abCheckJavaImport(ErrorSet errors, AbSyn ab) |
| 8319 | { |
| 8320 | Bool ret = false((int) 0); |
| 8321 | |
| 8322 | if (abIsId(ab)((ab)->abHdr.tag == (AB_Id))) { |
| 8323 | ret = abCheckJavaImportId(errors, ab); |
| 8324 | } |
| 8325 | else if (abHasTag(ab, AB_Apply)((ab)->abHdr.tag == (AB_Apply))) { |
| 8326 | AbSyn op = ab->abApply.op; |
| 8327 | if (abCheckJavaImportId(errors, op)) { |
| 8328 | int i; |
| 8329 | ret = true1; |
| 8330 | for (i=0; ret && i<abApplyArgc(ab)(((ab)->abHdr.argc)-1); i++) { |
| 8331 | ret = abCheckJavaImport(errors, abApplyArg(ab, i)((ab)->abApply.argv[i])); |
| 8332 | } |
| 8333 | } |
| 8334 | } |
| 8335 | |
| 8336 | return ret; |
| 8337 | } |
| 8338 | |
| 8339 | localstatic Bool |
| 8340 | abCheckJavaImportId(ErrorSet errors, AbSyn id) |
| 8341 | { |
| 8342 | Syme syme = abSyme(id)((id)->abHdr.seman ? (id)->abHdr.seman->syme : 0); |
| 8343 | Bool ret = true1;; |
| 8344 | if (!errorSetPrintf(errors, abIsJavaImportId(id), |
| 8345 | "%pAbSyn is not a valid java type\n", id)) { |
| 8346 | ret = false((int) 0); |
| 8347 | } |
| 8348 | afprintf(dbOut, "CheckJavaImportId: %pAbSyn %d\n", id, ret); |
| 8349 | |
| 8350 | return ret; |
| 8351 | } |
| 8352 | |
| 8353 | Bool |
| 8354 | tfJavaCanExport(Stab stab, TForm self, TForm tf) |
| 8355 | { |
| 8356 | Bool result = true1; |
| 8357 | |
| 8358 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 8359 | |
| 8360 | if (!tfIsMap(tf)(((tf)->tag) == TF_Map)) { |
| 8361 | return false((int) 0); |
| 8362 | } |
| 8363 | ErrorSet errorSink = errorSetNew(); |
| 8364 | tfJavaCheckArgs(errorSink, stab, self, tfMapArg(tf)tfFollowArg(tf, 0)); |
| 8365 | tfJavaCheckArgs(errorSink, stab, self, tfMapRet(tf)tfFollowArg(tf, 1)); |
| 8366 | |
| 8367 | if (errorSetHasErrors(errorSink)) { |
| 8368 | result = false((int) 0); |
| 8369 | } |
| 8370 | errorSetFree(errorSink); |
| 8371 | |
| 8372 | return result; |
| 8373 | } |
| 8374 | |
| 8375 | |
| 8376 | Bool |
| 8377 | tfJavaCheckArgs(ErrorSet errors, Stab stab, TForm self, TForm tf) |
| 8378 | { |
| 8379 | Length argc; |
| 8380 | Bool flg = true1; |
| 8381 | int i; |
| 8382 | |
| 8383 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 8384 | |
| 8385 | tf = tfIgnoreExceptions(tf); |
| 8386 | argc = tfAsMultiArgc(tf); |
| 8387 | for (i=0; i<argc; i++) { |
| 8388 | TForm arg = tfAsMultiArgN(tf, argc, i); |
| 8389 | SymeList sl; |
| 8390 | |
| 8391 | if (!errorSetPrintf(errors, !tfIsNotDomain(arg)((((arg)->tag) == TF_Type) || (((arg)->tag) == TF_With) || ((((arg)->tag) == TF_Syntax) && ((((arg)->__absyn ))->abHdr.tag == (AB_With))) || (((arg)->tag) == TF_Join ) || (((arg)->tag) == TF_If) || (((arg)->tag) == TF_Third )), "Position %d must be a domain", i)) { |
| 8392 | flg = false((int) 0); |
| 8393 | continue; |
| 8394 | } |
| 8395 | flg = flg && tfJavaCheckArg(errors, stab, self, arg); |
| 8396 | } |
| 8397 | |
| 8398 | return flg; |
| 8399 | } |
| 8400 | |
| 8401 | localstatic Bool |
| 8402 | tfJavaCheckArg(ErrorSet errors, Stab stab, TForm self, TForm arg) |
| 8403 | { |
| 8404 | Syme enc, dec; |
| 8405 | Bool flg = true1; |
| 8406 | |
| 8407 | arg = tfIgnoreExceptions(arg); |
| 8408 | |
| 8409 | if (tfIsSelf(arg)(((((arg)->tag) == TF_General) && ((((arg)->__absyn ))->abHdr.tag) == AB_Id) && (((arg)->__absyn)-> abId.sym) == (ssymSelf))) |
| 8410 | return true1; |
| 8411 | if (tfIsJavaImport(arg)) |
| 8412 | return true1; |
| 8413 | if (self && tfEqual(self, arg)) |
| 8414 | return true1; |
| 8415 | if (stabIsForeignExport(stab, arg)) |
| 8416 | return true1; |
| 8417 | |
| 8418 | if (tfHasSelf(arg)((arg)->hasSelf) && tfIsId(arg)((((arg)->tag) == TF_General) && ((((arg)->__absyn ))->abHdr.tag) == AB_Id) && symeExtension(tfIdSyme(arg)((((arg)->__absyn))->abHdr.seman ? (((arg)->__absyn) )->abHdr.seman->syme : 0))) { |
| 8419 | arg = tfFrSyme(stabFile(), symeExtensionFull(tfIdSyme(arg)((((arg)->__absyn))->abHdr.seman ? (((arg)->__absyn) )->abHdr.seman->syme : 0))); |
| 8420 | } |
| 8421 | |
| 8422 | enc = tfGetDomExport(arg, symString(ssymTheToJava)((ssymTheToJava)->str), tfIsJavaEncoder); |
| 8423 | dec = tfGetDomExport(arg, symString(ssymTheFromJava)((ssymTheFromJava)->str), tfIsJavaDecoder); |
| 8424 | if (!errorSetPrintf(errors, dec != NULL((void*)0), "The domain %s must export toJava: %% -> ?", |
| 8425 | abPretty(tfExpr(arg)tfToAbSyn(arg)))) |
| 8426 | flg = false((int) 0); |
| 8427 | if (!errorSetPrintf(errors, enc != NULL((void*)0), "The domain %s must export fromJava: ? -> %%", |
| 8428 | abPretty(tfExpr(arg)tfToAbSyn(arg)))) |
| 8429 | flg = false((int) 0); |
| 8430 | return true1; |
| 8431 | } |
| 8432 | |
| 8433 | |
| 8434 | Bool |
| 8435 | tfIsJavaEncoder(TForm tf) |
| 8436 | { |
| 8437 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 8438 | /* Should be looking for % -> builtin */ |
| 8439 | if (!tfIsMap(tf)(((tf)->tag) == TF_Map)) |
| 8440 | return false((int) 0); |
| 8441 | if (!tfIsSelf(tfMapArg(tf))(((((tfFollowArg(tf, 0))->tag) == TF_General) && ( (((tfFollowArg(tf, 0))->__absyn))->abHdr.tag) == AB_Id) && (((tfFollowArg(tf, 0))->__absyn)->abId.sym) == (ssymSelf))) |
| 8442 | return false((int) 0); |
| 8443 | return true1; |
| 8444 | } |
| 8445 | |
| 8446 | Bool |
| 8447 | tfIsJavaDecoder(TForm tf) |
| 8448 | { |
| 8449 | tfFollow(tf)((tf) = tfFollowFn(tf)); |
| 8450 | |
| 8451 | if (!tfIsMap(tf)(((tf)->tag) == TF_Map)) |
| 8452 | return false((int) 0); |
| 8453 | if (!tfIsSelf(tfMapRet(tf))(((((tfFollowArg(tf, 1))->tag) == TF_General) && ( (((tfFollowArg(tf, 1))->__absyn))->abHdr.tag) == AB_Id) && (((tfFollowArg(tf, 1))->__absyn)->abId.sym) == (ssymSelf))) |
| 8454 | return false((int) 0); |
| 8455 | if (tfMapRetc(tf) != 1) |
| 8456 | return false((int) 0); |
| 8457 | return true1; |
| 8458 | } |
| 8459 | |
| 8460 | /****************************************************************************** |
| 8461 | * |
| 8462 | * :: Table of information about type form tags |
| 8463 | * |
| 8464 | *****************************************************************************/ |
| 8465 | |
| 8466 | #define TF_NARY(-1) (-1) /* Identifies tags with N-ary data argument. */ |
| 8467 | |
| 8468 | struct tform_info tformInfoTable[] = { |
| 8469 | |
| 8470 | /* Special type form symbols */ |
| 8471 | {TF_Unknown, "Unknown", "Unknown", 0, 0}, |
| 8472 | {TF_Exit, "Exit", "Exit", 0, 0}, |
| 8473 | {TF_Literal, "Literal", "Literal", 0, 0}, |
| 8474 | {TF_Test, "Test", "Test", 0, 0}, |
| 8475 | {TF_Type, "Type", "Type", 0, 0}, |
| 8476 | {TF_Category, "Category", "Category", 0, 0}, |
| 8477 | |
| 8478 | /* Type forms described by abstract syntax */ |
| 8479 | {TF_Syntax, "Syntax", "Syntax", 0, 0}, |
| 8480 | {TF_General, "General", "General", 0, 0}, |
| 8481 | |
| 8482 | /* Type forms described by subordinate type forms */ |
| 8483 | {TF_Add, "Add", "Add", 0, 0}, |
| 8484 | {TF_Assign, "Assign", ":=", 0, 1}, |
| 8485 | {TF_Cross, "Cross", "Cross", 0, TF_NARY(-1)}, |
| 8486 | {TF_Declare, "Declare", ":", 0, 1}, |
| 8487 | {TF_Default, "Default", "==", 0, 2}, |
| 8488 | {TF_Define, "Define", "==", 0, 2}, |
| 8489 | {TF_Enumerate, "Enumeration", "Enumeration", 0, 1}, |
| 8490 | {TF_Forward, "Forward", "Forward", 0, 1}, |
| 8491 | {TF_Generator, "Generator", "Generator", 0, 1}, |
| 8492 | {TF_If, "If", "If", 0, 3}, |
| 8493 | {TF_Instance, "Instance", "Instance", 0, 2}, |
| 8494 | {TF_Join, "Join", "Join", 0, TF_NARY(-1)}, |
| 8495 | {TF_Map, "Map", "->", 0, 2}, |
| 8496 | {TF_Meet, "Meet", "Meet", 0, TF_NARY(-1)}, |
| 8497 | {TF_Multiple, "Multiple", "Multiple", 0, TF_NARY(-1)}, |
| 8498 | {TF_PackedMap, "PackedMap", "->*", 0, 2}, |
| 8499 | {TF_Raw, "Raw", "Raw", 0, 1}, |
| 8500 | {TF_RawRecord, "RawRecord", "RawRecord", 0, 0}, |
| 8501 | {TF_Record, "Record", "Record", 0, 0}, |
| 8502 | {TF_Reference, "Reference", "Ref", 0, 1}, |
| 8503 | {TF_Subst, "Subst", "Subst", 0, 1}, |
| 8504 | {TF_Third, "Third", "Third", 0, 2}, |
| 8505 | {TF_Trigger, "Trigger", "Trigger", 0, 1}, |
| 8506 | {TF_TrailingArray,"TrailingArray", "TrailingArray",0, 1}, |
| 8507 | {TF_Tuple, "Tuple", "Tuple", 0, 1}, |
| 8508 | {TF_Union, "Union", "Union", 0, 0}, |
| 8509 | {TF_Variable, "Variable", "Variable", 0, 1}, |
| 8510 | {TF_With, "With", "With", 0, 2}, |
| 8511 | {TF_Except, "Except", "Except", 0, 2}, |
| 8512 | {TF_XGenerator, "XGenerator", "XGenerator", 0, 1}, |
| 8513 | |
| 8514 | {TF_LIMIT, "LIMIT", "LIMIT", 0, 0} |
| 8515 | }; |