📄 classini.c
字号:
PrimitiveClassMap[INTEGER] = AddSystemClass(INTEGER_TYPE_NAME,number); PrimitiveClassMap[FLOAT] = AddSystemClass(FLOAT_TYPE_NAME,number); lexeme = AddSystemClass(LEXEME_TYPE_NAME,primitive); PrimitiveClassMap[SYMBOL] = AddSystemClass(SYMBOL_TYPE_NAME,lexeme); PrimitiveClassMap[STRING] = AddSystemClass(STRING_TYPE_NAME,lexeme); PrimitiveClassMap[MULTIFIELD] = AddSystemClass(MULTIFIELD_TYPE_NAME,primitive); address = AddSystemClass(ADDRESS_TYPE_NAME,primitive); PrimitiveClassMap[EXTERNAL_ADDRESS] = AddSystemClass(EXTERNAL_ADDRESS_TYPE_NAME,address); PrimitiveClassMap[FACT_ADDRESS] = AddSystemClass(FACT_ADDRESS_TYPE_NAME,address); instance = AddSystemClass(INSTANCE_TYPE_NAME,primitive); PrimitiveClassMap[INSTANCE_ADDRESS] = AddSystemClass(INSTANCE_ADDRESS_TYPE_NAME,instance); PrimitiveClassMap[INSTANCE_NAME] = AddSystemClass(INSTANCE_NAME_TYPE_NAME,instance);#if INSTANCE_PATTERN_MATCHING initialObject = AddSystemClass(INITIAL_OBJECT_CLASS_NAME,user); initialObject->abstract = 0; initialObject->reactive = 1;#endif /* ================================================================================ INSTANCE-ADDRESS is-a INSTANCE and ADDRESS. The links between INSTANCE-ADDRESS and ADDRESS still need to be made. =============================================================================== */ AddClassLink(&PrimitiveClassMap[INSTANCE_ADDRESS]->directSuperclasses,address,-1); AddClassLink(&PrimitiveClassMap[INSTANCE_ADDRESS]->allSuperclasses,address,2); AddClassLink(&address->directSubclasses,PrimitiveClassMap[INSTANCE_ADDRESS],-1); /* ======================================================================= The order of the class in the list MUST correspond to their type codes! See CONSTANT.H ======================================================================= */ AddConstructToModule((struct constructHeader *) PrimitiveClassMap[FLOAT]); AddConstructToModule((struct constructHeader *) PrimitiveClassMap[INTEGER]); AddConstructToModule((struct constructHeader *) PrimitiveClassMap[SYMBOL]); AddConstructToModule((struct constructHeader *) PrimitiveClassMap[STRING]); AddConstructToModule((struct constructHeader *) PrimitiveClassMap[MULTIFIELD]); AddConstructToModule((struct constructHeader *) PrimitiveClassMap[EXTERNAL_ADDRESS]); AddConstructToModule((struct constructHeader *) PrimitiveClassMap[FACT_ADDRESS]); AddConstructToModule((struct constructHeader *) PrimitiveClassMap[INSTANCE_ADDRESS]); AddConstructToModule((struct constructHeader *) PrimitiveClassMap[INSTANCE_NAME]); AddConstructToModule((struct constructHeader *) any); AddConstructToModule((struct constructHeader *) primitive); AddConstructToModule((struct constructHeader *) number); AddConstructToModule((struct constructHeader *) lexeme); AddConstructToModule((struct constructHeader *) address); AddConstructToModule((struct constructHeader *) instance); AddConstructToModule((struct constructHeader *) user);#if INSTANCE_PATTERN_MATCHING AddConstructToModule((struct constructHeader *) initialObject);#endif for (any = (DEFCLASS *) GetNextDefclass(NULL) ; any != NULL ; any = (DEFCLASS *) GetNextDefclass((VOID *) any)) AssignClassID(any); } #endif/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */ /********************************************************* NAME : SetupDefclasses DESCRIPTION : Initializes Class Hash Table, Function Parsers, and Data Structures INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : NOTES : None *********************************************************/ static VOID SetupDefclasses() { InstallPrimitive(&DefclassEntityRecord,DEFCLASS_PTR); DefclassModuleIndex = RegisterModuleItem("defclass",#if (! RUN_TIME) AllocateModule,FreeModule,#else NULL,NULL,#endif#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY BloadDefclassModuleReference,#else NULL,#endif#if CONSTRUCT_COMPILER && (! RUN_TIME) DefclassCModuleReference,#else NULL,#endif FindDefclass); DefclassConstruct = AddConstruct("defclass","defclasses",#if (! BLOAD_ONLY) && (! RUN_TIME) ParseDefclass,#else NULL,#endif FindDefclass, GetConstructNamePointer,GetConstructPPForm, GetConstructModuleItem,GetNextDefclass, SetNextConstruct,IsDefclassDeletable, Undefclass,#if (! RUN_TIME) RemoveDefclass#else NULL#endif ); AddClearReadyFunction("defclass",InstancesPurge,0);#if ! RUN_TIME AddClearFunction("defclass",CreateSystemClasses,0); InitializeClasses();#if ! BLOAD_ONLY#if DEFMODULE_CONSTRUCT AddPortConstructItem("defclass",SYMBOL); AddAfterModuleDefinedFunction("defclass",UpdateDefclassesScope,0);#endif DefineFunction2("undefclass",'v',PTIF UndefclassCommand,"UndefclassCommand","11w"); AddSaveFunction("defclass",SaveDefclasses,10);#endif#if DEBUGGING_FUNCTIONS DefineFunction2("list-defclasses",'v',PTIF ListDefclassesCommand,"ListDefclassesCommand","01"); DefineFunction2("ppdefclass",'v',PTIF PPDefclassCommand,"PPDefclassCommand","11w"); DefineFunction2("describe-class",'v',PTIF DescribeClassCommand,"DescribeClassCommand","11w"); DefineFunction2("browse-classes",'v',PTIF BrowseClassesCommand,"BrowseClassesCommand","01w");#endif DefineFunction2("get-defclass-list",'m',PTIF GetDefclassListFunction, "GetDefclassListFunction","01"); DefineFunction2("superclassp",'b',PTIF SuperclassPCommand,"SuperclassPCommand","22w"); DefineFunction2("subclassp",'b',PTIF SubclassPCommand,"SubclassPCommand","22w"); DefineFunction2("class-existp",'b',PTIF ClassExistPCommand,"ClassExistPCommand","11w"); DefineFunction2("message-handler-existp",'b', PTIF MessageHandlerExistPCommand,"MessageHandlerExistPCommand","23w"); DefineFunction2("class-abstractp",'b',PTIF ClassAbstractPCommand,"ClassAbstractPCommand","11w");#if INSTANCE_PATTERN_MATCHING DefineFunction2("class-reactivep",'b',PTIF ClassReactivePCommand,"ClassReactivePCommand","11w");#endif DefineFunction2("class-slots",'m',PTIF ClassSlotsCommand,"ClassSlotsCommand","12w"); DefineFunction2("class-superclasses",'m', PTIF ClassSuperclassesCommand,"ClassSuperclassesCommand","12w"); DefineFunction2("class-subclasses",'m', PTIF ClassSubclassesCommand,"ClassSubclassesCommand","12w"); DefineFunction2("get-defmessage-handler-list",'m', PTIF GetDefmessageHandlersListCmd,"GetDefmessageHandlersListCmd","02w"); DefineFunction2("slot-existp",'b',PTIF SlotExistPCommand,"SlotExistPCommand","23w"); DefineFunction2("slot-facets",'m',PTIF SlotFacetsCommand,"SlotFacetsCommand","22w"); DefineFunction2("slot-sources",'m',PTIF SlotSourcesCommand,"SlotSourcesCommand","22w"); DefineFunction2("slot-types",'m',PTIF SlotTypesCommand,"SlotTypesCommand","22w"); DefineFunction2("slot-allowed-values",'m',PTIF SlotAllowedValuesCommand,"SlotAllowedValuesCommand","22w"); DefineFunction2("slot-range",'m',PTIF SlotRangeCommand,"SlotRangeCommand","22w"); DefineFunction2("slot-cardinality",'m',PTIF SlotCardinalityCommand,"SlotCardinalityCommand","22w"); DefineFunction2("slot-writablep",'b',PTIF SlotWritablePCommand,"SlotWritablePCommand","22w"); DefineFunction2("slot-initablep",'b',PTIF SlotInitablePCommand,"SlotInitablePCommand","22w"); DefineFunction2("slot-publicp",'b',PTIF SlotPublicPCommand,"SlotPublicPCommand","22w"); DefineFunction2("slot-direct-accessp",'b',PTIF SlotDirectAccessPCommand, "SlotDirectAccessPCommand","22w"); DefineFunction2("slot-default-value",'u',PTIF SlotDefaultValueCommand, "SlotDefaultValueCommand","22w"); DefineFunction2("defclass-module",'w',PTIF GetDefclassModuleCommand, "GetDefclassModuleCommand","11w");#endif#if DEBUGGING_FUNCTIONS AddWatchItem("instances",0,&WatchInstances,75,DefclassWatchAccess,DefclassWatchPrint); AddWatchItem("slots",1,&WatchSlots,74,DefclassWatchAccess,DefclassWatchPrint);#endif }#if (! RUN_TIME)/********************************************************* NAME : AddSystemClass DESCRIPTION : Performs all necessary allocations for adding a system class INPUTS : 1) The name-string of the system class 2) The address of the parent class (NULL if none) RETURNS : The address of the new system class SIDE EFFECTS : Allocations performed NOTES : Assumes system-class name is unique Also assumes SINGLE INHERITANCE for system classes to simplify precedence list determination Adds classes to has table but NOT to class list (this is responsibility of caller) *********************************************************/static DEFCLASS *AddSystemClass(name,parent) char *name; DEFCLASS *parent; { DEFCLASS *sys; register unsigned i; char defaultScopeMap[1]; sys = NewClass((SYMBOL_HN *) AddSymbol(name)); sys->abstract = 1;#if INSTANCE_PATTERN_MATCHING sys->reactive = 0;#endif IncrementSymbolCount(sys->header.name); sys->installed = 1; sys->system = 1; sys->hashTableIndex = HashClass(sys->header.name); AddClassLink(&sys->allSuperclasses,sys,-1); if (parent != NULL) { AddClassLink(&sys->directSuperclasses,parent,-1); AddClassLink(&parent->directSubclasses,sys,-1); AddClassLink(&sys->allSuperclasses,parent,-1); for (i = 1 ; i < parent->allSuperclasses.classCount ; i++) AddClassLink(&sys->allSuperclasses,parent->allSuperclasses.classArray[i],-1); } sys->nxtHash = ClassTable[sys->hashTableIndex]; ClassTable[sys->hashTableIndex] = sys; /* ========================================= Add default scope maps for a system class There is only one module (MAIN) so far - which has an id of 0 ========================================= */ ClearBitString((VOID *) defaultScopeMap,(int) sizeof(char)); SetBitMap(defaultScopeMap,0);#if DEFMODULE_CONSTRUCT sys->scopeMap = (BITMAP_HN *) AddBitMap((VOID *) defaultScopeMap,(int) sizeof(char)); IncrementBitMapCount(sys->scopeMap);#endif return(sys); }/***************************************************** NAME : AllocateModule DESCRIPTION : Creates and initializes a list of deffunctions for a new module INPUTS : None RETURNS : The new deffunction module SIDE EFFECTS : Deffunction module created NOTES : None *****************************************************/static VOID *AllocateModule() { return((VOID *) get_struct(defclassModule)); } /*************************************************** NAME : FreeModule DESCRIPTION : Removes a deffunction module and all associated deffunctions INPUTS : The deffunction module RETURNS : Nothing useful SIDE EFFECTS : Module and deffunctions deleted NOTES : None ***************************************************/static VOID FreeModule(theItem) VOID *theItem; { FreeConstructHeaderModule((struct defmoduleItemHeader *) theItem,DefclassConstruct); DeleteSlotName(FindIDSlotNameHash(ISA_ID)); DeleteSlotName(FindIDSlotNameHash(NAME_ID)); rtn_struct(defclassModule,theItem); } #endif#if (! BLOAD_ONLY) && (! RUN_TIME) && DEFMODULE_CONSTRUCT /*************************************************** NAME : UpdateDefclassesScope DESCRIPTION : This function updates the scope bitmaps for existing classes when a new module is defined INPUTS : None RETURNS : Nothing SIDE EFFECTS : Class scope bitmaps are updated NOTES : None ***************************************************/static VOID UpdateDefclassesScope() { register unsigned i; DEFCLASS *theDefclass; int newModuleID,count; char *newScopeMap; int newScopeMapSize; char *className; struct defmodule *matchModule; newModuleID = (int) ((struct defmodule *) GetCurrentModule())->bsaveID; newScopeMapSize = (int) (sizeof(char) * ((GetNumberOfDefmodules() / BITS_PER_BYTE) + 1)); newScopeMap = (char *) gm2(newScopeMapSize); for (i = 0 ; i < CLASS_TABLE_HASH_SIZE ; i++) for (theDefclass = ClassTable[i] ; theDefclass != NULL ; theDefclass = theDefclass->nxtHash) { matchModule = theDefclass->header.whichModule->theModule; className = ValueToString(theDefclass->header.name); ClearBitString((VOID *) newScopeMap,newScopeMapSize); CopyMemory(char,theDefclass->scopeMap->size, newScopeMap,ValueToBitMap(theDefclass->scopeMap)); DecrementBitMapCount(theDefclass->scopeMap); if (theDefclass->system) SetBitMap(newScopeMap,newModuleID); else if (FindImportedConstruct("defclass",matchModule, className,&count,CLIPS_TRUE,NULL) != NULL) SetBitMap(newScopeMap,newModuleID); theDefclass->scopeMap = (BITMAP_HN *) AddBitMap((VOID *) newScopeMap,newScopeMapSize); IncrementBitMapCount(theDefclass->scopeMap); } rm((VOID *) newScopeMap,newScopeMapSize); } #endif #endif /*************************************************** NAME : DESCRIPTION : INPUTS : RETURNS : SIDE EFFECTS : NOTES : ***************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -