]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/SWIG/naming.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 *******************************************************************************/
20 // --------------------------------------------------------------------------------
25 // SWIG naming service.
27 // This module provides universal naming services for manufacturing function names.
28 // All language modules use this so it provides a convenient centralized
29 // mechanism for producing names.
30 // --------------------------------------------------------------------------------
32 // Structure for holding names
36 int first
; // Scoping information
37 int last
; // Scoping information
39 NamingScheme(char *n
) {
40 format
= copy_string(n
);
47 // Hash table containing naming data
49 static Hash naming_hash
;
51 // Variable indicating naming scope
53 static int naming_scope
= -1;
55 //-----------------------------------------------------------------
56 // make_wrap_name(char *s)
58 // Takes the name at src, and converts it into a syntactically
59 // valid identifier name. This is a hack to get the wrapper
60 // generator to support class member functions and other things.
62 // ie. We can define a function name as obj->foo(),
63 // but we'll need to call the wrapper function something like
65 //-----------------------------------------------------------------
67 void make_wrap_name(char *s
) {
72 for (i
= 0; i
< (int) strlen(s
); i
++, c1
++) {
73 if(!isalnum(*c1
)) *c1
= '_';
77 // --------------------------------------------------------------------------------
78 // int name_scope(int scope)
80 // Set the scope variable. This is used to determine what naming scheme to
81 // use. Returns the current value of the scope.
82 // --------------------------------------------------------------------------------
84 int name_scope(int scope
) {
90 // --------------------------------------------------------------------------------
91 // void name_register(char *method, char *format)
93 // Registers a new naming scheme.
94 // --------------------------------------------------------------------------------
96 void name_register(char *method
, char *format
) {
97 NamingScheme
*ns
, *nns
;
99 ns
= (NamingScheme
*) naming_hash
.lookup(method
);
101 naming_hash
.remove(method
);
104 nns
= new NamingScheme(format
); // Create a new naming scheme
105 if (ns
) ns
->last
= type_id
;
108 naming_hash
.add(method
,nns
);
111 // --------------------------------------------------------------------------------
112 // char *name_getformat(char *method)
114 // Looks up a naming scheme in the hash table. The scope of the name should have
115 // been set prior to calling this. If not set, we just use the last name entered.
116 // Returns the format string or NULL if no name has been set.
117 // --------------------------------------------------------------------------------
119 static char *name_getformat(char *method
) {
123 if (naming_scope
== -1) scope
= type_id
;
124 else scope
= naming_scope
;
126 ns
= (NamingScheme
*) naming_hash
.lookup(method
);
128 if ((ns
->first
<= scope
) && (scope
< ns
->last
))
135 // --------------------------------------------------------------------------------
136 // char *name_wrapper(char *fname, char *prefix, int suppress)
138 // Returns the name of a wrapper function. The following variables are
145 // By default a wrapper function gets the name _wrap_prefixfname.
147 // --------------------------------------------------------------------------------
149 char *name_wrapper(char *fname
, char *prefix
, int suppress
) {
153 f
= name_getformat("wrapper");
155 f
= "_wrap_%p%f"; // Default wrapper name
158 fmt
.replace("%f",fname
);
159 fmt
.replace("%l",typemap_lang
);
160 fmt
.replace("%p",prefix
);
167 // --------------------------------------------------------------------------------
168 // char *name_member(char *fname, char *classname, int suppress)
170 // Returns the name of a method function. The following variables are
177 // By default, the name of a method is given as Classname_method.
178 // --------------------------------------------------------------------------------
180 char *name_member(char *fname
, char *classname
, int suppress
) {
184 f
= name_getformat("member");
189 fmt
.replace("%f",fname
);
190 fmt
.replace("%l",typemap_lang
);
191 fmt
.replace("%c",classname
);
198 // --------------------------------------------------------------------------------
199 // char *name_get(char *vname, int suppress)
201 // Returns the name of the accessor function used to get a variable.
203 // %v -> variable name
205 // --------------------------------------------------------------------------------
207 char *name_get(char *vname
, int suppress
) {
211 f
= name_getformat("get");
216 fmt
.replace("%v",vname
);
222 // --------------------------------------------------------------------------------
223 // char *name_set(char *vname, int suppress)
225 // Returns the name of the accessor function used to set a variable.
227 // %v -> variable name
228 // --------------------------------------------------------------------------------
230 char *name_set(char *vname
, int suppress
) {
234 f
= name_getformat("set");
239 fmt
.replace("%v",vname
);
246 // --------------------------------------------------------------------------------
247 // char *name_construct(char *classname, int suppress)
249 // Returns the name of the accessor function used to create an object.
250 // By default this is "new_classname"
255 // --------------------------------------------------------------------------------
257 char *name_construct(char *classname
, int suppress
) {
261 f
= name_getformat("construct");
266 fmt
.replace("%l",typemap_lang
);
267 fmt
.replace("%c",classname
);
274 // --------------------------------------------------------------------------------
275 // char *name_destroy(char *classname, int suppress)
277 // Returns the name of the accessor function used to destroy an object.
278 // By default this is "delete_classname"
283 // --------------------------------------------------------------------------------
285 char *name_destroy(char *classname
, int suppress
) {
289 f
= name_getformat("destroy");
294 fmt
.replace("%l",typemap_lang
);
295 fmt
.replace("%c",classname
);