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 #include "setup.h"
00031
00032 #if DEFRULE_CONSTRUCT && OBJECT_SYSTEM && (! RUN_TIME) && CONSTRUCT_COMPILER
00033
00034 #include <stdio.h>
00035 #define _STDIO_INCLUDED_
00036
00037 #include "conscomp.h"
00038 #include "envrnmnt.h"
00039 #include "objrtfnx.h"
00040 #include "objrtmch.h"
00041 #include "pattern.h"
00042 #include "sysdep.h"
00043
00044 #define _OBJRTCMP_SOURCE_
00045 #include "objrtcmp.h"
00046
00047
00048
00049
00050
00051
00052 #define ObjectPNPrefix() ArbitraryPrefix(ObjectReteData(theEnv)->ObjectPatternCodeItem,0)
00053 #define ObjectANPrefix() ArbitraryPrefix(ObjectReteData(theEnv)->ObjectPatternCodeItem,1)
00054
00055
00056
00057
00058
00059
00060
00061 static void BeforeObjectPatternsToCode(void *);
00062 static OBJECT_PATTERN_NODE *GetNextObjectPatternNode(OBJECT_PATTERN_NODE *);
00063 static void InitObjectPatternsCode(void *,FILE *,int,int);
00064 static int ObjectPatternsToCode(void *,char *,char *,char *,int,FILE *,int,int);
00065 static void IntermediatePatternNodeReference(void *,OBJECT_PATTERN_NODE *,FILE *,int,int);
00066 static int IntermediatePatternNodesToCode(void *,char *,char *,char *,int,FILE *,int,int,int);
00067 static int AlphaPatternNodesToCode(void *,char *,char *,char *,int,FILE *,int,int,int);
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 globle void ObjectPatternsCompilerSetup(
00085 void *theEnv)
00086 {
00087 ObjectReteData(theEnv)->ObjectPatternCodeItem =
00088 AddCodeGeneratorItem(theEnv,"object-patterns",0,BeforeObjectPatternsToCode,
00089 InitObjectPatternsCode,ObjectPatternsToCode,2);
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 globle void ObjectPatternNodeReference(
00111 void *theEnv,
00112 void *theVPattern,
00113 FILE *theFile,
00114 int imageID,
00115 int maxIndices)
00116 {
00117 OBJECT_ALPHA_NODE *thePattern;
00118
00119 if (theVPattern == NULL)
00120 fprintf(theFile,"NULL");
00121 else
00122 {
00123 thePattern = (OBJECT_ALPHA_NODE *) theVPattern;
00124 fprintf(theFile,"&%s%d_%d[%d]",
00125 ObjectANPrefix(),imageID,
00126 (((int) thePattern->bsaveID) / maxIndices) + 1,
00127 ((int) thePattern->bsaveID) % maxIndices);
00128 }
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 static void BeforeObjectPatternsToCode(
00149 void *theEnv)
00150 {
00151 long whichPattern;
00152 OBJECT_PATTERN_NODE *intermediateNode;
00153 OBJECT_ALPHA_NODE *alphaNode;
00154
00155 whichPattern = 0L;
00156 intermediateNode = ObjectNetworkPointer(theEnv);
00157 while (intermediateNode != NULL)
00158 {
00159 intermediateNode->bsaveID = whichPattern++;
00160 intermediateNode = GetNextObjectPatternNode(intermediateNode);
00161 }
00162
00163 whichPattern = 0L;
00164 alphaNode = ObjectNetworkTerminalPointer(theEnv);
00165 while (alphaNode != NULL)
00166 {
00167 alphaNode->bsaveID = whichPattern++;
00168 alphaNode = alphaNode->nxtTerminal;
00169 }
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 static OBJECT_PATTERN_NODE *GetNextObjectPatternNode(
00183 OBJECT_PATTERN_NODE *thePattern)
00184 {
00185 if (thePattern->nextLevel != NULL)
00186 return(thePattern->nextLevel);
00187 while (thePattern->rightNode == NULL)
00188 {
00189 thePattern = thePattern->lastLevel;
00190 if (thePattern == NULL)
00191 return(NULL);
00192 }
00193 return(thePattern->rightNode);
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 static void InitObjectPatternsCode(
00210 void *theEnv,
00211 FILE *initFP,
00212 int imageID,
00213 int maxIndices)
00214 {
00215 long firstIntermediateNode,firstAlphaNode;
00216
00217 if (ObjectNetworkPointer(theEnv) != NULL)
00218 {
00219 firstIntermediateNode = ObjectNetworkPointer(theEnv)->bsaveID;
00220 firstAlphaNode = ObjectNetworkTerminalPointer(theEnv)->bsaveID;
00221 fprintf(initFP," SetObjectNetworkPointer(theEnv,&%s%d_%d[%d]);\n",
00222 ObjectPNPrefix(),imageID,
00223 (int) ((firstIntermediateNode / maxIndices) + 1),
00224 (int) (firstIntermediateNode % maxIndices));
00225 fprintf(initFP," SetObjectNetworkTerminalPointer(theEnv,&%s%d_%d[%d]);\n",
00226 ObjectANPrefix(),imageID,
00227 (int) ((firstAlphaNode / maxIndices) + 1),
00228 (int) (firstAlphaNode % maxIndices));
00229 }
00230 else
00231 {
00232 fprintf(initFP," SetObjectNetworkPointer(theEnv,NULL);\n");
00233 fprintf(initFP," SetObjectNetworkTerminalPointer(theEnv,NULL);\n");
00234 }
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 static int ObjectPatternsToCode(
00253 void *theEnv,
00254 char *fileName,
00255 char *pathName,
00256 char *fileNameBuffer,
00257 int fileID,
00258 FILE *headerFP,
00259 int imageID,
00260 int maxIndices)
00261 {
00262 int version;
00263
00264 version = IntermediatePatternNodesToCode(theEnv,fileName,pathName,fileNameBuffer,
00265 fileID,headerFP,imageID,maxIndices,1);
00266 if (version == 0)
00267 return(0);
00268 if (! AlphaPatternNodesToCode(theEnv,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID,maxIndices,version))
00269 return(0);
00270 return(1);
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 static void IntermediatePatternNodeReference(
00290 void *theEnv,
00291 OBJECT_PATTERN_NODE *thePattern,
00292 FILE *theFile,
00293 int imageID,
00294 int maxIndices)
00295 {
00296 if (thePattern == NULL)
00297 fprintf(theFile,"NULL");
00298 else
00299 {
00300 fprintf(theFile,"&%s%d_%d[%d]",
00301 ObjectPNPrefix(),imageID,
00302 (((int) thePattern->bsaveID) / maxIndices) + 1,
00303 ((int) thePattern->bsaveID) % maxIndices);
00304 }
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 static int IntermediatePatternNodesToCode(
00323 void *theEnv,
00324 char *fileName,
00325 char *pathName,
00326 char *fileNameBuffer,
00327 int fileID,
00328 FILE *headerFP,
00329 int imageID,
00330 int maxIndices,
00331 int version)
00332 {
00333 FILE *fp;
00334 int arrayVersion;
00335 int newHeader;
00336 int i;
00337 OBJECT_PATTERN_NODE *thePattern;
00338
00339
00340
00341
00342 if (ObjectNetworkPointer(theEnv) == NULL)
00343 return(1);
00344
00345 fprintf(headerFP,"#include \"objrtmch.h\"\n");
00346
00347
00348
00349
00350 if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL)
00351 return(0);
00352 newHeader = TRUE;
00353
00354 arrayVersion = 1;
00355 i = 1;
00356
00357 thePattern = ObjectNetworkPointer(theEnv);
00358 while (thePattern != NULL)
00359 {
00360 if (newHeader)
00361 {
00362 fprintf(fp,"OBJECT_PATTERN_NODE %s%d_%d[] = {\n",
00363 ObjectPNPrefix(),imageID,arrayVersion);
00364 fprintf(headerFP,"extern OBJECT_PATTERN_NODE %s%d_%d[];\n",
00365 ObjectPNPrefix(),imageID,arrayVersion);
00366 newHeader = FALSE;
00367 }
00368 fprintf(fp,"{0,%u,%u,%u,%u,%u,0L,%u,",thePattern->multifieldNode,
00369 thePattern->endSlot,
00370 thePattern->selector,
00371 thePattern->whichField,
00372 thePattern->leaveFields,
00373 thePattern->slotNameID);
00374
00375 PrintHashedExpressionReference(theEnv,fp,thePattern->networkTest,imageID,maxIndices);
00376 fprintf(fp,",");
00377 IntermediatePatternNodeReference(theEnv,thePattern->nextLevel,fp,imageID,maxIndices);
00378 fprintf(fp,",");
00379 IntermediatePatternNodeReference(theEnv,thePattern->lastLevel,fp,imageID,maxIndices);
00380 fprintf(fp,",");
00381 IntermediatePatternNodeReference(theEnv,thePattern->leftNode,fp,imageID,maxIndices);
00382 fprintf(fp,",");
00383 IntermediatePatternNodeReference(theEnv,thePattern->rightNode,fp,imageID,maxIndices);
00384 fprintf(fp,",");
00385 ObjectPatternNodeReference(theEnv,(void *) thePattern->alphaNode,fp,imageID,maxIndices);
00386 fprintf(fp,",0L}");
00387
00388 i++;
00389 thePattern = GetNextObjectPatternNode(thePattern);
00390
00391 if ((i > maxIndices) || (thePattern == NULL))
00392 {
00393 fprintf(fp,"};\n");
00394 GenClose(theEnv,fp);
00395 i = 1;
00396 version++;
00397 arrayVersion++;
00398 if (thePattern != NULL)
00399 {
00400 if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL)
00401 return(0);
00402 newHeader = TRUE;
00403 }
00404 }
00405 else if (thePattern != NULL)
00406 { fprintf(fp,",\n"); }
00407 }
00408
00409 return(version);
00410 }
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 static int AlphaPatternNodesToCode(
00428 void *theEnv,
00429 char *fileName,
00430 char *pathName,
00431 char *fileNameBuffer,
00432 int fileID,
00433 FILE *headerFP,
00434 int imageID,
00435 int maxIndices,
00436 int version)
00437 {
00438 FILE *fp;
00439 int arrayVersion;
00440 int newHeader;
00441 int i;
00442 OBJECT_ALPHA_NODE *thePattern;
00443
00444
00445
00446
00447 if (ObjectNetworkTerminalPointer(theEnv) == NULL)
00448 return(version);
00449
00450
00451
00452
00453 if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL)
00454 return(0);
00455 newHeader = TRUE;
00456
00457 arrayVersion = 1;
00458 i = 1;
00459
00460 thePattern = ObjectNetworkTerminalPointer(theEnv);
00461 while (thePattern != NULL)
00462 {
00463 if (newHeader)
00464 {
00465 fprintf(fp,"OBJECT_ALPHA_NODE %s%d_%d[] = {\n",
00466 ObjectANPrefix(),imageID,arrayVersion);
00467 fprintf(headerFP,"extern OBJECT_ALPHA_NODE %s%d_%d[];\n",
00468 ObjectANPrefix(),imageID,arrayVersion);
00469 newHeader = FALSE;
00470 }
00471
00472 fprintf(fp,"{");
00473
00474 PatternNodeHeaderToCode(theEnv,fp,&thePattern->header,imageID,maxIndices);
00475
00476 fprintf(fp,",0L,");
00477 PrintBitMapReference(theEnv,fp,thePattern->classbmp);
00478 fprintf(fp,",");
00479 PrintBitMapReference(theEnv,fp,thePattern->slotbmp);
00480 fprintf(fp,",");
00481 IntermediatePatternNodeReference(theEnv,thePattern->patternNode,fp,imageID,maxIndices);
00482 fprintf(fp,",");
00483 ObjectPatternNodeReference(theEnv,thePattern->nxtInGroup,fp,imageID,maxIndices);
00484 fprintf(fp,",");
00485 ObjectPatternNodeReference(theEnv,thePattern->nxtTerminal,fp,imageID,maxIndices);
00486 fprintf(fp,",0L}");
00487
00488 i++;
00489 thePattern = thePattern->nxtTerminal;
00490
00491 if ((i > maxIndices) || (thePattern == NULL))
00492 {
00493 fprintf(fp,"};\n");
00494 GenClose(theEnv,fp);
00495 i = 1;
00496 version++;
00497 arrayVersion++;
00498 if (thePattern != NULL)
00499 {
00500 if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL)
00501 return(0);
00502 newHeader = TRUE;
00503 }
00504 }
00505 else if (thePattern != NULL)
00506 { fprintf(fp,",\n"); }
00507 }
00508
00509 return(version);
00510 }
00511
00512 #endif