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
00034
00035 #define _TMPLTFUN_SOURCE_
00036
00037 #include "setup.h"
00038
00039 #if DEFTEMPLATE_CONSTRUCT
00040
00041 #include <stdio.h>
00042 #define _STDIO_INCLUDED_
00043 #include <string.h>
00044
00045 #include "constant.h"
00046 #include "memalloc.h"
00047 #include "symbol.h"
00048 #include "scanner.h"
00049 #include "exprnpsr.h"
00050 #include "envrnmnt.h"
00051 #include "argacces.h"
00052 #include "router.h"
00053 #include "cstrnchk.h"
00054 #include "default.h"
00055 #include "factmngr.h"
00056 #include "commline.h"
00057 #include "factrhs.h"
00058 #include "modulutl.h"
00059 #include "reorder.h"
00060 #include "sysdep.h"
00061 #include "tmpltdef.h"
00062 #include "tmpltlhs.h"
00063 #include "tmpltutl.h"
00064 #include "tmpltrhs.h"
00065
00066 #include "tmpltfun.h"
00067
00068
00069
00070
00071
00072 static void DuplicateModifyCommand(void *,int,DATA_OBJECT_PTR);
00073 static SYMBOL_HN *CheckDeftemplateAndSlotArguments(void *,char *,struct deftemplate **,int);
00074
00075 #if (! RUN_TIME) && (! BLOAD_ONLY)
00076 static struct expr *ModAndDupParse(void *,struct expr *,char *,char *);
00077 static SYMBOL_HN *FindTemplateForFactAddress(SYMBOL_HN *,struct lhsParseNode *);
00078 #endif
00079
00080
00081
00082
00083 globle void DeftemplateFunctions(
00084 void *theEnv)
00085 {
00086 #if ! RUN_TIME
00087 EnvDefineFunction(theEnv,"modify",'u', PTIEF ModifyCommand,"ModifyCommand");
00088 EnvDefineFunction(theEnv,"duplicate",'u', PTIEF DuplicateCommand,"DuplicateCommand");
00089
00090 EnvDefineFunction2(theEnv,"deftemplate-slot-names",'u', PTIEF DeftemplateSlotNamesFunction,
00091 "DeftemplateSlotNamesFunction", "11z");
00092 EnvDefineFunction2(theEnv,"deftemplate-slot-default-value",'u',PTIEF DeftemplateSlotDefaultValueFunction,
00093 "DeftemplateSlotDefaultValueFunction","22w");
00094 EnvDefineFunction2(theEnv,"deftemplate-slot-cardinality",'u',PTIEF DeftemplateSlotCardinalityFunction,
00095 "DeftemplateSlotCardinalityFunction","22w");
00096 EnvDefineFunction2(theEnv,"deftemplate-slot-allowed-values",'u',PTIEF DeftemplateSlotAllowedValuesFunction,
00097 "DeftemplateSlotAllowedValuesFunction","22w");
00098 EnvDefineFunction2(theEnv,"deftemplate-slot-range",'u',PTIEF DeftemplateSlotRangeFunction,
00099 "DeftemplateSlotRangeFunction","22w");
00100 EnvDefineFunction2(theEnv,"deftemplate-slot-types",'u',PTIEF DeftemplateSlotTypesFunction,
00101 "DeftemplateSlotTypesFunction","22w");
00102
00103 EnvDefineFunction2(theEnv,"deftemplate-slot-multip",'b',PTIEF DeftemplateSlotMultiPFunction,
00104 "DeftemplateSlotMultiPFunction","22w");
00105 EnvDefineFunction2(theEnv,"deftemplate-slot-singlep",'b',PTIEF DeftemplateSlotSinglePFunction,
00106 "DeftemplateSlotSinglePFunction","22w");
00107 EnvDefineFunction2(theEnv,"deftemplate-slot-existp",'b',PTIEF DeftemplateSlotExistPFunction,
00108 "DeftemplateSlotExistPFunction","22w");
00109 EnvDefineFunction2(theEnv,"deftemplate-slot-defaultp",'w',PTIEF DeftemplateSlotDefaultPFunction,
00110 "DeftemplateSlotDefaultPFunction","22w");
00111
00112 EnvDefineFunction2(theEnv,"deftemplate-slot-facet-existp",'b',PTIEF DeftemplateSlotFacetExistPFunction,
00113 "DeftemplateSlotFacetExistPFunction","33w");
00114
00115 EnvDefineFunction2(theEnv,"deftemplate-slot-facet-value",'u',PTIEF DeftemplateSlotFacetValueFunction,
00116 "DeftemplateSlotFacetValueFunction","33w");
00117
00118 #if (! BLOAD_ONLY)
00119 AddFunctionParser(theEnv,"modify",ModifyParse);
00120 AddFunctionParser(theEnv,"duplicate",DuplicateParse);
00121 #endif
00122 FuncSeqOvlFlags(theEnv,"modify",FALSE,FALSE);
00123 FuncSeqOvlFlags(theEnv,"duplicate",FALSE,FALSE);
00124 #else
00125 #if MAC_MCW || WIN_MCW || MAC_XCD
00126 #pragma unused(theEnv)
00127 #endif
00128 #endif
00129 }
00130
00131
00132
00133
00134
00135 globle void ModifyCommand(
00136 void *theEnv,
00137 DATA_OBJECT_PTR returnValue)
00138 {
00139 DuplicateModifyCommand(theEnv,TRUE,returnValue);
00140 }
00141
00142
00143
00144
00145
00146 globle void DuplicateCommand(
00147 void *theEnv,
00148 DATA_OBJECT_PTR returnValue)
00149 {
00150 DuplicateModifyCommand(theEnv,FALSE,returnValue);
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 static void DuplicateModifyCommand(
00162 void *theEnv,
00163 int retractIt,
00164 DATA_OBJECT_PTR returnValue)
00165 {
00166 long long factNum;
00167 struct fact *oldFact, *newFact, *theFact;
00168 struct expr *testPtr;
00169 DATA_OBJECT computeResult;
00170 struct deftemplate *templatePtr;
00171 struct templateSlot *slotPtr;
00172 int i, position, found;
00173
00174
00175
00176
00177
00178 SetpType(returnValue,SYMBOL);
00179 SetpValue(returnValue,EnvFalseSymbol(theEnv));
00180
00181
00182
00183
00184
00185
00186 testPtr = GetFirstArgument();
00187 EvaluateExpression(theEnv,testPtr,&computeResult);
00188
00189
00190
00191
00192
00193
00194 if (computeResult.type == INTEGER)
00195 {
00196 factNum = ValueToLong(computeResult.value);
00197 if (factNum < 0)
00198 {
00199 if (retractIt) ExpectedTypeError2(theEnv,"modify",1);
00200 else ExpectedTypeError2(theEnv,"duplicate",1);
00201 SetEvaluationError(theEnv,TRUE);
00202 return;
00203 }
00204
00205 oldFact = (struct fact *) EnvGetNextFact(theEnv,NULL);
00206 while (oldFact != NULL)
00207 {
00208 if (oldFact->factIndex == factNum)
00209 { break; }
00210 else
00211 { oldFact = oldFact->nextFact; }
00212 }
00213
00214 if (oldFact == NULL)
00215 {
00216 char tempBuffer[20];
00217 gensprintf(tempBuffer,"f-%lld",factNum);
00218 CantFindItemErrorMessage(theEnv,"fact",tempBuffer);
00219 return;
00220 }
00221 }
00222
00223
00224
00225
00226
00227
00228 else if (computeResult.type == FACT_ADDRESS)
00229 { oldFact = (struct fact *) computeResult.value; }
00230
00231
00232
00233
00234
00235 else
00236 {
00237 if (retractIt) ExpectedTypeError2(theEnv,"modify",1);
00238 else ExpectedTypeError2(theEnv,"duplicate",1);
00239 SetEvaluationError(theEnv,TRUE);
00240 return;
00241 }
00242
00243
00244
00245
00246
00247 templatePtr = oldFact->whichDeftemplate;
00248
00249 if (templatePtr->implied) return;
00250
00251
00252
00253
00254
00255 newFact = (struct fact *) CreateFactBySize(theEnv,oldFact->theProposition.multifieldLength);
00256 newFact->whichDeftemplate = templatePtr;
00257 for (i = 0; i < (int) oldFact->theProposition.multifieldLength; i++)
00258 {
00259 newFact->theProposition.theFields[i].type = oldFact->theProposition.theFields[i].type;
00260 if (newFact->theProposition.theFields[i].type != MULTIFIELD)
00261 { newFact->theProposition.theFields[i].value = oldFact->theProposition.theFields[i].value; }
00262 else
00263 { newFact->theProposition.theFields[i].value = NULL; }
00264 }
00265
00266
00267
00268
00269
00270 testPtr = testPtr->nextArg;
00271 while (testPtr != NULL)
00272 {
00273
00274
00275
00276
00277
00278
00279
00280
00281 if (testPtr->type == INTEGER)
00282 { position = (int) ValueToLong(testPtr->value); }
00283 else
00284 {
00285 found = FALSE;
00286 position = 0;
00287 slotPtr = templatePtr->slotList;
00288 while (slotPtr != NULL)
00289 {
00290 if (slotPtr->slotName == (SYMBOL_HN *) testPtr->value)
00291 {
00292 found = TRUE;
00293 slotPtr = NULL;
00294 }
00295 else
00296 {
00297 slotPtr = slotPtr->next;
00298 position++;
00299 }
00300 }
00301
00302 if (! found)
00303 {
00304 InvalidDeftemplateSlotMessage(theEnv,ValueToString(testPtr->value),
00305 ValueToString(templatePtr->header.name),TRUE);
00306 SetEvaluationError(theEnv,TRUE);
00307 ReturnFact(theEnv,newFact);
00308 return;
00309 }
00310 }
00311
00312
00313
00314
00315
00316 if (newFact->theProposition.theFields[position].type != MULTIFIELD)
00317 {
00318
00319
00320
00321
00322
00323
00324
00325 if ((testPtr->argList == NULL) ? TRUE : (testPtr->argList->nextArg != NULL))
00326 {
00327 MultiIntoSingleFieldSlotError(theEnv,GetNthSlot(templatePtr,position),templatePtr);
00328 ReturnFact(theEnv,newFact);
00329 return;
00330 }
00331
00332
00333
00334
00335
00336 EvaluateExpression(theEnv,testPtr->argList,&computeResult);
00337 SetEvaluationError(theEnv,FALSE);
00338
00339
00340
00341
00342
00343
00344
00345 if (computeResult.type == MULTIFIELD)
00346 {
00347 ReturnFact(theEnv,newFact);
00348 MultiIntoSingleFieldSlotError(theEnv,GetNthSlot(templatePtr,position),templatePtr);
00349 return;
00350 }
00351
00352
00353
00354
00355
00356 newFact->theProposition.theFields[position].type =
00357 computeResult.type;
00358 newFact->theProposition.theFields[position].value =
00359 computeResult.value;
00360 }
00361
00362
00363
00364
00365
00366 else
00367 {
00368
00369
00370
00371
00372 StoreInMultifield(theEnv,&computeResult,testPtr->argList,FALSE);
00373 SetEvaluationError(theEnv,FALSE);
00374
00375
00376
00377
00378
00379 newFact->theProposition.theFields[position].type =
00380 computeResult.type;
00381 newFact->theProposition.theFields[position].value =
00382 computeResult.value;
00383 }
00384
00385 testPtr = testPtr->nextArg;
00386 }
00387
00388
00389
00390
00391
00392
00393 for (i = 0; i < (int) oldFact->theProposition.multifieldLength; i++)
00394 {
00395 if ((newFact->theProposition.theFields[i].type == MULTIFIELD) &&
00396 (newFact->theProposition.theFields[i].value == NULL))
00397
00398 {
00399 newFact->theProposition.theFields[i].value =
00400 CopyMultifield(theEnv,(struct multifield *) oldFact->theProposition.theFields[i].value);
00401 }
00402 }
00403
00404
00405
00406
00407
00408 if (retractIt) EnvRetract(theEnv,oldFact);
00409 theFact = (struct fact *) EnvAssert(theEnv,newFact);
00410
00411
00412
00413
00414
00415 if (theFact != NULL)
00416 {
00417 SetpDOBegin(returnValue,1);
00418 SetpDOEnd(returnValue,theFact->theProposition.multifieldLength);
00419 SetpType(returnValue,FACT_ADDRESS);
00420 SetpValue(returnValue,(void *) theFact);
00421 }
00422
00423 return;
00424 }
00425
00426
00427
00428
00429
00430 globle void DeftemplateSlotNamesFunction(
00431 void *theEnv,
00432 DATA_OBJECT *returnValue)
00433 {
00434 char *deftemplateName;
00435 struct deftemplate *theDeftemplate;
00436
00437
00438
00439
00440
00441 returnValue->type = SYMBOL;
00442 returnValue->value = EnvFalseSymbol(theEnv);
00443
00444
00445
00446
00447
00448 if (EnvArgCountCheck(theEnv,"deftemplate-slot-names",EXACTLY,1) == -1) return;
00449
00450
00451
00452
00453
00454 deftemplateName = GetConstructName(theEnv,"deftemplate-slot-names","deftemplate name");
00455 if (deftemplateName == NULL) return;
00456
00457 theDeftemplate = (struct deftemplate *) EnvFindDeftemplate(theEnv,deftemplateName);
00458 if (theDeftemplate == NULL)
00459 {
00460 CantFindItemErrorMessage(theEnv,"deftemplate",deftemplateName);
00461 return;
00462 }
00463
00464
00465
00466
00467
00468 EnvDeftemplateSlotNames(theEnv,theDeftemplate,returnValue);
00469 }
00470
00471
00472
00473
00474
00475 globle void EnvDeftemplateSlotNames(
00476 void *theEnv,
00477 void *vTheDeftemplate,
00478 DATA_OBJECT *returnValue)
00479 {
00480 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
00481 struct multifield *theList;
00482 struct templateSlot *theSlot;
00483 unsigned long count;
00484
00485
00486
00487
00488
00489
00490 if (theDeftemplate->implied)
00491 {
00492 SetpType(returnValue,MULTIFIELD);
00493 SetpDOBegin(returnValue,1);
00494 SetpDOEnd(returnValue,1);
00495 theList = (struct multifield *) EnvCreateMultifield(theEnv,(int) 1);
00496 SetMFType(theList,1,SYMBOL);
00497 SetMFValue(theList,1,EnvAddSymbol(theEnv,"implied"));
00498 SetpValue(returnValue,(void *) theList);
00499 return;
00500 }
00501
00502
00503
00504
00505
00506 for (count = 0, theSlot = theDeftemplate->slotList;
00507 theSlot != NULL;
00508 count++, theSlot = theSlot->next)
00509 { }
00510
00511
00512
00513
00514
00515 SetpType(returnValue,MULTIFIELD);
00516 SetpDOBegin(returnValue,1);
00517 SetpDOEnd(returnValue,(long) count);
00518 theList = (struct multifield *) EnvCreateMultifield(theEnv,count);
00519 SetpValue(returnValue,(void *) theList);
00520
00521
00522
00523
00524
00525 for (count = 1, theSlot = theDeftemplate->slotList;
00526 theSlot != NULL;
00527 count++, theSlot = theSlot->next)
00528 {
00529 SetMFType(theList,count,SYMBOL);
00530 SetMFValue(theList,count,theSlot->slotName);
00531 }
00532 }
00533
00534
00535
00536
00537
00538 globle void *DeftemplateSlotDefaultPFunction(
00539 void *theEnv)
00540 {
00541 struct deftemplate *theDeftemplate;
00542 SYMBOL_HN *slotName;
00543 int defaultType;
00544
00545
00546
00547
00548
00549 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-existp",&theDeftemplate,2);
00550 if (slotName == NULL)
00551 { return(EnvFalseSymbol(theEnv)); }
00552
00553
00554
00555
00556
00557 defaultType = EnvDeftemplateSlotDefaultP(theEnv,theDeftemplate,ValueToString(slotName));
00558
00559 if (defaultType == STATIC_DEFAULT)
00560 { return(EnvAddSymbol(theEnv,"static")); }
00561 else if (defaultType == DYNAMIC_DEFAULT)
00562 { return(EnvAddSymbol(theEnv,"dynamic")); }
00563
00564 return(EnvFalseSymbol(theEnv));
00565 }
00566
00567
00568
00569
00570
00571 globle int EnvDeftemplateSlotDefaultP(
00572 void *theEnv,
00573 void *vTheDeftemplate,
00574 char *slotName)
00575 {
00576 short position;
00577 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
00578 struct templateSlot *theSlot;
00579
00580
00581
00582
00583
00584
00585 if (theDeftemplate->implied)
00586 {
00587 if (strcmp(slotName,"implied") == 0)
00588 {
00589 return(STATIC_DEFAULT);
00590 }
00591 else
00592 {
00593 SetEvaluationError(theEnv,TRUE);
00594 InvalidDeftemplateSlotMessage(theEnv,slotName,
00595 ValueToString(theDeftemplate->header.name),FALSE);
00596 return(NO_DEFAULT);
00597 }
00598 }
00599
00600
00601
00602
00603
00604
00605 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
00606 {
00607 SetEvaluationError(theEnv,TRUE);
00608 InvalidDeftemplateSlotMessage(theEnv,slotName,
00609 ValueToString(theDeftemplate->header.name),FALSE);
00610 return(NO_DEFAULT);
00611 }
00612
00613
00614
00615
00616
00617 if (theSlot->noDefault)
00618 { return(NO_DEFAULT); }
00619 else if (theSlot->defaultDynamic)
00620 { return(DYNAMIC_DEFAULT); }
00621
00622 return(STATIC_DEFAULT);
00623 }
00624
00625
00626
00627
00628
00629 globle void DeftemplateSlotDefaultValueFunction(
00630 void *theEnv,
00631 DATA_OBJECT_PTR theValue)
00632 {
00633 struct deftemplate *theDeftemplate;
00634 SYMBOL_HN *slotName;
00635
00636
00637
00638
00639
00640 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-default-value",&theDeftemplate,2);
00641 if (slotName == NULL)
00642 {
00643 theValue->type = SYMBOL;
00644 theValue->value = EnvFalseSymbol(theEnv);
00645 return;
00646 }
00647
00648
00649
00650
00651
00652 EnvDeftemplateSlotDefaultValue(theEnv,theDeftemplate,ValueToString(slotName),theValue);
00653 }
00654
00655
00656
00657
00658
00659 globle intBool EnvDeftemplateSlotDefaultValue(
00660 void *theEnv,
00661 void *vTheDeftemplate,
00662 char *slotName,
00663 DATA_OBJECT_PTR theValue)
00664 {
00665 short position;
00666 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
00667 struct templateSlot *theSlot;
00668 DATA_OBJECT tempDO;
00669
00670
00671
00672
00673
00674 SetpType(theValue,SYMBOL);
00675 SetpValue(theValue,EnvFalseSymbol(theEnv));
00676
00677
00678
00679
00680
00681
00682 if (theDeftemplate->implied)
00683 {
00684 if (strcmp(slotName,"implied") == 0)
00685 {
00686 theValue->type = MULTIFIELD;
00687 theValue->value = EnvCreateMultifield(theEnv,0L);
00688 theValue->begin = 1;
00689 theValue->end = 0;
00690 return(TRUE);
00691 }
00692 else
00693 {
00694 SetEvaluationError(theEnv,TRUE);
00695 InvalidDeftemplateSlotMessage(theEnv,slotName,
00696 ValueToString(theDeftemplate->header.name),FALSE);
00697 return(FALSE);
00698 }
00699 }
00700
00701
00702
00703
00704
00705
00706 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
00707 {
00708 SetEvaluationError(theEnv,TRUE);
00709 InvalidDeftemplateSlotMessage(theEnv,slotName,
00710 ValueToString(theDeftemplate->header.name),FALSE);
00711 return(FALSE);
00712 }
00713
00714
00715
00716
00717
00718 if (theSlot->noDefault)
00719 {
00720 SetpType(theValue,SYMBOL);
00721 SetpValue(theValue,EnvAddSymbol(theEnv,"?NONE"));
00722 }
00723 else if (DeftemplateSlotDefault(theEnv,theDeftemplate,theSlot,&tempDO,TRUE))
00724 {
00725 SetpDOBegin(theValue,GetDOBegin(tempDO));
00726 SetpDOEnd(theValue,GetDOEnd(tempDO));
00727 SetpType(theValue,tempDO.type);
00728 SetpValue(theValue,tempDO.value);
00729 }
00730 else
00731 { return (FALSE); }
00732
00733 return(TRUE);
00734 }
00735
00736
00737
00738
00739
00740 globle void DeftemplateSlotCardinalityFunction(
00741 void *theEnv,
00742 DATA_OBJECT_PTR theValue)
00743 {
00744 struct deftemplate *theDeftemplate;
00745 SYMBOL_HN *slotName;
00746
00747
00748
00749
00750
00751 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-cardinality",&theDeftemplate,2);
00752 if (slotName == NULL)
00753 {
00754 EnvSetMultifieldErrorValue(theEnv,theValue);
00755 return;
00756 }
00757
00758
00759
00760
00761
00762 EnvDeftemplateSlotCardinality(theEnv,theDeftemplate,ValueToString(slotName),theValue);
00763 }
00764
00765
00766
00767
00768
00769 globle void EnvDeftemplateSlotCardinality(
00770 void *theEnv,
00771 void *vTheDeftemplate,
00772 char *slotName,
00773 DATA_OBJECT *result)
00774 {
00775 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
00776 short position;
00777 struct templateSlot *theSlot;
00778
00779
00780
00781
00782
00783
00784 if (theDeftemplate->implied)
00785 {
00786 if (strcmp(slotName,"implied") == 0)
00787 {
00788 result->type = MULTIFIELD;
00789 result->begin = 0;
00790 result->end = 1;
00791 result->value = EnvCreateMultifield(theEnv,2L);
00792 SetMFType(result->value,1,INTEGER);
00793 SetMFValue(result->value,1,SymbolData(theEnv)->Zero);
00794 SetMFType(result->value,2,SYMBOL);
00795 SetMFValue(result->value,2,SymbolData(theEnv)->PositiveInfinity);
00796 return;
00797 }
00798 else
00799 {
00800 EnvSetMultifieldErrorValue(theEnv,result);
00801 SetEvaluationError(theEnv,TRUE);
00802 InvalidDeftemplateSlotMessage(theEnv,slotName,
00803 ValueToString(theDeftemplate->header.name),FALSE);
00804 return;
00805 }
00806 }
00807
00808
00809
00810
00811
00812
00813 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
00814 {
00815 EnvSetMultifieldErrorValue(theEnv,result);
00816 SetEvaluationError(theEnv,TRUE);
00817 InvalidDeftemplateSlotMessage(theEnv,slotName,
00818 ValueToString(theDeftemplate->header.name),FALSE);
00819 return;
00820 }
00821
00822
00823
00824
00825
00826 if (theSlot->multislot == 0)
00827 {
00828 EnvSetMultifieldErrorValue(theEnv,result);
00829 return;
00830 }
00831
00832 result->type = MULTIFIELD;
00833 result->begin = 0;
00834 result->end = 1;
00835 result->value = EnvCreateMultifield(theEnv,2L);
00836
00837 if (theSlot->constraints != NULL)
00838 {
00839 SetMFType(result->value,1,theSlot->constraints->minFields->type);
00840 SetMFValue(result->value,1,theSlot->constraints->minFields->value);
00841 SetMFType(result->value,2,theSlot->constraints->maxFields->type);
00842 SetMFValue(result->value,2,theSlot->constraints->maxFields->value);
00843 }
00844 else
00845 {
00846 SetMFType(result->value,1,INTEGER);
00847 SetMFValue(result->value,1,SymbolData(theEnv)->Zero);
00848 SetMFType(result->value,2,SYMBOL);
00849 SetMFValue(result->value,2,SymbolData(theEnv)->PositiveInfinity);
00850 }
00851 }
00852
00853
00854
00855
00856
00857 globle void DeftemplateSlotAllowedValuesFunction(
00858 void *theEnv,
00859 DATA_OBJECT_PTR theValue)
00860 {
00861 struct deftemplate *theDeftemplate;
00862 SYMBOL_HN *slotName;
00863
00864
00865
00866
00867
00868 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-allowed-values",&theDeftemplate,2);
00869 if (slotName == NULL)
00870 {
00871 EnvSetMultifieldErrorValue(theEnv,theValue);
00872 return;
00873 }
00874
00875
00876
00877
00878
00879 EnvDeftemplateSlotAllowedValues(theEnv,theDeftemplate,ValueToString(slotName),theValue);
00880 }
00881
00882
00883
00884
00885
00886 globle void EnvDeftemplateSlotAllowedValues(
00887 void *theEnv,
00888 void *vTheDeftemplate,
00889 char *slotName,
00890 DATA_OBJECT *result)
00891 {
00892 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
00893 short position;
00894 struct templateSlot *theSlot;
00895 int i;
00896 EXPRESSION *theExp;
00897
00898
00899
00900
00901
00902
00903 if (theDeftemplate->implied)
00904 {
00905 if (strcmp(slotName,"implied") == 0)
00906 {
00907 result->type = SYMBOL;
00908 result->value = EnvFalseSymbol(theEnv);
00909 return;
00910 }
00911 else
00912 {
00913 EnvSetMultifieldErrorValue(theEnv,result);
00914 SetEvaluationError(theEnv,TRUE);
00915 InvalidDeftemplateSlotMessage(theEnv,slotName,
00916 ValueToString(theDeftemplate->header.name),FALSE);
00917 return;
00918 }
00919 }
00920
00921
00922
00923
00924
00925
00926 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
00927 {
00928 EnvSetMultifieldErrorValue(theEnv,result);
00929 SetEvaluationError(theEnv,TRUE);
00930 InvalidDeftemplateSlotMessage(theEnv,slotName,
00931 ValueToString(theDeftemplate->header.name),FALSE);
00932 return;
00933 }
00934
00935
00936
00937
00938
00939 if ((theSlot->constraints != NULL) ? (theSlot->constraints->restrictionList == NULL) : TRUE)
00940 {
00941 result->type = SYMBOL;
00942 result->value = EnvFalseSymbol(theEnv);
00943 return;
00944 }
00945
00946 result->type = MULTIFIELD;
00947 result->begin = 0;
00948 result->end = ExpressionSize(theSlot->constraints->restrictionList) - 1;
00949 result->value = EnvCreateMultifield(theEnv,(unsigned long) (result->end + 1));
00950 i = 1;
00951
00952 theExp = theSlot->constraints->restrictionList;
00953 while (theExp != NULL)
00954 {
00955 SetMFType(result->value,i,theExp->type);
00956 SetMFValue(result->value,i,theExp->value);
00957 theExp = theExp->nextArg;
00958 i++;
00959 }
00960 }
00961
00962
00963
00964
00965
00966 globle void DeftemplateSlotRangeFunction(
00967 void *theEnv,
00968 DATA_OBJECT_PTR theValue)
00969 {
00970 struct deftemplate *theDeftemplate;
00971 SYMBOL_HN *slotName;
00972
00973
00974
00975
00976
00977 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-range",&theDeftemplate,2);
00978 if (slotName == NULL)
00979 {
00980 EnvSetMultifieldErrorValue(theEnv,theValue);
00981 return;
00982 }
00983
00984
00985
00986
00987
00988 EnvDeftemplateSlotRange(theEnv,theDeftemplate,ValueToString(slotName),theValue);
00989 }
00990
00991
00992
00993
00994
00995 globle void EnvDeftemplateSlotRange(
00996 void *theEnv,
00997 void *vTheDeftemplate,
00998 char *slotName,
00999 DATA_OBJECT *result)
01000 {
01001 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
01002 short position;
01003 struct templateSlot *theSlot;
01004
01005
01006
01007
01008
01009
01010 if (theDeftemplate->implied)
01011 {
01012 if (strcmp(slotName,"implied") == 0)
01013 {
01014 result->type = MULTIFIELD;
01015 result->begin = 0;
01016 result->end = 1;
01017 result->value = EnvCreateMultifield(theEnv,2L);
01018 SetMFType(result->value,1,SYMBOL);
01019 SetMFValue(result->value,1,SymbolData(theEnv)->NegativeInfinity);
01020 SetMFType(result->value,2,SYMBOL);
01021 SetMFValue(result->value,2,SymbolData(theEnv)->PositiveInfinity);
01022 return;
01023 }
01024 else
01025 {
01026 EnvSetMultifieldErrorValue(theEnv,result);
01027 SetEvaluationError(theEnv,TRUE);
01028 InvalidDeftemplateSlotMessage(theEnv,slotName,
01029 ValueToString(theDeftemplate->header.name),FALSE);
01030 return;
01031 }
01032 }
01033
01034
01035
01036
01037
01038
01039 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
01040 {
01041 EnvSetMultifieldErrorValue(theEnv,result);
01042 SetEvaluationError(theEnv,TRUE);
01043 InvalidDeftemplateSlotMessage(theEnv,slotName,
01044 ValueToString(theDeftemplate->header.name),FALSE);
01045 return;
01046 }
01047
01048
01049
01050
01051
01052 if ((theSlot->constraints == NULL) ? FALSE :
01053 (theSlot->constraints->anyAllowed || theSlot->constraints->floatsAllowed ||
01054 theSlot->constraints->integersAllowed))
01055 {
01056 result->type = MULTIFIELD;
01057 result->begin = 0;
01058 result->end = 1;
01059 result->value = EnvCreateMultifield(theEnv,2L);
01060 SetMFType(result->value,1,theSlot->constraints->minValue->type);
01061 SetMFValue(result->value,1,theSlot->constraints->minValue->value);
01062 SetMFType(result->value,2,theSlot->constraints->maxValue->type);
01063 SetMFValue(result->value,2,theSlot->constraints->maxValue->value);
01064 }
01065 else
01066 {
01067 result->type = SYMBOL;
01068 result->value = EnvFalseSymbol(theEnv);
01069 return;
01070 }
01071 }
01072
01073
01074
01075
01076
01077 globle void DeftemplateSlotTypesFunction(
01078 void *theEnv,
01079 DATA_OBJECT_PTR theValue)
01080 {
01081 struct deftemplate *theDeftemplate;
01082 SYMBOL_HN *slotName;
01083
01084
01085
01086
01087
01088 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-types",&theDeftemplate,2);
01089 if (slotName == NULL)
01090 {
01091 EnvSetMultifieldErrorValue(theEnv,theValue);
01092 return;
01093 }
01094
01095
01096
01097
01098
01099 EnvDeftemplateSlotTypes(theEnv,theDeftemplate,ValueToString(slotName),theValue);
01100 }
01101
01102
01103
01104
01105
01106 globle void EnvDeftemplateSlotTypes(
01107 void *theEnv,
01108 void *vTheDeftemplate,
01109 char *slotName,
01110 DATA_OBJECT *result)
01111 {
01112 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
01113 short position;
01114 struct templateSlot *theSlot = NULL;
01115 int numTypes, i, allTypes = FALSE;
01116
01117
01118
01119
01120
01121
01122 if (theDeftemplate->implied)
01123 {
01124 if (strcmp(slotName,"implied") != 0)
01125 {
01126 EnvSetMultifieldErrorValue(theEnv,result);
01127 SetEvaluationError(theEnv,TRUE);
01128 InvalidDeftemplateSlotMessage(theEnv,slotName,
01129 ValueToString(theDeftemplate->header.name),FALSE);
01130 return;
01131 }
01132 }
01133
01134
01135
01136
01137
01138
01139 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
01140 {
01141 EnvSetMultifieldErrorValue(theEnv,result);
01142 SetEvaluationError(theEnv,TRUE);
01143 InvalidDeftemplateSlotMessage(theEnv,slotName,
01144 ValueToString(theDeftemplate->header.name),FALSE);
01145 return;
01146 }
01147
01148
01149
01150
01151
01152
01153
01154 if ((theDeftemplate->implied) ||
01155 ((theSlot->constraints != NULL) ? theSlot->constraints->anyAllowed : TRUE))
01156 {
01157 #if OBJECT_SYSTEM
01158 numTypes = 8;
01159 #else
01160 numTypes = 6;
01161 #endif
01162 allTypes = TRUE;
01163 }
01164
01165
01166
01167
01168
01169 else
01170 {
01171 numTypes = theSlot->constraints->symbolsAllowed +
01172 theSlot->constraints->stringsAllowed +
01173 theSlot->constraints->floatsAllowed +
01174 theSlot->constraints->integersAllowed +
01175 theSlot->constraints->instanceNamesAllowed +
01176 theSlot->constraints->instanceAddressesAllowed +
01177 theSlot->constraints->externalAddressesAllowed +
01178 theSlot->constraints->factAddressesAllowed;
01179 }
01180
01181
01182
01183
01184
01185 result->type = MULTIFIELD;
01186 result->begin = 0;
01187 result->end = numTypes - 1;
01188 result->value = EnvCreateMultifield(theEnv,(long) numTypes);
01189
01190 i = 1;
01191
01192 if (allTypes || theSlot->constraints->floatsAllowed)
01193 {
01194 SetMFType(result->value,i,SYMBOL);
01195 SetMFValue(result->value,i++,EnvAddSymbol(theEnv,"FLOAT"));
01196 }
01197
01198 if (allTypes || theSlot->constraints->integersAllowed)
01199 {
01200 SetMFType(result->value,i,SYMBOL);
01201 SetMFValue(result->value,i++,EnvAddSymbol(theEnv,"INTEGER"));
01202 }
01203
01204 if (allTypes || theSlot->constraints->symbolsAllowed)
01205 {
01206 SetMFType(result->value,i,SYMBOL);
01207 SetMFValue(result->value,i++,EnvAddSymbol(theEnv,"SYMBOL"));
01208 }
01209
01210 if (allTypes || theSlot->constraints->stringsAllowed)
01211 {
01212 SetMFType(result->value,i,SYMBOL);
01213 SetMFValue(result->value,i++,EnvAddSymbol(theEnv,"STRING"));
01214 }
01215
01216 if (allTypes || theSlot->constraints->externalAddressesAllowed)
01217 {
01218 SetMFType(result->value,i,SYMBOL);
01219 SetMFValue(result->value,i++,EnvAddSymbol(theEnv,"EXTERNAL-ADDRESS"));
01220 }
01221
01222 if (allTypes || theSlot->constraints->factAddressesAllowed)
01223 {
01224 SetMFType(result->value,i,SYMBOL);
01225 SetMFValue(result->value,i++,EnvAddSymbol(theEnv,"FACT-ADDRESS"));
01226 }
01227
01228 #if OBJECT_SYSTEM
01229 if (allTypes || theSlot->constraints->instanceAddressesAllowed)
01230 {
01231 SetMFType(result->value,i,SYMBOL);
01232 SetMFValue(result->value,i++,EnvAddSymbol(theEnv,"INSTANCE-ADDRESS"));
01233 }
01234
01235 if (allTypes || theSlot->constraints->instanceNamesAllowed)
01236 {
01237 SetMFType(result->value,i,SYMBOL);
01238 SetMFValue(result->value,i,EnvAddSymbol(theEnv,"INSTANCE-NAME"));
01239 }
01240 #endif
01241 }
01242
01243
01244
01245
01246
01247 globle int DeftemplateSlotMultiPFunction(
01248 void *theEnv)
01249 {
01250 struct deftemplate *theDeftemplate;
01251 SYMBOL_HN *slotName;
01252
01253
01254
01255
01256
01257 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-multip",&theDeftemplate,2);
01258 if (slotName == NULL)
01259 { return(FALSE); }
01260
01261
01262
01263
01264
01265 return EnvDeftemplateSlotMultiP(theEnv,theDeftemplate,ValueToString(slotName));
01266 }
01267
01268
01269
01270
01271
01272 globle int EnvDeftemplateSlotMultiP(
01273 void *theEnv,
01274 void *vTheDeftemplate,
01275 char *slotName)
01276 {
01277 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
01278 short position;
01279 struct templateSlot *theSlot;
01280
01281
01282
01283
01284
01285
01286 if (theDeftemplate->implied)
01287 {
01288 if (strcmp(slotName,"implied") == 0)
01289 { return(TRUE); }
01290 else
01291 {
01292 SetEvaluationError(theEnv,TRUE);
01293 InvalidDeftemplateSlotMessage(theEnv,slotName,
01294 ValueToString(theDeftemplate->header.name),FALSE);
01295 return(FALSE);
01296 }
01297 }
01298
01299
01300
01301
01302
01303
01304 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
01305 {
01306 SetEvaluationError(theEnv,TRUE);
01307 InvalidDeftemplateSlotMessage(theEnv,slotName,
01308 ValueToString(theDeftemplate->header.name),FALSE);
01309 return(FALSE);
01310 }
01311
01312
01313
01314
01315
01316 return(theSlot->multislot);
01317 }
01318
01319
01320
01321
01322
01323 globle int DeftemplateSlotSinglePFunction(
01324 void *theEnv)
01325 {
01326 struct deftemplate *theDeftemplate;
01327 SYMBOL_HN *slotName;
01328
01329
01330
01331
01332
01333 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-singlep",&theDeftemplate,2);
01334 if (slotName == NULL)
01335 { return(FALSE); }
01336
01337
01338
01339
01340
01341 return EnvDeftemplateSlotSingleP(theEnv,theDeftemplate,ValueToString(slotName));
01342 }
01343
01344
01345
01346
01347
01348 globle int EnvDeftemplateSlotSingleP(
01349 void *theEnv,
01350 void *vTheDeftemplate,
01351 char *slotName)
01352 {
01353 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
01354 short position;
01355 struct templateSlot *theSlot;
01356
01357
01358
01359
01360
01361
01362 if (theDeftemplate->implied)
01363 {
01364 if (strcmp(slotName,"implied") == 0)
01365 { return(FALSE); }
01366 else
01367 {
01368 SetEvaluationError(theEnv,TRUE);
01369 InvalidDeftemplateSlotMessage(theEnv,slotName,
01370 ValueToString(theDeftemplate->header.name),FALSE);
01371 return(FALSE);
01372 }
01373 }
01374
01375
01376
01377
01378
01379
01380 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
01381 {
01382 SetEvaluationError(theEnv,TRUE);
01383 InvalidDeftemplateSlotMessage(theEnv,slotName,
01384 ValueToString(theDeftemplate->header.name),FALSE);
01385 return(FALSE);
01386 }
01387
01388
01389
01390
01391
01392 return(! theSlot->multislot);
01393 }
01394
01395
01396
01397
01398
01399 globle int DeftemplateSlotExistPFunction(
01400 void *theEnv)
01401 {
01402 struct deftemplate *theDeftemplate;
01403 SYMBOL_HN *slotName;
01404
01405
01406
01407
01408
01409 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-existp",&theDeftemplate,2);
01410 if (slotName == NULL)
01411 { return(FALSE); }
01412
01413
01414
01415
01416
01417 return EnvDeftemplateSlotExistP(theEnv,theDeftemplate,ValueToString(slotName));
01418 }
01419
01420
01421
01422
01423
01424 globle int EnvDeftemplateSlotExistP(
01425 void *theEnv,
01426 void *vTheDeftemplate,
01427 char *slotName)
01428 {
01429 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
01430 short position;
01431
01432
01433
01434
01435
01436
01437 if (theDeftemplate->implied)
01438 {
01439 if (strcmp(slotName,"implied") == 0)
01440 { return(TRUE); }
01441 else
01442 { return(FALSE); }
01443 }
01444
01445
01446
01447
01448
01449
01450 else if (FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position) == NULL)
01451 { return(FALSE); }
01452
01453
01454
01455
01456
01457 return(TRUE);
01458 }
01459
01460
01461
01462
01463
01464 globle int DeftemplateSlotFacetExistPFunction(
01465 void *theEnv)
01466 {
01467 struct deftemplate *theDeftemplate;
01468 SYMBOL_HN *slotName;
01469 DATA_OBJECT facetName;
01470
01471
01472
01473
01474
01475 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-facet-existp",&theDeftemplate,3);
01476 if (slotName == NULL)
01477 { return(FALSE); }
01478
01479
01480
01481
01482
01483 if (EnvArgTypeCheck(theEnv,"deftemplate-slot-facet-existp",3,SYMBOL,&facetName) == FALSE)
01484 { return(FALSE); }
01485
01486
01487
01488
01489
01490 return EnvDeftemplateSlotFacetExistP(theEnv,theDeftemplate,ValueToString(slotName),DOToString(facetName));
01491 }
01492
01493
01494
01495
01496
01497 globle int EnvDeftemplateSlotFacetExistP(
01498 void *theEnv,
01499 void *vTheDeftemplate,
01500 char *slotName,
01501 char *facetName)
01502 {
01503 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
01504 short position;
01505 struct templateSlot *theSlot;
01506 SYMBOL_HN *facetHN;
01507 struct expr *tempFacet;
01508
01509
01510
01511
01512
01513 if (theDeftemplate->implied)
01514 { return(FALSE); }
01515
01516
01517
01518
01519
01520
01521 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
01522 { return(FALSE); }
01523
01524
01525
01526
01527
01528 facetHN = FindSymbolHN(theEnv,facetName);
01529 for (tempFacet = theSlot->facetList;
01530 tempFacet != NULL;
01531 tempFacet = tempFacet->nextArg)
01532 {
01533 if (tempFacet->value == facetHN)
01534 { return(TRUE); }
01535 }
01536
01537
01538
01539
01540
01541 return(FALSE);
01542 }
01543
01544
01545
01546
01547
01548 globle void DeftemplateSlotFacetValueFunction(
01549 void *theEnv,
01550 DATA_OBJECT *returnValue)
01551 {
01552 struct deftemplate *theDeftemplate;
01553 SYMBOL_HN *slotName;
01554 DATA_OBJECT facetName;
01555
01556
01557
01558
01559
01560 returnValue->type = SYMBOL;
01561 returnValue->value = EnvFalseSymbol(theEnv);
01562
01563
01564
01565
01566
01567 slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-facet-existp",&theDeftemplate,3);
01568 if (slotName == NULL)
01569 { return; }
01570
01571
01572
01573
01574
01575 if (EnvArgTypeCheck(theEnv,"deftemplate-slot-facet-existp",3,SYMBOL,&facetName) == FALSE)
01576 { return; }
01577
01578
01579
01580
01581
01582 EnvDeftemplateSlotFacetValue(theEnv,theDeftemplate,ValueToString(slotName),DOToString(facetName),returnValue);
01583 }
01584
01585
01586
01587
01588
01589 globle int EnvDeftemplateSlotFacetValue(
01590 void *theEnv,
01591 void *vTheDeftemplate,
01592 char *slotName,
01593 char *facetName,
01594 DATA_OBJECT *rv)
01595 {
01596 struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
01597 short position;
01598 struct templateSlot *theSlot;
01599 SYMBOL_HN *facetHN;
01600 struct expr *tempFacet;
01601
01602
01603
01604
01605
01606 if (theDeftemplate->implied)
01607 { return(FALSE); }
01608
01609
01610
01611
01612
01613
01614 else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
01615 { return(FALSE); }
01616
01617
01618
01619
01620
01621 facetHN = FindSymbolHN(theEnv,facetName);
01622 for (tempFacet = theSlot->facetList;
01623 tempFacet != NULL;
01624 tempFacet = tempFacet->nextArg)
01625 {
01626 if (tempFacet->value == facetHN)
01627 {
01628 EvaluateExpression(theEnv,tempFacet->argList,rv);
01629 return(TRUE);
01630 }
01631 }
01632
01633
01634
01635
01636
01637 return(FALSE);
01638 }
01639
01640
01641
01642
01643
01644 static SYMBOL_HN *CheckDeftemplateAndSlotArguments(
01645 void *theEnv,
01646 char *functionName,
01647 struct deftemplate **theDeftemplate,
01648 int expectedArgs)
01649 {
01650 DATA_OBJECT tempDO;
01651 char *deftemplateName;
01652
01653
01654
01655
01656
01657 if (EnvArgCountCheck(theEnv,functionName,EXACTLY,expectedArgs) == -1)
01658 { return(NULL); }
01659
01660
01661
01662
01663
01664 if (EnvArgCountCheck(theEnv,functionName,AT_LEAST,2) == -1)
01665 { return(NULL); }
01666
01667
01668
01669
01670
01671 EnvRtnUnknown(theEnv,1,&tempDO);
01672
01673 if (GetType(tempDO) != SYMBOL)
01674 {
01675 ExpectedTypeError1(theEnv,functionName,1,"deftemplate name");
01676 return(NULL);
01677 }
01678
01679 deftemplateName = DOToString(tempDO);
01680
01681 *theDeftemplate = (struct deftemplate *) EnvFindDeftemplate(theEnv,deftemplateName);
01682 if (*theDeftemplate == NULL)
01683 {
01684 CantFindItemErrorMessage(theEnv,"deftemplate",deftemplateName);
01685 return(NULL);
01686 }
01687
01688
01689
01690
01691
01692 if (EnvArgTypeCheck(theEnv,functionName,2,SYMBOL,&tempDO) == FALSE)
01693 { return(NULL); }
01694
01695 return((SYMBOL_HN *) GetValue(tempDO));
01696 }
01697
01698 #if (! RUN_TIME) && (! BLOAD_ONLY)
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710 globle intBool UpdateModifyDuplicate(
01711 void *theEnv,
01712 struct expr *top,
01713 char *name,
01714 void *vTheLHS)
01715 {
01716 struct expr *functionArgs, *tempArg;
01717 SYMBOL_HN *templateName;
01718 struct deftemplate *theDeftemplate;
01719 struct templateSlot *slotPtr;
01720 short position;
01721
01722
01723
01724
01725
01726
01727 functionArgs = top->argList;
01728 if (functionArgs->type == SF_VARIABLE)
01729 {
01730 templateName = FindTemplateForFactAddress((SYMBOL_HN *) functionArgs->value,
01731 (struct lhsParseNode *) vTheLHS);
01732 if (templateName == NULL) return(TRUE);
01733 }
01734 else
01735 { return(TRUE); }
01736
01737
01738
01739
01740
01741
01742 theDeftemplate = (struct deftemplate *)
01743 LookupConstruct(theEnv,DeftemplateData(theEnv)->DeftemplateConstruct,
01744 ValueToString(templateName),
01745 FALSE);
01746
01747 if (theDeftemplate == NULL) return(TRUE);
01748
01749 if (theDeftemplate->implied) return(TRUE);
01750
01751
01752
01753
01754
01755 tempArg = functionArgs->nextArg;
01756 while (tempArg != NULL)
01757 {
01758
01759
01760
01761
01762 if ((slotPtr = FindSlot(theDeftemplate,(SYMBOL_HN *) tempArg->value,&position)) == NULL)
01763 {
01764 InvalidDeftemplateSlotMessage(theEnv,ValueToString(tempArg->value),
01765 ValueToString(theDeftemplate->header.name),TRUE);
01766 return(FALSE);
01767 }
01768
01769
01770
01771
01772
01773 if (slotPtr->multislot == FALSE)
01774 {
01775 if (tempArg->argList == NULL)
01776 {
01777 SingleFieldSlotCardinalityError(theEnv,slotPtr->slotName->contents);
01778 return(FALSE);
01779 }
01780 else if (tempArg->argList->nextArg != NULL)
01781 {
01782 SingleFieldSlotCardinalityError(theEnv,slotPtr->slotName->contents);
01783 return(FALSE);
01784 }
01785 else if ((tempArg->argList->type == MF_VARIABLE) ||
01786 ((tempArg->argList->type == FCALL) ?
01787 (((struct FunctionDefinition *) tempArg->argList->value)->returnValueType == 'm') :
01788 FALSE))
01789 {
01790 SingleFieldSlotCardinalityError(theEnv,slotPtr->slotName->contents);
01791 return(FALSE);
01792 }
01793 }
01794
01795
01796
01797
01798
01799 if (CheckRHSSlotTypes(theEnv,tempArg->argList,slotPtr,name) == 0)
01800 return(FALSE);
01801
01802
01803
01804
01805
01806 tempArg->type = INTEGER;
01807 tempArg->value = (void *) EnvAddLong(theEnv,(long long) (FindSlotPosition(theDeftemplate,(SYMBOL_HN *) tempArg->value) - 1));
01808
01809 tempArg = tempArg->nextArg;
01810 }
01811
01812 return(TRUE);
01813 }
01814
01815
01816
01817
01818
01819
01820 static SYMBOL_HN *FindTemplateForFactAddress(
01821 SYMBOL_HN *factAddress,
01822 struct lhsParseNode *theLHS)
01823 {
01824 struct lhsParseNode *thePattern = NULL;
01825
01826
01827
01828
01829
01830
01831
01832 while (theLHS != NULL)
01833 {
01834 if (theLHS->value == (void *) factAddress)
01835 {
01836 thePattern = theLHS;
01837 theLHS = NULL;
01838 }
01839 else
01840 { theLHS = theLHS->bottom; }
01841 }
01842
01843 if (thePattern == NULL) return(NULL);
01844
01845
01846
01847
01848
01849
01850 thePattern = thePattern->right;
01851 if ((thePattern->type != SF_WILDCARD) || (thePattern->bottom == NULL))
01852 { return(NULL); }
01853
01854 thePattern = thePattern->bottom;
01855 if ((thePattern->type != SYMBOL) ||
01856 (thePattern->right != NULL) ||
01857 (thePattern->bottom != NULL))
01858 { return(NULL); }
01859
01860
01861
01862
01863
01864 return((SYMBOL_HN *) thePattern->value);
01865 }
01866
01867
01868
01869
01870 globle struct expr *ModifyParse(
01871 void *theEnv,
01872 struct expr *top,
01873 char *logicalName)
01874 {
01875 return(ModAndDupParse(theEnv,top,logicalName,"modify"));
01876 }
01877
01878
01879
01880
01881 globle struct expr *DuplicateParse(
01882 void *theEnv,
01883 struct expr *top,
01884 char *logicalName)
01885 {
01886 return(ModAndDupParse(theEnv,top,logicalName,"duplicate"));
01887 }
01888
01889
01890
01891
01892 static struct expr *ModAndDupParse(
01893 void *theEnv,
01894 struct expr *top,
01895 char *logicalName,
01896 char *name)
01897 {
01898 int error = FALSE;
01899 struct token theToken;
01900 struct expr *nextOne, *tempSlot;
01901 struct expr *newField, *firstField, *lastField;
01902 int printError;
01903 short done;
01904
01905
01906
01907
01908
01909 SavePPBuffer(theEnv," ");
01910 GetToken(theEnv,logicalName,&theToken);
01911
01912 if ((theToken.type == SF_VARIABLE) || (theToken.type == GBL_VARIABLE))
01913 { nextOne = GenConstant(theEnv,theToken.type,theToken.value); }
01914 else if (theToken.type == INTEGER)
01915 {
01916 if (! TopLevelCommand(theEnv))
01917 {
01918 PrintErrorID(theEnv,"TMPLTFUN",1,TRUE);
01919 EnvPrintRouter(theEnv,WERROR,"Fact-indexes can only be used by ");
01920 EnvPrintRouter(theEnv,WERROR,name);
01921 EnvPrintRouter(theEnv,WERROR," as a top level command.\n");
01922 ReturnExpression(theEnv,top);
01923 return(NULL);
01924 }
01925
01926 nextOne = GenConstant(theEnv,INTEGER,theToken.value);
01927 }
01928 else
01929 {
01930 ExpectedTypeError2(theEnv,name,1);
01931 ReturnExpression(theEnv,top);
01932 return(NULL);
01933 }
01934
01935 nextOne->nextArg = NULL;
01936 nextOne->argList = NULL;
01937 top->argList = nextOne;
01938 nextOne = top->argList;
01939
01940
01941
01942
01943
01944 GetToken(theEnv,logicalName,&theToken);
01945 while (theToken.type != RPAREN)
01946 {
01947 PPBackup(theEnv);
01948 SavePPBuffer(theEnv," ");
01949 SavePPBuffer(theEnv,theToken.printForm);
01950
01951
01952
01953
01954
01955 if (theToken.type != LPAREN)
01956 {
01957 SyntaxErrorMessage(theEnv,"duplicate/modify function");
01958 ReturnExpression(theEnv,top);
01959 return(NULL);
01960 }
01961
01962
01963
01964
01965
01966 GetToken(theEnv,logicalName,&theToken);
01967 if (theToken.type != SYMBOL)
01968 {
01969 SyntaxErrorMessage(theEnv,"duplicate/modify function");
01970 ReturnExpression(theEnv,top);
01971 return(NULL);
01972 }
01973
01974
01975
01976
01977
01978 for (tempSlot = top->argList->nextArg;
01979 tempSlot != NULL;
01980 tempSlot = tempSlot->nextArg)
01981 {
01982 if (tempSlot->value == theToken.value)
01983 {
01984 AlreadyParsedErrorMessage(theEnv,"slot ",ValueToString(theToken.value));
01985 ReturnExpression(theEnv,top);
01986 return(NULL);
01987 }
01988 }
01989
01990
01991
01992
01993
01994 nextOne->nextArg = GenConstant(theEnv,SYMBOL,theToken.value);
01995 nextOne = nextOne->nextArg;
01996
01997
01998
01999
02000
02001 firstField = NULL;
02002 lastField = NULL;
02003 done = FALSE;
02004 while (! done)
02005 {
02006 SavePPBuffer(theEnv," ");
02007 newField = GetAssertArgument(theEnv,logicalName,&theToken,&error,
02008 RPAREN,FALSE,&printError);
02009
02010 if (error)
02011 {
02012 if (printError) SyntaxErrorMessage(theEnv,"deftemplate pattern");
02013 ReturnExpression(theEnv,top);
02014 return(NULL);
02015 }
02016
02017 if (newField == NULL)
02018 { done = TRUE; }
02019
02020 if (lastField == NULL)
02021 { firstField = newField; }
02022 else
02023 { lastField->nextArg = newField; }
02024 lastField = newField;
02025 }
02026
02027
02028
02029
02030
02031 if (theToken.type != RPAREN)
02032 {
02033 SyntaxErrorMessage(theEnv,"duplicate/modify function");
02034 ReturnExpression(theEnv,top);
02035 ReturnExpression(theEnv,firstField);
02036 return(NULL);
02037 }
02038 else
02039 {
02040 PPBackup(theEnv);
02041 PPBackup(theEnv);
02042 SavePPBuffer(theEnv,")");
02043 }
02044
02045 nextOne->argList = firstField;
02046
02047 GetToken(theEnv,logicalName,&theToken);
02048 }
02049
02050
02051
02052
02053
02054 return(top);
02055 }
02056
02057 #endif
02058
02059 #endif
02060