📄 classcom.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* CLASS COMMANDS MODULE */ /*******************************************************//**************************************************************//* Purpose: CLIPS Kernel Interface Commands for Object System *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//**************************************************************/ /* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if OBJECT_SYSTEM#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE#include "bload.h"#endif#include "argacces.h"#include "classfun.h"#include "classini.h"#include "modulutl.h"#include "msgcom.h"#include "router.h"#define _CLASSCOM_SOURCE_#include "classcom.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** *//* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if ANSI_COMPILER#if (! BLOAD_ONLY) && (! RUN_TIME) && DEBUGGING_FUNCTIONSstatic VOID SaveDefclass(struct constructHeader *,VOID *);#endif#else#if (! BLOAD_ONLY) && (! RUN_TIME) && DEBUGGING_FUNCTIONSstatic VOID SaveDefclass();#endif#endif/* ========================================= ***************************************** INTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** *//* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */ /******************************************************************* NAME : FindDefclass 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 *FindDefclass(classAndModuleName) char *classAndModuleName; { SYMBOL_HN *classSymbol; DEFCLASS *cls; struct defmodule *theModule; SaveCurrentModule(); classSymbol = FindSymbol(ExtractModuleAndConstructName(classAndModuleName)); theModule = ((struct defmodule *) GetCurrentModule()); RestoreCurrentModule(); if (classSymbol == NULL) return(NULL); cls = 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(classAndModuleName) char *classAndModuleName; { DEFCLASS *cls; char *className; SYMBOL_HN *classSymbol; struct defmodule *theModule; if (FindModuleSeparator(classAndModuleName) == CLIPS_FALSE) return(LookupDefclassInScope(classAndModuleName)); SaveCurrentModule(); className = ExtractModuleAndConstructName(classAndModuleName); theModule = ((struct defmodule *) GetCurrentModule()); RestoreCurrentModule(); if(className == NULL) return(NULL); if ((classSymbol = FindSymbol(className)) == NULL) return(NULL); cls = 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 : 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(className) char *className; { DEFCLASS *cls; SYMBOL_HN *classSymbol; if ((classSymbol = FindSymbol(className)) == NULL) return(NULL); cls = ClassTable[HashClass(classSymbol)]; while (cls != NULL) { if ((cls->header.name == classSymbol) && DefclassInScope(cls,NULL)) return(cls->installed ? cls : NULL); cls = cls->nxtHash; } return(NULL); } /****************************************************** 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(theModule,className) struct defmodule *theModule; char *className; { DEFCLASS *cls; SYMBOL_HN *classSymbol; if ((classSymbol = FindSymbol(className)) == NULL) return(NULL); cls = 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 : DefclassInScope DESCRIPTION : Determines if a defclass is in scope of the given module INPUTS : 1) The defclass 2) The module (NULL for current module) RETURNS : CLIPS_TRUE if in scope, CLIPS_FALSE otherwise SIDE EFFECTS : None NOTES : None ***************************************************/globle BOOLEAN DefclassInScope(theDefclass,theModule) DEFCLASS *theDefclass; struct defmodule *theModule; {#if DEFMODULE_CONSTRUCT int moduleID; char *scopeMap; scopeMap = (char *) ValueToBitMap(theDefclass->scopeMap); if (theModule == NULL) theModule = ((struct defmodule *) GetCurrentModule()); moduleID = (int) theModule->bsaveID; return(TestBitMap(scopeMap,moduleID) ? CLIPS_TRUE : CLIPS_FALSE);#else return(CLIPS_TRUE);#endif } /*********************************************************** NAME : GetNextDefclass DESCRIPTION : Finds first or next defclass INPUTS : The address of the current defclass RETURNS : The address of the next defclass (NULL if none) SIDE EFFECTS : None NOTES : If ptr == NULL, the first defclass is returned. ***********************************************************/globle VOID *GetNextDefclass(ptr) VOID *ptr; { return((VOID *) GetNextConstructItem((struct constructHeader *) ptr,DefclassModuleIndex)); } /*************************************************** NAME : IsDefclassDeletable DESCRIPTION : Determines if a defclass can be deleted INPUTS : Address of the defclass RETURNS : CLIPS_TRUE if deletable, CLIPS_FALSE otherwise SIDE EFFECTS : None NOTES : None ***************************************************/globle BOOLEAN IsDefclassDeletable(ptr) VOID *ptr; {#if (MAC_MPW || MAC_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(ptr)#endif#if BLOAD_ONLY || RUN_TIME return(CLIPS_FALSE);#else DEFCLASS *cls; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded()) return(CLIPS_FALSE);#endif cls = (DEFCLASS *) ptr; if (cls->system == 1) return(CLIPS_FALSE); return((IsClassBeingUsed(cls) == CLIPS_FALSE) ? CLIPS_TRUE : CLIPS_FALSE);#endif }/************************************************************* NAME : UndefclassCommand DESCRIPTION : Deletes a class and its subclasses, as well as their associated instances INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : None NOTES : Syntax : CLIPS> (undefclass <class-name> | *) *************************************************************/globle VOID UndefclassCommand() { UndefconstructCommand("undefclass",DefclassConstruct); } /******************************************************** NAME : Undefclass DESCRIPTION : Deletes the named defclass INPUTS : None RETURNS : CLIPS_TRUE if deleted, or CLIPS_FALSE SIDE EFFECTS : Defclass and handlers removed NOTES : Interface for AddConstruct() ********************************************************/globle BOOLEAN Undefclass(theDefclass) VOID *theDefclass; {#if (MAC_MPW || MAC_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(theDefclass)#endif#if RUN_TIME || BLOAD_ONLY return(CLIPS_FALSE);#else DEFCLASS *cls; cls = (DEFCLASS *) theDefclass;#if BLOAD || BLOAD_AND_BSAVE if (Bloaded()) return(CLIPS_FALSE);#endif if (cls == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -