00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define _MODULUTL_SOURCE_
00025
00026 #include "setup.h"
00027
00028 #include "memalloc.h"
00029 #include "router.h"
00030 #include "envrnmnt.h"
00031 #include "sysdep.h"
00032
00033 #include "modulpsr.h"
00034 #include "modulutl.h"
00035
00036
00037
00038
00039
00040 static void *SearchImportedConstructModules(void *,struct symbolHashNode *,
00041 struct defmodule *,
00042 struct moduleItem *,struct symbolHashNode *,
00043 int *,int,struct defmodule *);
00044
00045
00046
00047
00048
00049
00050
00051 globle unsigned FindModuleSeparator(
00052 char *theString)
00053 {
00054 unsigned i, foundColon;
00055
00056 for (i = 0, foundColon = FALSE; theString[i] != EOS; i++)
00057 {
00058 if (theString[i] == ':')
00059 {
00060 if (foundColon) return(i);
00061 foundColon = TRUE;
00062 }
00063 else
00064 { foundColon = FALSE; }
00065 }
00066
00067 return(FALSE);
00068 }
00069
00070
00071
00072
00073
00074
00075
00076 globle SYMBOL_HN *ExtractModuleName(
00077 void *theEnv,
00078 unsigned thePosition,
00079 char *theString)
00080 {
00081 char *newString;
00082 SYMBOL_HN *returnValue;
00083
00084
00085
00086
00087
00088
00089 if (thePosition <= 1) return(NULL);
00090
00091
00092
00093
00094
00095 newString = (char *) gm2(theEnv,thePosition);
00096
00097
00098
00099
00100
00101 genstrncpy(newString,theString,
00102 (STD_SIZE) thePosition - 1);
00103
00104
00105
00106
00107
00108 newString[thePosition-1] = EOS;
00109
00110
00111
00112
00113
00114
00115 returnValue = (SYMBOL_HN *) EnvAddSymbol(theEnv,newString);
00116
00117
00118
00119
00120
00121 rm(theEnv,newString,thePosition);
00122
00123
00124
00125
00126
00127 return(returnValue);
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 globle SYMBOL_HN *ExtractConstructName(
00137 void *theEnv,
00138 unsigned thePosition,
00139 char *theString)
00140 {
00141 size_t theLength;
00142 char *newString;
00143 SYMBOL_HN *returnValue;
00144
00145
00146
00147
00148
00149
00150 if (thePosition == 0) return((SYMBOL_HN *) EnvAddSymbol(theEnv,theString));
00151
00152
00153
00154
00155
00156 theLength = strlen(theString);
00157
00158
00159
00160
00161
00162
00163 if (theLength <= (thePosition + 1)) return(NULL);
00164
00165
00166
00167
00168
00169
00170 newString = (char *) gm2(theEnv,theLength - thePosition);
00171
00172
00173
00174
00175
00176
00177 genstrncpy(newString,&theString[thePosition+1],
00178 (STD_SIZE) theLength - thePosition);
00179
00180
00181
00182
00183
00184 returnValue = (SYMBOL_HN *) EnvAddSymbol(theEnv,newString);
00185
00186
00187
00188
00189
00190 rm(theEnv,newString,theLength - thePosition);
00191
00192
00193
00194
00195
00196 return(returnValue);
00197 }
00198
00199
00200
00201
00202
00203
00204 globle char *ExtractModuleAndConstructName(
00205 void *theEnv,
00206 char *theName)
00207 {
00208 unsigned separatorPosition;
00209 SYMBOL_HN *moduleName, *shortName;
00210 struct defmodule *theModule;
00211
00212
00213
00214
00215
00216 separatorPosition = FindModuleSeparator(theName);
00217 if (! separatorPosition) return(theName);
00218
00219
00220
00221
00222
00223 moduleName = ExtractModuleName(theEnv,separatorPosition,theName);
00224 if (moduleName == NULL) return(NULL);
00225
00226
00227
00228
00229
00230 theModule = (struct defmodule *) EnvFindDefmodule(theEnv,ValueToString(moduleName));
00231 if (theModule == NULL) return(NULL);
00232
00233
00234
00235
00236
00237 EnvSetCurrentModule(theEnv,(void *) theModule);
00238
00239
00240
00241
00242
00243 shortName = ExtractConstructName(theEnv,separatorPosition,theName);
00244 if (shortName == NULL) return(NULL);
00245 return(ValueToString(shortName));
00246 }
00247
00248
00249
00250
00251
00252
00253 globle void *FindImportedConstruct(
00254 void *theEnv,
00255 char *constructName,
00256 struct defmodule *matchModule,
00257 char *findName,
00258 int *count,
00259 int searchCurrent,
00260 struct defmodule *notYetDefinedInModule)
00261 {
00262 void *rv;
00263 struct moduleItem *theModuleItem;
00264
00265
00266
00267
00268
00269 *count = 0;
00270
00271
00272
00273
00274
00275
00276 if (FindModuleSeparator(findName)) return(NULL);
00277
00278
00279
00280
00281
00282
00283
00284 SaveCurrentModule(theEnv);
00285
00286
00287
00288
00289
00290
00291 if ((theModuleItem = FindModuleItem(theEnv,constructName)) == NULL)
00292 {
00293 RestoreCurrentModule(theEnv);
00294 return(NULL);
00295 }
00296
00297
00298
00299
00300
00301
00302 if (theModuleItem->findFunction == NULL)
00303 {
00304 RestoreCurrentModule(theEnv);
00305 return(NULL);
00306 }
00307
00308
00309
00310
00311
00312
00313 MarkModulesAsUnvisited(theEnv);
00314
00315
00316
00317
00318
00319 rv = SearchImportedConstructModules(theEnv,(SYMBOL_HN *) EnvAddSymbol(theEnv,constructName),
00320 matchModule,theModuleItem,
00321 (SYMBOL_HN *) EnvAddSymbol(theEnv,findName),count,
00322 searchCurrent,notYetDefinedInModule);
00323
00324
00325
00326
00327
00328 RestoreCurrentModule(theEnv);
00329
00330
00331
00332
00333
00334 return(rv);
00335 }
00336
00337
00338
00339
00340
00341
00342 globle void AmbiguousReferenceErrorMessage(
00343 void *theEnv,
00344 char *constructName,
00345 char *findName)
00346 {
00347 EnvPrintRouter(theEnv,WERROR,"Ambiguous reference to ");
00348 EnvPrintRouter(theEnv,WERROR,constructName);
00349 EnvPrintRouter(theEnv,WERROR," ");
00350 EnvPrintRouter(theEnv,WERROR,findName);
00351 EnvPrintRouter(theEnv,WERROR,".\nIt is imported from more than one module.\n");
00352 }
00353
00354
00355
00356
00357
00358
00359 globle void MarkModulesAsUnvisited(
00360 void *theEnv)
00361 {
00362 struct defmodule *theModule;
00363
00364 DefmoduleData(theEnv)->CurrentModule->visitedFlag = FALSE;
00365 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00366 theModule != NULL;
00367 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00368 { theModule->visitedFlag = FALSE; }
00369 }
00370
00371
00372
00373
00374
00375
00376 static void *SearchImportedConstructModules(
00377 void *theEnv,
00378 struct symbolHashNode *constructType,
00379 struct defmodule *matchModule,
00380 struct moduleItem *theModuleItem,
00381 struct symbolHashNode *findName,
00382 int *count,
00383 int searchCurrent,
00384 struct defmodule *notYetDefinedInModule)
00385 {
00386 struct defmodule *theModule;
00387 struct portItem *theImportList, *theExportList;
00388 void *rv, *arv = NULL;
00389 int searchModule, exported;
00390 struct defmodule *currentModule;
00391
00392
00393
00394
00395
00396
00397
00398 currentModule = ((struct defmodule *) EnvGetCurrentModule(theEnv));
00399 if (currentModule->visitedFlag) return(NULL);
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 if ((searchCurrent) &&
00410 ((matchModule == NULL) || (currentModule == matchModule)))
00411 {
00412
00413
00414
00415
00416 rv = (*theModuleItem->findFunction)(theEnv,ValueToString(findName));
00417
00418
00419
00420
00421
00422
00423
00424
00425 if (notYetDefinedInModule == currentModule)
00426 {
00427 (*count)++;
00428 arv = rv;
00429 }
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439 else if (rv != NULL)
00440 {
00441 if (((struct constructHeader *) rv)->whichModule->theModule == currentModule)
00442 { (*count)++; }
00443 arv = rv;
00444 }
00445 }
00446
00447
00448
00449
00450
00451 currentModule->visitedFlag = TRUE;
00452
00453
00454
00455
00456
00457
00458 theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv));
00459 theImportList = theModule->importList;
00460
00461 while (theImportList != NULL)
00462 {
00463
00464
00465
00466
00467
00468
00469
00470 searchModule = FALSE;
00471 if ((theImportList->constructType == NULL) ||
00472 (theImportList->constructType == constructType))
00473 {
00474 if ((theImportList->constructName == NULL) ||
00475 (theImportList->constructName == findName))
00476 { searchModule = TRUE; }
00477 }
00478
00479
00480
00481
00482
00483 if (searchModule)
00484 {
00485 theModule = (struct defmodule *)
00486 EnvFindDefmodule(theEnv,ValueToString(theImportList->moduleName));
00487 if (theModule == NULL) searchModule = FALSE;
00488 }
00489
00490
00491
00492
00493
00494 if (searchModule)
00495 {
00496 exported = FALSE;
00497 theExportList = theModule->exportList;
00498 while ((theExportList != NULL) && (! exported))
00499 {
00500 if ((theExportList->constructType == NULL) ||
00501 (theExportList->constructType == constructType))
00502 {
00503 if ((theExportList->constructName == NULL) ||
00504 (theExportList->constructName == findName))
00505 { exported = TRUE; }
00506 }
00507
00508 theExportList = theExportList->next;
00509 }
00510
00511 if (! exported) searchModule = FALSE;
00512 }
00513
00514
00515
00516
00517
00518 if (searchModule)
00519 {
00520 EnvSetCurrentModule(theEnv,(void *) theModule);
00521 if ((rv = SearchImportedConstructModules(theEnv,constructType,matchModule,
00522 theModuleItem,findName,
00523 count,TRUE,
00524 notYetDefinedInModule)) != NULL)
00525 { arv = rv; }
00526 }
00527
00528
00529
00530
00531
00532 theImportList = theImportList->next;
00533 }
00534
00535
00536
00537
00538
00539
00540 return(arv);
00541 }
00542
00543
00544
00545
00546
00547 globle intBool ConstructExported(
00548 void *theEnv,
00549 char *constructTypeStr,
00550 struct symbolHashNode *moduleName,
00551 struct symbolHashNode *findName)
00552 {
00553 struct symbolHashNode *constructType;
00554 struct defmodule *theModule;
00555 struct portItem *theExportList;
00556
00557 constructType = FindSymbolHN(theEnv,constructTypeStr);
00558 theModule = (struct defmodule *) EnvFindDefmodule(theEnv,ValueToString(moduleName));
00559
00560 if ((constructType == NULL) || (theModule == NULL) || (findName == NULL))
00561 { return(FALSE); }
00562
00563 theExportList = theModule->exportList;
00564 while (theExportList != NULL)
00565 {
00566 if ((theExportList->constructType == NULL) ||
00567 (theExportList->constructType == constructType))
00568 {
00569 if ((theExportList->constructName == NULL) ||
00570 (theExportList->constructName == findName))
00571 { return TRUE; }
00572 }
00573
00574 theExportList = theExportList->next;
00575 }
00576
00577 return FALSE;
00578 }
00579
00580
00581
00582
00583
00584
00585
00586
00587 globle void ListItemsDriver(
00588 void *theEnv,
00589 char *logicalName,
00590 struct defmodule *theModule,
00591 char *singleName,
00592 char *pluralName,
00593 void *(*nextFunction)(void *,void *),
00594 char *(*nameFunction)(void *),
00595 void (*printFunction)(void *,char *,void *),
00596 int (*doItFunction)(void *,void *))
00597 {
00598 void *constructPtr;
00599 char *constructName;
00600 long count = 0;
00601 int allModules = FALSE;
00602 int doIt;
00603
00604
00605
00606
00607
00608 SaveCurrentModule(theEnv);
00609
00610
00611
00612
00613
00614 if (theModule == NULL)
00615 {
00616 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00617 allModules = TRUE;
00618 }
00619
00620 while (theModule != NULL)
00621 {
00622 if (allModules)
00623 {
00624 EnvPrintRouter(theEnv,logicalName,EnvGetDefmoduleName(theEnv,theModule));
00625 EnvPrintRouter(theEnv,logicalName,":\n");
00626 }
00627
00628 EnvSetCurrentModule(theEnv,(void *) theModule);
00629 constructPtr = (*nextFunction)(theEnv,NULL);
00630 while (constructPtr != NULL)
00631 {
00632 if (EvaluationData(theEnv)->HaltExecution == TRUE) return;
00633
00634 if (doItFunction == NULL) doIt = TRUE;
00635 else doIt = (*doItFunction)(theEnv,constructPtr);
00636
00637 if (! doIt) {}
00638 else if (nameFunction != NULL)
00639 {
00640 constructName = (*nameFunction)(constructPtr);
00641 if (constructName != NULL)
00642 {
00643 if (allModules) EnvPrintRouter(theEnv,logicalName," ");
00644 EnvPrintRouter(theEnv,logicalName,constructName);
00645 EnvPrintRouter(theEnv,logicalName,"\n");
00646 }
00647 }
00648 else if (printFunction != NULL)
00649 {
00650 if (allModules) EnvPrintRouter(theEnv,logicalName," ");
00651 (*printFunction)(theEnv,logicalName,constructPtr);
00652 EnvPrintRouter(theEnv,logicalName,"\n");
00653 }
00654
00655 constructPtr = (*nextFunction)(theEnv,constructPtr);
00656 count++;
00657 }
00658
00659 if (allModules) theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule);
00660 else theModule = NULL;
00661 }
00662
00663
00664
00665
00666
00667 if (singleName != NULL) PrintTally(theEnv,logicalName,count,singleName,pluralName);
00668
00669 RestoreCurrentModule(theEnv);
00670 }
00671
00672
00673
00674
00675 globle long DoForAllModules(
00676 void *theEnv,
00677 void (*actionFunction)(struct defmodule *,void *),
00678 int interruptable,
00679 void *userBuffer)
00680 {
00681 void *theModule;
00682 long moduleCount = 0L;
00683
00684
00685
00686
00687
00688 SaveCurrentModule(theEnv);
00689
00690
00691
00692
00693
00694 for (theModule = EnvGetNextDefmodule(theEnv,NULL);
00695 theModule != NULL;
00696 theModule = EnvGetNextDefmodule(theEnv,theModule), moduleCount++)
00697 {
00698 EnvSetCurrentModule(theEnv,(void *) theModule);
00699
00700 if ((interruptable) && GetHaltExecution(theEnv))
00701 {
00702 RestoreCurrentModule(theEnv);
00703 return(-1L);
00704 }
00705
00706 (*actionFunction)((struct defmodule *) theModule,userBuffer);
00707 }
00708
00709
00710
00711
00712
00713 RestoreCurrentModule(theEnv);
00714
00715
00716
00717
00718
00719 return(moduleCount);
00720 }
00721
00722
00723