genrcbin.c

来自「clips源代码」· C语言 代码 · 共 888 行 · 第 1/3 页

C
888
字号
   /* ================================================================      Important to save all expressions for methods before any      expressions for restrictions, since methods will be stored first      ================================================================ */   DoForAllConstructs(theEnv,BsaveMethodExpressions,DefgenericData(theEnv)->DefgenericModuleIndex,                      FALSE,(void *) fp);   DoForAllConstructs(theEnv,BsaveRestrictionExpressions,DefgenericData(theEnv)->DefgenericModuleIndex,                      FALSE,(void *) fp);  }/***************************************************  NAME         : BsaveMethodExpressions  DESCRIPTION  : Saves the needed expressions for                 a defgeneric methods bsave  INPUTS       : 1) The defgeneric                 2) Output data file pointer  RETURNS      : Nothing useful  SIDE EFFECTS : Method action expressions saved  NOTES        : None ***************************************************/static void BsaveMethodExpressions(  void *theEnv,  struct constructHeader *theDefgeneric,  void *userBuffer)  {   DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric;   long i;   for (i = 0 ; i < gfunc->mcnt ; i++)     BsaveExpression(theEnv,gfunc->methods[i].actions,(FILE *) userBuffer);  }/***************************************************  NAME         : BsaveRestrictionExpressions  DESCRIPTION  : Saves the needed expressions for                 a defgeneric method restriction                 queries bsave  INPUTS       : 1) The defgeneric                 2) Output data file pointer  RETURNS      : Nothing useful  SIDE EFFECTS : Method restriction query                 expressions saved  NOTES        : None ***************************************************/static void BsaveRestrictionExpressions(  void *theEnv,  struct constructHeader *theDefgeneric,  void *userBuffer)  {   DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric;   long i,j;   DEFMETHOD *meth;   for (i = 0 ; i < gfunc->mcnt ; i++)     {      meth = &gfunc->methods[i];      for (j = 0 ; j < meth->restrictionCount ; j++)        BsaveExpression(theEnv,meth->restrictions[j].query,(FILE *) userBuffer);     }  }/***********************************************************  NAME         : BsaveStorageGenerics  DESCRIPTION  : Writes out number of each type of structure                   required for generics                 Space required for counts (unsigned long)  INPUTS       : File pointer of binary file  RETURNS      : Nothing useful  SIDE EFFECTS : Binary file adjusted  NOTES        : None ***********************************************************/static void BsaveStorageGenerics(  void *theEnv,  FILE *fp)  {   size_t space;   space = sizeof(long) * 5;   GenWrite((void *) &space,sizeof(size_t),fp);   GenWrite((void *) &DefgenericBinaryData(theEnv)->ModuleCount,sizeof(long),fp);   GenWrite((void *) &DefgenericBinaryData(theEnv)->GenericCount,sizeof(long),fp);   GenWrite((void *) &DefgenericBinaryData(theEnv)->MethodCount,sizeof(long),fp);   GenWrite((void *) &DefgenericBinaryData(theEnv)->RestrictionCount,sizeof(long),fp);   GenWrite((void *) &DefgenericBinaryData(theEnv)->TypeCount,sizeof(long),fp);  }/****************************************************************************************  NAME         : BsaveGenerics  DESCRIPTION  : Writes out generic function in binary format                 Space required (unsigned long)                 All generic modules (sizeof(DEFGENERIC_MODULE) * Number of generic modules)                 All generic headers (sizeof(DEFGENERIC) * Number of generics)                 All methods (sizeof(DEFMETHOD) * Number of methods)                 All method restrictions (sizeof(RESTRICTION) * Number of restrictions)                 All restriction type arrays (sizeof(void *) * # of types)  INPUTS       : File pointer of binary file  RETURNS      : Nothing useful  SIDE EFFECTS : Binary file adjusted  NOTES        : None ****************************************************************************************/static void BsaveGenerics(  void *theEnv,  FILE *fp)  {   struct defmodule *theModule;   DEFGENERIC_MODULE *theModuleItem;   size_t space;   BSAVE_DEFGENERIC_MODULE dummy_generic_module;   /* =====================================================================      Space is: Sum over all structures(sizeof(structure) * structure-cnt))      ===================================================================== */   space = ((unsigned long) DefgenericBinaryData(theEnv)->ModuleCount * sizeof(BSAVE_DEFGENERIC_MODULE)) +           ((unsigned long) DefgenericBinaryData(theEnv)->GenericCount * sizeof(BSAVE_GENERIC)) +           ((unsigned long) DefgenericBinaryData(theEnv)->MethodCount * sizeof(BSAVE_METHOD)) +           ((unsigned long) DefgenericBinaryData(theEnv)->RestrictionCount * sizeof(BSAVE_RESTRICTION)) +           ((unsigned long) DefgenericBinaryData(theEnv)->TypeCount * sizeof(unsigned long));   /* ================================================================      Write out the total amount of space required:  modules,headers,      methods, restrictions, types      ================================================================ */   GenWrite((void *) &space,sizeof(size_t),fp);   /* ======================================      Write out the generic function modules      ====================================== */   DefgenericBinaryData(theEnv)->GenericCount = 0L;   theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);   while (theModule != NULL)     {      theModuleItem = (DEFGENERIC_MODULE *)                      GetModuleItem(theEnv,theModule,FindModuleItem(theEnv,"defgeneric")->moduleIndex);      AssignBsaveDefmdlItemHdrVals(&dummy_generic_module.header,                                           &theModuleItem->header);      GenWrite((void *) &dummy_generic_module,               sizeof(BSAVE_DEFGENERIC_MODULE),fp);      theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,(void *) theModule);     }   /* ======================================      Write out the generic function headers      ====================================== */   DefgenericBinaryData(theEnv)->MethodCount = 0L;   DoForAllConstructs(theEnv,BsaveDefgenericHeader,DefgenericData(theEnv)->DefgenericModuleIndex,                      FALSE,(void *) fp);   /* =====================      Write out the methods      ===================== */   DefgenericBinaryData(theEnv)->RestrictionCount = 0L;   DoForAllConstructs(theEnv,BsaveMethods,DefgenericData(theEnv)->DefgenericModuleIndex,                      FALSE,(void *) fp);   /* =================================      Write out the method restrictions      ================================= */   DefgenericBinaryData(theEnv)->TypeCount = 0L;   DoForAllConstructs(theEnv,BsaveMethodRestrictions,DefgenericData(theEnv)->DefgenericModuleIndex,                      FALSE,(void *) fp);   /* =============================================================      Finally, write out the type lists for the method restrictions      ============================================================= */   DoForAllConstructs(theEnv,BsaveRestrictionTypes,DefgenericData(theEnv)->DefgenericModuleIndex,                      FALSE,(void *) fp);   RestoreBloadCount(theEnv,&DefgenericBinaryData(theEnv)->ModuleCount);   RestoreBloadCount(theEnv,&DefgenericBinaryData(theEnv)->GenericCount);   RestoreBloadCount(theEnv,&DefgenericBinaryData(theEnv)->MethodCount);   RestoreBloadCount(theEnv,&DefgenericBinaryData(theEnv)->RestrictionCount);   RestoreBloadCount(theEnv,&DefgenericBinaryData(theEnv)->TypeCount);  }/***************************************************  NAME         : BsaveDefgenericHeader  DESCRIPTION  : Bsaves a generic function header  INPUTS       : 1) The defgeneric                 2) Output data file pointer  RETURNS      : Nothing useful  SIDE EFFECTS : Defgeneric header saved  NOTES        : None ***************************************************/static void BsaveDefgenericHeader(  void *theEnv,  struct constructHeader *theDefgeneric,  void *userBuffer)  {   DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric;   BSAVE_GENERIC dummy_generic;   AssignBsaveConstructHeaderVals(&dummy_generic.header,&gfunc->header);   dummy_generic.mcnt = gfunc->mcnt;   if (gfunc->methods != NULL)     {      dummy_generic.methods = DefgenericBinaryData(theEnv)->MethodCount;      DefgenericBinaryData(theEnv)->MethodCount += (long) gfunc->mcnt;     }   else     dummy_generic.methods = -1L;   GenWrite((void *) &dummy_generic,(unsigned long) sizeof(BSAVE_GENERIC),(FILE *) userBuffer);  }/***************************************************  NAME         : BsaveMethods  DESCRIPTION  : Bsaves defgeneric methods  INPUTS       : 1) The defgeneric                 2) Output data file pointer  RETURNS      : Nothing useful  SIDE EFFECTS : Defgeneric methods saved  NOTES        : None ***************************************************/static void BsaveMethods(  void *theEnv,  struct constructHeader *theDefgeneric,  void *userBuffer)  {   DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric;   DEFMETHOD *meth;   BSAVE_METHOD dummy_method;   long i;   for (i = 0 ; i < gfunc->mcnt ; i++)     {      meth = &gfunc->methods[i];      dummy_method.index = meth->index;      dummy_method.restrictionCount = meth->restrictionCount;      dummy_method.minRestrictions = meth->minRestrictions;      dummy_method.maxRestrictions = meth->maxRestrictions;      dummy_method.localVarCount = meth->localVarCount;      dummy_method.system = meth->system;      if (meth->restrictions != NULL)        {         dummy_method.restrictions = DefgenericBinaryData(theEnv)->RestrictionCount;         DefgenericBinaryData(theEnv)->RestrictionCount += meth->restrictionCount;        }      else        dummy_method.restrictions = -1L;      if (meth->actions != NULL)        {         dummy_method.actions = ExpressionData(theEnv)->ExpressionCount;         ExpressionData(theEnv)->ExpressionCount += ExpressionSize(meth->actions);        }      else        dummy_method.actions = -1L;      GenWrite((void *) &dummy_method,sizeof(BSAVE_METHOD),(FILE *) userBuffer);     }  }/******************************************************  NAME         : BsaveMethodRestrictions  DESCRIPTION  : Bsaves defgeneric methods' retrictions  INPUTS       : 1) The defgeneric                 2) Output data file pointer  RETURNS      : Nothing useful  SIDE EFFECTS : Defgeneric methods' restrictions saved  NOTES        : None ******************************************************/static void BsaveMethodRestrictions(  void *theEnv,  struct constructHeader *theDefgeneric,  void *userBuffer)  {   DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric;   BSAVE_RESTRICTION dummy_restriction;   RESTRICTION *rptr;   short i,j;   for (i = 0 ; i < gfunc->mcnt ; i++)     {      for (j = 0 ; j < gfunc->methods[i].restrictionCount ; j++)        {         rptr = &gfunc->methods[i].restrictions[j];         dummy_restriction.tcnt = rptr->tcnt;         if (rptr->types != NULL)           {            dummy_restriction.types = DefgenericBinaryData(theEnv)->TypeCount;            DefgenericBinaryData(theEnv)->TypeCount += rptr->tcnt;           }         else           dummy_restriction.types = -1L;         if (rptr->query != NULL)           {            dummy_restriction.query = ExpressionData(theEnv)->ExpressionCount;            ExpressionData(theEnv)->ExpressionCount += ExpressionSize(rptr->query);           }         else           dummy_restriction.query = -1L;         GenWrite((void *) &dummy_restriction,                  sizeof(BSAVE_RESTRICTION),(FILE *) userBuffer);        }     }  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?