4444 """
4545'''
4646
47- decl_banner = autogen_top + '''
48- from .types cimport *
49-
50- cdef extern from *:
51- '''
52-
5347
5448function_re = re .compile (r"^[A-Za-z][A-Za-z0-9_]*$" )
5549function_blacklist = {"O" , # O(p^e) needs special parser support
@@ -75,7 +69,27 @@ class PariFunctionGenerator(object):
7569 def __init__ (self ):
7670 self .gen_filename = os .path .join ('cypari2' , 'auto_gen.pxi' )
7771 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 " )
7993
8094 def can_handle_function (self , function , cname = "" , ** kwds ):
8195 """
@@ -107,9 +121,10 @@ def can_handle_function(self, function, cname="", **kwds):
107121 if sec == "programming/control" :
108122 # Skip if, return, break, ...
109123 return False
124+
110125 return True
111126
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 ):
113128 r"""
114129 Handle one PARI function: decide whether or not to add the
115130 function, in which file (as method of :class:`Gen` or
@@ -118,8 +133,8 @@ def handle_pari_function(self, function, cname, prototype="", help="", obsolete=
118133
119134 EXAMPLES::
120135
121- >>> from autogen.parser import read_pari_desc
122136 >>> from autogen.generator import PariFunctionGenerator
137+ >>> import sys
123138 >>> G = PariFunctionGenerator()
124139 >>> G.gen_file = sys.stdout
125140 >>> G.instance_file = sys.stdout
@@ -201,13 +216,14 @@ def bernvec(self, long x):
201216 return new_gen(_ret)
202217 <BLANKLINE>
203218 """
204- try :
205- args , ret = parse_prototype (prototype , help )
206- except NotImplementedError :
207- return # Skip unsupported prototype codes
208-
219+ if args is None or ret is None :
220+ aargs , rret = parse_prototype (prototype , help )
221+ if args is None :
222+ args = aargs
223+ if ret is None :
224+ ret = rret
225+ sys .stdout .flush ()
209226 doc = get_rest_doc (function )
210-
211227 self .write_declaration (cname , args , ret , self .decl_file )
212228
213229 if len (args ) > 0 and isinstance (args [0 ], PariArgumentGEN ):
@@ -293,29 +309,43 @@ def __call__(self):
293309 """
294310 D = read_pari_desc ()
295311 D = sorted (D .values (), key = lambda d : d ['function' ])
296- sys .stdout .write ("Generating PARI functions:" )
297312
298313 self .gen_file = io .open (self .gen_filename + '.tmp' , 'w' , encoding = 'utf-8' )
299314 self .gen_file .write (gen_banner )
300315 self .instance_file = io .open (self .instance_filename + '.tmp' , 'w' , encoding = 'utf-8' )
301316 self .instance_file .write (instance_banner )
302317 self .decl_file = io .open (self .decl_filename + '.tmp' , 'w' , encoding = 'utf-8' )
303- self .decl_file .write (decl_banner )
318+
319+ DD = []
320+ sys .stdout .write ("Unhandled PARI function:\n " )
321+ for v in D :
322+ func = v ["function" ]
323+ if not self .can_handle_function (** v ):
324+ sys .stdout .write (" (%s)" % func )
325+ else :
326+ try :
327+ args , ret = parse_prototype (v ["prototype" ], v ["help" ])
328+ v ["args" ] = args
329+ v ["ret" ] = ret
330+ DD .append (v )
331+ except NotImplementedError :
332+ sys .stdout .write (" ((%s))" % func )
333+ sys .stdout .write ("\n " )
334+
335+ self .write_paridecl_no_desc (DD )
304336
305337 # Check for availability of hi-res SVG plotting. This requires
306338 # PARI-2.10 or later.
307339 have_plot_svg = False
308340
309- for v in D :
341+ sys .stdout .write ("Generating PARI functions:\n " )
342+ for v in DD :
310343 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 )
344+ sys .stdout .write (" %s" % func )
345+ self .handle_pari_function (** v )
346+ sys .stdout .flush ()
347+ if func == "plothraw" :
348+ have_plot_svg = True
319349 sys .stdout .write ("\n " )
320350
321351 self .instance_file .write ("DEF HAVE_PLOT_SVG = {}" .format (have_plot_svg ))
0 commit comments