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 DEFRULE_CONSTRUCT && OBJECT_SYSTEM && (! RUN_TIME) && (! BLOAD_ONLY)
00036
00037 #ifndef _STDIO_INCLUDED_
00038 #include <stdio.h>
00039 #define _STDIO_INCLUDED_
00040 #endif
00041
00042 #include "classfun.h"
00043 #include "envrnmnt.h"
00044 #include "objrtfnx.h"
00045
00046 #define _OBJRTGEN_SOURCE_
00047 #include "objrtgen.h"
00048
00049
00050
00051
00052
00053
00054
00055 static void GenObjectGetVar(void *,int,EXPRESSION *,struct lhsParseNode *,int);
00056 static intBool IsSimpleSlotVariable(struct lhsParseNode *);
00057 static EXPRESSION *GenerateSlotComparisonTest(void *,int,int,struct lhsParseNode *,struct lhsParseNode *);
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 globle void ReplaceGetJNObjectValue(
00070 void *theEnv,
00071 EXPRESSION *theItem,
00072 struct lhsParseNode *theNode,
00073 int side)
00074 {
00075 GenObjectGetVar(theEnv,TRUE,theItem,theNode,side);
00076 }
00077
00078 globle EXPRESSION *GenGetJNObjectValue(
00079 void *theEnv,
00080 struct lhsParseNode *theNode,
00081 int side)
00082 {
00083 EXPRESSION *theItem;
00084
00085 theItem = GenConstant(theEnv,0,NULL);
00086 GenObjectGetVar(theEnv,TRUE,theItem,theNode,side);
00087 return(theItem);
00088 }
00089
00090 globle EXPRESSION *ObjectJNVariableComparison(
00091 void *theEnv,
00092 struct lhsParseNode *selfNode,
00093 struct lhsParseNode *referringNode,
00094 int isNand)
00095 {
00096 return(GenerateSlotComparisonTest(theEnv,TRUE,isNand,selfNode,referringNode));
00097 }
00098
00099
00100
00101
00102
00103 globle EXPRESSION *GenObjectPNConstantCompare(
00104 void *theEnv,
00105 struct lhsParseNode *theNode)
00106 {
00107 struct ObjectCmpPNConstant hack;
00108 EXPRESSION *theExp;
00109 unsigned short tmpType;
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 ClearBitString((void *) &hack,(int) sizeof(struct ObjectCmpPNConstant));
00125 if (theNode->negated)
00126 hack.fail = 1;
00127 else
00128 hack.pass = 1;
00129 if (((theNode->withinMultifieldSlot == FALSE) ||
00130 (theNode->multiFieldsAfter == 0) ||
00131 (theNode->multiFieldsBefore == 0)) &&
00132 (theNode->slotNumber != ISA_ID) && (theNode->slotNumber != NAME_ID))
00133 {
00134 if (theNode->withinMultifieldSlot == FALSE)
00135 hack.fromBeginning = TRUE;
00136 else if (theNode->multiFieldsBefore == 0)
00137 {
00138 hack.fromBeginning = TRUE;
00139 hack.offset = theNode->singleFieldsBefore;
00140 }
00141 else
00142 hack.offset = theNode->singleFieldsAfter;
00143 theExp = GenConstant(theEnv,OBJ_PN_CONSTANT,EnvAddBitMap(theEnv,(void *) &hack,
00144 (int) sizeof(struct ObjectCmpPNConstant)));
00145 theExp->argList = GenConstant(theEnv,theNode->type,theNode->value);
00146 }
00147 else
00148 {
00149 hack.general = 1;
00150 theExp = GenConstant(theEnv,OBJ_PN_CONSTANT,EnvAddBitMap(theEnv,(void *) &hack,
00151 (int) sizeof(struct ObjectCmpPNConstant)));
00152 theExp->argList = GenConstant(theEnv,0,NULL);
00153 tmpType = theNode->type;
00154 theNode->type = SF_VARIABLE;
00155 GenObjectGetVar(theEnv,FALSE,theExp->argList,theNode,-1);
00156 theNode->type = tmpType;
00157 theExp->argList->nextArg = GenConstant(theEnv,theNode->type,theNode->value);
00158 }
00159 return(theExp);
00160 }
00161
00162 globle void ReplaceGetPNObjectValue(
00163 void *theEnv,
00164 EXPRESSION *theItem,
00165 struct lhsParseNode *theNode)
00166 {
00167 GenObjectGetVar(theEnv,FALSE,theItem,theNode,-1);
00168 }
00169
00170 globle EXPRESSION *GenGetPNObjectValue(
00171 void *theEnv,
00172 struct lhsParseNode *theNode)
00173 {
00174 EXPRESSION *theItem;
00175
00176 theItem = GenConstant(theEnv,0,NULL);
00177 GenObjectGetVar(theEnv,FALSE,theItem,theNode,-1);
00178 return(theItem);
00179 }
00180
00181 globle EXPRESSION *ObjectPNVariableComparison(
00182 void *theEnv,
00183 struct lhsParseNode *selfNode,
00184 struct lhsParseNode *referringNode)
00185 {
00186 return(GenerateSlotComparisonTest(theEnv,FALSE,FALSE,selfNode,referringNode));
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 globle void GenObjectLengthTest(
00201 void *theEnv,
00202 struct lhsParseNode *theNode)
00203 {
00204 struct ObjectMatchLength hack;
00205 EXPRESSION *theTest;
00206
00207 if ((theNode->singleFieldsAfter == 0) &&
00208 (theNode->type != SF_VARIABLE) &&
00209 (theNode->type != SF_WILDCARD))
00210 return;
00211
00212 ClearBitString((void *) &hack,(int) sizeof(struct ObjectMatchLength));
00213
00214 if ((theNode->type != MF_VARIABLE) &&
00215 (theNode->type != MF_WILDCARD) &&
00216 (theNode->multiFieldsAfter == 0))
00217 hack.exactly = 1;
00218 else
00219 hack.exactly = 0;
00220
00221 if ((theNode->type == SF_VARIABLE) || (theNode->type == SF_WILDCARD))
00222 hack.minLength = 1 + theNode->singleFieldsAfter;
00223 else
00224 hack.minLength = theNode->singleFieldsAfter;
00225
00226 theTest = GenConstant(theEnv,OBJ_SLOT_LENGTH,EnvAddBitMap(theEnv,(void *) &hack,
00227 (int) sizeof(struct ObjectMatchLength)));
00228
00229 if (theNode->constantSelector != NULL)
00230 { theNode->constantSelector->nextArg = CopyExpression(theEnv,theTest); }
00231
00232 theNode->networkTest = CombineExpressions(theEnv,theTest,theNode->networkTest);
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 globle void GenObjectZeroLengthTest(
00247 void *theEnv,
00248 struct lhsParseNode *theNode)
00249 {
00250 struct ObjectMatchLength hack;
00251 EXPRESSION *theTest;
00252
00253 ClearBitString((void *) &hack,(int) sizeof(struct ObjectMatchLength));
00254 hack.exactly = 1;
00255 hack.minLength = 0;
00256 theTest = GenConstant(theEnv,OBJ_SLOT_LENGTH,EnvAddBitMap(theEnv,(void *) &hack,
00257 (int) sizeof(struct ObjectMatchLength)));
00258 theNode->networkTest = CombineExpressions(theEnv,theTest,theNode->networkTest);
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 static void GenObjectGetVar(
00287 void *theEnv,
00288 int joinReference,
00289 EXPRESSION *theItem,
00290 struct lhsParseNode *theNode,
00291 int side)
00292 {
00293 struct ObjectMatchVar1 hack1;
00294 struct ObjectMatchVar2 hack2;
00295
00296 ClearBitString((void *) &hack1,(int) sizeof(struct ObjectMatchVar1));
00297 ClearBitString((void *) &hack2,(int) sizeof(struct ObjectMatchVar2));
00298
00299 if (joinReference)
00300 {
00301 if (side == LHS)
00302 {
00303 hack1.lhs = 1;
00304 hack2.lhs = 1;
00305 hack1.whichPattern = (unsigned short) theNode->joinDepth;
00306 hack2.whichPattern = (unsigned short) theNode->joinDepth;
00307 }
00308 else if (side == RHS)
00309 {
00310 hack1.rhs = 1;
00311 hack2.rhs = 1;
00312 hack1.whichPattern = (unsigned short) 0;
00313 hack2.whichPattern = (unsigned short) 0;
00314 }
00315 else if (side == NESTED_RHS)
00316 {
00317 hack1.rhs = 1;
00318 hack2.rhs = 1;
00319 hack1.whichPattern = (unsigned short) theNode->joinDepth;
00320 hack2.whichPattern = (unsigned short) theNode->joinDepth;
00321 }
00322 else
00323 {
00324 hack1.whichPattern = (unsigned short) theNode->joinDepth;
00325 hack2.whichPattern = (unsigned short) theNode->joinDepth;
00326 }
00327 }
00328
00329
00330
00331
00332 if (theNode->slotNumber < 0)
00333 {
00334 hack1.objectAddress = 1;
00335 SetpType(theItem,(joinReference ? OBJ_GET_SLOT_JNVAR1 : OBJ_GET_SLOT_PNVAR1));
00336 theItem->value = EnvAddBitMap(theEnv,(void *) &hack1,(int) sizeof(struct ObjectMatchVar1));
00337 return;
00338 }
00339
00340
00341
00342
00343 if ((theNode->singleFieldsBefore == 0) &&
00344 (theNode->singleFieldsAfter == 0) &&
00345 (theNode->multiFieldsBefore == 0) &&
00346 (theNode->multiFieldsAfter == 0) &&
00347 ((theNode->withinMultifieldSlot == FALSE) ||
00348 (theNode->type == MF_VARIABLE) ||
00349 (theNode->type == MF_WILDCARD)))
00350 {
00351 hack1.allFields = 1;
00352 hack1.whichSlot = (unsigned short) theNode->slotNumber;
00353 theItem->type = (unsigned short) (joinReference ? OBJ_GET_SLOT_JNVAR1 : OBJ_GET_SLOT_PNVAR1);
00354 theItem->value = EnvAddBitMap(theEnv,(void *) &hack1,(int) sizeof(struct ObjectMatchVar1));
00355 return;
00356 }
00357
00358
00359
00360
00361
00362
00363 if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE) || ConstantType(theNode->type)) &&
00364 ((theNode->multiFieldsBefore == 0) || (theNode->multiFieldsAfter == 0)))
00365 {
00366 hack2.whichSlot = (unsigned short) theNode->slotNumber;
00367 if (theNode->multiFieldsBefore == 0)
00368 {
00369 hack2.fromBeginning = 1;
00370 hack2.beginningOffset = theNode->singleFieldsBefore;
00371 }
00372 else
00373 {
00374 hack2.fromEnd = 1;
00375 hack2.endOffset = theNode->singleFieldsAfter;
00376 }
00377 theItem->type = (unsigned short) (joinReference ? OBJ_GET_SLOT_JNVAR2 : OBJ_GET_SLOT_PNVAR2);
00378 theItem->value = EnvAddBitMap(theEnv,(void *) &hack2,sizeof(struct ObjectMatchVar2));
00379 return;
00380 }
00381
00382 if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE) || ConstantType(theNode->type)) &&
00383 (theNode->multiFieldsBefore == 0) &&
00384 (theNode->multiFieldsAfter == 0))
00385 {
00386 hack2.whichSlot = (unsigned short) theNode->slotNumber;
00387 hack2.fromBeginning = 1;
00388 hack2.fromEnd = 1;
00389 hack2.beginningOffset = theNode->singleFieldsBefore;
00390 hack2.endOffset = theNode->singleFieldsAfter;
00391 theItem->type = (unsigned short) (joinReference ? OBJ_GET_SLOT_JNVAR2 : OBJ_GET_SLOT_PNVAR2);
00392 theItem->value = EnvAddBitMap(theEnv,(void *) &hack2,sizeof(struct ObjectMatchVar2));
00393 return;
00394 }
00395
00396
00397
00398
00399 hack1.whichSlot = (unsigned short) theNode->slotNumber;
00400 hack1.whichField = (unsigned short) theNode->index;
00401 theItem->type = (unsigned short) (joinReference ? OBJ_GET_SLOT_JNVAR1 : OBJ_GET_SLOT_PNVAR1);
00402 theItem->value = EnvAddBitMap(theEnv,(void *) &hack1,sizeof(struct ObjectMatchVar1));
00403 }
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 static intBool IsSimpleSlotVariable(
00419 struct lhsParseNode *node)
00420 {
00421 if ((node->type == MF_WILDCARD) || (node->type == MF_VARIABLE))
00422 return(FALSE);
00423 if ((node->slotNumber < 0) ||
00424 (node->slotNumber == ISA_ID) ||
00425 (node->slotNumber == NAME_ID))
00426 return(FALSE);
00427 if (node->withinMultifieldSlot == FALSE)
00428 return(TRUE);
00429 if (node->multifieldSlot == TRUE)
00430 return(FALSE);
00431 if ((node->multiFieldsBefore == 0) || (node->multiFieldsAfter == 0))
00432 return(TRUE);
00433 return(FALSE);
00434 }
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467 static EXPRESSION *GenerateSlotComparisonTest(
00468 void *theEnv,
00469 int joinTest,
00470 int isNand,
00471 struct lhsParseNode *selfNode,
00472 struct lhsParseNode *referringNode)
00473 {
00474 EXPRESSION *theExp;
00475 struct ObjectCmpPNSingleSlotVars1 phack1;
00476 struct ObjectCmpPNSingleSlotVars2 phack2;
00477 struct ObjectCmpPNSingleSlotVars3 phack3;
00478 struct ObjectCmpJoinSingleSlotVars1 jhack1;
00479 struct ObjectCmpJoinSingleSlotVars2 jhack2;
00480 struct ObjectCmpJoinSingleSlotVars3 jhack3;
00481
00482
00483
00484
00485
00486
00487
00488 if (IsSimpleSlotVariable(selfNode) && IsSimpleSlotVariable(referringNode))
00489 {
00490
00491
00492
00493 if ((selfNode->withinMultifieldSlot == FALSE) &&
00494 (referringNode->withinMultifieldSlot == FALSE))
00495 {
00496 ClearBitString((void *) &phack1,(int) sizeof(struct ObjectCmpPNSingleSlotVars1));
00497 ClearBitString((void *) &jhack1,(int) sizeof(struct ObjectCmpJoinSingleSlotVars1));
00498 if (selfNode->negated)
00499 phack1.fail = jhack1.fail = 1;
00500 else
00501 phack1.pass = jhack1.pass = 1;
00502 phack1.firstSlot = jhack1.firstSlot = (unsigned short) selfNode->slotNumber;
00503 phack1.secondSlot = jhack1.secondSlot = (unsigned short) referringNode->slotNumber;
00504 if (joinTest)
00505 {
00506 if (isNand)
00507 { jhack1.firstPattern = (unsigned short) selfNode->joinDepth; }
00508 else
00509 { jhack1.firstPattern = 0; }
00510 jhack1.firstPatternRHS = TRUE;
00511
00512 if (isNand && (selfNode->beginNandDepth == referringNode->beginNandDepth))
00513 { jhack1.secondPatternRHS = TRUE; }
00514 else
00515 { jhack1.secondPatternLHS = TRUE; }
00516 jhack1.secondPattern = (unsigned short) referringNode->joinDepth;
00517
00518 theExp = GenConstant(theEnv,OBJ_JN_CMP1,EnvAddBitMap(theEnv,(void *) &jhack1,
00519 (int) sizeof(struct ObjectCmpJoinSingleSlotVars1)));
00520 }
00521 else
00522 theExp = GenConstant(theEnv,OBJ_PN_CMP1,EnvAddBitMap(theEnv,(void *) &phack1,
00523 (int) sizeof(struct ObjectCmpPNSingleSlotVars1)));
00524 }
00525
00526
00527
00528
00529
00530 else if ((selfNode->withinMultifieldSlot == FALSE) ||
00531 (referringNode->withinMultifieldSlot == FALSE))
00532 {
00533 ClearBitString((void *) &phack2,(int) sizeof(struct ObjectCmpPNSingleSlotVars2));
00534 ClearBitString((void *) &jhack2,(int) sizeof(struct ObjectCmpJoinSingleSlotVars2));
00535 if (selfNode->negated)
00536 phack2.fail = jhack2.fail = 1;
00537 else
00538 phack2.pass = jhack2.pass = 1;
00539 if (selfNode->withinMultifieldSlot == TRUE)
00540 {
00541 phack2.firstSlot = jhack2.firstSlot = (unsigned short) selfNode->slotNumber;
00542 phack2.secondSlot = jhack2.secondSlot = (unsigned short) referringNode->slotNumber;
00543 if (joinTest)
00544 {
00545 if (isNand)
00546 { jhack2.firstPattern = (unsigned short) selfNode->joinDepth; }
00547 else
00548 { jhack2.firstPattern = 0; }
00549 jhack2.firstPatternRHS = TRUE;
00550
00551 if (isNand && (selfNode->beginNandDepth == referringNode->beginNandDepth))
00552 { jhack2.secondPatternRHS = TRUE; }
00553 else
00554 { jhack2.secondPatternLHS = TRUE; }
00555 jhack2.secondPattern = (unsigned short) referringNode->joinDepth;
00556 }
00557 if (selfNode->multiFieldsBefore == 0)
00558 {
00559 phack2.fromBeginning = jhack2.fromBeginning = 1;
00560 phack2.offset = jhack2.offset = selfNode->singleFieldsBefore;
00561 }
00562 else
00563 phack2.offset = jhack2.offset = selfNode->singleFieldsAfter;
00564 }
00565 else
00566 {
00567 phack2.firstSlot = jhack2.firstSlot = (unsigned short) referringNode->slotNumber;
00568 phack2.secondSlot = jhack2.secondSlot = (unsigned short) selfNode->slotNumber;
00569 if (joinTest)
00570 {
00571 if (isNand)
00572 { jhack2.secondPattern = (unsigned short) selfNode->joinDepth; }
00573 else
00574 { jhack2.secondPattern = 0; }
00575 jhack2.secondPatternRHS = TRUE;
00576
00577 if (isNand && (selfNode->beginNandDepth == referringNode->beginNandDepth))
00578 { jhack2.firstPatternRHS = TRUE; }
00579 else
00580 { jhack2.firstPatternLHS = TRUE; }
00581 jhack2.firstPattern = (unsigned short) referringNode->joinDepth;
00582 }
00583 if (referringNode->multiFieldsBefore == 0)
00584 {
00585 phack2.fromBeginning = jhack2.fromBeginning = 1;
00586 phack2.offset = jhack2.offset = referringNode->singleFieldsBefore;
00587 }
00588 else
00589 phack2.offset = jhack2.offset = referringNode->singleFieldsAfter;
00590 }
00591 if (joinTest)
00592 theExp = GenConstant(theEnv,OBJ_JN_CMP2,EnvAddBitMap(theEnv,(void *) &jhack2,
00593 (int) sizeof(struct ObjectCmpJoinSingleSlotVars2)));
00594 else
00595 theExp = GenConstant(theEnv,OBJ_PN_CMP2,EnvAddBitMap(theEnv,(void *) &phack2,
00596 (int) sizeof(struct ObjectCmpPNSingleSlotVars2)));
00597 }
00598
00599
00600
00601
00602
00603 else
00604 {
00605 ClearBitString((void *) &phack3,(int) sizeof(struct ObjectCmpPNSingleSlotVars3));
00606 ClearBitString((void *) &jhack3,(int) sizeof(struct ObjectCmpJoinSingleSlotVars3));
00607 if (selfNode->negated)
00608 phack3.fail = jhack3.fail = 1;
00609 else
00610 phack3.pass = jhack3.pass = 1;
00611 phack3.firstSlot = jhack3.firstSlot = (unsigned short) selfNode->slotNumber;
00612 phack3.secondSlot = jhack3.secondSlot = (unsigned short) referringNode->slotNumber;
00613 if (selfNode->multiFieldsBefore == 0)
00614 {
00615 phack3.firstFromBeginning = jhack3.firstFromBeginning = 1;
00616 phack3.firstOffset = jhack3.firstOffset = selfNode->singleFieldsBefore;
00617 }
00618 else
00619 phack3.firstOffset = jhack3.firstOffset = selfNode->singleFieldsAfter;
00620 if (referringNode->multiFieldsBefore == 0)
00621 {
00622 phack3.secondFromBeginning = jhack3.secondFromBeginning = 1;
00623 phack3.secondOffset = jhack3.secondOffset = referringNode->singleFieldsBefore;
00624 }
00625 else
00626 phack3.secondOffset = jhack3.secondOffset = referringNode->singleFieldsAfter;
00627 if (joinTest)
00628 {
00629 if (isNand)
00630 { jhack3.firstPattern = (unsigned short) selfNode->joinDepth; }
00631 else
00632 { jhack3.firstPattern = 0; }
00633 jhack3.firstPatternRHS = TRUE;
00634
00635 if (isNand && (selfNode->beginNandDepth == referringNode->beginNandDepth))
00636 { jhack3.secondPatternRHS = TRUE; }
00637 else
00638 { jhack3.secondPatternLHS = TRUE; }
00639 jhack3.secondPattern = (unsigned short) referringNode->joinDepth;
00640
00641 theExp = GenConstant(theEnv,OBJ_JN_CMP3,EnvAddBitMap(theEnv,(void *) &jhack3,
00642 (int) sizeof(struct ObjectCmpJoinSingleSlotVars3)));
00643 }
00644 else
00645 theExp = GenConstant(theEnv,OBJ_PN_CMP3,EnvAddBitMap(theEnv,(void *) &phack3,
00646 (int) sizeof(struct ObjectCmpPNSingleSlotVars3)));
00647 }
00648 }
00649
00650
00651
00652
00653
00654
00655 else
00656 {
00657 theExp = GenConstant(theEnv,FCALL,selfNode->negated ? ExpressionData(theEnv)->PTR_NEQ : ExpressionData(theEnv)->PTR_EQ);
00658 theExp->argList = GenConstant(theEnv,0,NULL);
00659
00660 if (isNand)
00661 { GenObjectGetVar(theEnv,joinTest,theExp->argList,selfNode,NESTED_RHS); }
00662 else
00663 { GenObjectGetVar(theEnv,joinTest,theExp->argList,selfNode,RHS); }
00664
00665 theExp->argList->nextArg = GenConstant(theEnv,0,NULL);
00666
00667 if (isNand && (selfNode->beginNandDepth == referringNode->beginNandDepth))
00668 { GenObjectGetVar(theEnv,joinTest,theExp->argList->nextArg,referringNode,NESTED_RHS); }
00669 else
00670 { GenObjectGetVar(theEnv,joinTest,theExp->argList->nextArg,referringNode,LHS); }
00671 }
00672 return(theExp);
00673 }
00674
00675 #endif
00676
00677
00678
00679
00680
00681
00682
00683
00684