1    /*******************************************************/
2    /*      "C" Language Integrated Production System      */
3    /*                                                     */
4    /*             CLIPS Version 6.30  01/25/15            */
5    /*                                                     */
6    /*                  CONSTRUCT MODULE                   */
7    /*******************************************************/
8 
9 /*************************************************************/
10 /* Purpose:                                                  */
11 /*                                                           */
12 /* Principal Programmer(s):                                  */
13 /*      Gary D. Riley                                        */
14 /*                                                           */
15 /* Contributing Programmer(s):                               */
16 /*                                                           */
17 /* Revision History:                                         */
18 /*                                                           */
19 /*      6.24: Added environment parameter to GenClose.       */
20 /*            Added environment parameter to GenOpen.        */
21 /*                                                           */
22 /*            Renamed BOOLEAN macro type to intBool.         */
23 /*                                                           */
24 /*      6.30: Changed garbage collection algorithm.          */
25 /*                                                           */
26 /*            Removed conditional code for unsupported       */
27 /*            compilers/operating systems (IBM_MCW and       */
28 /*            MAC_MCW).                                      */
29 /*                                                           */
30 /*            Added code for capturing errors/warnings       */
31 /*            (EnvSetParserErrorCallback).                   */
32 /*                                                           */
33 /*            Fixed issue with save function when multiple   */
34 /*            defmodules exist.                              */
35 /*                                                           */
36 /*            Added const qualifiers to remove C++           */
37 /*            deprecation warnings.                          */
38 /*                                                           */
39 /*            Converted API macros to function calls.        */
40 /*                                                           */
41 /*            Fixed linkage issue when BLOAD_ONLY compiler   */
42 /*            flag is set to 1.                              */
43 /*                                                           */
44 /*            Added code to prevent a clear command from     */
45 /*            being executed during fact assertions via      */
46 /*            Increment/DecrementClearReadyLocks API.        */
47 /*                                                           */
48 /*            Added code to keep track of pointers to        */
49 /*            constructs that are contained externally to    */
50 /*            to constructs, DanglingConstructs.             */
51 /*                                                           */
52 /*************************************************************/
53 
54 #ifndef _H_constrct
55 
56 #define _H_constrct
57 
58 struct constructHeader;
59 struct construct;
60 
61 #ifndef _H_moduldef
62 #include "moduldef.h"
63 #endif
64 #ifndef _H_symbol
65 #include "symbol.h"
66 #endif
67 
68 #include "userdata.h"
69 
70 struct constructHeader
71   {
72    struct symbolHashNode *name;
73    const char *ppForm;
74    struct defmoduleItemHeader *whichModule;
75    long bsaveID;
76    struct constructHeader *next;
77    struct userData *usrData;
78   };
79 
80 #define CHS (struct constructHeader *)
81 
82 struct construct
83   {
84    const char *constructName;
85    const char *pluralName;
86    int (*parseFunction)(void *,const char *);
87    void *(*findFunction)(void *,const char *);
88    struct symbolHashNode *(*getConstructNameFunction)(struct constructHeader *);
89    const char *(*getPPFormFunction)(void *,struct constructHeader *);
90    struct defmoduleItemHeader *(*getModuleItemFunction)(struct constructHeader *);
91    void *(*getNextItemFunction)(void *,void *);
92    void (*setNextItemFunction)(struct constructHeader *,struct constructHeader *);
93    intBool (*isConstructDeletableFunction)(void *,void *);
94    int (*deleteFunction)(void *,void *);
95    void (*freeFunction)(void *,void *);
96    struct construct *next;
97   };
98 
99 #ifndef _H_evaluatn
100 #include "evaluatn.h"
101 #endif
102 #ifndef _H_scanner
103 #include "scanner.h"
104 #endif
105 
106 #define CONSTRUCT_DATA 42
107 
108 struct constructData
109   {
110    int ClearReadyInProgress;
111    int ClearInProgress;
112    int ResetReadyInProgress;
113    int ResetInProgress;
114    short ClearReadyLocks;
115    int DanglingConstructs;
116 #if (! RUN_TIME) && (! BLOAD_ONLY)
117    struct callFunctionItem *ListOfSaveFunctions;
118    intBool PrintWhileLoading;
119    unsigned WatchCompilations;
120    int CheckSyntaxMode;
121    int ParsingConstruct;
122    char *ErrorString;
123    char *WarningString;
124    char *ParsingFileName;
125    char *ErrorFileName;
126    char *WarningFileName;
127    long ErrLineNumber;
128    long WrnLineNumber;
129    int errorCaptureRouterCount;
130    size_t MaxErrChars;
131    size_t CurErrPos;
132    size_t MaxWrnChars;
133    size_t CurWrnPos;
134    void (*ParserErrorCallback)(void *,const char *,const char *,const char *,long);
135 #endif
136    struct construct *ListOfConstructs;
137    struct callFunctionItem *ListOfResetFunctions;
138    struct callFunctionItem *ListOfClearFunctions;
139    struct callFunctionItem *ListOfClearReadyFunctions;
140    int Executing;
141    int (*BeforeResetFunction)(void *);
142   };
143 
144 #define ConstructData(theEnv) ((struct constructData *) GetEnvironmentData(theEnv,CONSTRUCT_DATA))
145 
146 #ifdef LOCALE
147 #undef LOCALE
148 #endif
149 
150 #ifdef _CONSTRCT_SOURCE_
151 #define LOCALE
152 #else
153 #define LOCALE extern
154 #endif
155 
156    LOCALE void                           EnvClear(void *);
157    LOCALE void                           EnvReset(void *);
158    LOCALE int                            EnvSave(void *,const char *);
159 
160    LOCALE void                           InitializeConstructData(void *);
161    LOCALE intBool                        AddSaveFunction(void *,const char *,void (*)(void *,void *,const char *),int);
162    LOCALE intBool                        RemoveSaveFunction(void *,const char *);
163    LOCALE intBool                        EnvAddResetFunction(void *,const char *,void (*)(void *),int);
164    LOCALE intBool                        EnvRemoveResetFunction(void *,const char *);
165    LOCALE intBool                        AddClearReadyFunction(void *,const char *,int (*)(void *),int);
166    LOCALE intBool                        RemoveClearReadyFunction(void *,const char *);
167    LOCALE intBool                        EnvAddClearFunction(void *,const char *,void (*)(void *),int);
168    LOCALE intBool                        EnvRemoveClearFunction(void *,const char *);
169    LOCALE void                           EnvIncrementClearReadyLocks(void *);
170    LOCALE void                           EnvDecrementClearReadyLocks(void *);
171    LOCALE struct construct              *AddConstruct(void *,const char *,const char *,
172                                                       int (*)(void *,const char *),
173                                                       void *(*)(void *,const char *),
174                                                       SYMBOL_HN *(*)(struct constructHeader *),
175                                                       const char *(*)(void *,struct constructHeader *),
176                                                       struct defmoduleItemHeader *(*)(struct constructHeader *),
177                                                       void *(*)(void *,void *),
178                                                       void (*)(struct constructHeader *,struct constructHeader *),
179                                                       intBool (*)(void *,void *),
180                                                       int (*)(void *,void *),
181                                                       void (*)(void *,void *));
182    LOCALE int                            RemoveConstruct(void *,const char *);
183    LOCALE void                           SetCompilationsWatch(void *,unsigned);
184    LOCALE unsigned                       GetCompilationsWatch(void *);
185    LOCALE void                           SetPrintWhileLoading(void *,intBool);
186    LOCALE intBool                        GetPrintWhileLoading(void *);
187    LOCALE int                            ExecutingConstruct(void *);
188    LOCALE void                           SetExecutingConstruct(void *,int);
189    LOCALE void                           InitializeConstructs(void *);
190    LOCALE int                          (*SetBeforeResetFunction(void *,int (*)(void *)))(void *);
191    LOCALE void                           ResetCommand(void *);
192    LOCALE void                           ClearCommand(void *);
193    LOCALE intBool                        ClearReady(void *);
194    LOCALE struct construct              *FindConstruct(void *,const char *);
195    LOCALE void                           DeinstallConstructHeader(void *,struct constructHeader *);
196    LOCALE void                           DestroyConstructHeader(void *,struct constructHeader *);
197    LOCALE void                         (*EnvSetParserErrorCallback(void *theEnv,
198                                                                    void (*functionPtr)(void *,const char *,const char *,
199                                                                                        const char *,long)))
200                                             (void *,const char *,const char *,const char*,long);
201 
202 
203 #if ALLOW_ENVIRONMENT_GLOBALS
204 
205    LOCALE intBool                        AddClearFunction(const char *,void (*)(void),int);
206    LOCALE intBool                        AddResetFunction(const char *,void (*)(void),int);
207    LOCALE void                           Clear(void);
208    LOCALE void                           Reset(void);
209    LOCALE intBool                        RemoveClearFunction(const char *);
210    LOCALE intBool                        RemoveResetFunction(const char *);
211 #if (! RUN_TIME) && (! BLOAD_ONLY)
212    LOCALE int                            Save(const char *);
213 #endif
214 
215 #endif /* ALLOW_ENVIRONMENT_GLOBALS */
216 
217 #endif /* _H_constrct */
218 
219 
220 
221 
222