1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * Main header file for SWIG modules.
8 * ----------------------------------------------------------------------------- */
10 /* $Id: swigmod.h 11470 2009-07-29 20:50:39Z wsfulton $ */
12 #ifndef SWIG_SWIGMOD_H_
13 #define SWIG_SWIGMOD_H_
16 #include "preprocessor.h"
19 #if !defined(HAVE_BOOL)
21 #define true ((bool)1)
22 #define false ((bool)0)
26 #define PLAIN_VIRTUAL 1
27 #define PURE_VIRTUAL 2
29 extern String *input_file;
30 extern int line_number;
31 extern int start_line;
32 extern int CPlusPlus; // C++ mode
33 extern int Extend; // Extend mode
36 extern int ImportMode;
37 extern int NoExcept; // -no_except option
38 extern int Abstract; // abstract base class
39 extern int SmartPointer; // smart pointer methods being emitted
40 extern int SwigRuntime;
42 /* Overload "argc" and "argv" */
43 extern String *argv_template_string;
44 extern String *argc_template_string;
46 /* Miscellaneous stuff */
55 Dispatcher ():cplus_mode(PUBLIC) {
57 virtual ~ Dispatcher () {
60 virtual int emit_one(Node *n);
61 virtual int emit_children(Node *n);
62 virtual int defaultHandler(Node *n);
64 /* Top of the parse tree */
65 virtual int top(Node *n) = 0;
69 virtual int applyDirective(Node *n);
70 virtual int clearDirective(Node *n);
71 virtual int constantDirective(Node *n);
72 virtual int extendDirective(Node *n);
73 virtual int fragmentDirective(Node *n);
74 virtual int importDirective(Node *n);
75 virtual int includeDirective(Node *n);
76 virtual int insertDirective(Node *n);
77 virtual int moduleDirective(Node *n);
78 virtual int nativeDirective(Node *n);
79 virtual int pragmaDirective(Node *n);
80 virtual int typemapDirective(Node *n);
81 virtual int typemapitemDirective(Node *n);
82 virtual int typemapcopyDirective(Node *n);
83 virtual int typesDirective(Node *n);
87 virtual int cDeclaration(Node *n);
88 virtual int externDeclaration(Node *n);
89 virtual int enumDeclaration(Node *n);
90 virtual int enumvalueDeclaration(Node *n);
91 virtual int enumforwardDeclaration(Node *n);
92 virtual int classDeclaration(Node *n);
93 virtual int classforwardDeclaration(Node *n);
94 virtual int constructorDeclaration(Node *n);
95 virtual int destructorDeclaration(Node *n);
96 virtual int accessDeclaration(Node *n);
97 virtual int usingDeclaration(Node *n);
98 virtual int namespaceDeclaration(Node *n);
99 virtual int templateDeclaration(Node *n);
101 enum AccessMode { PUBLIC, PRIVATE, PROTECTED };
104 AccessMode cplus_mode;
107 /* ----------------------------------------------------------------------------
110 * This class defines the functions that need to be supported by the
111 * scripting language being used. The translator calls these virtual
112 * functions to output different types of code for different languages.
113 * ------------------------------------------------------------------------- */
115 class Language:public Dispatcher {
119 virtual int emit_one(Node *n);
121 /* Parse command line options */
123 virtual void main(int argc, char *argv[]);
125 /* Top of the parse tree */
127 virtual int top(Node *n);
129 /* SWIG directives */
132 virtual int applyDirective(Node *n);
133 virtual int clearDirective(Node *n);
134 virtual int constantDirective(Node *n);
135 virtual int extendDirective(Node *n);
136 virtual int fragmentDirective(Node *n);
137 virtual int importDirective(Node *n);
138 virtual int includeDirective(Node *n);
139 virtual int insertDirective(Node *n);
140 virtual int moduleDirective(Node *n);
141 virtual int nativeDirective(Node *n);
142 virtual int pragmaDirective(Node *n);
143 virtual int typemapDirective(Node *n);
144 virtual int typemapcopyDirective(Node *n);
145 virtual int typesDirective(Node *n);
149 virtual int cDeclaration(Node *n);
150 virtual int externDeclaration(Node *n);
151 virtual int enumDeclaration(Node *n);
152 virtual int enumvalueDeclaration(Node *n);
153 virtual int enumforwardDeclaration(Node *n);
154 virtual int classDeclaration(Node *n);
155 virtual int classforwardDeclaration(Node *n);
156 virtual int constructorDeclaration(Node *n);
157 virtual int destructorDeclaration(Node *n);
158 virtual int accessDeclaration(Node *n);
159 virtual int namespaceDeclaration(Node *n);
160 virtual int usingDeclaration(Node *n);
162 /* Function handlers */
164 virtual int functionHandler(Node *n);
165 virtual int globalfunctionHandler(Node *n);
166 virtual int memberfunctionHandler(Node *n);
167 virtual int staticmemberfunctionHandler(Node *n);
168 virtual int callbackfunctionHandler(Node *n);
170 /* Variable handlers */
172 virtual int variableHandler(Node *n);
173 virtual int globalvariableHandler(Node *n);
174 virtual int membervariableHandler(Node *n);
175 virtual int staticmembervariableHandler(Node *n);
179 virtual int memberconstantHandler(Node *n);
180 virtual int constructorHandler(Node *n);
181 virtual int copyconstructorHandler(Node *n);
182 virtual int destructorHandler(Node *n);
183 virtual int classHandler(Node *n);
187 virtual int typedefHandler(Node *n);
189 /* Low-level code generation */
191 virtual int constantWrapper(Node *n);
192 virtual int variableWrapper(Node *n);
193 virtual int functionWrapper(Node *n);
194 virtual int nativeWrapper(Node *n);
196 /* C++ director class generation */
197 virtual int classDirector(Node *n);
198 virtual int classDirectorInit(Node *n);
199 virtual int classDirectorEnd(Node *n);
200 virtual int unrollVirtualMethods(Node *n, Node *parent, List *vm, int default_director, int &virtual_destructor, int protectedbase = 0);
201 virtual int classDirectorConstructor(Node *n);
202 virtual int classDirectorDefaultConstructor(Node *n);
203 virtual int classDirectorMethod(Node *n, Node *parent, String *super);
204 virtual int classDirectorConstructors(Node *n);
205 virtual int classDirectorDestructor(Node *n);
206 virtual int classDirectorMethods(Node *n);
207 virtual int classDirectorDisown(Node *n);
210 virtual int validIdentifier(String *s); /* valid identifier? */
211 virtual int addSymbol(const String *s, const Node *n); /* Add symbol */
212 virtual Node *symbolLookup(String *s); /* Symbol lookup */
213 virtual Node *classLookup(SwigType *s); /* Class lookup */
214 virtual Node *enumLookup(SwigType *s); /* Enum lookup */
215 virtual int abstractClassTest(Node *n); /* Is class really abstract? */
216 virtual int is_assignable(Node *n); /* Is variable assignable? */
217 virtual String *runtimeCode(); /* returns the language specific runtime code */
218 virtual String *defaultExternalRuntimeFilename(); /* the default filename for the external runtime */
219 virtual void replaceSpecialVariables(String *method, String *tm, Parm *parm); /* Language specific special variable substitutions for $typemap() */
221 /* Runtime is C++ based, so extern "C" header section */
222 void enable_cplus_runtime_mode();
224 /* Returns the cplus_runtime mode */
225 int cplus_runtime_mode();
227 /* Allow director related code generation */
228 void allow_directors(int val = 1);
230 /* Return true if directors are enabled */
231 int directorsEnabled() const;
233 /* Allow director protected members related code generation */
234 void allow_dirprot(int val = 1);
236 /* Allow all protected members code generation (for directors) */
237 void allow_allprotected(int val = 0);
239 /* Returns the dirprot mode */
240 int dirprot_mode() const;
242 /* Check if the non public constructor is needed (for directors) */
243 int need_nonpublic_ctor(Node *n);
245 /* Check if the non public member is needed (for directors) */
246 int need_nonpublic_member(Node *n);
248 /* Set none comparison string */
249 void setSubclassInstanceCheck(String *s);
251 /* Set overload variable templates argc and argv */
252 void setOverloadResolutionTemplates(String *argc, String *argv);
254 /* Language instance is a singleton - get instance */
255 static Language* instance();
258 /* Allow multiple-input typemaps */
259 void allow_multiple_input(int val = 1);
261 /* Allow overloaded functions */
262 void allow_overloading(int val = 1);
264 /* Wrapping class query */
265 int is_wrapping_class();
267 /* Return the node for the current class */
268 Node *getCurrentClass() const;
270 /* Return C++ mode */
271 int getCPlusMode() const;
273 /* Return the real name of the current class */
274 String *getClassName() const;
276 /* Return the classes hash */
277 Hash *getClassHash() const;
279 /* Return the current class prefix */
280 String *getClassPrefix() const;
282 /* Fully qualified type name to use */
283 String *getClassType() const;
285 /* Return true if the current method is part of a smart-pointer */
286 int is_smart_pointer() const;
288 /* Some language modules require additional wrappers for virtual methods not declared in sub-classes */
289 virtual bool extraDirectorProtectedCPPMethodsRequired() const;
291 /* Director subclass comparison test */
292 String *none_comparison;
294 /* Director constructor "template" code */
295 String *director_ctor_code;
297 /* Director 'protected' constructor "template" code */
298 String *director_prot_ctor_code;
300 /* Director allows multiple inheritance */
301 int director_multiple_inheritance;
303 /* Director language module */
304 int director_language;
314 static Language *this_;
317 int SWIG_main(int, char **, Language *);
318 void emit_parameter_variables(ParmList *l, Wrapper *f);
319 void emit_return_variable(Node *n, SwigType *rt, Wrapper *f);
320 void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */
321 void SWIG_config_file(const_String_or_char_ptr );
322 const String *SWIG_output_directory();
323 void SWIG_config_cppext(const char *ext);
325 /* get the list of generated files */
326 List *SWIG_output_files();
328 void SWIG_library_directory(const char *);
329 int emit_num_arguments(ParmList *);
330 int emit_num_required(ParmList *);
331 int emit_isvarargs(ParmList *);
332 void emit_attach_parmmaps(ParmList *, Wrapper *f);
333 void emit_mark_varargs(ParmList *l);
334 String *emit_action(Node *n);
335 int emit_action_code(Node *n, String *wrappercode, String *action);
336 void Swig_overload_check(Node *n);
337 String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *);
338 String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int *);
339 String *Swig_overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int *);
340 SwigType *cplus_value_type(SwigType *t);
342 /* directors.cxx start */
343 String *Swig_csuperclass_call(String *base, String *method, ParmList *l);
344 String *Swig_class_declaration(Node *n, String *name);
345 String *Swig_class_name(Node *n);
346 String *Swig_method_call(const_String_or_char_ptr name, ParmList *parms);
347 String *Swig_method_decl(SwigType *rtype, SwigType *decl, const_String_or_char_ptr id, List *args, int strip, int values);
348 String *Swig_director_declaration(Node *n);
349 void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f);
350 /* directors.cxx end */
353 void SWIG_typemap_lang(const char *);
354 typedef Language *(*ModuleFactory) (void);
357 void Swig_register_module(const char *name, ModuleFactory fac);
358 ModuleFactory Swig_find_module(const char *name);
362 int is_public(Node *n);
363 int is_private(Node *n);
364 int is_protected(Node *n);
365 int is_member_director(Node *parentnode, Node *member);
366 int is_member_director(Node *member);
367 int is_non_virtual_protected_access(Node *n); /* Check if the non-virtual protected members are required (for directors) */
368 int use_naturalvar_mode(Node *n);
370 void Wrapper_virtual_elimination_mode_set(int);
371 void Wrapper_fast_dispatch_mode_set(int);
372 void Wrapper_cast_dispatch_mode_set(int);
373 void Wrapper_naturalvar_mode_set(int);
376 void clean_overloaded(Node *n);
380 void Swig_contracts(Node *n);
381 void Swig_contract_mode_set(int flag);
382 int Swig_contract_mode_get();
386 void Swig_browser(Node *n, int);
387 void Swig_default_allocators(Node *n);
388 void Swig_process_types(Node *n);