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