44
44
"""
45
45
'''
46
46
47
- decl_banner = autogen_top + '''
48
- from .types cimport *
49
-
50
- cdef extern from *:
51
- '''
52
-
53
47
54
48
function_re = re .compile (r"^[A-Za-z][A-Za-z0-9_]*$" )
55
49
function_blacklist = {"O" , # O(p^e) needs special parser support
@@ -75,7 +69,27 @@ class PariFunctionGenerator(object):
75
69
def __init__ (self ):
76
70
self .gen_filename = os .path .join ('cypari2' , 'auto_gen.pxi' )
77
71
self .instance_filename = os .path .join ('cypari2' , 'auto_instance.pxi' )
78
- self .decl_filename = os .path .join ('cypari2' , 'auto_paridecl.pxd' )
72
+ self .decl_filename = os .path .join ('cypari2' , 'paridecl.pxd' )
73
+
74
+ def write_paridecl_no_desc (self , D ):
75
+ r"""
76
+ Write the template ``template_paridecl.pxd`` into the declaration file
77
+ after removing all functions from ``D`` (that are obtained from
78
+ ``pari.desc``).
79
+ """
80
+ fnc = re .compile (" (int|long|void|GEN) +([A-Za-z][0-9A-Za-z_]*)\(.*\)" )
81
+
82
+ functions = set (f .get ('cname' ) for f in D )
83
+
84
+ with open ('autogen/template_paridecl.pxd' ) as template :
85
+ for line in template .read ().split ('\n ' ):
86
+ match = fnc .match (line )
87
+ if match :
88
+ out_type , fname = match .groups ()
89
+ if fname in functions :
90
+ continue
91
+ self .decl_file .write (line )
92
+ self .decl_file .write ("\n " )
79
93
80
94
def can_handle_function (self , function , cname = "" , ** kwds ):
81
95
"""
@@ -107,9 +121,10 @@ def can_handle_function(self, function, cname="", **kwds):
107
121
if sec == "programming/control" :
108
122
# Skip if, return, break, ...
109
123
return False
124
+
110
125
return True
111
126
112
- def handle_pari_function (self , function , cname , prototype = "" , help = "" , obsolete = None , ** kwds ):
127
+ def handle_pari_function (self , function , cname , prototype , help , args = None , ret = None , obsolete = None , ** kwds ):
113
128
r"""
114
129
Handle one PARI function: decide whether or not to add the
115
130
function, in which file (as method of :class:`Gen` or
@@ -118,8 +133,8 @@ def handle_pari_function(self, function, cname, prototype="", help="", obsolete=
118
133
119
134
EXAMPLES::
120
135
121
- >>> from autogen.parser import read_pari_desc
122
136
>>> from autogen.generator import PariFunctionGenerator
137
+ >>> import sys
123
138
>>> G = PariFunctionGenerator()
124
139
>>> G.gen_file = sys.stdout
125
140
>>> G.instance_file = sys.stdout
@@ -201,13 +216,10 @@ def bernvec(self, long x):
201
216
return new_gen(_ret)
202
217
<BLANKLINE>
203
218
"""
204
- try :
219
+ if args is None or ret is None :
205
220
args , ret = parse_prototype (prototype , help )
206
- except NotImplementedError :
207
- return # Skip unsupported prototype codes
208
-
221
+ sys .stdout .flush ()
209
222
doc = get_rest_doc (function )
210
-
211
223
self .write_declaration (cname , args , ret , self .decl_file )
212
224
213
225
if len (args ) > 0 and isinstance (args [0 ], PariArgumentGEN ):
@@ -222,6 +234,8 @@ def bernvec(self, long x):
222
234
self .write_method (function , cname , args , ret , args [1 :],
223
235
self .instance_file , doc , obsolete )
224
236
237
+ return 0
238
+
225
239
def write_declaration (self , cname , args , ret , file ):
226
240
"""
227
241
Write a .pxd declaration of a PARI library function.
@@ -293,29 +307,43 @@ def __call__(self):
293
307
"""
294
308
D = read_pari_desc ()
295
309
D = sorted (D .values (), key = lambda d : d ['function' ])
296
- sys .stdout .write ("Generating PARI functions:" )
297
310
298
311
self .gen_file = io .open (self .gen_filename + '.tmp' , 'w' , encoding = 'utf-8' )
299
312
self .gen_file .write (gen_banner )
300
313
self .instance_file = io .open (self .instance_filename + '.tmp' , 'w' , encoding = 'utf-8' )
301
314
self .instance_file .write (instance_banner )
302
315
self .decl_file = io .open (self .decl_filename + '.tmp' , 'w' , encoding = 'utf-8' )
303
- self .decl_file .write (decl_banner )
316
+
317
+ DD = []
318
+ sys .stdout .write ("Unhandled PARI function:\n " )
319
+ for v in D :
320
+ func = v ["function" ]
321
+ if not self .can_handle_function (** v ):
322
+ sys .stdout .write (" (%s)" % func )
323
+ else :
324
+ try :
325
+ args , ret = parse_prototype (v ["prototype" ], v ["help" ])
326
+ v ["args" ] = args
327
+ v ["ret" ] = ret
328
+ DD .append (v )
329
+ except NotImplementedError :
330
+ sys .stdout .write (" ((%s))" % func )
331
+ sys .stdout .write ("\n " )
332
+
333
+ self .write_paridecl_no_desc (DD )
304
334
305
335
# Check for availability of hi-res SVG plotting. This requires
306
336
# PARI-2.10 or later.
307
337
have_plot_svg = False
308
338
309
- for v in D :
339
+ sys .stdout .write ("Generating PARI functions:\n " )
340
+ for v in DD :
310
341
func = v ["function" ]
311
- if self .can_handle_function (** v ):
312
- sys .stdout .write (" %s" % func )
313
- sys .stdout .flush ()
314
- self .handle_pari_function (** v )
315
- if func == "plothraw" :
316
- have_plot_svg = True
317
- else :
318
- sys .stdout .write (" (%s)" % func )
342
+ sys .stdout .write (" %s" % func )
343
+ self .handle_pari_function (** v )
344
+ sys .stdout .flush ()
345
+ if func == "plothraw" :
346
+ have_plot_svg = True
319
347
sys .stdout .write ("\n " )
320
348
321
349
self .instance_file .write ("DEF HAVE_PLOT_SVG = {}" .format (have_plot_svg ))
0 commit comments