📄 genrcbin.c
字号:
for (j = 0 ; j < meth->restrictionCount ; j++) { rptr = &meth->restrictions[j]; ExpressionCount += ExpressionSize(rptr->query); MarkNeededItems(rptr->query); TypeCount += rptr->tcnt; } } }/*************************************************** NAME : BsaveGenericsExpressions DESCRIPTION : Writes out all expressions needed by generic functions INPUTS : The file pointer of the binary file RETURNS : Nothing useful SIDE EFFECTS : File updated NOTES : None ***************************************************/static VOID BsaveGenericsExpressions(fp) FILE *fp; { /* ================================================================ Important to save all expressions for methods before any expressions for restrictions, since methods will be stored first ================================================================ */ DoForAllConstructs(BsaveMethodExpressions,DefgenericModuleIndex, CLIPS_FALSE,(VOID *) fp); DoForAllConstructs(BsaveRestrictionExpressions,DefgenericModuleIndex, CLIPS_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(theDefgeneric,userBuffer) struct constructHeader *theDefgeneric; VOID *userBuffer; { DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric; register unsigned i; for (i = 0 ; i < gfunc->mcnt ; i++) BsaveExpression(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(theDefgeneric,userBuffer) struct constructHeader *theDefgeneric; VOID *userBuffer; { DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric; register unsigned i,j; DEFMETHOD *meth; for (i = 0 ; i < gfunc->mcnt ; i++) { meth = &gfunc->methods[i]; for (j = 0 ; j < meth->restrictionCount ; j++) BsaveExpression(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(fp) FILE *fp; { unsigned long space; space = sizeof(long) * 5; GenWrite((VOID *) &space,(unsigned long) sizeof(long),fp); GenWrite((VOID *) &ModuleCount,(unsigned long) sizeof(long),fp); GenWrite((VOID *) &GenericCount,(unsigned long) sizeof(long),fp); GenWrite((VOID *) &MethodCount,(unsigned long) sizeof(long),fp); GenWrite((VOID *) &RestrictionCount,(unsigned long) sizeof(long),fp); GenWrite((VOID *) &TypeCount,(unsigned long) 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(fp) FILE *fp; { struct defmodule *theModule; DEFGENERIC_MODULE *theModuleItem; unsigned long space; BSAVE_DEFGENERIC_MODULE dummy_generic_module; /* ===================================================================== Space is: Sum over all structures(sizeof(structure) * structure-cnt)) ===================================================================== */ space = ((unsigned long) ModuleCount * (unsigned long) sizeof(BSAVE_DEFGENERIC_MODULE)) + ((unsigned long) GenericCount * (unsigned long) sizeof(BSAVE_GENERIC)) + ((unsigned long) MethodCount * (unsigned long) sizeof(BSAVE_METHOD)) + ((unsigned long) RestrictionCount * (unsigned long) sizeof(BSAVE_RESTRICTION)) + ((unsigned long) TypeCount * (unsigned long) sizeof(unsigned long)); /* ================================================================ Write out the total amount of space required: modules,headers, methods, restrictions, types ================================================================ */ GenWrite((VOID *) &space,(unsigned long) sizeof(unsigned long),fp); /* ====================================== Write out the generic function modules ====================================== */ GenericCount = 0L; theModule = (struct defmodule *) GetNextDefmodule(NULL); while (theModule != NULL) { theModuleItem = (DEFGENERIC_MODULE *) GetModuleItem(theModule,FindModuleItem("defgeneric")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&dummy_generic_module.header, &theModuleItem->header); GenWrite((VOID *) &dummy_generic_module, (unsigned long) sizeof(BSAVE_DEFGENERIC_MODULE),fp); theModule = (struct defmodule *) GetNextDefmodule((VOID *) theModule); } /* ====================================== Write out the generic function headers ====================================== */ MethodCount = 0L; DoForAllConstructs(BsaveDefgenericHeader,DefgenericModuleIndex, CLIPS_FALSE,(VOID *) fp); /* ===================== Write out the methods ===================== */ RestrictionCount = 0L; DoForAllConstructs(BsaveMethods,DefgenericModuleIndex, CLIPS_FALSE,(VOID *) fp); /* ================================= Write out the method restrictions ================================= */ TypeCount = 0L; DoForAllConstructs(BsaveMethodRestrictions,DefgenericModuleIndex, CLIPS_FALSE,(VOID *) fp); /* ============================================================= Finally, write out the type lists for the method restrictions ============================================================= */ DoForAllConstructs(BsaveRestrictionTypes,DefgenericModuleIndex, CLIPS_FALSE,(VOID *) fp); if (Bloaded()) { RestoreBloadCount(&ModuleCount); RestoreBloadCount(&GenericCount); RestoreBloadCount(&MethodCount); RestoreBloadCount(&RestrictionCount); RestoreBloadCount(&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(theDefgeneric,userBuffer) 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 = MethodCount; MethodCount += 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(theDefgeneric,userBuffer) struct constructHeader *theDefgeneric; VOID *userBuffer; { DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric; DEFMETHOD *meth; BSAVE_METHOD dummy_method; register unsigned 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 = RestrictionCount; RestrictionCount += meth->restrictionCount; } else dummy_method.restrictions = -1L; if (meth->actions != NULL) { dummy_method.actions = ExpressionCount; ExpressionCount += ExpressionSize(meth->actions); } else dummy_method.actions = -1L; GenWrite((VOID *) &dummy_method,(unsigned long) 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(theDefgeneric,userBuffer) struct constructHeader *theDefgeneric; VOID *userBuffer; { DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric; BSAVE_RESTRICTION dummy_restriction; RESTRICTION *rptr; register unsigned 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 = TypeCount; TypeCount += rptr->tcnt; } else dummy_restriction.types = -1L;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -