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 DEFGENERIC_CONSTRUCT && (! BLOAD_ONLY) && (! RUN_TIME)
00036
00037 #if BLOAD || BLOAD_AND_BSAVE
00038 #include "bload.h"
00039 #endif
00040
00041 #if DEFFUNCTION_CONSTRUCT
00042 #include "dffnxfun.h"
00043 #endif
00044
00045 #if OBJECT_SYSTEM
00046 #include "classfun.h"
00047 #include "classcom.h"
00048 #endif
00049
00050 #include "memalloc.h"
00051 #include "cstrcpsr.h"
00052 #include "envrnmnt.h"
00053 #include "exprnpsr.h"
00054 #include "genrccom.h"
00055 #include "immthpsr.h"
00056 #include "modulutl.h"
00057 #include "prcdrpsr.h"
00058 #include "prccode.h"
00059 #include "router.h"
00060 #include "scanner.h"
00061
00062 #define _GENRCPSR_SOURCE_
00063 #include "genrcpsr.h"
00064
00065
00066
00067
00068
00069
00070 #define HIGHER_PRECEDENCE -1
00071 #define IDENTICAL 0
00072 #define LOWER_PRECEDENCE 1
00073
00074 #define CURR_ARG_VAR "current-argument"
00075
00076
00077
00078
00079
00080
00081
00082 static intBool ValidGenericName(void *,char *);
00083 static SYMBOL_HN *ParseMethodNameAndIndex(void *,char *,int *);
00084
00085 #if DEBUGGING_FUNCTIONS
00086 static void CreateDefaultGenericPPForm(void *,DEFGENERIC *);
00087 #endif
00088
00089 static int ParseMethodParameters(void *,char *,EXPRESSION **,SYMBOL_HN **);
00090 static RESTRICTION *ParseRestriction(void *,char *);
00091 static void ReplaceCurrentArgRefs(void *,EXPRESSION *);
00092 static int DuplicateParameters(void *,EXPRESSION *,EXPRESSION **,SYMBOL_HN *);
00093 static EXPRESSION *AddParameter(void *,EXPRESSION *,EXPRESSION *,SYMBOL_HN *,RESTRICTION *);
00094 static EXPRESSION *ValidType(void *,SYMBOL_HN *);
00095 static intBool RedundantClasses(void *,void *,void *);
00096 static DEFGENERIC *AddGeneric(void *,SYMBOL_HN *,int *);
00097 static DEFMETHOD *AddGenericMethod(void *,DEFGENERIC *,int,short);
00098 static int RestrictionsCompare(EXPRESSION *,int,int,int,DEFMETHOD *);
00099 static int TypeListCompare(RESTRICTION *,RESTRICTION *);
00100 static DEFGENERIC *NewGeneric(void *,SYMBOL_HN *);
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 globle intBool ParseDefgeneric(
00118 void *theEnv,
00119 char *readSource)
00120 {
00121 SYMBOL_HN *gname;
00122 DEFGENERIC *gfunc;
00123 int newGeneric;
00124
00125 SetPPBufferStatus(theEnv,ON);
00126 FlushPPBuffer(theEnv);
00127 SavePPBuffer(theEnv,"(defgeneric ");
00128 SetIndentDepth(theEnv,3);
00129
00130 #if BLOAD || BLOAD_AND_BSAVE
00131 if ((Bloaded(theEnv) == TRUE) && (! ConstructData(theEnv)->CheckSyntaxMode))
00132 {
00133 CannotLoadWithBloadMessage(theEnv,"defgeneric");
00134 return(TRUE);
00135 }
00136 #endif
00137
00138 gname = GetConstructNameAndComment(theEnv,readSource,&DefgenericData(theEnv)->GenericInputToken,"defgeneric",
00139 EnvFindDefgeneric,NULL,"^",TRUE,
00140 TRUE,TRUE);
00141 if (gname == NULL)
00142 return(TRUE);
00143
00144 if (ValidGenericName(theEnv,ValueToString(gname)) == FALSE)
00145 return(TRUE);
00146
00147 if (DefgenericData(theEnv)->GenericInputToken.type != RPAREN)
00148 {
00149 PrintErrorID(theEnv,"GENRCPSR",1,FALSE);
00150 EnvPrintRouter(theEnv,WERROR,"Expected ')' to complete defgeneric.\n");
00151 return(TRUE);
00152 }
00153 SavePPBuffer(theEnv,"\n");
00154
00155
00156
00157
00158
00159
00160 if (ConstructData(theEnv)->CheckSyntaxMode)
00161 { return(FALSE); }
00162
00163 gfunc = AddGeneric(theEnv,gname,&newGeneric);
00164
00165 #if DEBUGGING_FUNCTIONS
00166 SetDefgenericPPForm((void *) gfunc,EnvGetConserveMemory(theEnv) ? NULL : CopyPPBuffer(theEnv));
00167 #endif
00168 return(FALSE);
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 globle intBool ParseDefmethod(
00187 void *theEnv,
00188 char *readSource)
00189 {
00190 SYMBOL_HN *gname;
00191 int rcnt,mposn,mi,newMethod,mnew = FALSE,lvars,error;
00192 EXPRESSION *params,*actions,*tmp;
00193 SYMBOL_HN *wildcard;
00194 DEFMETHOD *meth;
00195 DEFGENERIC *gfunc;
00196 int theIndex;
00197
00198 SetPPBufferStatus(theEnv,ON);
00199 FlushPPBuffer(theEnv);
00200 SetIndentDepth(theEnv,3);
00201 SavePPBuffer(theEnv,"(defmethod ");
00202
00203 #if BLOAD || BLOAD_AND_BSAVE
00204 if ((Bloaded(theEnv) == TRUE) && (! ConstructData(theEnv)->CheckSyntaxMode))
00205 {
00206 CannotLoadWithBloadMessage(theEnv,"defmethod");
00207 return(TRUE);
00208 }
00209 #endif
00210
00211 gname = ParseMethodNameAndIndex(theEnv,readSource,&theIndex);
00212 if (gname == NULL)
00213 return(TRUE);
00214
00215 if (ValidGenericName(theEnv,ValueToString(gname)) == FALSE)
00216 return(TRUE);
00217
00218
00219
00220
00221
00222 gfunc = AddGeneric(theEnv,gname,&newMethod);
00223
00224 #if DEBUGGING_FUNCTIONS
00225 if (newMethod && (! ConstructData(theEnv)->CheckSyntaxMode))
00226 CreateDefaultGenericPPForm(theEnv,gfunc);
00227 #endif
00228
00229 IncrementIndentDepth(theEnv,1);
00230 rcnt = ParseMethodParameters(theEnv,readSource,¶ms,&wildcard);
00231 DecrementIndentDepth(theEnv,1);
00232 if (rcnt == -1)
00233 goto DefmethodParseError;
00234 PPCRAndIndent(theEnv);
00235 for (tmp = params ; tmp != NULL ; tmp = tmp->nextArg)
00236 {
00237 ReplaceCurrentArgRefs(theEnv,((RESTRICTION *) tmp->argList)->query);
00238 if (ReplaceProcVars(theEnv,"method",((RESTRICTION *) tmp->argList)->query,
00239 params,wildcard,NULL,NULL))
00240 {
00241 DeleteTempRestricts(theEnv,params);
00242 goto DefmethodParseError;
00243 }
00244 }
00245 meth = FindMethodByRestrictions(gfunc,params,rcnt,wildcard,&mposn);
00246 error = FALSE;
00247 if (meth != NULL)
00248 {
00249 if (meth->system)
00250 {
00251 PrintErrorID(theEnv,"GENRCPSR",17,FALSE);
00252 EnvPrintRouter(theEnv,WERROR,"Cannot replace the implicit system method #");
00253 PrintLongInteger(theEnv,WERROR,(long long) meth->index);
00254 EnvPrintRouter(theEnv,WERROR,".\n");
00255 error = TRUE;
00256 }
00257 else if ((theIndex != 0) && (theIndex != meth->index))
00258 {
00259 PrintErrorID(theEnv,"GENRCPSR",2,FALSE);
00260 EnvPrintRouter(theEnv,WERROR,"New method #");
00261 PrintLongInteger(theEnv,WERROR,(long long) theIndex);
00262 EnvPrintRouter(theEnv,WERROR," would be indistinguishable from method #");
00263 PrintLongInteger(theEnv,WERROR,(long long) meth->index);
00264 EnvPrintRouter(theEnv,WERROR,".\n");
00265 error = TRUE;
00266 }
00267 }
00268 else if (theIndex != 0)
00269 {
00270 mi = FindMethodByIndex(gfunc,theIndex);
00271 if (mi == -1)
00272 mnew = TRUE;
00273 else if (gfunc->methods[mi].system)
00274 {
00275 PrintErrorID(theEnv,"GENRCPSR",17,FALSE);
00276 EnvPrintRouter(theEnv,WERROR,"Cannot replace the implicit system method #");
00277 PrintLongInteger(theEnv,WERROR,(long long) theIndex);
00278 EnvPrintRouter(theEnv,WERROR,".\n");
00279 error = TRUE;
00280 }
00281 }
00282 else
00283 mnew = TRUE;
00284 if (error)
00285 {
00286 DeleteTempRestricts(theEnv,params);
00287 goto DefmethodParseError;
00288 }
00289 ExpressionData(theEnv)->ReturnContext = TRUE;
00290 actions = ParseProcActions(theEnv,"method",readSource,
00291 &DefgenericData(theEnv)->GenericInputToken,params,wildcard,
00292 NULL,NULL,&lvars,NULL);
00293
00294
00295
00296
00297
00298 if ((DefgenericData(theEnv)->GenericInputToken.type != RPAREN) &&
00299 (actions != NULL))
00300 {
00301 SyntaxErrorMessage(theEnv,"defmethod");
00302 DeleteTempRestricts(theEnv,params);
00303 ReturnPackedExpression(theEnv,actions);
00304 goto DefmethodParseError;
00305 }
00306
00307 if (actions == NULL)
00308 {
00309 DeleteTempRestricts(theEnv,params);
00310 goto DefmethodParseError;
00311 }
00312
00313
00314
00315
00316
00317
00318 if (ConstructData(theEnv)->CheckSyntaxMode)
00319 {
00320 DeleteTempRestricts(theEnv,params);
00321 ReturnPackedExpression(theEnv,actions);
00322 if (newMethod)
00323 {
00324 RemoveConstructFromModule(theEnv,(struct constructHeader *) gfunc);
00325 RemoveDefgeneric(theEnv,(struct constructHeader *) gfunc);
00326 }
00327 return(FALSE);
00328 }
00329
00330 PPBackup(theEnv);
00331 PPBackup(theEnv);
00332 SavePPBuffer(theEnv,DefgenericData(theEnv)->GenericInputToken.printForm);
00333 SavePPBuffer(theEnv,"\n");
00334
00335 #if DEBUGGING_FUNCTIONS
00336 meth = AddMethod(theEnv,gfunc,meth,mposn,(short) theIndex,params,rcnt,lvars,wildcard,actions,
00337 EnvGetConserveMemory(theEnv) ? NULL : CopyPPBuffer(theEnv),FALSE);
00338 #else
00339 meth = AddMethod(theEnv,gfunc,meth,mposn,theIndex,params,rcnt,lvars,wildcard,actions,NULL,FALSE);
00340 #endif
00341 DeleteTempRestricts(theEnv,params);
00342 if (GetPrintWhileLoading(theEnv) && GetCompilationsWatch(theEnv))
00343 {
00344 EnvPrintRouter(theEnv,WDIALOG," Method #");
00345 PrintLongInteger(theEnv,WDIALOG,(long long) meth->index);
00346 if (mnew)
00347 EnvPrintRouter(theEnv,WDIALOG," defined.\n");
00348 else
00349 EnvPrintRouter(theEnv,WDIALOG," redefined.\n");
00350 }
00351 return(FALSE);
00352
00353 DefmethodParseError:
00354 if (newMethod)
00355 {
00356 RemoveConstructFromModule(theEnv,(struct constructHeader *) gfunc);
00357 RemoveDefgeneric(theEnv,(void *) gfunc);
00358 }
00359 return(TRUE);
00360 }
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 globle DEFMETHOD *AddMethod(
00392 void *theEnv,
00393 DEFGENERIC *gfunc,
00394 DEFMETHOD *meth,
00395 int mposn,
00396 short mi,
00397 EXPRESSION *params,
00398 int rcnt,
00399 int lvars,
00400 SYMBOL_HN *wildcard,
00401 EXPRESSION *actions,
00402 char *ppForm,
00403 int copyRestricts)
00404 {
00405 RESTRICTION *rptr,*rtmp;
00406 register int i,j;
00407 int mai;
00408
00409 SaveBusyCount(gfunc);
00410 if (meth == NULL)
00411 {
00412 mai = (mi != 0) ? FindMethodByIndex(gfunc,mi) : -1;
00413 if (mai == -1)
00414 meth = AddGenericMethod(theEnv,gfunc,mposn,mi);
00415 else
00416 {
00417 DeleteMethodInfo(theEnv,gfunc,&gfunc->methods[mai]);
00418 if (mai < mposn)
00419 {
00420 mposn--;
00421 for (i = mai+1 ; i <= mposn ; i++)
00422 GenCopyMemory(DEFMETHOD,1,&gfunc->methods[i-1],&gfunc->methods[i]);
00423 }
00424 else
00425 {
00426 for (i = mai-1 ; i >= mposn ; i--)
00427 GenCopyMemory(DEFMETHOD,1,&gfunc->methods[i+1],&gfunc->methods[i]);
00428 }
00429 meth = &gfunc->methods[mposn];
00430 meth->index = mi;
00431 }
00432 }
00433 else
00434 {
00435
00436
00437
00438 ExpressionDeinstall(theEnv,meth->actions);
00439 ReturnPackedExpression(theEnv,meth->actions);
00440 if (meth->ppForm != NULL)
00441 rm(theEnv,(void *) meth->ppForm,(sizeof(char) * (strlen(meth->ppForm)+1)));
00442 }
00443 meth->system = 0;
00444 meth->actions = actions;
00445 ExpressionInstall(theEnv,meth->actions);
00446 meth->ppForm = ppForm;
00447 if (mposn == -1)
00448 {
00449 RestoreBusyCount(gfunc);
00450 return(meth);
00451 }
00452
00453 meth->localVarCount = (short) lvars;
00454 meth->restrictionCount = (short) rcnt;
00455 if (wildcard != NULL)
00456 {
00457 meth->minRestrictions = (short) (rcnt-1);
00458 meth->maxRestrictions = -1;
00459 }
00460 else
00461 meth->minRestrictions = meth->maxRestrictions = (short) rcnt;
00462 if (rcnt != 0)
00463 meth->restrictions = (RESTRICTION *)
00464 gm2(theEnv,(sizeof(RESTRICTION) * rcnt));
00465 else
00466 meth->restrictions = NULL;
00467 for (i = 0 ; i < rcnt ; i++)
00468 {
00469 rptr = &meth->restrictions[i];
00470 rtmp = (RESTRICTION *) params->argList;
00471 rptr->query = PackExpression(theEnv,rtmp->query);
00472 rptr->tcnt = rtmp->tcnt;
00473 if (copyRestricts)
00474 {
00475 if (rtmp->types != NULL)
00476 {
00477 rptr->types = (void **) gm2(theEnv,(rptr->tcnt * sizeof(void *)));
00478 GenCopyMemory(void *,rptr->tcnt,rptr->types,rtmp->types);
00479 }
00480 else
00481 rptr->types = NULL;
00482 }
00483 else
00484 {
00485 rptr->types = rtmp->types;
00486
00487
00488
00489
00490
00491 rtmp->tcnt = 0;
00492 rtmp->types = NULL;
00493 }
00494 ExpressionInstall(theEnv,rptr->query);
00495 for (j = 0 ; j < rptr->tcnt ; j++)
00496 #if OBJECT_SYSTEM
00497 IncrementDefclassBusyCount(theEnv,rptr->types[j]);
00498 #else
00499 IncrementIntegerCount((INTEGER_HN *) rptr->types[j]);
00500 #endif
00501 params = params->nextArg;
00502 }
00503 RestoreBusyCount(gfunc);
00504 return(meth);
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518 globle void PackRestrictionTypes(
00519 void *theEnv,
00520 RESTRICTION *rptr,
00521 EXPRESSION *types)
00522 {
00523 EXPRESSION *tmp;
00524 long i;
00525
00526 rptr->tcnt = 0;
00527 for (tmp = types ; tmp != NULL ; tmp = tmp->nextArg)
00528 rptr->tcnt++;
00529 if (rptr->tcnt != 0)
00530 rptr->types = (void **) gm2(theEnv,(sizeof(void *) * rptr->tcnt));
00531 else
00532 rptr->types = NULL;
00533 for (i = 0 , tmp = types ; i < rptr->tcnt ; i++ , tmp = tmp->nextArg)
00534 rptr->types[i] = (void *) tmp->value;
00535 ReturnExpression(theEnv,types);
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 globle void DeleteTempRestricts(
00548 void *theEnv,
00549 EXPRESSION *phead)
00550 {
00551 EXPRESSION *ptmp;
00552 RESTRICTION *rtmp;
00553
00554 while (phead != NULL)
00555 {
00556 ptmp = phead;
00557 phead = phead->nextArg;
00558 rtmp = (RESTRICTION *) ptmp->argList;
00559 rtn_struct(theEnv,expr,ptmp);
00560 ReturnExpression(theEnv,rtmp->query);
00561 if (rtmp->tcnt != 0)
00562 rm(theEnv,(void *) rtmp->types,(sizeof(void *) * rtmp->tcnt));
00563 rtn_struct(theEnv,restriction,rtmp);
00564 }
00565 }
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585 globle DEFMETHOD *FindMethodByRestrictions(
00586 DEFGENERIC *gfunc,
00587 EXPRESSION *params,
00588 int rcnt,
00589 SYMBOL_HN *wildcard,
00590 int *posn)
00591 {
00592 register int i,cmp;
00593 int min,max;
00594
00595 if (wildcard != NULL)
00596 {
00597 min = rcnt-1;
00598 max = -1;
00599 }
00600 else
00601 min = max = rcnt;
00602 for (i = 0 ; i < gfunc->mcnt ; i++)
00603 {
00604 cmp = RestrictionsCompare(params,rcnt,min,max,&gfunc->methods[i]);
00605 if (cmp == IDENTICAL)
00606 {
00607 *posn = -1;
00608 return(&gfunc->methods[i]);
00609 }
00610 else if (cmp == HIGHER_PRECEDENCE)
00611 {
00612 *posn = i;
00613 return(NULL);
00614 }
00615 }
00616 *posn = i;
00617 return(NULL);
00618 }
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638 static intBool ValidGenericName(
00639 void *theEnv,
00640 char *theDefgenericName)
00641 {
00642 struct constructHeader *theDefgeneric;
00643 #if DEFFUNCTION_CONSTRUCT
00644 struct defmodule *theModule;
00645 struct constructHeader *theDeffunction;
00646 #endif
00647 struct FunctionDefinition *systemFunction;
00648
00649
00650
00651
00652
00653 if (FindConstruct(theEnv,theDefgenericName) != NULL)
00654 {
00655 PrintErrorID(theEnv,"GENRCPSR",3,FALSE);
00656 EnvPrintRouter(theEnv,WERROR,"Defgenerics are not allowed to replace constructs.\n");
00657 return(FALSE);
00658 }
00659
00660 #if DEFFUNCTION_CONSTRUCT
00661
00662
00663
00664
00665
00666 theDeffunction =
00667 (struct constructHeader *) LookupDeffunctionInScope(theEnv,theDefgenericName);
00668 if (theDeffunction != NULL)
00669 {
00670 theModule = GetConstructModuleItem(theDeffunction)->theModule;
00671 if (theModule != ((struct defmodule *) EnvGetCurrentModule(theEnv)))
00672 {
00673 PrintErrorID(theEnv,"GENRCPSR",4,FALSE);
00674 EnvPrintRouter(theEnv,WERROR,"Deffunction ");
00675 EnvPrintRouter(theEnv,WERROR,EnvGetDeffunctionName(theEnv,(void *) theDeffunction));
00676 EnvPrintRouter(theEnv,WERROR," imported from module ");
00677 EnvPrintRouter(theEnv,WERROR,EnvGetDefmoduleName(theEnv,(void *) theModule));
00678 EnvPrintRouter(theEnv,WERROR," conflicts with this defgeneric.\n");
00679 return(FALSE);
00680 }
00681 else
00682 {
00683 PrintErrorID(theEnv,"GENRCPSR",5,FALSE);
00684 EnvPrintRouter(theEnv,WERROR,"Defgenerics are not allowed to replace deffunctions.\n");
00685 }
00686 return(FALSE);
00687 }
00688 #endif
00689
00690
00691
00692
00693
00694 theDefgeneric = (struct constructHeader *) EnvFindDefgeneric(theEnv,theDefgenericName);
00695 if (theDefgeneric != NULL)
00696 {
00697
00698
00699
00700
00701
00702 if (MethodsExecuting((DEFGENERIC *) theDefgeneric))
00703 {
00704 MethodAlterError(theEnv,(DEFGENERIC *) theDefgeneric);
00705 return(FALSE);
00706 }
00707 }
00708
00709
00710
00711
00712
00713 systemFunction = FindFunction(theEnv,theDefgenericName);
00714 if ((systemFunction != NULL) ?
00715 (systemFunction->overloadable == FALSE) : FALSE)
00716 {
00717 PrintErrorID(theEnv,"GENRCPSR",16,FALSE);
00718 EnvPrintRouter(theEnv,WERROR,"The system function ");
00719 EnvPrintRouter(theEnv,WERROR,theDefgenericName);
00720 EnvPrintRouter(theEnv,WERROR," cannot be overloaded.\n");
00721 return(FALSE);
00722 }
00723 return(TRUE);
00724 }
00725
00726 #if DEBUGGING_FUNCTIONS
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740 static void CreateDefaultGenericPPForm(
00741 void *theEnv,
00742 DEFGENERIC *gfunc)
00743 {
00744 char *moduleName,*genericName,*buf;
00745
00746 moduleName = EnvGetDefmoduleName(theEnv,(void *) ((struct defmodule *) EnvGetCurrentModule(theEnv)));
00747 genericName = EnvGetDefgenericName(theEnv,(void *) gfunc);
00748 buf = (char *) gm2(theEnv,(sizeof(char) * (strlen(moduleName) + strlen(genericName) + 17)));
00749 gensprintf(buf,"(defgeneric %s::%s)\n",moduleName,genericName);
00750 SetDefgenericPPForm((void *) gfunc,buf);
00751 }
00752
00753 #endif
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766 static SYMBOL_HN *ParseMethodNameAndIndex(
00767 void *theEnv,
00768 char *readSource,
00769 int *theIndex)
00770 {
00771 SYMBOL_HN *gname;
00772
00773 *theIndex = 0;
00774 gname = GetConstructNameAndComment(theEnv,readSource,&DefgenericData(theEnv)->GenericInputToken,"defgeneric",
00775 EnvFindDefgeneric,NULL,"&",TRUE,FALSE,TRUE);
00776 if (gname == NULL)
00777 return(NULL);
00778 if (GetType(DefgenericData(theEnv)->GenericInputToken) == INTEGER)
00779 {
00780 int tmp;
00781
00782 PPBackup(theEnv);
00783 PPBackup(theEnv);
00784 SavePPBuffer(theEnv," ");
00785 SavePPBuffer(theEnv,DefgenericData(theEnv)->GenericInputToken.printForm);
00786 tmp = (int) ValueToLong(GetValue(DefgenericData(theEnv)->GenericInputToken));
00787 if (tmp < 1)
00788 {
00789 PrintErrorID(theEnv,"GENRCPSR",6,FALSE);
00790 EnvPrintRouter(theEnv,WERROR,"Method index out of range.\n");
00791 return(NULL);
00792 }
00793 *theIndex = tmp;
00794 PPCRAndIndent(theEnv);
00795 GetToken(theEnv,readSource,&DefgenericData(theEnv)->GenericInputToken);
00796 }
00797 if (GetType(DefgenericData(theEnv)->GenericInputToken) == STRING)
00798 {
00799 PPBackup(theEnv);
00800 PPBackup(theEnv);
00801 SavePPBuffer(theEnv," ");
00802 SavePPBuffer(theEnv,DefgenericData(theEnv)->GenericInputToken.printForm);
00803 PPCRAndIndent(theEnv);
00804 GetToken(theEnv,readSource,&DefgenericData(theEnv)->GenericInputToken);
00805 }
00806 return(gname);
00807 }
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825 static int ParseMethodParameters(
00826 void *theEnv,
00827 char *readSource,
00828 EXPRESSION **params,
00829 SYMBOL_HN **wildcard)
00830 {
00831 EXPRESSION *phead = NULL,*pprv;
00832 SYMBOL_HN *pname;
00833 RESTRICTION *rtmp;
00834 int rcnt = 0;
00835
00836 *wildcard = NULL;
00837 *params = NULL;
00838 if (GetType(DefgenericData(theEnv)->GenericInputToken) != LPAREN)
00839 {
00840 PrintErrorID(theEnv,"GENRCPSR",7,FALSE);
00841 EnvPrintRouter(theEnv,WERROR,"Expected a '(' to begin method parameter restrictions.\n");
00842 return(-1);
00843 }
00844 GetToken(theEnv,readSource,&DefgenericData(theEnv)->GenericInputToken);
00845 while (DefgenericData(theEnv)->GenericInputToken.type != RPAREN)
00846 {
00847 if (*wildcard != NULL)
00848 {
00849 DeleteTempRestricts(theEnv,phead);
00850 PrintErrorID(theEnv,"PRCCODE",8,FALSE);
00851 EnvPrintRouter(theEnv,WERROR,"No parameters allowed after wildcard parameter.\n");
00852 return(-1);
00853 }
00854 if ((DefgenericData(theEnv)->GenericInputToken.type == SF_VARIABLE) || (DefgenericData(theEnv)->GenericInputToken.type == MF_VARIABLE))
00855 {
00856 pname = (SYMBOL_HN *) DefgenericData(theEnv)->GenericInputToken.value;
00857 if (DuplicateParameters(theEnv,phead,&pprv,pname))
00858 {
00859 DeleteTempRestricts(theEnv,phead);
00860 return(-1);
00861 }
00862 if (DefgenericData(theEnv)->GenericInputToken.type == MF_VARIABLE)
00863 *wildcard = pname;
00864 rtmp = get_struct(theEnv,restriction);
00865 PackRestrictionTypes(theEnv,rtmp,NULL);
00866 rtmp->query = NULL;
00867 phead = AddParameter(theEnv,phead,pprv,pname,rtmp);
00868 rcnt++;
00869 }
00870 else if (DefgenericData(theEnv)->GenericInputToken.type == LPAREN)
00871 {
00872 GetToken(theEnv,readSource,&DefgenericData(theEnv)->GenericInputToken);
00873 if ((DefgenericData(theEnv)->GenericInputToken.type != SF_VARIABLE) &&
00874 (DefgenericData(theEnv)->GenericInputToken.type != MF_VARIABLE))
00875 {
00876 DeleteTempRestricts(theEnv,phead);
00877 PrintErrorID(theEnv,"GENRCPSR",8,FALSE);
00878 EnvPrintRouter(theEnv,WERROR,"Expected a variable for parameter specification.\n");
00879 return(-1);
00880 }
00881 pname = (SYMBOL_HN *) DefgenericData(theEnv)->GenericInputToken.value;
00882 if (DuplicateParameters(theEnv,phead,&pprv,pname))
00883 {
00884 DeleteTempRestricts(theEnv,phead);
00885 return(-1);
00886 }
00887 if (DefgenericData(theEnv)->GenericInputToken.type == MF_VARIABLE)
00888 *wildcard = pname;
00889 SavePPBuffer(theEnv," ");
00890 rtmp = ParseRestriction(theEnv,readSource);
00891 if (rtmp == NULL)
00892 {
00893 DeleteTempRestricts(theEnv,phead);
00894 return(-1);
00895 }
00896 phead = AddParameter(theEnv,phead,pprv,pname,rtmp);
00897 rcnt++;
00898 }
00899 else
00900 {
00901 DeleteTempRestricts(theEnv,phead);
00902 PrintErrorID(theEnv,"GENRCPSR",9,FALSE);
00903 EnvPrintRouter(theEnv,WERROR,"Expected a variable or '(' for parameter specification.\n");
00904 return(-1);
00905 }
00906 PPCRAndIndent(theEnv);
00907 GetToken(theEnv,readSource,&DefgenericData(theEnv)->GenericInputToken);
00908 }
00909 if (rcnt != 0)
00910 {
00911 PPBackup(theEnv);
00912 PPBackup(theEnv);
00913 SavePPBuffer(theEnv,")");
00914 }
00915 *params = phead;
00916 return(rcnt);
00917 }
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938 static RESTRICTION *ParseRestriction(
00939 void *theEnv,
00940 char *readSource)
00941 {
00942 EXPRESSION *types = NULL,*new_types,
00943 *typesbot,*tmp,*tmp2,
00944 *query = NULL;
00945 RESTRICTION *rptr;
00946
00947 GetToken(theEnv,readSource,&DefgenericData(theEnv)->GenericInputToken);
00948 while (DefgenericData(theEnv)->GenericInputToken.type != RPAREN)
00949 {
00950 if (query != NULL)
00951 {
00952 PrintErrorID(theEnv,"GENRCPSR",10,FALSE);
00953 EnvPrintRouter(theEnv,WERROR,"Query must be last in parameter restriction.\n");
00954 ReturnExpression(theEnv,query);
00955 ReturnExpression(theEnv,types);
00956 return(NULL);
00957 }
00958 if (DefgenericData(theEnv)->GenericInputToken.type == SYMBOL)
00959 {
00960 new_types = ValidType(theEnv,(SYMBOL_HN *) DefgenericData(theEnv)->GenericInputToken.value);
00961 if (new_types == NULL)
00962 {
00963 ReturnExpression(theEnv,types);
00964 ReturnExpression(theEnv,query);
00965 return(NULL);
00966 }
00967 if (types == NULL)
00968 types = new_types;
00969 else
00970 {
00971 for (typesbot = tmp = types ; tmp != NULL ; tmp = tmp->nextArg)
00972 {
00973 for (tmp2 = new_types ; tmp2 != NULL ; tmp2 = tmp2->nextArg)
00974 {
00975 if (tmp->value == tmp2->value)
00976 {
00977 PrintErrorID(theEnv,"GENRCPSR",11,FALSE);
00978 #if OBJECT_SYSTEM
00979 EnvPrintRouter(theEnv,WERROR,"Duplicate classes not allowed in parameter restriction.\n");
00980 #else
00981 EnvPrintRouter(theEnv,WERROR,"Duplicate types not allowed in parameter restriction.\n");
00982 #endif
00983 ReturnExpression(theEnv,query);
00984 ReturnExpression(theEnv,types);
00985 ReturnExpression(theEnv,new_types);
00986 return(NULL);
00987 }
00988 if (RedundantClasses(theEnv,tmp->value,tmp2->value))
00989 {
00990 ReturnExpression(theEnv,query);
00991 ReturnExpression(theEnv,types);
00992 ReturnExpression(theEnv,new_types);
00993 return(NULL);
00994 }
00995 }
00996 typesbot = tmp;
00997 }
00998 typesbot->nextArg = new_types;
00999 }
01000 }
01001 else if (DefgenericData(theEnv)->GenericInputToken.type == LPAREN)
01002 {
01003 query = Function1Parse(theEnv,readSource);
01004 if (query == NULL)
01005 {
01006 ReturnExpression(theEnv,types);
01007 return(NULL);
01008 }
01009 if (GetParsedBindNames(theEnv) != NULL)
01010 {
01011 PrintErrorID(theEnv,"GENRCPSR",12,FALSE);
01012 EnvPrintRouter(theEnv,WERROR,"Binds are not allowed in query expressions.\n");
01013 ReturnExpression(theEnv,query);
01014 ReturnExpression(theEnv,types);
01015 return(NULL);
01016 }
01017 }
01018 #if DEFGLOBAL_CONSTRUCT
01019 else if (DefgenericData(theEnv)->GenericInputToken.type == GBL_VARIABLE)
01020 query = GenConstant(theEnv,GBL_VARIABLE,DefgenericData(theEnv)->GenericInputToken.value);
01021 #endif
01022 else
01023 {
01024 PrintErrorID(theEnv,"GENRCPSR",13,FALSE);
01025 #if OBJECT_SYSTEM
01026 EnvPrintRouter(theEnv,WERROR,"Expected a valid class name or query.\n");
01027 #else
01028 EnvPrintRouter(theEnv,WERROR,"Expected a valid type name or query.\n");
01029 #endif
01030 ReturnExpression(theEnv,query);
01031 ReturnExpression(theEnv,types);
01032 return(NULL);
01033 }
01034 SavePPBuffer(theEnv," ");
01035 GetToken(theEnv,readSource,&DefgenericData(theEnv)->GenericInputToken);
01036 }
01037 PPBackup(theEnv);
01038 PPBackup(theEnv);
01039 SavePPBuffer(theEnv,")");
01040 if ((types == NULL) && (query == NULL))
01041 {
01042 PrintErrorID(theEnv,"GENRCPSR",13,FALSE);
01043 #if OBJECT_SYSTEM
01044 EnvPrintRouter(theEnv,WERROR,"Expected a valid class name or query.\n");
01045 #else
01046 EnvPrintRouter(theEnv,WERROR,"Expected a valid type name or query.\n");
01047 #endif
01048 return(NULL);
01049 }
01050 rptr = get_struct(theEnv,restriction);
01051 rptr->query = query;
01052 PackRestrictionTypes(theEnv,rptr,types);
01053 return(rptr);
01054 }
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066 static void ReplaceCurrentArgRefs(
01067 void *theEnv,
01068 EXPRESSION *query)
01069 {
01070 while (query != NULL)
01071 {
01072 if ((query->type != SF_VARIABLE) ? FALSE :
01073 (strcmp(ValueToString(query->value),CURR_ARG_VAR) == 0))
01074 {
01075 query->type = FCALL;
01076 query->value = (void *) FindFunction(theEnv,"(gnrc-current-arg)");
01077 }
01078 if (query->argList != NULL)
01079 ReplaceCurrentArgRefs(theEnv,query->argList);
01080 query = query->nextArg;
01081 }
01082 }
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097 static int DuplicateParameters(
01098 void *theEnv,
01099 EXPRESSION *head,
01100 EXPRESSION **prv,
01101 SYMBOL_HN *name)
01102 {
01103 *prv = NULL;
01104 while (head != NULL)
01105 {
01106 if (head->value == (void *) name)
01107 {
01108 PrintErrorID(theEnv,"PRCCODE",7,FALSE);
01109 EnvPrintRouter(theEnv,WERROR,"Duplicate parameter names not allowed.\n");
01110 return(TRUE);
01111 }
01112 *prv = head;
01113 head = head->nextArg;
01114 }
01115 return(FALSE);
01116 }
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134 static EXPRESSION *AddParameter(
01135 void *theEnv,
01136 EXPRESSION *phead,
01137 EXPRESSION *pprv,
01138 SYMBOL_HN *pname,
01139 RESTRICTION *rptr)
01140 {
01141 EXPRESSION *ptmp;
01142
01143 ptmp = GenConstant(theEnv,SYMBOL,(void *) pname);
01144 if (phead == NULL)
01145 phead = ptmp;
01146 else
01147 pprv->nextArg = ptmp;
01148 ptmp->argList = (EXPRESSION *) rptr;
01149 return(phead);
01150 }
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165 static EXPRESSION *ValidType(
01166 void *theEnv,
01167 SYMBOL_HN *tname)
01168 {
01169 #if OBJECT_SYSTEM
01170 DEFCLASS *cls;
01171
01172 if (FindModuleSeparator(ValueToString(tname)))
01173 IllegalModuleSpecifierMessage(theEnv);
01174 else
01175 {
01176 cls = LookupDefclassInScope(theEnv,ValueToString(tname));
01177 if (cls == NULL)
01178 {
01179 PrintErrorID(theEnv,"GENRCPSR",14,FALSE);
01180 EnvPrintRouter(theEnv,WERROR,"Unknown class in method.\n");
01181 return(NULL);
01182 }
01183 return(GenConstant(theEnv,DEFCLASS_PTR,(void *) cls));
01184 }
01185 #else
01186 if (strcmp(ValueToString(tname),INTEGER_TYPE_NAME) == 0)
01187 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) INTEGER)));
01188 if (strcmp(ValueToString(tname),FLOAT_TYPE_NAME) == 0)
01189 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) FLOAT)));
01190 if (strcmp(ValueToString(tname),SYMBOL_TYPE_NAME) == 0)
01191 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) SYMBOL)));
01192 if (strcmp(ValueToString(tname),STRING_TYPE_NAME) == 0)
01193 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) STRING)));
01194 if (strcmp(ValueToString(tname),MULTIFIELD_TYPE_NAME) == 0)
01195 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) MULTIFIELD)));
01196 if (strcmp(ValueToString(tname),EXTERNAL_ADDRESS_TYPE_NAME) == 0)
01197 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) EXTERNAL_ADDRESS)));
01198 if (strcmp(ValueToString(tname),FACT_ADDRESS_TYPE_NAME) == 0)
01199 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) FACT_ADDRESS)));
01200 if (strcmp(ValueToString(tname),NUMBER_TYPE_NAME) == 0)
01201 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) NUMBER_TYPE_CODE)));
01202 if (strcmp(ValueToString(tname),LEXEME_TYPE_NAME) == 0)
01203 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) LEXEME_TYPE_CODE)));
01204 if (strcmp(ValueToString(tname),ADDRESS_TYPE_NAME) == 0)
01205 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) ADDRESS_TYPE_CODE)));
01206 if (strcmp(ValueToString(tname),PRIMITIVE_TYPE_NAME) == 0)
01207 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) PRIMITIVE_TYPE_CODE)));
01208 if (strcmp(ValueToString(tname),OBJECT_TYPE_NAME) == 0)
01209 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) OBJECT_TYPE_CODE)));
01210 if (strcmp(ValueToString(tname),INSTANCE_TYPE_NAME) == 0)
01211 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) INSTANCE_TYPE_CODE)));
01212 if (strcmp(ValueToString(tname),INSTANCE_NAME_TYPE_NAME) == 0)
01213 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) INSTANCE_NAME)));
01214 if (strcmp(ValueToString(tname),INSTANCE_ADDRESS_TYPE_NAME) == 0)
01215 return(GenConstant(theEnv,INTEGER,(void *) EnvAddLong(theEnv,(long long) INSTANCE_ADDRESS)));
01216
01217 PrintErrorID(theEnv,"GENRCPSR",14,FALSE);
01218 EnvPrintRouter(theEnv,WERROR,"Unknown type in method.\n");
01219 #endif
01220 return(NULL);
01221 }
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234 static intBool RedundantClasses(
01235 void *theEnv,
01236 void *c1,
01237 void *c2)
01238 {
01239 char *tname;
01240
01241 #if OBJECT_SYSTEM
01242 if (HasSuperclass((DEFCLASS *) c1,(DEFCLASS *) c2))
01243 tname = EnvGetDefclassName(theEnv,c1);
01244 else if (HasSuperclass((DEFCLASS *) c2,(DEFCLASS *) c1))
01245 tname = EnvGetDefclassName(theEnv,c2);
01246 #else
01247 if (SubsumeType(ValueToInteger(c1),ValueToInteger(c2)))
01248 tname = TypeName(theEnv,ValueToInteger(c1));
01249 else if (SubsumeType(ValueToInteger(c2),ValueToInteger(c1)))
01250 tname = TypeName(theEnv,ValueToInteger(c2));
01251 #endif
01252 else
01253 return(FALSE);
01254 PrintErrorID(theEnv,"GENRCPSR",15,FALSE);
01255 EnvPrintRouter(theEnv,WERROR,tname);
01256 EnvPrintRouter(theEnv,WERROR," class is redundant.\n");
01257 return(TRUE);
01258 }
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275 static DEFGENERIC *AddGeneric(
01276 void *theEnv,
01277 SYMBOL_HN *name,
01278 int *newGeneric)
01279 {
01280 DEFGENERIC *gfunc;
01281
01282 gfunc = (DEFGENERIC *) EnvFindDefgeneric(theEnv,ValueToString(name));
01283 if (gfunc != NULL)
01284 {
01285 *newGeneric = FALSE;
01286
01287 if (ConstructData(theEnv)->CheckSyntaxMode)
01288 { return(gfunc); }
01289
01290
01291
01292
01293 RemoveConstructFromModule(theEnv,(struct constructHeader *) gfunc);
01294 }
01295 else
01296 {
01297 *newGeneric = TRUE;
01298 gfunc = NewGeneric(theEnv,name);
01299 IncrementSymbolCount(name);
01300 AddImplicitMethods(theEnv,gfunc);
01301 }
01302 AddConstructToModule((struct constructHeader *) gfunc);
01303 return(gfunc);
01304 }
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320 static DEFMETHOD *AddGenericMethod(
01321 void *theEnv,
01322 DEFGENERIC *gfunc,
01323 int mposn,
01324 short mi)
01325 {
01326 DEFMETHOD *narr;
01327 long b, e;
01328
01329 narr = (DEFMETHOD *) gm2(theEnv,(sizeof(DEFMETHOD) * (gfunc->mcnt+1)));
01330 for (b = e = 0 ; b < gfunc->mcnt ; b++ , e++)
01331 {
01332 if (b == mposn)
01333 e++;
01334 GenCopyMemory(DEFMETHOD,1,&narr[e],&gfunc->methods[b]);
01335 }
01336 if (mi == 0)
01337 narr[mposn].index = gfunc->new_index++;
01338 else
01339 {
01340 narr[mposn].index = mi;
01341 if (mi >= gfunc->new_index)
01342 gfunc->new_index = (short) (mi+1);
01343 }
01344 narr[mposn].busy = 0;
01345 #if DEBUGGING_FUNCTIONS
01346 narr[mposn].trace = DefgenericData(theEnv)->WatchMethods;
01347 #endif
01348 narr[mposn].minRestrictions = 0;
01349 narr[mposn].maxRestrictions = 0;
01350 narr[mposn].restrictionCount = 0;
01351 narr[mposn].localVarCount = 0;
01352 narr[mposn].system = 0;
01353 narr[mposn].restrictions = NULL;
01354 narr[mposn].actions = NULL;
01355 narr[mposn].ppForm = NULL;
01356 narr[mposn].usrData = NULL;
01357 if (gfunc->mcnt != 0)
01358 rm(theEnv,(void *) gfunc->methods,(sizeof(DEFMETHOD) * gfunc->mcnt));
01359 gfunc->mcnt++;
01360 gfunc->methods = narr;
01361 return(&narr[mposn]);
01362 }
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383 static int RestrictionsCompare(
01384 EXPRESSION *params,
01385 int rcnt,
01386 int min,
01387 int max,
01388 DEFMETHOD *meth)
01389 {
01390 register int i;
01391 register RESTRICTION *r1,*r2;
01392 int diff = FALSE,rtn;
01393
01394 for (i = 0 ; (i < rcnt) && (i < meth->restrictionCount) ; i++)
01395 {
01396
01397
01398
01399
01400 if ((i == rcnt-1) && (max == -1) &&
01401 (meth->maxRestrictions != -1))
01402 return(LOWER_PRECEDENCE);
01403 if ((i == meth->restrictionCount-1) && (max != -1) &&
01404 (meth->maxRestrictions == -1))
01405 return(HIGHER_PRECEDENCE);
01406
01407
01408
01409
01410 r1 = (RESTRICTION *) params->argList;
01411 r2 = &meth->restrictions[i];
01412 rtn = TypeListCompare(r1,r2);
01413 if (rtn != IDENTICAL)
01414 return(rtn);
01415
01416
01417
01418
01419 if ((r1->query == NULL) && (r2->query != NULL))
01420 return(LOWER_PRECEDENCE);
01421 if ((r1->query != NULL) && (r2->query == NULL))
01422 return(HIGHER_PRECEDENCE);
01423
01424
01425
01426
01427
01428
01429 if (IdenticalExpression(r1->query,r2->query) == FALSE)
01430 diff = TRUE;
01431 params = params->nextArg;
01432 }
01433
01434
01435
01436
01437
01438
01439 if (rcnt == meth->restrictionCount)
01440 return(diff ? LOWER_PRECEDENCE : IDENTICAL);
01441
01442
01443
01444
01445
01446
01447
01448
01449 if (min > meth->minRestrictions)
01450 return(HIGHER_PRECEDENCE);
01451 if (meth->minRestrictions < min)
01452 return(LOWER_PRECEDENCE);
01453 return((max == - 1) ? LOWER_PRECEDENCE : HIGHER_PRECEDENCE);
01454 }
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468 static int TypeListCompare(
01469 RESTRICTION *r1,
01470 RESTRICTION *r2)
01471 {
01472 long i;
01473 int diff = FALSE;
01474
01475 if ((r1->tcnt == 0) && (r2->tcnt == 0))
01476 return(IDENTICAL);
01477 if (r1->tcnt == 0)
01478 return(LOWER_PRECEDENCE);
01479 if (r2->tcnt == 0)
01480 return(HIGHER_PRECEDENCE);
01481 for (i = 0 ; (i < r1->tcnt) && (i < r2->tcnt) ; i++)
01482 {
01483 if (r1->types[i] != r2->types[i])
01484 {
01485 diff = TRUE;
01486 #if OBJECT_SYSTEM
01487 if (HasSuperclass((DEFCLASS *) r1->types[i],(DEFCLASS *) r2->types[i]))
01488 return(HIGHER_PRECEDENCE);
01489 if (HasSuperclass((DEFCLASS *) r2->types[i],(DEFCLASS *) r1->types[i]))
01490 return(LOWER_PRECEDENCE);
01491 #else
01492 if (SubsumeType(ValueToInteger(r1->types[i]),ValueToInteger(r2->types[i])))
01493 return(HIGHER_PRECEDENCE);
01494 if (SubsumeType(ValueToInteger(r2->types[i]),ValueToInteger(r1->types[i])))
01495 return(LOWER_PRECEDENCE);
01496 #endif
01497 }
01498 }
01499 if (r1->tcnt < r2->tcnt)
01500 return(HIGHER_PRECEDENCE);
01501 if (r1->tcnt > r2->tcnt)
01502 return(LOWER_PRECEDENCE);
01503 if (diff)
01504 return(LOWER_PRECEDENCE);
01505 return(IDENTICAL);
01506 }
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517 static DEFGENERIC *NewGeneric(
01518 void *theEnv,
01519 SYMBOL_HN *gname)
01520 {
01521 DEFGENERIC *ngen;
01522
01523 ngen = get_struct(theEnv,defgeneric);
01524 InitializeConstructHeader(theEnv,"defgeneric",(struct constructHeader *) ngen,gname);
01525 ngen->busy = 0;
01526 ngen->new_index = 1;
01527 ngen->methods = NULL;
01528 ngen->mcnt = 0;
01529 #if DEBUGGING_FUNCTIONS
01530 ngen->trace = DefgenericData(theEnv)->WatchGenerics;
01531 #endif
01532 return(ngen);
01533 }
01534
01535 #endif
01536
01537
01538
01539
01540
01541
01542
01543
01544