]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/SWIG/wrapfunc.cxx
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 *******************************************************************************/
16 // ------------------------------------------------------------------
19 // Created : June 22, 1996
22 // This file defines a class for writing wrappers. Instead of worrying
23 // about I/O problems, this wrapper class can be used to write functions
26 // Defines 3 string objects.
27 // def - Wrapper function definition (function name and arguments)
28 // locals - Local variable definitions
29 // code - The actual wrapper function code
31 //-------------------------------------------------------------------
36 // -------------------------------------------------------------------
37 // Print out a wrapper function.
39 // -------------------------------------------------------------------
41 void WrapperFunction::print(FILE *f
) {
42 fprintf(f
,"%s\n",def
.get());
43 fprintf(f
,"%s\n",locals
.get());
44 fprintf(f
,"%s\n",code
.get());
47 // -------------------------------------------------------------------
48 // Print out a wrapper function.
50 // -------------------------------------------------------------------
52 void WrapperFunction::print(String
&f
) {
58 // -------------------------------------------------------------------
59 // Safely add a local variable.
61 // Maintains a hash table to prevent double adding.
62 // -------------------------------------------------------------------
64 void WrapperFunction::add_local(char *type
, char *name
, char *defarg
) {
69 new_type
= new char[strlen(type
)+1];
70 strcpy(new_type
,type
);
72 // Figure out what the name of this variable is
76 while ((isalnum(*c
) || (*c
== '_') || (*c
== '$')) && (*c
)) {
81 if (h
.add(temp
,new_type
,WrapperFunction::del_type
) == -1) {
82 // Check to see if a type mismatch has occurred
83 stored_type
= (char *) h
.lookup(temp
);
84 if (strcmp(type
,stored_type
) != 0)
85 fprintf(stderr
,"Error. Type %s conflicts with previously declared type of %s\n",
90 // Successful, write some wrapper code
93 locals
<< tab4
<< type
<< " " << name
<< ";\n";
95 locals
<< tab4
<< type
<< " " << name
<< " = " << defarg
<< ";\n";
99 // -------------------------------------------------------------------
100 // char *WrapperFunction::new_local(char *type, char *name, char *defarg) {
102 // A safe way to add a new local variable. type and name are used as
103 // a starting point, but a new local variable will be created if these
104 // are already in use.
105 // -------------------------------------------------------------------
107 char *WrapperFunction::new_local(char *type
, char *name
, char *defarg
) {
109 static String new_name
;
111 new_type
= new char[strlen(type
)+1];
113 strcpy(new_type
,type
);
116 for (c
= name
; ((isalnum(*c
) || (*c
== '_') || (*c
== '$')) && (*c
)); c
++)
119 // Try to add a new local variable
120 if (h
.add(new_name
,new_type
,WrapperFunction::del_type
) == -1) {
121 // Local variable already exists, try to generate a new name
124 // This is a little funky. We copy characters until we reach a nonvalid
125 // identifier symbol, add a number, then append the rest. This is
126 // needed to properly handle arrays.
128 for (c
= name
; ((isalnum(*c
) || (*c
== '_') || (*c
== '$')) && (*c
)); c
++)
131 while (h
.add(new_name
,new_type
,WrapperFunction::del_type
) == -1) {
135 for (c
= name
; ((isalnum(*c
) || (*c
== '_') || (*c
== '$')) && (*c
)); c
++)
141 // Successful, write some wrapper code
143 locals
<< tab4
<< type
<< " " << new_name
<< ";\n";
145 locals
<< tab4
<< type
<< " " << new_name
<< " = " << defarg
<< ";\n";
147 // Need to strip off the array symbols now
150 while ((isalnum(*c
) || (*c
== '_') || (*c
== '$')) && (*c
))
156 // ------------------------------------------------------------------
157 // static WrapperFunction::del_type(void *obj)
159 // Callback function used when cleaning up the hash table.
160 // ------------------------------------------------------------------
162 void WrapperFunction::del_type(void *obj
) {