00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "setup.h"
00034
00035 #if OBJECT_SYSTEM
00036
00037 #ifndef _STDIO_INCLUDED_
00038 #define _STDIO_INCLUDED_
00039 #include <stdio.h>
00040 #endif
00041
00042 #include <string.h>
00043
00044 #include "classcom.h"
00045 #include "classfun.h"
00046 #include "classinf.h"
00047 #include "constant.h"
00048 #include "envrnmnt.h"
00049 #include "evaluatn.h"
00050 #include "exprnpsr.h"
00051 #include "extnfunc.h"
00052 #include "moduldef.h"
00053 #include "prntutil.h"
00054 #include "router.h"
00055
00056 #define _INSPSR_SOURCE_
00057 #include "inspsr.h"
00058
00059
00060
00061
00062
00063
00064 #define MAKE_TYPE 0
00065 #define INITIALIZE_TYPE 1
00066 #define MODIFY_TYPE 2
00067 #define DUPLICATE_TYPE 3
00068
00069 #define CLASS_RLN "of"
00070 #define DUPLICATE_NAME_REF "to"
00071
00072
00073
00074
00075
00076
00077
00078 static intBool ReplaceClassNameWithReference(void *,EXPRESSION *);
00079
00080
00081
00082
00083
00084
00085
00086 #if ! RUN_TIME
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 globle EXPRESSION *ParseInitializeInstance(
00164 void *theEnv,
00165 EXPRESSION *top,
00166 char *readSource)
00167 {
00168 int error,fcalltype,readclass;
00169
00170 if ((top->value == (void *) FindFunction(theEnv,"make-instance")) ||
00171 (top->value == (void *) FindFunction(theEnv,"active-make-instance")))
00172 fcalltype = MAKE_TYPE;
00173 else if ((top->value == (void *) FindFunction(theEnv,"initialize-instance")) ||
00174 (top->value == (void *) FindFunction(theEnv,"active-initialize-instance")))
00175 fcalltype = INITIALIZE_TYPE;
00176 else if ((top->value == (void *) FindFunction(theEnv,"modify-instance")) ||
00177 (top->value == (void *) FindFunction(theEnv,"active-modify-instance")) ||
00178 (top->value == (void *) FindFunction(theEnv,"message-modify-instance")) ||
00179 (top->value == (void *) FindFunction(theEnv,"active-message-modify-instance")))
00180 fcalltype = MODIFY_TYPE;
00181 else
00182 fcalltype = DUPLICATE_TYPE;
00183 IncrementIndentDepth(theEnv,3);
00184 error = FALSE;
00185 if (top->type == UNKNOWN_VALUE)
00186 top->type = FCALL;
00187 else
00188 SavePPBuffer(theEnv," ");
00189 top->argList = ArgumentParse(theEnv,readSource,&error);
00190 if (error)
00191 goto ParseInitializeInstanceError;
00192 else if (top->argList == NULL)
00193 {
00194 SyntaxErrorMessage(theEnv,"instance");
00195 goto ParseInitializeInstanceError;
00196 }
00197 SavePPBuffer(theEnv," ");
00198
00199 if (fcalltype == MAKE_TYPE)
00200 {
00201
00202
00203
00204
00205 if ((top->argList->type != SYMBOL) ? FALSE :
00206 (strcmp(ValueToString(top->argList->value),CLASS_RLN) == 0))
00207 {
00208 top->argList->nextArg = ArgumentParse(theEnv,readSource,&error);
00209 if (error == TRUE)
00210 goto ParseInitializeInstanceError;
00211 if (top->argList->nextArg == NULL)
00212 {
00213 SyntaxErrorMessage(theEnv,"instance class");
00214 goto ParseInitializeInstanceError;
00215 }
00216 if ((top->argList->nextArg->type != SYMBOL) ? TRUE :
00217 (strcmp(ValueToString(top->argList->nextArg->value),CLASS_RLN) != 0))
00218 {
00219 top->argList->type = FCALL;
00220 top->argList->value = (void *) FindFunction(theEnv,"gensym*");
00221 readclass = FALSE;
00222 }
00223 else
00224 readclass = TRUE;
00225 }
00226 else
00227 {
00228 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00229 if ((GetType(DefclassData(theEnv)->ObjectParseToken) != SYMBOL) ? TRUE :
00230 (strcmp(CLASS_RLN,DOToString(DefclassData(theEnv)->ObjectParseToken)) != 0))
00231 {
00232 SyntaxErrorMessage(theEnv,"make-instance");
00233 goto ParseInitializeInstanceError;
00234 }
00235 SavePPBuffer(theEnv," ");
00236 readclass = TRUE;
00237 }
00238 if (readclass)
00239 {
00240 top->argList->nextArg = ArgumentParse(theEnv,readSource,&error);
00241 if (error)
00242 goto ParseInitializeInstanceError;
00243 if (top->argList->nextArg == NULL)
00244 {
00245 SyntaxErrorMessage(theEnv,"instance class");
00246 goto ParseInitializeInstanceError;
00247 }
00248 }
00249
00250
00251
00252
00253
00254 if (ReplaceClassNameWithReference(theEnv,top->argList->nextArg) == FALSE)
00255 goto ParseInitializeInstanceError;
00256
00257 PPCRAndIndent(theEnv);
00258 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00259 top->argList->nextArg->nextArg =
00260 ParseSlotOverrides(theEnv,readSource,&error);
00261 }
00262 else
00263 {
00264 PPCRAndIndent(theEnv);
00265 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00266 if (fcalltype == DUPLICATE_TYPE)
00267 {
00268 if ((DefclassData(theEnv)->ObjectParseToken.type != SYMBOL) ? FALSE :
00269 (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),DUPLICATE_NAME_REF) == 0))
00270 {
00271 PPBackup(theEnv);
00272 PPBackup(theEnv);
00273 SavePPBuffer(theEnv,DefclassData(theEnv)->ObjectParseToken.printForm);
00274 SavePPBuffer(theEnv," ");
00275 top->argList->nextArg = ArgumentParse(theEnv,readSource,&error);
00276 if (error)
00277 goto ParseInitializeInstanceError;
00278 if (top->argList->nextArg == NULL)
00279 {
00280 SyntaxErrorMessage(theEnv,"instance name");
00281 goto ParseInitializeInstanceError;
00282 }
00283 PPCRAndIndent(theEnv);
00284 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00285 }
00286 else
00287 top->argList->nextArg = GenConstant(theEnv,FCALL,(void *) FindFunction(theEnv,"gensym*"));
00288 top->argList->nextArg->nextArg = ParseSlotOverrides(theEnv,readSource,&error);
00289 }
00290 else
00291 top->argList->nextArg = ParseSlotOverrides(theEnv,readSource,&error);
00292 }
00293 if (error)
00294 goto ParseInitializeInstanceError;
00295 if (GetType(DefclassData(theEnv)->ObjectParseToken) != RPAREN)
00296 {
00297 SyntaxErrorMessage(theEnv,"slot-override");
00298 goto ParseInitializeInstanceError;
00299 }
00300 DecrementIndentDepth(theEnv,3);
00301 return(top);
00302
00303 ParseInitializeInstanceError:
00304 SetEvaluationError(theEnv,TRUE);
00305 ReturnExpression(theEnv,top);
00306 DecrementIndentDepth(theEnv,3);
00307 return(NULL);
00308 }
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 globle EXPRESSION *ParseSlotOverrides(
00331 void *theEnv,
00332 char *readSource,
00333 int *error)
00334 {
00335 EXPRESSION *top = NULL,*bot = NULL,*theExp;
00336
00337 while (GetType(DefclassData(theEnv)->ObjectParseToken) == LPAREN)
00338 {
00339 *error = FALSE;
00340 theExp = ArgumentParse(theEnv,readSource,error);
00341 if (*error == TRUE)
00342 {
00343 ReturnExpression(theEnv,top);
00344 return(NULL);
00345 }
00346 else if (theExp == NULL)
00347 {
00348 SyntaxErrorMessage(theEnv,"slot-override");
00349 *error = TRUE;
00350 ReturnExpression(theEnv,top);
00351 SetEvaluationError(theEnv,TRUE);
00352 return(NULL);
00353 }
00354 theExp->nextArg = GenConstant(theEnv,SYMBOL,EnvTrueSymbol(theEnv));
00355 if (CollectArguments(theEnv,theExp->nextArg,readSource) == NULL)
00356 {
00357 *error = TRUE;
00358 ReturnExpression(theEnv,top);
00359 return(NULL);
00360 }
00361 if (top == NULL)
00362 top = theExp;
00363 else
00364 bot->nextArg = theExp;
00365 bot = theExp->nextArg;
00366 PPCRAndIndent(theEnv);
00367 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00368 }
00369 PPBackup(theEnv);
00370 PPBackup(theEnv);
00371 SavePPBuffer(theEnv,DefclassData(theEnv)->ObjectParseToken.printForm);
00372 return(top);
00373 }
00374
00375 #endif
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 globle EXPRESSION *ParseSimpleInstance(
00411 void *theEnv,
00412 EXPRESSION *top,
00413 char *readSource)
00414 {
00415 EXPRESSION *theExp,*vals = NULL,*vbot,*tval;
00416 unsigned short type;
00417
00418 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00419 if ((GetType(DefclassData(theEnv)->ObjectParseToken) != INSTANCE_NAME) &&
00420 (GetType(DefclassData(theEnv)->ObjectParseToken) != SYMBOL))
00421 goto MakeInstanceError;
00422
00423 if ((GetType(DefclassData(theEnv)->ObjectParseToken) == SYMBOL) &&
00424 (strcmp(CLASS_RLN,DOToString(DefclassData(theEnv)->ObjectParseToken)) == 0))
00425 {
00426 top->argList = GenConstant(theEnv,FCALL,
00427 (void *) FindFunction(theEnv,"gensym*"));
00428 }
00429 else
00430 {
00431 top->argList = GenConstant(theEnv,INSTANCE_NAME,
00432 (void *) GetValue(DefclassData(theEnv)->ObjectParseToken));
00433 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00434 if ((GetType(DefclassData(theEnv)->ObjectParseToken) != SYMBOL) ? TRUE :
00435 (strcmp(CLASS_RLN,DOToString(DefclassData(theEnv)->ObjectParseToken)) != 0))
00436 goto MakeInstanceError;
00437 }
00438
00439 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00440 if (GetType(DefclassData(theEnv)->ObjectParseToken) != SYMBOL)
00441 goto MakeInstanceError;
00442 top->argList->nextArg =
00443 GenConstant(theEnv,SYMBOL,(void *) GetValue(DefclassData(theEnv)->ObjectParseToken));
00444 theExp = top->argList->nextArg;
00445 if (ReplaceClassNameWithReference(theEnv,theExp) == FALSE)
00446 goto MakeInstanceError;
00447 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00448 while (GetType(DefclassData(theEnv)->ObjectParseToken) == LPAREN)
00449 {
00450 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00451 if (GetType(DefclassData(theEnv)->ObjectParseToken) != SYMBOL)
00452 goto SlotOverrideError;
00453 theExp->nextArg = GenConstant(theEnv,SYMBOL,(void *) GetValue(DefclassData(theEnv)->ObjectParseToken));
00454 theExp->nextArg->nextArg = GenConstant(theEnv,SYMBOL,EnvTrueSymbol(theEnv));
00455 theExp = theExp->nextArg->nextArg;
00456 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00457 vbot = NULL;
00458 while (GetType(DefclassData(theEnv)->ObjectParseToken) != RPAREN)
00459 {
00460 type = GetType(DefclassData(theEnv)->ObjectParseToken);
00461 if (type == LPAREN)
00462 {
00463 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00464 if ((GetType(DefclassData(theEnv)->ObjectParseToken) != SYMBOL) ? TRUE :
00465 (strcmp(ValueToString(DefclassData(theEnv)->ObjectParseToken.value),"create$") != 0))
00466 goto SlotOverrideError;
00467 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00468 if (GetType(DefclassData(theEnv)->ObjectParseToken) != RPAREN)
00469 goto SlotOverrideError;
00470 tval = GenConstant(theEnv,FCALL,(void *) FindFunction(theEnv,"create$"));
00471 }
00472 else
00473 {
00474 if ((type != SYMBOL) && (type != STRING) &&
00475 (type != FLOAT) && (type != INTEGER) && (type != INSTANCE_NAME))
00476 goto SlotOverrideError;
00477 tval = GenConstant(theEnv,type,(void *) GetValue(DefclassData(theEnv)->ObjectParseToken));
00478 }
00479 if (vals == NULL)
00480 vals = tval;
00481 else
00482 vbot->nextArg = tval;
00483 vbot = tval;
00484 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00485 }
00486 theExp->argList = vals;
00487 GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
00488 vals = NULL;
00489 }
00490 if (GetType(DefclassData(theEnv)->ObjectParseToken) != RPAREN)
00491 goto SlotOverrideError;
00492 return(top);
00493
00494 MakeInstanceError:
00495 SyntaxErrorMessage(theEnv,"make-instance");
00496 SetEvaluationError(theEnv,TRUE);
00497 ReturnExpression(theEnv,top);
00498 return(NULL);
00499
00500 SlotOverrideError:
00501 SyntaxErrorMessage(theEnv,"slot-override");
00502 SetEvaluationError(theEnv,TRUE);
00503 ReturnExpression(theEnv,top);
00504 ReturnExpression(theEnv,vals);
00505 return(NULL);
00506 }
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528 static intBool ReplaceClassNameWithReference(
00529 void *theEnv,
00530 EXPRESSION *theExp)
00531 {
00532 char *theClassName;
00533 void *theDefclass;
00534
00535 if (theExp->type == SYMBOL)
00536 {
00537 theClassName = ValueToString(theExp->value);
00538 theDefclass = (void *) LookupDefclassInScope(theEnv,theClassName);
00539 if (theDefclass == NULL)
00540 {
00541 CantFindItemErrorMessage(theEnv,"class",theClassName);
00542 return(FALSE);
00543 }
00544 if (EnvClassAbstractP(theEnv,theDefclass))
00545 {
00546 PrintErrorID(theEnv,"INSMNGR",3,FALSE);
00547 EnvPrintRouter(theEnv,WERROR,"Cannot create instances of abstract class ");
00548 EnvPrintRouter(theEnv,WERROR,theClassName);
00549 EnvPrintRouter(theEnv,WERROR,".\n");
00550 return(FALSE);
00551 }
00552 theExp->type = DEFCLASS_PTR;
00553 theExp->value = theDefclass;
00554 }
00555 return(TRUE);
00556 }
00557
00558 #endif
00559
00560
00561