#include "setup.h"
#if OBJECT_SYSTEM
#include <stdio.h>
#include "classcom.h"
#include "classexm.h"
#include "classfun.h"
#include "classinf.h"
#include "classpsr.h"
#include "cstrccom.h"
#include "cstrcpsr.h"
#include "envrnmnt.h"
#include "extnfunc.h"
#include "inscom.h"
#include "memalloc.h"
#include "modulpsr.h"
#include "modulutl.h"
#include "msgcom.h"
#include "watch.h"
#if DEFINSTANCES_CONSTRUCT
#include "defins.h"
#endif
#if INSTANCE_SET_QUERIES
#include "insquery.h"
#endif
#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY
#include "bload.h"
#include "objbin.h"
#endif
#if CONSTRUCT_COMPILER && (! RUN_TIME)
#include "objcmp.h"
#endif
#if DEFRULE_CONSTRUCT
#include "objrtbld.h"
#include "objrtfnx.h"
#include "objrtmch.h"
#endif
#if RUN_TIME
#include "insfun.h"
#include "msgfun.h"
#include "pattern.h"
#endif
#include "classini.h"
#define SUPERCLASS_RLN "is-a"
#define NAME_RLN "name"
static void SetupDefclasses(Environment *);
static void DeallocateDefclassData(Environment *);
#if (! RUN_TIME)
static void DestroyDefclassAction(Environment *,ConstructHeader *,void *);
static Defclass *AddSystemClass(Environment *,const char *,Defclass *);
static void *AllocateModule(Environment *);
static void ReturnModule(Environment *,void *);
#else
static void SearchForHashedPatternNodes(Environment *,OBJECT_PATTERN_NODE *);
#endif
#if (! BLOAD_ONLY) && (! RUN_TIME) && DEFMODULE_CONSTRUCT
static void UpdateDefclassesScope(Environment *,void *);
#endif
void SetupObjectSystem(
Environment *theEnv)
{
EntityRecord defclassEntityRecord = { "DEFCLASS_PTR", DEFCLASS_PTR,1,0,0,
NULL,NULL,NULL,NULL,NULL,
(EntityBusyCountFunction *) DecrementDefclassBusyCount,
(EntityBusyCountFunction *) IncrementDefclassBusyCount,
NULL,NULL,NULL,NULL,NULL };
AllocateEnvironmentData(theEnv,DEFCLASS_DATA,sizeof(struct defclassData),NULL);
AddEnvironmentCleanupFunction(theEnv,"defclasses",DeallocateDefclassData,-500);
memcpy(&DefclassData(theEnv)->DefclassEntityRecord,&defclassEntityRecord,sizeof(struct entityRecord));
DefclassData(theEnv)->newSlotID = 2;
#if ! RUN_TIME
DefclassData(theEnv)->ClassDefaultsModeValue = CONVENIENCE_MODE;
DefclassData(theEnv)->ISA_SYMBOL = CreateSymbol(theEnv,SUPERCLASS_RLN);
IncrementLexemeCount(DefclassData(theEnv)->ISA_SYMBOL);
DefclassData(theEnv)->NAME_SYMBOL = CreateSymbol(theEnv,NAME_RLN);
IncrementLexemeCount(DefclassData(theEnv)->NAME_SYMBOL);
#endif
SetupDefclasses(theEnv);
SetupInstances(theEnv);
SetupMessageHandlers(theEnv);
#if DEFINSTANCES_CONSTRUCT
SetupDefinstances(theEnv);
#endif
#if INSTANCE_SET_QUERIES
SetupQuery(theEnv);
#endif
#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY
SetupObjectsBload(theEnv);
#endif
#if CONSTRUCT_COMPILER && (! RUN_TIME)
SetupObjectsCompiler(theEnv);
#endif
#if DEFRULE_CONSTRUCT
SetupObjectPatternStuff(theEnv);
#endif
}
static void DeallocateDefclassData(
Environment *theEnv)
{
#if ! RUN_TIME
SLOT_NAME *tmpSNPPtr, *nextSNPPtr;
int i;
struct defclassModule *theModuleItem;
Defmodule *theModule;
bool bloaded = false;
#if BLOAD || BLOAD_AND_BSAVE
if (Bloaded(theEnv)) bloaded = true;
#endif
if (! bloaded)
{
DoForAllConstructs(theEnv,DestroyDefclassAction,DefclassData(theEnv)->DefclassModuleIndex,false,NULL);
for (theModule = GetNextDefmodule(theEnv,NULL);
theModule != NULL;
theModule = GetNextDefmodule(theEnv,theModule))
{
theModuleItem = (struct defclassModule *)
GetModuleItem(theEnv,theModule,
DefclassData(theEnv)->DefclassModuleIndex);
rtn_struct(theEnv,defclassModule,theModuleItem);
}
}
if (! bloaded)
{
if (DefclassData(theEnv)->ClassIDMap != NULL)
{
genfree(theEnv,DefclassData(theEnv)->ClassIDMap,DefclassData(theEnv)->AvailClassID * sizeof(Defclass *));
}
}
if (DefclassData(theEnv)->ClassTable != NULL)
{
genfree(theEnv,DefclassData(theEnv)->ClassTable,sizeof(Defclass *) * CLASS_TABLE_HASH_SIZE);
}
if (! bloaded)
{
for (i = 0; i < SLOT_NAME_TABLE_HASH_SIZE; i++)
{
tmpSNPPtr = DefclassData(theEnv)->SlotNameTable[i];
while (tmpSNPPtr != NULL)
{
nextSNPPtr = tmpSNPPtr->nxt;
rtn_struct(theEnv,slotName,tmpSNPPtr);
tmpSNPPtr = nextSNPPtr;
}
}
}
if (DefclassData(theEnv)->SlotNameTable != NULL)
{
genfree(theEnv,DefclassData(theEnv)->SlotNameTable,sizeof(SLOT_NAME *) * SLOT_NAME_TABLE_HASH_SIZE);
}
#else
Defclass *cls;
void *tmpexp;
unsigned int i;
int j;
if (DefclassData(theEnv)->ClassTable != NULL)
{
for (j = 0 ; j < CLASS_TABLE_HASH_SIZE ; j++)
for (cls = DefclassData(theEnv)->ClassTable[j] ; cls != NULL ; cls = cls->nxtHash)
{
for (i = 0 ; i < cls->slotCount ; i++)
{
if ((cls->slots[i].defaultValue != NULL) && (cls->slots[i].dynamicDefault == 0))
{
UDFValue *theValue = (UDFValue *) cls->slots[i].defaultValue;
tmpexp = theValue->supplementalInfo;
if (theValue->header->type == MULTIFIELD_TYPE)
{ ReturnMultifield(theEnv,theValue->multifieldValue); }
rtn_struct(theEnv,udfValue,cls->slots[i].defaultValue);
cls->slots[i].defaultValue = tmpexp;
}
}
}
}
#endif
}
#if ! RUN_TIME
static void DestroyDefclassAction(
Environment *theEnv,
ConstructHeader *theConstruct,
void *buffer)
{
#if MAC_XCD
#pragma unused(buffer)
#endif
Defclass *theDefclass = (Defclass *) theConstruct;
if (theDefclass == NULL) return;
#if (! BLOAD_ONLY)
DestroyDefclass(theEnv,theDefclass);
#else
#if MAC_XCD
#pragma unused(theEnv)
#endif
#endif
}
#endif
#if RUN_TIME
void ObjectsRunTimeInitialize(
Environment *theEnv,
Defclass *ctable[],
SLOT_NAME *sntable[],
Defclass **cidmap,
unsigned short mid)
{
Defclass *cls;
void *tmpexp;
unsigned int i,j;
if (DefclassData(theEnv)->ClassTable != NULL)
{
for (j = 0 ; j < CLASS_TABLE_HASH_SIZE ; j++)
for (cls = DefclassData(theEnv)->ClassTable[j] ; cls != NULL ; cls = cls->nxtHash)
{
for (i = 0 ; i < cls->slotCount ; i++)
{
if ((cls->slots[i].defaultValue != NULL) && (cls->slots[i].dynamicDefault == 0))
{
UDFValue *theValue = (UDFValue *) cls->slots[i].defaultValue;
tmpexp = theValue->supplementalInfo;
ReleaseUDFV(theEnv,theValue);
if (theValue->header->type == MULTIFIELD_TYPE)
{ ReturnMultifield(theEnv,theValue->multifieldValue); }
rtn_struct(theEnv,udfValue,cls->slots[i].defaultValue);
cls->slots[i].defaultValue = tmpexp;
}
}
}
}
InstanceQueryData(theEnv)->QUERY_DELIMITER_SYMBOL = FindSymbolHN(theEnv,QUERY_DELIMITER_STRING,SYMBOL_BIT);
MessageHandlerData(theEnv)->INIT_SYMBOL = FindSymbolHN(theEnv,INIT_STRING,SYMBOL_BIT);
MessageHandlerData(theEnv)->DELETE_SYMBOL = FindSymbolHN(theEnv,DELETE_STRING,SYMBOL_BIT);
MessageHandlerData(theEnv)->CREATE_SYMBOL = FindSymbolHN(theEnv,CREATE_STRING,SYMBOL_BIT);
DefclassData(theEnv)->ISA_SYMBOL = FindSymbolHN(theEnv,SUPERCLASS_RLN,SYMBOL_BIT);
DefclassData(theEnv)->NAME_SYMBOL = FindSymbolHN(theEnv,NAME_RLN,SYMBOL_BIT);
DefclassData(theEnv)->ClassTable = (Defclass **) ctable;
DefclassData(theEnv)->SlotNameTable = (SLOT_NAME **) sntable;
DefclassData(theEnv)->ClassIDMap = (Defclass **) cidmap;
DefclassData(theEnv)->MaxClassID = mid;
DefclassData(theEnv)->PrimitiveClassMap[FLOAT_TYPE] =
LookupDefclassByMdlOrScope(theEnv,FLOAT_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[INTEGER_TYPE] =
LookupDefclassByMdlOrScope(theEnv,INTEGER_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[STRING_TYPE] =
LookupDefclassByMdlOrScope(theEnv,STRING_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[SYMBOL_TYPE] =
LookupDefclassByMdlOrScope(theEnv,SYMBOL_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[MULTIFIELD_TYPE] =
LookupDefclassByMdlOrScope(theEnv,MULTIFIELD_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[EXTERNAL_ADDRESS_TYPE] =
LookupDefclassByMdlOrScope(theEnv,EXTERNAL_ADDRESS_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[FACT_ADDRESS_TYPE] =
LookupDefclassByMdlOrScope(theEnv,FACT_ADDRESS_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_NAME_TYPE] =
LookupDefclassByMdlOrScope(theEnv,INSTANCE_NAME_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS_TYPE] =
LookupDefclassByMdlOrScope(theEnv,INSTANCE_ADDRESS_TYPE_NAME);
for (j = 0 ; j < CLASS_TABLE_HASH_SIZE ; j++)
for (cls = DefclassData(theEnv)->ClassTable[j] ; cls != NULL ; cls = cls->nxtHash)
{
cls->header.env = theEnv;
for (i = 0; i < cls->handlerCount; i++)
{ cls->handlers[i].header.env = theEnv; }
for (i = 0 ; i < cls->slotCount ; i++)
{
if ((cls->slots[i].defaultValue != NULL) && (cls->slots[i].dynamicDefault == 0))
{
tmpexp = cls->slots[i].defaultValue;
cls->slots[i].defaultValue = get_struct(theEnv,udfValue);
EvaluateAndStoreInDataObject(theEnv,cls->slots[i].multiple,(Expression *) tmpexp,
(UDFValue *) cls->slots[i].defaultValue,false);
RetainUDFV(theEnv,(UDFValue *) cls->slots[i].defaultValue);
((UDFValue *) cls->slots[i].defaultValue)->supplementalInfo = tmpexp;
}
}
}
SearchForHashedPatternNodes(theEnv,ObjectReteData(theEnv)->ObjectPatternNetworkPointer);
}
static void SearchForHashedPatternNodes(
Environment *theEnv,
OBJECT_PATTERN_NODE *theNode)
{
while (theNode != NULL)
{
if ((theNode->lastLevel != NULL) && (theNode->lastLevel->selector))
{ AddHashedPatternNode(theEnv,theNode->lastLevel,theNode,theNode->networkTest->type,theNode->networkTest->value); }
SearchForHashedPatternNodes(theEnv,theNode->nextLevel);
theNode = theNode->rightNode;
}
}
#else
void CreateSystemClasses(
Environment *theEnv,
void *context)
{
Defclass *user,*any,*primitive,*number,*lexeme,*address,*instance;
AddSlotName(theEnv,DefclassData(theEnv)->ISA_SYMBOL,ISA_ID,true);
AddSlotName(theEnv,DefclassData(theEnv)->NAME_SYMBOL,NAME_ID,true);
DefclassData(theEnv)->newSlotID = 2;
any = AddSystemClass(theEnv,OBJECT_TYPE_NAME,NULL);
primitive = AddSystemClass(theEnv,PRIMITIVE_TYPE_NAME,any);
user = AddSystemClass(theEnv,USER_TYPE_NAME,any);
number = AddSystemClass(theEnv,NUMBER_TYPE_NAME,primitive);
DefclassData(theEnv)->PrimitiveClassMap[INTEGER_TYPE] = AddSystemClass(theEnv,INTEGER_TYPE_NAME,number);
DefclassData(theEnv)->PrimitiveClassMap[FLOAT_TYPE] = AddSystemClass(theEnv,FLOAT_TYPE_NAME,number);
lexeme = AddSystemClass(theEnv,LEXEME_TYPE_NAME,primitive);
DefclassData(theEnv)->PrimitiveClassMap[SYMBOL_TYPE] = AddSystemClass(theEnv,SYMBOL_TYPE_NAME,lexeme);
DefclassData(theEnv)->PrimitiveClassMap[STRING_TYPE] = AddSystemClass(theEnv,STRING_TYPE_NAME,lexeme);
DefclassData(theEnv)->PrimitiveClassMap[MULTIFIELD_TYPE] = AddSystemClass(theEnv,MULTIFIELD_TYPE_NAME,primitive);
address = AddSystemClass(theEnv,ADDRESS_TYPE_NAME,primitive);
DefclassData(theEnv)->PrimitiveClassMap[EXTERNAL_ADDRESS_TYPE] = AddSystemClass(theEnv,EXTERNAL_ADDRESS_TYPE_NAME,address);
DefclassData(theEnv)->PrimitiveClassMap[FACT_ADDRESS_TYPE] = AddSystemClass(theEnv,FACT_ADDRESS_TYPE_NAME,address);
instance = AddSystemClass(theEnv,INSTANCE_TYPE_NAME,primitive);
DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS_TYPE] = AddSystemClass(theEnv,INSTANCE_ADDRESS_TYPE_NAME,instance);
DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_NAME_TYPE] = AddSystemClass(theEnv,INSTANCE_NAME_TYPE_NAME,instance);
AddClassLink(theEnv,&DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS_TYPE]->directSuperclasses,address,true,0);
AddClassLink(theEnv,&DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS_TYPE]->allSuperclasses,address,false,2);
AddClassLink(theEnv,&address->directSubclasses,DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS_TYPE],true,0);
AddConstructToModule(&DefclassData(theEnv)->PrimitiveClassMap[FLOAT_TYPE]->header);
AddConstructToModule(&DefclassData(theEnv)->PrimitiveClassMap[INTEGER_TYPE]->header);
AddConstructToModule(&DefclassData(theEnv)->PrimitiveClassMap[SYMBOL_TYPE]->header);
AddConstructToModule(&DefclassData(theEnv)->PrimitiveClassMap[STRING_TYPE]->header);
AddConstructToModule(&DefclassData(theEnv)->PrimitiveClassMap[MULTIFIELD_TYPE]->header);
AddConstructToModule(&DefclassData(theEnv)->PrimitiveClassMap[EXTERNAL_ADDRESS_TYPE]->header);
AddConstructToModule(&DefclassData(theEnv)->PrimitiveClassMap[FACT_ADDRESS_TYPE]->header);
AddConstructToModule(&DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS_TYPE]->header);
AddConstructToModule(&DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_NAME_TYPE]->header);
AddConstructToModule(&any->header);
AddConstructToModule(&primitive->header);
AddConstructToModule(&number->header);
AddConstructToModule(&lexeme->header);
AddConstructToModule(&address->header);
AddConstructToModule(&instance->header);
AddConstructToModule(&user->header);
for (any = GetNextDefclass(theEnv,NULL) ;
any != NULL ;
any = GetNextDefclass(theEnv,any))
AssignClassID(theEnv,any);
}
#endif
static void SetupDefclasses(
Environment *theEnv)
{
InstallPrimitive(theEnv,&DefclassData(theEnv)->DefclassEntityRecord,DEFCLASS_PTR);
DefclassData(theEnv)->DefclassModuleIndex =
RegisterModuleItem(theEnv,"defclass",
#if (! RUN_TIME)
AllocateModule,
ReturnModule,
#else
NULL,NULL,
#endif
#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY
BloadDefclassModuleReference,
#else
NULL,
#endif
#if CONSTRUCT_COMPILER && (! RUN_TIME)
DefclassCModuleReference,
#else
NULL,
#endif
(FindConstructFunction *) FindDefclassInModule);
DefclassData(theEnv)->DefclassConstruct = AddConstruct(theEnv,"defclass","defclasses",
#if (! BLOAD_ONLY) && (! RUN_TIME)
ParseDefclass,
#else
NULL,
#endif
(FindConstructFunction *) FindDefclass,
GetConstructNamePointer,GetConstructPPForm,
GetConstructModuleItem,
(GetNextConstructFunction *) GetNextDefclass,
SetNextConstruct,
(IsConstructDeletableFunction *) DefclassIsDeletable,
(DeleteConstructFunction *) Undefclass,
#if (! RUN_TIME)
(FreeConstructFunction *) RemoveDefclass
#else
NULL
#endif
);
AddClearReadyFunction(theEnv,"defclass",InstancesPurge,0,NULL);
#if ! RUN_TIME
AddClearFunction(theEnv,"defclass",CreateSystemClasses,0,NULL);
InitializeClasses(theEnv);
#if ! BLOAD_ONLY
#if DEFMODULE_CONSTRUCT
AddPortConstructItem(theEnv,"defclass",SYMBOL_TOKEN);
AddAfterModuleDefinedFunction(theEnv,"defclass",UpdateDefclassesScope,0,NULL);
#endif
AddUDF(theEnv,"undefclass","v",1,1,"y",UndefclassCommand,"UndefclassCommand",NULL);
AddSaveFunction(theEnv,"defclass",SaveDefclasses,10,NULL);
#endif
#if DEBUGGING_FUNCTIONS
AddUDF(theEnv,"list-defclasses","v",0,1,"y",ListDefclassesCommand,"ListDefclassesCommand",NULL);
AddUDF(theEnv,"ppdefclass","vs",1,2,";y;ldsyn",PPDefclassCommand,"PPDefclassCommand",NULL);
AddUDF(theEnv,"describe-class","v",1,1,"y",DescribeClassCommand,"DescribeClassCommand",NULL);
AddUDF(theEnv,"browse-classes","v",0,1,"y",BrowseClassesCommand,"BrowseClassesCommand",NULL);
#endif
AddUDF(theEnv,"get-defclass-list","m",0,1,"y",GetDefclassListFunction,"GetDefclassListFunction",NULL);
AddUDF(theEnv,"superclassp","b",2,2,"y",SuperclassPCommand,"SuperclassPCommand",NULL);
AddUDF(theEnv,"subclassp","b",2,2,"y",SubclassPCommand,"SubclassPCommand",NULL);
AddUDF(theEnv,"class-existp","b", 1,1,"y",ClassExistPCommand,"ClassExistPCommand",NULL);
AddUDF(theEnv,"message-handler-existp","b",2,3,"y",MessageHandlerExistPCommand,"MessageHandlerExistPCommand",NULL);
AddUDF(theEnv,"class-abstractp","b",1,1,"y",ClassAbstractPCommand,"ClassAbstractPCommand",NULL);
#if DEFRULE_CONSTRUCT
AddUDF(theEnv,"class-reactivep","b",1,1,"y",ClassReactivePCommand,"ClassReactivePCommand",NULL);
#endif
AddUDF(theEnv,"class-slots","m",1,2,"y",ClassSlotsCommand,"ClassSlotsCommand",NULL);
AddUDF(theEnv,"class-superclasses","m",1,2,"y",ClassSuperclassesCommand,"ClassSuperclassesCommand",NULL);
AddUDF(theEnv,"class-subclasses","m",1,2,"y",ClassSubclassesCommand,"ClassSubclassesCommand",NULL);
AddUDF(theEnv,"get-defmessage-handler-list","m",0,2,"y",GetDefmessageHandlersListCmd,"GetDefmessageHandlersListCmd",NULL);
AddUDF(theEnv,"slot-existp","b",2,3,"y",SlotExistPCommand,"SlotExistPCommand",NULL);
AddUDF(theEnv,"slot-facets","m",2,2,"y",SlotFacetsCommand,"SlotFacetsCommand",NULL);
AddUDF(theEnv,"slot-sources","m",2,2,"y",SlotSourcesCommand,"SlotSourcesCommand",NULL);
AddUDF(theEnv,"slot-types","m",2,2,"y",SlotTypesCommand,"SlotTypesCommand",NULL);
AddUDF(theEnv,"slot-allowed-values","m",2,2,"y",SlotAllowedValuesCommand,"SlotAllowedValuesCommand",NULL);
AddUDF(theEnv,"slot-allowed-classes","m",2,2,"y",SlotAllowedClassesCommand,"SlotAllowedClassesCommand",NULL);
AddUDF(theEnv,"slot-range","m",2,2,"y",SlotRangeCommand,"SlotRangeCommand",NULL);
AddUDF(theEnv,"slot-cardinality","m",2,2,"y",SlotCardinalityCommand,"SlotCardinalityCommand",NULL);
AddUDF(theEnv,"slot-writablep","b",2,2,"y",SlotWritablePCommand,"SlotWritablePCommand",NULL);
AddUDF(theEnv,"slot-initablep","b",2,2,"y",SlotInitablePCommand,"SlotInitablePCommand",NULL);
AddUDF(theEnv,"slot-publicp","b",2,2,"y",SlotPublicPCommand,"SlotPublicPCommand",NULL);
AddUDF(theEnv,"slot-direct-accessp","b",2,2,"y",SlotDirectAccessPCommand,"SlotDirectAccessPCommand",NULL);
AddUDF(theEnv,"slot-default-value","*",2,2,"y",SlotDefaultValueCommand,"SlotDefaultValueCommand",NULL);
AddUDF(theEnv,"defclass-module","y",1,1,"y",GetDefclassModuleCommand,"GetDefclassModuleCommand",NULL);
AddUDF(theEnv,"get-class-defaults-mode","y",0,0,NULL,GetClassDefaultsModeCommand,"GetClassDefaultsModeCommand",NULL);
AddUDF(theEnv,"set-class-defaults-mode","y",1,1,"y",SetClassDefaultsModeCommand,"SetClassDefaultsModeCommand",NULL);
#endif
#if DEBUGGING_FUNCTIONS
AddWatchItem(theEnv,"instances",0,&DefclassData(theEnv)->WatchInstances,75,DefclassWatchAccess,DefclassWatchPrint);
AddWatchItem(theEnv,"slots",1,&DefclassData(theEnv)->WatchSlots,74,DefclassWatchAccess,DefclassWatchPrint);
#endif
}
#if (! RUN_TIME)
static Defclass *AddSystemClass(
Environment *theEnv,
const char *name,
Defclass *parent)
{
Defclass *sys;
unsigned long i;
char defaultScopeMap[1];
sys = NewClass(theEnv,CreateSymbol(theEnv,name));
sys->abstract = 1;
#if DEFRULE_CONSTRUCT
sys->reactive = 0;
#endif
IncrementLexemeCount(sys->header.name);
sys->installed = 1;
sys->system = 1;
sys->hashTableIndex = HashClass(sys->header.name);
AddClassLink(theEnv,&sys->allSuperclasses,sys,true,0);
if (parent != NULL)
{
AddClassLink(theEnv,&sys->directSuperclasses,parent,true,0);
AddClassLink(theEnv,&parent->directSubclasses,sys,true,0);
AddClassLink(theEnv,&sys->allSuperclasses,parent,true,0);
for (i = 1 ; i < parent->allSuperclasses.classCount ; i++)
AddClassLink(theEnv,&sys->allSuperclasses,parent->allSuperclasses.classArray[i],true,0);
}
sys->nxtHash = DefclassData(theEnv)->ClassTable[sys->hashTableIndex];
DefclassData(theEnv)->ClassTable[sys->hashTableIndex] = sys;
ClearBitString(defaultScopeMap,sizeof(char));
SetBitMap(defaultScopeMap,0);
#if DEFMODULE_CONSTRUCT
sys->scopeMap = (CLIPSBitMap *) AddBitMap(theEnv,defaultScopeMap,sizeof(char));
IncrementBitMapCount(sys->scopeMap);
#endif
return(sys);
}
static void *AllocateModule(
Environment *theEnv)
{
return (void *) get_struct(theEnv,defclassModule);
}
static void ReturnModule(
Environment *theEnv,
void *theItem)
{
FreeConstructHeaderModule(theEnv,(struct defmoduleItemHeader *) theItem,DefclassData(theEnv)->DefclassConstruct);
DeleteSlotName(theEnv,FindIDSlotNameHash(theEnv,ISA_ID));
DeleteSlotName(theEnv,FindIDSlotNameHash(theEnv,NAME_ID));
rtn_struct(theEnv,defclassModule,theItem);
}
#endif
#if (! BLOAD_ONLY) && (! RUN_TIME) && DEFMODULE_CONSTRUCT
static void UpdateDefclassesScope(
Environment *theEnv,
void *context)
{
unsigned i;
Defclass *theDefclass;
unsigned long newModuleID;
unsigned int count;
char *newScopeMap;
unsigned short newScopeMapSize;
const char *className;
Defmodule *matchModule;
newModuleID = GetCurrentModule(theEnv)->header.bsaveID;
newScopeMapSize = (sizeof(char) * ((GetNumberOfDefmodules(theEnv) / BITS_PER_BYTE) + 1));
newScopeMap = (char *) gm2(theEnv,newScopeMapSize);
for (i = 0 ; i < CLASS_TABLE_HASH_SIZE ; i++)
for (theDefclass = DefclassData(theEnv)->ClassTable[i] ;
theDefclass != NULL ;
theDefclass = theDefclass->nxtHash)
{
matchModule = theDefclass->header.whichModule->theModule;
className = theDefclass->header.name->contents;
ClearBitString(newScopeMap,newScopeMapSize);
GenCopyMemory(char,theDefclass->scopeMap->size,
newScopeMap,theDefclass->scopeMap->contents);
DecrementBitMapReferenceCount(theEnv,theDefclass->scopeMap);
if (theDefclass->system)
SetBitMap(newScopeMap,newModuleID);
else if (FindImportedConstruct(theEnv,"defclass",matchModule,
className,&count,true,NULL) != NULL)
SetBitMap(newScopeMap,newModuleID);
theDefclass->scopeMap = (CLIPSBitMap *) AddBitMap(theEnv,newScopeMap,newScopeMapSize);
IncrementBitMapCount(theDefclass->scopeMap);
}
rm(theEnv,newScopeMap,newScopeMapSize);
}
#endif
#endif