]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/Include/swig.h
   1 /******************************************************************************* 
   2  * Simplified Wrapper and Interface Generator  (SWIG) 
   4  * Author : David Beazley 
   6  * Department of Computer Science 
   7  * University of Chicago 
  10  * beazley@cs.uchicago.edu 
  12  * Please read the file LICENSE for the copyright and terms by which SWIG 
  13  * can be used and distributed. 
  14  *******************************************************************************/ 
  15 /*********************************************************************** 
  20  * This is the header file containing the main class definitions and 
  21  * declarations.   Should be included in all extensions and code 
  24  ***********************************************************************/ 
  35 /* Global variables.   Needs to be cleaned up */ 
  38 #define Status Swig_Status 
  40 #define stderr swig_log 
  41 extern  FILE   *swig_log
; 
  44 extern  FILE      *f_header
;                        // Some commonly used 
  45 extern  FILE      *f_wrappers
;                      // FILE pointers 
  48 extern  char      InitName
[256]; 
  49 extern  char      LibDir
[512];                      // Library directory 
  50 extern  char     **InitNames
;                       // List of other init functions 
  51 extern  int       Status
;                           // Variable creation status 
  52 extern  int       TypeStrict
;                       // Type checking strictness 
  55 extern  int       line_number
; 
  56 extern  int       start_line
; 
  57 extern  char     *input_file
;                       // Current input file 
  58 extern  int       CPlusPlus
;                        // C++ mode 
  59 extern  int       ObjC
;                             // Objective-C mode 
  60 extern  int       ObjCClass
;                        // Objective-C style class 
  61 extern  int       AddMethods
;                       // AddMethods mode 
  62 extern  int       NewObject
;                        // NewObject mode 
  63 extern  int       Inline
;                           // Inline mode 
  64 extern  int       NoInclude
;                        // NoInclude flag 
  65 extern  char     *typemap_lang
;                     // Current language name 
  66 extern  int       error_count
; 
  67 extern  char     *copy_string(char *); 
  68 extern  char      output_dir
[512];                  // Output directory 
  70 #define FatalError()   if ((error_count++) > 20) { fprintf(stderr,"Confused by earlier errors. Bailing out\n"); SWIG_exit(1); } 
  72 /* Miscellaneous stuff */ 
  74 #define  STAT_READONLY  1 
  77 extern char* getSwigLib(); 
  79 // ----------------------------------------------------------------------- 
  81 // ----------------------------------------------------------------------- 
  85   int   maxsize
;            // Max size of current string 
  86   void  add(const char *newstr
);  // Function to add a new string 
  87   void  add(char c
);              // Add a character 
  88   void  insert(const char *newstr
); 
  92   String(const char *s
); 
  95   char  *str
;               // String data 
  96   friend String
& operator<<(String
&,const char *s
); 
  97   friend String
& operator<<(String
&,const int); 
  98   friend String
& operator<<(String
&,const char); 
  99   friend String
& operator<<(String
&,String
&); 
 100   friend String
& operator>>(const char *s
, String
&); 
 101   friend String
& operator>>(String
&,String
&); 
 102   String
