Exemple #1
0
static void DumpExpression(
  struct expr *exprPtr)
  {

   while (exprPtr != NULL)
     {
      fprintf(ExpressionFP,"{");
      fprintf(ExpressionFP,"%d,",exprPtr->type);
      fprintf(ExpressionFP,"VS ");
      switch (exprPtr->type)
        {
         case FCALL:
           PrintFunctionReference(ExpressionFP,(struct FunctionDefinition *) exprPtr->value);
           break;

         case INTEGER:
           PrintIntegerReference(ExpressionFP,(INTEGER_HN *) exprPtr->value);
           break;

         case FLOAT:
           PrintFloatReference(ExpressionFP,(FLOAT_HN *) exprPtr->value);
           break;

         case PCALL:
#if DEFFUNCTION_CONSTRUCT
           PrintDeffunctionReference(ExpressionFP,(DEFFUNCTION *) exprPtr->value,
                                     ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case GCALL:
#if DEFGENERIC_CONSTRUCT
           PrintGenericFunctionReference(ExpressionFP,(DEFGENERIC *) exprPtr->value,
                                         ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case DEFTEMPLATE_PTR:
#if DEFTEMPLATE_CONSTRUCT
           DeftemplateCConstructReference(ExpressionFP,exprPtr->value,ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case DEFGLOBAL_PTR:
#if DEFGLOBAL_CONSTRUCT
           DefglobalCConstructReference(ExpressionFP,exprPtr->value,ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case DEFCLASS_PTR:
#if OBJECT_SYSTEM
           PrintClassReference(ExpressionFP,(DEFCLASS *) exprPtr->value,ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

          case FACT_ADDRESS:
#if DEFTEMPLATE_CONSTRUCT
           fprintf(ExpressionFP,"&DummyFact");
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case INSTANCE_ADDRESS:
#if OBJECT_SYSTEM
           fprintf(ExpressionFP,"&DummyInstance");
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case STRING:
         case SYMBOL:
         case INSTANCE_NAME:
         case GBL_VARIABLE:
           PrintSymbolReference(ExpressionFP,(SYMBOL_HN *) exprPtr->value);
           break;

         case RVOID:
           fprintf(ExpressionFP,"NULL");
           break;

         default:
           if (PrimitivesArray[exprPtr->type] == NULL)
             { fprintf(ExpressionFP,"NULL"); }
           else if (PrimitivesArray[exprPtr->type]->bitMap)
             { PrintBitMapReference(ExpressionFP,(BITMAP_HN *) exprPtr->value); }
           else
             { fprintf(ExpressionFP,"NULL"); }
           break;
        }

      fprintf(ExpressionFP,",");

      ExpressionCount++;
      if (exprPtr->argList == NULL)
        { fprintf(ExpressionFP,"NULL,"); }
      else
        {
         fprintf(ExpressionFP,"&E%d_%d[%ld],",ImageID,ExpressionVersion,
                                                       ExpressionCount);
        }

      if (exprPtr->nextArg == NULL)
        { fprintf(ExpressionFP,"NULL}"); }
      else
        {
         fprintf(ExpressionFP,"&E%d_%d[%ld]}",ImageID,ExpressionVersion,
                              ExpressionCount + ExpressionSize(exprPtr->argList));
        }

      if (exprPtr->argList != NULL)
        {
         fprintf(ExpressionFP,",\n");
         DumpExpression(exprPtr->argList);
        }

      exprPtr = exprPtr->nextArg;
      if (exprPtr != NULL) fprintf(ExpressionFP,",\n");
     }
  }
Exemple #2
0
static int FuzzyValuesToCode(
    char *fileName,
    int version)
{
    int i, j;
    struct fuzzyValueHashNode *hashPtr;
    int count;
    int numberOfEntries;
    struct fuzzyValueHashNode **fuzzyValueTable;
    int newHeader = TRUE;
    int arrayVersion = 1;
    FILE *fp;
    int arraySize;
    int xyArrayPartition = 1, xyArrayPartitionCount = 0;

    /*====================================*/
    /* Count the total number of entries. */
    /*====================================*/

    fuzzyValueTable = GetFuzzyValueTable();
    count = numberOfEntries = 0;

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        hashPtr = fuzzyValueTable[i];
        while (hashPtr != NULL)
        {
            numberOfEntries++;
            hashPtr = hashPtr->next;
        }
    }

    if (numberOfEntries == 0) return(version);

    for (i = 1; i <= (numberOfEntries / MaxIndices) + 1 ; i++)
    {
        fprintf(HeaderFP,"extern struct fuzzy_value W%d_%d[];\n",ImageID,i);
    }

    /*==================*/
    /* Create the file. */
    /*==================*/

    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(-1);

    /*=====================*/
    /* Fillin the entries. */
    /*=====================*/

    j = 0;

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        hashPtr = fuzzyValueTable[i];
        while (hashPtr != NULL)
        {
            if (newHeader)
            {
                fprintf(fp,"struct fuzzy_value W%d_%d[] = {\n",ImageID,arrayVersion);
                newHeader = FALSE;
            }

            /* fill in the entries of the fuzzy value struct:
                  whichDeftemplate - ptr to deftemplate structure
                  name  - char *
                  maxn  - int
                  n     - int
                  x     - ptr to double (will be index into X array)
                  y     - ptr to double (will be index into X array)
            */

            fprintf(fp,"{");
            DeftemplateCConstructReference(fp, hashPtr->contents->whichDeftemplate,
                                           ImageID, MaxIndices);
            fprintf(fp,",");
            PrintCString(fp,hashPtr->contents->name);
            /* NOTE: arraySize twice in next fprintf line is correct!
                     We don't want to store maxn value since we pack the arrays
                     when writing X array out to c file
            */
            arraySize = hashPtr->contents->n;
            fprintf(fp,",%d,%d", arraySize, arraySize);
            fprintf(fp,",(double *)&X%d_%d[%d], (double *)&X%d_%d[%d]",
                    ImageID, xyArrayPartition, xyArrayPartitionCount,
                    ImageID, xyArrayPartition, xyArrayPartitionCount+arraySize);

            xyArrayPartitionCount += arraySize + arraySize;
            if (xyArrayPartitionCount >= MaxIndices)
            {
                xyArrayPartitionCount = 0;
                xyArrayPartition++;
            }

            count++;
            j++;

            if ((count == numberOfEntries) || (j >= MaxIndices))
            {
                fprintf(fp,"}};\n");
                fclose(fp);
                j = 0;
                arrayVersion++;
                version++;
                if (count < numberOfEntries)
                {
                    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(0);
                    newHeader = TRUE;
                }
            }
            else
            {
                fprintf(fp,"},\n");
            }

            hashPtr = hashPtr->next;
        }
    }

    return(version);
}