Package pyplusplus :: Package function_transformers :: Module function_transformation |

# Source Code for Module pyplusplus.function_transformers.function_transformation

     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{function_transformation_t}.
     7  """
     8  import md5
     9  import controllers
    10  from pygccxml import declarations
    11  from pyplusplus import code_repository
    12
    13 -class function_transformation_t:
    14 -    def __init__(self, function, transformer_creator, **keywd):
    15          """Constructor. """
    16          self.__function = function
    17          self.__controller = None
    18          if isinstance( function.parent, declarations.class_t ):
    19              if declarations.VIRTUALITY_TYPES.NOT_VIRTUAL == function.virtuality:
    20                  self.__controller = controllers.mem_fun_controller_t( function )
    21              else:
    22                  self.__controller = controllers.virtual_mem_fun_controller_t( function )
    23          else:
    24              self.__controller = controllers.free_fun_controller_t( function )
    25          self.__transformers = map( lambda tr_creator: tr_creator( function ), transformer_creator )
    26          self.__thread_safe = keywd.get( 'thread_safe', False )
    27          self.__controller.apply( self.__transformers )
    28          self.__unique_name = None
    29          self.__alias = keywd.get( 'alias', None )
    30
    31      @property
    32 -    def unique_name( self ):
    33          if None is self.__unique_name:
    34              obj = md5.new()
    35              if self.__function.mangled: # free functions don't have a mangled value
    36                  obj.update( self.__function.mangled )
    37              else:
    38                  obj.update( self.__function.decl_string )
    39                  obj.update( self.__function.location.file_name )
    40                  obj.update( str( self.__function.location.line ) )
    41              self.__unique_name = self.__function.name + '_' + obj.hexdigest ()
    42          return self.__unique_name
    43
    44      @property
    45 -    def alias( self ):
    46          if None is self.__alias:
    47              if self.__function.overloads:
    48                  self.__alias = self.unique_name
    49              else:
    50                  self.__alias = self.__function.alias
    51          return self.__alias
    52
    53      @property
    54 -    def transformers( self ):
    55          return self.__transformers
    56
    57      @property
    58 -    def controller( self ):
    59          return self.__controller
    60
    61 -    def required_headers( self ):
    62          headers = []
    63          map( lambda transformer: headers.extend( transformer.required_headers() )
    64               , self.transformers )
    65          if self.__function.call_policies:
    66              headers.append( code_repository.call_policies.file_name )
    67          return headers
    68
    69      @property
    70 -    def thread_safe( self ):
    71          return self.__thread_safe
    72