📄 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 *);
static intBool IsSimpleSlotVariable(struct lhsParseNode *);
static EXPRESSION *GenerateSlotComparisonTest(void *,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)
{
GenObjectGetVar(theEnv,TRUE,theItem,theNode);
}
globle EXPRESSION *GenGetJNObjectValue(
void *theEnv,
struct lhsParseNode *theNode)
{
EXPRESSION *theItem;
theItem = GenConstant(theEnv,0,NULL);
GenObjectGetVar(theEnv,TRUE,theItem,theNode);
return(theItem);
}
globle EXPRESSION *ObjectJNVariableComparison(
void *theEnv,
struct lhsParseNode *selfNode,
struct lhsParseNode *referringNode)
{
return(GenerateSlotComparisonTest(theEnv,TRUE,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);
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);
}
globle EXPRESSION *GenGetPNObjectValue(
void *theEnv,
struct lhsParseNode *theNode)
{
EXPRESSION *theItem;
theItem = GenConstant(theEnv,0,NULL);
GenObjectGetVar(theEnv,FALSE,theItem,theNode);
return(theItem);
}
globle EXPRESSION *ObjectPNVariableComparison(
void *theEnv,
struct lhsParseNode *selfNode,
struct lhsParseNode *referringNode)
{
return(GenerateSlotComparisonTest(theEnv,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)));
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
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)
{
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;
}
/* ========================
Access an object address
======================== */
if (theNode->slotNumber < 0)
{
hack1.objectAddress = 1;
SetpType(theItem,(joinReference ? OBJ_GET_SLOT_JNVAR1 : OBJ_GET_SLOT_PNVAR1));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -