📄 classinf.c
字号:
SetMFType(result->value,i,SYMBOL); SetMFValue(result->value,i,GetDefclassNamePointer((VOID *) ctmp->cls)); } DeleteClassLinks(ctop); }globle VOID SlotTypes(clsptr,sname,result) VOID *clsptr; char *sname; DATA_OBJECT *result; { register int i,j; register SLOT_DESC *sp; char typemap[2]; int msize; if ((sp = SlotInfoSlot(result,(DEFCLASS *) clsptr,sname,"slot-types"))== NULL) return; if ((sp->constraint != NULL) ? sp->constraint->anyAllowed : CLIPS_TRUE) { typemap[0] = typemap[1] = (char) 0xFF; ClearBitMap(typemap,MULTIFIELD); msize = 8; } else { typemap[0] = typemap[1] = (char) 0x00; msize = 0; if (sp->constraint->symbolsAllowed) { msize++; SetBitMap(typemap,SYMBOL); } if (sp->constraint->stringsAllowed) { msize++; SetBitMap(typemap,STRING); } if (sp->constraint->floatsAllowed) { msize++; SetBitMap(typemap,FLOAT); } if (sp->constraint->integersAllowed) { msize++; SetBitMap(typemap,INTEGER); } if (sp->constraint->instanceNamesAllowed) { msize++; SetBitMap(typemap,INSTANCE_NAME); } if (sp->constraint->instanceAddressesAllowed) { msize++; SetBitMap(typemap,INSTANCE_ADDRESS); } if (sp->constraint->externalAddressesAllowed) { msize++; SetBitMap(typemap,EXTERNAL_ADDRESS); } if (sp->constraint->factAddressesAllowed) { msize++; SetBitMap(typemap,FACT_ADDRESS); } } result->end = msize - 1; result->value = CreateMultifield(msize); i = 1; j = 0; while (i <= msize) { if (TestBitMap(typemap,j)) { SetMFType(result->value,i,SYMBOL); SetMFValue(result->value,i, (VOID *) GetDefclassNamePointer((VOID *)PrimitiveClassMap[j])); i++; } j++; } } globle VOID SlotAllowedValues(clsptr,sname,result) VOID *clsptr; char *sname; DATA_OBJECT *result; { register int i; register SLOT_DESC *sp; register EXPRESSION *exp; if ((sp = SlotInfoSlot(result,(DEFCLASS *) clsptr,sname,"slot-allowed-values")) == NULL) return; if ((sp->constraint != NULL) ? (sp->constraint->restrictionList == NULL) : CLIPS_TRUE) { result->type = SYMBOL; result->value = CLIPSFalseSymbol; return; } result->end = ExpressionSize(sp->constraint->restrictionList) - 1; result->value = CreateMultifield(result->end + 1); i = 1; exp = sp->constraint->restrictionList; while (exp != NULL) { SetMFType(result->value,i,exp->type); SetMFValue(result->value,i,exp->value); exp = exp->nextArg; i++; } } globle VOID SlotRange(clsptr,sname,result) VOID *clsptr; char *sname; DATA_OBJECT *result; { register SLOT_DESC *sp; if ((sp = SlotInfoSlot(result,(DEFCLASS *) clsptr,sname,"slot-range")) == NULL) return; if ((sp->constraint == NULL) ? CLIPS_FALSE : (sp->constraint->anyAllowed || sp->constraint->floatsAllowed || sp->constraint->integersAllowed)) { result->end = 1; result->value = CreateMultifield(2L); SetMFType(result->value,1,sp->constraint->minValue->type); SetMFValue(result->value,1,sp->constraint->minValue->value); SetMFType(result->value,2,sp->constraint->maxValue->type); SetMFValue(result->value,2,sp->constraint->maxValue->value); } else { result->type = SYMBOL; result->value = CLIPSFalseSymbol; return; } } globle VOID SlotCardinality(clsptr,sname,result) VOID *clsptr; char *sname; DATA_OBJECT *result; { register SLOT_DESC *sp; if ((sp = SlotInfoSlot(result,(DEFCLASS *) clsptr,sname,"slot-cardinality")) == NULL) return; if (sp->multiple == 0) { SetMultifieldErrorValue(result); return; } result->end = 1; result->value = CreateMultifield(2L); if (sp->constraint != NULL) { SetMFType(result->value,1,sp->constraint->minFields->type); SetMFValue(result->value,1,sp->constraint->minFields->value); SetMFType(result->value,2,sp->constraint->maxFields->type); SetMFValue(result->value,2,sp->constraint->maxFields->value); } else { SetMFType(result->value,1,INTEGER); SetMFValue(result->value,1,Zero); SetMFType(result->value,2,SYMBOL); SetMFValue(result->value,2,PositiveInfinity); } } /* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//***************************************************** NAME : SlotInfoSupportFunction DESCRIPTION : Support routine for slot-sources, slot-facets, et. al. INPUTS : 1) Data object buffer 2) Name of the CLIPS caller 3) Pointer to support function to call RETURNS : Nothing useful SIDE EFFECTS : Support function called and data object buffer set NOTES : None *****************************************************/static VOID SlotInfoSupportFunction(result,fnxname,fnx) DATA_OBJECT *result; char *fnxname;#if ANSI_COMPILER VOID (*fnx)(VOID *,char *,DATA_OBJECT *);#else VOID (*fnx)();#endif { SYMBOL_HN *ssym; DEFCLASS *cls; ssym = CheckClassAndSlot(fnxname,&cls); if (ssym == NULL) { SetMultifieldErrorValue(result); return; } (*fnx)((VOID *) cls,ValueToString(ssym),result); }/***************************************************************** NAME : CountSubclasses DESCRIPTION : Counts the number of direct or indirect subclasses for a class INPUTS : 1) Address of class 2) Include (1) or exclude (0) indirect subclasses 3) Traversal id RETURNS : The number of subclasses SIDE EFFECTS : None NOTES : None *****************************************************************/static int CountSubclasses(cls,inhp,tvid) DEFCLASS *cls; int inhp,tvid; { register unsigned i,cnt; register DEFCLASS *subcls; for (cnt = 0 , i = 0 ; i < cls->directSubclasses.classCount ; i++) { subcls = cls->directSubclasses.classArray[i]; if (TestTraversalID(subcls->traversalRecord,tvid) == 0) { cnt++; SetTraversalID(subcls->traversalRecord,tvid); if (inhp && (subcls->directSubclasses.classCount != 0)) cnt += CountSubclasses(subcls,inhp,tvid); } } return(cnt); } /********************************************************************* NAME : StoreSubclasses DESCRIPTION : Stores the names of direct or indirect subclasses for a class in a mutlifield INPUTS : 1) Caller's multifield buffer 2) Starting index 3) Address of the class 4) Include (1) or exclude (0) indirect subclasses 5) Traversal id RETURNS : The number of subclass names stored in the multifield SIDE EFFECTS : Multifield set with subclass names NOTES : Assumes multifield is big enough to hold subclasses *********************************************************************/static int StoreSubclasses(mfval,si,cls,inhp,tvid) VOID *mfval; int si; DEFCLASS *cls; int inhp,tvid; { register unsigned i,classi; register DEFCLASS *subcls; for (i = si , classi = 0 ; classi < cls->directSubclasses.classCount ; classi++) { subcls = cls->directSubclasses.classArray[classi]; if (TestTraversalID(subcls->traversalRecord,tvid) == 0) { SetTraversalID(subcls->traversalRecord,tvid); SetMFType(mfval,i,SYMBOL); SetMFValue(mfval,i++,(VOID *) GetDefclassNamePointer((VOID *) subcls)); if (inhp && (subcls->directSubclasses.classCount != 0)) i += StoreSubclasses(mfval,(int) i,subcls,inhp,tvid); } } return(i - si); } /********************************************************* NAME : SlotInfoSlot DESCRIPTION : Runtime support routine for slot-sources, slot-facets, et. al. which looks up a slot INPUTS : 1) Data object buffer 2) Class pointer 3) Name-string of slot to find 4) The name of the calling function RETURNS : Nothing useful SIDE EFFECTS : Support function called and data object buffer initialized NOTES : None *********************************************************/static SLOT_DESC *SlotInfoSlot(result,cls,sname,fnxname) DATA_OBJECT *result; DEFCLASS *cls; char *sname,*fnxname; { SYMBOL_HN *ssym; int i; if ((ssym = FindSymbol(sname)) == NULL) { SetEvaluationError(CLIPS_TRUE); SetMultifieldErrorValue(result); return(NULL); } i = FindInstanceTemplateSlot(cls,ssym); if (i == -1) { SlotExistError(sname,fnxname); SetEvaluationError(CLIPS_TRUE); SetMultifieldErrorValue(result); return(NULL); } result->type = MULTIFIELD; result->begin = 0; return(cls->instanceTemplate[i]); }#endif /*************************************************** NAME : DESCRIPTION : INPUTS : RETURNS : SIDE EFFECTS : NOTES : ***************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -