Package pyplusplus :: Package function_transformers :: Module transformer

Source Code for Module pyplusplus.function_transformers.transformer

 1  # Copyright 2006 Roman Yakovenko. 
 2  # Distributed under the Boost Software License, Version 1.0. (See 
 3  # accompanying file LICENSE_1_0.txt or copy at 
 4  # http://www.boost.org/LICENSE_1_0.txt) 
 5   
 6  """This module contains the class L{transformer_t}. 
 7  """ 
 8   
 9  import sys, os.path, copy, re, types 
10  from pygccxml import declarations, parser 
11   
12  return_ = -1 
13 #return_ is a spacial const, which represent an index of return type 14 15 -class transformer_t(object):
16 """Base class for a function transformer.""" 17 18 USE_1_BASED_INDEXING = False 19
20 - def __init__(self, function):
21 """@param function: reference to function declaration""" 22 object.__init__( self ) 23 self.__function = function
24 25 @property
26 - def function( self ):
27 """reference to the function, for which a wrapper will be generated""" 28 return self.__function
29
30 - def required_headers( self ):
31 """Returns list of header files that transformer generated code depends on.""" 32 raise NotImplementedError( self.__class__.__name__ )
33
34 - def get_argument( self, reference ):
35 """returns reference to the desired argument 36 37 @param reference: name( str ) or index( int ) of the argument 38 """ 39 if isinstance( reference, str ): 40 found = filter( lambda arg: arg.name == reference, self.function.arguments ) 41 if len( found ) == 1: 42 return found[0] 43 raise RuntimeError( "Argument with %s was not found" % reference ) 44 else: 45 assert isinstance( reference, int ) 46 if transformer_t.USE_1_BASED_INDEXING: 47 reference += 1 48 return self.function.arguments[ reference ]
49
50 - def get_type( self, reference ):
51 """returns type of the desired argument or return type of the function 52 53 @param reference: name( str ) or index( int ) of the argument 54 """ 55 global return_ 56 if isinstance( reference, int ) and reference == return_: 57 return self.function.return_type 58 else: 59 return self.get_argument( reference ).type
60
61 - def configure_mem_fun( self, controller ):
62 """Transformers should overridde the method, in order to define custom 63 transformation for non-virtual member function. 64 65 @param controller: instance of L{mem_fun_controller_t} class 66 """ 67 raise NotImplementedError(self.__class__.__name__)
68
69 - def configure_free_fun( self, controller ):
70 """Transformers should overridde the method, in order to define custom 71 transformation for free function. 72 73 @param controller: instance of L{free_fun_controller_t} class 74 """ 75 raise NotImplementedError(self.__class__.__name__)
76
77 - def configure_virtual_mem_fun( self, controller ):
78 """Transformers should overridde the method, in order to define custom 79 transformation for virtual member function. 80 81 @param controller: instance of L{virtual_mem_fun_controller_t} class 82 """ 83 raise NotImplementedError(self.__class__.__name__)
84 85 #TODO: FT for constructor 86 #~ def configure_constructor( self, controller ): 87 #~ """Transformers should overridde the method, in order to define custom 88 #~ transformation for constructor. 89 90 #~ @param controller: instance of L{constructor_controller_t} class 91 #~ """ 92 #~ raise NotImplementedError(self.__class__.__name__) 93