📄 symblcmp.c
字号:
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.24 06/05/06 */
/* */
/* SYMBOL CONSTRUCT COMPILER MODULE */
/*******************************************************/
/*************************************************************/
/* Purpose: Implements the constructs-to-c feature for */
/* atomic data values: symbols, integers, floats, and */
/* bit maps. */
/* */
/* Principal Programmer(s): */
/* Gary D. Riley */
/* Barry Cameron */
/* */
/* Contributing Programmer(s): */
/* Brian L. Donnell */
/* */
/* Revision History: */
/* */
/* 6.24: Added environment parameter to GenClose. */
/* */
/* Corrected code to remove compiler warnings. */
/* */
/*************************************************************/
#define _SYMBLCMP_SOURCE_
#include "setup.h"
#if CONSTRUCT_COMPILER && (! RUN_TIME)
#include <stdio.h>
#define _STDIO_INCLUDED_
#include <string.h>
#include "envrnmnt.h"
#include "symbol.h"
#include "memalloc.h"
#include "constant.h"
#include "exprnpsr.h"
#include "cstrccom.h"
#include "constrct.h"
#include "argacces.h"
#include "cstrncmp.h"
#include "router.h"
#include "conscomp.h"
#include "sysdep.h"
#include "utility.h"
#include "symblcmp.h"
/***************************************/
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
/***************************************/
static int SymbolHashNodesToCode(void *,char *,int);
static int BitMapHashNodesToCode(void *,char *,int);
static int BitMapValuesToCode(void *,char *,int);
static int FloatHashNodesToCode(void *,char *,int);
static int IntegerHashNodesToCode(void *,char *,int);
static int HashTablesToCode(void *,char *);
static void PrintCString(FILE *,char *);
/**************************************************************/
/* AtomicValuesToCode: Driver routine for generating the code */
/* used by the symbol, integer, float, and bit map tables. */
/**************************************************************/
globle void AtomicValuesToCode(
void *theEnv,
char *fileName)
{
int version;
SetAtomicValueIndices(theEnv,TRUE);
HashTablesToCode(theEnv,fileName);
version = SymbolHashNodesToCode(theEnv,fileName,5);
version = FloatHashNodesToCode(theEnv,fileName,version);
version = IntegerHashNodesToCode(theEnv,fileName,version);
version = BitMapHashNodesToCode(theEnv,fileName,version);
BitMapValuesToCode(theEnv,fileName,version);
}
/*****************************************************/
/* SymbolHashNodesToCode: Produces the code for the */
/* symbol hash table entries for a run-time module */
/* created using the constructs-to-c function. */
/*****************************************************/
static int SymbolHashNodesToCode(
void *theEnv,
char *fileName,
int version)
{
unsigned long i, j;
struct symbolHashNode *hashPtr;
int count;
int numberOfEntries;
struct symbolHashNode **symbolTable;
int newHeader = TRUE;
int arrayVersion = 1;
FILE *fp;
/*====================================*/
/* Count the total number of entries. */
/*====================================*/
symbolTable = GetSymbolTable(theEnv);
count = numberOfEntries = 0;
for (i = 0; i < SYMBOL_HASH_SIZE; i++)
{
for (hashPtr = symbolTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{ numberOfEntries++; }
}
if (numberOfEntries == 0) return(version);
for (i = 1; i <= (unsigned long) (numberOfEntries / ConstructCompilerData(theEnv)->MaxIndices) + 1 ; i++)
{ fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct symbolHashNode S%d_%ld[];\n",ConstructCompilerData(theEnv)->ImageID,i); }
/*==================*/
/* Create the file. */
/*==================*/
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(-1);
/*===================*/
/* List the entries. */
/*===================*/
j = 0;
for (i = 0; i < SYMBOL_HASH_SIZE; i++)
{
for (hashPtr = symbolTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{
if (newHeader)
{
fprintf(fp,"struct symbolHashNode S%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,arrayVersion);
newHeader = FALSE;
}
if (hashPtr->next == NULL)
{ fprintf(fp,"{NULL,"); }
else
{
if ((j + 1) >= (unsigned long) ConstructCompilerData(theEnv)->MaxIndices)
{ fprintf(fp,"{&S%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion + 1,0); }
else
{ fprintf(fp,"{&S%d_%d[%ld],",ConstructCompilerData(theEnv)->ImageID,arrayVersion,j + 1); }
}
fprintf(fp,"%ld,0,1,0,0,%ld,",hashPtr->count + 1,i);
PrintCString(fp,hashPtr->contents);
count++;
j++;
if ((count == numberOfEntries) || (j >= (unsigned) ConstructCompilerData(theEnv)->MaxIndices))
{
fprintf(fp,"}};\n");
GenClose(theEnv,fp);
j = 0;
arrayVersion++;
version++;
if (count < numberOfEntries)
{
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(0);
newHeader = TRUE;
}
}
else
{ fprintf(fp,"},\n"); }
}
}
return(version);
}
/******************************************************/
/* BitMapHashNodesToCode: Produces the code for the */
/* bit map hash table entries for a run-time module */
/* created using the constructs-to-c function. */
/******************************************************/
static int BitMapHashNodesToCode(
void *theEnv,
char *fileName,
int version)
{
int i, j;
struct bitMapHashNode *hashPtr;
int count;
int numberOfEntries;
struct bitMapHashNode **bitMapTable;
int newHeader = TRUE;
int arrayVersion = 1;
FILE *fp;
int longsReqdPartition = 1,longsReqdPartitionCount = 0;
/*====================================*/
/* Count the total number of entries. */
/*====================================*/
bitMapTable = GetBitMapTable(theEnv);
count = numberOfEntries = 0;
for (i = 0; i < BITMAP_HASH_SIZE; i++)
{
for (hashPtr = bitMapTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{ numberOfEntries++; }
}
if (numberOfEntries == 0) return(version);
for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv)->MaxIndices) + 1 ; i++)
{ fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct bitMapHashNode B%d_%d[];\n",ConstructCompilerData(theEnv)->ImageID,i); }
/*==================*/
/* Create the file. */
/*==================*/
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(-1);
/*===================*/
/* List the entries. */
/*===================*/
j = 0;
for (i = 0; i < BITMAP_HASH_SIZE; i++)
{
for (hashPtr = bitMapTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{
if (newHeader)
{
fprintf(fp,"struct bitMapHashNode B%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,arrayVersion);
newHeader = FALSE;
}
if (hashPtr->next == NULL)
{ fprintf(fp,"{NULL,"); }
else
{
if ((j + 1) >= ConstructCompilerData(theEnv)->MaxIndices)
{ fprintf(fp,"{&B%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion + 1,0); }
else
{ fprintf(fp,"{&B%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion,j + 1); }
}
fprintf(fp,"%ld,0,1,0,0,%d,(char *) &L%d_%d[%d],%d",
hashPtr->count + 1,i,
ConstructCompilerData(theEnv)->ImageID,longsReqdPartition,longsReqdPartitionCount,
hashPtr->size);
longsReqdPartitionCount += (int) (hashPtr->size / sizeof(unsigned long));
if ((hashPtr->size % sizeof(unsigned long)) != 0)
longsReqdPartitionCount++;
if (longsReqdPartitionCount >= ConstructCompilerData(theEnv)->MaxIndices)
{
longsReqdPartitionCount = 0;
longsReqdPartition++;
}
count++;
j++;
if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv)->MaxIndices))
{
fprintf(fp,"}};\n");
GenClose(theEnv,fp);
j = 0;
arrayVersion++;
version++;
if (count < numberOfEntries)
{
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(0);
newHeader = TRUE;
}
}
else
{ fprintf(fp,"},\n"); }
}
}
return(version);
}
/*****************************************************/
/* BitMapValuesToCode: Produces the code for the bit */
/* map strings for a run-time module created using */
/* the constructs-to-c function. */
/*****************************************************/
static int BitMapValuesToCode(
void *theEnv,
char *fileName,
int version)
{
int i, j, k;
unsigned l;
struct bitMapHashNode *hashPtr;
int count;
int numberOfEntries;
struct bitMapHashNode **bitMapTable;
int newHeader = TRUE;
int arrayVersion = 1;
FILE *fp;
unsigned long tmpLong;
int longsReqd;
/*====================================*/
/* Count the total number of entries. */
/*====================================*/
bitMapTable = GetBitMapTable(theEnv);
count = numberOfEntries = 0;
for (i = 0; i < BITMAP_HASH_SIZE; i++)
{
for (hashPtr = bitMapTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{
numberOfEntries += (int) (hashPtr->size / sizeof(unsigned long));
if ((hashPtr->size % sizeof(unsigned long)) != 0)
{ numberOfEntries++; }
}
}
if (numberOfEntries == 0) return(version);
for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv)->MaxIndices) + 1 ; i++)
{ fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern unsigned long L%d_%d[];\n",ConstructCompilerData(theEnv)->ImageID,i); }
/*==================*/
/* Create the file. */
/*==================*/
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(-1);
/*===================*/
/* List the entries. */
/*===================*/
j = 0;
for (i = 0; i < BITMAP_HASH_SIZE; i++)
{
for (hashPtr = bitMapTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{
if (newHeader)
{
fprintf(fp,"unsigned long L%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,arrayVersion);
newHeader = FALSE;
}
longsReqd = (int) (hashPtr->size / sizeof(unsigned long));
if ((hashPtr->size % sizeof(unsigned long)) != 0)
longsReqd++;
for (k = 0 ; k < longsReqd ; k++)
{
if (k > 0)
fprintf(fp,",");
tmpLong = 0L;
for (l = 0 ;
((l < sizeof(unsigned long)) &&
(((k * sizeof(unsigned long)) + l) < hashPtr->size)) ;
l++)
((char *) &tmpLong)[l] = hashPtr->contents[(k * sizeof(unsigned long)) + l];
fprintf(fp,"0x%lxL",tmpLong);
}
count += longsReqd;
j += longsReqd;
if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv)->MaxIndices))
{
fprintf(fp,"};\n");
GenClose(theEnv,fp);
j = 0;
arrayVersion++;
version++;
if (count < numberOfEntries)
{
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(0);
newHeader = TRUE;
}
}
else
{ fprintf(fp,",\n"); }
}
}
return(version);
}
/****************************************************/
/* FloatHashNodesToCode: Produces the code for the */
/* float hash table entries for a run-time module */
/* created using the constructs-to-c function. */
/****************************************************/
static int FloatHashNodesToCode(
void *theEnv,
char *fileName,
int version)
{
int i, j;
struct floatHashNode *hashPtr;
int count;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -