?? classini.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.24 06/02/06 */ /* */ /* CLASS INITIALIZATION MODULE */ /*******************************************************//**************************************************************//* Purpose: Defclass Initialization Routines *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* 6.23: Corrected compilation errors for files *//* generated by constructs-to-c. DR0861 *//* *//* 6.24: Added allowed-classes slot facet. *//* *//* Converted INSTANCE_PATTERN_MATCHING to *//* DEFRULE_CONSTRUCT. *//* *//* Corrected code to remove run-time program *//* compiler warning. *//* *//**************************************************************//* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if OBJECT_SYSTEM#ifndef _STDIO_INCLUDED_#define _STDIO_INCLUDED_#include <stdio.h>#endif#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"#endif#include "classini.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** */#define SUPERCLASS_RLN "is-a"#define NAME_RLN "name"#define INITIAL_OBJECT_NAME "initial-object"/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */static void SetupDefclasses(void *);static void DeallocateDefclassData(void *);#if (! RUN_TIME)static void DestroyDefclassAction(void *,struct constructHeader *,void *);static DEFCLASS *AddSystemClass(void *,char *,DEFCLASS *);static void *AllocateModule(void *);static void ReturnModule(void *,void *);#elsestatic void SearchForHashedPatternNodes(void *,OBJECT_PATTERN_NODE *);#endif#if (! BLOAD_ONLY) && (! RUN_TIME) && DEFMODULE_CONSTRUCTstatic void UpdateDefclassesScope(void *);#endif/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//********************************************************** NAME : SetupObjectSystem DESCRIPTION : Initializes all COOL constructs, functions, and data structures INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : COOL initialized NOTES : Order of setup calls is important **********************************************************/globle void SetupObjectSystem( void *theEnv) { ENTITY_RECORD defclassEntityRecord = { "DEFCLASS_PTR", DEFCLASS_PTR,1,0,0, NULL,NULL,NULL,NULL,NULL, DecrementDefclassBusyCount, 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)); #if ! RUN_TIME DefclassData(theEnv)->ClassDefaultsMode = CONVENIENCE_MODE; DefclassData(theEnv)->ISA_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,SUPERCLASS_RLN); IncrementSymbolCount(DefclassData(theEnv)->ISA_SYMBOL); DefclassData(theEnv)->NAME_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,NAME_RLN); IncrementSymbolCount(DefclassData(theEnv)->NAME_SYMBOL);#if DEFRULE_CONSTRUCT DefclassData(theEnv)->INITIAL_OBJECT_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,INITIAL_OBJECT_NAME); IncrementSymbolCount(DefclassData(theEnv)->INITIAL_OBJECT_SYMBOL);#endif#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 } /***************************************************//* DeallocateDefclassData: Deallocates environment *//* data for the defclass construct. *//***************************************************/static void DeallocateDefclassData( void *theEnv) {#if ! RUN_TIME SLOT_NAME *tmpSNPPtr, *nextSNPPtr; int i; struct defclassModule *theModuleItem; void *theModule; int bloaded = FALSE; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) bloaded = TRUE;#endif /*=============================*/ /* Destroy all the defclasses. */ /*=============================*/ if (! bloaded) { DoForAllConstructs(theEnv,DestroyDefclassAction,DefclassData(theEnv)->DefclassModuleIndex,FALSE,NULL); for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { theModuleItem = (struct defclassModule *) GetModuleItem(theEnv,(struct defmodule *) theModule, DefclassData(theEnv)->DefclassModuleIndex); rtn_struct(theEnv,defclassModule,theModuleItem); } } /*==========================*/ /* Remove the class tables. */ /*==========================*/ 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); } /*==============================*/ /* Free up the slot name table. */ /*==============================*/ 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; register unsigned int i; register int j; if (DefclassData(theEnv)->ClassTable != NULL) { for (j = 0 ; j < CLASS_TABLE_HASH_SIZE ; j++)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -