00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #define _CSTRNCMP_SOURCE_
00028
00029 #include "setup.h"
00030
00031 #if CONSTRUCT_COMPILER && (! RUN_TIME)
00032
00033 #include "constant.h"
00034
00035 #include "conscomp.h"
00036 #include "envrnmnt.h"
00037 #include "memalloc.h"
00038 #include "router.h"
00039 #include "sysdep.h"
00040
00041 #include "cstrncmp.h"
00042
00043
00044
00045
00046
00047
00048 globle int ConstraintsToCode(
00049 void *theEnv,
00050 char *fileName,
00051 char *pathName,
00052 char *fileNameBuffer,
00053 int fileID,
00054 FILE *headerFP,
00055 int imageID,
00056 int maxIndices)
00057 {
00058 int i, j, count;
00059 int newHeader = TRUE;
00060 FILE *fp;
00061 int version = 1;
00062 int arrayVersion = 1;
00063 unsigned short numberOfConstraints = 0;
00064 CONSTRAINT_RECORD *tmpPtr;
00065
00066
00067
00068
00069
00070 for (i = 0 ; i < SIZE_CONSTRAINT_HASH; i++)
00071 {
00072 for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i];
00073 tmpPtr != NULL;
00074 tmpPtr = tmpPtr->next)
00075 { tmpPtr->bsaveIndex = numberOfConstraints++; }
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 if ((! EnvGetDynamicConstraintChecking(theEnv)) && (numberOfConstraints != 0))
00085 {
00086 numberOfConstraints = 0;
00087 PrintWarningID(theEnv,"CSTRNCMP",1,FALSE);
00088 EnvPrintRouter(theEnv,WWARNING,"Constraints are not saved with a constructs-to-c image\n");
00089 EnvPrintRouter(theEnv,WWARNING," when dynamic constraint checking is disabled.\n");
00090 }
00091
00092 if (numberOfConstraints == 0) return(-1);
00093
00094
00095
00096
00097
00098 for (i = 1; i <= (numberOfConstraints / maxIndices) + 1 ; i++)
00099 { fprintf(headerFP,"extern CONSTRAINT_RECORD C%d_%d[];\n",imageID,i); }
00100
00101
00102
00103
00104
00105 if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL) return(-1);
00106
00107
00108
00109
00110
00111 j = 0;
00112 count = 0;
00113
00114 for (i = 0; i < SIZE_CONSTRAINT_HASH; i++)
00115 {
00116 for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i];
00117 tmpPtr != NULL;
00118 tmpPtr = tmpPtr->next)
00119 {
00120 if (newHeader)
00121 {
00122 fprintf(fp,"CONSTRAINT_RECORD C%d_%d[] = {\n",imageID,arrayVersion);
00123 newHeader = FALSE;
00124 }
00125
00126 fprintf(fp,"{%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
00127 tmpPtr->anyAllowed,
00128 tmpPtr->symbolsAllowed,
00129 tmpPtr->stringsAllowed,
00130 tmpPtr->floatsAllowed,
00131 tmpPtr->integersAllowed,
00132 tmpPtr->instanceNamesAllowed,
00133 tmpPtr->instanceAddressesAllowed,
00134 tmpPtr->externalAddressesAllowed,
00135 tmpPtr->factAddressesAllowed,
00136 0,
00137 tmpPtr->anyRestriction,
00138 tmpPtr->symbolRestriction,
00139 tmpPtr->stringRestriction,
00140 tmpPtr->floatRestriction,
00141 tmpPtr->integerRestriction,
00142 tmpPtr->classRestriction,
00143 tmpPtr->instanceNameRestriction,
00144 tmpPtr->multifieldsAllowed,
00145 tmpPtr->singlefieldsAllowed);
00146
00147 fprintf(fp,",0,");
00148
00149 PrintHashedExpressionReference(theEnv,fp,tmpPtr->classList,imageID,maxIndices);
00150 fprintf(fp,",");
00151 PrintHashedExpressionReference(theEnv,fp,tmpPtr->restrictionList,imageID,maxIndices);
00152 fprintf(fp,",");
00153 PrintHashedExpressionReference(theEnv,fp,tmpPtr->minValue,imageID,maxIndices);
00154 fprintf(fp,",");
00155 PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxValue,imageID,maxIndices);
00156 fprintf(fp,",");
00157 PrintHashedExpressionReference(theEnv,fp,tmpPtr->minFields,imageID,maxIndices);
00158 fprintf(fp,",");
00159 PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxFields,imageID,maxIndices);
00160
00161
00162
00163 fprintf(fp,",NULL");
00164
00165
00166
00167 if (tmpPtr->next == NULL)
00168 { fprintf(fp,",NULL,"); }
00169 else
00170 {
00171 if ((j + 1) >= maxIndices)
00172 { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion + 1,0); }
00173 else
00174 { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion,j + 1); }
00175 }
00176
00177 fprintf(fp,"%d,%d",tmpPtr->bucket,tmpPtr->count + 1);
00178
00179 count++;
00180 j++;
00181
00182 if ((count == numberOfConstraints) || (j >= maxIndices))
00183 {
00184 fprintf(fp,"}};\n");
00185 GenClose(theEnv,fp);
00186 j = 0;
00187 version++;
00188 arrayVersion++;
00189 if (count < numberOfConstraints)
00190 {
00191 if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(0);
00192 newHeader = TRUE;
00193 }
00194 }
00195 else
00196 { fprintf(fp,"},\n"); }
00197 }
00198 }
00199
00200 return(version);
00201 }
00202
00203
00204
00205
00206
00207 globle void PrintConstraintReference(
00208 void *theEnv,
00209 FILE *fp,
00210 CONSTRAINT_RECORD *cPtr,
00211 int imageID,
00212 int maxIndices)
00213 {
00214 if ((cPtr == NULL) || (! EnvGetDynamicConstraintChecking(theEnv)))
00215 { fprintf(fp,"NULL"); }
00216 else fprintf(fp,"&C%d_%d[%d]",imageID,
00217 (int) (cPtr->bsaveIndex / maxIndices) + 1,
00218 (int) cPtr->bsaveIndex % maxIndices);
00219 }
00220
00221 #endif
00222
00223
00224