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 #define _GLOBLPSR_SOURCE_
00028
00029 #include "setup.h"
00030
00031 #if DEFGLOBAL_CONSTRUCT
00032
00033 #include <string.h>
00034
00035 #include "pprint.h"
00036 #include "router.h"
00037 #include "memalloc.h"
00038 #include "scanner.h"
00039 #include "evaluatn.h"
00040 #include "exprnpsr.h"
00041 #include "constrct.h"
00042 #include "multifld.h"
00043 #include "watch.h"
00044 #include "modulutl.h"
00045 #include "modulpsr.h"
00046 #include "cstrcpsr.h"
00047 #include "globldef.h"
00048 #include "globlbsc.h"
00049 #include "envrnmnt.h"
00050
00051 #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
00052 #include "bload.h"
00053 #endif
00054
00055 #include "globlpsr.h"
00056
00057
00058
00059
00060
00061 #if (! RUN_TIME) && (! BLOAD_ONLY)
00062 static intBool GetVariableDefinition(void *,char *,int *,int,struct token *);
00063 static void AddDefglobal(void *,SYMBOL_HN *,DATA_OBJECT_PTR,struct expr *);
00064 #endif
00065
00066
00067
00068
00069
00070 globle intBool ParseDefglobal(
00071 void *theEnv,
00072 char *readSource)
00073 {
00074 int defglobalError = FALSE;
00075 #if (MAC_MCW || WIN_MCW) && (RUN_TIME || BLOAD_ONLY)
00076 #pragma unused(theEnv,readSource)
00077 #endif
00078
00079 #if (! RUN_TIME) && (! BLOAD_ONLY)
00080
00081 struct token theToken;
00082 int tokenRead = TRUE;
00083 struct defmodule *theModule;
00084
00085
00086
00087
00088
00089 SetPPBufferStatus(theEnv,ON);
00090 FlushPPBuffer(theEnv);
00091 SetIndentDepth(theEnv,3);
00092 SavePPBuffer(theEnv,"(defglobal ");
00093
00094
00095
00096
00097
00098
00099 #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
00100 if ((Bloaded(theEnv) == TRUE) && (! ConstructData(theEnv)->CheckSyntaxMode))
00101 {
00102 CannotLoadWithBloadMessage(theEnv,"defglobal");
00103 return(TRUE);
00104 }
00105 #endif
00106
00107
00108
00109
00110
00111 GetToken(theEnv,readSource,&theToken);
00112 if (theToken.type == SYMBOL)
00113 {
00114
00115
00116
00117
00118
00119
00120
00121 tokenRead = FALSE;
00122 if (FindModuleSeparator(ValueToString(theToken.value)))
00123 {
00124 SyntaxErrorMessage(theEnv,"defglobal");
00125 return(TRUE);
00126 }
00127
00128
00129
00130
00131
00132 theModule = (struct defmodule *) EnvFindDefmodule(theEnv,ValueToString(theToken.value));
00133 if (theModule == NULL)
00134 {
00135 CantFindItemErrorMessage(theEnv,"defmodule",ValueToString(theToken.value));
00136 return(TRUE);
00137 }
00138
00139
00140
00141
00142
00143
00144 SavePPBuffer(theEnv," ");
00145 EnvSetCurrentModule(theEnv,(void *) theModule);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154 else
00155 {
00156 PPBackup(theEnv);
00157 SavePPBuffer(theEnv,EnvGetDefmoduleName(theEnv,((struct defmodule *) EnvGetCurrentModule(theEnv))));
00158 SavePPBuffer(theEnv," ");
00159 SavePPBuffer(theEnv,theToken.printForm);
00160 }
00161
00162
00163
00164
00165
00166 while (GetVariableDefinition(theEnv,readSource,&defglobalError,tokenRead,&theToken))
00167 {
00168 tokenRead = FALSE;
00169
00170 FlushPPBuffer(theEnv);
00171 SavePPBuffer(theEnv,"(defglobal ");
00172 SavePPBuffer(theEnv,EnvGetDefmoduleName(theEnv,((struct defmodule *) EnvGetCurrentModule(theEnv))));
00173 SavePPBuffer(theEnv," ");
00174 }
00175
00176 #endif
00177
00178
00179
00180
00181
00182 return(defglobalError);
00183 }
00184
00185 #if (! RUN_TIME) && (! BLOAD_ONLY)
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 static intBool GetVariableDefinition(
00196 void *theEnv,
00197 char *readSource,
00198 int *defglobalError,
00199 int tokenRead,
00200 struct token *theToken)
00201 {
00202 SYMBOL_HN *variableName;
00203 struct expr *assignPtr;
00204 DATA_OBJECT assignValue;
00205
00206
00207
00208
00209
00210
00211 if (! tokenRead) GetToken(theEnv,readSource,theToken);
00212 if (theToken->type == RPAREN) return(FALSE);
00213
00214 if (theToken->type == SF_VARIABLE)
00215 {
00216 SyntaxErrorMessage(theEnv,"defglobal");
00217 *defglobalError = TRUE;
00218 return(FALSE);
00219 }
00220 else if (theToken->type != GBL_VARIABLE)
00221 {
00222 SyntaxErrorMessage(theEnv,"defglobal");
00223 *defglobalError = TRUE;
00224 return(FALSE);
00225 }
00226
00227 variableName = (SYMBOL_HN *) theToken->value;
00228
00229 SavePPBuffer(theEnv," ");
00230
00231
00232
00233
00234
00235 #if DEBUGGING_FUNCTIONS
00236 if ((EnvGetWatchItem(theEnv,"compilations") == ON) && GetPrintWhileLoading(theEnv))
00237 {
00238 if (QFindDefglobal(theEnv,variableName) != NULL)
00239 {
00240 PrintWarningID(theEnv,"CSTRCPSR",1,TRUE);
00241 EnvPrintRouter(theEnv,WDIALOG,"Redefining defglobal: ");
00242 }
00243 else EnvPrintRouter(theEnv,WDIALOG,"Defining defglobal: ");
00244 EnvPrintRouter(theEnv,WDIALOG,ValueToString(variableName));
00245 EnvPrintRouter(theEnv,WDIALOG,"\n");
00246 }
00247 else
00248 #endif
00249 { if (GetPrintWhileLoading(theEnv)) EnvPrintRouter(theEnv,WDIALOG,":"); }
00250
00251
00252
00253
00254
00255 #if DEFMODULE_CONSTRUCT
00256 if (FindImportExportConflict(theEnv,"defglobal",((struct defmodule *) EnvGetCurrentModule(theEnv)),ValueToString(variableName)))
00257 {
00258 ImportExportConflictMessage(theEnv,"defglobal",ValueToString(variableName),NULL,NULL);
00259 *defglobalError = TRUE;
00260 return(FALSE);
00261 }
00262 #endif
00263
00264
00265
00266
00267
00268 GetToken(theEnv,readSource,theToken);
00269 if (strcmp(theToken->printForm,"=") != 0)
00270 {
00271 SyntaxErrorMessage(theEnv,"defglobal");
00272 *defglobalError = TRUE;
00273 return(FALSE);
00274 }
00275
00276 SavePPBuffer(theEnv," ");
00277
00278
00279
00280
00281
00282 assignPtr = ParseAtomOrExpression(theEnv,readSource,NULL);
00283 if (assignPtr == NULL)
00284 {
00285 *defglobalError = TRUE;
00286 return(FALSE);
00287 }
00288
00289
00290
00291
00292
00293 if (! ConstructData(theEnv)->CheckSyntaxMode)
00294 {
00295 SetEvaluationError(theEnv,FALSE);
00296 if (EvaluateExpression(theEnv,assignPtr,&assignValue))
00297 {
00298 ReturnExpression(theEnv,assignPtr);
00299 *defglobalError = TRUE;
00300 return(FALSE);
00301 }
00302 }
00303 else
00304 { ReturnExpression(theEnv,assignPtr); }
00305
00306 SavePPBuffer(theEnv,")");
00307
00308
00309
00310
00311
00312 if (! ConstructData(theEnv)->CheckSyntaxMode)
00313 { AddDefglobal(theEnv,variableName,&assignValue,assignPtr); }
00314
00315
00316
00317
00318
00319
00320 return(TRUE);
00321 }
00322
00323
00324
00325
00326 static void AddDefglobal(
00327 void *theEnv,
00328 SYMBOL_HN *name,
00329 DATA_OBJECT_PTR vPtr,
00330 struct expr *ePtr)
00331 {
00332 struct defglobal *defglobalPtr;
00333 intBool newGlobal = FALSE;
00334 #if DEBUGGING_FUNCTIONS
00335 int GlobalHadWatch = FALSE;
00336 #endif
00337
00338
00339
00340
00341
00342
00343
00344 defglobalPtr = QFindDefglobal(theEnv,name);
00345 if (defglobalPtr == NULL)
00346 {
00347 newGlobal = TRUE;
00348 defglobalPtr = get_struct(theEnv,defglobal);
00349 }
00350 else
00351 {
00352 DeinstallConstructHeader(theEnv,&defglobalPtr->header);
00353 #if DEBUGGING_FUNCTIONS
00354 GlobalHadWatch = defglobalPtr->watch;
00355 #endif
00356 }
00357
00358
00359
00360
00361
00362 if (newGlobal == FALSE)
00363 {
00364 ValueDeinstall(theEnv,&defglobalPtr->current);
00365 if (defglobalPtr->current.type == MULTIFIELD)
00366 { ReturnMultifield(theEnv,(struct multifield *) defglobalPtr->current.value); }
00367
00368 RemoveHashedExpression(theEnv,defglobalPtr->initial);
00369 }
00370
00371
00372
00373
00374
00375 defglobalPtr->current.type = vPtr->type;
00376 if (vPtr->type != MULTIFIELD) defglobalPtr->current.value = vPtr->value;
00377 else DuplicateMultifield(theEnv,&defglobalPtr->current,vPtr);
00378 ValueInstall(theEnv,&defglobalPtr->current);
00379
00380 defglobalPtr->initial = AddHashedExpression(theEnv,ePtr);
00381 ReturnExpression(theEnv,ePtr);
00382 DefglobalData(theEnv)->ChangeToGlobals = TRUE;
00383
00384
00385
00386
00387
00388
00389 #if DEBUGGING_FUNCTIONS
00390 defglobalPtr->watch = GlobalHadWatch ? TRUE : WatchGlobals;
00391 #endif
00392
00393
00394
00395
00396
00397 defglobalPtr->header.name = name;
00398 defglobalPtr->header.usrData = NULL;
00399 IncrementSymbolCount(name);
00400
00401 SavePPBuffer(theEnv,"\n");
00402 if (EnvGetConserveMemory(theEnv) == TRUE)
00403 { defglobalPtr->header.ppForm = NULL; }
00404 else
00405 { defglobalPtr->header.ppForm = CopyPPBuffer(theEnv); }
00406
00407 defglobalPtr->inScope = TRUE;
00408
00409
00410
00411
00412
00413 if (newGlobal == FALSE) return;
00414
00415
00416
00417
00418
00419 defglobalPtr->busyCount = 0;
00420 defglobalPtr->header.whichModule = (struct defmoduleItemHeader *)
00421 GetModuleItem(theEnv,NULL,FindModuleItem(theEnv,"defglobal")->moduleIndex);
00422
00423
00424
00425
00426
00427
00428 AddConstructToModule(&defglobalPtr->header);
00429 }
00430
00431
00432
00433
00434
00435
00436 globle intBool ReplaceGlobalVariable(
00437 void *theEnv,
00438 struct expr *ePtr)
00439 {
00440 struct defglobal *theGlobal;
00441 int count;
00442
00443
00444
00445
00446
00447 theGlobal = (struct defglobal *)
00448 FindImportedConstruct(theEnv,"defglobal",NULL,ValueToString(ePtr->value),
00449 &count,TRUE,NULL);
00450
00451
00452
00453
00454
00455 if (theGlobal == NULL)
00456 {
00457 GlobalReferenceErrorMessage(theEnv,ValueToString(ePtr->value));
00458 return(FALSE);
00459 }
00460
00461
00462
00463
00464
00465
00466
00467 if (count > 1)
00468 {
00469 AmbiguousReferenceErrorMessage(theEnv,"defglobal",ValueToString(ePtr->value));
00470 return(FALSE);
00471 }
00472
00473
00474
00475
00476
00477
00478 ePtr->type = DEFGLOBAL_PTR;
00479 ePtr->value = (void *) theGlobal;
00480
00481 return(TRUE);
00482 }
00483
00484
00485
00486
00487
00488 globle void GlobalReferenceErrorMessage(
00489 void *theEnv,
00490 char *variableName)
00491 {
00492 PrintErrorID(theEnv,"GLOBLPSR",1,TRUE);
00493 EnvPrintRouter(theEnv,WERROR,"\nGlobal variable ?*");
00494 EnvPrintRouter(theEnv,WERROR,variableName);
00495 EnvPrintRouter(theEnv,WERROR,"* was referenced, but is not defined.\n");
00496 }
00497
00498 #endif
00499
00500 #endif
00501
00502
00503