📄 genrccmp.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* */ /*******************************************************//*************************************************************//* Purpose: Generic Function Construct Compiler Code *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//*************************************************************/ /* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if DEFGENERIC_CONSTRUCT && CONSTRUCT_COMPILER && (! RUN_TIME)#if DEFRULE_CONSTRUCT#include "network.h"#endif#include "genrccom.h"#include "conscomp.h"#if OBJECT_SYSTEM#include "objcmp.h"#endif#define _GENRCCMP_SOURCE_#include "genrccmp.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** */#define MODULEI 0#define GENERICI 1#define METHODI 2#define RESTRICTIONI 3#define TYPEI 4#define SAVE_ITEMS 5/* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */#define MethodPrefix() ArbitraryPrefix(DefgenericCodeItem,2)#define RestrictionPrefix() ArbitraryPrefix(DefgenericCodeItem,3)#define TypePrefix() ArbitraryPrefix(DefgenericCodeItem,4)/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if ANSI_COMPILERstatic VOID ReadyDefgenericsForCode(void);static int DefgenericsToCode(char *,int,FILE *,int,int);static VOID CloseDefgenericFiles(FILE *[SAVE_ITEMS],int [SAVE_ITEMS], struct CodeGeneratorFile [SAVE_ITEMS],int); static VOID DefgenericModuleToCode(FILE *,struct defmodule *,int,int);static VOID SingleDefgenericToCode(FILE *,int,int,DEFGENERIC *,int,int,int);static VOID MethodToCode(FILE *,int,DEFMETHOD *,int,int);static VOID RestrictionToCode(FILE *,int,RESTRICTION *,int,int);static VOID TypeToCode(FILE *,int,VOID *,int);#elsestatic VOID ReadyDefgenericsForCode();static int DefgenericsToCode();static VOID CloseDefgenericFiles(); static VOID DefgenericModuleToCode();static VOID SingleDefgenericToCode();static VOID MethodToCode();static VOID RestrictionToCode();static VOID TypeToCode();#endif /* ========================================= ***************************************** INTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */static struct CodeGeneratorItem *DefgenericCodeItem;/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */ /*************************************************** NAME : SetupGenericsCompiler DESCRIPTION : Initializes the construct compiler item for generic functions INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Code generator item initialized NOTES : None ***************************************************/globle VOID SetupGenericsCompiler() { DefgenericCodeItem = AddCodeGeneratorItem("generics",0,ReadyDefgenericsForCode, NULL,DefgenericsToCode,5); } /*************************************************** NAME : PrintGenericFunctionReference DESCRIPTION : Prints a reference to the run-time generic array for the construct compiler INPUTS : 1) The file output destination 2) A pointer to the generic 3) The id of the run-time image 4) The maximum number of indices in any array RETURNS : Nothing useful SIDE EFFECTS : Reference printed NOTES : None ***************************************************/globle VOID PrintGenericFunctionReference(fp,gfunc,imageID,maxIndices) FILE *fp; DEFGENERIC *gfunc; int imageID, maxIndices; { if (gfunc == NULL) fprintf(fp,"NULL"); else fprintf(fp,"&%s%d_%d[%d]",ConstructPrefix(DefgenericCodeItem),imageID, (int) ((gfunc->header.bsaveID / maxIndices) + 1), (int) (gfunc->header.bsaveID % maxIndices)); }/**************************************************** NAME : DefgenericCModuleReference DESCRIPTION : Prints out a reference to a defgeneric module INPUTS : 1) The output file 2) The id of the module item 3) The id of the image 4) The maximum number of elements allowed in an array RETURNS : Nothing useful SIDE EFFECTS : Defgeneric module reference printed NOTES : None ****************************************************/globle VOID DefgenericCModuleReference(theFile,count,imageID,maxIndices) FILE *theFile; int count; int imageID; int maxIndices; { fprintf(theFile,"MIHS &%s%d_%d[%d]", ModulePrefix(DefgenericCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */ /*************************************************** NAME : ReadyDefgenericsForCode DESCRIPTION : Sets index of generic-functions for use in compiled expressions INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : BsaveIndices set NOTES : None ***************************************************/static VOID ReadyDefgenericsForCode() { MarkConstructBsaveIDs(DefgenericModuleIndex); }/******************************************************* NAME : DefgenericsToCode DESCRIPTION : Writes out static array code for generic functions, methods, etc. INPUTS : 1) The base name of the construct set 2) The base id for this construct 3) The file pointer for the header file 4) The base id for the construct set 5) The max number of indices allowed in an array RETURNS : -1 if no generic functions, 0 on errors, 1 if generic functions written SIDE EFFECTS : Code written to files NOTES : None *******************************************************/static int DefgenericsToCode(fileName,fileID,headerFP,imageID,maxIndices) char *fileName; int fileID; FILE *headerFP; int imageID; int maxIndices; { int fileCount = 1; struct defmodule *theModule; DEFGENERIC *theDefgeneric; DEFMETHOD *theMethod; RESTRICTION *theRestriction; register unsigned i,j,k; int moduleCount = 0; int itemArrayCounts[SAVE_ITEMS]; int itemArrayVersions[SAVE_ITEMS]; FILE *itemFiles[SAVE_ITEMS]; int itemReopenFlags[SAVE_ITEMS]; struct CodeGeneratorFile itemCodeFiles[SAVE_ITEMS]; for (i = 0 ; i < SAVE_ITEMS ; i++) { itemArrayCounts[i] = 0; itemArrayVersions[i] = 1; itemFiles[i] = NULL; itemReopenFlags[i] = CLIPS_FALSE; itemCodeFiles[i].filePrefix = NULL; } /* =========================================== Include the appropriate generic header file =========================================== */ fprintf(headerFP,"#include \"genrcfun.h\"\n"); /* ============================================================= Loop through all the modules and all the defgenerics writing their C code representation to the file as they are traversed ============================================================= */ theModule = (struct defmodule *) GetNextDefmodule(NULL); while (theModule != NULL) { SetCurrentModule((VOID *) theModule); itemFiles[MODULEI] = OpenFileIfNeeded(itemFiles[MODULEI],fileName,fileID,imageID,&fileCount, itemArrayVersions[MODULEI],headerFP, "DEFGENERIC_MODULE",ModulePrefix(DefgenericCodeItem), itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]); if (itemFiles[MODULEI] == NULL) goto GenericCodeError; DefgenericModuleToCode(itemFiles[MODULEI],theModule,imageID,maxIndices); itemFiles[MODULEI] = CloseFileIfNeeded(itemFiles[MODULEI],&itemArrayCounts[MODULEI], &itemArrayVersions[MODULEI],maxIndices, &itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]); theDefgeneric = (DEFGENERIC *) GetNextDefgeneric(NULL); while (theDefgeneric != NULL) { itemFiles[GENERICI] = OpenFileIfNeeded(itemFiles[GENERICI],fileName,fileID,imageID,&fileCount, itemArrayVersions[GENERICI],headerFP, "DEFGENERIC",ConstructPrefix(DefgenericCodeItem), itemReopenFlags[GENERICI],&itemCodeFiles[GENERICI]); if (itemFiles[GENERICI] == NULL) goto GenericCodeError; SingleDefgenericToCode(itemFiles[GENERICI],imageID,maxIndices,theDefgeneric, moduleCount,itemArrayVersions[METHODI], itemArrayCounts[METHODI]); itemArrayCounts[GENERICI]++; itemFiles[GENERICI] = CloseFileIfNeeded(itemFiles[GENERICI],&itemArrayCounts[GENERICI], &itemArrayVersions[GENERICI],maxIndices, &itemReopenFlags[GENERICI],&itemCodeFiles[GENERICI]); if (theDefgeneric->mcnt > 0) { /* =========================================== Make sure that all methods for a particular generic function go into the same array =========================================== */ itemFiles[METHODI] = OpenFileIfNeeded(itemFiles[METHODI],fileName,fileID,imageID,&fileCount, itemArrayVersions[METHODI],headerFP, "DEFMETHOD",MethodPrefix(), itemReopenFlags[METHODI],&itemCodeFiles[METHODI]); if (itemFiles[METHODI] == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -