00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #define _CSTRCPSR_SOURCE_
00031
00032 #include "setup.h"
00033
00034 #if (! RUN_TIME) && (! BLOAD_ONLY)
00035
00036 #include <stdio.h>
00037 #define _STDIO_INCLUDED_
00038 #include <stdlib.h>
00039
00040 #include "envrnmnt.h"
00041 #include "router.h"
00042 #include "watch.h"
00043 #include "constrct.h"
00044 #include "prcdrpsr.h"
00045 #include "exprnpsr.h"
00046 #include "modulutl.h"
00047 #include "modulpsr.h"
00048 #include "sysdep.h"
00049 #include "utility.h"
00050
00051 #include "cstrcpsr.h"
00052
00053
00054
00055
00056
00057 static int FindConstructBeginning(void *,char *,struct token *,int,int *);
00058
00059
00060
00061
00062 #if ALLOW_ENVIRONMENT_GLOBALS
00063 globle int Load(
00064 char *fileName)
00065 {
00066 return EnvLoad(GetCurrentEnvironment(),fileName);
00067 }
00068 #endif
00069
00070
00071
00072
00073
00074
00075
00076
00077 globle int EnvLoad(
00078 void *theEnv,
00079 char *fileName)
00080 {
00081 FILE *theFile;
00082 int noErrorsDetected;
00083
00084
00085
00086
00087
00088 if ((theFile = GenOpen(theEnv,fileName,"r")) == NULL) return(0);
00089
00090
00091
00092
00093
00094
00095
00096 SetFastLoad(theEnv,theFile);
00097 noErrorsDetected = LoadConstructsFromLogicalName(theEnv,(char *) theFile);
00098 SetFastLoad(theEnv,NULL);
00099
00100
00101
00102
00103
00104 GenClose(theEnv,theFile);
00105
00106
00107
00108
00109
00110
00111 if (noErrorsDetected) return(1);
00112
00113 return(-1);
00114 }
00115
00116
00117
00118
00119
00120 globle int LoadConstructsFromLogicalName(
00121 void *theEnv,
00122 char *readSource)
00123 {
00124 int constructFlag;
00125 struct token theToken;
00126 int noErrors = TRUE;
00127 int foundConstruct;
00128
00129
00130
00131
00132
00133
00134 if (EvaluationData(theEnv)->CurrentEvaluationDepth == 0) SetHaltExecution(theEnv,FALSE);
00135 SetEvaluationError(theEnv,FALSE);
00136
00137
00138
00139
00140
00141 EvaluationData(theEnv)->CurrentEvaluationDepth++;
00142 GetToken(theEnv,readSource,&theToken);
00143 foundConstruct = FindConstructBeginning(theEnv,readSource,&theToken,FALSE,&noErrors);
00144
00145
00146
00147
00148
00149 while ((foundConstruct == TRUE) && (GetHaltExecution(theEnv) == FALSE))
00150 {
00151
00152
00153
00154
00155 FlushPPBuffer(theEnv);
00156
00157
00158
00159
00160
00161 constructFlag = ParseConstruct(theEnv,ValueToString(theToken.value),readSource);
00162
00163
00164
00165
00166
00167
00168
00169
00170 if (constructFlag == 1)
00171 {
00172 EnvPrintRouter(theEnv,WERROR,"\nERROR:\n");
00173 PrintInChunks(theEnv,WERROR,GetPPBuffer(theEnv));
00174 EnvPrintRouter(theEnv,WERROR,"\n");
00175 noErrors = FALSE;
00176 GetToken(theEnv,readSource,&theToken);
00177 foundConstruct = FindConstructBeginning(theEnv,readSource,&theToken,TRUE,&noErrors);
00178 }
00179
00180
00181
00182
00183
00184 else
00185 {
00186 GetToken(theEnv,readSource,&theToken);
00187 foundConstruct = FindConstructBeginning(theEnv,readSource,&theToken,FALSE,&noErrors);
00188 }
00189
00190
00191
00192
00193
00194 if (foundConstruct)
00195 { IncrementSymbolCount(theToken.value); }
00196 EvaluationData(theEnv)->CurrentEvaluationDepth--;
00197 PeriodicCleanup(theEnv,FALSE,TRUE);
00198 YieldTime(theEnv);
00199 EvaluationData(theEnv)->CurrentEvaluationDepth++;
00200 if (foundConstruct)
00201 { DecrementSymbolCount(theEnv,(SYMBOL_HN *) theToken.value); }
00202 }
00203
00204 EvaluationData(theEnv)->CurrentEvaluationDepth--;
00205
00206
00207
00208
00209
00210
00211 #if DEBUGGING_FUNCTIONS
00212 if ((EnvGetWatchItem(theEnv,"compilations") != TRUE) && GetPrintWhileLoading(theEnv))
00213 #else
00214 if (GetPrintWhileLoading(theEnv))
00215 #endif
00216 { EnvPrintRouter(theEnv,WDIALOG,"\n"); }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 DestroyPPBuffer(theEnv);
00227
00228
00229
00230
00231
00232
00233 return(noErrors);
00234 }
00235
00236
00237
00238
00239
00240
00241
00242 static int FindConstructBeginning(
00243 void *theEnv,
00244 char *readSource,
00245 struct token *theToken,
00246 int errorCorrection,
00247 int *noErrors)
00248 {
00249 int leftParenthesisFound = FALSE;
00250 int firstAttempt = TRUE;
00251
00252
00253
00254
00255
00256
00257 while (theToken->type != STOP)
00258 {
00259
00260
00261
00262
00263
00264 if (theToken->type == LPAREN)
00265 { leftParenthesisFound = TRUE; }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 else if ((theToken->type == SYMBOL) && (leftParenthesisFound == TRUE))
00277 {
00278
00279
00280
00281
00282 if (FindConstruct(theEnv,ValueToString(theToken->value)) != NULL) return(TRUE);
00283
00284
00285
00286
00287
00288
00289 if (firstAttempt && (! errorCorrection))
00290 {
00291 errorCorrection = TRUE;
00292 *noErrors = FALSE;
00293 PrintErrorID(theEnv,"CSTRCPSR",1,TRUE);
00294 EnvPrintRouter(theEnv,WERROR,"Expected the beginning of a construct.\n");
00295 }
00296
00297
00298
00299
00300
00301
00302 firstAttempt = FALSE;
00303 leftParenthesisFound = FALSE;
00304 }
00305
00306
00307
00308
00309
00310
00311
00312
00313 else
00314 {
00315 if (firstAttempt && (! errorCorrection))
00316 {
00317 errorCorrection = TRUE;
00318 *noErrors = FALSE;
00319 PrintErrorID(theEnv,"CSTRCPSR",1,TRUE);
00320 EnvPrintRouter(theEnv,WERROR,"Expected the beginning of a construct.\n");
00321 }
00322
00323 firstAttempt = FALSE;
00324 leftParenthesisFound = FALSE;
00325 }
00326
00327
00328
00329
00330
00331 GetToken(theEnv,readSource,theToken);
00332 }
00333
00334
00335
00336
00337
00338 return(FALSE);
00339 }
00340
00341
00342
00343
00344
00345
00346
00347 globle int ParseConstruct(
00348 void *theEnv,
00349 char *name,
00350 char *logicalName)
00351 {
00352 struct construct *currentPtr;
00353 int rv, ov;
00354
00355
00356
00357
00358
00359
00360 currentPtr = FindConstruct(theEnv,name);
00361 if (currentPtr == NULL) return(-1);
00362
00363
00364
00365
00366
00367 ov = GetHaltExecution(theEnv);
00368 SetEvaluationError(theEnv,FALSE);
00369 SetHaltExecution(theEnv,FALSE);
00370 ClearParsedBindNames(theEnv);
00371 PushRtnBrkContexts(theEnv);
00372 ExpressionData(theEnv)->ReturnContext = FALSE;
00373 ExpressionData(theEnv)->BreakContext = FALSE;
00374 EvaluationData(theEnv)->CurrentEvaluationDepth++;
00375
00376
00377
00378
00379
00380 ConstructData(theEnv)->ParsingConstruct = TRUE;
00381 rv = (*currentPtr->parseFunction)(theEnv,logicalName);
00382 ConstructData(theEnv)->ParsingConstruct = FALSE;
00383
00384
00385
00386
00387
00388 EvaluationData(theEnv)->CurrentEvaluationDepth--;
00389 PopRtnBrkContexts(theEnv);
00390
00391 ClearParsedBindNames(theEnv);
00392 SetPPBufferStatus(theEnv,OFF);
00393 SetHaltExecution(theEnv,ov);
00394
00395
00396
00397
00398
00399
00400 return(rv);
00401 }
00402
00403
00404
00405
00406
00407
00408 #if WIN_BTC && (! DEBUGGING_FUNCTIONS)
00409 #pragma argsused
00410 #endif
00411 globle SYMBOL_HN *GetConstructNameAndComment(
00412 void *theEnv,
00413 char *readSource,
00414 struct token *inputToken,
00415 char *constructName,
00416 void *(*findFunction)(void *,char *),
00417 int (*deleteFunction)(void *,void *),
00418 char *constructSymbol,
00419 int fullMessageCR,
00420 int getComment,
00421 int moduleNameAllowed)
00422 {
00423 #if (MAC_MCW || WIN_MCW || MAC_XCD) && (! DEBUGGING_FUNCTIONS)
00424 #pragma unused(fullMessageCR)
00425 #endif
00426 SYMBOL_HN *name, *moduleName;
00427 int redefining = FALSE;
00428 void *theConstruct;
00429 unsigned separatorPosition;
00430 struct defmodule *theModule;
00431
00432
00433
00434
00435
00436
00437 GetToken(theEnv,readSource,inputToken);
00438 if (inputToken->type != SYMBOL)
00439 {
00440 PrintErrorID(theEnv,"CSTRCPSR",2,TRUE);
00441 EnvPrintRouter(theEnv,WERROR,"Missing name for ");
00442 EnvPrintRouter(theEnv,WERROR,constructName);
00443 EnvPrintRouter(theEnv,WERROR," construct\n");
00444 return(NULL);
00445 }
00446
00447 name = (SYMBOL_HN *) inputToken->value;
00448
00449
00450
00451
00452
00453 separatorPosition = FindModuleSeparator(ValueToString(name));
00454 if (separatorPosition)
00455 {
00456 if (moduleNameAllowed == FALSE)
00457 {
00458 SyntaxErrorMessage(theEnv,"module specifier");
00459 return(NULL);
00460 }
00461
00462 moduleName = ExtractModuleName(theEnv,separatorPosition,ValueToString(name));
00463 if (moduleName == NULL)
00464 {
00465 SyntaxErrorMessage(theEnv,"construct name");
00466 return(NULL);
00467 }
00468
00469 theModule = (struct defmodule *) EnvFindDefmodule(theEnv,ValueToString(moduleName));
00470 if (theModule == NULL)
00471 {
00472 CantFindItemErrorMessage(theEnv,"defmodule",ValueToString(moduleName));
00473 return(NULL);
00474 }
00475
00476 EnvSetCurrentModule(theEnv,(void *) theModule);
00477 name = ExtractConstructName(theEnv,separatorPosition,ValueToString(name));
00478 if (name == NULL)
00479 {
00480 SyntaxErrorMessage(theEnv,"construct name");
00481 return(NULL);
00482 }
00483 }
00484
00485
00486
00487
00488
00489
00490 else
00491 {
00492 theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv));
00493 if (moduleNameAllowed)
00494 {
00495 PPBackup(theEnv);
00496 SavePPBuffer(theEnv,EnvGetDefmoduleName(theEnv,theModule));
00497 SavePPBuffer(theEnv,"::");
00498 SavePPBuffer(theEnv,ValueToString(name));
00499 }
00500 }
00501
00502
00503
00504
00505
00506 #if DEFMODULE_CONSTRUCT
00507 if (FindImportExportConflict(theEnv,constructName,theModule,ValueToString(name)))
00508 {
00509 ImportExportConflictMessage(theEnv,constructName,ValueToString(name),NULL,NULL);
00510 return(NULL);
00511 }
00512 #endif
00513
00514
00515
00516
00517
00518
00519 if ((findFunction != NULL) && (! ConstructData(theEnv)->CheckSyntaxMode))
00520 {
00521 theConstruct = (*findFunction)(theEnv,ValueToString(name));
00522 if (theConstruct != NULL)
00523 {
00524 redefining = TRUE;
00525 if (deleteFunction != NULL)
00526 {
00527 if ((*deleteFunction)(theEnv,theConstruct) == FALSE)
00528 {
00529 PrintErrorID(theEnv,"CSTRCPSR",4,TRUE);
00530 EnvPrintRouter(theEnv,WERROR,"Cannot redefine ");
00531 EnvPrintRouter(theEnv,WERROR,constructName);
00532 EnvPrintRouter(theEnv,WERROR," ");
00533 EnvPrintRouter(theEnv,WERROR,ValueToString(name));
00534 EnvPrintRouter(theEnv,WERROR," while it is in use.\n");
00535 return(NULL);
00536 }
00537 }
00538 }
00539 }
00540
00541
00542
00543
00544
00545
00546 #if DEBUGGING_FUNCTIONS
00547 if ((EnvGetWatchItem(theEnv,"compilations") == TRUE) &&
00548 GetPrintWhileLoading(theEnv) && (! ConstructData(theEnv)->CheckSyntaxMode))
00549 {
00550 if (redefining)
00551 {
00552 PrintWarningID(theEnv,"CSTRCPSR",1,TRUE);
00553 EnvPrintRouter(theEnv,WDIALOG,"Redefining ");
00554 }
00555 else EnvPrintRouter(theEnv,WDIALOG,"Defining ");
00556
00557 EnvPrintRouter(theEnv,WDIALOG,constructName);
00558 EnvPrintRouter(theEnv,WDIALOG,": ");
00559 EnvPrintRouter(theEnv,WDIALOG,ValueToString(name));
00560
00561 if (fullMessageCR) EnvPrintRouter(theEnv,WDIALOG,"\n");
00562 else EnvPrintRouter(theEnv,WDIALOG," ");
00563 }
00564 else
00565 #endif
00566 {
00567 if (GetPrintWhileLoading(theEnv) && (! ConstructData(theEnv)->CheckSyntaxMode))
00568 { EnvPrintRouter(theEnv,WDIALOG,constructSymbol); }
00569 }
00570
00571
00572
00573
00574
00575 GetToken(theEnv,readSource,inputToken);
00576 if ((inputToken->type == STRING) && getComment)
00577 {
00578 PPBackup(theEnv);
00579 SavePPBuffer(theEnv," ");
00580 SavePPBuffer(theEnv,inputToken->printForm);
00581 GetToken(theEnv,readSource,inputToken);
00582 if (inputToken->type != RPAREN)
00583 {
00584 PPBackup(theEnv);
00585 SavePPBuffer(theEnv,"\n ");
00586 SavePPBuffer(theEnv,inputToken->printForm);
00587 }
00588 }
00589 else if (inputToken->type != RPAREN)
00590 {
00591 PPBackup(theEnv);
00592 SavePPBuffer(theEnv,"\n ");
00593 SavePPBuffer(theEnv,inputToken->printForm);
00594 }
00595
00596
00597
00598
00599
00600 return(name);
00601 }
00602
00603
00604
00605
00606
00607 globle void RemoveConstructFromModule(
00608 void *theEnv,
00609 struct constructHeader *theConstruct)
00610 {
00611 struct constructHeader *lastConstruct,*currentConstruct;
00612
00613
00614
00615
00616
00617
00618 lastConstruct = NULL;
00619 currentConstruct = theConstruct->whichModule->firstItem;
00620 while (currentConstruct != theConstruct)
00621 {
00622 lastConstruct = currentConstruct;
00623 currentConstruct = currentConstruct->next;
00624 }
00625
00626
00627
00628
00629
00630 if (currentConstruct == NULL)
00631 {
00632 SystemError(theEnv,"CSTRCPSR",1);
00633 EnvExitRouter(theEnv,EXIT_FAILURE);
00634 }
00635
00636
00637
00638
00639
00640 if (lastConstruct == NULL)
00641 { theConstruct->whichModule->firstItem = theConstruct->next; }
00642 else
00643 { lastConstruct->next = theConstruct->next; }
00644
00645
00646
00647
00648
00649
00650 if (theConstruct == theConstruct->whichModule->lastItem)
00651 { theConstruct->whichModule->lastItem = lastConstruct; }
00652 }
00653
00654
00655
00656
00657
00658
00659 globle void ImportExportConflictMessage(
00660 void *theEnv,
00661 char *constructName,
00662 char *itemName,
00663 char *causedByConstruct,
00664 char *causedByName)
00665 {
00666 PrintErrorID(theEnv,"CSTRCPSR",3,TRUE);
00667 EnvPrintRouter(theEnv,WERROR,"Cannot define ");
00668 EnvPrintRouter(theEnv,WERROR,constructName);
00669 EnvPrintRouter(theEnv,WERROR," ");
00670 EnvPrintRouter(theEnv,WERROR,itemName);
00671 EnvPrintRouter(theEnv,WERROR," because of an import/export conflict");
00672
00673 if (causedByConstruct == NULL) EnvPrintRouter(theEnv,WERROR,".\n");
00674 else
00675 {
00676 EnvPrintRouter(theEnv,WERROR," caused by the ");
00677 EnvPrintRouter(theEnv,WERROR,causedByConstruct);
00678 EnvPrintRouter(theEnv,WERROR," ");
00679 EnvPrintRouter(theEnv,WERROR,causedByName);
00680 EnvPrintRouter(theEnv,WERROR,".\n");
00681 }
00682 }
00683
00684 #endif
00685
00686