pyplusplus.messages.warnings_

Package pyplusplus :: Package messages :: Module warnings_ |

# Source Code for Module pyplusplus.messages.warnings_

      1  # Copyright 2004-2008 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 package defines all user messages (warnings + errors), which will be
      7  reported to user.
      8  """
      9
     10 -class message_type(str):
     11      """implementation details"""
     12 -    def __new__(self, value, identifier=None):
     13          return str.__new__(self, value )
     14
     15 -    def __init__(self, value, identifier=None):
     16          self.__identifier = identifier
     17
     18      @property
     19 -    def identifier( self ):
     20          return self.__identifier
     21
     22 -    def __mod__( self, values ):
     23          str_value = super( message_type, self ).__str__()
     24          return self.__class__( str_value % values, self.identifier )
     25
     26 -class warning( message_type ):
     27      prefix = 'warning'
     28
     29 -class compilation_error( message_type ):
     30      prefix = 'compilation error'
     31
     32 -class execution_error( message_type ):
     33      prefix = 'execution error'
     34
     35 -class code_generation_error( message_type ):
     36      prefix = 'code generation error'
     37
     38
     39  W0000 = warning( '%s' ) #general message, usefull in few cases
     40
     41  W1000 = compilation_error(
     42              'Py++, by default, does not expose internal compilers declarations. '
     43              'Names of those declarations usually start with "__".' )
     44
     45  W1001 = compilation_error(
     46              'Py++, by default, does not expose internal declarations. '
     47              'GCC-XML reports that these declaration belong to "<internal>" header.' )
     48
     49  W1002 = compilation_error(
     50              'Py++, by default, does not expose compiler generated declarations.' )
     51
     52  W1003 = warning(
     53              'Virtual functions that returns const reference cannot be overridden from Python. '
     54              'Reason: boost::python::override::operator()(...) saves the result of the marshaling '
     55              '(from Python to C++) on the stack. Thus operator() returns reference '
     56              'to a temporary variable. Consider to use "Function Transformation" functionality '
     57              'to solve the problem.' )
     58
     59  W1004 = compilation_error(
     60              'Boost.Python library can not expose function, which takes as argument/returns '
     61              'pointer to function. '
     62              ' See http://www.boost.org/libs/python/doc/v2/faq.html#funcptr for more information.' )
     63
     64  W1005 = compilation_error(
     65              'Py++ cannot expose function that takes as argument/returns instance of non-public class. '
     66              'Generated code will not compile.' )
     67
     68  W1006 = compilation_error(
     69              'Py++ need your help to expose function that takes as argument/returns C++ arrays. '
     70              'Take a look on "Function Transformation" functionality and define the transformation.' )
     71
     72  W1007 = warning(
     73              'The function has more than %d arguments ( %d ). '
     74              'You should adjust BOOST_PYTHON_MAX_ARITY macro. '
     75              'For more information see: http://www.boost.org/libs/python/doc/v2/configuration.html' )
     76
     77  W1008 = warning(
     78              'The function returns non-const reference to "Python immutable" type. '
     79              'The value cannot be modified from Python. ' )
     80
     81  W1009 = execution_error(
     82              'The function takes as argument (name=%s, pos=%d) non-const reference '
     83              'to Python immutable type - function could not be called from Python. '
     84              'Take a look on "Function Transformation" functionality and define the transformation.' )
     85
     86  W1010 = execution_error(
     87              'The function introduces registration order problem. '
     88              'For more information about the problem read next document: '
     89              'http://language-binding.net/pyplusplus/documentation/functions/registration_order.html '
     90              'Problematic functions list: %s' )
     91
     92  W1011 = warning( "Py++ doesn't export private not virtual functions." )
     93
     94  W1012 = compilation_error( 'Py++ does not exports compiler generated constructors.' )
     95
     96  W1013 = compilation_error( "Py++ doesn't export private constructor." )
     97
     98  W1014 = compilation_error(
     99              '"%s" is not supported. '
    100              'See Boost.Python documentation: http://www.boost.org/libs/python/doc/v2/operators.html#introduction.' )
    101
    102  W1015 = compilation_error( "Py++ doesn't export private operators." )
    103
    104  W1016 = warning(
    105              'Py++ does not exports non-const casting operators with user defined type as return value. '
    106              'This could be changed in future.' )
    107
    108  W1017 = compilation_error( "Py++ doesn't export non-public casting operators." )
    109
    110  W1018 = compilation_error( 'Py++ can not expose anonymous class "%s", declared in a namespace.' )
    111
    112  W1019 = compilation_error( 'Py++ can not expose private class.' )
    113
    114  W1020 = warning( "Py++ will generate class wrapper - hand written code should be added to the wrapper class" )
    115
    116  W1021 = warning( "Py++ will generate class wrapper - hand written code should be added to the wrapper class null constructor body" )
    117
    118  W1022 = warning( "Py++ will generate class wrapper - hand written code should be added to the wrapper class copy constructor body" )
    119
    120  W1023 = warning(
    121              "Py++ will generate class wrapper - there are few functions that should be redefined in class wrapper. "
    122              "The functions are: %s." )
    123
    124  W1024 = warning( 'Py++ will generate class wrapper - class contains "%s" - bit field member variable' )
    125
    126  W1025 = warning( 'Py++ will generate class wrapper - class contains "%s" - T* member variable' )
    127
    128  W1026 = warning( 'Py++ will generate class wrapper - class contains "%s" - T& member variable' )
    129
    130  W1027 = warning( 'Py++ will generate class wrapper - class contains "%s" - array member variable' )
    131
    132  W1028 = warning( 'Py++ will generate class wrapper - class contains definition of nested class "%s", which requires wrapper class' )
    133
    134  W1029 = warning( "Py++ will generate class wrapper - hand written code should be added to the wrapper class constructor body" )
    135
    136  W1030 = warning( 'Py++ will generate class wrapper - class contains "%s" - [pure] virtual member function' )
    137
    138  W1031 = warning( 'Py++ will generate class wrapper - user asked to expose non - public member function "%s"' )
    139
    140  W1032 = execution_error(
    141              "Boost.Python library does not support enums with duplicate values. "
    142              "You can read more about this here: "
    143              "http://boost.org/libs/python/todo.html#support-for-enums-with-duplicate-values . "
    144              "The quick work around is to add new class variable to the exported enum, from Python. " )
    145
    146  W1033 = compilation_error( "Py++ can not expose anonymous variables" )
    147
    148  W1034 = compilation_error( "Py++ can not expose alignment bit." )
    149
    150  W1035 = compilation_error( "Py++ can not expose static pointer member variables. This could be changed in future." )
    151
    152  W1036 = compilation_error( "Py++ can not expose pointer to Python immutable member variables. This could be changed in future." )
    153
    154  W1037 = compilation_error(
    155              "Boost.Python library can not expose variables, which are pointer to function."
    156              " See http://www.boost.org/libs/python/doc/v2/faq.html#funcptr for more information." )
    157
    158  W1038 = compilation_error( "Py++ can not expose variables of with anonymous type." )
    159
    160  W1039 = compilation_error( "Py++ doesn't expose private or protected member variables." )
    161
    162  W1040 = execution_error(
    163              'The declaration is unexposed, but there are other declarations, which refer to it. '
    164              'This could cause "no to_python converter found" run time error. '
    165              'Declarations: %s' )
    166
    167  W1041 = warning(
    168              'Property "%s" could not be created. There is another exposed declaration with the same name( alias )." '
    169              'The property will make it inaccessible.' )
    170
    171  W1042 = warning(
    172              'Py++ can not find out container value_type( mapped_type ). '
    173              'The container class is template instantiation declaration and not definition. '
    174              'This container class will be exported, but there is a possibility, that '
    175              'generated code will not compile or will lack some functionality. '
    176              'The solution to the problem is to create a variable of the class.' )
    177
    178  W1043 = warning( 'Py++ created an ugly alias ("%s") for template instantiated class.' )
    179
    180  W1044 = warning( 'Py++ created an ugly alias ("%s") for function wrapper.' )
    181
    182  W1045 = compilation_error(
    183              'Py++ does not expose static arrays with unknown size. '
    184              'You can fix this by setting array size to the actual one.'
    185              'For more information see "array_t" class documentation.' )
    186
    187  W1046 = warning(
    188              'The virtual function was declared with empty throw. '
    189              'Adding the ability to override the function from Python breaks the exception specification. '
    190              'The function wrapper can throw any exception. '
    191              'In case of exception in run-time, the behaviour of the program is undefined! ' )
    192
    193  W1047 = warning(
    194              'There are two or more classes that use same alias("%s"). '
    195              'Duplicated aliases causes few problems, but the main one is that some '
    196              'of the classes will not be exposed to Python.'
    197              'Other classes : %s' )
    198
    199  W1048 = warning(
    200              'There are two or more aliases within "pyplusplus::aliases" namespace for '
    201              'the class. Py++ selected "%s" as class alias. Other aliases: %s' )
    202
    203  W1049 = warning(
    204              'This method could not be overriden in Python - method returns reference '
    205              'to local variable!' )
    206
    207  W1050 = compilation_error(
    208              'The function returns "%s" type. You have to specify a call policies.'
    209              'Be sure to take a look on Py++ defined call policies: '
    210              'http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#py-defined-call-policies' )
    211
    212  W1051 = warning(
    213              'The function takes as argument (name=%s, pos=%d) "%s" type. '
    214              'You have to specify a call policies or to use "Function Transformation" '
    215              'functionality.' )
    216
    217  W1052 = warning(
    218              'Py++ will not expose free operator "%s" - all classes, this operator works on, are excluded.' )
    219
    220  W1053 = warning(
    221              'Py++ will not expose function "%s" - the function has variable-argument list, spicified by ellipsis (...).' )
    222
    223  W1054 = compilation_error( 'Py++ can not expose unions.' )
    224
    225  W1055 = warning( "Py++ will generate class wrapper - hand written code should be added to the wrapper class destructor body" )
    226
    227  W1056 = compilation_error( "Py++ can not expose array of pointers of Python immutable types. Take a look on 'ctypes integration' feature." )
    228
    229  W1057 = compilation_error( 'Py++ can not expose "%s" - it does not belong to named class.' )
    230
    231  W1058 = compilation_error( 'Py++ can not expose "%s" it belongs to anonymous class'
    232                             ' and requires additional code to expose.'
    233                             ' This could be changed in future.')
    234
    235  W1059 = compilation_error( 'Py++ can not expose "%s" - it requires additional code to expose.'
    236                             ' This could be changed in future.')
    237
    238  W1060 = compilation_error( 'Py++ can not expose "%s" - it has name, Py++ only exposes anonymous unions.'
    239                             ' This could be changed in future.')
    240
    241  W1061 = compilation_error( 'Py++ can not expose "%s" - its type is "%s".'
    242                             ' This could be changed in future.')
    243
    244  W1062 = compilation_error( '"%s" contains "fake constructor" "%s", that was excluded.'
    245                             ' Py++ will not generate "__init__" method, based on that function.')
    246
    247  W1063 = compilation_error( '"%s" contains "fake constructor" "%s", that is exportable.'
    248                             ' Py++ will not generate "__init__" method, based on that function.')
    249
    250  W1064 = compilation_error( 'Py++ can not expose "%s" as "fake constructor" of "%s".'
    251                             ' Only the following function types supported: %s' )
    252
    253  W1065 = code_generation_error(
    254              'There are two or more classes that use same class wrapper alias("%s"). '
    255              'Duplicated class wrapper aliases causes few problems, but the main one is that during '
    256              'files generation Py++ uses class wrapper aliases for the file names. '
    257              'Py++ will rewrite the file content and at best will introduce compile time error. '
    258              'The worst case scenario: you will discover the problem during run-time.'
    259              'Use `wrapper_alias` property to change class wrapper alias value'
    260              'Other classes : %s' )
    261
    262
    263  warnings = globals()
    264
    265  all_warning_msgs = []
    266
    267  for identifier, explanation in warnings.items():
    268      if len( identifier ) != 5:
    269          continue
    270      if identifier[0] != 'W':
    271          continue
    272      try:
    273          int( identifier[1:] )
    274      except:
    275          continue
    276      msg = '%s %s: %s' % ( explanation.__class__.prefix, identifier, str(explanation) )
    277      msg_inst = explanation.__class__( msg, identifier )
    278      globals()[ identifier ] = msg_inst
    279      all_warning_msgs.append( msg_inst )
    280
    281
    282  del warnings
    283  del identifier
    284  del explanation
    285
    286
    287  if __name__ == '__main__':
    288      x = W1051 % ( 'xxxxxxxx', 122, 'yyyyyyyyyy' )
    289      print x
    290      print x.__class__.__name__
    291
    292      print '\n\n\n'
    293
    294      y = W1000
    295      print y
    296