/******************************************************************* NAME : EnvFindDefclass DESCRIPTION : Looks up a specified class in the class hash table (Only looks in current or specified module) INPUTS : The name-string of the class (including module) RETURNS : The address of the found class, NULL otherwise SIDE EFFECTS : None NOTES : None ******************************************************************/ globle void *EnvFindDefclass( // TBD Needs to look in imported void *theEnv, const char *classAndModuleName) { SYMBOL_HN *classSymbol = NULL; DEFCLASS *cls; struct defmodule *theModule = NULL; const char *className; SaveCurrentModule(theEnv); className = ExtractModuleAndConstructName(theEnv,classAndModuleName); if (className != NULL) { classSymbol = FindSymbolHN(theEnv,ExtractModuleAndConstructName(theEnv,classAndModuleName)); theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv)); } RestoreCurrentModule(theEnv); if (classSymbol == NULL) return(NULL); cls = DefclassData(theEnv)->ClassTable[HashClass(classSymbol)]; while (cls != NULL) { if (cls->header.name == classSymbol) { if (cls->system || (cls->header.whichModule->theModule == theModule)) return(cls->installed ? (void *) cls : NULL); } cls = cls->nxtHash; } return(NULL); }
/*************************************************** NAME : LookupDefclassByMdlOrScope DESCRIPTION : Finds a class anywhere (if module is specified) or in current or imported modules INPUTS : The class name RETURNS : The class (NULL if not found) SIDE EFFECTS : Error message printed on ambiguous references NOTES : Assumes no two classes of the same name are ever in the same scope ***************************************************/ globle DEFCLASS *LookupDefclassByMdlOrScope( void *theEnv, const char *classAndModuleName) { DEFCLASS *cls; const char *className; SYMBOL_HN *classSymbol; struct defmodule *theModule; if (FindModuleSeparator(classAndModuleName) == FALSE) return(LookupDefclassInScope(theEnv,classAndModuleName)); SaveCurrentModule(theEnv); className = ExtractModuleAndConstructName(theEnv,classAndModuleName); theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv)); RestoreCurrentModule(theEnv); if(className == NULL) return(NULL); if ((classSymbol = FindSymbolHN(theEnv,className)) == NULL) return(NULL); cls = DefclassData(theEnv)->ClassTable[HashClass(classSymbol)]; while (cls != NULL) { if ((cls->header.name == classSymbol) && (cls->header.whichModule->theModule == theModule)) return(cls->installed ? cls : NULL); cls = cls->nxtHash; } return(NULL); }
/******************************************************* NAME : PutClassInTable DESCRIPTION : Inserts a class in the class hash table INPUTS : The class RETURNS : Nothing useful SIDE EFFECTS : Class inserted NOTES : None *******************************************************/ globle void PutClassInTable( DEFCLASS *cls) { cls->hashTableIndex = HashClass(GetDefclassNamePointer((void *) cls)); cls->nxtHash = ClassTable[cls->hashTableIndex]; ClassTable[cls->hashTableIndex] = cls; }
/******************************************************* NAME : PutClassInTable DESCRIPTION : Inserts a class in the class hash table INPUTS : The class RETURNS : Nothing useful SIDE EFFECTS : Class inserted NOTES : None *******************************************************/ globle void PutClassInTable( void *theEnv, DEFCLASS *cls) { cls->hashTableIndex = HashClass(GetDefclassNamePointer((void *) cls)); cls->nxtHash = DefclassData(theEnv)->ClassTable[cls->hashTableIndex]; DefclassData(theEnv)->ClassTable[cls->hashTableIndex] = cls; }
/**************************************************** NAME : LookupDefclassInScope DESCRIPTION : Finds a class in current or imported modules (module specifier is not allowed) INPUTS : The class name RETURNS : The class (NULL if not found) SIDE EFFECTS : Error message printed on ambiguous references NOTES : Assumes no two classes of the same name are ever in the same scope ****************************************************/ globle DEFCLASS *LookupDefclassInScope( void *theEnv, const char *className) { DEFCLASS *cls; SYMBOL_HN *classSymbol; if ((classSymbol = FindSymbolHN(theEnv,className)) == NULL) return(NULL); cls = DefclassData(theEnv)->ClassTable[HashClass(classSymbol)]; while (cls != NULL) { if ((cls->header.name == classSymbol) && DefclassInScope(theEnv,cls,NULL)) return(cls->installed ? cls : NULL); cls = cls->nxtHash; } return(NULL); }
/********************************************************* 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( void *theEnv, char *name, DEFCLASS *parent) { DEFCLASS *sys; long i; char defaultScopeMap[1]; sys = NewClass(theEnv,(SYMBOL_HN *) EnvAddSymbol(theEnv,name)); sys->abstract = 1; #if DEFRULE_CONSTRUCT sys->reactive = 0; #endif IncrementSymbolCount(sys->header.name); sys->installed = 1; sys->system = 1; sys->hashTableIndex = HashClass(sys->header.name); AddClassLink(theEnv,&sys->allSuperclasses,sys,-1); if (parent != NULL) { AddClassLink(theEnv,&sys->directSuperclasses,parent,-1); AddClassLink(theEnv,&parent->directSubclasses,sys,-1); AddClassLink(theEnv,&sys->allSuperclasses,parent,-1); for (i = 1 ; i < parent->allSuperclasses.classCount ; i++) AddClassLink(theEnv,&sys->allSuperclasses,parent->allSuperclasses.classArray[i],-1); } sys->nxtHash = DefclassData(theEnv)->ClassTable[sys->hashTableIndex]; DefclassData(theEnv)->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 *) EnvAddBitMap(theEnv,(void *) defaultScopeMap,(int) sizeof(char)); IncrementBitMapCount(sys->scopeMap); #endif return(sys); }
/****************************************************** NAME : LookupDefclassAnywhere DESCRIPTION : Finds a class in specified (or any) module INPUTS : 1) The module (NULL if don't care) 2) The class name (module specifier in name not allowed) RETURNS : The class (NULL if not found) SIDE EFFECTS : None NOTES : Does *not* generate an error if multiple classes of the same name exist as do the other lookup functions ******************************************************/ globle DEFCLASS *LookupDefclassAnywhere( void *theEnv, struct defmodule *theModule, const char *className) { DEFCLASS *cls; SYMBOL_HN *classSymbol; if ((classSymbol = FindSymbolHN(theEnv,className)) == NULL) return(NULL); cls = DefclassData(theEnv)->ClassTable[HashClass(classSymbol)]; while (cls != NULL) { if ((cls->header.name == classSymbol) && ((theModule == NULL) || (cls->header.whichModule->theModule == theModule))) return(cls->installed ? cls : NULL); cls = cls->nxtHash; } return(NULL); }
/***************************************************************************** NAME : AddClass DESCRIPTION : Determines the precedence list of the new class. If it is valid, the routine checks to see if the class already exists. If it does not, all the subclass links are made from the class's direct superclasses, and the class is inserted in the hash table. If it does, all sublclasses are deleted. An error will occur if any instances of the class (direct or indirect) exist. If all checks out, the old definition is replaced by the new. INPUTS : The new class description RETURNS : Nothing useful SIDE EFFECTS : The class is deleted if there is an error. NOTES : No change in the class graph state will occur if there were any errors. Assumes class is not busy!!! *****************************************************************************/ static void AddClass( void *theEnv, DEFCLASS *cls) { DEFCLASS *ctmp; #if DEBUGGING_FUNCTIONS int oldTraceInstances = FALSE, oldTraceSlots = FALSE; #endif /* =============================================== If class does not already exist, insert and form progeny links with all direct superclasses =============================================== */ cls->hashTableIndex = HashClass(GetDefclassNamePointer((void *) cls)); ctmp = (DEFCLASS *) EnvFindDefclass(theEnv,EnvGetDefclassName(theEnv,(void *) cls)); if (ctmp != NULL) { #if DEBUGGING_FUNCTIONS oldTraceInstances = ctmp->traceInstances; oldTraceSlots = ctmp->traceSlots; #endif DeleteClassUAG(theEnv,ctmp); } PutClassInTable(theEnv,cls); BuildSubclassLinks(theEnv,cls); InstallClass(theEnv,cls,TRUE); AddConstructToModule((struct constructHeader *) cls); FormInstanceTemplate(theEnv,cls); FormSlotNameMap(theEnv,cls); AssignClassID(theEnv,cls); #if DEBUGGING_FUNCTIONS if (cls->abstract) { cls->traceInstances = FALSE; cls->traceSlots = FALSE; } else { if (oldTraceInstances) cls->traceInstances = TRUE; if (oldTraceSlots) cls->traceSlots = TRUE; } #endif #if DEBUGGING_FUNCTIONS if (EnvGetConserveMemory(theEnv) == FALSE) SetDefclassPPForm((void *) cls,CopyPPBuffer(theEnv)); #endif #if DEFMODULE_CONSTRUCT /* ========================================= Create a bitmap indicating whether this class is in scope or not for every module ========================================= */ cls->scopeMap = (BITMAP_HN *) CreateClassScopeMap(theEnv,cls); #endif /* ============================================== Define get- and put- handlers for public slots ============================================== */ CreatePublicSlotMessageHandlers(theEnv,cls); }