?? objrtfnx.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.30 10/19/06 */ /* */ /* INFERENCE ENGINE OBJECT ACCESS ROUTINES MODULE */ /*******************************************************//**************************************************************//* Purpose: RETE Network Interface for Objects *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 *//* *//* 6.24: Converted INSTANCE_PATTERN_MATCHING to *//* DEFRULE_CONSTRUCT. *//* *//* Renamed BOOLEAN macro type to intBool. *//* *//* 6.30: Added support for hashed alpha memories. *//* *//**************************************************************//* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if DEFRULE_CONSTRUCT && OBJECT_SYSTEM#include <stdio.h>#define _STDIO_INCLUDED_#include <string.h>#include "classcom.h"#include "classfun.h"#if DEVELOPER#include "exprnops.h"#endif#if BLOAD || BLOAD_AND_BSAVE#include "bload.h"#endif#include "constant.h"#include "drive.h"#include "engine.h"#include "envrnmnt.h"#include "memalloc.h"#include "multifld.h"#include "objrtmch.h"#include "reteutil.h"#include "router.h"#define _OBJRTFNX_SOURCE_#include "objrtfnx.h"/* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */#define GetInsSlot(ins,si) ins->slotAddresses[ins->cls->slotNameMap[si]-1]/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */static void PrintObjectGetVarJN1(void *,char *,void *);static intBool ObjectGetVarJNFunction1(void *,void *,DATA_OBJECT *);static void PrintObjectGetVarJN2(void *,char *,void *);static intBool ObjectGetVarJNFunction2(void *,void *,DATA_OBJECT *);static void PrintObjectGetVarPN1(void *,char *,void *);static intBool ObjectGetVarPNFunction1(void *,void *,DATA_OBJECT *);static void PrintObjectGetVarPN2(void *,char *,void *);static intBool ObjectGetVarPNFunction2(void *,void *,DATA_OBJECT *);static void PrintObjectCmpConstant(void *,char *,void *);static void PrintSlotLengthTest(void *,char *,void *);static intBool SlotLengthTestFunction(void *,void *,DATA_OBJECT *);static void PrintPNSimpleCompareFunction1(void *,char *,void *);static intBool PNSimpleCompareFunction1(void *,void *,DATA_OBJECT *);static void PrintPNSimpleCompareFunction2(void *,char *,void *);static intBool PNSimpleCompareFunction2(void *,void *,DATA_OBJECT *);static void PrintPNSimpleCompareFunction3(void *,char *,void *);static intBool PNSimpleCompareFunction3(void *,void *,DATA_OBJECT *);static void PrintJNSimpleCompareFunction1(void *,char *,void *);static intBool JNSimpleCompareFunction1(void *,void *,DATA_OBJECT *);static void PrintJNSimpleCompareFunction2(void *,char *,void *);static intBool JNSimpleCompareFunction2(void *,void *,DATA_OBJECT *);static void PrintJNSimpleCompareFunction3(void *,char *,void *);static intBool JNSimpleCompareFunction3(void *,void *,DATA_OBJECT *);static void GetPatternObjectAndMarks(void *,int,int,int,INSTANCE_TYPE **,struct multifieldMarker **);static void GetObjectValueGeneral(void *,DATA_OBJECT *,INSTANCE_TYPE *, struct multifieldMarker *,struct ObjectMatchVar1 *);static void GetObjectValueSimple(void *,DATA_OBJECT *,INSTANCE_TYPE *,struct ObjectMatchVar2 *);static long CalculateSlotField(struct multifieldMarker *,INSTANCE_SLOT *,long,long *); /* 6.04 Bug Fix */static void GetInsMultiSlotField(FIELD *,INSTANCE_TYPE *,unsigned,unsigned,unsigned);static void DeallocateObjectReteData(void *);static void DestroyObjectPatternNetwork(void *,OBJECT_PATTERN_NODE *);static void DestroyObjectAlphaNodes(void *,OBJECT_ALPHA_NODE *);/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//*************************************************** NAME : InstallObjectPrimitives DESCRIPTION : Installs all the entity records associated with object pattern matching operations INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Primitive operations installed NOTES : None ***************************************************/globle void InstallObjectPrimitives( void *theEnv) { struct entityRecord objectGVInfo1 = { "OBJ_GET_SLOT_JNVAR1", OBJ_GET_SLOT_JNVAR1,0,1,0, PrintObjectGetVarJN1, PrintObjectGetVarJN1,NULL, ObjectGetVarJNFunction1, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord objectGVInfo2 = { "OBJ_GET_SLOT_JNVAR2", OBJ_GET_SLOT_JNVAR2,0,1,0, PrintObjectGetVarJN2, PrintObjectGetVarJN2,NULL, ObjectGetVarJNFunction2, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord objectGVPNInfo1 = { "OBJ_GET_SLOT_PNVAR1", OBJ_GET_SLOT_PNVAR1,0,1,0, PrintObjectGetVarPN1, PrintObjectGetVarPN1,NULL, ObjectGetVarPNFunction1, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord objectGVPNInfo2 = { "OBJ_GET_SLOT_PNVAR2", OBJ_GET_SLOT_PNVAR2,0,1,0, PrintObjectGetVarPN2, PrintObjectGetVarPN2,NULL, ObjectGetVarPNFunction2, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord objectCmpConstantInfo = { "OBJ_PN_CONSTANT", OBJ_PN_CONSTANT,0,1,1, PrintObjectCmpConstant, PrintObjectCmpConstant,NULL, ObjectCmpConstantFunction, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord lengthTestInfo = { "OBJ_SLOT_LENGTH", OBJ_SLOT_LENGTH,0,1,0, PrintSlotLengthTest, PrintSlotLengthTest,NULL, SlotLengthTestFunction, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord pNSimpleCompareInfo1 = { "OBJ_PN_CMP1", OBJ_PN_CMP1,0,1,1, PrintPNSimpleCompareFunction1, PrintPNSimpleCompareFunction1,NULL, PNSimpleCompareFunction1, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord pNSimpleCompareInfo2 = { "OBJ_PN_CMP2", OBJ_PN_CMP2,0,1,1, PrintPNSimpleCompareFunction2, PrintPNSimpleCompareFunction2,NULL, PNSimpleCompareFunction2, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord pNSimpleCompareInfo3 = { "OBJ_PN_CMP3", OBJ_PN_CMP3,0,1,1, PrintPNSimpleCompareFunction3, PrintPNSimpleCompareFunction3,NULL, PNSimpleCompareFunction3, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord jNSimpleCompareInfo1 = { "OBJ_JN_CMP1", OBJ_JN_CMP1,0,1,1, PrintJNSimpleCompareFunction1, PrintJNSimpleCompareFunction1,NULL, JNSimpleCompareFunction1, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord jNSimpleCompareInfo2 = { "OBJ_JN_CMP2", OBJ_JN_CMP2,0,1,1, PrintJNSimpleCompareFunction2, PrintJNSimpleCompareFunction2,NULL, JNSimpleCompareFunction2, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord jNSimpleCompareInfo3 = { "OBJ_JN_CMP3", OBJ_JN_CMP3,0,1,1, PrintJNSimpleCompareFunction3, PrintJNSimpleCompareFunction3,NULL, JNSimpleCompareFunction3, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; AllocateEnvironmentData(theEnv,OBJECT_RETE_DATA,sizeof(struct objectReteData),DeallocateObjectReteData); ObjectReteData(theEnv)->CurrentObjectSlotLength = 1; memcpy(&ObjectReteData(theEnv)->ObjectGVInfo1,&objectGVInfo1,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->ObjectGVInfo2,&objectGVInfo2,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->ObjectGVPNInfo1,&objectGVPNInfo1,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->ObjectGVPNInfo2,&objectGVPNInfo2,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->ObjectCmpConstantInfo,&objectCmpConstantInfo,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->LengthTestInfo,&lengthTestInfo,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->PNSimpleCompareInfo1,&pNSimpleCompareInfo1,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->PNSimpleCompareInfo2,&pNSimpleCompareInfo2,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->PNSimpleCompareInfo3,&pNSimpleCompareInfo3,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->JNSimpleCompareInfo1,&jNSimpleCompareInfo1,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->JNSimpleCompareInfo2,&jNSimpleCompareInfo2,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->JNSimpleCompareInfo3,&jNSimpleCompareInfo3,sizeof(struct entityRecord)); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectGVInfo1,OBJ_GET_SLOT_JNVAR1); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectGVInfo2,OBJ_GET_SLOT_JNVAR2); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectGVPNInfo1,OBJ_GET_SLOT_PNVAR1); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectGVPNInfo2,OBJ_GET_SLOT_PNVAR2); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectCmpConstantInfo,OBJ_PN_CONSTANT); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->LengthTestInfo,OBJ_SLOT_LENGTH); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->PNSimpleCompareInfo1,OBJ_PN_CMP1); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->PNSimpleCompareInfo2,OBJ_PN_CMP2); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->PNSimpleCompareInfo3,OBJ_PN_CMP3); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->JNSimpleCompareInfo1,OBJ_JN_CMP1); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->JNSimpleCompareInfo2,OBJ_JN_CMP2); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->JNSimpleCompareInfo3,OBJ_JN_CMP3); } /*****************************************************//* DeallocateObjectReteData: Deallocates environment *//* data for the object rete network. *//*****************************************************/static void DeallocateObjectReteData( void *theEnv) { OBJECT_PATTERN_NODE *theNetwork; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) return;#endif theNetwork = ObjectReteData(theEnv)->ObjectPatternNetworkPointer; DestroyObjectPatternNetwork(theEnv,theNetwork); } /****************************************************************//* DestroyObjectPatternNetwork: Deallocates the data structures *//* associated with the object pattern network. *//****************************************************************/static void DestroyObjectPatternNetwork( void *theEnv, OBJECT_PATTERN_NODE *thePattern) { OBJECT_PATTERN_NODE *patternPtr; if (thePattern == NULL) return; while (thePattern != NULL) { patternPtr = thePattern->rightNode; DestroyObjectPatternNetwork(theEnv,thePattern->nextLevel); DestroyObjectAlphaNodes(theEnv,thePattern->alphaNode);#if ! RUN_TIME rtn_struct(theEnv,objectPatternNode,thePattern);#endif thePattern = patternPtr; } } /************************************************************//* DestroyObjectAlphaNodes: Deallocates the data structures *//* associated with the object alpha nodes. *//************************************************************/static void DestroyObjectAlphaNodes( void *theEnv, OBJECT_ALPHA_NODE *theNode) { OBJECT_ALPHA_NODE *nodePtr; if (theNode == NULL) return; while (theNode != NULL) { nodePtr = theNode->nxtInGroup; DestroyAlphaMemory(theEnv,&theNode->header,FALSE);#if ! RUN_TIME rtn_struct(theEnv,objectAlphaNode,theNode);#endif theNode = nodePtr; } }/***************************************************** NAME : ObjectCmpConstantFunction DESCRIPTION : Used to compare object slot values against a constant INPUTS : 1) The constant test bitmap 2) Data object buffer to hold result RETURNS : TRUE if test successful, FALSE otherwise SIDE EFFECTS : Buffer set to symbol TRUE if test successful, FALSE otherwise NOTES : Called directly by EvaluatePatternExpression() *****************************************************/globle intBool ObjectCmpConstantFunction( void *theEnv, void *theValue, DATA_OBJECT *theResult) { struct ObjectCmpPNConstant *hack; DATA_OBJECT theVar; EXPRESSION *constantExp; int rv; SEGMENT *theSegment; hack = (struct ObjectCmpPNConstant *) ValueToBitMap(theValue); if (hack->general) { EvaluateExpression(theEnv,GetFirstArgument(),&theVar); constantExp = GetFirstArgument()->nextArg; } else { constantExp = GetFirstArgument(); if (ObjectReteData(theEnv)->CurrentPatternObjectSlot->type == MULTIFIELD) { theSegment = (struct multifield *) ObjectReteData(theEnv)->CurrentPatternObjectSlot->value; if (hack->fromBeginning) { theVar.type = theSegment->theFields[hack->offset].type; theVar.value = theSegment->theFields[hack->offset].value; } else
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -