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 #define _GENERATE_SOURCE_
00026
00027 #include <stdio.h>
00028 #define _STDIO_INCLUDED_
00029 #include <stdlib.h>
00030
00031 #include "setup.h"
00032
00033 #if (! RUN_TIME) && (! BLOAD_ONLY) && DEFRULE_CONSTRUCT
00034
00035 #include "constant.h"
00036 #include "envrnmnt.h"
00037 #include "memalloc.h"
00038 #include "symbol.h"
00039 #include "exprnpsr.h"
00040 #include "argacces.h"
00041 #include "extnfunc.h"
00042 #include "router.h"
00043 #include "ruledef.h"
00044 #include "pattern.h"
00045 #include "generate.h"
00046
00047 #if DEFGLOBAL_CONSTRUCT
00048 #include "globlpsr.h"
00049 #endif
00050
00051
00052
00053
00054
00055 static void ExtractAnds(void *,struct lhsParseNode *,int,
00056 struct expr **,struct expr **,struct expr **,
00057 struct expr **,struct expr **,int);
00058 static void ExtractFieldTest(void *,struct lhsParseNode *,int,
00059 struct expr **,struct expr **,struct expr **,
00060 struct expr **,struct expr **,int);
00061 static struct expr *GetfieldReplace(void *,struct lhsParseNode *);
00062 static struct expr *GenPNConstant(void *,struct lhsParseNode *);
00063 static struct expr *GenJNConstant(void *,struct lhsParseNode *,int);
00064 static struct expr *GenJNColon(void *,struct lhsParseNode *,int);
00065 static struct expr *GenPNColon(void *,struct lhsParseNode *);
00066 static struct expr *GenJNEq(void *,struct lhsParseNode *,int);
00067 static struct expr *GenPNEq(void *,struct lhsParseNode *);
00068 static struct expr *GenJNVariableComparison(void *,struct lhsParseNode *,
00069 struct lhsParseNode *,int);
00070 static struct expr *GenPNVariableComparison(void *,struct lhsParseNode *,
00071 struct lhsParseNode *);
00072 static int AllVariablesInPattern(struct lhsParseNode *,
00073 int);
00074 static int AllVariablesInExpression(struct lhsParseNode *,
00075 int);
00076 static int FieldIsNandTest(struct lhsParseNode *);
00077
00078
00079
00080
00081
00082 globle void FieldConversion(
00083 void *theEnv,
00084 struct lhsParseNode *theField,
00085 struct lhsParseNode *thePattern)
00086 {
00087 int testInPatternNetwork = TRUE;
00088 struct lhsParseNode *patternPtr;
00089 struct expr *headOfPNExpression, *headOfJNExpression, *headOfNandExpression;
00090 struct expr *lastPNExpression, *lastJNExpression, *lastNandExpression;
00091 struct expr *tempExpression;
00092 struct expr *patternNetTest = NULL;
00093 struct expr *joinNetTest = NULL;
00094 struct expr *nandTest = NULL;
00095 struct expr *constantSelector = NULL;
00096 struct expr *constantValue = NULL;
00097 int nandField;
00098
00099
00100
00101
00102
00103 if (theField == NULL)
00104 {
00105 SystemError(theEnv,"ANALYSIS",3);
00106 EnvExitRouter(theEnv,EXIT_FAILURE);
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116 if (theField->bottom != NULL)
00117 {
00118 if (theField->bottom->bottom != NULL)
00119 { testInPatternNetwork = AllVariablesInPattern(theField->bottom,theField->pattern); }
00120 }
00121
00122
00123
00124
00125
00126
00127 nandField = FieldIsNandTest(theField);
00128
00129
00130
00131
00132
00133
00134
00135 headOfPNExpression = lastPNExpression = NULL;
00136 headOfJNExpression = lastJNExpression = NULL;
00137 headOfNandExpression = lastNandExpression = NULL;
00138
00139 for (patternPtr = theField->bottom;
00140 patternPtr != NULL;
00141 patternPtr = patternPtr->bottom)
00142 {
00143
00144
00145
00146
00147
00148 ExtractAnds(theEnv,patternPtr,testInPatternNetwork,&patternNetTest,&joinNetTest,&nandTest,
00149 &constantSelector,&constantValue,nandField);
00150
00151
00152
00153
00154
00155
00156
00157 if (constantSelector != NULL)
00158 {
00159 if ((patternPtr == theField->bottom) &&
00160 (patternPtr->bottom == NULL))
00161 {
00162 theField->constantSelector = constantSelector;
00163 theField->constantValue = constantValue;
00164 }
00165 else
00166 {
00167 ReturnExpression(theEnv,constantSelector);
00168 ReturnExpression(theEnv,constantValue);
00169 ReturnExpression(theEnv,theField->constantSelector);
00170 ReturnExpression(theEnv,theField->constantValue);
00171 theField->constantSelector = NULL;
00172 theField->constantValue = NULL;
00173 }
00174 }
00175
00176
00177
00178
00179
00180
00181 if (patternNetTest != NULL)
00182 {
00183 if (lastPNExpression == NULL)
00184 { headOfPNExpression = patternNetTest; }
00185 else
00186 { lastPNExpression->nextArg = patternNetTest; }
00187 lastPNExpression = patternNetTest;
00188 }
00189
00190
00191
00192
00193
00194
00195 if (joinNetTest != NULL)
00196 {
00197 if (lastJNExpression == NULL)
00198 { headOfJNExpression = joinNetTest; }
00199 else
00200 { lastJNExpression->nextArg = joinNetTest; }
00201 lastJNExpression = joinNetTest;
00202 }
00203
00204
00205
00206
00207
00208
00209 if (nandTest != NULL)
00210 {
00211 if (lastNandExpression == NULL)
00212 { headOfNandExpression = nandTest; }
00213 else
00214 { lastNandExpression->nextArg = nandTest; }
00215 lastNandExpression = nandTest;
00216 }
00217 }
00218
00219
00220
00221
00222
00223
00224
00225 if ((headOfPNExpression != NULL) ? (headOfPNExpression->nextArg != NULL) : FALSE)
00226 {
00227 tempExpression = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_OR);
00228 tempExpression->argList = headOfPNExpression;
00229 headOfPNExpression = tempExpression;
00230 }
00231
00232
00233
00234
00235
00236
00237
00238 if ((headOfJNExpression != NULL) ? (headOfJNExpression->nextArg != NULL) : FALSE)
00239 {
00240 tempExpression = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_OR);
00241 tempExpression->argList = headOfJNExpression;
00242 headOfJNExpression = tempExpression;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251 if ((headOfNandExpression != NULL) ? (headOfNandExpression->nextArg != NULL) : FALSE)
00252 {
00253 tempExpression = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_OR);
00254 tempExpression->argList = headOfNandExpression;
00255 headOfNandExpression = tempExpression;
00256 }
00257
00258
00259
00260
00261
00262
00263
00264
00265 if (((theField->type == MF_VARIABLE) || (theField->type == SF_VARIABLE)) &&
00266 (theField->referringNode != NULL))
00267 {
00268
00269
00270
00271
00272
00273 if (theField->referringNode->pattern == theField->pattern)
00274 {
00275 tempExpression = GenPNVariableComparison(theEnv,theField,theField->referringNode);
00276 headOfPNExpression = CombineExpressions(theEnv,tempExpression,headOfPNExpression);
00277 }
00278
00279
00280
00281
00282
00283
00284 else if (theField->referringNode->pattern > 0)
00285 {
00286 tempExpression = GenJNVariableComparison(theEnv,theField,theField->referringNode,nandField);
00287
00288 if (theField->beginNandDepth > theField->referringNode->beginNandDepth)
00289 {
00290 headOfNandExpression = CombineExpressions(theEnv,tempExpression,headOfNandExpression);
00291
00292
00293
00294
00295
00296 if (theField->patternType->genGetJNValueFunction)
00297 {
00298 tempExpression = (*theField->patternType->genGetJNValueFunction)(theEnv,theField,LHS);
00299 thePattern->externalRightHash = AppendExpressions(tempExpression,thePattern->externalRightHash);
00300 }
00301
00302 if (theField->referringNode->patternType->genGetJNValueFunction)
00303 {
00304 tempExpression = (*theField->referringNode->patternType->genGetJNValueFunction)(theEnv,theField->referringNode,LHS);
00305 thePattern->externalLeftHash = AppendExpressions(tempExpression,thePattern->externalLeftHash);
00306 }
00307 }
00308 else
00309 {
00310 headOfJNExpression = CombineExpressions(theEnv,tempExpression,headOfJNExpression);
00311
00312
00313
00314
00315
00316 if (theField->patternType->genGetPNValueFunction != NULL)
00317 {
00318 tempExpression = (*theField->patternType->genGetPNValueFunction)(theEnv,theField);
00319 thePattern->rightHash = AppendExpressions(tempExpression,thePattern->rightHash);
00320 }
00321
00322 if (theField->referringNode->patternType->genGetJNValueFunction)
00323 {
00324 tempExpression = (*theField->referringNode->patternType->genGetJNValueFunction)(theEnv,theField->referringNode,LHS);
00325 thePattern->leftHash = AppendExpressions(tempExpression,thePattern->leftHash);
00326 }
00327 }
00328 }
00329 }
00330
00331
00332
00333
00334
00335 theField->networkTest = headOfPNExpression;
00336
00337
00338
00339
00340
00341 thePattern->networkTest = CombineExpressions(theEnv,thePattern->networkTest,headOfJNExpression);
00342
00343
00344
00345
00346
00347 thePattern->externalNetworkTest = CombineExpressions(theEnv,thePattern->externalNetworkTest,headOfNandExpression);
00348 }
00349
00350
00351
00352
00353
00354
00355 static void ExtractAnds(
00356 void *theEnv,
00357 struct lhsParseNode *andField,
00358 int testInPatternNetwork,
00359 struct expr **patternNetTest,
00360 struct expr **joinNetTest,
00361 struct expr **nandTest,
00362 struct expr **constantSelector,
00363 struct expr **constantValue,
00364 int nandField)
00365 {
00366 struct expr *newPNTest, *newJNTest, *newNandTest, *newConstantSelector, *newConstantValue;
00367
00368
00369
00370
00371
00372
00373 *patternNetTest = NULL;
00374 *joinNetTest = NULL;
00375 *nandTest = NULL;
00376 *constantSelector = NULL;
00377 *constantValue = NULL;
00378
00379
00380
00381
00382
00383
00384 for (;
00385 andField != NULL;
00386 andField = andField->right)
00387 {
00388
00389
00390
00391
00392
00393 ExtractFieldTest(theEnv,andField,testInPatternNetwork,&newPNTest,&newJNTest,&newNandTest,&newConstantSelector,&newConstantValue,nandField);
00394
00395
00396
00397
00398
00399
00400 *patternNetTest = CombineExpressions(theEnv,*patternNetTest,newPNTest);
00401 *joinNetTest = CombineExpressions(theEnv,*joinNetTest,newJNTest);
00402 *nandTest = CombineExpressions(theEnv,*nandTest,newNandTest);
00403 *constantSelector = CombineExpressions(theEnv,*constantSelector,newConstantSelector);
00404 *constantValue = CombineExpressions(theEnv,*constantValue,newConstantValue);
00405 }
00406 }
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 static void ExtractFieldTest(
00425 void *theEnv,
00426 struct lhsParseNode *theField,
00427 int testInPatternNetwork,
00428 struct expr **patternNetTest,
00429 struct expr **joinNetTest,
00430 struct expr **nandTest,
00431 struct expr **constantSelector,
00432 struct expr **constantValue,
00433 int nandField)
00434 {
00435 struct expr *rv;
00436
00437 *patternNetTest = NULL;
00438 *joinNetTest = NULL;
00439 *nandTest = NULL;
00440 *constantSelector = NULL;
00441 *constantValue = NULL;
00442
00443
00444
00445
00446
00447 if ((theField->type == STRING) || (theField->type == SYMBOL) ||
00448 #if OBJECT_SYSTEM
00449 (theField->type == INSTANCE_NAME) ||
00450 #endif
00451 (theField->type == FLOAT) || (theField->type == INTEGER))
00452 {
00453 if (testInPatternNetwork == TRUE)
00454 {
00455 *patternNetTest = GenPNConstant(theEnv,theField);
00456
00457 if (! theField->negated)
00458 {
00459 *constantSelector = (*theField->patternType->genGetPNValueFunction)(theEnv,theField);
00460 *constantValue = GenConstant(theEnv,theField->type,theField->value);
00461 }
00462 }
00463 else
00464 {
00465 rv = GenJNConstant(theEnv,theField,nandField);
00466
00467 if (nandField)
00468 { *nandTest = rv; }
00469 else
00470 { *joinNetTest = rv; }
00471 }
00472 }
00473
00474
00475
00476
00477
00478 else if (theField->type == PREDICATE_CONSTRAINT)
00479 {
00480 if ((testInPatternNetwork == TRUE) &&
00481 (AllVariablesInExpression(theField->expression,theField->pattern) == TRUE))
00482 { *patternNetTest = GenPNColon(theEnv,theField); }
00483 else
00484 {
00485 rv = GenJNColon(theEnv,theField,nandField);
00486
00487 if (nandField)
00488 { *nandTest = rv; }
00489 else
00490 { *joinNetTest = rv; }
00491 }
00492 }
00493
00494
00495
00496
00497
00498 else if (theField->type == RETURN_VALUE_CONSTRAINT)
00499 {
00500 if ((testInPatternNetwork == TRUE) &&
00501 (AllVariablesInExpression(theField->expression,theField->pattern) == TRUE))
00502 { *patternNetTest = GenPNEq(theEnv,theField); }
00503 else
00504 {
00505 rv = GenJNEq(theEnv,theField,nandField);
00506
00507 if (nandField)
00508 { *nandTest = rv; }
00509 else
00510 { *joinNetTest = rv; }
00511 }
00512 }
00513
00514
00515
00516
00517
00518 else if ((theField->type == SF_VARIABLE) || (theField->type == MF_VARIABLE))
00519 {
00520 if ((testInPatternNetwork == TRUE) &&
00521 ((theField->referringNode != NULL) ?
00522 (theField->referringNode->pattern == theField->pattern) :
00523 FALSE))
00524 { *patternNetTest = GenPNVariableComparison(theEnv,theField,theField->referringNode); }
00525 else
00526 {
00527 if (nandField)
00528 { *nandTest = GenJNVariableComparison(theEnv,theField,theField->referringNode,nandField); }
00529 else
00530 { *joinNetTest = GenJNVariableComparison(theEnv,theField,theField->referringNode,nandField); }
00531
00532 }
00533 }
00534 }
00535
00536
00537
00538
00539
00540
00541
00542
00543 static struct expr *GenPNConstant(
00544 void *theEnv,
00545 struct lhsParseNode *theField)
00546 {
00547 struct expr *top;
00548
00549
00550
00551
00552
00553
00554
00555
00556 if (theField->patternType->genPNConstantFunction != NULL)
00557 { return (*theField->patternType->genPNConstantFunction)(theEnv,theField); }
00558
00559
00560
00561
00562
00563
00564
00565 if (theField->negated)
00566 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); }
00567 else
00568 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); }
00569
00570 top->argList = (*theField->patternType->genGetPNValueFunction)(theEnv,theField);
00571 top->argList->nextArg = GenConstant(theEnv,theField->type,theField->value);
00572
00573 return(top);
00574 }
00575
00576
00577
00578
00579
00580
00581
00582 static struct expr *GenJNConstant(
00583 void *theEnv,
00584 struct lhsParseNode *theField,
00585 int isNand)
00586 {
00587 struct expr *top;
00588
00589
00590
00591
00592
00593
00594
00595
00596 if (theField->patternType->genJNConstantFunction != NULL)
00597 {
00598 if (isNand)
00599 { return (*theField->patternType->genJNConstantFunction)(theEnv,theField,NESTED_RHS); }
00600 else
00601 { return (*theField->patternType->genJNConstantFunction)(theEnv,theField,RHS); }
00602 }
00603
00604
00605
00606
00607
00608
00609
00610 if (theField->negated)
00611 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); }
00612 else
00613 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); }
00614
00615 if (isNand)
00616 { top->argList = (*theField->patternType->genGetJNValueFunction)(theEnv,theField,NESTED_RHS); }
00617 else
00618 { top->argList = (*theField->patternType->genGetJNValueFunction)(theEnv,theField,RHS); }
00619
00620 top->argList->nextArg = GenConstant(theEnv,theField->type,theField->value);
00621
00622 return(top);
00623 }
00624
00625
00626
00627
00628
00629
00630 static struct expr *GenJNColon(
00631 void *theEnv,
00632 struct lhsParseNode *theField,
00633 int isNand)
00634 {
00635 struct expr *top, *conversion;
00636
00637
00638
00639
00640
00641
00642 if (isNand)
00643 { conversion = GetvarReplace(theEnv,theField->expression,TRUE); }
00644 else
00645 { conversion = GetvarReplace(theEnv,theField->expression,FALSE); }
00646
00647
00648
00649
00650
00651
00652
00653
00654 if (theField->negated)
00655 {
00656 top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NOT);
00657 top->argList = conversion;
00658 }
00659 else
00660 { top = conversion; }
00661
00662 return(top);
00663 }
00664
00665
00666
00667
00668
00669
00670 static struct expr *GenPNColon(
00671 void *theEnv,
00672 struct lhsParseNode *theField)
00673 {
00674 struct expr *top, *conversion;
00675
00676
00677
00678
00679
00680
00681 conversion = GetfieldReplace(theEnv,theField->expression);
00682
00683
00684
00685
00686
00687
00688
00689
00690 if (theField->negated)
00691 {
00692 top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NOT);
00693 top->argList = conversion;
00694 }
00695 else
00696 { top = conversion; }
00697
00698 return(top);
00699 }
00700
00701
00702
00703
00704
00705
00706 static struct expr *GenJNEq(
00707 void *theEnv,
00708 struct lhsParseNode *theField,
00709 int isNand)
00710 {
00711 struct expr *top, *conversion;
00712
00713
00714
00715
00716
00717
00718 if (isNand)
00719 { conversion = GetvarReplace(theEnv,theField->expression,TRUE); }
00720 else
00721 { conversion = GetvarReplace(theEnv,theField->expression,FALSE); }
00722
00723
00724
00725
00726
00727
00728
00729
00730 if (theField->negated)
00731 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); }
00732 else
00733 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); }
00734
00735 if (isNand)
00736 { top->argList = (*theField->patternType->genGetJNValueFunction)(theEnv,theField,NESTED_RHS); }
00737 else
00738 { top->argList = (*theField->patternType->genGetJNValueFunction)(theEnv,theField,RHS); }
00739
00740 top->argList->nextArg = conversion;
00741
00742 return(top);
00743 }
00744
00745
00746
00747
00748
00749
00750 static struct expr *GenPNEq(
00751 void *theEnv,
00752 struct lhsParseNode *theField)
00753 {
00754 struct expr *top, *conversion;
00755
00756
00757
00758
00759
00760
00761 conversion = GetfieldReplace(theEnv,theField->expression);
00762
00763
00764
00765
00766
00767
00768
00769
00770 if (theField->negated)
00771 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); }
00772 else
00773 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); }
00774
00775 top->argList = (*theField->patternType->genGetPNValueFunction)(theEnv,theField);
00776 top->argList->nextArg = conversion;
00777
00778 return(top);
00779 }
00780
00781
00782
00783
00784
00785
00786
00787 globle struct expr *GetvarReplace(
00788 void *theEnv,
00789 struct lhsParseNode *nodeList,
00790 int isNand)
00791 {
00792 struct expr *newList;
00793
00794
00795
00796
00797
00798
00799 if (nodeList == NULL) return(NULL);
00800
00801
00802
00803
00804
00805
00806
00807 newList = get_struct(theEnv,expr);
00808 newList->type = nodeList->type;
00809 newList->value = nodeList->value;
00810 newList->nextArg = GetvarReplace(theEnv,nodeList->right,isNand);
00811 newList->argList = GetvarReplace(theEnv,nodeList->bottom,isNand);
00812
00813
00814
00815
00816
00817
00818
00819 if ((nodeList->type == SF_VARIABLE) || (nodeList->type == MF_VARIABLE))
00820 {
00821
00822
00823
00824
00825
00826
00827 if (isNand)
00828 {
00829 if (nodeList->beginNandDepth > nodeList->referringNode->beginNandDepth)
00830 {
00831 (*nodeList->referringNode->patternType->replaceGetJNValueFunction)
00832 (theEnv,newList,nodeList->referringNode,LHS);
00833 }
00834 else
00835 {
00836 (*nodeList->referringNode->patternType->replaceGetJNValueFunction)
00837 (theEnv,newList,nodeList->referringNode,NESTED_RHS);
00838 }
00839 }
00840 else
00841 {
00842 if (nodeList->joinDepth != nodeList->referringNode->joinDepth)
00843 {
00844 (*nodeList->referringNode->patternType->replaceGetJNValueFunction)
00845 (theEnv,newList,nodeList->referringNode,LHS);
00846 }
00847 else
00848 {
00849 (*nodeList->referringNode->patternType->replaceGetJNValueFunction)
00850 (theEnv,newList,nodeList->referringNode,RHS);
00851 }
00852 }
00853 }
00854 #if DEFGLOBAL_CONSTRUCT
00855 else if (newList->type == GBL_VARIABLE)
00856 { ReplaceGlobalVariable(theEnv,newList); }
00857 #endif
00858
00859
00860
00861
00862
00863 return(newList);
00864 }
00865
00866
00867
00868
00869 globle intBool IsNandTest(
00870 struct lhsParseNode *nodeList)
00871 {
00872 if (nodeList == NULL) return(FALSE);
00873
00874 if (IsNandTest(nodeList->right))
00875 { return(TRUE); }
00876
00877 if (IsNandTest(nodeList->bottom))
00878 { return(TRUE); }
00879
00880 if ((nodeList->type == SF_VARIABLE) || (nodeList->type == MF_VARIABLE))
00881 {
00882 if (nodeList->beginNandDepth > nodeList->referringNode->beginNandDepth)
00883 { return(TRUE); }
00884 }
00885
00886 return(FALSE);
00887 }
00888
00889
00890
00891
00892
00893
00894
00895 static struct expr *GetfieldReplace(
00896 void *theEnv,
00897 struct lhsParseNode *nodeList)
00898 {
00899 struct expr *newList;
00900
00901
00902
00903
00904
00905
00906 if (nodeList == NULL) return(NULL);
00907
00908
00909
00910
00911
00912
00913
00914 newList = get_struct(theEnv,expr);
00915 newList->type = nodeList->type;
00916 newList->value = nodeList->value;
00917 newList->nextArg = GetfieldReplace(theEnv,nodeList->right);
00918 newList->argList = GetfieldReplace(theEnv,nodeList->bottom);
00919
00920
00921
00922
00923
00924
00925
00926 if ((nodeList->type == SF_VARIABLE) || (nodeList->type == MF_VARIABLE))
00927 {
00928 (*nodeList->referringNode->patternType->replaceGetPNValueFunction)
00929 (theEnv,newList,nodeList->referringNode);
00930 }
00931 #if DEFGLOBAL_CONSTRUCT
00932 else if (newList->type == GBL_VARIABLE)
00933 { ReplaceGlobalVariable(theEnv,newList); }
00934 #endif
00935
00936
00937
00938
00939
00940 return(newList);
00941 }
00942
00943
00944
00945
00946
00947 static struct expr *GenJNVariableComparison(
00948 void *theEnv,
00949 struct lhsParseNode *selfNode,
00950 struct lhsParseNode *referringNode,
00951 int isNand)
00952 {
00953 struct expr *top;
00954
00955
00956
00957
00958
00959
00960 if ((selfNode->patternType->genCompareJNValuesFunction == NULL) ||
00961 (referringNode->patternType->genCompareJNValuesFunction == NULL))
00962 { return(NULL); }
00963
00964
00965
00966
00967
00968
00969 if (selfNode->patternType->genCompareJNValuesFunction ==
00970 referringNode->patternType->genCompareJNValuesFunction)
00971
00972 {
00973 return (*selfNode->patternType->genCompareJNValuesFunction)(theEnv,selfNode,
00974 referringNode,isNand);
00975 }
00976
00977
00978
00979
00980
00981
00982
00983
00984 if (selfNode->negated) top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ);
00985 else top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ);
00986
00987 top->argList = (*selfNode->patternType->genGetJNValueFunction)(theEnv,selfNode,RHS);
00988 top->argList->nextArg = (*referringNode->patternType->genGetJNValueFunction)(theEnv,referringNode,LHS);
00989
00990 return(top);
00991 }
00992
00993
00994
00995
00996
00997 static struct expr *GenPNVariableComparison(
00998 void *theEnv,
00999 struct lhsParseNode *selfNode,
01000 struct lhsParseNode *referringNode)
01001 {
01002 if (selfNode->patternType->genComparePNValuesFunction != NULL)
01003 {
01004 return (*selfNode->patternType->genComparePNValuesFunction)(theEnv,selfNode,referringNode);
01005 }
01006
01007 return(NULL);
01008 }
01009
01010
01011
01012
01013
01014
01015 static int AllVariablesInPattern(
01016 struct lhsParseNode *orField,
01017 int pattern)
01018 {
01019 struct lhsParseNode *andField;
01020
01021
01022
01023
01024
01025 for (;
01026 orField != NULL;
01027 orField = orField->bottom)
01028 {
01029
01030
01031
01032
01033 for (andField = orField;
01034 andField != NULL;
01035 andField = andField->right)
01036 {
01037
01038
01039
01040
01041
01042
01043 if ((andField->type == SF_VARIABLE) || (andField->type == MF_VARIABLE))
01044 { if (andField->referringNode->pattern != pattern) return(FALSE); }
01045
01046
01047
01048
01049
01050
01051 else if ((andField->type == PREDICATE_CONSTRAINT) ||
01052 (andField->type == RETURN_VALUE_CONSTRAINT))
01053 {
01054 if (AllVariablesInExpression(andField->expression,pattern) == FALSE)
01055 { return(FALSE); }
01056 }
01057 }
01058 }
01059
01060
01061
01062
01063
01064
01065 return(TRUE);
01066 }
01067
01068
01069
01070
01071
01072
01073 static int AllVariablesInExpression(
01074 struct lhsParseNode *theExpression,
01075 int pattern)
01076 {
01077
01078
01079
01080
01081 for (;
01082 theExpression != NULL;
01083 theExpression = theExpression->right)
01084 {
01085
01086
01087
01088
01089
01090
01091 if ((theExpression->type == SF_VARIABLE) ||
01092 (theExpression->type == MF_VARIABLE))
01093 { if (theExpression->referringNode->pattern != pattern) return(FALSE); }
01094
01095
01096
01097
01098
01099 if (AllVariablesInExpression(theExpression->bottom,pattern) == FALSE)
01100 { return(FALSE); }
01101 }
01102
01103
01104
01105
01106
01107
01108 return(TRUE);
01109 }
01110
01111
01112
01113
01114
01115
01116 static int FieldIsNandTest(
01117 struct lhsParseNode *theField)
01118 {
01119 struct lhsParseNode *andField;
01120 struct lhsParseNode *orField;
01121
01122 if (((theField->type == SF_VARIABLE) || (theField->type == MF_VARIABLE)) &&
01123 (theField->referringNode != NULL))
01124 {
01125 if (theField->beginNandDepth > theField->referringNode->beginNandDepth)
01126 { return(TRUE); }
01127 }
01128
01129
01130
01131
01132
01133 orField = theField->bottom;
01134 for (;
01135 orField != NULL;
01136 orField = orField->bottom)
01137 {
01138
01139
01140
01141
01142 for (andField = orField;
01143 andField != NULL;
01144 andField = andField->right)
01145 {
01146
01147
01148
01149
01150
01151 if ((andField->type == SF_VARIABLE) || (andField->type == MF_VARIABLE))
01152 {
01153 if (andField->beginNandDepth > andField->referringNode->beginNandDepth)
01154 { return(TRUE); }
01155 }
01156
01157
01158
01159
01160
01161
01162
01163 else if ((andField->type == PREDICATE_CONSTRAINT) ||
01164 (andField->type == RETURN_VALUE_CONSTRAINT))
01165 {
01166 if (IsNandTest(andField->expression))
01167 { return(TRUE); }
01168 }
01169 }
01170 }
01171
01172
01173
01174
01175
01176
01177 return(FALSE);
01178 }
01179
01180 #endif
01181
01182