1 /*******************************************************/
2 /* "C" Language Integrated Production System */
4 /* CLIPS Version 6.30 08/16/14 */
6 /* CONSTRAINT CONSTRUCTS-TO-C MODULE */
7 /*******************************************************/
9 /*************************************************************/
10 /* Purpose: Implements the constructs-to-c feature for */
11 /* constraint records. */
13 /* Principal Programmer(s): */
16 /* Contributing Programmer(s): */
19 /* Revision History: */
21 /* 6.24: Added allowed-classes slot facet. */
23 /* Added environment parameter to GenClose. */
25 /* 6.30: Added support for path name argument to */
26 /* constructs-to-c. */
28 /* Added const qualifiers to remove C++ */
29 /* deprecation warnings. */
31 /*************************************************************/
33 #define _CSTRNCMP_SOURCE_
37 #if CONSTRUCT_COMPILER && (! RUN_TIME)
49 /***********************************************/
50 /* ConstraintsToCode: Produces the constraint */
51 /* record code for a run-time module created */
52 /* using the constructs-to-c function. */
53 /***********************************************/
54 globle int ConstraintsToCode(
69 unsigned short numberOfConstraints = 0;
70 CONSTRAINT_RECORD *tmpPtr;
72 /*===============================================*/
73 /* Count the total number of constraint records. */
74 /*===============================================*/
76 for (i = 0 ; i < SIZE_CONSTRAINT_HASH; i++)
78 for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i];
80 tmpPtr = tmpPtr->next)
81 { tmpPtr->bsaveIndex = numberOfConstraints++; }
84 /*=====================================================*/
85 /* If dynamic constraint checking is disabled, then */
86 /* contraints won't be saved. If there are constraints */
87 /* which could be saved, then issue a warning message. */
88 /*=====================================================*/
90 if ((! EnvGetDynamicConstraintChecking(theEnv)) && (numberOfConstraints != 0))
92 numberOfConstraints = 0;
93 PrintWarningID(theEnv,"CSTRNCMP",1,FALSE);
94 EnvPrintRouter(theEnv,WWARNING,"Constraints are not saved with a constructs-to-c image\n");
95 EnvPrintRouter(theEnv,WWARNING," when dynamic constraint checking is disabled.\n");
98 if (numberOfConstraints == 0) return(-1);
100 /*=================================================*/
101 /* Print the extern definition in the header file. */
102 /*=================================================*/
104 for (i = 1; i <= (numberOfConstraints / maxIndices) + 1 ; i++)
105 { fprintf(headerFP,"extern CONSTRAINT_RECORD C%d_%d[];\n",imageID,i); }
107 /*==================*/
108 /* Create the file. */
109 /*==================*/
111 if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL) return(-1);
113 /*===================*/
114 /* List the entries. */
115 /*===================*/
120 for (i = 0; i < SIZE_CONSTRAINT_HASH; i++)
122 for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i];
124 tmpPtr = tmpPtr->next)
128 fprintf(fp,"CONSTRAINT_RECORD C%d_%d[] = {\n",imageID,arrayVersion);
132 fprintf(fp,"{%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
134 tmpPtr->symbolsAllowed,
135 tmpPtr->stringsAllowed,
136 tmpPtr->floatsAllowed,
137 tmpPtr->integersAllowed,
138 tmpPtr->instanceNamesAllowed,
139 tmpPtr->instanceAddressesAllowed,
140 tmpPtr->externalAddressesAllowed,
141 tmpPtr->factAddressesAllowed,
142 0, /* void allowed */
143 tmpPtr->anyRestriction,
144 tmpPtr->symbolRestriction,
145 tmpPtr->stringRestriction,
146 tmpPtr->floatRestriction,
147 tmpPtr->integerRestriction,
148 tmpPtr->classRestriction,
149 tmpPtr->instanceNameRestriction,
150 tmpPtr->multifieldsAllowed,
151 tmpPtr->singlefieldsAllowed);
153 fprintf(fp,",0,"); /* bsaveIndex */
155 PrintHashedExpressionReference(theEnv,fp,tmpPtr->classList,imageID,maxIndices);
157 PrintHashedExpressionReference(theEnv,fp,tmpPtr->restrictionList,imageID,maxIndices);
159 PrintHashedExpressionReference(theEnv,fp,tmpPtr->minValue,imageID,maxIndices);
161 PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxValue,imageID,maxIndices);
163 PrintHashedExpressionReference(theEnv,fp,tmpPtr->minFields,imageID,maxIndices);
165 PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxFields,imageID,maxIndices);
167 /* multifield slot */
173 if (tmpPtr->next == NULL)
174 { fprintf(fp,",NULL,"); }
177 if ((j + 1) >= maxIndices)
178 { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion + 1,0); }
180 { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion,j + 1); }
183 fprintf(fp,"%d,%d",tmpPtr->bucket,tmpPtr->count + 1);
188 if ((count == numberOfConstraints) || (j >= maxIndices))
195 if (count < numberOfConstraints)
197 if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(0);
202 { fprintf(fp,"},\n"); }
209 /**********************************************************/
210 /* PrintConstraintReference: Prints C code representation */
211 /* of a constraint record data structure reference. */
212 /**********************************************************/
213 globle void PrintConstraintReference(
216 CONSTRAINT_RECORD *cPtr,
220 if ((cPtr == NULL) || (! EnvGetDynamicConstraintChecking(theEnv)))
221 { fprintf(fp,"NULL"); }
222 else fprintf(fp,"&C%d_%d[%d]",imageID,
223 (int) (cPtr->bsaveIndex / maxIndices) + 1,
224 (int) cPtr->bsaveIndex % maxIndices);
227 #endif /* CONSTRUCT_COMPILER && (! RUN_TIME) */