📄 classexm.c
字号:
int slotIndex; SLOT_DESC *sd; ssym = CheckClassAndSlot(theEnv,func,classBuffer); if (ssym == NULL) return(NULL); slotIndex = FindInstanceTemplateSlot(theEnv,*classBuffer,ssym); if (slotIndex == -1) { if (existsErrorFlag) { SlotExistError(theEnv,ValueToString(ssym),func); SetEvaluationError(theEnv,TRUE); } return(NULL); } sd = (*classBuffer)->instanceTemplate[slotIndex]; if ((sd->cls == *classBuffer) || inheritFlag) return(sd); PrintErrorID(theEnv,"CLASSEXM",1,FALSE); EnvPrintRouter(theEnv,WERROR,"Inherited slot "); EnvPrintRouter(theEnv,WERROR,ValueToString(ssym)); EnvPrintRouter(theEnv,WERROR," from class "); PrintClassName(theEnv,WERROR,sd->cls,FALSE); EnvPrintRouter(theEnv,WERROR," is not valid for function "); EnvPrintRouter(theEnv,WERROR,func); EnvPrintRouter(theEnv,WERROR,"\n"); SetEvaluationError(theEnv,TRUE); return(NULL); }/*************************************************** NAME : LookupSlot DESCRIPTION : Finds a slot in a class INPUTS : 1) The class 2) The slot name 3) A flag indicating if inherited slots are OK or not RETURNS : The slot descriptor address, or NULL if not found SIDE EFFECTS : None NOTES : None ***************************************************/static SLOT_DESC *LookupSlot( void *theEnv, DEFCLASS *theDefclass, char *slotName, intBool inheritFlag) { SYMBOL_HN *slotSymbol; int slotIndex; SLOT_DESC *sd; slotSymbol = FindSymbolHN(theEnv,slotName); if (slotSymbol == NULL) return(NULL); slotIndex = FindInstanceTemplateSlot(theEnv,theDefclass,slotSymbol); if (slotIndex == -1) return(NULL); sd = theDefclass->instanceTemplate[slotIndex]; if ((sd->cls != theDefclass) && (inheritFlag == FALSE)) return(NULL); return(sd); }#if DEBUGGING_FUNCTIONS/***************************************************** NAME : CheckClass DESCRIPTION : Used for to check class name for class accessor functions such as ppdefclass and undefclass INPUTS : 1) The name of the H/L function 2) Name of the class RETURNS : The class address, or NULL if ther was an error SIDE EFFECTS : None NOTES : None ******************************************************/static DEFCLASS *CheckClass( void *theEnv, char *func, char *cname) { DEFCLASS *cls; cls = LookupDefclassByMdlOrScope(theEnv,cname); if (cls == NULL) ClassExistError(theEnv,func,cname); return(cls); }/********************************************************* NAME : GetClassNameArgument DESCRIPTION : Gets a class name-string INPUTS : Calling function name RETURNS : Class name (NULL on errors) SIDE EFFECTS : None NOTES : Assumes only 1 argument *********************************************************/static char *GetClassNameArgument( void *theEnv, char *fname) { DATA_OBJECT temp; if (EnvArgTypeCheck(theEnv,fname,1,SYMBOL,&temp) == FALSE) return(NULL); return(DOToString(temp)); }/**************************************************************** NAME : PrintClassBrowse DESCRIPTION : Displays a "graph" of class and subclasses INPUTS : 1) The logical name of the output 2) The class address 3) The depth of the graph RETURNS : Nothing useful SIDE EFFECTS : None NOTES : None ****************************************************************/static void PrintClassBrowse( void *theEnv, char *logicalName, DEFCLASS *cls, long depth) { long i; for (i = 0 ; i < depth ; i++) EnvPrintRouter(theEnv,logicalName," "); EnvPrintRouter(theEnv,logicalName,EnvGetDefclassName(theEnv,(void *) cls)); if (cls->directSuperclasses.classCount > 1) EnvPrintRouter(theEnv,logicalName," *"); EnvPrintRouter(theEnv,logicalName,"\n"); for (i = 0 ;i < cls->directSubclasses.classCount ; i++) PrintClassBrowse(theEnv,logicalName,cls->directSubclasses.classArray[i],depth+1); }/********************************************************* NAME : DisplaySeparator DESCRIPTION : Prints a separator line for DescribeClass INPUTS : 1) The logical name of the output 2) The buffer to use for the line 3) The buffer size 4) The character to use RETURNS : Nothing useful SIDE EFFECTS : Buffer overwritten and displayed NOTES : None *********************************************************/static void DisplaySeparator( void *theEnv, char *logicalName, char *buf, int maxlen, int sepchar) { register int i; for (i = 0 ; i < maxlen-2 ; i++) buf[i] = (char) sepchar; buf[i++] = '\n'; buf[i] = '\0'; EnvPrintRouter(theEnv,logicalName,buf); }/************************************************************* NAME : DisplaySlotBasicInfo DESCRIPTION : Displays a table summary of basic facets for the slots of a class including: single/multiple default/no-default/default-dynamic inherit/no-inherit read-write/initialize-only/read-only local/shared composite/exclusive reactive/non-reactive public/private create-accessor read/write override-message The function also displays the source class(es) for the facets INPUTS : 1) The logical name of the output 2) A format string for use in sprintf (for printing slot names) 3) A format string for use in sprintf (for printing slot override message names) 4) A buffer to store the display in 5) A pointer to the class RETURNS : Nothing useful SIDE EFFECTS : Buffer written to and displayed NOTES : None *************************************************************/static void DisplaySlotBasicInfo( void *theEnv, char *logicalName, char *slotNamePrintFormat, char *overrideMessagePrintFormat, char *buf, DEFCLASS *cls) { long i; SLOT_DESC *sp; char *createString; gensprintf(buf,slotNamePrintFormat,"SLOTS");#if DEFRULE_CONSTRUCT genstrcat(buf,"FLD DEF PRP ACC STO MCH SRC VIS CRT ");#else genstrcat(buf,"FLD DEF PRP ACC STO SRC VIS CRT ");#endif EnvPrintRouter(theEnv,logicalName,buf); gensprintf(buf,overrideMessagePrintFormat,"OVRD-MSG"); EnvPrintRouter(theEnv,logicalName,buf); EnvPrintRouter(theEnv,logicalName,"SOURCE(S)\n"); for (i = 0 ; i < cls->instanceSlotCount ; i++) { sp = cls->instanceTemplate[i]; gensprintf(buf,slotNamePrintFormat,ValueToString(sp->slotName->name)); genstrcat(buf,sp->multiple ? "MLT " : "SGL "); if (sp->noDefault) genstrcat(buf,"NIL "); else genstrcat(buf,sp->dynamicDefault ? "DYN " : "STC "); genstrcat(buf,sp->noInherit ? "NIL " : "INH "); if (sp->initializeOnly) genstrcat(buf,"INT "); else if (sp->noWrite) genstrcat(buf," R "); else genstrcat(buf,"RW "); genstrcat(buf,sp->shared ? "SHR " : "LCL ");#if DEFRULE_CONSTRUCT genstrcat(buf,sp->reactive ? "RCT " : "NIL ");#endif genstrcat(buf,sp->composite ? "CMP " : "EXC "); genstrcat(buf,sp->publicVisibility ? "PUB " : "PRV "); createString = GetCreateAccessorString(sp); if (createString[1] == '\0') genstrcat(buf," "); genstrcat(buf,createString); if ((createString[1] == '\0') ? TRUE : (createString[2] == '\0')) genstrcat(buf," "); genstrcat(buf," "); EnvPrintRouter(theEnv,logicalName,buf); gensprintf(buf,overrideMessagePrintFormat, sp->noWrite ? "NIL" : ValueToString(sp->overrideMessage)); EnvPrintRouter(theEnv,logicalName,buf); PrintSlotSources(theEnv,logicalName,sp->slotName->name,&sp->cls->allSuperclasses,0,TRUE); EnvPrintRouter(theEnv,logicalName,"\n"); } }/*************************************************** NAME : PrintSlotSources DESCRIPTION : Displays a list of source classes for a composite class (in order of most general to specific) INPUTS : 1) The logical name of the output 2) The name of the slot 3) The precedence list of the class of the slot (the source class shold be first in the list) 4) The index into the packed links array 5) Flag indicating whether to disregard noniherit facet RETURNS : TRUE if a class is printed, FALSE otherwise SIDE EFFECTS : Recursively prints out appropriate memebers from list in reverse order NOTES : None ***************************************************/static intBool PrintSlotSources( void *theEnv, char *logicalName, SYMBOL_HN *sname, PACKED_CLASS_LINKS *sprec, long theIndex, int inhp) { SLOT_DESC *csp; if (theIndex == sprec->classCount) return(FALSE); csp = FindClassSlot(sprec->classArray[theIndex],sname); if ((csp != NULL) ? ((csp->noInherit == 0) || inhp) : FALSE) { if (csp->composite) { if (PrintSlotSources(theEnv,logicalName,sname,sprec,theIndex+1,FALSE)) EnvPrintRouter(theEnv,logicalName," "); } PrintClassName(theEnv,logicalName,sprec->classArray[theIndex],FALSE); return(TRUE); } else return(PrintSlotSources(theEnv,logicalName,sname,sprec,theIndex+1,FALSE)); }/********************************************************* NAME : DisplaySlotConstraintInfo DESCRIPTION : Displays a table summary of type-checking facets for the slots of a class including: type allowed-symbols allowed-integers allowed-floats allowed-values allowed-instance-names range min-number-of-elements max-number-of-elements The function also displays the source class(es) for the facets INPUTS : 1) A format string for use in sprintf 2) A buffer to store the display in 3) Maximum buffer size 4) A pointer to the class RETURNS : Nothing useful SIDE EFFECTS : Buffer written to and displayed NOTES : None *********************************************************/static void DisplaySlotConstraintInfo( void *theEnv, char *logicalName, char *slotNamePrintFormat, char *buf, unsigned maxlen, DEFCLASS *cls) { long i; CONSTRAINT_RECORD *cr; char *strdest = "***describe-class***"; gensprintf(buf,slotNamePrintFormat,"SLOTS"); genstrcat(buf,"SYM STR INN INA EXA FTA INT FLT\n"); EnvPrintRouter(theEnv,logicalName,buf); for (i = 0 ; i < cls->instanceSlotCount ; i++) { cr = cls->instanceTemplate[i]->constraint; gensprintf(buf,slotNamePrintFormat,ValueToString(cls->instanceTemplate[i]->slotName->name)); if (cr != NULL) { genstrcat(buf,ConstraintCode(cr,(unsigned) cr->symbolsAllowed, (unsigned) cr->symbolRestriction)); genstrcat(buf,ConstraintCode(cr,(unsigned) cr->stringsAllowed, (unsigned) cr->stringRestriction)); genstrcat(buf,ConstraintCode(cr,(unsigned) cr->instanceNamesAllowed, (unsigned) (cr->instanceNameRestriction || cr->classRestriction))); genstrcat(buf,ConstraintCode(cr,(unsigned) cr->instanceAddressesAllowed, (unsigned) cr->classRestriction)); genstrcat(buf,ConstraintCode(cr,(unsigned) cr->externalAddressesAllowed,0)); genstrcat(buf,ConstraintCode(cr,(unsigned) cr->factAddressesAllowed,0)); genstrcat(buf,ConstraintCode(cr,(unsigned) cr->integersAllowed, (unsigned) cr->integerRestriction)); genstrcat(buf,ConstraintCode(cr,(unsigned) cr->floatsAllowed, (unsigned) cr->floatRestriction)); OpenStringDestination(theEnv,strdest,buf + strlen(buf),(maxlen - strlen(buf) - 1)); if (cr->integersAllowed || cr->floatsAllowed || cr->anyAllowed) { EnvPrintRouter(theEnv,strdest,"RNG:["); PrintExpression(theEnv,strdest,cr->minValue); EnvPrintRouter(theEnv,strdest,".."); PrintExpression(theEnv,strdest,cr->maxValue); EnvPrintRouter(theEnv,strdest,"] "); } if (cls->instanceTemplate[i]->multiple) { EnvPrintRouter(theEnv,strdest,"CRD:["); PrintExpression(theEnv,strdest,cr->minFields); EnvPrintRouter(theEnv,strdest,".."); PrintExpression(theEnv,strdest,cr->maxFields); EnvPrintRouter(theEnv,strdest,"]"); } } else { OpenStringDestination(theEnv,strdest,buf,maxlen); EnvPrintRouter(theEnv,strdest," + + + + + + + + RNG:[-oo..+oo]"); if (cls->instanceTemplate[i]->multiple) EnvPrintRouter(theEnv,strdest," CRD:[0..+oo]"); } EnvPrintRouter(theEnv,strdest,"\n"); CloseStringDestination(theEnv,strdest); EnvPrintRouter(theEnv,logicalName,buf); } }/****************************************************** NAME : ConstraintCode DESCRIPTION : Gives a string code representing the type of constraint INPUTS : 1) The constraint record 2) Allowed Flag 3) Restricted Values flag RETURNS : " " for type not allowed " + " for any value of type allowed " # " for some values of type allowed SIDE EFFECTS : None NOTES : Used by DisplaySlotConstraintInfo ******************************************************/static char *ConstraintCode( CONSTRAINT_RECORD *cr, unsigned allow, unsigned restrictValues) { if (allow || cr->anyAllowed) return((char *) ((restrictValues || cr->anyRestriction) ? " # " : " + ")); return(" "); }#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -