1 /*******************************************************/ 2 /* "C" Language Integrated Production System */ 3 /* */ 4 /* CLIPS Version 6.30 08/22/14 */ 5 /* */ 6 /* DEFMODULE HEADER FILE */ 7 /*******************************************************/ 8 9 /*************************************************************/ 10 /* Purpose: Defines basic defmodule primitive functions such */ 11 /* as allocating and deallocating, traversing, and finding */ 12 /* defmodule data structures. */ 13 /* */ 14 /* Principal Programmer(s): */ 15 /* Gary D. Riley */ 16 /* */ 17 /* Contributing Programmer(s): */ 18 /* Brian L. Dantes */ 19 /* */ 20 /* Revision History: */ 21 /* */ 22 /* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 */ 23 /* */ 24 /* Corrected compilation errors for files */ 25 /* generated by constructs-to-c. DR0861 */ 26 /* */ 27 /* 6.24: Renamed BOOLEAN macro type to intBool. */ 28 /* */ 29 /* 6.30: Changed integer type/precision. */ 30 /* */ 31 /* Removed conditional code for unsupported */ 32 /* compilers/operating systems (IBM_MCW, */ 33 /* MAC_MCW, and IBM_TBC). */ 34 /* */ 35 /* Added const qualifiers to remove C++ */ 36 /* deprecation warnings. */ 37 /* */ 38 /* Converted API macros to function calls. */ 39 /* */ 40 /*************************************************************/ 41 42 #ifndef _H_moduldef 43 #define _H_moduldef 44 45 struct defmodule; 46 struct portItem; 47 struct defmoduleItemHeader; 48 struct moduleItem; 49 50 #ifndef _STDIO_INCLUDED_ 51 #include <stdio.h> 52 #define _STDIO_INCLUDED_ 53 #endif 54 55 #ifndef _H_conscomp 56 #include "conscomp.h" 57 #endif 58 #ifndef _H_modulpsr 59 #include "modulpsr.h" 60 #endif 61 #ifndef _H_utility 62 #include "utility.h" 63 #endif 64 #ifndef _H_symbol 65 #include "symbol.h" 66 #endif 67 #ifndef _H_evaluatn 68 #include "evaluatn.h" 69 #endif 70 #ifndef _H_constrct 71 #include "constrct.h" 72 #endif 73 74 /**********************************************************************/ 75 /* defmodule */ 76 /* ---------- */ 77 /* name: The name of the defmodule (stored as a reference in the */ 78 /* table). */ 79 /* */ 80 /* ppForm: The pretty print representation of the defmodule (used by */ 81 /* the save and ppdefmodule commands). */ 82 /* */ 83 /* itemsArray: An array of pointers to the module specific data used */ 84 /* by each construct specified with the RegisterModuleItem */ 85 /* function. The data pointer stored in the array is allocated by */ 86 /* the allocateFunction in moduleItem data structure. */ 87 /* */ 88 /* importList: The list of items which are being imported by this */ 89 /* module from other modules. */ 90 /* */ 91 /* next: A pointer to the next defmodule data structure. */ 92 /**********************************************************************/ 93 struct defmodule 94 { 95 struct symbolHashNode *name; 96 char *ppForm; 97 struct defmoduleItemHeader **itemsArray; 98 struct portItem *importList; 99 struct portItem *exportList; 100 unsigned visitedFlag; 101 long bsaveID; 102 struct userData *usrData; 103 struct defmodule *next; 104 }; 105 106 struct portItem 107 { 108 struct symbolHashNode *moduleName; 109 struct symbolHashNode *constructType; 110 struct symbolHashNode *constructName; 111 struct portItem *next; 112 }; 113 114 struct defmoduleItemHeader 115 { 116 struct defmodule *theModule; 117 struct constructHeader *firstItem; 118 struct constructHeader *lastItem; 119 }; 120 121 #define MIHS (struct defmoduleItemHeader *) 122 123 /**********************************************************************/ 124 /* moduleItem */ 125 /* ---------- */ 126 /* name: The name of the construct which can be placed in a module. */ 127 /* For example, "defrule". */ 128 /* */ 129 /* allocateFunction: Used to allocate a data structure containing all */ 130 /* pertinent information related to a specific construct for a */ 131 /* given module. For example, the deffacts construct stores a */ 132 /* pointer to the first and last deffacts for each each module. */ 133 /* */ 134 /* freeFunction: Used to deallocate a data structure allocated by */ 135 /* the allocateFunction. In addition, the freeFunction deletes */ 136 /* all constructs of the specified type in the given module. */ 137 /* */ 138 /* bloadModuleReference: Used during a binary load to establish a */ 139 /* link between the defmodule data structure and the data structure */ 140 /* containing all pertinent module information for a specific */ 141 /* construct. */ 142 /* */ 143 /* findFunction: Used to determine if a specified construct is in a */ 144 /* specific module. The name is the specific construct is passed as */ 145 /* a string and the function returns a pointer to the specified */ 146 /* construct if it exists. */ 147 /* */ 148 /* exportable: If TRUE, then the specified construct type can be */ 149 /* exported (and hence imported). If FALSE, it can't be exported. */ 150 /* */ 151 /* next: A pointer to the next moduleItem data structure. */ 152 /**********************************************************************/ 153 154 struct moduleItem 155 { 156 const char *name; 157 int moduleIndex; 158 void *(*allocateFunction)(void *); 159 void (*freeFunction)(void *,void *); 160 void *(*bloadModuleReference)(void *,int); 161 void (*constructsToCModuleReference)(void *,FILE *,int,int,int); 162 void *(*findFunction)(void *,const char *); 163 struct moduleItem *next; 164 }; 165 166 typedef struct moduleStackItem 167 { 168 intBool changeFlag; 169 struct defmodule *theModule; 170 struct moduleStackItem *next; 171 } MODULE_STACK_ITEM; 172 173 #define DEFMODULE_DATA 4 174 175 struct defmoduleData 176 { 177 struct moduleItem *LastModuleItem; 178 struct callFunctionItem *AfterModuleChangeFunctions; 179 MODULE_STACK_ITEM *ModuleStack; 180 intBool CallModuleChangeFunctions; 181 struct defmodule *ListOfDefmodules; 182 struct defmodule *CurrentModule; 183 struct defmodule *LastDefmodule; 184 int NumberOfModuleItems; 185 struct moduleItem *ListOfModuleItems; 186 long ModuleChangeIndex; 187 int MainModuleRedefinable; 188 #if (! RUN_TIME) && (! BLOAD_ONLY) 189 struct portConstructItem *ListOfPortConstructItems; 190 long NumberOfDefmodules; 191 struct callFunctionItem *AfterModuleDefinedFunctions; 192 #endif 193 #if CONSTRUCT_COMPILER && (! RUN_TIME) 194 struct CodeGeneratorItem *DefmoduleCodeItem; 195 #endif 196 #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) 197 long BNumberOfDefmodules; 198 long NumberOfPortItems; 199 struct portItem *PortItemArray; 200 struct defmodule *DefmoduleArray; 201 #endif 202 }; 203 204 #define DefmoduleData(theEnv) ((struct defmoduleData *) GetEnvironmentData(theEnv,DEFMODULE_DATA)) 205 206 #ifdef LOCALE 207 #undef LOCALE 208 #endif 209 210 #ifdef _MODULDEF_SOURCE_ 211 #define LOCALE 212 #else 213 #define LOCALE extern 214 #endif 215 216 LOCALE void InitializeDefmodules(void *); 217 LOCALE void *EnvFindDefmodule(void *,const char *); 218 LOCALE const char *EnvGetDefmoduleName(void *,void *); 219 LOCALE const char *EnvGetDefmodulePPForm(void *,void *); 220 LOCALE void *EnvGetNextDefmodule(void *,void *); 221 LOCALE void RemoveAllDefmodules(void *); 222 LOCALE int AllocateModuleStorage(void); 223 LOCALE int RegisterModuleItem(void *,const char *, 224 void *(*)(void *), 225 void (*)(void *,void *), 226 void *(*)(void *,int), 227 void (*)(void *,FILE *,int,int,int), 228 void *(*)(void *,const char *)); 229 LOCALE void *GetModuleItem(void *,struct defmodule *,int); 230 LOCALE void SetModuleItem(void *,struct defmodule *,int,void *); 231 LOCALE void *EnvGetCurrentModule(void *); 232 LOCALE void *EnvSetCurrentModule(void *,void *); 233 LOCALE void *GetCurrentModuleCommand(void *); 234 LOCALE void *SetCurrentModuleCommand(void *); 235 LOCALE int GetNumberOfModuleItems(void *); 236 LOCALE void CreateMainModule(void *); 237 LOCALE void SetListOfDefmodules(void *,void *); 238 LOCALE struct moduleItem *GetListOfModuleItems(void *); 239 LOCALE struct moduleItem *FindModuleItem(void *,const char *); 240 LOCALE void SaveCurrentModule(void *); 241 LOCALE void RestoreCurrentModule(void *); 242 LOCALE void AddAfterModuleChangeFunction(void *,const char *,void (*)(void *),int); 243 LOCALE void IllegalModuleSpecifierMessage(void *); 244 LOCALE void AllocateDefmoduleGlobals(void *); 245 246 #if ALLOW_ENVIRONMENT_GLOBALS 247 248 LOCALE void *FindDefmodule(const char *); 249 LOCALE void *GetCurrentModule(void); 250 LOCALE const char *GetDefmoduleName(void *); 251 LOCALE const char *GetDefmodulePPForm(void *); 252 LOCALE void *GetNextDefmodule(void *); 253 LOCALE void *SetCurrentModule(void *); 254 255 #endif /* ALLOW_ENVIRONMENT_GLOBALS */ 256 257 #endif /* _H_moduldef */ 258 259 260