📄 factgen.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* FACT RETE FUNCTION GENERATION MODULE */ /*******************************************************/ /*************************************************************//* Purpose: Creates expressions used by the fact pattern *//* matcher and the join network. The expressions created *//* are used to extract and compare values from facts as *//* needed by the Rete pattern matching algorithm. These *//* expressions are also used to extract values from facts *//* needed by expressions on the RHS of a rule. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//*************************************************************/#define _FACTGEN_SOURCE_#include "setup.h"#if DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT#include <stdio.h>#define _CLIPS_STDIO_#include "constant.h"#include "clipsmem.h"#include "router.h"#include "scanner.h"#include "exprnpsr.h"#include "constrct.h"#include "network.h"#include "reteutil.h"#include "factmch.h"#include "factrete.h"#include "factmngr.h"#include "pattern.h"#include "factprt.h"#include "tmpltdef.h"#include "tmpltlhs.h" #include "factgen.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER#if (! RUN_TIME) && (! BLOAD_ONLY) static VOID *FactGetVarJN1(struct lhsParseNode *); static VOID *FactGetVarJN2(struct lhsParseNode *); static VOID *FactGetVarJN3(struct lhsParseNode *); static VOID *FactGetVarPN1(struct lhsParseNode *); static VOID *FactGetVarPN2(struct lhsParseNode *); static VOID *FactGetVarPN3(struct lhsParseNode *);#endif#else#if (! RUN_TIME) && (! BLOAD_ONLY) static VOID *FactGetVarJN1(); static VOID *FactGetVarJN2(); static VOID *FactGetVarJN3(); static VOID *FactGetVarPN1(); static VOID *FactGetVarPN2(); static VOID *FactGetVarPN3();#endif#endif/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/ globle struct entityRecord FactJNGV1Info = { FACT_JN_VAR1,0,1,0, PrintFactJNGetVar1, PrintFactJNGetVar1,NULL, FactJNGetVar1, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactJNGV2Info = { FACT_JN_VAR2,0,1,0, PrintFactJNGetVar2, PrintFactJNGetVar2,NULL, FactJNGetVar2, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactJNGV3Info = { FACT_JN_VAR3,0,1,0, PrintFactJNGetVar3, PrintFactJNGetVar3,NULL, FactJNGetVar3, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactPNGV1Info = { FACT_PN_VAR1,0,1,0, PrintFactPNGetVar1, PrintFactPNGetVar1,NULL, FactPNGetVar1, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactPNGV2Info = { FACT_PN_VAR2,0,1,0, PrintFactPNGetVar2, PrintFactPNGetVar2,NULL, FactPNGetVar2, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactPNGV3Info = { FACT_PN_VAR3,0,1,0, PrintFactPNGetVar3, PrintFactPNGetVar3,NULL, FactPNGetVar3, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactJNCV1Info = { FACT_JN_CMP1,0,1,1, PrintFactJNCompVars1, PrintFactJNCompVars1,NULL, FactJNCompVars1, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactJNCV2Info = { FACT_JN_CMP2,0,1,1, PrintFactJNCompVars2, PrintFactJNCompVars2,NULL, FactJNCompVars2, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactPNCV1Info = { FACT_PN_CMP1,0,1,1, PrintFactPNCompVars1, PrintFactPNCompVars1,NULL, FactPNCompVars1, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactStoreMFInfo = { FACT_STORE_MULTIFIELD,0,1,0, NULL,NULL,NULL, FactStoreMultifield, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactSlotLengthInfo = { FACT_SLOT_LENGTH,0,1,0, PrintFactSlotLength, PrintFactSlotLength,NULL, FactSlotLength, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactPNConstant1Info = { FACT_PN_CONSTANT1,0,1,1, PrintFactPNConstant1, PrintFactPNConstant1,NULL, FactPNConstant1, NULL,NULL,NULL,NULL,NULL,NULL }; globle struct entityRecord FactPNConstant2Info = { FACT_PN_CONSTANT2,0,1,1, PrintFactPNConstant2, PrintFactPNConstant2,NULL, FactPNConstant2, NULL,NULL,NULL,NULL,NULL,NULL };/*******************************************************************//* InitializeFactReteFunctions: Installs the fact pattern matching *//* and value access routines as primitive operations. *//*******************************************************************/globle VOID InitializeFactReteFunctions() {#if DEFRULE_CONSTRUCT InstallPrimitive((ENTITY_RECORD_PTR) &FactInfo,FACT_ADDRESS); InstallPrimitive(&FactJNGV1Info,FACT_JN_VAR1); InstallPrimitive(&FactJNGV2Info,FACT_JN_VAR2); InstallPrimitive(&FactJNGV3Info,FACT_JN_VAR3); InstallPrimitive(&FactPNGV1Info,FACT_PN_VAR1); InstallPrimitive(&FactPNGV2Info,FACT_PN_VAR2); InstallPrimitive(&FactPNGV3Info,FACT_PN_VAR3); InstallPrimitive(&FactJNCV1Info,FACT_JN_CMP1); InstallPrimitive(&FactJNCV2Info,FACT_JN_CMP2); InstallPrimitive(&FactPNCV1Info,FACT_PN_CMP1); InstallPrimitive(&FactStoreMFInfo,FACT_STORE_MULTIFIELD); InstallPrimitive(&FactSlotLengthInfo,FACT_SLOT_LENGTH); InstallPrimitive(&FactPNConstant1Info,FACT_PN_CONSTANT1); InstallPrimitive(&FactPNConstant2Info,FACT_PN_CONSTANT2);#endif }#if (! RUN_TIME) && (! BLOAD_ONLY)/******************************************************************//* FactGenPNConstant: Generates an expression for use in the fact *//* pattern network that compares a field from a single field or *//* multifield slot against a constant. *//******************************************************************/globle struct expr *FactGenPNConstant(theField) struct lhsParseNode *theField; { struct expr *top; int tempValue; struct factConstantPN1Call hack1; struct factConstantPN2Call hack2; /*=================================================================*/ /* If the value of a single field slot (or relation name) is being */ /* compared against a constant, then use specialized routines for */ /* doing the comparison. */ /*=================================================================*/ if (theField->withinMultifieldSlot == CLIPS_FALSE) { ClearBitString(&hack1,sizeof(struct factConstantPN1Call)); if (theField->negated) hack1.testForEquality = CLIPS_FALSE; else hack1.testForEquality = CLIPS_TRUE; hack1.whichSlot = theField->slotNumber - 1; top = GenConstant(FACT_PN_CONSTANT1,AddBitMap(&hack1,sizeof(struct factConstantPN1Call))); top->argList = GenConstant(theField->type,theField->value); return(top); } /*=================================================================*/ /* If a constant comparison is being done within a multifield slot */ /* and the constant's position has no multifields to the left, */ /* then use the same routine used for the single field slot case, */ /* but include the offset from the beginning of the slot. */ /*=================================================================*/ else if ((theField->multiFieldsBefore == 0) || ((theField->multiFieldsBefore == 1) && (theField->multiFieldsAfter == 0))) { ClearBitString(&hack2,sizeof(struct factConstantPN2Call)); if (theField->negated) hack2.testForEquality = CLIPS_FALSE; else hack2.testForEquality = CLIPS_TRUE; hack2.whichSlot = theField->slotNumber - 1; if (theField->multiFieldsBefore == 0) { hack2.fromBeginning = CLIPS_TRUE; hack2.offset = theField->singleFieldsBefore; } else { hack2.fromBeginning = CLIPS_FALSE; hack2.offset = theField->singleFieldsAfter; } top = GenConstant(FACT_PN_CONSTANT2,AddBitMap(&hack2,sizeof(struct factConstantPN2Call))); top->argList = GenConstant(theField->type,theField->value); return(top); } /*===============================================================*/ /* Otherwise, use the equality or inequality function to compare */ /* the constant against the value returned by the appropriate */ /* pattern network variable retrieval function call. */ /*===============================================================*/ else { if (theField->negated) { top = GenConstant(FCALL,PTR_NEQ); } else { top = GenConstant(FCALL,PTR_EQ); } tempValue = theField->type; theField->type = SF_VARIABLE; top->argList = FactGenGetfield(theField); theField->type = tempValue; top->argList->nextArg = GenConstant(theField->type,theField->value); } /*===============================================================*/ /* Return the expression for performing the constant comparison. */ /*===============================================================*/ return(top); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -