📄 objrtcmp.c
字号:
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.24 05/17/06 */
/* */
/* OBJECT PATTERN NETWORK CONSTRUCTS-TO-C MODULE */
/*******************************************************/
/**************************************************************/
/* Purpose: Saves object pattern network for constructs-to-c */
/* */
/* Principal Programmer(s): */
/* Brian L. Donnell */
/* */
/* Contributing Programmer(s): */
/* */
/* Revision History: */
/* */
/* 6.24: Converted INSTANCE_PATTERN_MATCHING to */
/* DEFRULE_CONSTRUCT. */
/* */
/* Added environment parameter to GenClose. */
/* */
/**************************************************************/
/* =========================================
*****************************************
EXTERNAL DEFINITIONS
=========================================
***************************************** */
#include "setup.h"
#if DEFRULE_CONSTRUCT && OBJECT_SYSTEM && (! RUN_TIME) && CONSTRUCT_COMPILER
#include <stdio.h>
#define _STDIO_INCLUDED_
#include "conscomp.h"
#include "envrnmnt.h"
#include "objrtfnx.h"
#include "objrtmch.h"
#include "pattern.h"
#include "sysdep.h"
#define _OBJRTCMP_SOURCE_
#include "objrtcmp.h"
/* =========================================
*****************************************
MACROS AND TYPES
=========================================
***************************************** */
#define ObjectPNPrefix() ArbitraryPrefix(ObjectReteData(theEnv)->ObjectPatternCodeItem,0)
#define ObjectANPrefix() ArbitraryPrefix(ObjectReteData(theEnv)->ObjectPatternCodeItem,1)
/* =========================================
*****************************************
INTERNALLY VISIBLE FUNCTION HEADERS
=========================================
***************************************** */
static void BeforeObjectPatternsToCode(void *);
static OBJECT_PATTERN_NODE *GetNextObjectPatternNode(OBJECT_PATTERN_NODE *);
static void InitObjectPatternsCode(void *,FILE *,int,int);
static int ObjectPatternsToCode(void *,char *,int,FILE *,int,int);
static void IntermediatePatternNodeReference(void *,OBJECT_PATTERN_NODE *,FILE *,int,int);
static int IntermediatePatternNodesToCode(void *,char *,int,FILE *,int,int,int);
static int AlphaPatternNodesToCode(void *,char *,int,FILE *,int,int,int);
/* =========================================
*****************************************
EXTERNALLY VISIBLE FUNCTIONS
=========================================
***************************************** */
/***************************************************
NAME : ObjectPatternsCompilerSetup
DESCRIPTION : Sets up interface for object
patterns to construct compiler
INPUTS : None
RETURNS : Nothing useful
SIDE EFFECTS : Code generator item added
NOTES : None
***************************************************/
globle void ObjectPatternsCompilerSetup(
void *theEnv)
{
ObjectReteData(theEnv)->ObjectPatternCodeItem =
AddCodeGeneratorItem(theEnv,"object-patterns",0,BeforeObjectPatternsToCode,
InitObjectPatternsCode,ObjectPatternsToCode,2);
}
/***************************************************
NAME : ObjectPatternNodeReference
DESCRIPTION : Prints out a reference to an
object pattern alpha memory for
the join network interface to the
construct compiler
INPUTS : 1) A pointer to the object pattern
alpha memory
2) A pointer to the output file
3) The id of constructs-to-c image
4) The maximum number of indices
allowed in any single array
in the image
RETURNS : Nothing useful
SIDE EFFECTS : Reference to object pattern alpha
memory printed
NOTES : None
***************************************************/
globle void ObjectPatternNodeReference(
void *theEnv,
void *theVPattern,
FILE *theFile,
int imageID,
int maxIndices)
{
OBJECT_ALPHA_NODE *thePattern;
if (theVPattern == NULL)
fprintf(theFile,"NULL");
else
{
thePattern = (OBJECT_ALPHA_NODE *) theVPattern;
fprintf(theFile,"&%s%d_%d[%d]",
ObjectANPrefix(),imageID,
(((int) thePattern->bsaveID) / maxIndices) + 1,
((int) thePattern->bsaveID) % maxIndices);
}
}
/* =========================================
*****************************************
INTERNALLY VISIBLE FUNCTIONS
=========================================
***************************************** */
/*****************************************************
NAME : BeforeObjectPatternsToCode
DESCRIPTION : Marks all object pattern intermediate
and alpha memory nodes with a
unique integer id prior to the
constructs-to-c execution
INPUTS : None
RETURNS : Nothing useful
SIDE EFFECTS : bsaveIDs of nodes set
NOTES : None
*****************************************************/
static void BeforeObjectPatternsToCode(
void *theEnv)
{
long whichPattern;
OBJECT_PATTERN_NODE *intermediateNode;
OBJECT_ALPHA_NODE *alphaNode;
whichPattern = 0L;
intermediateNode = ObjectNetworkPointer(theEnv);
while (intermediateNode != NULL)
{
intermediateNode->bsaveID = whichPattern++;
intermediateNode = GetNextObjectPatternNode(intermediateNode);
}
whichPattern = 0L;
alphaNode = ObjectNetworkTerminalPointer(theEnv);
while (alphaNode != NULL)
{
alphaNode->bsaveID = whichPattern++;
alphaNode = alphaNode->nxtTerminal;
}
}
/***************************************************
NAME : GetNextObjectPatternNode
DESCRIPTION : Grabs the next node in a depth
first perusal of the object pattern
intermediate nodes
INPUTS : The previous node
RETURNS : The next node (NULL if done)
SIDE EFFECTS : None
NOTES : Alpha meory nodes are ignored
***************************************************/
static OBJECT_PATTERN_NODE *GetNextObjectPatternNode(
OBJECT_PATTERN_NODE *thePattern)
{
if (thePattern->nextLevel != NULL)
return(thePattern->nextLevel);
while (thePattern->rightNode == NULL)
{
thePattern = thePattern->lastLevel;
if (thePattern == NULL)
return(NULL);
}
return(thePattern->rightNode);
}
/***************************************************
NAME : InitObjectPatternsCode
DESCRIPTION : Prints out run-time initialization
code for object patterns
INPUTS : 1) A pointer to the output file
2) The id of constructs-to-c image
3) The maximum number of indices
allowed in any single array
in the image
RETURNS : Nothing useful
SIDE EFFECTS : Initialization code written
NOTES : None
***************************************************/
static void InitObjectPatternsCode(
void *theEnv,
FILE *initFP,
int imageID,
int maxIndices)
{
long firstIntermediateNode,firstAlphaNode;
if (ObjectNetworkPointer(theEnv) != NULL)
{
firstIntermediateNode = ObjectNetworkPointer(theEnv)->bsaveID;
firstAlphaNode = ObjectNetworkTerminalPointer(theEnv)->bsaveID;
fprintf(initFP," SetObjectNetworkPointer(theEnv,&%s%d_%d[%d]);\n",
ObjectPNPrefix(),imageID,
(int) ((firstIntermediateNode / maxIndices) + 1),
(int) (firstIntermediateNode % maxIndices));
fprintf(initFP," SetObjectNetworkTerminalPointer(theEnv,&%s%d_%d[%d]);\n",
ObjectANPrefix(),imageID,
(int) ((firstAlphaNode / maxIndices) + 1),
(int) (firstAlphaNode % maxIndices));
}
else
{
fprintf(initFP," SetObjectNetworkPointer(theEnv,NULL);\n");
fprintf(initFP," SetObjectNetworkTerminalPointer(theEnv,NULL);\n");
}
}
/***********************************************************
NAME : ObjectPatternsToCode
DESCRIPTION : Writes out data structures for run-time
creation of object patterns
INPUTS : 1) The base image output file name
2) The base image file id
3) A pointer to the header output file
4) The id of constructs-to-c image
5) The maximum number of indices
allowed in any single array
in the image
RETURNS : 1 if OK, 0 if could not open a file
SIDE EFFECTS : Object patterns code written to files
NOTES : None
***********************************************************/
static int ObjectPatternsToCode(
void *theEnv,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -