📄 factrete.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* FACT RETE ACCESS FUNCTIONS MODULE */ /*******************************************************/ /*************************************************************//* Purpose: Rete access functions for fact pattern matching. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//*************************************************************/#define _FACTRETE_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#include "setup.h"#if DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT#include "clipsmem.h"#include "extnfunc.h"#include "router.h"#if INCREMENTAL_RESET#include "incrrset.h"#endif#include "reteutil.h"#include "drive.h"#include "factgen.h"#include "factmch.h"#include "factrete.h"/***************************************************************//* FactPNGetVar1: Fact pattern network function for extracting *//* a variable's value. This is the most generalized routine. *//***************************************************************/globle BOOLEAN FactPNGetVar1(theValue,returnValue) VOID *theValue; DATA_OBJECT_PTR returnValue; { int theField, theSlot; struct fact *factPtr; struct field *fieldPtr; struct multifieldMarker *marks; struct multifield *segmentPtr; int extent; struct factGetVarPN1Call *hack; /*==========================================*/ /* Retrieve the arguments for the function. */ /*==========================================*/ hack = (struct factGetVarPN1Call *) ValueToBitMap(theValue); /*=====================================================*/ /* Get the pointer to the fact from the partial match. */ /*=====================================================*/ factPtr = CurrentPatternFact; marks = CurrentPatternMarks; /*==========================================================*/ /* Determine if we want to retrieve the fact address of the */ /* fact, rather than retrieving a field from the fact. */ /*==========================================================*/ if (hack->factAddress) { returnValue->type = FACT_ADDRESS; returnValue->value = (VOID *) factPtr; return(CLIPS_TRUE); } /*=========================================================*/ /* Determine if we want to retrieve the entire slot value. */ /*=========================================================*/ if (hack->allFields) { theSlot = hack->whichSlot; fieldPtr = &factPtr->theProposition.theFields[theSlot]; returnValue->type = fieldPtr->type; returnValue->value = fieldPtr->value; if (returnValue->type == MULTIFIELD) { returnValue->begin = 0; returnValue->end = ((struct multifield *) fieldPtr->value)->multifieldLength - 1; } return(CLIPS_TRUE); } /*====================================================*/ /* If the slot being accessed is a single field slot, */ /* then just return the single value found in that */ /* slot. The multifieldMarker data structures do not */ /* have to be considered since access to a single */ /* field slot is not affected by variable bindings */ /* from multifield slots. */ /*====================================================*/ theField = hack->whichField; theSlot = hack->whichSlot; fieldPtr = &factPtr->theProposition.theFields[theSlot]; /*==========================================================*/ /* Retrieve a value from a multifield slot. First determine */ /* the range of fields for the variable being retrieved. */ /*==========================================================*/ extent = -1; theField = AdjustFieldPosition(marks,theField,theSlot,&extent); /*=============================================================*/ /* If a range of values are being retrieved (i.e. a multifield */ /* variable), then return the values as a multifield. */ /*=============================================================*/ if (extent != -1) { returnValue->type = MULTIFIELD; returnValue->value = (VOID *) fieldPtr->value; returnValue->begin = theField; returnValue->end = theField + extent - 1; return(CLIPS_TRUE); } /*========================================================*/ /* Otherwise a single field value is being retrieved from */ /* a multifield slot. Just return the type and value. */ /*========================================================*/ segmentPtr = (struct multifield *) fieldPtr->value; fieldPtr = &segmentPtr->theFields[theField]; returnValue->type = fieldPtr->type; returnValue->value = fieldPtr->value; return(CLIPS_TRUE); } /**************************************************//* FactPNGetVar2: Fact pattern network function *//* for extracting a variable's value. The value *//* extracted is from a single field slot. *//**************************************************/globle BOOLEAN FactPNGetVar2(theValue,returnValue) VOID *theValue; DATA_OBJECT_PTR returnValue; { struct fact *factPtr; struct factGetVarPN2Call *hack; struct field *fieldPtr; /*==========================================*/ /* Retrieve the arguments for the function. */ /*==========================================*/ hack = (struct factGetVarPN2Call *) ValueToBitMap(theValue); /*==============================*/ /* Get the pointer to the fact. */ /*==============================*/ factPtr = CurrentPatternFact; /*============================================*/ /* Extract the value from the specified slot. */ /*============================================*/ fieldPtr = &factPtr->theProposition.theFields[hack->whichSlot]; returnValue->type = fieldPtr->type; returnValue->value = fieldPtr->value; return(CLIPS_TRUE); }/*****************************************************************//* FactPNGetVar3: Fact pattern network function for extracting a *//* variable's value. The value extracted is from a multifield *//* slot that contains at most one multifield variable. *//*****************************************************************/globle BOOLEAN FactPNGetVar3(theValue,returnValue) VOID *theValue; DATA_OBJECT_PTR returnValue; { struct fact *factPtr; struct multifield *segmentPtr; struct field *fieldPtr; struct factGetVarPN3Call *hack; /*==========================================*/ /* Retrieve the arguments for the function. */ /*==========================================*/ hack = (struct factGetVarPN3Call *) ValueToBitMap(theValue); /*==============================*/ /* Get the pointer to the fact. */ /*==============================*/ factPtr = CurrentPatternFact; /*============================================================*/ /* Get the multifield value from which the data is retrieved. */ /*============================================================*/ segmentPtr = (struct multifield *) factPtr->theProposition.theFields[hack->whichSlot].value; /*=========================================*/ /* If the beginning and end flags are set, */ /* then retrieve a multifield value. */ /*=========================================*/ if (hack->fromBeginning && hack->fromEnd) { returnValue->type = MULTIFIELD; returnValue->value = (VOID *) segmentPtr; returnValue->begin = hack->beginOffset; returnValue->end = segmentPtr->multifieldLength - (hack->endOffset + 1); return(CLIPS_TRUE); } /*=====================================================*/ /* Return a single field value from a multifield slot. */ /*=====================================================*/ if (hack->fromBeginning) { fieldPtr = &segmentPtr->theFields[hack->beginOffset]; } else { fieldPtr = &segmentPtr->theFields[segmentPtr->multifieldLength - (hack->endOffset + 1)]; } returnValue->type = fieldPtr->type; returnValue->value = fieldPtr->value; return(CLIPS_TRUE); } /******************************************************//* FactPNConstant1: Fact pattern network function for *//* comparing a value stored in a single field slot *//* to a constant for either equality or inequality. *//******************************************************/#if IBM_TBC#pragma argsused#endifgloble BOOLEAN FactPNConstant1(theValue,returnValue) VOID *theValue; DATA_OBJECT_PTR returnValue; {#if MAC_MPW || MAC_MCW#pragma unused(returnValue)#endif struct factConstantPN1Call *hack; struct field *fieldPtr; struct expr *theConstant; /*==========================================*/ /* Retrieve the arguments for the function. */ /*==========================================*/ hack = (struct factConstantPN1Call *) ValueToBitMap(theValue); /*============================================*/ /* Extract the value from the specified slot. */ /*============================================*/ fieldPtr = &CurrentPatternFact->theProposition.theFields[hack->whichSlot]; /*====================================*/ /* Compare the value to the constant. */ /*====================================*/ theConstant = GetFirstArgument(); if (theConstant->type != fieldPtr->type) return(1 - hack->testForEquality); if (theConstant->value != fieldPtr->value) return(1 - hack->testForEquality); return(hack->testForEquality); } /****************************************************************//* FactPNConstant2: Fact pattern network function for comparing *//* a value stored in a slot to a constant for either equality *//* or inequality. The value being retrieved from the slot has *//* no multifields to its right (thus it can be retrieved *//* relative to the beginning). *//****************************************************************/#if IBM_TBC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -