50
50
"""
51
51
'''
52
52
53
- decl_banner = autogen_top + '''
54
- from .types cimport *
55
-
56
- cdef extern from *:
57
- '''
58
-
59
53
60
54
function_re = re .compile (r"^[A-Za-z][A-Za-z0-9_]*$" )
61
55
function_blacklist = {"O" , # O(p^e) needs special parser support
@@ -82,7 +76,27 @@ class PariFunctionGenerator(object):
82
76
def __init__ (self ):
83
77
self .gen_filename = os .path .join ('cypari2' , 'auto_gen.pxi' )
84
78
self .instance_filename = os .path .join ('cypari2' , 'auto_instance.pxi' )
85
- self .decl_filename = os .path .join ('cypari2' , 'auto_paridecl.pxd' )
79
+ self .decl_filename = os .path .join ('cypari2' , 'paridecl.pxd' )
80
+
81
+ def write_paridecl_no_desc (self , D ):
82
+ r"""
83
+ Write the template ``template_paridecl.pxd`` into the declaration file
84
+ after removing all functions from ``D`` (that are obtained from
85
+ ``pari.desc``).
86
+ """
87
+ fnc = re .compile (" (int|long|void|GEN) +([A-Za-z][0-9A-Za-z_]*)\(.*\)" )
88
+
89
+ functions = set (f .get ('cname' ) for f in D )
90
+
91
+ with open ('autogen/template_paridecl.pxd' ) as template :
92
+ for line in template .read ().split ('\n ' ):
93
+ match = fnc .match (line )
94
+ if match :
95
+ out_type , fname = match .groups ()
96
+ if fname in functions :
97
+ continue
98
+ self .decl_file .write (line )
99
+ self .decl_file .write ("\n " )
86
100
87
101
def can_handle_function (self , function , cname = "" , ** kwds ):
88
102
"""
@@ -117,9 +131,10 @@ def can_handle_function(self, function, cname="", **kwds):
117
131
if sec == "programming/control" :
118
132
# Skip if, return, break, ...
119
133
return False
134
+
120
135
return True
121
136
122
- def handle_pari_function (self , function , cname , prototype = "" , help = "" , obsolete = None , ** kwds ):
137
+ def handle_pari_function (self , function , cname , prototype , help , args = None , ret = None , obsolete = None , ** kwds ):
123
138
r"""
124
139
Handle one PARI function: decide whether or not to add the
125
140
function, in which file (as method of :class:`Gen` or
@@ -128,8 +143,8 @@ def handle_pari_function(self, function, cname, prototype="", help="", obsolete=
128
143
129
144
EXAMPLES::
130
145
131
- >>> from autogen.parser import read_pari_desc
132
146
>>> from autogen.generator import PariFunctionGenerator
147
+ >>> import sys
133
148
>>> G = PariFunctionGenerator()
134
149
>>> G.gen_file = sys.stdout
135
150
>>> G.instance_file = sys.stdout
@@ -226,13 +241,14 @@ def polredord(self, x):
226
241
return new_gen(_ret)
227
242
<BLANKLINE>
228
243
"""
229
- try :
230
- args , ret = parse_prototype (prototype , help )
231
- except NotImplementedError :
232
- return # Skip unsupported prototype codes
233
-
244
+ if args is None or ret is None :
245
+ aargs , rret = parse_prototype (prototype , help )
246
+ if args is None :
247
+ args = aargs
248
+ if ret is None :
249
+ ret = rret
250
+ sys .stdout .flush ()
234
251
doc = get_rest_doc (function )
235
-
236
252
self .write_declaration (cname , args , ret , self .decl_file )
237
253
238
254
if len (args ) > 0 and isinstance (args [0 ], PariArgumentGEN ):
@@ -320,29 +336,43 @@ def __call__(self):
320
336
"""
321
337
D = read_pari_desc ()
322
338
D = sorted (D .values (), key = lambda d : d ['function' ])
323
- sys .stdout .write ("Generating PARI functions:" )
324
339
325
340
self .gen_file = io .open (self .gen_filename + '.tmp' , 'w' , encoding = 'utf-8' )
326
341
self .gen_file .write (gen_banner )
327
342
self .instance_file = io .open (self .instance_filename + '.tmp' , 'w' , encoding = 'utf-8' )
328
343
self .instance_file .write (instance_banner )
329
344
self .decl_file = io .open (self .decl_filename + '.tmp' , 'w' , encoding = 'utf-8' )
330
- self .decl_file .write (decl_banner )
345
+
346
+ DD = []
347
+ sys .stdout .write ("Unhandled PARI function:\n " )
348
+ for v in D :
349
+ func = v ["function" ]
350
+ if not self .can_handle_function (** v ):
351
+ sys .stdout .write (" (%s)" % func )
352
+ else :
353
+ try :
354
+ args , ret = parse_prototype (v ["prototype" ], v ["help" ])
355
+ v ["args" ] = args
356
+ v ["ret" ] = ret
357
+ DD .append (v )
358
+ except NotImplementedError :
359
+ sys .stdout .write (" ((%s))" % func )
360
+ sys .stdout .write ("\n " )
361
+
362
+ self .write_paridecl_no_desc (DD )
331
363
332
364
# Check for availability of hi-res SVG plotting. This requires
333
365
# PARI-2.10 or later.
334
366
have_plot_svg = False
335
367
336
- for v in D :
368
+ sys .stdout .write ("Generating PARI functions:\n " )
369
+ for v in DD :
337
370
func = v ["function" ]
338
- if self .can_handle_function (** v ):
339
- sys .stdout .write (" %s" % func )
340
- sys .stdout .flush ()
341
- self .handle_pari_function (** v )
342
- if func == "plothraw" :
343
- have_plot_svg = True
344
- else :
345
- sys .stdout .write (" (%s)" % func )
371
+ sys .stdout .write (" %s" % func )
372
+ self .handle_pari_function (** v )
373
+ sys .stdout .flush ()
374
+ if func == "plothraw" :
375
+ have_plot_svg = True
346
376
sys .stdout .write ("\n " )
347
377
348
378
self .instance_file .write ("DEF HAVE_PLOT_SVG = {}" .format (have_plot_svg ))
0 commit comments