& operator=(const char *); 
 103   operator char*() const { return str
; } 
 105   void   replace(const char *token
, const char *rep
); 
 106   void   replaceid(const char *id
, const char *rep
); 
 117 // ------------------------------------------------------------------- 
 119 // ------------------------------------------------------------------- 
 124     Node(const char *k
, void *obj
, void (*d
)(void *)) { 
 125       key 
= new char[strlen(k
)+1]; 
 133       if (del_proc
) (*del_proc
)(object
); 
 138     void (*del_proc
)(void *); 
 140   int    h1(const char *key
);      // Hashing function 
 141   int    hashsize
;                 // Size of hash table 
 142   Node  
**hashtable
;               // Actual hash table 
 143   int    index
;                    // Current index (used by iterators) 
 144   Node   
*current
;                 // Current item in hash table 
 148   int    add(const char *key
, void *object
); 
 149   int    add(const char *key
, void *object
, void (*del
)(void *)); 
 150   void  *lookup(const char *key
); 
 151   void   remove(const char *key
); 
 158 /************************************************************************ 
 161  * Defines the basic datatypes supported by the translator. 
 163  ************************************************************************/ 
 182 // These types are now obsolete, but defined for backwards compatibility 
 188 // Class for storing data types 
 194   static Hash       
*typedef_hash
[MAXSCOPE
]; 
 197   int         type
;          // SWIG Type code 
 198   char        name
[MAX_NAME
];      // Name of type 
 199   char        is_pointer
;    // Is this a pointer? 
 200   char        implicit_ptr
;  // Implicit ptr 
 201   char        is_reference
;  // A C++ reference type 
 202   char        status
;        // Is this datatype read-only? 
 203   char        *qualifier
;    // A qualifier string (ie. const). 
 204   char        *arraystr
;     // String containing array part 
 205   int         id
;            // type identifier (unique for every type). 
 207   DataType(DataType 
*); 
 210   void        primitive();   // Turn a datatype into its primitive type 
 211   char       *print_type();  // Return string containing datatype 
 212   char       *print_full();  // Return string with full datatype 
 213   char       *print_cast();  // Return string for type casting 
 214   char       *print_mangle();// Return mangled version of type 
 215   char       *print_real(char *local
=0);  // Print the real datatype (as far as we can determine) 
 216   char       *print_arraycast(); // Prints an array cast 
 217   char       *print_mangle_default(); // Default mangling scheme 
 219   // Array query functions 
 220   int        array_dimensions();   // Return number of array dimensions (if any) 
 221   char       *get_dimension(int);  // Return string containing a particular dimension 
 222   char       *get_array();         // Returns the array string for a datatype 
 226   void       typedef_add(char *name
, int mode 
= 0); // Add this type to typedef list 
 227   void       typedef_resolve(int level 
= 0);        // See if this type has been typedef'd 
 228   void       typedef_replace();                     // Replace this type with it's original type 
 229 static int   is_typedef(char *name
);                // See if this is a typedef 
 230   void       typedef_updatestatus(int newstatus
);   // Change status of a typedef 
 231 static void  init_typedef(void);                    // Initialize typedef manager 
 232 static void  merge_scope(Hash 
*h
);                  // Functions for managing scoping of datatypes 
 233 static void  new_scope(Hash 
*h 
= 0); 
 234 static Hash 
*collapse_scope(char *); 
 235   int        check_defined();                       // Check to see if type is defined by a typedef. 
 238 #define STAT_REPLACETYPE   2 
 240 /************************************************************************ 
 243  * Structure for holding information about function parameters 
 245  *      CALL_VALUE  -->  Call by value even though function parameter 
 248  *      CALL_REF    -->  Call by reference even though function parameter 
 252  ************************************************************************/ 
 254 #define CALL_VALUE      0x01 
 255 #define CALL_REFERENCE  0x02 
 256 #define CALL_OUTPUT     0x04 
 259   DataType   
*t
;                // Datatype of this parameter 
 260   int        call_type
;         // Call type (value or reference or value) 
 261   char       *name
;             // Name of parameter (optional) 
 262   char       *defvalue
;         // Default value (as a string) 
 263   int        ignore
;            // Ignore flag 
 264   char       *objc_separator
;   // Parameter separator for Objective-C 
 265   Parm(DataType 
*type
, char *n
); 
 270 // ------------------------------------------------------------- 
 273 // This class is used for manipulating parameter lists in 
 274 // function and type declarations. 
 275 // ------------------------------------------------------------- 
 281   int   maxparms
;                 // Max parms possible in current list 
 282   Parm  
**parms
;                  // Pointer to parms array 
 283   void  moreparms();              // Increase number of stored parms 
 284   int    current_parm
;            // Internal state for get_first,get_next 
 286   int   nparms
;                   // Number of parms in list 
 287   void  append(Parm 
*p
);          // Append a parameter to the end 
 288   void  insert(Parm 
*p
, int pos
); // Insert a parameter into the list 
 289   void  del(int pos
);             // Delete a parameter at position pos 
 290   int   numopt();                 // Get number of optional arguments 
 291   int   numarg();                 // Get number of active arguments 
 292   Parm 
*get(int pos
);             // Get the parameter at position pos 
 293   Parm 
&operator[](int);          // An alias for get(). 
 295   ParmList(ParmList 
*l
); 
 298   // Keep this for backwards compatibility 
 300   Parm  
*get_first();              // Get first parameter from list 
 301   Parm  
*get_next();               // Get next parameter from list 
 302   void   print_types(FILE *f
);     // Print list of datatypes 
 303   void   print_types(String 
&f
);   // Generate list of datatypes. 
 304   void   print_args(FILE *f
);      // Print argument list 
 305   int    check_defined();          // Checks to make sure the arguments are defined 
 306   void   sub_parmnames(String 
&s
); // Remaps real parameter names in code fragment 
 309 // Modes for different types of inheritance 
 311 #define INHERIT_FUNC       0x1 
 312 #define INHERIT_VAR        0x2 
 313 #define INHERIT_CONST      0x4 
 314 #define INHERIT_ALL        (INHERIT_FUNC | INHERIT_VAR | INHERIT_CONST) 
 317   Pragma() { next 
= 0; } 
 326 /************************************************************************ 
 329  * This class defines the functions that need to be supported by the 
 330  * scripting language being used.    The translator calls these virtual 
 331  * functions to output different types of code for different languages. 
 333  * By implementing this using virtual functions, hopefully it will be 
 334  * easy to support different types of scripting languages. 
 336  * The following functions are used : 
 338  *    parse_args(argc, argv) 
 339  *           Parse the arguments used by this language. 
 342  *           Entry function that starts parsing of a particular language 
 344  *    create_function(fname, iname, rtype, parmlist) 
 345  *           Creates a function wrappper. 
 347  *    link_variable(vname, iname, type) 
 348  *           Creates a link to a variable. 
 350  *    declare_const(cname, type, value) 
 351  *           Creates a constant (for #define). 
 353  *    initialize(char *fn) 
 354  *           Produces initialization code. 
 357  *           Produce code for headers 
 362  *    usage_var(iname,type,string) 
 363  *           Produces usage string for variable declaration. 
 365  *    usage_func(iname,rttype, parmlist, string) 
 366  *           Produces usage string for function declaration. 
 368  *    usage_const(iname, type, value, string) 
 369  *           Produces usage string for constants 
 371  *    set_module(char *modname) 
 372  *           Sets the name of the module (%module directive) 
 374  *    set_init(char *initname) 
 375  *           Sets name of initialization function (an alternative to set_module) 
 376  *    add_native(char *name, char *funcname); 
 377  *           Adds a native wrapper function to the initialize process 
 379  *    type_mangle(DataType *t); 
 380  *           Mangles the name of a datatype. 
 381  * --- C++ Functions --- 
 383  *    These functions are optional additions to any of the target 
 384  *    languages.   SWIG handles inheritance, symbol tables, and other 
 387  *    cpp_open_class(char *classname, char *rname) 
 388  *          Open a new C++ class definition. 
 389  *    cpp_close_class(char *) 
 390  *          Close current C++ class 
 391  *    cpp_member_func(char *name, char *rname, DataType *rt, ParmList *l) 
 392  *          Create a C++ member function 
 393  *    cpp_constructor(char *name, char *iname, ParmList *l) 
 394  *          Create a C++ constructor. 
 395  *    cpp_destructor(char *name, char *iname) 
 396  *          Create a C++ destructor 
 397  *    cpp_variable(char *name, char *iname, DataType *t) 
 398  *          Create a C++ member data item. 
 399  *    cpp_declare_const(char *name, char *iname, int type, char *value) 
 400  *          Create a C++ constant. 
 401  *    cpp_inherit(char *baseclass) 
 402  *          Inherit data from baseclass. 
 403  *    cpp_static_func(char *name, char *iname, DataType *t, ParmList *l) 
 404  *          A C++ static member function. 
 405  *    cpp_static_var(char *name, char *iname, DataType *t) 
 406  *          A C++ static member data variable. 
 408  *************************************************************************/ 
 412   virtual void parse_args(int argc
, char *argv
[]) = 0; 
 413   virtual void parse() = 0; 
 414   virtual void create_function(char *, char *, DataType 
*, ParmList 
*) = 0; 
 415   virtual void link_variable(char *, char *, DataType 
*)  = 0; 
 416   virtual void declare_const(char *, char *, DataType 
*, char *) = 0; 
 417   virtual void initialize(void) = 0; 
 418   virtual void headers(void) = 0; 
 419   virtual void close(void) = 0; 
 420   virtual void set_module(char *mod_name
,char **mod_list
) = 0; 
 421   virtual void set_init(char *init_name
); 
 422   virtual void add_native(char *, char *); 
 423   virtual char *type_mangle(DataType 
*t
) { 
 424     return t
->print_mangle_default(); 
 426   virtual void add_typedef(DataType 
*t
, char *name
); 
 427   virtual void create_command(char *cname
, char *iname
); 
 430   // C++ language extensions. 
 431   // You can redefine these, or use the defaults below 
 434   virtual void cpp_member_func(char *name
, char *iname
, DataType 
*t
, ParmList 
*l
); 
 435   virtual void cpp_constructor(char *name
, char *iname
, ParmList 
*l
); 
 436   virtual void cpp_destructor(char *name
, char *newname
); 
 437   virtual void cpp_open_class(char *name
, char *rename
, char *ctype
, int strip
); 
 438   virtual void cpp_close_class(); 
 439   virtual void cpp_cleanup(); 
 440   virtual void cpp_inherit(char **baseclass
, int mode 
= INHERIT_ALL
); 
 441   virtual void cpp_variable(char *name
, char *iname
, DataType 
*t
); 
 442   virtual void cpp_static_func(char *name
, char *iname
, DataType 
*t
, ParmList 
*l
); 
 443   virtual void cpp_declare_const(char *name
, char *iname
, DataType 
*type
, char *value
); 
 444   virtual void cpp_static_var(char *name
, char *iname
, DataType 
*t
); 
 445   virtual void cpp_pragma(Pragma 
*plist
); 
 449   virtual void pragma(char *, char *, char *); 
 451   // Declaration of a class, but not a full definition 
 453   virtual void cpp_class_decl(char *, char *, char *); 
 457   virtual void import(char *filename
); 
 463 // -------------------------------------------------------------------- 
 466 // Base class for the documentation system.   Basically everything is 
 467 // a documentation entry of some sort.   Specific derived classes 
 468 // are created internally and shouldn't be accessed by third-party 
 470 // -------------------------------------------------------------------- 
 474   char        *name
;                 // Name of the entry 
 475   String      usage
;                 // Short description (optional) 
 476   String      cinfo
;                 // Information about C interface (optional). 
 477   String      text
;                  // Supporting text (optional) 
 478   DocEntry    
*parent
;               // Parent of this entry (optional) 
 479   DocEntry    
*child
;                // Children of this entry (optional) 
 480   DocEntry    
*next
;                 // Next entry (or sibling) 
 481   DocEntry    
*previous
;             // Previous entry 
 482   int          counter
;              // Counter for section control 
 483   int          is_separator
;         // Is this a separator entry? 
 484   int          sorted
;               // Sorted? 
 485   int          line_number
;          // Line number 
 486   int          end_line
;             // Ending line number 
 487   int          format
;               // Format this documentation entry 
 488   int          print_info
;           // Print C information about this entry 
 490   virtual ~DocEntry();               // Destructor (common to all subclasses) 
 492   // Methods applicable to all documentation entries 
 494   virtual void output(Documentation 
*d
); 
 495   void add(DocEntry 
*de
);            // Add documentation entry to the list 
 496   void addchild(DocEntry 
*de
);       // Add documentation entry as a child 
 497   void sort_children();              // Sort all of the children 
 498   void remove();                     // Remove this doc entry 
 499   void parse_args(int argc
, char **argv
); // Parse command line options 
 500   void style(char *name
,char *value
);// Change doc style. 
 501   static DocEntry  
*dead_entries
;    // Dead documentation entries 
 504 extern DocEntry      
*doc_entry
; 
 506 // Default DocEntry style parameters 
 508 #define SWIGDEFAULT_SORT            0 
 509 #define SWIGDEFAULT_FORMAT          1 
 510 #define SWIGDEFAULT_INFO            1 
 512 // ---------------------------------------------------------------------- 
 513 // Documentation module base class 
 515 // This class defines methods that need to be implemented for a 
 516 // documentation module. 
 518 // title()          - Print out a title entry 
 519 // newsection()     - Start a new section (may be nested to form subsections) 
 520 // endsection()     - End a section 
 521 // print_decl()     - Print a standard declaration 
 522 // print_text()     - Print standard text 
 523 // init()           - Initialize the documentation module 
 524 // close()          - Close documentation module 
 525 // ---------------------------------------------------------------------- 
 527 class Documentation 
{ 
 529   virtual void parse_args(int argc
, char **argv
) = 0; 
 530   virtual void title(DocEntry 
*de
) = 0; 
 531   virtual void newsection(DocEntry 
*de
, int sectnum
) = 0; 
 532   virtual void endsection() = 0; 
 533   virtual void print_decl(DocEntry 
*de
) = 0; 
 534   virtual void print_text(DocEntry 
*de
) = 0; 
 535   virtual void separator() = 0; 
 536   virtual void init(char *filename
) = 0; 
 537   virtual void close(void) = 0; 
 538   virtual void style(char *name
, char *value
) = 0; 
 543 extern  void  emit_extern_var(char *, DataType 
*, int, FILE *); 
 544 extern  void  emit_extern_func(char *, DataType 
*, ParmList 
*, int, FILE *); 
 545 extern  int   emit_args(DataType 
*, ParmList 
*, FILE *); 
 547 extern  void  emit_func_call(char *, DataType 
*, ParmList 
*, FILE *); 
 549 extern  void  emit_hex(FILE *); 
 550 extern  void  emit_set_get(char *, char *, DataType 
*); 
 551 extern  void  emit_banner(FILE *); 
 552 extern  void  emit_ptr_equivalence(FILE *); 
 553 extern  int   SWIG_main(int, char **, Language 
*, Documentation 
*); 
 554 extern  void  make_wrap_name(char *); 
 556 // Some functions for emitting some C++ helper code 
 558 extern void cplus_emit_member_func(char *classname
, char *classtype
, char *classrename
, 
 559                                    char *mname
, char *mrename
, DataType 
*type
, ParmList 
*l
, 
 562 extern void cplus_emit_static_func(char *classname
, char *classtype
, char *classrename
, 
 563                                    char *mname
, char *mrename
, DataType 
*type
, ParmList 
*l
, 
 566 extern void cplus_emit_destructor(char *classname
, char *classtype
, char *classrename
, 
 567                                   char *name
, char *iname
, int mode
); 
 569 extern void cplus_emit_constructor(char *classname
, char *classtype
, char *classrename
, 
 570                                    char *name
, char *iname
, ParmList 
*l
, int mode
); 
 572 extern void cplus_emit_variable_get(char *classname
, char *classtype
, char *classrename
, 
 573                                     char *name
, char *iname
, DataType 
*type
, int mode
); 
 575 extern void cplus_emit_variable_set(char *classname
, char *classtype
, char *classrename
, 
 576                                     char *name
, char *iname
, DataType 
*type
, int mode
); 
 578 extern char *cplus_base_class(char *name
); 
 580 extern void cplus_support_doc(String 
&f
); 
 582 /* Function for building search directories */ 
 584 extern  void  add_directory(char *dirname
); 
 585 extern  int   insert_file(char *, FILE *); 
 586 extern  int   get_file(char *filename
, String 
&str
); 
 587 extern  int   checkout_file(char *filename
, char *dest
); 
 588 extern  int   checkin_file(char *dir
, char *lang
, char *source
, char *dest
); 
 589 extern  int   include_file(char *filename
); 
 593 extern void check_options(); 
 594 extern void init_args(int argc
, char **); 
 595 extern void mark_arg(int n
); 
 596 extern void arg_error(); 
 598 extern void library_add(char *name
); 
 599 extern void library_insert(); 
 601 // ----------------------------------------------------------------------- 
 602 //  Class for Creating Wrapper Functions 
 603 // ----------------------------------------------------------------------- 
 605 class WrapperFunction 
{ 
 614   void    print(String 
&f
); 
 615   void    add_local(char *type
, char *name
, char *defvalue 
= 0); 
 616   char   *new_local(char *type
, char *name
, char *defvalue 
= 0); 
 617 static    void    del_type(void *obj
); 
 620 extern  int   emit_args(DataType 
*, ParmList 
*, WrapperFunction 
&f
); 
 621 extern  void  emit_func_call(char *, DataType 
*, ParmList 
*, WrapperFunction 
&f
); 
 622 extern  void  SWIG_exit(int); 
 624 // Symbol table management 
 626 extern int  add_symbol(char *, DataType 
*, char *); 
 627 extern void remove_symbol(char *); 
 628 extern int  update_symbol(char *, DataType 
*, char *); 
 629 extern char *lookup_symvalue(char *); 
 630 extern DataType 
*lookup_symtype(char *); 
 631 extern int  lookup_symbol(char *); 
 633 // ----------------------------------------------------------------------- 
 635 // ----------------------------------------------------------------------- 
 637 extern void    typemap_register(char *op
, char *lang
, DataType 
*type
, char *pname
, char *code
, ParmList 
*l 
= 0); 
 638 extern void    typemap_register(char *op
, char *lang
, char *type
, char *pname
, char *code
,ParmList 
*l 
= 0); 
 639 extern void    typemap_register_default(char *op
, char *lang
, int type
, int ptr
, char *arraystr
, char *code
, ParmList 
*l 
= 0); 
 640 extern char   *typemap_lookup(char *op
, char *lang
, DataType 
*type
, char *pname
, char *source
, char *target
, 
 641                               WrapperFunction 
*f 
= 0); 
 642 extern void    typemap_clear(char *op
, char *lang
, DataType 
*type
, char *pname
); 
 643 extern void    typemap_copy(char *op
, char *lang
, DataType 
*stype
, char *sname
, DataType 
*ttype
, char *tname
); 
 644 extern char   *typemap_check(char *op
, char *lang
, DataType 
*type
, char *pname
); 
 645 extern void    typemap_apply(DataType 
*tm_type
, char *tmname
, DataType 
*type
, char *pname
); 
 646 extern void    typemap_clear_apply(DataType 
*type
, char *pname
); 
 649 // ----------------------------------------------------------------------- 
 650 // Code fragment support 
 651 // ----------------------------------------------------------------------- 
 653 extern void    fragment_register(char *op
, char *lang
, char *code
); 
 654 extern char   *fragment_lookup(char *op
, char *lang
, int age
); 
 655 extern void    fragment_clear(char *op
, char *lang
); 
 658 extern  void  emit_ptr_equivalence(WrapperFunction 
&); 
 660 // ----------------------------------------------------------------------- 
 662 // ----------------------------------------------------------------------- 
 666 extern void   name_register(char *method
, char *format
); 
 667 extern int    name_scope(int); 
 668 extern char  *name_wrapper(char *fname
, char *prefix
, int suppress
=0); 
 669 extern char  *name_member(char *fname
, char *classname
, int suppress
=0); 
 670 extern char  *name_get(char *vname
, int suppress
=0); 
 671 extern char  *name_set(char *vname
, int suppress
=0); 
 672 extern char  *name_construct(char *classname
, int suppress
=0); 
 673 extern char  *name_destroy(char *classname
, int suppress
=0);