⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objrtfnx.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*               CLIPS Version 6.05  04/09/97          */   /*                                                     */   /*    INFERENCE ENGINE OBJECT ACCESS ROUTINES MODULE   */   /*******************************************************//**************************************************************//* Purpose: RETE Network Interface for Objects                *//*                                                            *//* Principal Programmer(s):                                   *//*      Brian L. Donnell                                      *//*                                                            *//* Contributing Programmer(s):                                *//*                                                            *//* Revision History:                                          *//*                                                            *//**************************************************************//* =========================================   *****************************************               EXTERNAL DEFINITIONS   =========================================   ***************************************** */#include "setup.h"#if INSTANCE_PATTERN_MATCHING#include <stdio.h>#define _CLIPS_STDIO_#include "classcom.h"#include "classfun.h"#if DEVELOPER#include "exprnops.h"#endif#include "constant.h"#include "drive.h"#include "multifld.h"#include "objrtmch.h"#include "reteutil.h"#include "router.h"#define _OBJRTFNX_SOURCE_#include "objrtfnx.h"/* =========================================   *****************************************                   CONSTANTS   =========================================   ***************************************** *//* =========================================   *****************************************                 MACROS AND TYPES   =========================================   ***************************************** */#define GetInsSlot(ins,si) ins->slotAddresses[ins->cls->slotNameMap[si]-1]/* =========================================   *****************************************      INTERNALLY VISIBLE FUNCTION HEADERS   =========================================   ***************************************** */#if ANSI_COMPILERstatic VOID PrintObjectGetVarJN1(char *,VOID *);static BOOLEAN ObjectGetVarJNFunction1(VOID *,DATA_OBJECT *);static VOID PrintObjectGetVarJN2(char *,VOID *);static BOOLEAN ObjectGetVarJNFunction2(VOID *,DATA_OBJECT *);static VOID PrintObjectGetVarPN1(char *,VOID *);static BOOLEAN ObjectGetVarPNFunction1(VOID *,DATA_OBJECT *);static VOID PrintObjectGetVarPN2(char *,VOID *);static BOOLEAN ObjectGetVarPNFunction2(VOID *,DATA_OBJECT *);static VOID PrintObjectCmpConstant(char *,VOID *);static VOID PrintSlotLengthTest(char *,VOID *);static BOOLEAN SlotLengthTestFunction(VOID *,DATA_OBJECT *);static VOID PrintPNSimpleCompareFunction1(char *,VOID *);static BOOLEAN PNSimpleCompareFunction1(VOID *,DATA_OBJECT *);static VOID PrintPNSimpleCompareFunction2(char *,VOID *);static BOOLEAN PNSimpleCompareFunction2(VOID *,DATA_OBJECT *);static VOID PrintPNSimpleCompareFunction3(char *,VOID *);static BOOLEAN PNSimpleCompareFunction3(VOID *,DATA_OBJECT *);static VOID PrintJNSimpleCompareFunction1(char *,VOID *);static BOOLEAN JNSimpleCompareFunction1(VOID *,DATA_OBJECT *);static VOID PrintJNSimpleCompareFunction2(char *,VOID *);static BOOLEAN JNSimpleCompareFunction2(VOID *,DATA_OBJECT *);static VOID PrintJNSimpleCompareFunction3(char *,VOID *);static BOOLEAN JNSimpleCompareFunction3(VOID *,DATA_OBJECT *);static VOID GetPatternObjectAndMarks(int,INSTANCE_TYPE **,struct multifieldMarker **);static VOID GetObjectValueGeneral(DATA_OBJECT *,INSTANCE_TYPE *,                                 struct multifieldMarker *,struct ObjectMatchVar1 *);static VOID GetObjectValueSimple(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);#elsestatic VOID PrintObjectGetVarJN1();static BOOLEAN ObjectGetVarJNFunction1();static VOID PrintObjectGetVarJN2();static BOOLEAN ObjectGetVarJNFunction2();static VOID PrintObjectGetVarPN1();static BOOLEAN ObjectGetVarPNFunction1();static VOID PrintObjectGetVarPN2();static BOOLEAN ObjectGetVarPNFunction2();static VOID PrintObjectCmpConstant();static VOID PrintSlotLengthTest();static BOOLEAN SlotLengthTestFunction();static VOID PrintPNSimpleCompareFunction1();static BOOLEAN PNSimpleCompareFunction1();static VOID PrintPNSimpleCompareFunction2();static BOOLEAN PNSimpleCompareFunction2();static VOID PrintPNSimpleCompareFunction3();static BOOLEAN PNSimpleCompareFunction3();static VOID PrintJNSimpleCompareFunction1();static BOOLEAN JNSimpleCompareFunction1();static VOID PrintJNSimpleCompareFunction2();static BOOLEAN JNSimpleCompareFunction2();static VOID PrintJNSimpleCompareFunction3();static BOOLEAN JNSimpleCompareFunction3();static VOID GetPatternObjectAndMarks();static VOID GetObjectValueGeneral();static VOID GetObjectValueSimple();static long CalculateSlotField(); /* 6.04 Bug Fix */static VOID GetInsMultiSlotField();#endif/* =========================================   *****************************************      EXTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** */globle INSTANCE_TYPE *CurrentPatternObject = NULL;globle INSTANCE_SLOT *CurrentPatternObjectSlot = NULL;globle int CurrentObjectSlotLength = 1;globle struct multifieldMarker *CurrentPatternObjectMarks = NULL;   /* =========================================   *****************************************      INTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** */   static struct entityRecord ObjectGVInfo1 = { OBJ_GET_SLOT_JNVAR1,0,1,0,                                             PrintObjectGetVarJN1,                                             PrintObjectGetVarJN1,NULL,                                              ObjectGetVarJNFunction1,                                             NULL,NULL,NULL,NULL,NULL,NULL };                                               static struct entityRecord ObjectGVInfo2 = { OBJ_GET_SLOT_JNVAR2,0,1,0,                                             PrintObjectGetVarJN2,                                             PrintObjectGetVarJN2,NULL,                                              ObjectGetVarJNFunction2,                                             NULL,NULL,NULL,NULL,NULL,NULL };                                                                                               static struct entityRecord ObjectGVPNInfo1 = { OBJ_GET_SLOT_PNVAR1,0,1,0,                                               PrintObjectGetVarPN1,                                               PrintObjectGetVarPN1,NULL,                                                ObjectGetVarPNFunction1,                                               NULL,NULL,NULL,NULL,NULL,NULL };                                                  static struct entityRecord ObjectGVPNInfo2 = { OBJ_GET_SLOT_PNVAR2,0,1,0,                                               PrintObjectGetVarPN2,                                               PrintObjectGetVarPN2,NULL,                                                ObjectGetVarPNFunction2,                                               NULL,NULL,NULL,NULL,NULL,NULL };                                                                                                 static struct entityRecord ObjectCmpConstantInfo = { OBJ_PN_CONSTANT,0,1,1,                                                     PrintObjectCmpConstant,                                                     PrintObjectCmpConstant,NULL,                                                      ObjectCmpConstantFunction,                                                     NULL,NULL,NULL,NULL,NULL,NULL };                                                                                                 static struct entityRecord LengthTestInfo = { OBJ_SLOT_LENGTH,0,1,0,                                              PrintSlotLengthTest,                                              PrintSlotLengthTest,NULL,                                              SlotLengthTestFunction,                                              NULL,NULL,NULL,NULL,NULL,NULL };static struct entityRecord PNSimpleCompareInfo1 = { OBJ_PN_CMP1,0,1,1,                                                    PrintPNSimpleCompareFunction1,                                                    PrintPNSimpleCompareFunction1,NULL,                                                    PNSimpleCompareFunction1,                                                    NULL,NULL,NULL,NULL,NULL,NULL };static struct entityRecord PNSimpleCompareInfo2 = { OBJ_PN_CMP2,0,1,1,                                                    PrintPNSimpleCompareFunction2,                                                    PrintPNSimpleCompareFunction2,NULL,                                                    PNSimpleCompareFunction2,                                                    NULL,NULL,NULL,NULL,NULL,NULL };static struct entityRecord PNSimpleCompareInfo3 = { OBJ_PN_CMP3,0,1,1,                                                    PrintPNSimpleCompareFunction3,                                                    PrintPNSimpleCompareFunction3,NULL,                                                    PNSimpleCompareFunction3,                                                    NULL,NULL,NULL,NULL,NULL,NULL };static struct entityRecord JNSimpleCompareInfo1 = { OBJ_JN_CMP1,0,1,1,                                                    PrintJNSimpleCompareFunction1,                                                    PrintJNSimpleCompareFunction1,NULL,                                                    JNSimpleCompareFunction1,                                                    NULL,NULL,NULL,NULL,NULL,NULL };static struct entityRecord JNSimpleCompareInfo2 = { OBJ_JN_CMP2,0,1,1,                                                    PrintJNSimpleCompareFunction2,                                                    PrintJNSimpleCompareFunction2,NULL,                                                    JNSimpleCompareFunction2,                                                    NULL,NULL,NULL,NULL,NULL,NULL };static struct entityRecord JNSimpleCompareInfo3 = { OBJ_JN_CMP3,0,1,1,                                                    PrintJNSimpleCompareFunction3,                                                    PrintJNSimpleCompareFunction3,NULL,                                                    JNSimpleCompareFunction3,                                                    NULL,NULL,NULL,NULL,NULL,NULL };/* =========================================   *****************************************          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()  {   InstallPrimitive(&ObjectGVInfo1,OBJ_GET_SLOT_JNVAR1);   InstallPrimitive(&ObjectGVInfo2,OBJ_GET_SLOT_JNVAR2);   InstallPrimitive(&ObjectGVPNInfo1,OBJ_GET_SLOT_PNVAR1);   InstallPrimitive(&ObjectGVPNInfo2,OBJ_GET_SLOT_PNVAR2);   InstallPrimitive(&ObjectCmpConstantInfo,OBJ_PN_CONSTANT);   InstallPrimitive(&LengthTestInfo,OBJ_SLOT_LENGTH);   InstallPrimitive(&PNSimpleCompareInfo1,OBJ_PN_CMP1);   InstallPrimitive(&PNSimpleCompareInfo2,OBJ_PN_CMP2);   InstallPrimitive(&PNSimpleCompareInfo3,OBJ_PN_CMP3);   InstallPrimitive(&JNSimpleCompareInfo1,OBJ_JN_CMP1);   InstallPrimitive(&JNSimpleCompareInfo2,OBJ_JN_CMP2);   InstallPrimitive(&JNSimpleCompareInfo3,OBJ_JN_CMP3);  }/*****************************************************  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      : CLIPS_TRUE if test successful,                 CLIPS_FALSE otherwise  SIDE EFFECTS : Buffer set to symbol CLIPS_TRUE if test                 successful, CLIPS_FALSE otherwise  NOTES        : Called directly by                   EvaluatePatternExpression() *****************************************************/globle BOOLEAN ObjectCmpConstantFunction(theValue,theResult)  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(GetFirstArgument(),&theVar);      constantExp = GetFirstArgument()->nextArg;     }   else     {      constantExp = GetFirstArgument();      if (CurrentPatternObjectSlot->type == MULTIFIELD)        {         theSegment = (struct multifield *) CurrentPatternObjectSlot->value;         if (hack->fromBeginning)           {            theVar.type = theSegment->theFields[hack->offset].type;            theVar.value = theSegment->theFields[hack->offset].value;           }         else           {            theVar.type = theSegment->theFields[theSegment->multifieldLength -                                       (hack->offset + 1)].type;            theVar.value = theSegment->theFields[theSegment->multifieldLength -                                       (hack->offset + 1)].value;           }        }      else        {         theVar.type = (int) CurrentPatternObjectSlot->type;         theVar.value = CurrentPatternObjectSlot->value;        }     }   if (theVar.type != constantExp->type)     rv = hack->fail;   else if (theVar.value != constantExp->value)     rv = hack->fail;   else     rv = hack->pass;   theResult->type = SYMBOL;   theResult->value = rv ? CLIPSTrueSymbol : CLIPSFalseSymbol;   return(rv);  }  /* =========================================   *****************************************          INTERNALLY VISIBLE FUNCTIONS   =========================================   ***************************************** */#if IBM_TBC && (! DEVELOPER)#pragma argsused#endifstatic VOID PrintObjectGetVarJN1(logicalName,theValue)  char *logicalName;  VOID *theValue;  {#if DEVELOPER   struct ObjectMatchVar1 *hack;   hack = (struct ObjectMatchVar1 *) ValueToBitMap(theValue);      if (hack->objectAddress)     {      PrintCLIPS(logicalName,"(obj-ptr ");      PrintLongInteger(logicalName,(long) hack->whichPattern);     }   else if (hack->allFields)     {      PrintCLIPS(logicalName,"(obj-slot-contents ");      PrintLongInteger(logicalName,(long) hack->whichPattern);      PrintCLIPS(logicalName," ");      PrintCLIPS(logicalName,ValueToString(FindIDSlotName((unsigned) hack->whichSlot)));     }   else     {      PrintCLIPS(logicalName,"(obj-slot-var ");      PrintLongInteger(logicalName,(long) hack->whichPattern);      PrintCLIPS(logicalName," ");      PrintCLIPS(logicalName,ValueToString(FindIDSlotName((unsigned) hack->whichSlot)));      PrintCLIPS(logicalName," ");      PrintLongInteger(logicalName,(long) hack->whichField);     }   PrintCLIPS(logicalName,")");#else#if MAC_MPW || MAC_MCW#pragma unused(logicalName)#pragma unused(theValue)#endif#endif  }  static BOOLEAN ObjectGetVarJNFunction1(theValue,theResult)  VOID *theValue;  DATA_OBJECT *theResult;  {   struct ObjectMatchVar1 *hack;   INSTANCE_TYPE *theInstance;   struct multifieldMarker *theMarks;      hack = (struct ObjectMatchVar1 *) ValueToBitMap(theValue);   GetPatternObjectAndMarks(((int) hack->whichPattern) - 1,&theInstance,&theMarks);   GetObjectValueGeneral(theResult,theInstance,theMarks,hack);   return(CLIPS_TRUE);  }  #if IBM_TBC && (! DEVELOPER)#pragma argsused#endifstatic VOID PrintObjectGetVarJN2(logicalName,theValue)  char *logicalName;  VOID *theValue;  {#if DEVELOPER   struct ObjectMatchVar2 *hack;      hack = (struct ObjectMatchVar2 *) ValueToBitMap(theValue);   PrintCLIPS(logicalName,"(obj-slot-quick-var ");   PrintLongInteger(logicalName,(long) hack->whichPattern);   PrintCLIPS(logicalName," ");   PrintCLIPS(logicalName,ValueToString(FindIDSlotName((unsigned) hack->whichSlot)));   if (hack->fromBeginning)     {      PrintCLIPS(logicalName," B");      PrintLongInteger(logicalName,(long) (hack->beginningOffset + 1));     }   if (hack->fromEnd)     {      PrintCLIPS(logicalName," E");      PrintLongInteger(logicalName,(long) (hack->endOffset + 1));     }   PrintCLIPS(logicalName,")");#else#if MAC_MPW || MAC_MCW#pragma unused(logicalName)#pragma unused(theValue)#endif#endif  }  static BOOLEAN ObjectGetVarJNFunction2(theValue,theResult)  VOID *theValue;  DATA_OBJECT *theResult;  {   struct ObjectMatchVar2 *hack;   INSTANCE_TYPE *theInstance;   struct multifieldMarker *theMarks;      hack = (struct ObjectMatchVar2 *) ValueToBitMap(theValue);   GetPatternObjectAndMarks(((int) hack->whichPattern) - 1,&theInstance,&theMarks);   GetObjectValueSimple(theResult,theInstance,hack);   return(CLIPS_TRUE);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -