?? objrtgen.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.24 05/17/06 */ /* */ /* INFERENCE ENGINE OBJECT PARSING ROUTINES MODULE */ /*******************************************************//**************************************************************//* Purpose: RETE Network Parsing Interface for Objects *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* 6.23: Changed name of variable exp to theExp *//* because of Unix compiler warnings of shadowed *//* definitions. *//* *//* 6.24: Converted INSTANCE_PATTERN_MATCHING to *//* DEFRULE_CONSTRUCT. *//* *//* Renamed BOOLEAN macro type to intBool. *//* *//**************************************************************//* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if DEFRULE_CONSTRUCT && OBJECT_SYSTEM && (! RUN_TIME) && (! BLOAD_ONLY)#ifndef _STDIO_INCLUDED_#include <stdio.h>#define _STDIO_INCLUDED_#endif#include "classfun.h"#include "envrnmnt.h"#include "objrtfnx.h"#define _OBJRTGEN_SOURCE_#include "objrtgen.h"/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */static void GenObjectGetVar(void *,int,EXPRESSION *,struct lhsParseNode *,int);static intBool IsSimpleSlotVariable(struct lhsParseNode *);static EXPRESSION *GenerateSlotComparisonTest(void *,int,int,struct lhsParseNode *,struct lhsParseNode *);/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//********************************************** Build functions used by AddPatternParser() to provide object access to the join nertwork **********************************************/globle void ReplaceGetJNObjectValue( void *theEnv, EXPRESSION *theItem, struct lhsParseNode *theNode, int side) { GenObjectGetVar(theEnv,TRUE,theItem,theNode,side); }globle EXPRESSION *GenGetJNObjectValue( void *theEnv, struct lhsParseNode *theNode, int side) { EXPRESSION *theItem; theItem = GenConstant(theEnv,0,NULL); GenObjectGetVar(theEnv,TRUE,theItem,theNode,side); return(theItem); }globle EXPRESSION *ObjectJNVariableComparison( void *theEnv, struct lhsParseNode *selfNode, struct lhsParseNode *referringNode, int isNand) { return(GenerateSlotComparisonTest(theEnv,TRUE,isNand,selfNode,referringNode)); }/********************************************** Build functions used by AddPatternParser() to provide object access to the pattern network **********************************************/globle EXPRESSION *GenObjectPNConstantCompare( void *theEnv, struct lhsParseNode *theNode) { struct ObjectCmpPNConstant hack; EXPRESSION *theExp; unsigned short tmpType; /* =============================================================== 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 a constant comparison is being done within a multifield slot and the constant's position has no multifields to the left or no multifields to the right, then use the same routine used for the single field slot case, but include the offset from either the beginning or end of the slot. Otherwise, use a general eq/neq test. =============================================================== */ ClearBitString((void *) &hack,(int) sizeof(struct ObjectCmpPNConstant)); if (theNode->negated) hack.fail = 1; else hack.pass = 1; if (((theNode->withinMultifieldSlot == FALSE) || (theNode->multiFieldsAfter == 0) || (theNode->multiFieldsBefore == 0)) && (theNode->slotNumber != ISA_ID) && (theNode->slotNumber != NAME_ID)) { if (theNode->withinMultifieldSlot == FALSE) hack.fromBeginning = TRUE; else if (theNode->multiFieldsBefore == 0) { hack.fromBeginning = TRUE; hack.offset = theNode->singleFieldsBefore; } else hack.offset = theNode->singleFieldsAfter; theExp = GenConstant(theEnv,OBJ_PN_CONSTANT,AddBitMap(theEnv,(void *) &hack, (int) sizeof(struct ObjectCmpPNConstant))); theExp->argList = GenConstant(theEnv,theNode->type,theNode->value); } else { hack.general = 1; theExp = GenConstant(theEnv,OBJ_PN_CONSTANT,AddBitMap(theEnv,(void *) &hack, (int) sizeof(struct ObjectCmpPNConstant))); theExp->argList = GenConstant(theEnv,0,NULL); tmpType = theNode->type; theNode->type = SF_VARIABLE; GenObjectGetVar(theEnv,FALSE,theExp->argList,theNode,-1); theNode->type = tmpType; theExp->argList->nextArg = GenConstant(theEnv,theNode->type,theNode->value); } return(theExp); }globle void ReplaceGetPNObjectValue( void *theEnv, EXPRESSION *theItem, struct lhsParseNode *theNode) { GenObjectGetVar(theEnv,FALSE,theItem,theNode,-1); }globle EXPRESSION *GenGetPNObjectValue( void *theEnv, struct lhsParseNode *theNode) { EXPRESSION *theItem; theItem = GenConstant(theEnv,0,NULL); GenObjectGetVar(theEnv,FALSE,theItem,theNode,-1); return(theItem); }globle EXPRESSION *ObjectPNVariableComparison( void *theEnv, struct lhsParseNode *selfNode, struct lhsParseNode *referringNode) { return(GenerateSlotComparisonTest(theEnv,FALSE,FALSE,selfNode,referringNode)); }/**************************************************** NAME : GenObjectLengthTest DESCRIPTION : Generates a test on the cardinality of a slot matching an object pattern INPUTS : The first lhsParseNode for a slot in an object pattern RETURNS : Nothing useful SIDE EFFECTS : The lhsParseNode network test is modified to include the length test NOTES : None ****************************************************/globle void GenObjectLengthTest( void *theEnv, struct lhsParseNode *theNode) { struct ObjectMatchLength hack; EXPRESSION *theTest; if ((theNode->singleFieldsAfter == 0) && (theNode->type != SF_VARIABLE) && (theNode->type != SF_WILDCARD)) return; ClearBitString((void *) &hack,(int) sizeof(struct ObjectMatchLength)); if ((theNode->type != MF_VARIABLE) && (theNode->type != MF_WILDCARD) && (theNode->multiFieldsAfter == 0)) hack.exactly = 1; else hack.exactly = 0; if ((theNode->type == SF_VARIABLE) || (theNode->type == SF_WILDCARD)) hack.minLength = 1 + theNode->singleFieldsAfter; else hack.minLength = theNode->singleFieldsAfter; theTest = GenConstant(theEnv,OBJ_SLOT_LENGTH,AddBitMap(theEnv,(void *) &hack, (int) sizeof(struct ObjectMatchLength))); if (theNode->constantSelector != NULL) { theNode->constantSelector->nextArg = CopyExpression(theEnv,theTest); } theNode->networkTest = CombineExpressions(theEnv,theTest,theNode->networkTest); }/**************************************************** NAME : GenObjectZeroLengthTest DESCRIPTION : Generates a test on the cardinality of a slot matching an object pattern INPUTS : The first lhsParseNode for a slot in an object pattern RETURNS : Nothing useful SIDE EFFECTS : The lhsParseNode network test is modified to include the length test NOTES : None ****************************************************/globle void GenObjectZeroLengthTest( void *theEnv, struct lhsParseNode *theNode) { struct ObjectMatchLength hack; EXPRESSION *theTest; ClearBitString((void *) &hack,(int) sizeof(struct ObjectMatchLength)); hack.exactly = 1; hack.minLength = 0; theTest = GenConstant(theEnv,OBJ_SLOT_LENGTH,AddBitMap(theEnv,(void *) &hack, (int) sizeof(struct ObjectMatchLength))); theNode->networkTest = CombineExpressions(theEnv,theTest,theNode->networkTest); }/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//*************************************************** NAME : GenObjectGetVar DESCRIPTION : Generates the expressions necessary to access object pattern variables INPUTS : 1) An integer code indicating if this is a join network reference or a pattern network reference 2) The expression for which to set the type and value 3) The lhsParseNode for the variable reference 4) For a join reference, the side from which the variable must be retrieved. RETURNS : Nothing useful SIDE EFFECTS : The value is a packed long holding pattern index, slot number, field index, etc. NOTES : None ***************************************************/static void GenObjectGetVar( void *theEnv, int joinReference, EXPRESSION *theItem, struct lhsParseNode *theNode, int side) { struct ObjectMatchVar1 hack1; struct ObjectMatchVar2 hack2; ClearBitString((void *) &hack1,(int) sizeof(struct ObjectMatchVar1)); ClearBitString((void *) &hack2,(int) sizeof(struct ObjectMatchVar2)); if (joinReference) { /* hack1.whichPattern = (unsigned short) theNode->pattern; hack2.whichPattern = (unsigned short) theNode->pattern; */ if (side == LHS) { hack1.lhs = 1; hack2.lhs = 1; hack1.whichPattern = (unsigned short) theNode->joinDepth; hack2.whichPattern = (unsigned short) theNode->joinDepth; } else if (side == RHS) { hack1.rhs = 1; hack2.rhs = 1; hack1.whichPattern = (unsigned short) 0; hack2.whichPattern = (unsigned short) 0; } else if (side == NESTED_RHS) { hack1.rhs = 1; hack2.rhs = 1; hack1.whichPattern = (unsigned short) theNode->joinDepth; hack2.whichPattern = (unsigned short) theNode->joinDepth; } else { hack1.whichPattern = (unsigned short) theNode->joinDepth; hack2.whichPattern = (unsigned short) theNode->joinDepth; } } /* ======================== Access an object address ======================== */ if (theNode->slotNumber < 0) { hack1.objectAddress = 1; SetpType(theItem,(joinReference ? OBJ_GET_SLOT_JNVAR1 : OBJ_GET_SLOT_PNVAR1)); theItem->value = AddBitMap(theEnv,(void *) &hack1,(int) sizeof(struct ObjectMatchVar1)); return; } /* ====================================== Access the entire contents of the slot ====================================== */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -