1
2
3
4
5
6 """defines controller classes which help to define the function transformation
7
8 The idea behind implementation of "Function Transformation" functionality is simple:
9 Py++ defines few templates. Transformers are just editors for the templates.
10 In most cases, transformers don't directly edit the template, but use controller
11 classes for this purpose. Controller classes provide an abstraction of the templates.
12 """
13
14 import string
15 import templates
16 from pygccxml import declarations
19 """defines C++ variable"""
20 - def __init__( self, type, name, initialize_expr='' ):
21 """
22 @param type: type of the variable
23 @type type: instance of L{pygccxml.declarations.type_t}
24
25 @param name: name( str ) of the variable
26
27 @param initialize_expr: an expression that initialize the variable
28 """
29 self.__name = name
30 self.__type = type
31 self.__initialize_expr = initialize_expr
32
33 @property
35 "variable name"
36 return self.__name
37
38 @property
40 "variable type"
41 return self.__type
42
43 @property
45 "inirialize expression"
46 return self.__initialize_expr
47
53
55 """function wrapper variables manager
56
57 Almost every time we define new transformer, we need to define variables.
58 It is important to keep the variable names unique. This class will ensure this.
59 Every time you declare new variable, it will return the unique variable name.
60 The name will be built from the original variable name and some index, which
61 will make the variable to be unique.
62 """
64 object.__init__( self )
65 self.__variables = []
66 self.__names_in_use = set()
67
68 @property
70 "list of all declared variables"
71 return self.__variables
72
74 """declare variable
75
76 @param type: type of the variable
77 @type type: instance of L{pygccxml.declarations.type_t}
78
79 @param name: name( str ) of the variable
80
81 @param initialize_expr: an expression that initialize the variable
82
83 @return: the unique variable name
84 """
85 unique_name = self.__create_unique_var_name( name )
86 self.__variables.append( variable_t( type, unique_name, initialize_expr ) )
87 return unique_name
88
90 """register predefined variable name
91
92 There are use cases, where it is convenience to define variables within
93 a template. In such cases, the only thing that should be done is registering
94 a unique name of the variable.
95 """
96 return self.__create_unique_var_name( name )
97
108
113
115 """base class for all controller classes"""
116
119
120 @property
122 return self.__function
123
124 - def apply( self, transformations ):
125 """asks all transformations to configure the controller"""
126 raise NotImplementedError()
127
129 """base class for free and member function controllers"""
140
141 @property
144
147
150
151 @property
153 return self.__result_var
154
155 @property
158
159 @property
161 return filter( None, self.__wrapper_args )
162
168
170 arg = self.find_wrapper_arg( name )
171 if not arg:
172 raise LookupError( "Unable to remove '%s' argument - not found!" % name )
173 self.__wrapper_args[ self.__wrapper_args.index(arg) ] = None
174
175 @property
177 return self.__arg_expressions
178
181
182 @property
193
194 @property
196 return self.__return_variables
197
199 self.__return_variables.append( variable_name )
200
201 @property
203 return self.__pre_call
204
206 self.__pre_call.append( code )
207
208 @property
209 - def post_call( self ):
210 return self.__post_call
211
212 - def add_post_call_code( self, code ):
213 self.__post_call.append( code )
214
228
229 - def apply( self, transformations ):
231
232 @property
234 return self.__inst_arg
235
239
240 - def apply( self, transformations ):
242
257
258 @property
261
262 @property
265
268
271
272 @property
274 return self.__py_function_var
275
276 @property
278 return self.__py_pre_call
279
281 self.__py_pre_call.append( code )
282
283 @property
284 - def py_post_call( self ):
285 return self.__py_post_call
286
287 - def add_py_post_call_code( self, code ):
288 self.__py_post_call.append( code )
289
290 @property
292 return self.__py_result_var
293
294 @property
296 return filter( None, self.__py_arg_expressions )
297
299 self.__py_arg_expressions[ index ] = None
300
303
315
316 @property
318 return self.__inst_arg
319
320 @property
323
328
329 - def apply( self, transformations ):
331
332 @property
334 return self.__override_cntrl
335
336 @property
338 return self.__default_cntrl
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415