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. 4 * 5 * swigmod.h 6 * 7 * Main header file for SWIG modules. 8 * ----------------------------------------------------------------------------- */ 9 10/* $Id: swigmod.h 11470 2009-07-29 20:50:39Z wsfulton $ */ 11 12#ifndef SWIG_SWIGMOD_H_ 13#define SWIG_SWIGMOD_H_ 14 15#include "swig.h" 16#include "preprocessor.h" 17#include "swigwarn.h" 18 19#if !defined(HAVE_BOOL) 20typedef int bool; 21#define true ((bool)1) 22#define false ((bool)0) 23#endif 24 25#define NOT_VIRTUAL 0 26#define PLAIN_VIRTUAL 1 27#define PURE_VIRTUAL 2 28 29extern String *input_file; 30extern int line_number; 31extern int start_line; 32extern int CPlusPlus; // C++ mode 33extern int Extend; // Extend mode 34extern int Verbose; 35extern int IsVirtual; 36extern int ImportMode; 37extern int NoExcept; // -no_except option 38extern int Abstract; // abstract base class 39extern int SmartPointer; // smart pointer methods being emitted 40extern int SwigRuntime; 41 42/* Overload "argc" and "argv" */ 43extern String *argv_template_string; 44extern String *argc_template_string; 45 46/* Miscellaneous stuff */ 47 48#define tab2 " " 49#define tab4 " " 50#define tab8 " " 51 52class Dispatcher { 53public: 54 55 Dispatcher ():cplus_mode(PUBLIC) { 56 } 57 virtual ~ Dispatcher () { 58 } 59 60 virtual int emit_one(Node *n); 61 virtual int emit_children(Node *n); 62 virtual int defaultHandler(Node *n); 63 64 /* Top of the parse tree */ 65 virtual int top(Node *n) = 0; 66 67 /* SWIG directives */ 68 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); 84 85 /* C/C++ parsing */ 86 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); 100 101 enum AccessMode { PUBLIC, PRIVATE, PROTECTED }; 102 103protected: 104 AccessMode cplus_mode; 105}; 106 107/* ---------------------------------------------------------------------------- 108 * class language: 109 * 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 * ------------------------------------------------------------------------- */ 114 115class Language:public Dispatcher { 116public: 117 Language(); 118 virtual ~Language(); 119 virtual int emit_one(Node *n); 120 121 /* Parse command line options */ 122 123 virtual void main(int argc, char *argv[]); 124 125 /* Top of the parse tree */ 126 127 virtual int top(Node *n); 128 129 /* SWIG directives */ 130 131 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); 146 147 /* C/C++ parsing */ 148 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); 161 162 /* Function handlers */ 163 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); 169 170 /* Variable handlers */ 171 172 virtual int variableHandler(Node *n); 173 virtual int globalvariableHandler(Node *n); 174 virtual int membervariableHandler(Node *n); 175 virtual int staticmembervariableHandler(Node *n); 176 177 /* C++ handlers */ 178 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); 184 185 /* Miscellaneous */ 186 187 virtual int typedefHandler(Node *n); 188 189 /* Low-level code generation */ 190 191 virtual int constantWrapper(Node *n); 192 virtual int variableWrapper(Node *n); 193 virtual int functionWrapper(Node *n); 194 virtual int nativeWrapper(Node *n); 195 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); 208 209 /* Miscellaneous */ 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() */ 220 221 /* Runtime is C++ based, so extern "C" header section */ 222 void enable_cplus_runtime_mode(); 223 224 /* Returns the cplus_runtime mode */ 225 int cplus_runtime_mode(); 226 227 /* Allow director related code generation */ 228 void allow_directors(int val = 1); 229 230 /* Return true if directors are enabled */ 231 int directorsEnabled() const; 232 233 /* Allow director protected members related code generation */ 234 void allow_dirprot(int val = 1); 235 236 /* Allow all protected members code generation (for directors) */ 237 void allow_allprotected(int val = 0); 238 239 /* Returns the dirprot mode */ 240 int dirprot_mode() const; 241 242 /* Check if the non public constructor is needed (for directors) */ 243 int need_nonpublic_ctor(Node *n); 244 245 /* Check if the non public member is needed (for directors) */ 246 int need_nonpublic_member(Node *n); 247 248 /* Set none comparison string */ 249 void setSubclassInstanceCheck(String *s); 250 251 /* Set overload variable templates argc and argv */ 252 void setOverloadResolutionTemplates(String *argc, String *argv); 253 254 /* Language instance is a singleton - get instance */ 255 static Language* instance(); 256 257protected: 258 /* Allow multiple-input typemaps */ 259 void allow_multiple_input(int val = 1); 260 261 /* Allow overloaded functions */ 262 void allow_overloading(int val = 1); 263 264 /* Wrapping class query */ 265 int is_wrapping_class(); 266 267 /* Return the node for the current class */ 268 Node *getCurrentClass() const; 269 270 /* Return C++ mode */ 271 int getCPlusMode() const; 272 273 /* Return the real name of the current class */ 274 String *getClassName() const; 275 276 /* Return the classes hash */ 277 Hash *getClassHash() const; 278 279 /* Return the current class prefix */ 280 String *getClassPrefix() const; 281 282 /* Fully qualified type name to use */ 283 String *getClassType() const; 284 285 /* Return true if the current method is part of a smart-pointer */ 286 int is_smart_pointer() const; 287 288 /* Some language modules require additional wrappers for virtual methods not declared in sub-classes */ 289 virtual bool extraDirectorProtectedCPPMethodsRequired() const; 290 291 /* Director subclass comparison test */ 292 String *none_comparison; 293 294 /* Director constructor "template" code */ 295 String *director_ctor_code; 296 297 /* Director 'protected' constructor "template" code */ 298 String *director_prot_ctor_code; 299 300 /* Director allows multiple inheritance */ 301 int director_multiple_inheritance; 302 303 /* Director language module */ 304 int director_language; 305 306private: 307 Hash *symbols; 308 Hash *classtypes; 309 Hash *enumtypes; 310 int overloading; 311 int multiinput; 312 int cplus_runtime; 313 int directors; 314 static Language *this_; 315}; 316 317int SWIG_main(int, char **, Language *); 318void emit_parameter_variables(ParmList *l, Wrapper *f); 319void emit_return_variable(Node *n, SwigType *rt, Wrapper *f); 320void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */ 321void SWIG_config_file(const_String_or_char_ptr ); 322const String *SWIG_output_directory(); 323void SWIG_config_cppext(const char *ext); 324 325/* get the list of generated files */ 326List *SWIG_output_files(); 327 328void SWIG_library_directory(const char *); 329int emit_num_arguments(ParmList *); 330int emit_num_required(ParmList *); 331int emit_isvarargs(ParmList *); 332void emit_attach_parmmaps(ParmList *, Wrapper *f); 333void emit_mark_varargs(ParmList *l); 334String *emit_action(Node *n); 335int emit_action_code(Node *n, String *wrappercode, String *action); 336void Swig_overload_check(Node *n); 337String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *); 338String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int *); 339String *Swig_overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int *); 340SwigType *cplus_value_type(SwigType *t); 341 342/* directors.cxx start */ 343String *Swig_csuperclass_call(String *base, String *method, ParmList *l); 344String *Swig_class_declaration(Node *n, String *name); 345String *Swig_class_name(Node *n); 346String *Swig_method_call(const_String_or_char_ptr name, ParmList *parms); 347String *Swig_method_decl(SwigType *rtype, SwigType *decl, const_String_or_char_ptr id, List *args, int strip, int values); 348String *Swig_director_declaration(Node *n); 349void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f); 350/* directors.cxx end */ 351 352extern "C" { 353 void SWIG_typemap_lang(const char *); 354 typedef Language *(*ModuleFactory) (void); 355} 356 357void Swig_register_module(const char *name, ModuleFactory fac); 358ModuleFactory Swig_find_module(const char *name); 359 360/* Utilities */ 361 362int is_public(Node *n); 363int is_private(Node *n); 364int is_protected(Node *n); 365int is_member_director(Node *parentnode, Node *member); 366int is_member_director(Node *member); 367int is_non_virtual_protected_access(Node *n); /* Check if the non-virtual protected members are required (for directors) */ 368int use_naturalvar_mode(Node *n); 369 370void Wrapper_virtual_elimination_mode_set(int); 371void Wrapper_fast_dispatch_mode_set(int); 372void Wrapper_cast_dispatch_mode_set(int); 373void Wrapper_naturalvar_mode_set(int); 374 375 376void clean_overloaded(Node *n); 377 378/* Contracts */ 379 380void Swig_contracts(Node *n); 381void Swig_contract_mode_set(int flag); 382int Swig_contract_mode_get(); 383 384/* Browser */ 385 386void Swig_browser(Node *n, int); 387void Swig_default_allocators(Node *n); 388void Swig_process_types(Node *n); 389 390 391#endif 392