5050 """
5151'''
5252
53- decl_banner = autogen_top + '''
54- from .types cimport *
55-
56- cdef extern from *:
57- '''
58-
5953
6054function_re = re .compile (r"^[A-Za-z][A-Za-z0-9_]*$" )
6155function_blacklist = {"O" , # O(p^e) needs special parser support
@@ -82,7 +76,27 @@ class PariFunctionGenerator(object):
8276 def __init__ (self ):
8377 self .gen_filename = os .path .join ('cypari2' , 'auto_gen.pxi' )
8478 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 " )
86100
87101 def can_handle_function (self , function , cname = "" , ** kwds ):
88102 """
@@ -117,9 +131,10 @@ def can_handle_function(self, function, cname="", **kwds):
117131 if sec == "programming/control" :
118132 # Skip if, return, break, ...
119133 return False
134+
120135 return True
121136
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 ):
123138 r"""
124139 Handle one PARI function: decide whether or not to add the
125140 function, in which file (as method of :class:`Gen` or
@@ -128,8 +143,8 @@ def handle_pari_function(self, function, cname, prototype="", help="", obsolete=
128143
129144 EXAMPLES::
130145
131- >>> from autogen.parser import read_pari_desc
132146 >>> from autogen.generator import PariFunctionGenerator
147+ >>> import sys
133148 >>> G = PariFunctionGenerator()
134149 >>> G.gen_file = sys.stdout
135150 >>> G.instance_file = sys.stdout
@@ -226,13 +241,14 @@ def polredord(self, x):
226241 return new_gen(_ret)
227242 <BLANKLINE>
228243 """
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 ()
234251 doc = get_rest_doc (function )
235-
236252 self .write_declaration (cname , args , ret , self .decl_file )
237253
238254 if len (args ) > 0 and isinstance (args [0 ], PariArgumentGEN ):
@@ -320,29 +336,43 @@ def __call__(self):
320336 """
321337 D = read_pari_desc ()
322338 D = sorted (D .values (), key = lambda d : d ['function' ])
323- sys .stdout .write ("Generating PARI functions:" )
324339
325340 self .gen_file = io .open (self .gen_filename + '.tmp' , 'w' , encoding = 'utf-8' )
326341 self .gen_file .write (gen_banner )
327342 self .instance_file = io .open (self .instance_filename + '.tmp' , 'w' , encoding = 'utf-8' )
328343 self .instance_file .write (instance_banner )
329344 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 )
331363
332364 # Check for availability of hi-res SVG plotting. This requires
333365 # PARI-2.10 or later.
334366 have_plot_svg = False
335367
336- for v in D :
368+ sys .stdout .write ("Generating PARI functions:\n " )
369+ for v in DD :
337370 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
346376 sys .stdout .write ("\n " )
347377
348378 self .instance_file .write ("DEF HAVE_PLOT_SVG = {}" .format (have_plot_svg ))
0 commit comments