You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8099 lines
252 KiB

Merged revisions 53623-53858 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r53624 | peter.astrand | 2007-02-02 20:06:36 +0100 (Fri, 02 Feb 2007) | 1 line We had several if statements checking the value of a fd. This is unsafe, since valid fds might be zero. We should check for not None instead. ........ r53635 | kurt.kaiser | 2007-02-05 07:03:18 +0100 (Mon, 05 Feb 2007) | 2 lines Add 'raw' support to configHandler. Patch 1650174 Tal Einat. ........ r53641 | kurt.kaiser | 2007-02-06 00:02:16 +0100 (Tue, 06 Feb 2007) | 5 lines 1. Calltips now 'handle' tuples in the argument list (display '<tuple>' :) Suggested solution by Christos Georgiou, Bug 791968. 2. Clean up tests, were not failing when they should have been. 4. Remove some camelcase and an unneeded try/except block. ........ r53644 | kurt.kaiser | 2007-02-06 04:21:40 +0100 (Tue, 06 Feb 2007) | 2 lines Clean up ModifiedInterpreter.runcode() structure ........ r53646 | peter.astrand | 2007-02-06 16:37:50 +0100 (Tue, 06 Feb 2007) | 1 line Applied patch 1124861.3.patch to solve bug #1124861: Automatically create pipes on Windows, if GetStdHandle fails. Will backport. ........ r53648 | lars.gustaebel | 2007-02-06 19:38:13 +0100 (Tue, 06 Feb 2007) | 4 lines Patch #1652681: create nonexistent files in append mode and allow appending to empty files. ........ r53649 | kurt.kaiser | 2007-02-06 20:09:43 +0100 (Tue, 06 Feb 2007) | 4 lines Updated patch (CodeContext.061217.patch) to [ 1362975 ] CodeContext - Improved text indentation Tal Einat 16Dec06 ........ r53650 | kurt.kaiser | 2007-02-06 20:21:19 +0100 (Tue, 06 Feb 2007) | 2 lines narrow exception per [ 1540849 ] except too broad ........ r53653 | kurt.kaiser | 2007-02-07 04:39:41 +0100 (Wed, 07 Feb 2007) | 4 lines [ 1621265 ] Auto-completion list placement Move AC window below input line unless not enough space, then put it above. Patch: Tal Einat ........ r53654 | kurt.kaiser | 2007-02-07 09:07:13 +0100 (Wed, 07 Feb 2007) | 2 lines Handle AttributeError during calltip lookup ........ r53656 | raymond.hettinger | 2007-02-07 21:08:22 +0100 (Wed, 07 Feb 2007) | 3 lines SF #1615701: make d.update(m) honor __getitem__() and keys() in dict subclasses ........ r53658 | raymond.hettinger | 2007-02-07 22:04:20 +0100 (Wed, 07 Feb 2007) | 1 line SF: 1397711 Set docs conflated immutable and hashable ........ r53660 | raymond.hettinger | 2007-02-07 22:42:17 +0100 (Wed, 07 Feb 2007) | 1 line Check for a common user error with defaultdict(). ........ r53662 | raymond.hettinger | 2007-02-07 23:24:07 +0100 (Wed, 07 Feb 2007) | 1 line Bug #1575169: operator.isSequenceType() now returns False for subclasses of dict. ........ r53664 | raymond.hettinger | 2007-02-08 00:49:03 +0100 (Thu, 08 Feb 2007) | 1 line Silence compiler warning ........ r53666 | raymond.hettinger | 2007-02-08 01:07:32 +0100 (Thu, 08 Feb 2007) | 1 line Do not let overflows in enumerate() and count() pass silently. ........ r53668 | raymond.hettinger | 2007-02-08 01:50:39 +0100 (Thu, 08 Feb 2007) | 1 line Bypass set specific optimizations for set and frozenset subclasses. ........ r53670 | raymond.hettinger | 2007-02-08 02:42:35 +0100 (Thu, 08 Feb 2007) | 1 line Fix docstring bug ........ r53671 | martin.v.loewis | 2007-02-08 10:13:36 +0100 (Thu, 08 Feb 2007) | 3 lines Bug #1653736: Complain about keyword arguments to time.isoformat. Will backport to 2.5. ........ r53679 | kurt.kaiser | 2007-02-08 23:58:18 +0100 (Thu, 08 Feb 2007) | 6 lines Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented; mouse and cursor selection in ACWindow implemented; double Tab inserts current selection and closes ACW (similar to double-click and Return); scroll wheel now works in ACW. Added AutoComplete instructions to IDLE Help. ........ r53689 | martin.v.loewis | 2007-02-09 13:19:32 +0100 (Fri, 09 Feb 2007) | 3 lines Bug #1653736: Properly discard third argument to slot_nb_inplace_power. Will backport. ........ r53691 | martin.v.loewis | 2007-02-09 13:36:48 +0100 (Fri, 09 Feb 2007) | 4 lines Bug #1600860: Search for shared python library in LIBDIR, not lib/python/config, on "linux" and "gnu" systems. Will backport. ........ r53693 | martin.v.loewis | 2007-02-09 13:58:49 +0100 (Fri, 09 Feb 2007) | 2 lines Update broken link. Will backport to 2.5. ........ r53697 | georg.brandl | 2007-02-09 19:48:41 +0100 (Fri, 09 Feb 2007) | 2 lines Bug #1656078: typo in in profile docs. ........ r53731 | brett.cannon | 2007-02-11 06:36:00 +0100 (Sun, 11 Feb 2007) | 3 lines Change a very minor inconsistency (that is purely cosmetic) in the AST definition. ........ r53735 | skip.montanaro | 2007-02-11 19:24:37 +0100 (Sun, 11 Feb 2007) | 1 line fix trace.py --ignore-dir ........ r53741 | brett.cannon | 2007-02-11 20:44:41 +0100 (Sun, 11 Feb 2007) | 3 lines Check in changed Python-ast.c from a cosmetic change to Python.asdl (in r53731). ........ r53751 | brett.cannon | 2007-02-12 04:51:02 +0100 (Mon, 12 Feb 2007) | 5 lines Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c is specified at the top of the file. Also add a note that Python/Python-ast.c needs to be committed separately after a change to the AST grammar to capture the revision number of the change (which is what __version__ is set to). ........ r53752 | lars.gustaebel | 2007-02-12 10:25:53 +0100 (Mon, 12 Feb 2007) | 3 lines Bug #1656581: Point out that external file objects are supposed to be at position 0. ........ r53754 | martin.v.loewis | 2007-02-12 13:21:10 +0100 (Mon, 12 Feb 2007) | 3 lines Patch 1463026: Support default namespace in XMLGenerator. Fixes #847665. Will backport. ........ r53757 | armin.rigo | 2007-02-12 17:23:24 +0100 (Mon, 12 Feb 2007) | 4 lines Fix the line to what is my guess at the original author's meaning. (The line has no effect anyway, but is present because it's customary call the base class __init__). ........ r53763 | martin.v.loewis | 2007-02-13 09:34:45 +0100 (Tue, 13 Feb 2007) | 3 lines Patch #685268: Consider a package's __path__ in imputil. Will backport. ........ r53765 | martin.v.loewis | 2007-02-13 10:49:38 +0100 (Tue, 13 Feb 2007) | 2 lines Patch #698833: Support file decryption in zipfile. ........ r53766 | martin.v.loewis | 2007-02-13 11:10:39 +0100 (Tue, 13 Feb 2007) | 3 lines Patch #1517891: Make 'a' create the file if it doesn't exist. Fixes #1514451. ........ r53767 | martin.v.loewis | 2007-02-13 13:08:24 +0100 (Tue, 13 Feb 2007) | 3 lines Bug #1658794: Remove extraneous 'this'. Will backport to 2.5. ........ r53769 | martin.v.loewis | 2007-02-13 13:14:19 +0100 (Tue, 13 Feb 2007) | 3 lines Patch #1657276: Make NETLINK_DNRTMSG conditional. Will backport. ........ r53771 | lars.gustaebel | 2007-02-13 17:09:24 +0100 (Tue, 13 Feb 2007) | 4 lines Patch #1647484: Renamed GzipFile's filename attribute to name. The filename attribute is still accessible as a property that emits a DeprecationWarning. ........ r53772 | lars.gustaebel | 2007-02-13 17:24:00 +0100 (Tue, 13 Feb 2007) | 3 lines Strip the '.gz' extension from the filename that is written to the gzip header. ........ r53774 | martin.v.loewis | 2007-02-14 11:07:37 +0100 (Wed, 14 Feb 2007) | 2 lines Patch #1432399: Add HCI sockets. ........ r53775 | martin.v.loewis | 2007-02-14 12:30:07 +0100 (Wed, 14 Feb 2007) | 2 lines Update 1432399 to removal of _BT_SOCKADDR_MEMB. ........ r53776 | martin.v.loewis | 2007-02-14 12:30:56 +0100 (Wed, 14 Feb 2007) | 3 lines Ignore directory time stamps when considering whether to rerun libffi configure. ........ r53778 | lars.gustaebel | 2007-02-14 15:45:12 +0100 (Wed, 14 Feb 2007) | 4 lines A missing binary mode in AppendTest caused failures in Windows Buildbot. ........ r53782 | martin.v.loewis | 2007-02-15 10:51:35 +0100 (Thu, 15 Feb 2007) | 2 lines Patch #1397848: add the reasoning behind no-resize-on-shrinkage. ........ r53783 | georg.brandl | 2007-02-15 11:37:59 +0100 (Thu, 15 Feb 2007) | 2 lines Make functools.wraps() docs a bit clearer. ........ r53785 | georg.brandl | 2007-02-15 12:29:04 +0100 (Thu, 15 Feb 2007) | 2 lines Patch #1494140: Add documentation for the new struct.Struct object. ........ r53787 | georg.brandl | 2007-02-15 12:29:55 +0100 (Thu, 15 Feb 2007) | 2 lines Add missing \versionadded. ........ r53800 | brett.cannon | 2007-02-15 23:54:39 +0100 (Thu, 15 Feb 2007) | 11 lines Update the encoding package's search function to use absolute imports when calling __import__. This helps make the expected search locations for encoding modules be more explicit. One could use an explicit value for __path__ when making the call to __import__ to force the exact location searched for encodings. This would give the most strict search path possible if one is worried about malicious code being imported. The unfortunate side-effect of that is that if __path__ was modified on 'encodings' on purpose in a safe way it would not be picked up in future __import__ calls. ........ r53801 | brett.cannon | 2007-02-16 20:33:01 +0100 (Fri, 16 Feb 2007) | 2 lines Make the __import__ call in encodings.__init__ absolute with a level 0 call. ........ r53809 | vinay.sajip | 2007-02-16 23:36:24 +0100 (Fri, 16 Feb 2007) | 1 line Minor fix for currentframe (SF #1652788). ........ r53818 | raymond.hettinger | 2007-02-19 03:03:19 +0100 (Mon, 19 Feb 2007) | 3 lines Extend work on revision 52962: Eliminate redundant calls to PyObject_Hash(). ........ r53820 | raymond.hettinger | 2007-02-19 05:08:43 +0100 (Mon, 19 Feb 2007) | 1 line Add merge() function to heapq. ........ r53821 | raymond.hettinger | 2007-02-19 06:28:28 +0100 (Mon, 19 Feb 2007) | 1 line Add tie-breaker count to preserve sort stability. ........ r53822 | raymond.hettinger | 2007-02-19 07:59:32 +0100 (Mon, 19 Feb 2007) | 1 line Use C heapreplace() instead of slower _siftup() in pure python. ........ r53823 | raymond.hettinger | 2007-02-19 08:30:21 +0100 (Mon, 19 Feb 2007) | 1 line Add test for merge stability ........ r53824 | raymond.hettinger | 2007-02-19 10:14:10 +0100 (Mon, 19 Feb 2007) | 1 line Provide an example of defaultdict with non-zero constant factory function. ........ r53825 | lars.gustaebel | 2007-02-19 10:54:47 +0100 (Mon, 19 Feb 2007) | 2 lines Moved misplaced news item. ........ r53826 | martin.v.loewis | 2007-02-19 11:55:19 +0100 (Mon, 19 Feb 2007) | 3 lines Patch #1490190: posixmodule now includes os.chflags() and os.lchflags() functions on platforms where the underlying system calls are available. ........ r53827 | raymond.hettinger | 2007-02-19 19:15:04 +0100 (Mon, 19 Feb 2007) | 1 line Fixup docstrings for merge(). ........ r53829 | raymond.hettinger | 2007-02-19 21:44:04 +0100 (Mon, 19 Feb 2007) | 1 line Fixup set/dict interoperability. ........ r53837 | raymond.hettinger | 2007-02-21 06:20:38 +0100 (Wed, 21 Feb 2007) | 1 line Add itertools.izip_longest(). ........ r53838 | raymond.hettinger | 2007-02-21 18:22:05 +0100 (Wed, 21 Feb 2007) | 1 line Remove filler struct item and fix leak. ........
19 years ago
Merged revisions 56154-56264 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56155 | neal.norwitz | 2007-07-03 08:59:08 +0300 (Tue, 03 Jul 2007) | 1 line Get this test working after converting map to return an iterator ................ r56202 | neal.norwitz | 2007-07-09 04:30:09 +0300 (Mon, 09 Jul 2007) | 37 lines Merged revisions 56124-56201 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56129 | georg.brandl | 2007-06-30 04:01:01 -0700 (Sat, 30 Jun 2007) | 2 lines Document smtp.SMTPAuthenticationError. ........ r56137 | georg.brandl | 2007-07-01 01:11:35 -0700 (Sun, 01 Jul 2007) | 2 lines Fix a few webbrowser.py problems. ........ r56143 | georg.brandl | 2007-07-02 04:54:28 -0700 (Mon, 02 Jul 2007) | 2 lines Remove duplicate sentence from alarm() doc. ........ r56170 | mark.hammond | 2007-07-03 19:03:10 -0700 (Tue, 03 Jul 2007) | 3 lines copy built files to the PCBuild directory, where tools like distutils or external build processes can find them. ........ r56176 | kurt.kaiser | 2007-07-05 15:03:39 -0700 (Thu, 05 Jul 2007) | 10 lines Many calls to tk.call involve an arglist containing a single tuple. Calls using METH_OLDARGS unpack this tuple; calls using METH_VARARG don't. Tcl's concatenation of args was affected; IDLE doesn't start. Modify Tkapp_Call() to unpack single tuple arglists. Bug 1733943 Ref http://mail.python.org/pipermail/python-checkins/2007-May/060454.html ........ r56177 | neal.norwitz | 2007-07-05 21:13:39 -0700 (Thu, 05 Jul 2007) | 1 line Fix typo in comment ........ ................ r56251 | neal.norwitz | 2007-07-11 10:01:01 +0300 (Wed, 11 Jul 2007) | 1 line Get working with map returning an iterator (had to fix whitespace too) ................ r56255 | thomas.wouters | 2007-07-11 13:41:37 +0300 (Wed, 11 Jul 2007) | 6 lines Clean up merge glitch or copy-paste error (the entire module was duplicated, except the first half even had some more copy-paste errors, referring to listcomps and genexps instead of setcomps) ................ r56256 | thomas.wouters | 2007-07-11 15:16:01 +0300 (Wed, 11 Jul 2007) | 14 lines Dict comprehensions. Still needs doc changes (like many python-3000 features ;-). It generates bytecode similar to: x = {} for k, v in (generator here): x[k] = v except there is no tuple-packing and -unpacking involved. Trivial measurement suggests it's significantly faster than dict(generator here) (in the order of 2 to 3 times as fast) but I have not done extensive measurements. ................ r56263 | guido.van.rossum | 2007-07-11 15:36:26 +0300 (Wed, 11 Jul 2007) | 3 lines Patch 1724999 by Ali Gholami Rudi -- avoid complaints about dict size change during iter in destroy call. ................
19 years ago
Merged revisions 56154-56264 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56155 | neal.norwitz | 2007-07-03 08:59:08 +0300 (Tue, 03 Jul 2007) | 1 line Get this test working after converting map to return an iterator ................ r56202 | neal.norwitz | 2007-07-09 04:30:09 +0300 (Mon, 09 Jul 2007) | 37 lines Merged revisions 56124-56201 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56129 | georg.brandl | 2007-06-30 04:01:01 -0700 (Sat, 30 Jun 2007) | 2 lines Document smtp.SMTPAuthenticationError. ........ r56137 | georg.brandl | 2007-07-01 01:11:35 -0700 (Sun, 01 Jul 2007) | 2 lines Fix a few webbrowser.py problems. ........ r56143 | georg.brandl | 2007-07-02 04:54:28 -0700 (Mon, 02 Jul 2007) | 2 lines Remove duplicate sentence from alarm() doc. ........ r56170 | mark.hammond | 2007-07-03 19:03:10 -0700 (Tue, 03 Jul 2007) | 3 lines copy built files to the PCBuild directory, where tools like distutils or external build processes can find them. ........ r56176 | kurt.kaiser | 2007-07-05 15:03:39 -0700 (Thu, 05 Jul 2007) | 10 lines Many calls to tk.call involve an arglist containing a single tuple. Calls using METH_OLDARGS unpack this tuple; calls using METH_VARARG don't. Tcl's concatenation of args was affected; IDLE doesn't start. Modify Tkapp_Call() to unpack single tuple arglists. Bug 1733943 Ref http://mail.python.org/pipermail/python-checkins/2007-May/060454.html ........ r56177 | neal.norwitz | 2007-07-05 21:13:39 -0700 (Thu, 05 Jul 2007) | 1 line Fix typo in comment ........ ................ r56251 | neal.norwitz | 2007-07-11 10:01:01 +0300 (Wed, 11 Jul 2007) | 1 line Get working with map returning an iterator (had to fix whitespace too) ................ r56255 | thomas.wouters | 2007-07-11 13:41:37 +0300 (Wed, 11 Jul 2007) | 6 lines Clean up merge glitch or copy-paste error (the entire module was duplicated, except the first half even had some more copy-paste errors, referring to listcomps and genexps instead of setcomps) ................ r56256 | thomas.wouters | 2007-07-11 15:16:01 +0300 (Wed, 11 Jul 2007) | 14 lines Dict comprehensions. Still needs doc changes (like many python-3000 features ;-). It generates bytecode similar to: x = {} for k, v in (generator here): x[k] = v except there is no tuple-packing and -unpacking involved. Trivial measurement suggests it's significantly faster than dict(generator here) (in the order of 2 to 3 times as fast) but I have not done extensive measurements. ................ r56263 | guido.van.rossum | 2007-07-11 15:36:26 +0300 (Wed, 11 Jul 2007) | 3 lines Patch 1724999 by Ali Gholami Rudi -- avoid complaints about dict size change during iter in destroy call. ................
19 years ago
Merged revisions 56154-56264 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56155 | neal.norwitz | 2007-07-03 08:59:08 +0300 (Tue, 03 Jul 2007) | 1 line Get this test working after converting map to return an iterator ................ r56202 | neal.norwitz | 2007-07-09 04:30:09 +0300 (Mon, 09 Jul 2007) | 37 lines Merged revisions 56124-56201 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56129 | georg.brandl | 2007-06-30 04:01:01 -0700 (Sat, 30 Jun 2007) | 2 lines Document smtp.SMTPAuthenticationError. ........ r56137 | georg.brandl | 2007-07-01 01:11:35 -0700 (Sun, 01 Jul 2007) | 2 lines Fix a few webbrowser.py problems. ........ r56143 | georg.brandl | 2007-07-02 04:54:28 -0700 (Mon, 02 Jul 2007) | 2 lines Remove duplicate sentence from alarm() doc. ........ r56170 | mark.hammond | 2007-07-03 19:03:10 -0700 (Tue, 03 Jul 2007) | 3 lines copy built files to the PCBuild directory, where tools like distutils or external build processes can find them. ........ r56176 | kurt.kaiser | 2007-07-05 15:03:39 -0700 (Thu, 05 Jul 2007) | 10 lines Many calls to tk.call involve an arglist containing a single tuple. Calls using METH_OLDARGS unpack this tuple; calls using METH_VARARG don't. Tcl's concatenation of args was affected; IDLE doesn't start. Modify Tkapp_Call() to unpack single tuple arglists. Bug 1733943 Ref http://mail.python.org/pipermail/python-checkins/2007-May/060454.html ........ r56177 | neal.norwitz | 2007-07-05 21:13:39 -0700 (Thu, 05 Jul 2007) | 1 line Fix typo in comment ........ ................ r56251 | neal.norwitz | 2007-07-11 10:01:01 +0300 (Wed, 11 Jul 2007) | 1 line Get working with map returning an iterator (had to fix whitespace too) ................ r56255 | thomas.wouters | 2007-07-11 13:41:37 +0300 (Wed, 11 Jul 2007) | 6 lines Clean up merge glitch or copy-paste error (the entire module was duplicated, except the first half even had some more copy-paste errors, referring to listcomps and genexps instead of setcomps) ................ r56256 | thomas.wouters | 2007-07-11 15:16:01 +0300 (Wed, 11 Jul 2007) | 14 lines Dict comprehensions. Still needs doc changes (like many python-3000 features ;-). It generates bytecode similar to: x = {} for k, v in (generator here): x[k] = v except there is no tuple-packing and -unpacking involved. Trivial measurement suggests it's significantly faster than dict(generator here) (in the order of 2 to 3 times as fast) but I have not done extensive measurements. ................ r56263 | guido.van.rossum | 2007-07-11 15:36:26 +0300 (Wed, 11 Jul 2007) | 3 lines Patch 1724999 by Ali Gholami Rudi -- avoid complaints about dict size change during iter in destroy call. ................
19 years ago
Merged revisions 55225-55227,55229-55269 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r55238 | guido.van.rossum | 2007-05-10 16:46:05 -0700 (Thu, 10 May 2007) | 9 lines Merged revisions 55227 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55227 | guido.van.rossum | 2007-05-10 10:20:15 -0700 (Thu, 10 May 2007) | 2 lines Fix a bug in test_c_api() that caused a negative refcount. ........ ................ r55246 | neal.norwitz | 2007-05-11 00:01:52 -0700 (Fri, 11 May 2007) | 1 line Remove commands.getstatus() it is obsolete. ................ r55248 | neal.norwitz | 2007-05-11 00:29:05 -0700 (Fri, 11 May 2007) | 2 lines Remove bsddb185 support. ................ r55249 | neal.norwitz | 2007-05-11 00:29:50 -0700 (Fri, 11 May 2007) | 1 line Remove bsddb185 module too ................ r55250 | neal.norwitz | 2007-05-11 00:32:13 -0700 (Fri, 11 May 2007) | 1 line bsddb185: Gotta remove from the file checked in, not Setup ................ r55251 | neal.norwitz | 2007-05-11 00:53:26 -0700 (Fri, 11 May 2007) | 1 line Remove obsolete IRIX modules (as much as I could find, there is probably more) ................ r55252 | neal.norwitz | 2007-05-11 00:55:35 -0700 (Fri, 11 May 2007) | 1 line Remove SGI turd. ................ r55254 | georg.brandl | 2007-05-11 03:11:01 -0700 (Fri, 11 May 2007) | 2 lines Add a case for set comprehensions to the "cannot assign to" switch. ................ r55255 | georg.brandl | 2007-05-11 03:11:25 -0700 (Fri, 11 May 2007) | 2 lines Fix wrong imports. ................ r55261 | georg.brandl | 2007-05-11 07:37:48 -0700 (Fri, 11 May 2007) | 2 lines Remove removed tex files. ................ r55262 | georg.brandl | 2007-05-11 08:28:41 -0700 (Fri, 11 May 2007) | 2 lines Commit PEP 3132 implementation. ................ r55264 | georg.brandl | 2007-05-11 08:50:19 -0700 (Fri, 11 May 2007) | 2 lines Check in the inevitable AST version number and format Py_ssize_t with %zd. ................ r55265 | neal.norwitz | 2007-05-11 09:12:22 -0700 (Fri, 11 May 2007) | 1 line Remove mention of os.popen* and popen2.* since these will be removed. ................ r55266 | neal.norwitz | 2007-05-11 09:19:57 -0700 (Fri, 11 May 2007) | 1 line Get doc to build again (almost, the doc is fine) ................ r55267 | neal.norwitz | 2007-05-11 09:21:02 -0700 (Fri, 11 May 2007) | 1 line Really get doc to build (remove use of string module) ................ r55269 | neal.norwitz | 2007-05-11 09:29:43 -0700 (Fri, 11 May 2007) | 1 line Add some notes to cleanup later ................
19 years ago
Merged revisions 55225-55227,55229-55269 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r55238 | guido.van.rossum | 2007-05-10 16:46:05 -0700 (Thu, 10 May 2007) | 9 lines Merged revisions 55227 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55227 | guido.van.rossum | 2007-05-10 10:20:15 -0700 (Thu, 10 May 2007) | 2 lines Fix a bug in test_c_api() that caused a negative refcount. ........ ................ r55246 | neal.norwitz | 2007-05-11 00:01:52 -0700 (Fri, 11 May 2007) | 1 line Remove commands.getstatus() it is obsolete. ................ r55248 | neal.norwitz | 2007-05-11 00:29:05 -0700 (Fri, 11 May 2007) | 2 lines Remove bsddb185 support. ................ r55249 | neal.norwitz | 2007-05-11 00:29:50 -0700 (Fri, 11 May 2007) | 1 line Remove bsddb185 module too ................ r55250 | neal.norwitz | 2007-05-11 00:32:13 -0700 (Fri, 11 May 2007) | 1 line bsddb185: Gotta remove from the file checked in, not Setup ................ r55251 | neal.norwitz | 2007-05-11 00:53:26 -0700 (Fri, 11 May 2007) | 1 line Remove obsolete IRIX modules (as much as I could find, there is probably more) ................ r55252 | neal.norwitz | 2007-05-11 00:55:35 -0700 (Fri, 11 May 2007) | 1 line Remove SGI turd. ................ r55254 | georg.brandl | 2007-05-11 03:11:01 -0700 (Fri, 11 May 2007) | 2 lines Add a case for set comprehensions to the "cannot assign to" switch. ................ r55255 | georg.brandl | 2007-05-11 03:11:25 -0700 (Fri, 11 May 2007) | 2 lines Fix wrong imports. ................ r55261 | georg.brandl | 2007-05-11 07:37:48 -0700 (Fri, 11 May 2007) | 2 lines Remove removed tex files. ................ r55262 | georg.brandl | 2007-05-11 08:28:41 -0700 (Fri, 11 May 2007) | 2 lines Commit PEP 3132 implementation. ................ r55264 | georg.brandl | 2007-05-11 08:50:19 -0700 (Fri, 11 May 2007) | 2 lines Check in the inevitable AST version number and format Py_ssize_t with %zd. ................ r55265 | neal.norwitz | 2007-05-11 09:12:22 -0700 (Fri, 11 May 2007) | 1 line Remove mention of os.popen* and popen2.* since these will be removed. ................ r55266 | neal.norwitz | 2007-05-11 09:19:57 -0700 (Fri, 11 May 2007) | 1 line Get doc to build again (almost, the doc is fine) ................ r55267 | neal.norwitz | 2007-05-11 09:21:02 -0700 (Fri, 11 May 2007) | 1 line Really get doc to build (remove use of string module) ................ r55269 | neal.norwitz | 2007-05-11 09:29:43 -0700 (Fri, 11 May 2007) | 1 line Add some notes to cleanup later ................
19 years ago
14 years ago
14 years ago
14 years ago
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62048,62050-62051,62055-62066,62068-62074,62076-62078 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62048 | georg.brandl | 2008-03-29 23:53:55 -0700 (Sat, 29 Mar 2008) | 2 lines Adapt test_ast to the new ExceptHandler type. ........ r62050 | georg.brandl | 2008-03-30 00:09:22 -0700 (Sun, 30 Mar 2008) | 2 lines Convert test_ast to unittest and add a test for r62049. ........ r62051 | georg.brandl | 2008-03-30 12:00:49 -0700 (Sun, 30 Mar 2008) | 2 lines Make _fields attr for no fields consistent with _attributes attr. ........ r62059 | georg.brandl | 2008-03-30 13:20:39 -0700 (Sun, 30 Mar 2008) | 2 lines Make AST nodes pickleable. ........
18 years ago
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62048,62050-62051,62055-62066,62068-62074,62076-62078 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62048 | georg.brandl | 2008-03-29 23:53:55 -0700 (Sat, 29 Mar 2008) | 2 lines Adapt test_ast to the new ExceptHandler type. ........ r62050 | georg.brandl | 2008-03-30 00:09:22 -0700 (Sun, 30 Mar 2008) | 2 lines Convert test_ast to unittest and add a test for r62049. ........ r62051 | georg.brandl | 2008-03-30 12:00:49 -0700 (Sun, 30 Mar 2008) | 2 lines Make _fields attr for no fields consistent with _attributes attr. ........ r62059 | georg.brandl | 2008-03-30 13:20:39 -0700 (Sun, 30 Mar 2008) | 2 lines Make AST nodes pickleable. ........
18 years ago
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62048,62050-62051,62055-62066,62068-62074,62076-62078 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62048 | georg.brandl | 2008-03-29 23:53:55 -0700 (Sat, 29 Mar 2008) | 2 lines Adapt test_ast to the new ExceptHandler type. ........ r62050 | georg.brandl | 2008-03-30 00:09:22 -0700 (Sun, 30 Mar 2008) | 2 lines Convert test_ast to unittest and add a test for r62049. ........ r62051 | georg.brandl | 2008-03-30 12:00:49 -0700 (Sun, 30 Mar 2008) | 2 lines Make _fields attr for no fields consistent with _attributes attr. ........ r62059 | georg.brandl | 2008-03-30 13:20:39 -0700 (Sun, 30 Mar 2008) | 2 lines Make AST nodes pickleable. ........
18 years ago
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62048,62050-62051,62055-62066,62068-62074,62076-62078 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62048 | georg.brandl | 2008-03-29 23:53:55 -0700 (Sat, 29 Mar 2008) | 2 lines Adapt test_ast to the new ExceptHandler type. ........ r62050 | georg.brandl | 2008-03-30 00:09:22 -0700 (Sun, 30 Mar 2008) | 2 lines Convert test_ast to unittest and add a test for r62049. ........ r62051 | georg.brandl | 2008-03-30 12:00:49 -0700 (Sun, 30 Mar 2008) | 2 lines Make _fields attr for no fields consistent with _attributes attr. ........ r62059 | georg.brandl | 2008-03-30 13:20:39 -0700 (Sun, 30 Mar 2008) | 2 lines Make AST nodes pickleable. ........
18 years ago
14 years ago
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62048,62050-62051,62055-62066,62068-62074,62076-62078 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62048 | georg.brandl | 2008-03-29 23:53:55 -0700 (Sat, 29 Mar 2008) | 2 lines Adapt test_ast to the new ExceptHandler type. ........ r62050 | georg.brandl | 2008-03-30 00:09:22 -0700 (Sun, 30 Mar 2008) | 2 lines Convert test_ast to unittest and add a test for r62049. ........ r62051 | georg.brandl | 2008-03-30 12:00:49 -0700 (Sun, 30 Mar 2008) | 2 lines Make _fields attr for no fields consistent with _attributes attr. ........ r62059 | georg.brandl | 2008-03-30 13:20:39 -0700 (Sun, 30 Mar 2008) | 2 lines Make AST nodes pickleable. ........
18 years ago
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62048,62050-62051,62055-62066,62068-62074,62076-62078 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62048 | georg.brandl | 2008-03-29 23:53:55 -0700 (Sat, 29 Mar 2008) | 2 lines Adapt test_ast to the new ExceptHandler type. ........ r62050 | georg.brandl | 2008-03-30 00:09:22 -0700 (Sun, 30 Mar 2008) | 2 lines Convert test_ast to unittest and add a test for r62049. ........ r62051 | georg.brandl | 2008-03-30 12:00:49 -0700 (Sun, 30 Mar 2008) | 2 lines Make _fields attr for no fields consistent with _attributes attr. ........ r62059 | georg.brandl | 2008-03-30 13:20:39 -0700 (Sun, 30 Mar 2008) | 2 lines Make AST nodes pickleable. ........
18 years ago
Merged revisions 66974,66977,66984,66989,66992,66994-66996,66998-67000,67007,67015 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r66974 | benjamin.peterson | 2008-10-19 08:59:01 -0500 (Sun, 19 Oct 2008) | 1 line fix compiler warning ........ r66977 | benjamin.peterson | 2008-10-19 14:39:16 -0500 (Sun, 19 Oct 2008) | 1 line mention -n ........ r66984 | armin.ronacher | 2008-10-20 16:29:08 -0500 (Mon, 20 Oct 2008) | 3 lines Fixed #4062, added import for _ast.__version__ to ast to match the documented behavior. ........ r66989 | matthias.klose | 2008-10-21 04:12:25 -0500 (Tue, 21 Oct 2008) | 2 lines - install versioned manpage ........ r66992 | benjamin.peterson | 2008-10-21 15:51:13 -0500 (Tue, 21 Oct 2008) | 1 line make sure to call iteritems() ........ r66994 | amaury.forgeotdarc | 2008-10-21 17:01:38 -0500 (Tue, 21 Oct 2008) | 6 lines #4157 move two test functions out of platform.py. Turn them into unit tests, and correct an obvious typo: (("a", "b") ("c", "d") ("e", "f")) compiles even with the missing commas, but does not execute very well... ........ r66995 | benjamin.peterson | 2008-10-21 17:18:29 -0500 (Tue, 21 Oct 2008) | 1 line return ArgInfo from inspect.getargvalues #4092 ........ r66996 | benjamin.peterson | 2008-10-21 17:20:31 -0500 (Tue, 21 Oct 2008) | 1 line add NEWs note for last change ........ r66998 | benjamin.peterson | 2008-10-22 15:57:43 -0500 (Wed, 22 Oct 2008) | 1 line fix a few typos ........ r66999 | benjamin.peterson | 2008-10-22 16:05:30 -0500 (Wed, 22 Oct 2008) | 1 line and another typo... ........ r67000 | benjamin.peterson | 2008-10-22 16:16:34 -0500 (Wed, 22 Oct 2008) | 1 line fix #4150: pdb's up command didn't work for generators in post-mortem ........ r67007 | benjamin.peterson | 2008-10-23 16:43:48 -0500 (Thu, 23 Oct 2008) | 1 line only nonempty __slots__ don't work ........ r67015 | georg.brandl | 2008-10-25 02:00:52 -0500 (Sat, 25 Oct 2008) | 2 lines Typo fix. ........
17 years ago
Merged revisions 56154-56264 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56155 | neal.norwitz | 2007-07-03 08:59:08 +0300 (Tue, 03 Jul 2007) | 1 line Get this test working after converting map to return an iterator ................ r56202 | neal.norwitz | 2007-07-09 04:30:09 +0300 (Mon, 09 Jul 2007) | 37 lines Merged revisions 56124-56201 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56129 | georg.brandl | 2007-06-30 04:01:01 -0700 (Sat, 30 Jun 2007) | 2 lines Document smtp.SMTPAuthenticationError. ........ r56137 | georg.brandl | 2007-07-01 01:11:35 -0700 (Sun, 01 Jul 2007) | 2 lines Fix a few webbrowser.py problems. ........ r56143 | georg.brandl | 2007-07-02 04:54:28 -0700 (Mon, 02 Jul 2007) | 2 lines Remove duplicate sentence from alarm() doc. ........ r56170 | mark.hammond | 2007-07-03 19:03:10 -0700 (Tue, 03 Jul 2007) | 3 lines copy built files to the PCBuild directory, where tools like distutils or external build processes can find them. ........ r56176 | kurt.kaiser | 2007-07-05 15:03:39 -0700 (Thu, 05 Jul 2007) | 10 lines Many calls to tk.call involve an arglist containing a single tuple. Calls using METH_OLDARGS unpack this tuple; calls using METH_VARARG don't. Tcl's concatenation of args was affected; IDLE doesn't start. Modify Tkapp_Call() to unpack single tuple arglists. Bug 1733943 Ref http://mail.python.org/pipermail/python-checkins/2007-May/060454.html ........ r56177 | neal.norwitz | 2007-07-05 21:13:39 -0700 (Thu, 05 Jul 2007) | 1 line Fix typo in comment ........ ................ r56251 | neal.norwitz | 2007-07-11 10:01:01 +0300 (Wed, 11 Jul 2007) | 1 line Get working with map returning an iterator (had to fix whitespace too) ................ r56255 | thomas.wouters | 2007-07-11 13:41:37 +0300 (Wed, 11 Jul 2007) | 6 lines Clean up merge glitch or copy-paste error (the entire module was duplicated, except the first half even had some more copy-paste errors, referring to listcomps and genexps instead of setcomps) ................ r56256 | thomas.wouters | 2007-07-11 15:16:01 +0300 (Wed, 11 Jul 2007) | 14 lines Dict comprehensions. Still needs doc changes (like many python-3000 features ;-). It generates bytecode similar to: x = {} for k, v in (generator here): x[k] = v except there is no tuple-packing and -unpacking involved. Trivial measurement suggests it's significantly faster than dict(generator here) (in the order of 2 to 3 times as fast) but I have not done extensive measurements. ................ r56263 | guido.van.rossum | 2007-07-11 15:36:26 +0300 (Wed, 11 Jul 2007) | 3 lines Patch 1724999 by Ali Gholami Rudi -- avoid complaints about dict size change during iter in destroy call. ................
19 years ago
Merged revisions 56154-56264 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56155 | neal.norwitz | 2007-07-03 08:59:08 +0300 (Tue, 03 Jul 2007) | 1 line Get this test working after converting map to return an iterator ................ r56202 | neal.norwitz | 2007-07-09 04:30:09 +0300 (Mon, 09 Jul 2007) | 37 lines Merged revisions 56124-56201 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56129 | georg.brandl | 2007-06-30 04:01:01 -0700 (Sat, 30 Jun 2007) | 2 lines Document smtp.SMTPAuthenticationError. ........ r56137 | georg.brandl | 2007-07-01 01:11:35 -0700 (Sun, 01 Jul 2007) | 2 lines Fix a few webbrowser.py problems. ........ r56143 | georg.brandl | 2007-07-02 04:54:28 -0700 (Mon, 02 Jul 2007) | 2 lines Remove duplicate sentence from alarm() doc. ........ r56170 | mark.hammond | 2007-07-03 19:03:10 -0700 (Tue, 03 Jul 2007) | 3 lines copy built files to the PCBuild directory, where tools like distutils or external build processes can find them. ........ r56176 | kurt.kaiser | 2007-07-05 15:03:39 -0700 (Thu, 05 Jul 2007) | 10 lines Many calls to tk.call involve an arglist containing a single tuple. Calls using METH_OLDARGS unpack this tuple; calls using METH_VARARG don't. Tcl's concatenation of args was affected; IDLE doesn't start. Modify Tkapp_Call() to unpack single tuple arglists. Bug 1733943 Ref http://mail.python.org/pipermail/python-checkins/2007-May/060454.html ........ r56177 | neal.norwitz | 2007-07-05 21:13:39 -0700 (Thu, 05 Jul 2007) | 1 line Fix typo in comment ........ ................ r56251 | neal.norwitz | 2007-07-11 10:01:01 +0300 (Wed, 11 Jul 2007) | 1 line Get working with map returning an iterator (had to fix whitespace too) ................ r56255 | thomas.wouters | 2007-07-11 13:41:37 +0300 (Wed, 11 Jul 2007) | 6 lines Clean up merge glitch or copy-paste error (the entire module was duplicated, except the first half even had some more copy-paste errors, referring to listcomps and genexps instead of setcomps) ................ r56256 | thomas.wouters | 2007-07-11 15:16:01 +0300 (Wed, 11 Jul 2007) | 14 lines Dict comprehensions. Still needs doc changes (like many python-3000 features ;-). It generates bytecode similar to: x = {} for k, v in (generator here): x[k] = v except there is no tuple-packing and -unpacking involved. Trivial measurement suggests it's significantly faster than dict(generator here) (in the order of 2 to 3 times as fast) but I have not done extensive measurements. ................ r56263 | guido.van.rossum | 2007-07-11 15:36:26 +0300 (Wed, 11 Jul 2007) | 3 lines Patch 1724999 by Ali Gholami Rudi -- avoid complaints about dict size change during iter in destroy call. ................
19 years ago
Merged revisions 55225-55227,55229-55269 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r55238 | guido.van.rossum | 2007-05-10 16:46:05 -0700 (Thu, 10 May 2007) | 9 lines Merged revisions 55227 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55227 | guido.van.rossum | 2007-05-10 10:20:15 -0700 (Thu, 10 May 2007) | 2 lines Fix a bug in test_c_api() that caused a negative refcount. ........ ................ r55246 | neal.norwitz | 2007-05-11 00:01:52 -0700 (Fri, 11 May 2007) | 1 line Remove commands.getstatus() it is obsolete. ................ r55248 | neal.norwitz | 2007-05-11 00:29:05 -0700 (Fri, 11 May 2007) | 2 lines Remove bsddb185 support. ................ r55249 | neal.norwitz | 2007-05-11 00:29:50 -0700 (Fri, 11 May 2007) | 1 line Remove bsddb185 module too ................ r55250 | neal.norwitz | 2007-05-11 00:32:13 -0700 (Fri, 11 May 2007) | 1 line bsddb185: Gotta remove from the file checked in, not Setup ................ r55251 | neal.norwitz | 2007-05-11 00:53:26 -0700 (Fri, 11 May 2007) | 1 line Remove obsolete IRIX modules (as much as I could find, there is probably more) ................ r55252 | neal.norwitz | 2007-05-11 00:55:35 -0700 (Fri, 11 May 2007) | 1 line Remove SGI turd. ................ r55254 | georg.brandl | 2007-05-11 03:11:01 -0700 (Fri, 11 May 2007) | 2 lines Add a case for set comprehensions to the "cannot assign to" switch. ................ r55255 | georg.brandl | 2007-05-11 03:11:25 -0700 (Fri, 11 May 2007) | 2 lines Fix wrong imports. ................ r55261 | georg.brandl | 2007-05-11 07:37:48 -0700 (Fri, 11 May 2007) | 2 lines Remove removed tex files. ................ r55262 | georg.brandl | 2007-05-11 08:28:41 -0700 (Fri, 11 May 2007) | 2 lines Commit PEP 3132 implementation. ................ r55264 | georg.brandl | 2007-05-11 08:50:19 -0700 (Fri, 11 May 2007) | 2 lines Check in the inevitable AST version number and format Py_ssize_t with %zd. ................ r55265 | neal.norwitz | 2007-05-11 09:12:22 -0700 (Fri, 11 May 2007) | 1 line Remove mention of os.popen* and popen2.* since these will be removed. ................ r55266 | neal.norwitz | 2007-05-11 09:19:57 -0700 (Fri, 11 May 2007) | 1 line Get doc to build again (almost, the doc is fine) ................ r55267 | neal.norwitz | 2007-05-11 09:21:02 -0700 (Fri, 11 May 2007) | 1 line Really get doc to build (remove use of string module) ................ r55269 | neal.norwitz | 2007-05-11 09:29:43 -0700 (Fri, 11 May 2007) | 1 line Add some notes to cleanup later ................
19 years ago
Merged revisions 55225-55227,55229-55269 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r55238 | guido.van.rossum | 2007-05-10 16:46:05 -0700 (Thu, 10 May 2007) | 9 lines Merged revisions 55227 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55227 | guido.van.rossum | 2007-05-10 10:20:15 -0700 (Thu, 10 May 2007) | 2 lines Fix a bug in test_c_api() that caused a negative refcount. ........ ................ r55246 | neal.norwitz | 2007-05-11 00:01:52 -0700 (Fri, 11 May 2007) | 1 line Remove commands.getstatus() it is obsolete. ................ r55248 | neal.norwitz | 2007-05-11 00:29:05 -0700 (Fri, 11 May 2007) | 2 lines Remove bsddb185 support. ................ r55249 | neal.norwitz | 2007-05-11 00:29:50 -0700 (Fri, 11 May 2007) | 1 line Remove bsddb185 module too ................ r55250 | neal.norwitz | 2007-05-11 00:32:13 -0700 (Fri, 11 May 2007) | 1 line bsddb185: Gotta remove from the file checked in, not Setup ................ r55251 | neal.norwitz | 2007-05-11 00:53:26 -0700 (Fri, 11 May 2007) | 1 line Remove obsolete IRIX modules (as much as I could find, there is probably more) ................ r55252 | neal.norwitz | 2007-05-11 00:55:35 -0700 (Fri, 11 May 2007) | 1 line Remove SGI turd. ................ r55254 | georg.brandl | 2007-05-11 03:11:01 -0700 (Fri, 11 May 2007) | 2 lines Add a case for set comprehensions to the "cannot assign to" switch. ................ r55255 | georg.brandl | 2007-05-11 03:11:25 -0700 (Fri, 11 May 2007) | 2 lines Fix wrong imports. ................ r55261 | georg.brandl | 2007-05-11 07:37:48 -0700 (Fri, 11 May 2007) | 2 lines Remove removed tex files. ................ r55262 | georg.brandl | 2007-05-11 08:28:41 -0700 (Fri, 11 May 2007) | 2 lines Commit PEP 3132 implementation. ................ r55264 | georg.brandl | 2007-05-11 08:50:19 -0700 (Fri, 11 May 2007) | 2 lines Check in the inevitable AST version number and format Py_ssize_t with %zd. ................ r55265 | neal.norwitz | 2007-05-11 09:12:22 -0700 (Fri, 11 May 2007) | 1 line Remove mention of os.popen* and popen2.* since these will be removed. ................ r55266 | neal.norwitz | 2007-05-11 09:19:57 -0700 (Fri, 11 May 2007) | 1 line Get doc to build again (almost, the doc is fine) ................ r55267 | neal.norwitz | 2007-05-11 09:21:02 -0700 (Fri, 11 May 2007) | 1 line Really get doc to build (remove use of string module) ................ r55269 | neal.norwitz | 2007-05-11 09:29:43 -0700 (Fri, 11 May 2007) | 1 line Add some notes to cleanup later ................
19 years ago
  1. /* File automatically generated by Parser/asdl_c.py. */
  2. #include <stddef.h>
  3. #include "Python.h"
  4. #include "Python-ast.h"
  5. static PyTypeObject AST_type;
  6. static PyTypeObject *mod_type;
  7. static PyObject* ast2obj_mod(void*);
  8. static PyTypeObject *Module_type;
  9. _Py_IDENTIFIER(body);
  10. static char *Module_fields[]={
  11. "body",
  12. };
  13. static PyTypeObject *Interactive_type;
  14. static char *Interactive_fields[]={
  15. "body",
  16. };
  17. static PyTypeObject *Expression_type;
  18. static char *Expression_fields[]={
  19. "body",
  20. };
  21. static PyTypeObject *Suite_type;
  22. static char *Suite_fields[]={
  23. "body",
  24. };
  25. static PyTypeObject *stmt_type;
  26. _Py_IDENTIFIER(lineno);
  27. _Py_IDENTIFIER(col_offset);
  28. static char *stmt_attributes[] = {
  29. "lineno",
  30. "col_offset",
  31. };
  32. static PyObject* ast2obj_stmt(void*);
  33. static PyTypeObject *FunctionDef_type;
  34. _Py_IDENTIFIER(name);
  35. _Py_IDENTIFIER(args);
  36. _Py_IDENTIFIER(decorator_list);
  37. _Py_IDENTIFIER(returns);
  38. static char *FunctionDef_fields[]={
  39. "name",
  40. "args",
  41. "body",
  42. "decorator_list",
  43. "returns",
  44. };
  45. static PyTypeObject *AsyncFunctionDef_type;
  46. static char *AsyncFunctionDef_fields[]={
  47. "name",
  48. "args",
  49. "body",
  50. "decorator_list",
  51. "returns",
  52. };
  53. static PyTypeObject *ClassDef_type;
  54. _Py_IDENTIFIER(bases);
  55. _Py_IDENTIFIER(keywords);
  56. static char *ClassDef_fields[]={
  57. "name",
  58. "bases",
  59. "keywords",
  60. "body",
  61. "decorator_list",
  62. };
  63. static PyTypeObject *Return_type;
  64. _Py_IDENTIFIER(value);
  65. static char *Return_fields[]={
  66. "value",
  67. };
  68. static PyTypeObject *Delete_type;
  69. _Py_IDENTIFIER(targets);
  70. static char *Delete_fields[]={
  71. "targets",
  72. };
  73. static PyTypeObject *Assign_type;
  74. static char *Assign_fields[]={
  75. "targets",
  76. "value",
  77. };
  78. static PyTypeObject *AugAssign_type;
  79. _Py_IDENTIFIER(target);
  80. _Py_IDENTIFIER(op);
  81. static char *AugAssign_fields[]={
  82. "target",
  83. "op",
  84. "value",
  85. };
  86. static PyTypeObject *AnnAssign_type;
  87. _Py_IDENTIFIER(annotation);
  88. _Py_IDENTIFIER(simple);
  89. static char *AnnAssign_fields[]={
  90. "target",
  91. "annotation",
  92. "value",
  93. "simple",
  94. };
  95. static PyTypeObject *For_type;
  96. _Py_IDENTIFIER(iter);
  97. _Py_IDENTIFIER(orelse);
  98. static char *For_fields[]={
  99. "target",
  100. "iter",
  101. "body",
  102. "orelse",
  103. };
  104. static PyTypeObject *AsyncFor_type;
  105. static char *AsyncFor_fields[]={
  106. "target",
  107. "iter",
  108. "body",
  109. "orelse",
  110. };
  111. static PyTypeObject *While_type;
  112. _Py_IDENTIFIER(test);
  113. static char *While_fields[]={
  114. "test",
  115. "body",
  116. "orelse",
  117. };
  118. static PyTypeObject *If_type;
  119. static char *If_fields[]={
  120. "test",
  121. "body",
  122. "orelse",
  123. };
  124. static PyTypeObject *With_type;
  125. _Py_IDENTIFIER(items);
  126. static char *With_fields[]={
  127. "items",
  128. "body",
  129. };
  130. static PyTypeObject *AsyncWith_type;
  131. static char *AsyncWith_fields[]={
  132. "items",
  133. "body",
  134. };
  135. static PyTypeObject *Raise_type;
  136. _Py_IDENTIFIER(exc);
  137. _Py_IDENTIFIER(cause);
  138. static char *Raise_fields[]={
  139. "exc",
  140. "cause",
  141. };
  142. static PyTypeObject *Try_type;
  143. _Py_IDENTIFIER(handlers);
  144. _Py_IDENTIFIER(finalbody);
  145. static char *Try_fields[]={
  146. "body",
  147. "handlers",
  148. "orelse",
  149. "finalbody",
  150. };
  151. static PyTypeObject *Assert_type;
  152. _Py_IDENTIFIER(msg);
  153. static char *Assert_fields[]={
  154. "test",
  155. "msg",
  156. };
  157. static PyTypeObject *Import_type;
  158. _Py_IDENTIFIER(names);
  159. static char *Import_fields[]={
  160. "names",
  161. };
  162. static PyTypeObject *ImportFrom_type;
  163. _Py_IDENTIFIER(module);
  164. _Py_IDENTIFIER(level);
  165. static char *ImportFrom_fields[]={
  166. "module",
  167. "names",
  168. "level",
  169. };
  170. static PyTypeObject *Global_type;
  171. static char *Global_fields[]={
  172. "names",
  173. };
  174. static PyTypeObject *Nonlocal_type;
  175. static char *Nonlocal_fields[]={
  176. "names",
  177. };
  178. static PyTypeObject *Expr_type;
  179. static char *Expr_fields[]={
  180. "value",
  181. };
  182. static PyTypeObject *Pass_type;
  183. static PyTypeObject *Break_type;
  184. static PyTypeObject *Continue_type;
  185. static PyTypeObject *expr_type;
  186. static char *expr_attributes[] = {
  187. "lineno",
  188. "col_offset",
  189. };
  190. static PyObject* ast2obj_expr(void*);
  191. static PyTypeObject *BoolOp_type;
  192. _Py_IDENTIFIER(values);
  193. static char *BoolOp_fields[]={
  194. "op",
  195. "values",
  196. };
  197. static PyTypeObject *BinOp_type;
  198. _Py_IDENTIFIER(left);
  199. _Py_IDENTIFIER(right);
  200. static char *BinOp_fields[]={
  201. "left",
  202. "op",
  203. "right",
  204. };
  205. static PyTypeObject *UnaryOp_type;
  206. _Py_IDENTIFIER(operand);
  207. static char *UnaryOp_fields[]={
  208. "op",
  209. "operand",
  210. };
  211. static PyTypeObject *Lambda_type;
  212. static char *Lambda_fields[]={
  213. "args",
  214. "body",
  215. };
  216. static PyTypeObject *IfExp_type;
  217. static char *IfExp_fields[]={
  218. "test",
  219. "body",
  220. "orelse",
  221. };
  222. static PyTypeObject *Dict_type;
  223. _Py_IDENTIFIER(keys);
  224. static char *Dict_fields[]={
  225. "keys",
  226. "values",
  227. };
  228. static PyTypeObject *Set_type;
  229. _Py_IDENTIFIER(elts);
  230. static char *Set_fields[]={
  231. "elts",
  232. };
  233. static PyTypeObject *ListComp_type;
  234. _Py_IDENTIFIER(elt);
  235. _Py_IDENTIFIER(generators);
  236. static char *ListComp_fields[]={
  237. "elt",
  238. "generators",
  239. };
  240. static PyTypeObject *SetComp_type;
  241. static char *SetComp_fields[]={
  242. "elt",
  243. "generators",
  244. };
  245. static PyTypeObject *DictComp_type;
  246. _Py_IDENTIFIER(key);
  247. static char *DictComp_fields[]={
  248. "key",
  249. "value",
  250. "generators",
  251. };
  252. static PyTypeObject *GeneratorExp_type;
  253. static char *GeneratorExp_fields[]={
  254. "elt",
  255. "generators",
  256. };
  257. static PyTypeObject *Await_type;
  258. static char *Await_fields[]={
  259. "value",
  260. };
  261. static PyTypeObject *Yield_type;
  262. static char *Yield_fields[]={
  263. "value",
  264. };
  265. static PyTypeObject *YieldFrom_type;
  266. static char *YieldFrom_fields[]={
  267. "value",
  268. };
  269. static PyTypeObject *Compare_type;
  270. _Py_IDENTIFIER(ops);
  271. _Py_IDENTIFIER(comparators);
  272. static char *Compare_fields[]={
  273. "left",
  274. "ops",
  275. "comparators",
  276. };
  277. static PyTypeObject *Call_type;
  278. _Py_IDENTIFIER(func);
  279. static char *Call_fields[]={
  280. "func",
  281. "args",
  282. "keywords",
  283. };
  284. static PyTypeObject *FormattedValue_type;
  285. _Py_IDENTIFIER(conversion);
  286. _Py_IDENTIFIER(format_spec);
  287. static char *FormattedValue_fields[]={
  288. "value",
  289. "conversion",
  290. "format_spec",
  291. };
  292. static PyTypeObject *JoinedStr_type;
  293. static char *JoinedStr_fields[]={
  294. "values",
  295. };
  296. static PyTypeObject *Constant_type;
  297. static char *Constant_fields[]={
  298. "value",
  299. };
  300. static PyTypeObject *Attribute_type;
  301. _Py_IDENTIFIER(attr);
  302. _Py_IDENTIFIER(ctx);
  303. static char *Attribute_fields[]={
  304. "value",
  305. "attr",
  306. "ctx",
  307. };
  308. static PyTypeObject *Subscript_type;
  309. _Py_IDENTIFIER(slice);
  310. static char *Subscript_fields[]={
  311. "value",
  312. "slice",
  313. "ctx",
  314. };
  315. static PyTypeObject *Starred_type;
  316. static char *Starred_fields[]={
  317. "value",
  318. "ctx",
  319. };
  320. static PyTypeObject *Name_type;
  321. _Py_IDENTIFIER(id);
  322. static char *Name_fields[]={
  323. "id",
  324. "ctx",
  325. };
  326. static PyTypeObject *List_type;
  327. static char *List_fields[]={
  328. "elts",
  329. "ctx",
  330. };
  331. static PyTypeObject *Tuple_type;
  332. static char *Tuple_fields[]={
  333. "elts",
  334. "ctx",
  335. };
  336. static PyTypeObject *expr_context_type;
  337. static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
  338. *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
  339. static PyObject* ast2obj_expr_context(expr_context_ty);
  340. static PyTypeObject *Load_type;
  341. static PyTypeObject *Store_type;
  342. static PyTypeObject *Del_type;
  343. static PyTypeObject *AugLoad_type;
  344. static PyTypeObject *AugStore_type;
  345. static PyTypeObject *Param_type;
  346. static PyTypeObject *slice_type;
  347. static PyObject* ast2obj_slice(void*);
  348. static PyTypeObject *Slice_type;
  349. _Py_IDENTIFIER(lower);
  350. _Py_IDENTIFIER(upper);
  351. _Py_IDENTIFIER(step);
  352. static char *Slice_fields[]={
  353. "lower",
  354. "upper",
  355. "step",
  356. };
  357. static PyTypeObject *ExtSlice_type;
  358. _Py_IDENTIFIER(dims);
  359. static char *ExtSlice_fields[]={
  360. "dims",
  361. };
  362. static PyTypeObject *Index_type;
  363. static char *Index_fields[]={
  364. "value",
  365. };
  366. static PyTypeObject *boolop_type;
  367. static PyObject *And_singleton, *Or_singleton;
  368. static PyObject* ast2obj_boolop(boolop_ty);
  369. static PyTypeObject *And_type;
  370. static PyTypeObject *Or_type;
  371. static PyTypeObject *operator_type;
  372. static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
  373. *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton,
  374. *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton,
  375. *BitAnd_singleton, *FloorDiv_singleton;
  376. static PyObject* ast2obj_operator(operator_ty);
  377. static PyTypeObject *Add_type;
  378. static PyTypeObject *Sub_type;
  379. static PyTypeObject *Mult_type;
  380. static PyTypeObject *MatMult_type;
  381. static PyTypeObject *Div_type;
  382. static PyTypeObject *Mod_type;
  383. static PyTypeObject *Pow_type;
  384. static PyTypeObject *LShift_type;
  385. static PyTypeObject *RShift_type;
  386. static PyTypeObject *BitOr_type;
  387. static PyTypeObject *BitXor_type;
  388. static PyTypeObject *BitAnd_type;
  389. static PyTypeObject *FloorDiv_type;
  390. static PyTypeObject *unaryop_type;
  391. static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
  392. *USub_singleton;
  393. static PyObject* ast2obj_unaryop(unaryop_ty);
  394. static PyTypeObject *Invert_type;
  395. static PyTypeObject *Not_type;
  396. static PyTypeObject *UAdd_type;
  397. static PyTypeObject *USub_type;
  398. static PyTypeObject *cmpop_type;
  399. static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
  400. *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
  401. *NotIn_singleton;
  402. static PyObject* ast2obj_cmpop(cmpop_ty);
  403. static PyTypeObject *Eq_type;
  404. static PyTypeObject *NotEq_type;
  405. static PyTypeObject *Lt_type;
  406. static PyTypeObject *LtE_type;
  407. static PyTypeObject *Gt_type;
  408. static PyTypeObject *GtE_type;
  409. static PyTypeObject *Is_type;
  410. static PyTypeObject *IsNot_type;
  411. static PyTypeObject *In_type;
  412. static PyTypeObject *NotIn_type;
  413. static PyTypeObject *comprehension_type;
  414. static PyObject* ast2obj_comprehension(void*);
  415. _Py_IDENTIFIER(ifs);
  416. _Py_IDENTIFIER(is_async);
  417. static char *comprehension_fields[]={
  418. "target",
  419. "iter",
  420. "ifs",
  421. "is_async",
  422. };
  423. static PyTypeObject *excepthandler_type;
  424. static char *excepthandler_attributes[] = {
  425. "lineno",
  426. "col_offset",
  427. };
  428. static PyObject* ast2obj_excepthandler(void*);
  429. static PyTypeObject *ExceptHandler_type;
  430. _Py_IDENTIFIER(type);
  431. static char *ExceptHandler_fields[]={
  432. "type",
  433. "name",
  434. "body",
  435. };
  436. static PyTypeObject *arguments_type;
  437. static PyObject* ast2obj_arguments(void*);
  438. _Py_IDENTIFIER(vararg);
  439. _Py_IDENTIFIER(kwonlyargs);
  440. _Py_IDENTIFIER(kw_defaults);
  441. _Py_IDENTIFIER(kwarg);
  442. _Py_IDENTIFIER(defaults);
  443. static char *arguments_fields[]={
  444. "args",
  445. "vararg",
  446. "kwonlyargs",
  447. "kw_defaults",
  448. "kwarg",
  449. "defaults",
  450. };
  451. static PyTypeObject *arg_type;
  452. static PyObject* ast2obj_arg(void*);
  453. static char *arg_attributes[] = {
  454. "lineno",
  455. "col_offset",
  456. };
  457. _Py_IDENTIFIER(arg);
  458. static char *arg_fields[]={
  459. "arg",
  460. "annotation",
  461. };
  462. static PyTypeObject *keyword_type;
  463. static PyObject* ast2obj_keyword(void*);
  464. static char *keyword_fields[]={
  465. "arg",
  466. "value",
  467. };
  468. static PyTypeObject *alias_type;
  469. static PyObject* ast2obj_alias(void*);
  470. _Py_IDENTIFIER(asname);
  471. static char *alias_fields[]={
  472. "name",
  473. "asname",
  474. };
  475. static PyTypeObject *withitem_type;
  476. static PyObject* ast2obj_withitem(void*);
  477. _Py_IDENTIFIER(context_expr);
  478. _Py_IDENTIFIER(optional_vars);
  479. static char *withitem_fields[]={
  480. "context_expr",
  481. "optional_vars",
  482. };
  483. _Py_IDENTIFIER(_fields);
  484. _Py_IDENTIFIER(_attributes);
  485. typedef struct {
  486. PyObject_HEAD
  487. PyObject *dict;
  488. } AST_object;
  489. static void
  490. ast_dealloc(AST_object *self)
  491. {
  492. /* bpo-31095: UnTrack is needed before calling any callbacks */
  493. PyObject_GC_UnTrack(self);
  494. Py_CLEAR(self->dict);
  495. Py_TYPE(self)->tp_free(self);
  496. }
  497. static int
  498. ast_traverse(AST_object *self, visitproc visit, void *arg)
  499. {
  500. Py_VISIT(self->dict);
  501. return 0;
  502. }
  503. static int
  504. ast_clear(AST_object *self)
  505. {
  506. Py_CLEAR(self->dict);
  507. return 0;
  508. }
  509. static int
  510. ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
  511. {
  512. Py_ssize_t i, numfields = 0;
  513. int res = -1;
  514. PyObject *key, *value, *fields;
  515. if (_PyObject_LookupAttrId((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) {
  516. goto cleanup;
  517. }
  518. if (fields) {
  519. numfields = PySequence_Size(fields);
  520. if (numfields == -1)
  521. goto cleanup;
  522. }
  523. res = 0; /* if no error occurs, this stays 0 to the end */
  524. if (numfields < PyTuple_GET_SIZE(args)) {
  525. PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
  526. "%zd positional argument%s",
  527. Py_TYPE(self)->tp_name,
  528. numfields, numfields == 1 ? "" : "s");
  529. res = -1;
  530. goto cleanup;
  531. }
  532. for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
  533. /* cannot be reached when fields is NULL */
  534. PyObject *name = PySequence_GetItem(fields, i);
  535. if (!name) {
  536. res = -1;
  537. goto cleanup;
  538. }
  539. res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
  540. Py_DECREF(name);
  541. if (res < 0)
  542. goto cleanup;
  543. }
  544. if (kw) {
  545. i = 0; /* needed by PyDict_Next */
  546. while (PyDict_Next(kw, &i, &key, &value)) {
  547. res = PyObject_SetAttr(self, key, value);
  548. if (res < 0)
  549. goto cleanup;
  550. }
  551. }
  552. cleanup:
  553. Py_XDECREF(fields);
  554. return res;
  555. }
  556. /* Pickling support */
  557. static PyObject *
  558. ast_type_reduce(PyObject *self, PyObject *unused)
  559. {
  560. _Py_IDENTIFIER(__dict__);
  561. PyObject *dict;
  562. if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) {
  563. return NULL;
  564. }
  565. if (dict) {
  566. return Py_BuildValue("O()N", Py_TYPE(self), dict);
  567. }
  568. return Py_BuildValue("O()", Py_TYPE(self));
  569. }
  570. static PyMethodDef ast_type_methods[] = {
  571. {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
  572. {NULL}
  573. };
  574. static PyGetSetDef ast_type_getsets[] = {
  575. {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
  576. {NULL}
  577. };
  578. static PyTypeObject AST_type = {
  579. PyVarObject_HEAD_INIT(&PyType_Type, 0)
  580. "_ast.AST",
  581. sizeof(AST_object),
  582. 0,
  583. (destructor)ast_dealloc, /* tp_dealloc */
  584. 0, /* tp_print */
  585. 0, /* tp_getattr */
  586. 0, /* tp_setattr */
  587. 0, /* tp_reserved */
  588. 0, /* tp_repr */
  589. 0, /* tp_as_number */
  590. 0, /* tp_as_sequence */
  591. 0, /* tp_as_mapping */
  592. 0, /* tp_hash */
  593. 0, /* tp_call */
  594. 0, /* tp_str */
  595. PyObject_GenericGetAttr, /* tp_getattro */
  596. PyObject_GenericSetAttr, /* tp_setattro */
  597. 0, /* tp_as_buffer */
  598. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */
  599. 0, /* tp_doc */
  600. (traverseproc)ast_traverse, /* tp_traverse */
  601. (inquiry)ast_clear, /* tp_clear */
  602. 0, /* tp_richcompare */
  603. 0, /* tp_weaklistoffset */
  604. 0, /* tp_iter */
  605. 0, /* tp_iternext */
  606. ast_type_methods, /* tp_methods */
  607. 0, /* tp_members */
  608. ast_type_getsets, /* tp_getset */
  609. 0, /* tp_base */
  610. 0, /* tp_dict */
  611. 0, /* tp_descr_get */
  612. 0, /* tp_descr_set */
  613. offsetof(AST_object, dict),/* tp_dictoffset */
  614. (initproc)ast_type_init, /* tp_init */
  615. PyType_GenericAlloc, /* tp_alloc */
  616. PyType_GenericNew, /* tp_new */
  617. PyObject_GC_Del, /* tp_free */
  618. };
  619. static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
  620. {
  621. _Py_IDENTIFIER(__module__);
  622. _Py_IDENTIFIER(_ast);
  623. PyObject *fnames, *result;
  624. int i;
  625. fnames = PyTuple_New(num_fields);
  626. if (!fnames) return NULL;
  627. for (i = 0; i < num_fields; i++) {
  628. PyObject *field = PyUnicode_FromString(fields[i]);
  629. if (!field) {
  630. Py_DECREF(fnames);
  631. return NULL;
  632. }
  633. PyTuple_SET_ITEM(fnames, i, field);
  634. }
  635. result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
  636. type, base,
  637. _PyUnicode_FromId(&PyId__fields), fnames,
  638. _PyUnicode_FromId(&PyId___module__),
  639. _PyUnicode_FromId(&PyId__ast));
  640. Py_DECREF(fnames);
  641. return (PyTypeObject*)result;
  642. }
  643. static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
  644. {
  645. int i, result;
  646. PyObject *s, *l = PyTuple_New(num_fields);
  647. if (!l)
  648. return 0;
  649. for (i = 0; i < num_fields; i++) {
  650. s = PyUnicode_FromString(attrs[i]);
  651. if (!s) {
  652. Py_DECREF(l);
  653. return 0;
  654. }
  655. PyTuple_SET_ITEM(l, i, s);
  656. }
  657. result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0;
  658. Py_DECREF(l);
  659. return result;
  660. }
  661. /* Conversion AST -> Python */
  662. static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
  663. {
  664. Py_ssize_t i, n = asdl_seq_LEN(seq);
  665. PyObject *result = PyList_New(n);
  666. PyObject *value;
  667. if (!result)
  668. return NULL;
  669. for (i = 0; i < n; i++) {
  670. value = func(asdl_seq_GET(seq, i));
  671. if (!value) {
  672. Py_DECREF(result);
  673. return NULL;
  674. }
  675. PyList_SET_ITEM(result, i, value);
  676. }
  677. return result;
  678. }
  679. static PyObject* ast2obj_object(void *o)
  680. {
  681. if (!o)
  682. o = Py_None;
  683. Py_INCREF((PyObject*)o);
  684. return (PyObject*)o;
  685. }
  686. #define ast2obj_singleton ast2obj_object
  687. #define ast2obj_constant ast2obj_object
  688. #define ast2obj_identifier ast2obj_object
  689. #define ast2obj_string ast2obj_object
  690. #define ast2obj_bytes ast2obj_object
  691. static PyObject* ast2obj_int(long b)
  692. {
  693. return PyLong_FromLong(b);
  694. }
  695. /* Conversion Python -> AST */
  696. static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
  697. {
  698. if (obj == Py_None)
  699. obj = NULL;
  700. if (obj) {
  701. if (PyArena_AddPyObject(arena, obj) < 0) {
  702. *out = NULL;
  703. return -1;
  704. }
  705. Py_INCREF(obj);
  706. }
  707. *out = obj;
  708. return 0;
  709. }
  710. static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
  711. {
  712. if (PyArena_AddPyObject(arena, obj) < 0) {
  713. *out = NULL;
  714. return -1;
  715. }
  716. Py_INCREF(obj);
  717. *out = obj;
  718. return 0;
  719. }
  720. static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
  721. {
  722. if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
  723. PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
  724. return 1;
  725. }
  726. return obj2ast_object(obj, out, arena);
  727. }
  728. static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
  729. {
  730. int i;
  731. if (!PyLong_Check(obj)) {
  732. PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
  733. return 1;
  734. }
  735. i = _PyLong_AsInt(obj);
  736. if (i == -1 && PyErr_Occurred())
  737. return 1;
  738. *out = i;
  739. return 0;
  740. }
  741. static int add_ast_fields(void)
  742. {
  743. PyObject *empty_tuple, *d;
  744. if (PyType_Ready(&AST_type) < 0)
  745. return -1;
  746. d = AST_type.tp_dict;
  747. empty_tuple = PyTuple_New(0);
  748. if (!empty_tuple ||
  749. _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 ||
  750. _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) {
  751. Py_XDECREF(empty_tuple);
  752. return -1;
  753. }
  754. Py_DECREF(empty_tuple);
  755. return 0;
  756. }
  757. static int init_types(void)
  758. {
  759. static int initialized;
  760. if (initialized) return 1;
  761. if (add_ast_fields() < 0) return 0;
  762. mod_type = make_type("mod", &AST_type, NULL, 0);
  763. if (!mod_type) return 0;
  764. if (!add_attributes(mod_type, NULL, 0)) return 0;
  765. Module_type = make_type("Module", mod_type, Module_fields, 1);
  766. if (!Module_type) return 0;
  767. Interactive_type = make_type("Interactive", mod_type, Interactive_fields,
  768. 1);
  769. if (!Interactive_type) return 0;
  770. Expression_type = make_type("Expression", mod_type, Expression_fields, 1);
  771. if (!Expression_type) return 0;
  772. Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
  773. if (!Suite_type) return 0;
  774. stmt_type = make_type("stmt", &AST_type, NULL, 0);
  775. if (!stmt_type) return 0;
  776. if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
  777. FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields,
  778. 5);
  779. if (!FunctionDef_type) return 0;
  780. AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type,
  781. AsyncFunctionDef_fields, 5);
  782. if (!AsyncFunctionDef_type) return 0;
  783. ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5);
  784. if (!ClassDef_type) return 0;
  785. Return_type = make_type("Return", stmt_type, Return_fields, 1);
  786. if (!Return_type) return 0;
  787. Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
  788. if (!Delete_type) return 0;
  789. Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
  790. if (!Assign_type) return 0;
  791. AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
  792. if (!AugAssign_type) return 0;
  793. AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4);
  794. if (!AnnAssign_type) return 0;
  795. For_type = make_type("For", stmt_type, For_fields, 4);
  796. if (!For_type) return 0;
  797. AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 4);
  798. if (!AsyncFor_type) return 0;
  799. While_type = make_type("While", stmt_type, While_fields, 3);
  800. if (!While_type) return 0;
  801. If_type = make_type("If", stmt_type, If_fields, 3);
  802. if (!If_type) return 0;
  803. With_type = make_type("With", stmt_type, With_fields, 2);
  804. if (!With_type) return 0;
  805. AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 2);
  806. if (!AsyncWith_type) return 0;
  807. Raise_type = make_type("Raise", stmt_type, Raise_fields, 2);
  808. if (!Raise_type) return 0;
  809. Try_type = make_type("Try", stmt_type, Try_fields, 4);
  810. if (!Try_type) return 0;
  811. Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
  812. if (!Assert_type) return 0;
  813. Import_type = make_type("Import", stmt_type, Import_fields, 1);
  814. if (!Import_type) return 0;
  815. ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3);
  816. if (!ImportFrom_type) return 0;
  817. Global_type = make_type("Global", stmt_type, Global_fields, 1);
  818. if (!Global_type) return 0;
  819. Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
  820. if (!Nonlocal_type) return 0;
  821. Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
  822. if (!Expr_type) return 0;
  823. Pass_type = make_type("Pass", stmt_type, NULL, 0);
  824. if (!Pass_type) return 0;
  825. Break_type = make_type("Break", stmt_type, NULL, 0);
  826. if (!Break_type) return 0;
  827. Continue_type = make_type("Continue", stmt_type, NULL, 0);
  828. if (!Continue_type) return 0;
  829. expr_type = make_type("expr", &AST_type, NULL, 0);
  830. if (!expr_type) return 0;
  831. if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
  832. BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
  833. if (!BoolOp_type) return 0;
  834. BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
  835. if (!BinOp_type) return 0;
  836. UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
  837. if (!UnaryOp_type) return 0;
  838. Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
  839. if (!Lambda_type) return 0;
  840. IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
  841. if (!IfExp_type) return 0;
  842. Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
  843. if (!Dict_type) return 0;
  844. Set_type = make_type("Set", expr_type, Set_fields, 1);
  845. if (!Set_type) return 0;
  846. ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
  847. if (!ListComp_type) return 0;
  848. SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
  849. if (!SetComp_type) return 0;
  850. DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
  851. if (!DictComp_type) return 0;
  852. GeneratorExp_type = make_type("GeneratorExp", expr_type,
  853. GeneratorExp_fields, 2);
  854. if (!GeneratorExp_type) return 0;
  855. Await_type = make_type("Await", expr_type, Await_fields, 1);
  856. if (!Await_type) return 0;
  857. Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
  858. if (!Yield_type) return 0;
  859. YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1);
  860. if (!YieldFrom_type) return 0;
  861. Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
  862. if (!Compare_type) return 0;
  863. Call_type = make_type("Call", expr_type, Call_fields, 3);
  864. if (!Call_type) return 0;
  865. FormattedValue_type = make_type("FormattedValue", expr_type,
  866. FormattedValue_fields, 3);
  867. if (!FormattedValue_type) return 0;
  868. JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1);
  869. if (!JoinedStr_type) return 0;
  870. Constant_type = make_type("Constant", expr_type, Constant_fields, 1);
  871. if (!Constant_type) return 0;
  872. Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
  873. if (!Attribute_type) return 0;
  874. Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
  875. if (!Subscript_type) return 0;
  876. Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
  877. if (!Starred_type) return 0;
  878. Name_type = make_type("Name", expr_type, Name_fields, 2);
  879. if (!Name_type) return 0;
  880. List_type = make_type("List", expr_type, List_fields, 2);
  881. if (!List_type) return 0;
  882. Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
  883. if (!Tuple_type) return 0;
  884. expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
  885. if (!expr_context_type) return 0;
  886. if (!add_attributes(expr_context_type, NULL, 0)) return 0;
  887. Load_type = make_type("Load", expr_context_type, NULL, 0);
  888. if (!Load_type) return 0;
  889. Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
  890. if (!Load_singleton) return 0;
  891. Store_type = make_type("Store", expr_context_type, NULL, 0);
  892. if (!Store_type) return 0;
  893. Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
  894. if (!Store_singleton) return 0;
  895. Del_type = make_type("Del", expr_context_type, NULL, 0);
  896. if (!Del_type) return 0;
  897. Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
  898. if (!Del_singleton) return 0;
  899. AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
  900. if (!AugLoad_type) return 0;
  901. AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
  902. if (!AugLoad_singleton) return 0;
  903. AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
  904. if (!AugStore_type) return 0;
  905. AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
  906. if (!AugStore_singleton) return 0;
  907. Param_type = make_type("Param", expr_context_type, NULL, 0);
  908. if (!Param_type) return 0;
  909. Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
  910. if (!Param_singleton) return 0;
  911. slice_type = make_type("slice", &AST_type, NULL, 0);
  912. if (!slice_type) return 0;
  913. if (!add_attributes(slice_type, NULL, 0)) return 0;
  914. Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
  915. if (!Slice_type) return 0;
  916. ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
  917. if (!ExtSlice_type) return 0;
  918. Index_type = make_type("Index", slice_type, Index_fields, 1);
  919. if (!Index_type) return 0;
  920. boolop_type = make_type("boolop", &AST_type, NULL, 0);
  921. if (!boolop_type) return 0;
  922. if (!add_attributes(boolop_type, NULL, 0)) return 0;
  923. And_type = make_type("And", boolop_type, NULL, 0);
  924. if (!And_type) return 0;
  925. And_singleton = PyType_GenericNew(And_type, NULL, NULL);
  926. if (!And_singleton) return 0;
  927. Or_type = make_type("Or", boolop_type, NULL, 0);
  928. if (!Or_type) return 0;
  929. Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
  930. if (!Or_singleton) return 0;
  931. operator_type = make_type("operator", &AST_type, NULL, 0);
  932. if (!operator_type) return 0;
  933. if (!add_attributes(operator_type, NULL, 0)) return 0;
  934. Add_type = make_type("Add", operator_type, NULL, 0);
  935. if (!Add_type) return 0;
  936. Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
  937. if (!Add_singleton) return 0;
  938. Sub_type = make_type("Sub", operator_type, NULL, 0);
  939. if (!Sub_type) return 0;
  940. Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
  941. if (!Sub_singleton) return 0;
  942. Mult_type = make_type("Mult", operator_type, NULL, 0);
  943. if (!Mult_type) return 0;
  944. Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
  945. if (!Mult_singleton) return 0;
  946. MatMult_type = make_type("MatMult", operator_type, NULL, 0);
  947. if (!MatMult_type) return 0;
  948. MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL);
  949. if (!MatMult_singleton) return 0;
  950. Div_type = make_type("Div", operator_type, NULL, 0);
  951. if (!Div_type) return 0;
  952. Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
  953. if (!Div_singleton) return 0;
  954. Mod_type = make_type("Mod", operator_type, NULL, 0);
  955. if (!Mod_type) return 0;
  956. Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
  957. if (!Mod_singleton) return 0;
  958. Pow_type = make_type("Pow", operator_type, NULL, 0);
  959. if (!Pow_type) return 0;
  960. Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
  961. if (!Pow_singleton) return 0;
  962. LShift_type = make_type("LShift", operator_type, NULL, 0);
  963. if (!LShift_type) return 0;
  964. LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
  965. if (!LShift_singleton) return 0;
  966. RShift_type = make_type("RShift", operator_type, NULL, 0);
  967. if (!RShift_type) return 0;
  968. RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
  969. if (!RShift_singleton) return 0;
  970. BitOr_type = make_type("BitOr", operator_type, NULL, 0);
  971. if (!BitOr_type) return 0;
  972. BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
  973. if (!BitOr_singleton) return 0;
  974. BitXor_type = make_type("BitXor", operator_type, NULL, 0);
  975. if (!BitXor_type) return 0;
  976. BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
  977. if (!BitXor_singleton) return 0;
  978. BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
  979. if (!BitAnd_type) return 0;
  980. BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
  981. if (!BitAnd_singleton) return 0;
  982. FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
  983. if (!FloorDiv_type) return 0;
  984. FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
  985. if (!FloorDiv_singleton) return 0;
  986. unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
  987. if (!unaryop_type) return 0;
  988. if (!add_attributes(unaryop_type, NULL, 0)) return 0;
  989. Invert_type = make_type("Invert", unaryop_type, NULL, 0);
  990. if (!Invert_type) return 0;
  991. Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
  992. if (!Invert_singleton) return 0;
  993. Not_type = make_type("Not", unaryop_type, NULL, 0);
  994. if (!Not_type) return 0;
  995. Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
  996. if (!Not_singleton) return 0;
  997. UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
  998. if (!UAdd_type) return 0;
  999. UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
  1000. if (!UAdd_singleton) return 0;
  1001. USub_type = make_type("USub", unaryop_type, NULL, 0);
  1002. if (!USub_type) return 0;
  1003. USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
  1004. if (!USub_singleton) return 0;
  1005. cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
  1006. if (!cmpop_type) return 0;
  1007. if (!add_attributes(cmpop_type, NULL, 0)) return 0;
  1008. Eq_type = make_type("Eq", cmpop_type, NULL, 0);
  1009. if (!Eq_type) return 0;
  1010. Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
  1011. if (!Eq_singleton) return 0;
  1012. NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
  1013. if (!NotEq_type) return 0;
  1014. NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
  1015. if (!NotEq_singleton) return 0;
  1016. Lt_type = make_type("Lt", cmpop_type, NULL, 0);
  1017. if (!Lt_type) return 0;
  1018. Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
  1019. if (!Lt_singleton) return 0;
  1020. LtE_type = make_type("LtE", cmpop_type, NULL, 0);
  1021. if (!LtE_type) return 0;
  1022. LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
  1023. if (!LtE_singleton) return 0;
  1024. Gt_type = make_type("Gt", cmpop_type, NULL, 0);
  1025. if (!Gt_type) return 0;
  1026. Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
  1027. if (!Gt_singleton) return 0;
  1028. GtE_type = make_type("GtE", cmpop_type, NULL, 0);
  1029. if (!GtE_type) return 0;
  1030. GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
  1031. if (!GtE_singleton) return 0;
  1032. Is_type = make_type("Is", cmpop_type, NULL, 0);
  1033. if (!Is_type) return 0;
  1034. Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
  1035. if (!Is_singleton) return 0;
  1036. IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
  1037. if (!IsNot_type) return 0;
  1038. IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
  1039. if (!IsNot_singleton) return 0;
  1040. In_type = make_type("In", cmpop_type, NULL, 0);
  1041. if (!In_type) return 0;
  1042. In_singleton = PyType_GenericNew(In_type, NULL, NULL);
  1043. if (!In_singleton) return 0;
  1044. NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
  1045. if (!NotIn_type) return 0;
  1046. NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
  1047. if (!NotIn_singleton) return 0;
  1048. comprehension_type = make_type("comprehension", &AST_type,
  1049. comprehension_fields, 4);
  1050. if (!comprehension_type) return 0;
  1051. if (!add_attributes(comprehension_type, NULL, 0)) return 0;
  1052. excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
  1053. if (!excepthandler_type) return 0;
  1054. if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
  1055. return 0;
  1056. ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
  1057. ExceptHandler_fields, 3);
  1058. if (!ExceptHandler_type) return 0;
  1059. arguments_type = make_type("arguments", &AST_type, arguments_fields, 6);
  1060. if (!arguments_type) return 0;
  1061. if (!add_attributes(arguments_type, NULL, 0)) return 0;
  1062. arg_type = make_type("arg", &AST_type, arg_fields, 2);
  1063. if (!arg_type) return 0;
  1064. if (!add_attributes(arg_type, arg_attributes, 2)) return 0;
  1065. keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
  1066. if (!keyword_type) return 0;
  1067. if (!add_attributes(keyword_type, NULL, 0)) return 0;
  1068. alias_type = make_type("alias", &AST_type, alias_fields, 2);
  1069. if (!alias_type) return 0;
  1070. if (!add_attributes(alias_type, NULL, 0)) return 0;
  1071. withitem_type = make_type("withitem", &AST_type, withitem_fields, 2);
  1072. if (!withitem_type) return 0;
  1073. if (!add_attributes(withitem_type, NULL, 0)) return 0;
  1074. initialized = 1;
  1075. return 1;
  1076. }
  1077. static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
  1078. static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
  1079. static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
  1080. static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
  1081. arena);
  1082. static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
  1083. static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
  1084. static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
  1085. static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
  1086. static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
  1087. static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
  1088. arena);
  1089. static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
  1090. arena);
  1091. static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
  1092. static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
  1093. static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
  1094. static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
  1095. static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
  1096. mod_ty
  1097. Module(asdl_seq * body, PyArena *arena)
  1098. {
  1099. mod_ty p;
  1100. p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
  1101. if (!p)
  1102. return NULL;
  1103. p->kind = Module_kind;
  1104. p->v.Module.body = body;
  1105. return p;
  1106. }
  1107. mod_ty
  1108. Interactive(asdl_seq * body, PyArena *arena)
  1109. {
  1110. mod_ty p;
  1111. p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
  1112. if (!p)
  1113. return NULL;
  1114. p->kind = Interactive_kind;
  1115. p->v.Interactive.body = body;
  1116. return p;
  1117. }
  1118. mod_ty
  1119. Expression(expr_ty body, PyArena *arena)
  1120. {
  1121. mod_ty p;
  1122. if (!body) {
  1123. PyErr_SetString(PyExc_ValueError,
  1124. "field body is required for Expression");
  1125. return NULL;
  1126. }
  1127. p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
  1128. if (!p)
  1129. return NULL;
  1130. p->kind = Expression_kind;
  1131. p->v.Expression.body = body;
  1132. return p;
  1133. }
  1134. mod_ty
  1135. Suite(asdl_seq * body, PyArena *arena)
  1136. {
  1137. mod_ty p;
  1138. p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
  1139. if (!p)
  1140. return NULL;
  1141. p->kind = Suite_kind;
  1142. p->v.Suite.body = body;
  1143. return p;
  1144. }
  1145. stmt_ty
  1146. FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
  1147. decorator_list, expr_ty returns, int lineno, int col_offset,
  1148. PyArena *arena)
  1149. {
  1150. stmt_ty p;
  1151. if (!name) {
  1152. PyErr_SetString(PyExc_ValueError,
  1153. "field name is required for FunctionDef");
  1154. return NULL;
  1155. }
  1156. if (!args) {
  1157. PyErr_SetString(PyExc_ValueError,
  1158. "field args is required for FunctionDef");
  1159. return NULL;
  1160. }
  1161. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1162. if (!p)
  1163. return NULL;
  1164. p->kind = FunctionDef_kind;
  1165. p->v.FunctionDef.name = name;
  1166. p->v.FunctionDef.args = args;
  1167. p->v.FunctionDef.body = body;
  1168. p->v.FunctionDef.decorator_list = decorator_list;
  1169. p->v.FunctionDef.returns = returns;
  1170. p->lineno = lineno;
  1171. p->col_offset = col_offset;
  1172. return p;
  1173. }
  1174. stmt_ty
  1175. AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
  1176. * decorator_list, expr_ty returns, int lineno, int col_offset,
  1177. PyArena *arena)
  1178. {
  1179. stmt_ty p;
  1180. if (!name) {
  1181. PyErr_SetString(PyExc_ValueError,
  1182. "field name is required for AsyncFunctionDef");
  1183. return NULL;
  1184. }
  1185. if (!args) {
  1186. PyErr_SetString(PyExc_ValueError,
  1187. "field args is required for AsyncFunctionDef");
  1188. return NULL;
  1189. }
  1190. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1191. if (!p)
  1192. return NULL;
  1193. p->kind = AsyncFunctionDef_kind;
  1194. p->v.AsyncFunctionDef.name = name;
  1195. p->v.AsyncFunctionDef.args = args;
  1196. p->v.AsyncFunctionDef.body = body;
  1197. p->v.AsyncFunctionDef.decorator_list = decorator_list;
  1198. p->v.AsyncFunctionDef.returns = returns;
  1199. p->lineno = lineno;
  1200. p->col_offset = col_offset;
  1201. return p;
  1202. }
  1203. stmt_ty
  1204. ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
  1205. body, asdl_seq * decorator_list, int lineno, int col_offset, PyArena
  1206. *arena)
  1207. {
  1208. stmt_ty p;
  1209. if (!name) {
  1210. PyErr_SetString(PyExc_ValueError,
  1211. "field name is required for ClassDef");
  1212. return NULL;
  1213. }
  1214. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1215. if (!p)
  1216. return NULL;
  1217. p->kind = ClassDef_kind;
  1218. p->v.ClassDef.name = name;
  1219. p->v.ClassDef.bases = bases;
  1220. p->v.ClassDef.keywords = keywords;
  1221. p->v.ClassDef.body = body;
  1222. p->v.ClassDef.decorator_list = decorator_list;
  1223. p->lineno = lineno;
  1224. p->col_offset = col_offset;
  1225. return p;
  1226. }
  1227. stmt_ty
  1228. Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
  1229. {
  1230. stmt_ty p;
  1231. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1232. if (!p)
  1233. return NULL;
  1234. p->kind = Return_kind;
  1235. p->v.Return.value = value;
  1236. p->lineno = lineno;
  1237. p->col_offset = col_offset;
  1238. return p;
  1239. }
  1240. stmt_ty
  1241. Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
  1242. {
  1243. stmt_ty p;
  1244. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1245. if (!p)
  1246. return NULL;
  1247. p->kind = Delete_kind;
  1248. p->v.Delete.targets = targets;
  1249. p->lineno = lineno;
  1250. p->col_offset = col_offset;
  1251. return p;
  1252. }
  1253. stmt_ty
  1254. Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
  1255. *arena)
  1256. {
  1257. stmt_ty p;
  1258. if (!value) {
  1259. PyErr_SetString(PyExc_ValueError,
  1260. "field value is required for Assign");
  1261. return NULL;
  1262. }
  1263. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1264. if (!p)
  1265. return NULL;
  1266. p->kind = Assign_kind;
  1267. p->v.Assign.targets = targets;
  1268. p->v.Assign.value = value;
  1269. p->lineno = lineno;
  1270. p->col_offset = col_offset;
  1271. return p;
  1272. }
  1273. stmt_ty
  1274. AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
  1275. col_offset, PyArena *arena)
  1276. {
  1277. stmt_ty p;
  1278. if (!target) {
  1279. PyErr_SetString(PyExc_ValueError,
  1280. "field target is required for AugAssign");
  1281. return NULL;
  1282. }
  1283. if (!op) {
  1284. PyErr_SetString(PyExc_ValueError,
  1285. "field op is required for AugAssign");
  1286. return NULL;
  1287. }
  1288. if (!value) {
  1289. PyErr_SetString(PyExc_ValueError,
  1290. "field value is required for AugAssign");
  1291. return NULL;
  1292. }
  1293. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1294. if (!p)
  1295. return NULL;
  1296. p->kind = AugAssign_kind;
  1297. p->v.AugAssign.target = target;
  1298. p->v.AugAssign.op = op;
  1299. p->v.AugAssign.value = value;
  1300. p->lineno = lineno;
  1301. p->col_offset = col_offset;
  1302. return p;
  1303. }
  1304. stmt_ty
  1305. AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
  1306. lineno, int col_offset, PyArena *arena)
  1307. {
  1308. stmt_ty p;
  1309. if (!target) {
  1310. PyErr_SetString(PyExc_ValueError,
  1311. "field target is required for AnnAssign");
  1312. return NULL;
  1313. }
  1314. if (!annotation) {
  1315. PyErr_SetString(PyExc_ValueError,
  1316. "field annotation is required for AnnAssign");
  1317. return NULL;
  1318. }
  1319. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1320. if (!p)
  1321. return NULL;
  1322. p->kind = AnnAssign_kind;
  1323. p->v.AnnAssign.target = target;
  1324. p->v.AnnAssign.annotation = annotation;
  1325. p->v.AnnAssign.value = value;
  1326. p->v.AnnAssign.simple = simple;
  1327. p->lineno = lineno;
  1328. p->col_offset = col_offset;
  1329. return p;
  1330. }
  1331. stmt_ty
  1332. For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
  1333. lineno, int col_offset, PyArena *arena)
  1334. {
  1335. stmt_ty p;
  1336. if (!target) {
  1337. PyErr_SetString(PyExc_ValueError,
  1338. "field target is required for For");
  1339. return NULL;
  1340. }
  1341. if (!iter) {
  1342. PyErr_SetString(PyExc_ValueError,
  1343. "field iter is required for For");
  1344. return NULL;
  1345. }
  1346. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1347. if (!p)
  1348. return NULL;
  1349. p->kind = For_kind;
  1350. p->v.For.target = target;
  1351. p->v.For.iter = iter;
  1352. p->v.For.body = body;
  1353. p->v.For.orelse = orelse;
  1354. p->lineno = lineno;
  1355. p->col_offset = col_offset;
  1356. return p;
  1357. }
  1358. stmt_ty
  1359. AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
  1360. lineno, int col_offset, PyArena *arena)
  1361. {
  1362. stmt_ty p;
  1363. if (!target) {
  1364. PyErr_SetString(PyExc_ValueError,
  1365. "field target is required for AsyncFor");
  1366. return NULL;
  1367. }
  1368. if (!iter) {
  1369. PyErr_SetString(PyExc_ValueError,
  1370. "field iter is required for AsyncFor");
  1371. return NULL;
  1372. }
  1373. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1374. if (!p)
  1375. return NULL;
  1376. p->kind = AsyncFor_kind;
  1377. p->v.AsyncFor.target = target;
  1378. p->v.AsyncFor.iter = iter;
  1379. p->v.AsyncFor.body = body;
  1380. p->v.AsyncFor.orelse = orelse;
  1381. p->lineno = lineno;
  1382. p->col_offset = col_offset;
  1383. return p;
  1384. }
  1385. stmt_ty
  1386. While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
  1387. col_offset, PyArena *arena)
  1388. {
  1389. stmt_ty p;
  1390. if (!test) {
  1391. PyErr_SetString(PyExc_ValueError,
  1392. "field test is required for While");
  1393. return NULL;
  1394. }
  1395. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1396. if (!p)
  1397. return NULL;
  1398. p->kind = While_kind;
  1399. p->v.While.test = test;
  1400. p->v.While.body = body;
  1401. p->v.While.orelse = orelse;
  1402. p->lineno = lineno;
  1403. p->col_offset = col_offset;
  1404. return p;
  1405. }
  1406. stmt_ty
  1407. If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
  1408. col_offset, PyArena *arena)
  1409. {
  1410. stmt_ty p;
  1411. if (!test) {
  1412. PyErr_SetString(PyExc_ValueError,
  1413. "field test is required for If");
  1414. return NULL;
  1415. }
  1416. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1417. if (!p)
  1418. return NULL;
  1419. p->kind = If_kind;
  1420. p->v.If.test = test;
  1421. p->v.If.body = body;
  1422. p->v.If.orelse = orelse;
  1423. p->lineno = lineno;
  1424. p->col_offset = col_offset;
  1425. return p;
  1426. }
  1427. stmt_ty
  1428. With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena
  1429. *arena)
  1430. {
  1431. stmt_ty p;
  1432. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1433. if (!p)
  1434. return NULL;
  1435. p->kind = With_kind;
  1436. p->v.With.items = items;
  1437. p->v.With.body = body;
  1438. p->lineno = lineno;
  1439. p->col_offset = col_offset;
  1440. return p;
  1441. }
  1442. stmt_ty
  1443. AsyncWith(asdl_seq * items, asdl_seq * body, int lineno, int col_offset,
  1444. PyArena *arena)
  1445. {
  1446. stmt_ty p;
  1447. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1448. if (!p)
  1449. return NULL;
  1450. p->kind = AsyncWith_kind;
  1451. p->v.AsyncWith.items = items;
  1452. p->v.AsyncWith.body = body;
  1453. p->lineno = lineno;
  1454. p->col_offset = col_offset;
  1455. return p;
  1456. }
  1457. stmt_ty
  1458. Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena)
  1459. {
  1460. stmt_ty p;
  1461. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1462. if (!p)
  1463. return NULL;
  1464. p->kind = Raise_kind;
  1465. p->v.Raise.exc = exc;
  1466. p->v.Raise.cause = cause;
  1467. p->lineno = lineno;
  1468. p->col_offset = col_offset;
  1469. return p;
  1470. }
  1471. stmt_ty
  1472. Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
  1473. finalbody, int lineno, int col_offset, PyArena *arena)
  1474. {
  1475. stmt_ty p;
  1476. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1477. if (!p)
  1478. return NULL;
  1479. p->kind = Try_kind;
  1480. p->v.Try.body = body;
  1481. p->v.Try.handlers = handlers;
  1482. p->v.Try.orelse = orelse;
  1483. p->v.Try.finalbody = finalbody;
  1484. p->lineno = lineno;
  1485. p->col_offset = col_offset;
  1486. return p;
  1487. }
  1488. stmt_ty
  1489. Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
  1490. {
  1491. stmt_ty p;
  1492. if (!test) {
  1493. PyErr_SetString(PyExc_ValueError,
  1494. "field test is required for Assert");
  1495. return NULL;
  1496. }
  1497. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1498. if (!p)
  1499. return NULL;
  1500. p->kind = Assert_kind;
  1501. p->v.Assert.test = test;
  1502. p->v.Assert.msg = msg;
  1503. p->lineno = lineno;
  1504. p->col_offset = col_offset;
  1505. return p;
  1506. }
  1507. stmt_ty
  1508. Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
  1509. {
  1510. stmt_ty p;
  1511. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1512. if (!p)
  1513. return NULL;
  1514. p->kind = Import_kind;
  1515. p->v.Import.names = names;
  1516. p->lineno = lineno;
  1517. p->col_offset = col_offset;
  1518. return p;
  1519. }
  1520. stmt_ty
  1521. ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
  1522. col_offset, PyArena *arena)
  1523. {
  1524. stmt_ty p;
  1525. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1526. if (!p)
  1527. return NULL;
  1528. p->kind = ImportFrom_kind;
  1529. p->v.ImportFrom.module = module;
  1530. p->v.ImportFrom.names = names;
  1531. p->v.ImportFrom.level = level;
  1532. p->lineno = lineno;
  1533. p->col_offset = col_offset;
  1534. return p;
  1535. }
  1536. stmt_ty
  1537. Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
  1538. {
  1539. stmt_ty p;
  1540. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1541. if (!p)
  1542. return NULL;
  1543. p->kind = Global_kind;
  1544. p->v.Global.names = names;
  1545. p->lineno = lineno;
  1546. p->col_offset = col_offset;
  1547. return p;
  1548. }
  1549. stmt_ty
  1550. Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
  1551. {
  1552. stmt_ty p;
  1553. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1554. if (!p)
  1555. return NULL;
  1556. p->kind = Nonlocal_kind;
  1557. p->v.Nonlocal.names = names;
  1558. p->lineno = lineno;
  1559. p->col_offset = col_offset;
  1560. return p;
  1561. }
  1562. stmt_ty
  1563. Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
  1564. {
  1565. stmt_ty p;
  1566. if (!value) {
  1567. PyErr_SetString(PyExc_ValueError,
  1568. "field value is required for Expr");
  1569. return NULL;
  1570. }
  1571. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1572. if (!p)
  1573. return NULL;
  1574. p->kind = Expr_kind;
  1575. p->v.Expr.value = value;
  1576. p->lineno = lineno;
  1577. p->col_offset = col_offset;
  1578. return p;
  1579. }
  1580. stmt_ty
  1581. Pass(int lineno, int col_offset, PyArena *arena)
  1582. {
  1583. stmt_ty p;
  1584. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1585. if (!p)
  1586. return NULL;
  1587. p->kind = Pass_kind;
  1588. p->lineno = lineno;
  1589. p->col_offset = col_offset;
  1590. return p;
  1591. }
  1592. stmt_ty
  1593. Break(int lineno, int col_offset, PyArena *arena)
  1594. {
  1595. stmt_ty p;
  1596. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1597. if (!p)
  1598. return NULL;
  1599. p->kind = Break_kind;
  1600. p->lineno = lineno;
  1601. p->col_offset = col_offset;
  1602. return p;
  1603. }
  1604. stmt_ty
  1605. Continue(int lineno, int col_offset, PyArena *arena)
  1606. {
  1607. stmt_ty p;
  1608. p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
  1609. if (!p)
  1610. return NULL;
  1611. p->kind = Continue_kind;
  1612. p->lineno = lineno;
  1613. p->col_offset = col_offset;
  1614. return p;
  1615. }
  1616. expr_ty
  1617. BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
  1618. *arena)
  1619. {
  1620. expr_ty p;
  1621. if (!op) {
  1622. PyErr_SetString(PyExc_ValueError,
  1623. "field op is required for BoolOp");
  1624. return NULL;
  1625. }
  1626. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1627. if (!p)
  1628. return NULL;
  1629. p->kind = BoolOp_kind;
  1630. p->v.BoolOp.op = op;
  1631. p->v.BoolOp.values = values;
  1632. p->lineno = lineno;
  1633. p->col_offset = col_offset;
  1634. return p;
  1635. }
  1636. expr_ty
  1637. BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
  1638. PyArena *arena)
  1639. {
  1640. expr_ty p;
  1641. if (!left) {
  1642. PyErr_SetString(PyExc_ValueError,
  1643. "field left is required for BinOp");
  1644. return NULL;
  1645. }
  1646. if (!op) {
  1647. PyErr_SetString(PyExc_ValueError,
  1648. "field op is required for BinOp");
  1649. return NULL;
  1650. }
  1651. if (!right) {
  1652. PyErr_SetString(PyExc_ValueError,
  1653. "field right is required for BinOp");
  1654. return NULL;
  1655. }
  1656. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1657. if (!p)
  1658. return NULL;
  1659. p->kind = BinOp_kind;
  1660. p->v.BinOp.left = left;
  1661. p->v.BinOp.op = op;
  1662. p->v.BinOp.right = right;
  1663. p->lineno = lineno;
  1664. p->col_offset = col_offset;
  1665. return p;
  1666. }
  1667. expr_ty
  1668. UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
  1669. *arena)
  1670. {
  1671. expr_ty p;
  1672. if (!op) {
  1673. PyErr_SetString(PyExc_ValueError,
  1674. "field op is required for UnaryOp");
  1675. return NULL;
  1676. }
  1677. if (!operand) {
  1678. PyErr_SetString(PyExc_ValueError,
  1679. "field operand is required for UnaryOp");
  1680. return NULL;
  1681. }
  1682. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1683. if (!p)
  1684. return NULL;
  1685. p->kind = UnaryOp_kind;
  1686. p->v.UnaryOp.op = op;
  1687. p->v.UnaryOp.operand = operand;
  1688. p->lineno = lineno;
  1689. p->col_offset = col_offset;
  1690. return p;
  1691. }
  1692. expr_ty
  1693. Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
  1694. *arena)
  1695. {
  1696. expr_ty p;
  1697. if (!args) {
  1698. PyErr_SetString(PyExc_ValueError,
  1699. "field args is required for Lambda");
  1700. return NULL;
  1701. }
  1702. if (!body) {
  1703. PyErr_SetString(PyExc_ValueError,
  1704. "field body is required for Lambda");
  1705. return NULL;
  1706. }
  1707. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1708. if (!p)
  1709. return NULL;
  1710. p->kind = Lambda_kind;
  1711. p->v.Lambda.args = args;
  1712. p->v.Lambda.body = body;
  1713. p->lineno = lineno;
  1714. p->col_offset = col_offset;
  1715. return p;
  1716. }
  1717. expr_ty
  1718. IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
  1719. PyArena *arena)
  1720. {
  1721. expr_ty p;
  1722. if (!test) {
  1723. PyErr_SetString(PyExc_ValueError,
  1724. "field test is required for IfExp");
  1725. return NULL;
  1726. }
  1727. if (!body) {
  1728. PyErr_SetString(PyExc_ValueError,
  1729. "field body is required for IfExp");
  1730. return NULL;
  1731. }
  1732. if (!orelse) {
  1733. PyErr_SetString(PyExc_ValueError,
  1734. "field orelse is required for IfExp");
  1735. return NULL;
  1736. }
  1737. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1738. if (!p)
  1739. return NULL;
  1740. p->kind = IfExp_kind;
  1741. p->v.IfExp.test = test;
  1742. p->v.IfExp.body = body;
  1743. p->v.IfExp.orelse = orelse;
  1744. p->lineno = lineno;
  1745. p->col_offset = col_offset;
  1746. return p;
  1747. }
  1748. expr_ty
  1749. Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
  1750. *arena)
  1751. {
  1752. expr_ty p;
  1753. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1754. if (!p)
  1755. return NULL;
  1756. p->kind = Dict_kind;
  1757. p->v.Dict.keys = keys;
  1758. p->v.Dict.values = values;
  1759. p->lineno = lineno;
  1760. p->col_offset = col_offset;
  1761. return p;
  1762. }
  1763. expr_ty
  1764. Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
  1765. {
  1766. expr_ty p;
  1767. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1768. if (!p)
  1769. return NULL;
  1770. p->kind = Set_kind;
  1771. p->v.Set.elts = elts;
  1772. p->lineno = lineno;
  1773. p->col_offset = col_offset;
  1774. return p;
  1775. }
  1776. expr_ty
  1777. ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
  1778. PyArena *arena)
  1779. {
  1780. expr_ty p;
  1781. if (!elt) {
  1782. PyErr_SetString(PyExc_ValueError,
  1783. "field elt is required for ListComp");
  1784. return NULL;
  1785. }
  1786. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1787. if (!p)
  1788. return NULL;
  1789. p->kind = ListComp_kind;
  1790. p->v.ListComp.elt = elt;
  1791. p->v.ListComp.generators = generators;
  1792. p->lineno = lineno;
  1793. p->col_offset = col_offset;
  1794. return p;
  1795. }
  1796. expr_ty
  1797. SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
  1798. *arena)
  1799. {
  1800. expr_ty p;
  1801. if (!elt) {
  1802. PyErr_SetString(PyExc_ValueError,
  1803. "field elt is required for SetComp");
  1804. return NULL;
  1805. }
  1806. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1807. if (!p)
  1808. return NULL;
  1809. p->kind = SetComp_kind;
  1810. p->v.SetComp.elt = elt;
  1811. p->v.SetComp.generators = generators;
  1812. p->lineno = lineno;
  1813. p->col_offset = col_offset;
  1814. return p;
  1815. }
  1816. expr_ty
  1817. DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
  1818. col_offset, PyArena *arena)
  1819. {
  1820. expr_ty p;
  1821. if (!key) {
  1822. PyErr_SetString(PyExc_ValueError,
  1823. "field key is required for DictComp");
  1824. return NULL;
  1825. }
  1826. if (!value) {
  1827. PyErr_SetString(PyExc_ValueError,
  1828. "field value is required for DictComp");
  1829. return NULL;
  1830. }
  1831. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1832. if (!p)
  1833. return NULL;
  1834. p->kind = DictComp_kind;
  1835. p->v.DictComp.key = key;
  1836. p->v.DictComp.value = value;
  1837. p->v.DictComp.generators = generators;
  1838. p->lineno = lineno;
  1839. p->col_offset = col_offset;
  1840. return p;
  1841. }
  1842. expr_ty
  1843. GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
  1844. PyArena *arena)
  1845. {
  1846. expr_ty p;
  1847. if (!elt) {
  1848. PyErr_SetString(PyExc_ValueError,
  1849. "field elt is required for GeneratorExp");
  1850. return NULL;
  1851. }
  1852. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1853. if (!p)
  1854. return NULL;
  1855. p->kind = GeneratorExp_kind;
  1856. p->v.GeneratorExp.elt = elt;
  1857. p->v.GeneratorExp.generators = generators;
  1858. p->lineno = lineno;
  1859. p->col_offset = col_offset;
  1860. return p;
  1861. }
  1862. expr_ty
  1863. Await(expr_ty value, int lineno, int col_offset, PyArena *arena)
  1864. {
  1865. expr_ty p;
  1866. if (!value) {
  1867. PyErr_SetString(PyExc_ValueError,
  1868. "field value is required for Await");
  1869. return NULL;
  1870. }
  1871. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1872. if (!p)
  1873. return NULL;
  1874. p->kind = Await_kind;
  1875. p->v.Await.value = value;
  1876. p->lineno = lineno;
  1877. p->col_offset = col_offset;
  1878. return p;
  1879. }
  1880. expr_ty
  1881. Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
  1882. {
  1883. expr_ty p;
  1884. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1885. if (!p)
  1886. return NULL;
  1887. p->kind = Yield_kind;
  1888. p->v.Yield.value = value;
  1889. p->lineno = lineno;
  1890. p->col_offset = col_offset;
  1891. return p;
  1892. }
  1893. expr_ty
  1894. YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena)
  1895. {
  1896. expr_ty p;
  1897. if (!value) {
  1898. PyErr_SetString(PyExc_ValueError,
  1899. "field value is required for YieldFrom");
  1900. return NULL;
  1901. }
  1902. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1903. if (!p)
  1904. return NULL;
  1905. p->kind = YieldFrom_kind;
  1906. p->v.YieldFrom.value = value;
  1907. p->lineno = lineno;
  1908. p->col_offset = col_offset;
  1909. return p;
  1910. }
  1911. expr_ty
  1912. Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
  1913. int col_offset, PyArena *arena)
  1914. {
  1915. expr_ty p;
  1916. if (!left) {
  1917. PyErr_SetString(PyExc_ValueError,
  1918. "field left is required for Compare");
  1919. return NULL;
  1920. }
  1921. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1922. if (!p)
  1923. return NULL;
  1924. p->kind = Compare_kind;
  1925. p->v.Compare.left = left;
  1926. p->v.Compare.ops = ops;
  1927. p->v.Compare.comparators = comparators;
  1928. p->lineno = lineno;
  1929. p->col_offset = col_offset;
  1930. return p;
  1931. }
  1932. expr_ty
  1933. Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
  1934. col_offset, PyArena *arena)
  1935. {
  1936. expr_ty p;
  1937. if (!func) {
  1938. PyErr_SetString(PyExc_ValueError,
  1939. "field func is required for Call");
  1940. return NULL;
  1941. }
  1942. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1943. if (!p)
  1944. return NULL;
  1945. p->kind = Call_kind;
  1946. p->v.Call.func = func;
  1947. p->v.Call.args = args;
  1948. p->v.Call.keywords = keywords;
  1949. p->lineno = lineno;
  1950. p->col_offset = col_offset;
  1951. return p;
  1952. }
  1953. expr_ty
  1954. FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
  1955. int col_offset, PyArena *arena)
  1956. {
  1957. expr_ty p;
  1958. if (!value) {
  1959. PyErr_SetString(PyExc_ValueError,
  1960. "field value is required for FormattedValue");
  1961. return NULL;
  1962. }
  1963. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1964. if (!p)
  1965. return NULL;
  1966. p->kind = FormattedValue_kind;
  1967. p->v.FormattedValue.value = value;
  1968. p->v.FormattedValue.conversion = conversion;
  1969. p->v.FormattedValue.format_spec = format_spec;
  1970. p->lineno = lineno;
  1971. p->col_offset = col_offset;
  1972. return p;
  1973. }
  1974. expr_ty
  1975. JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena *arena)
  1976. {
  1977. expr_ty p;
  1978. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1979. if (!p)
  1980. return NULL;
  1981. p->kind = JoinedStr_kind;
  1982. p->v.JoinedStr.values = values;
  1983. p->lineno = lineno;
  1984. p->col_offset = col_offset;
  1985. return p;
  1986. }
  1987. expr_ty
  1988. Constant(constant value, int lineno, int col_offset, PyArena *arena)
  1989. {
  1990. expr_ty p;
  1991. if (!value) {
  1992. PyErr_SetString(PyExc_ValueError,
  1993. "field value is required for Constant");
  1994. return NULL;
  1995. }
  1996. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  1997. if (!p)
  1998. return NULL;
  1999. p->kind = Constant_kind;
  2000. p->v.Constant.value = value;
  2001. p->lineno = lineno;
  2002. p->col_offset = col_offset;
  2003. return p;
  2004. }
  2005. expr_ty
  2006. Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
  2007. col_offset, PyArena *arena)
  2008. {
  2009. expr_ty p;
  2010. if (!value) {
  2011. PyErr_SetString(PyExc_ValueError,
  2012. "field value is required for Attribute");
  2013. return NULL;
  2014. }
  2015. if (!attr) {
  2016. PyErr_SetString(PyExc_ValueError,
  2017. "field attr is required for Attribute");
  2018. return NULL;
  2019. }
  2020. if (!ctx) {
  2021. PyErr_SetString(PyExc_ValueError,
  2022. "field ctx is required for Attribute");
  2023. return NULL;
  2024. }
  2025. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  2026. if (!p)
  2027. return NULL;
  2028. p->kind = Attribute_kind;
  2029. p->v.Attribute.value = value;
  2030. p->v.Attribute.attr = attr;
  2031. p->v.Attribute.ctx = ctx;
  2032. p->lineno = lineno;
  2033. p->col_offset = col_offset;
  2034. return p;
  2035. }
  2036. expr_ty
  2037. Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
  2038. col_offset, PyArena *arena)
  2039. {
  2040. expr_ty p;
  2041. if (!value) {
  2042. PyErr_SetString(PyExc_ValueError,
  2043. "field value is required for Subscript");
  2044. return NULL;
  2045. }
  2046. if (!slice) {
  2047. PyErr_SetString(PyExc_ValueError,
  2048. "field slice is required for Subscript");
  2049. return NULL;
  2050. }
  2051. if (!ctx) {
  2052. PyErr_SetString(PyExc_ValueError,
  2053. "field ctx is required for Subscript");
  2054. return NULL;
  2055. }
  2056. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  2057. if (!p)
  2058. return NULL;
  2059. p->kind = Subscript_kind;
  2060. p->v.Subscript.value = value;
  2061. p->v.Subscript.slice = slice;
  2062. p->v.Subscript.ctx = ctx;
  2063. p->lineno = lineno;
  2064. p->col_offset = col_offset;
  2065. return p;
  2066. }
  2067. expr_ty
  2068. Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena
  2069. *arena)
  2070. {
  2071. expr_ty p;
  2072. if (!value) {
  2073. PyErr_SetString(PyExc_ValueError,
  2074. "field value is required for Starred");
  2075. return NULL;
  2076. }
  2077. if (!ctx) {
  2078. PyErr_SetString(PyExc_ValueError,
  2079. "field ctx is required for Starred");
  2080. return NULL;
  2081. }
  2082. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  2083. if (!p)
  2084. return NULL;
  2085. p->kind = Starred_kind;
  2086. p->v.Starred.value = value;
  2087. p->v.Starred.ctx = ctx;
  2088. p->lineno = lineno;
  2089. p->col_offset = col_offset;
  2090. return p;
  2091. }
  2092. expr_ty
  2093. Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
  2094. *arena)
  2095. {
  2096. expr_ty p;
  2097. if (!id) {
  2098. PyErr_SetString(PyExc_ValueError,
  2099. "field id is required for Name");
  2100. return NULL;
  2101. }
  2102. if (!ctx) {
  2103. PyErr_SetString(PyExc_ValueError,
  2104. "field ctx is required for Name");
  2105. return NULL;
  2106. }
  2107. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  2108. if (!p)
  2109. return NULL;
  2110. p->kind = Name_kind;
  2111. p->v.Name.id = id;
  2112. p->v.Name.ctx = ctx;
  2113. p->lineno = lineno;
  2114. p->col_offset = col_offset;
  2115. return p;
  2116. }
  2117. expr_ty
  2118. List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
  2119. *arena)
  2120. {
  2121. expr_ty p;
  2122. if (!ctx) {
  2123. PyErr_SetString(PyExc_ValueError,
  2124. "field ctx is required for List");
  2125. return NULL;
  2126. }
  2127. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  2128. if (!p)
  2129. return NULL;
  2130. p->kind = List_kind;
  2131. p->v.List.elts = elts;
  2132. p->v.List.ctx = ctx;
  2133. p->lineno = lineno;
  2134. p->col_offset = col_offset;
  2135. return p;
  2136. }
  2137. expr_ty
  2138. Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
  2139. *arena)
  2140. {
  2141. expr_ty p;
  2142. if (!ctx) {
  2143. PyErr_SetString(PyExc_ValueError,
  2144. "field ctx is required for Tuple");
  2145. return NULL;
  2146. }
  2147. p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
  2148. if (!p)
  2149. return NULL;
  2150. p->kind = Tuple_kind;
  2151. p->v.Tuple.elts = elts;
  2152. p->v.Tuple.ctx = ctx;
  2153. p->lineno = lineno;
  2154. p->col_offset = col_offset;
  2155. return p;
  2156. }
  2157. slice_ty
  2158. Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
  2159. {
  2160. slice_ty p;
  2161. p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
  2162. if (!p)
  2163. return NULL;
  2164. p->kind = Slice_kind;
  2165. p->v.Slice.lower = lower;
  2166. p->v.Slice.upper = upper;
  2167. p->v.Slice.step = step;
  2168. return p;
  2169. }
  2170. slice_ty
  2171. ExtSlice(asdl_seq * dims, PyArena *arena)
  2172. {
  2173. slice_ty p;
  2174. p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
  2175. if (!p)
  2176. return NULL;
  2177. p->kind = ExtSlice_kind;
  2178. p->v.ExtSlice.dims = dims;
  2179. return p;
  2180. }
  2181. slice_ty
  2182. Index(expr_ty value, PyArena *arena)
  2183. {
  2184. slice_ty p;
  2185. if (!value) {
  2186. PyErr_SetString(PyExc_ValueError,
  2187. "field value is required for Index");
  2188. return NULL;
  2189. }
  2190. p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
  2191. if (!p)
  2192. return NULL;
  2193. p->kind = Index_kind;
  2194. p->v.Index.value = value;
  2195. return p;
  2196. }
  2197. comprehension_ty
  2198. comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
  2199. PyArena *arena)
  2200. {
  2201. comprehension_ty p;
  2202. if (!target) {
  2203. PyErr_SetString(PyExc_ValueError,
  2204. "field target is required for comprehension");
  2205. return NULL;
  2206. }
  2207. if (!iter) {
  2208. PyErr_SetString(PyExc_ValueError,
  2209. "field iter is required for comprehension");
  2210. return NULL;
  2211. }
  2212. p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
  2213. if (!p)
  2214. return NULL;
  2215. p->target = target;
  2216. p->iter = iter;
  2217. p->ifs = ifs;
  2218. p->is_async = is_async;
  2219. return p;
  2220. }
  2221. excepthandler_ty
  2222. ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
  2223. col_offset, PyArena *arena)
  2224. {
  2225. excepthandler_ty p;
  2226. p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
  2227. if (!p)
  2228. return NULL;
  2229. p->kind = ExceptHandler_kind;
  2230. p->v.ExceptHandler.type = type;
  2231. p->v.ExceptHandler.name = name;
  2232. p->v.ExceptHandler.body = body;
  2233. p->lineno = lineno;
  2234. p->col_offset = col_offset;
  2235. return p;
  2236. }
  2237. arguments_ty
  2238. arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq *
  2239. kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena)
  2240. {
  2241. arguments_ty p;
  2242. p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
  2243. if (!p)
  2244. return NULL;
  2245. p->args = args;
  2246. p->vararg = vararg;
  2247. p->kwonlyargs = kwonlyargs;
  2248. p->kw_defaults = kw_defaults;
  2249. p->kwarg = kwarg;
  2250. p->defaults = defaults;
  2251. return p;
  2252. }
  2253. arg_ty
  2254. arg(identifier arg, expr_ty annotation, int lineno, int col_offset, PyArena
  2255. *arena)
  2256. {
  2257. arg_ty p;
  2258. if (!arg) {
  2259. PyErr_SetString(PyExc_ValueError,
  2260. "field arg is required for arg");
  2261. return NULL;
  2262. }
  2263. p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
  2264. if (!p)
  2265. return NULL;
  2266. p->arg = arg;
  2267. p->annotation = annotation;
  2268. p->lineno = lineno;
  2269. p->col_offset = col_offset;
  2270. return p;
  2271. }
  2272. keyword_ty
  2273. keyword(identifier arg, expr_ty value, PyArena *arena)
  2274. {
  2275. keyword_ty p;
  2276. if (!value) {
  2277. PyErr_SetString(PyExc_ValueError,
  2278. "field value is required for keyword");
  2279. return NULL;
  2280. }
  2281. p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
  2282. if (!p)
  2283. return NULL;
  2284. p->arg = arg;
  2285. p->value = value;
  2286. return p;
  2287. }
  2288. alias_ty
  2289. alias(identifier name, identifier asname, PyArena *arena)
  2290. {
  2291. alias_ty p;
  2292. if (!name) {
  2293. PyErr_SetString(PyExc_ValueError,
  2294. "field name is required for alias");
  2295. return NULL;
  2296. }
  2297. p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
  2298. if (!p)
  2299. return NULL;
  2300. p->name = name;
  2301. p->asname = asname;
  2302. return p;
  2303. }
  2304. withitem_ty
  2305. withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
  2306. {
  2307. withitem_ty p;
  2308. if (!context_expr) {
  2309. PyErr_SetString(PyExc_ValueError,
  2310. "field context_expr is required for withitem");
  2311. return NULL;
  2312. }
  2313. p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
  2314. if (!p)
  2315. return NULL;
  2316. p->context_expr = context_expr;
  2317. p->optional_vars = optional_vars;
  2318. return p;
  2319. }
  2320. PyObject*
  2321. ast2obj_mod(void* _o)
  2322. {
  2323. mod_ty o = (mod_ty)_o;
  2324. PyObject *result = NULL, *value = NULL;
  2325. if (!o) {
  2326. Py_RETURN_NONE;
  2327. }
  2328. switch (o->kind) {
  2329. case Module_kind:
  2330. result = PyType_GenericNew(Module_type, NULL, NULL);
  2331. if (!result) goto failed;
  2332. value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
  2333. if (!value) goto failed;
  2334. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2335. goto failed;
  2336. Py_DECREF(value);
  2337. break;
  2338. case Interactive_kind:
  2339. result = PyType_GenericNew(Interactive_type, NULL, NULL);
  2340. if (!result) goto failed;
  2341. value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
  2342. if (!value) goto failed;
  2343. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2344. goto failed;
  2345. Py_DECREF(value);
  2346. break;
  2347. case Expression_kind:
  2348. result = PyType_GenericNew(Expression_type, NULL, NULL);
  2349. if (!result) goto failed;
  2350. value = ast2obj_expr(o->v.Expression.body);
  2351. if (!value) goto failed;
  2352. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2353. goto failed;
  2354. Py_DECREF(value);
  2355. break;
  2356. case Suite_kind:
  2357. result = PyType_GenericNew(Suite_type, NULL, NULL);
  2358. if (!result) goto failed;
  2359. value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
  2360. if (!value) goto failed;
  2361. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2362. goto failed;
  2363. Py_DECREF(value);
  2364. break;
  2365. }
  2366. return result;
  2367. failed:
  2368. Py_XDECREF(value);
  2369. Py_XDECREF(result);
  2370. return NULL;
  2371. }
  2372. PyObject*
  2373. ast2obj_stmt(void* _o)
  2374. {
  2375. stmt_ty o = (stmt_ty)_o;
  2376. PyObject *result = NULL, *value = NULL;
  2377. if (!o) {
  2378. Py_RETURN_NONE;
  2379. }
  2380. switch (o->kind) {
  2381. case FunctionDef_kind:
  2382. result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
  2383. if (!result) goto failed;
  2384. value = ast2obj_identifier(o->v.FunctionDef.name);
  2385. if (!value) goto failed;
  2386. if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
  2387. goto failed;
  2388. Py_DECREF(value);
  2389. value = ast2obj_arguments(o->v.FunctionDef.args);
  2390. if (!value) goto failed;
  2391. if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
  2392. goto failed;
  2393. Py_DECREF(value);
  2394. value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
  2395. if (!value) goto failed;
  2396. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2397. goto failed;
  2398. Py_DECREF(value);
  2399. value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
  2400. if (!value) goto failed;
  2401. if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1)
  2402. goto failed;
  2403. Py_DECREF(value);
  2404. value = ast2obj_expr(o->v.FunctionDef.returns);
  2405. if (!value) goto failed;
  2406. if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1)
  2407. goto failed;
  2408. Py_DECREF(value);
  2409. break;
  2410. case AsyncFunctionDef_kind:
  2411. result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL);
  2412. if (!result) goto failed;
  2413. value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
  2414. if (!value) goto failed;
  2415. if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
  2416. goto failed;
  2417. Py_DECREF(value);
  2418. value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
  2419. if (!value) goto failed;
  2420. if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
  2421. goto failed;
  2422. Py_DECREF(value);
  2423. value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
  2424. if (!value) goto failed;
  2425. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2426. goto failed;
  2427. Py_DECREF(value);
  2428. value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
  2429. ast2obj_expr);
  2430. if (!value) goto failed;
  2431. if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1)
  2432. goto failed;
  2433. Py_DECREF(value);
  2434. value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
  2435. if (!value) goto failed;
  2436. if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1)
  2437. goto failed;
  2438. Py_DECREF(value);
  2439. break;
  2440. case ClassDef_kind:
  2441. result = PyType_GenericNew(ClassDef_type, NULL, NULL);
  2442. if (!result) goto failed;
  2443. value = ast2obj_identifier(o->v.ClassDef.name);
  2444. if (!value) goto failed;
  2445. if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
  2446. goto failed;
  2447. Py_DECREF(value);
  2448. value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
  2449. if (!value) goto failed;
  2450. if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1)
  2451. goto failed;
  2452. Py_DECREF(value);
  2453. value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
  2454. if (!value) goto failed;
  2455. if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1)
  2456. goto failed;
  2457. Py_DECREF(value);
  2458. value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
  2459. if (!value) goto failed;
  2460. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2461. goto failed;
  2462. Py_DECREF(value);
  2463. value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
  2464. if (!value) goto failed;
  2465. if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1)
  2466. goto failed;
  2467. Py_DECREF(value);
  2468. break;
  2469. case Return_kind:
  2470. result = PyType_GenericNew(Return_type, NULL, NULL);
  2471. if (!result) goto failed;
  2472. value = ast2obj_expr(o->v.Return.value);
  2473. if (!value) goto failed;
  2474. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  2475. goto failed;
  2476. Py_DECREF(value);
  2477. break;
  2478. case Delete_kind:
  2479. result = PyType_GenericNew(Delete_type, NULL, NULL);
  2480. if (!result) goto failed;
  2481. value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
  2482. if (!value) goto failed;
  2483. if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1)
  2484. goto failed;
  2485. Py_DECREF(value);
  2486. break;
  2487. case Assign_kind:
  2488. result = PyType_GenericNew(Assign_type, NULL, NULL);
  2489. if (!result) goto failed;
  2490. value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
  2491. if (!value) goto failed;
  2492. if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1)
  2493. goto failed;
  2494. Py_DECREF(value);
  2495. value = ast2obj_expr(o->v.Assign.value);
  2496. if (!value) goto failed;
  2497. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  2498. goto failed;
  2499. Py_DECREF(value);
  2500. break;
  2501. case AugAssign_kind:
  2502. result = PyType_GenericNew(AugAssign_type, NULL, NULL);
  2503. if (!result) goto failed;
  2504. value = ast2obj_expr(o->v.AugAssign.target);
  2505. if (!value) goto failed;
  2506. if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
  2507. goto failed;
  2508. Py_DECREF(value);
  2509. value = ast2obj_operator(o->v.AugAssign.op);
  2510. if (!value) goto failed;
  2511. if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
  2512. goto failed;
  2513. Py_DECREF(value);
  2514. value = ast2obj_expr(o->v.AugAssign.value);
  2515. if (!value) goto failed;
  2516. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  2517. goto failed;
  2518. Py_DECREF(value);
  2519. break;
  2520. case AnnAssign_kind:
  2521. result = PyType_GenericNew(AnnAssign_type, NULL, NULL);
  2522. if (!result) goto failed;
  2523. value = ast2obj_expr(o->v.AnnAssign.target);
  2524. if (!value) goto failed;
  2525. if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
  2526. goto failed;
  2527. Py_DECREF(value);
  2528. value = ast2obj_expr(o->v.AnnAssign.annotation);
  2529. if (!value) goto failed;
  2530. if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1)
  2531. goto failed;
  2532. Py_DECREF(value);
  2533. value = ast2obj_expr(o->v.AnnAssign.value);
  2534. if (!value) goto failed;
  2535. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  2536. goto failed;
  2537. Py_DECREF(value);
  2538. value = ast2obj_int(o->v.AnnAssign.simple);
  2539. if (!value) goto failed;
  2540. if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1)
  2541. goto failed;
  2542. Py_DECREF(value);
  2543. break;
  2544. case For_kind:
  2545. result = PyType_GenericNew(For_type, NULL, NULL);
  2546. if (!result) goto failed;
  2547. value = ast2obj_expr(o->v.For.target);
  2548. if (!value) goto failed;
  2549. if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
  2550. goto failed;
  2551. Py_DECREF(value);
  2552. value = ast2obj_expr(o->v.For.iter);
  2553. if (!value) goto failed;
  2554. if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
  2555. goto failed;
  2556. Py_DECREF(value);
  2557. value = ast2obj_list(o->v.For.body, ast2obj_stmt);
  2558. if (!value) goto failed;
  2559. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2560. goto failed;
  2561. Py_DECREF(value);
  2562. value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
  2563. if (!value) goto failed;
  2564. if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
  2565. goto failed;
  2566. Py_DECREF(value);
  2567. break;
  2568. case AsyncFor_kind:
  2569. result = PyType_GenericNew(AsyncFor_type, NULL, NULL);
  2570. if (!result) goto failed;
  2571. value = ast2obj_expr(o->v.AsyncFor.target);
  2572. if (!value) goto failed;
  2573. if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
  2574. goto failed;
  2575. Py_DECREF(value);
  2576. value = ast2obj_expr(o->v.AsyncFor.iter);
  2577. if (!value) goto failed;
  2578. if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
  2579. goto failed;
  2580. Py_DECREF(value);
  2581. value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
  2582. if (!value) goto failed;
  2583. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2584. goto failed;
  2585. Py_DECREF(value);
  2586. value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
  2587. if (!value) goto failed;
  2588. if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
  2589. goto failed;
  2590. Py_DECREF(value);
  2591. break;
  2592. case While_kind:
  2593. result = PyType_GenericNew(While_type, NULL, NULL);
  2594. if (!result) goto failed;
  2595. value = ast2obj_expr(o->v.While.test);
  2596. if (!value) goto failed;
  2597. if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
  2598. goto failed;
  2599. Py_DECREF(value);
  2600. value = ast2obj_list(o->v.While.body, ast2obj_stmt);
  2601. if (!value) goto failed;
  2602. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2603. goto failed;
  2604. Py_DECREF(value);
  2605. value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
  2606. if (!value) goto failed;
  2607. if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
  2608. goto failed;
  2609. Py_DECREF(value);
  2610. break;
  2611. case If_kind:
  2612. result = PyType_GenericNew(If_type, NULL, NULL);
  2613. if (!result) goto failed;
  2614. value = ast2obj_expr(o->v.If.test);
  2615. if (!value) goto failed;
  2616. if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
  2617. goto failed;
  2618. Py_DECREF(value);
  2619. value = ast2obj_list(o->v.If.body, ast2obj_stmt);
  2620. if (!value) goto failed;
  2621. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2622. goto failed;
  2623. Py_DECREF(value);
  2624. value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
  2625. if (!value) goto failed;
  2626. if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
  2627. goto failed;
  2628. Py_DECREF(value);
  2629. break;
  2630. case With_kind:
  2631. result = PyType_GenericNew(With_type, NULL, NULL);
  2632. if (!result) goto failed;
  2633. value = ast2obj_list(o->v.With.items, ast2obj_withitem);
  2634. if (!value) goto failed;
  2635. if (_PyObject_SetAttrId(result, &PyId_items, value) == -1)
  2636. goto failed;
  2637. Py_DECREF(value);
  2638. value = ast2obj_list(o->v.With.body, ast2obj_stmt);
  2639. if (!value) goto failed;
  2640. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2641. goto failed;
  2642. Py_DECREF(value);
  2643. break;
  2644. case AsyncWith_kind:
  2645. result = PyType_GenericNew(AsyncWith_type, NULL, NULL);
  2646. if (!result) goto failed;
  2647. value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
  2648. if (!value) goto failed;
  2649. if (_PyObject_SetAttrId(result, &PyId_items, value) == -1)
  2650. goto failed;
  2651. Py_DECREF(value);
  2652. value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
  2653. if (!value) goto failed;
  2654. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2655. goto failed;
  2656. Py_DECREF(value);
  2657. break;
  2658. case Raise_kind:
  2659. result = PyType_GenericNew(Raise_type, NULL, NULL);
  2660. if (!result) goto failed;
  2661. value = ast2obj_expr(o->v.Raise.exc);
  2662. if (!value) goto failed;
  2663. if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1)
  2664. goto failed;
  2665. Py_DECREF(value);
  2666. value = ast2obj_expr(o->v.Raise.cause);
  2667. if (!value) goto failed;
  2668. if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1)
  2669. goto failed;
  2670. Py_DECREF(value);
  2671. break;
  2672. case Try_kind:
  2673. result = PyType_GenericNew(Try_type, NULL, NULL);
  2674. if (!result) goto failed;
  2675. value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
  2676. if (!value) goto failed;
  2677. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2678. goto failed;
  2679. Py_DECREF(value);
  2680. value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
  2681. if (!value) goto failed;
  2682. if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1)
  2683. goto failed;
  2684. Py_DECREF(value);
  2685. value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
  2686. if (!value) goto failed;
  2687. if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
  2688. goto failed;
  2689. Py_DECREF(value);
  2690. value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
  2691. if (!value) goto failed;
  2692. if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1)
  2693. goto failed;
  2694. Py_DECREF(value);
  2695. break;
  2696. case Assert_kind:
  2697. result = PyType_GenericNew(Assert_type, NULL, NULL);
  2698. if (!result) goto failed;
  2699. value = ast2obj_expr(o->v.Assert.test);
  2700. if (!value) goto failed;
  2701. if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
  2702. goto failed;
  2703. Py_DECREF(value);
  2704. value = ast2obj_expr(o->v.Assert.msg);
  2705. if (!value) goto failed;
  2706. if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1)
  2707. goto failed;
  2708. Py_DECREF(value);
  2709. break;
  2710. case Import_kind:
  2711. result = PyType_GenericNew(Import_type, NULL, NULL);
  2712. if (!result) goto failed;
  2713. value = ast2obj_list(o->v.Import.names, ast2obj_alias);
  2714. if (!value) goto failed;
  2715. if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
  2716. goto failed;
  2717. Py_DECREF(value);
  2718. break;
  2719. case ImportFrom_kind:
  2720. result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
  2721. if (!result) goto failed;
  2722. value = ast2obj_identifier(o->v.ImportFrom.module);
  2723. if (!value) goto failed;
  2724. if (_PyObject_SetAttrId(result, &PyId_module, value) == -1)
  2725. goto failed;
  2726. Py_DECREF(value);
  2727. value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
  2728. if (!value) goto failed;
  2729. if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
  2730. goto failed;
  2731. Py_DECREF(value);
  2732. value = ast2obj_int(o->v.ImportFrom.level);
  2733. if (!value) goto failed;
  2734. if (_PyObject_SetAttrId(result, &PyId_level, value) == -1)
  2735. goto failed;
  2736. Py_DECREF(value);
  2737. break;
  2738. case Global_kind:
  2739. result = PyType_GenericNew(Global_type, NULL, NULL);
  2740. if (!result) goto failed;
  2741. value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
  2742. if (!value) goto failed;
  2743. if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
  2744. goto failed;
  2745. Py_DECREF(value);
  2746. break;
  2747. case Nonlocal_kind:
  2748. result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
  2749. if (!result) goto failed;
  2750. value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
  2751. if (!value) goto failed;
  2752. if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
  2753. goto failed;
  2754. Py_DECREF(value);
  2755. break;
  2756. case Expr_kind:
  2757. result = PyType_GenericNew(Expr_type, NULL, NULL);
  2758. if (!result) goto failed;
  2759. value = ast2obj_expr(o->v.Expr.value);
  2760. if (!value) goto failed;
  2761. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  2762. goto failed;
  2763. Py_DECREF(value);
  2764. break;
  2765. case Pass_kind:
  2766. result = PyType_GenericNew(Pass_type, NULL, NULL);
  2767. if (!result) goto failed;
  2768. break;
  2769. case Break_kind:
  2770. result = PyType_GenericNew(Break_type, NULL, NULL);
  2771. if (!result) goto failed;
  2772. break;
  2773. case Continue_kind:
  2774. result = PyType_GenericNew(Continue_type, NULL, NULL);
  2775. if (!result) goto failed;
  2776. break;
  2777. }
  2778. value = ast2obj_int(o->lineno);
  2779. if (!value) goto failed;
  2780. if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
  2781. goto failed;
  2782. Py_DECREF(value);
  2783. value = ast2obj_int(o->col_offset);
  2784. if (!value) goto failed;
  2785. if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
  2786. goto failed;
  2787. Py_DECREF(value);
  2788. return result;
  2789. failed:
  2790. Py_XDECREF(value);
  2791. Py_XDECREF(result);
  2792. return NULL;
  2793. }
  2794. PyObject*
  2795. ast2obj_expr(void* _o)
  2796. {
  2797. expr_ty o = (expr_ty)_o;
  2798. PyObject *result = NULL, *value = NULL;
  2799. if (!o) {
  2800. Py_RETURN_NONE;
  2801. }
  2802. switch (o->kind) {
  2803. case BoolOp_kind:
  2804. result = PyType_GenericNew(BoolOp_type, NULL, NULL);
  2805. if (!result) goto failed;
  2806. value = ast2obj_boolop(o->v.BoolOp.op);
  2807. if (!value) goto failed;
  2808. if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
  2809. goto failed;
  2810. Py_DECREF(value);
  2811. value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
  2812. if (!value) goto failed;
  2813. if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
  2814. goto failed;
  2815. Py_DECREF(value);
  2816. break;
  2817. case BinOp_kind:
  2818. result = PyType_GenericNew(BinOp_type, NULL, NULL);
  2819. if (!result) goto failed;
  2820. value = ast2obj_expr(o->v.BinOp.left);
  2821. if (!value) goto failed;
  2822. if (_PyObject_SetAttrId(result, &PyId_left, value) == -1)
  2823. goto failed;
  2824. Py_DECREF(value);
  2825. value = ast2obj_operator(o->v.BinOp.op);
  2826. if (!value) goto failed;
  2827. if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
  2828. goto failed;
  2829. Py_DECREF(value);
  2830. value = ast2obj_expr(o->v.BinOp.right);
  2831. if (!value) goto failed;
  2832. if (_PyObject_SetAttrId(result, &PyId_right, value) == -1)
  2833. goto failed;
  2834. Py_DECREF(value);
  2835. break;
  2836. case UnaryOp_kind:
  2837. result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
  2838. if (!result) goto failed;
  2839. value = ast2obj_unaryop(o->v.UnaryOp.op);
  2840. if (!value) goto failed;
  2841. if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
  2842. goto failed;
  2843. Py_DECREF(value);
  2844. value = ast2obj_expr(o->v.UnaryOp.operand);
  2845. if (!value) goto failed;
  2846. if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1)
  2847. goto failed;
  2848. Py_DECREF(value);
  2849. break;
  2850. case Lambda_kind:
  2851. result = PyType_GenericNew(Lambda_type, NULL, NULL);
  2852. if (!result) goto failed;
  2853. value = ast2obj_arguments(o->v.Lambda.args);
  2854. if (!value) goto failed;
  2855. if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
  2856. goto failed;
  2857. Py_DECREF(value);
  2858. value = ast2obj_expr(o->v.Lambda.body);
  2859. if (!value) goto failed;
  2860. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2861. goto failed;
  2862. Py_DECREF(value);
  2863. break;
  2864. case IfExp_kind:
  2865. result = PyType_GenericNew(IfExp_type, NULL, NULL);
  2866. if (!result) goto failed;
  2867. value = ast2obj_expr(o->v.IfExp.test);
  2868. if (!value) goto failed;
  2869. if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
  2870. goto failed;
  2871. Py_DECREF(value);
  2872. value = ast2obj_expr(o->v.IfExp.body);
  2873. if (!value) goto failed;
  2874. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  2875. goto failed;
  2876. Py_DECREF(value);
  2877. value = ast2obj_expr(o->v.IfExp.orelse);
  2878. if (!value) goto failed;
  2879. if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
  2880. goto failed;
  2881. Py_DECREF(value);
  2882. break;
  2883. case Dict_kind:
  2884. result = PyType_GenericNew(Dict_type, NULL, NULL);
  2885. if (!result) goto failed;
  2886. value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
  2887. if (!value) goto failed;
  2888. if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1)
  2889. goto failed;
  2890. Py_DECREF(value);
  2891. value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
  2892. if (!value) goto failed;
  2893. if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
  2894. goto failed;
  2895. Py_DECREF(value);
  2896. break;
  2897. case Set_kind:
  2898. result = PyType_GenericNew(Set_type, NULL, NULL);
  2899. if (!result) goto failed;
  2900. value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
  2901. if (!value) goto failed;
  2902. if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
  2903. goto failed;
  2904. Py_DECREF(value);
  2905. break;
  2906. case ListComp_kind:
  2907. result = PyType_GenericNew(ListComp_type, NULL, NULL);
  2908. if (!result) goto failed;
  2909. value = ast2obj_expr(o->v.ListComp.elt);
  2910. if (!value) goto failed;
  2911. if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
  2912. goto failed;
  2913. Py_DECREF(value);
  2914. value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
  2915. if (!value) goto failed;
  2916. if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
  2917. goto failed;
  2918. Py_DECREF(value);
  2919. break;
  2920. case SetComp_kind:
  2921. result = PyType_GenericNew(SetComp_type, NULL, NULL);
  2922. if (!result) goto failed;
  2923. value = ast2obj_expr(o->v.SetComp.elt);
  2924. if (!value) goto failed;
  2925. if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
  2926. goto failed;
  2927. Py_DECREF(value);
  2928. value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
  2929. if (!value) goto failed;
  2930. if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
  2931. goto failed;
  2932. Py_DECREF(value);
  2933. break;
  2934. case DictComp_kind:
  2935. result = PyType_GenericNew(DictComp_type, NULL, NULL);
  2936. if (!result) goto failed;
  2937. value = ast2obj_expr(o->v.DictComp.key);
  2938. if (!value) goto failed;
  2939. if (_PyObject_SetAttrId(result, &PyId_key, value) == -1)
  2940. goto failed;
  2941. Py_DECREF(value);
  2942. value = ast2obj_expr(o->v.DictComp.value);
  2943. if (!value) goto failed;
  2944. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  2945. goto failed;
  2946. Py_DECREF(value);
  2947. value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
  2948. if (!value) goto failed;
  2949. if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
  2950. goto failed;
  2951. Py_DECREF(value);
  2952. break;
  2953. case GeneratorExp_kind:
  2954. result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
  2955. if (!result) goto failed;
  2956. value = ast2obj_expr(o->v.GeneratorExp.elt);
  2957. if (!value) goto failed;
  2958. if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
  2959. goto failed;
  2960. Py_DECREF(value);
  2961. value = ast2obj_list(o->v.GeneratorExp.generators,
  2962. ast2obj_comprehension);
  2963. if (!value) goto failed;
  2964. if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
  2965. goto failed;
  2966. Py_DECREF(value);
  2967. break;
  2968. case Await_kind:
  2969. result = PyType_GenericNew(Await_type, NULL, NULL);
  2970. if (!result) goto failed;
  2971. value = ast2obj_expr(o->v.Await.value);
  2972. if (!value) goto failed;
  2973. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  2974. goto failed;
  2975. Py_DECREF(value);
  2976. break;
  2977. case Yield_kind:
  2978. result = PyType_GenericNew(Yield_type, NULL, NULL);
  2979. if (!result) goto failed;
  2980. value = ast2obj_expr(o->v.Yield.value);
  2981. if (!value) goto failed;
  2982. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  2983. goto failed;
  2984. Py_DECREF(value);
  2985. break;
  2986. case YieldFrom_kind:
  2987. result = PyType_GenericNew(YieldFrom_type, NULL, NULL);
  2988. if (!result) goto failed;
  2989. value = ast2obj_expr(o->v.YieldFrom.value);
  2990. if (!value) goto failed;
  2991. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  2992. goto failed;
  2993. Py_DECREF(value);
  2994. break;
  2995. case Compare_kind:
  2996. result = PyType_GenericNew(Compare_type, NULL, NULL);
  2997. if (!result) goto failed;
  2998. value = ast2obj_expr(o->v.Compare.left);
  2999. if (!value) goto failed;
  3000. if (_PyObject_SetAttrId(result, &PyId_left, value) == -1)
  3001. goto failed;
  3002. Py_DECREF(value);
  3003. {
  3004. Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
  3005. value = PyList_New(n);
  3006. if (!value) goto failed;
  3007. for(i = 0; i < n; i++)
  3008. PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
  3009. }
  3010. if (!value) goto failed;
  3011. if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1)
  3012. goto failed;
  3013. Py_DECREF(value);
  3014. value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
  3015. if (!value) goto failed;
  3016. if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1)
  3017. goto failed;
  3018. Py_DECREF(value);
  3019. break;
  3020. case Call_kind:
  3021. result = PyType_GenericNew(Call_type, NULL, NULL);
  3022. if (!result) goto failed;
  3023. value = ast2obj_expr(o->v.Call.func);
  3024. if (!value) goto failed;
  3025. if (_PyObject_SetAttrId(result, &PyId_func, value) == -1)
  3026. goto failed;
  3027. Py_DECREF(value);
  3028. value = ast2obj_list(o->v.Call.args, ast2obj_expr);
  3029. if (!value) goto failed;
  3030. if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
  3031. goto failed;
  3032. Py_DECREF(value);
  3033. value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
  3034. if (!value) goto failed;
  3035. if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1)
  3036. goto failed;
  3037. Py_DECREF(value);
  3038. break;
  3039. case FormattedValue_kind:
  3040. result = PyType_GenericNew(FormattedValue_type, NULL, NULL);
  3041. if (!result) goto failed;
  3042. value = ast2obj_expr(o->v.FormattedValue.value);
  3043. if (!value) goto failed;
  3044. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  3045. goto failed;
  3046. Py_DECREF(value);
  3047. value = ast2obj_int(o->v.FormattedValue.conversion);
  3048. if (!value) goto failed;
  3049. if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1)
  3050. goto failed;
  3051. Py_DECREF(value);
  3052. value = ast2obj_expr(o->v.FormattedValue.format_spec);
  3053. if (!value) goto failed;
  3054. if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1)
  3055. goto failed;
  3056. Py_DECREF(value);
  3057. break;
  3058. case JoinedStr_kind:
  3059. result = PyType_GenericNew(JoinedStr_type, NULL, NULL);
  3060. if (!result) goto failed;
  3061. value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
  3062. if (!value) goto failed;
  3063. if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
  3064. goto failed;
  3065. Py_DECREF(value);
  3066. break;
  3067. case Constant_kind:
  3068. result = PyType_GenericNew(Constant_type, NULL, NULL);
  3069. if (!result) goto failed;
  3070. value = ast2obj_constant(o->v.Constant.value);
  3071. if (!value) goto failed;
  3072. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  3073. goto failed;
  3074. Py_DECREF(value);
  3075. break;
  3076. case Attribute_kind:
  3077. result = PyType_GenericNew(Attribute_type, NULL, NULL);
  3078. if (!result) goto failed;
  3079. value = ast2obj_expr(o->v.Attribute.value);
  3080. if (!value) goto failed;
  3081. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  3082. goto failed;
  3083. Py_DECREF(value);
  3084. value = ast2obj_identifier(o->v.Attribute.attr);
  3085. if (!value) goto failed;
  3086. if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1)
  3087. goto failed;
  3088. Py_DECREF(value);
  3089. value = ast2obj_expr_context(o->v.Attribute.ctx);
  3090. if (!value) goto failed;
  3091. if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
  3092. goto failed;
  3093. Py_DECREF(value);
  3094. break;
  3095. case Subscript_kind:
  3096. result = PyType_GenericNew(Subscript_type, NULL, NULL);
  3097. if (!result) goto failed;
  3098. value = ast2obj_expr(o->v.Subscript.value);
  3099. if (!value) goto failed;
  3100. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  3101. goto failed;
  3102. Py_DECREF(value);
  3103. value = ast2obj_slice(o->v.Subscript.slice);
  3104. if (!value) goto failed;
  3105. if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1)
  3106. goto failed;
  3107. Py_DECREF(value);
  3108. value = ast2obj_expr_context(o->v.Subscript.ctx);
  3109. if (!value) goto failed;
  3110. if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
  3111. goto failed;
  3112. Py_DECREF(value);
  3113. break;
  3114. case Starred_kind:
  3115. result = PyType_GenericNew(Starred_type, NULL, NULL);
  3116. if (!result) goto failed;
  3117. value = ast2obj_expr(o->v.Starred.value);
  3118. if (!value) goto failed;
  3119. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  3120. goto failed;
  3121. Py_DECREF(value);
  3122. value = ast2obj_expr_context(o->v.Starred.ctx);
  3123. if (!value) goto failed;
  3124. if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
  3125. goto failed;
  3126. Py_DECREF(value);
  3127. break;
  3128. case Name_kind:
  3129. result = PyType_GenericNew(Name_type, NULL, NULL);
  3130. if (!result) goto failed;
  3131. value = ast2obj_identifier(o->v.Name.id);
  3132. if (!value) goto failed;
  3133. if (_PyObject_SetAttrId(result, &PyId_id, value) == -1)
  3134. goto failed;
  3135. Py_DECREF(value);
  3136. value = ast2obj_expr_context(o->v.Name.ctx);
  3137. if (!value) goto failed;
  3138. if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
  3139. goto failed;
  3140. Py_DECREF(value);
  3141. break;
  3142. case List_kind:
  3143. result = PyType_GenericNew(List_type, NULL, NULL);
  3144. if (!result) goto failed;
  3145. value = ast2obj_list(o->v.List.elts, ast2obj_expr);
  3146. if (!value) goto failed;
  3147. if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
  3148. goto failed;
  3149. Py_DECREF(value);
  3150. value = ast2obj_expr_context(o->v.List.ctx);
  3151. if (!value) goto failed;
  3152. if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
  3153. goto failed;
  3154. Py_DECREF(value);
  3155. break;
  3156. case Tuple_kind:
  3157. result = PyType_GenericNew(Tuple_type, NULL, NULL);
  3158. if (!result) goto failed;
  3159. value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
  3160. if (!value) goto failed;
  3161. if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
  3162. goto failed;
  3163. Py_DECREF(value);
  3164. value = ast2obj_expr_context(o->v.Tuple.ctx);
  3165. if (!value) goto failed;
  3166. if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
  3167. goto failed;
  3168. Py_DECREF(value);
  3169. break;
  3170. }
  3171. value = ast2obj_int(o->lineno);
  3172. if (!value) goto failed;
  3173. if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
  3174. goto failed;
  3175. Py_DECREF(value);
  3176. value = ast2obj_int(o->col_offset);
  3177. if (!value) goto failed;
  3178. if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
  3179. goto failed;
  3180. Py_DECREF(value);
  3181. return result;
  3182. failed:
  3183. Py_XDECREF(value);
  3184. Py_XDECREF(result);
  3185. return NULL;
  3186. }
  3187. PyObject* ast2obj_expr_context(expr_context_ty o)
  3188. {
  3189. switch(o) {
  3190. case Load:
  3191. Py_INCREF(Load_singleton);
  3192. return Load_singleton;
  3193. case Store:
  3194. Py_INCREF(Store_singleton);
  3195. return Store_singleton;
  3196. case Del:
  3197. Py_INCREF(Del_singleton);
  3198. return Del_singleton;
  3199. case AugLoad:
  3200. Py_INCREF(AugLoad_singleton);
  3201. return AugLoad_singleton;
  3202. case AugStore:
  3203. Py_INCREF(AugStore_singleton);
  3204. return AugStore_singleton;
  3205. case Param:
  3206. Py_INCREF(Param_singleton);
  3207. return Param_singleton;
  3208. default:
  3209. /* should never happen, but just in case ... */
  3210. PyErr_Format(PyExc_SystemError, "unknown expr_context found");
  3211. return NULL;
  3212. }
  3213. }
  3214. PyObject*
  3215. ast2obj_slice(void* _o)
  3216. {
  3217. slice_ty o = (slice_ty)_o;
  3218. PyObject *result = NULL, *value = NULL;
  3219. if (!o) {
  3220. Py_RETURN_NONE;
  3221. }
  3222. switch (o->kind) {
  3223. case Slice_kind:
  3224. result = PyType_GenericNew(Slice_type, NULL, NULL);
  3225. if (!result) goto failed;
  3226. value = ast2obj_expr(o->v.Slice.lower);
  3227. if (!value) goto failed;
  3228. if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1)
  3229. goto failed;
  3230. Py_DECREF(value);
  3231. value = ast2obj_expr(o->v.Slice.upper);
  3232. if (!value) goto failed;
  3233. if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1)
  3234. goto failed;
  3235. Py_DECREF(value);
  3236. value = ast2obj_expr(o->v.Slice.step);
  3237. if (!value) goto failed;
  3238. if (_PyObject_SetAttrId(result, &PyId_step, value) == -1)
  3239. goto failed;
  3240. Py_DECREF(value);
  3241. break;
  3242. case ExtSlice_kind:
  3243. result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
  3244. if (!result) goto failed;
  3245. value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
  3246. if (!value) goto failed;
  3247. if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1)
  3248. goto failed;
  3249. Py_DECREF(value);
  3250. break;
  3251. case Index_kind:
  3252. result = PyType_GenericNew(Index_type, NULL, NULL);
  3253. if (!result) goto failed;
  3254. value = ast2obj_expr(o->v.Index.value);
  3255. if (!value) goto failed;
  3256. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  3257. goto failed;
  3258. Py_DECREF(value);
  3259. break;
  3260. }
  3261. return result;
  3262. failed:
  3263. Py_XDECREF(value);
  3264. Py_XDECREF(result);
  3265. return NULL;
  3266. }
  3267. PyObject* ast2obj_boolop(boolop_ty o)
  3268. {
  3269. switch(o) {
  3270. case And:
  3271. Py_INCREF(And_singleton);
  3272. return And_singleton;
  3273. case Or:
  3274. Py_INCREF(Or_singleton);
  3275. return Or_singleton;
  3276. default:
  3277. /* should never happen, but just in case ... */
  3278. PyErr_Format(PyExc_SystemError, "unknown boolop found");
  3279. return NULL;
  3280. }
  3281. }
  3282. PyObject* ast2obj_operator(operator_ty o)
  3283. {
  3284. switch(o) {
  3285. case Add:
  3286. Py_INCREF(Add_singleton);
  3287. return Add_singleton;
  3288. case Sub:
  3289. Py_INCREF(Sub_singleton);
  3290. return Sub_singleton;
  3291. case Mult:
  3292. Py_INCREF(Mult_singleton);
  3293. return Mult_singleton;
  3294. case MatMult:
  3295. Py_INCREF(MatMult_singleton);
  3296. return MatMult_singleton;
  3297. case Div:
  3298. Py_INCREF(Div_singleton);
  3299. return Div_singleton;
  3300. case Mod:
  3301. Py_INCREF(Mod_singleton);
  3302. return Mod_singleton;
  3303. case Pow:
  3304. Py_INCREF(Pow_singleton);
  3305. return Pow_singleton;
  3306. case LShift:
  3307. Py_INCREF(LShift_singleton);
  3308. return LShift_singleton;
  3309. case RShift:
  3310. Py_INCREF(RShift_singleton);
  3311. return RShift_singleton;
  3312. case BitOr:
  3313. Py_INCREF(BitOr_singleton);
  3314. return BitOr_singleton;
  3315. case BitXor:
  3316. Py_INCREF(BitXor_singleton);
  3317. return BitXor_singleton;
  3318. case BitAnd:
  3319. Py_INCREF(BitAnd_singleton);
  3320. return BitAnd_singleton;
  3321. case FloorDiv:
  3322. Py_INCREF(FloorDiv_singleton);
  3323. return FloorDiv_singleton;
  3324. default:
  3325. /* should never happen, but just in case ... */
  3326. PyErr_Format(PyExc_SystemError, "unknown operator found");
  3327. return NULL;
  3328. }
  3329. }
  3330. PyObject* ast2obj_unaryop(unaryop_ty o)
  3331. {
  3332. switch(o) {
  3333. case Invert:
  3334. Py_INCREF(Invert_singleton);
  3335. return Invert_singleton;
  3336. case Not:
  3337. Py_INCREF(Not_singleton);
  3338. return Not_singleton;
  3339. case UAdd:
  3340. Py_INCREF(UAdd_singleton);
  3341. return UAdd_singleton;
  3342. case USub:
  3343. Py_INCREF(USub_singleton);
  3344. return USub_singleton;
  3345. default:
  3346. /* should never happen, but just in case ... */
  3347. PyErr_Format(PyExc_SystemError, "unknown unaryop found");
  3348. return NULL;
  3349. }
  3350. }
  3351. PyObject* ast2obj_cmpop(cmpop_ty o)
  3352. {
  3353. switch(o) {
  3354. case Eq:
  3355. Py_INCREF(Eq_singleton);
  3356. return Eq_singleton;
  3357. case NotEq:
  3358. Py_INCREF(NotEq_singleton);
  3359. return NotEq_singleton;
  3360. case Lt:
  3361. Py_INCREF(Lt_singleton);
  3362. return Lt_singleton;
  3363. case LtE:
  3364. Py_INCREF(LtE_singleton);
  3365. return LtE_singleton;
  3366. case Gt:
  3367. Py_INCREF(Gt_singleton);
  3368. return Gt_singleton;
  3369. case GtE:
  3370. Py_INCREF(GtE_singleton);
  3371. return GtE_singleton;
  3372. case Is:
  3373. Py_INCREF(Is_singleton);
  3374. return Is_singleton;
  3375. case IsNot:
  3376. Py_INCREF(IsNot_singleton);
  3377. return IsNot_singleton;
  3378. case In:
  3379. Py_INCREF(In_singleton);
  3380. return In_singleton;
  3381. case NotIn:
  3382. Py_INCREF(NotIn_singleton);
  3383. return NotIn_singleton;
  3384. default:
  3385. /* should never happen, but just in case ... */
  3386. PyErr_Format(PyExc_SystemError, "unknown cmpop found");
  3387. return NULL;
  3388. }
  3389. }
  3390. PyObject*
  3391. ast2obj_comprehension(void* _o)
  3392. {
  3393. comprehension_ty o = (comprehension_ty)_o;
  3394. PyObject *result = NULL, *value = NULL;
  3395. if (!o) {
  3396. Py_RETURN_NONE;
  3397. }
  3398. result = PyType_GenericNew(comprehension_type, NULL, NULL);
  3399. if (!result) return NULL;
  3400. value = ast2obj_expr(o->target);
  3401. if (!value) goto failed;
  3402. if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
  3403. goto failed;
  3404. Py_DECREF(value);
  3405. value = ast2obj_expr(o->iter);
  3406. if (!value) goto failed;
  3407. if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
  3408. goto failed;
  3409. Py_DECREF(value);
  3410. value = ast2obj_list(o->ifs, ast2obj_expr);
  3411. if (!value) goto failed;
  3412. if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1)
  3413. goto failed;
  3414. Py_DECREF(value);
  3415. value = ast2obj_int(o->is_async);
  3416. if (!value) goto failed;
  3417. if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1)
  3418. goto failed;
  3419. Py_DECREF(value);
  3420. return result;
  3421. failed:
  3422. Py_XDECREF(value);
  3423. Py_XDECREF(result);
  3424. return NULL;
  3425. }
  3426. PyObject*
  3427. ast2obj_excepthandler(void* _o)
  3428. {
  3429. excepthandler_ty o = (excepthandler_ty)_o;
  3430. PyObject *result = NULL, *value = NULL;
  3431. if (!o) {
  3432. Py_RETURN_NONE;
  3433. }
  3434. switch (o->kind) {
  3435. case ExceptHandler_kind:
  3436. result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);
  3437. if (!result) goto failed;
  3438. value = ast2obj_expr(o->v.ExceptHandler.type);
  3439. if (!value) goto failed;
  3440. if (_PyObject_SetAttrId(result, &PyId_type, value) == -1)
  3441. goto failed;
  3442. Py_DECREF(value);
  3443. value = ast2obj_identifier(o->v.ExceptHandler.name);
  3444. if (!value) goto failed;
  3445. if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
  3446. goto failed;
  3447. Py_DECREF(value);
  3448. value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
  3449. if (!value) goto failed;
  3450. if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
  3451. goto failed;
  3452. Py_DECREF(value);
  3453. break;
  3454. }
  3455. value = ast2obj_int(o->lineno);
  3456. if (!value) goto failed;
  3457. if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
  3458. goto failed;
  3459. Py_DECREF(value);
  3460. value = ast2obj_int(o->col_offset);
  3461. if (!value) goto failed;
  3462. if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
  3463. goto failed;
  3464. Py_DECREF(value);
  3465. return result;
  3466. failed:
  3467. Py_XDECREF(value);
  3468. Py_XDECREF(result);
  3469. return NULL;
  3470. }
  3471. PyObject*
  3472. ast2obj_arguments(void* _o)
  3473. {
  3474. arguments_ty o = (arguments_ty)_o;
  3475. PyObject *result = NULL, *value = NULL;
  3476. if (!o) {
  3477. Py_RETURN_NONE;
  3478. }
  3479. result = PyType_GenericNew(arguments_type, NULL, NULL);
  3480. if (!result) return NULL;
  3481. value = ast2obj_list(o->args, ast2obj_arg);
  3482. if (!value) goto failed;
  3483. if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
  3484. goto failed;
  3485. Py_DECREF(value);
  3486. value = ast2obj_arg(o->vararg);
  3487. if (!value) goto failed;
  3488. if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1)
  3489. goto failed;
  3490. Py_DECREF(value);
  3491. value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
  3492. if (!value) goto failed;
  3493. if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1)
  3494. goto failed;
  3495. Py_DECREF(value);
  3496. value = ast2obj_list(o->kw_defaults, ast2obj_expr);
  3497. if (!value) goto failed;
  3498. if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1)
  3499. goto failed;
  3500. Py_DECREF(value);
  3501. value = ast2obj_arg(o->kwarg);
  3502. if (!value) goto failed;
  3503. if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1)
  3504. goto failed;
  3505. Py_DECREF(value);
  3506. value = ast2obj_list(o->defaults, ast2obj_expr);
  3507. if (!value) goto failed;
  3508. if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1)
  3509. goto failed;
  3510. Py_DECREF(value);
  3511. return result;
  3512. failed:
  3513. Py_XDECREF(value);
  3514. Py_XDECREF(result);
  3515. return NULL;
  3516. }
  3517. PyObject*
  3518. ast2obj_arg(void* _o)
  3519. {
  3520. arg_ty o = (arg_ty)_o;
  3521. PyObject *result = NULL, *value = NULL;
  3522. if (!o) {
  3523. Py_RETURN_NONE;
  3524. }
  3525. result = PyType_GenericNew(arg_type, NULL, NULL);
  3526. if (!result) return NULL;
  3527. value = ast2obj_identifier(o->arg);
  3528. if (!value) goto failed;
  3529. if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1)
  3530. goto failed;
  3531. Py_DECREF(value);
  3532. value = ast2obj_expr(o->annotation);
  3533. if (!value) goto failed;
  3534. if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1)
  3535. goto failed;
  3536. Py_DECREF(value);
  3537. value = ast2obj_int(o->lineno);
  3538. if (!value) goto failed;
  3539. if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
  3540. goto failed;
  3541. Py_DECREF(value);
  3542. value = ast2obj_int(o->col_offset);
  3543. if (!value) goto failed;
  3544. if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
  3545. goto failed;
  3546. Py_DECREF(value);
  3547. return result;
  3548. failed:
  3549. Py_XDECREF(value);
  3550. Py_XDECREF(result);
  3551. return NULL;
  3552. }
  3553. PyObject*
  3554. ast2obj_keyword(void* _o)
  3555. {
  3556. keyword_ty o = (keyword_ty)_o;
  3557. PyObject *result = NULL, *value = NULL;
  3558. if (!o) {
  3559. Py_RETURN_NONE;
  3560. }
  3561. result = PyType_GenericNew(keyword_type, NULL, NULL);
  3562. if (!result) return NULL;
  3563. value = ast2obj_identifier(o->arg);
  3564. if (!value) goto failed;
  3565. if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1)
  3566. goto failed;
  3567. Py_DECREF(value);
  3568. value = ast2obj_expr(o->value);
  3569. if (!value) goto failed;
  3570. if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
  3571. goto failed;
  3572. Py_DECREF(value);
  3573. return result;
  3574. failed:
  3575. Py_XDECREF(value);
  3576. Py_XDECREF(result);
  3577. return NULL;
  3578. }
  3579. PyObject*
  3580. ast2obj_alias(void* _o)
  3581. {
  3582. alias_ty o = (alias_ty)_o;
  3583. PyObject *result = NULL, *value = NULL;
  3584. if (!o) {
  3585. Py_RETURN_NONE;
  3586. }
  3587. result = PyType_GenericNew(alias_type, NULL, NULL);
  3588. if (!result) return NULL;
  3589. value = ast2obj_identifier(o->name);
  3590. if (!value) goto failed;
  3591. if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
  3592. goto failed;
  3593. Py_DECREF(value);
  3594. value = ast2obj_identifier(o->asname);
  3595. if (!value) goto failed;
  3596. if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1)
  3597. goto failed;
  3598. Py_DECREF(value);
  3599. return result;
  3600. failed:
  3601. Py_XDECREF(value);
  3602. Py_XDECREF(result);
  3603. return NULL;
  3604. }
  3605. PyObject*
  3606. ast2obj_withitem(void* _o)
  3607. {
  3608. withitem_ty o = (withitem_ty)_o;
  3609. PyObject *result = NULL, *value = NULL;
  3610. if (!o) {
  3611. Py_RETURN_NONE;
  3612. }
  3613. result = PyType_GenericNew(withitem_type, NULL, NULL);
  3614. if (!result) return NULL;
  3615. value = ast2obj_expr(o->context_expr);
  3616. if (!value) goto failed;
  3617. if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1)
  3618. goto failed;
  3619. Py_DECREF(value);
  3620. value = ast2obj_expr(o->optional_vars);
  3621. if (!value) goto failed;
  3622. if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1)
  3623. goto failed;
  3624. Py_DECREF(value);
  3625. return result;
  3626. failed:
  3627. Py_XDECREF(value);
  3628. Py_XDECREF(result);
  3629. return NULL;
  3630. }
  3631. int
  3632. obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
  3633. {
  3634. int isinstance;
  3635. PyObject *tmp = NULL;
  3636. if (obj == Py_None) {
  3637. *out = NULL;
  3638. return 0;
  3639. }
  3640. isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);
  3641. if (isinstance == -1) {
  3642. return 1;
  3643. }
  3644. if (isinstance) {
  3645. asdl_seq* body;
  3646. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  3647. return 1;
  3648. }
  3649. if (tmp == NULL) {
  3650. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
  3651. return 1;
  3652. }
  3653. else {
  3654. int res;
  3655. Py_ssize_t len;
  3656. Py_ssize_t i;
  3657. if (!PyList_Check(tmp)) {
  3658. PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  3659. goto failed;
  3660. }
  3661. len = PyList_GET_SIZE(tmp);
  3662. body = _Py_asdl_seq_new(len, arena);
  3663. if (body == NULL) goto failed;
  3664. for (i = 0; i < len; i++) {
  3665. stmt_ty val;
  3666. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  3667. if (res != 0) goto failed;
  3668. if (len != PyList_GET_SIZE(tmp)) {
  3669. PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
  3670. goto failed;
  3671. }
  3672. asdl_seq_SET(body, i, val);
  3673. }
  3674. Py_CLEAR(tmp);
  3675. }
  3676. *out = Module(body, arena);
  3677. if (*out == NULL) goto failed;
  3678. return 0;
  3679. }
  3680. isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);
  3681. if (isinstance == -1) {
  3682. return 1;
  3683. }
  3684. if (isinstance) {
  3685. asdl_seq* body;
  3686. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  3687. return 1;
  3688. }
  3689. if (tmp == NULL) {
  3690. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
  3691. return 1;
  3692. }
  3693. else {
  3694. int res;
  3695. Py_ssize_t len;
  3696. Py_ssize_t i;
  3697. if (!PyList_Check(tmp)) {
  3698. PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  3699. goto failed;
  3700. }
  3701. len = PyList_GET_SIZE(tmp);
  3702. body = _Py_asdl_seq_new(len, arena);
  3703. if (body == NULL) goto failed;
  3704. for (i = 0; i < len; i++) {
  3705. stmt_ty val;
  3706. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  3707. if (res != 0) goto failed;
  3708. if (len != PyList_GET_SIZE(tmp)) {
  3709. PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
  3710. goto failed;
  3711. }
  3712. asdl_seq_SET(body, i, val);
  3713. }
  3714. Py_CLEAR(tmp);
  3715. }
  3716. *out = Interactive(body, arena);
  3717. if (*out == NULL) goto failed;
  3718. return 0;
  3719. }
  3720. isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);
  3721. if (isinstance == -1) {
  3722. return 1;
  3723. }
  3724. if (isinstance) {
  3725. expr_ty body;
  3726. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  3727. return 1;
  3728. }
  3729. if (tmp == NULL) {
  3730. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
  3731. return 1;
  3732. }
  3733. else {
  3734. int res;
  3735. res = obj2ast_expr(tmp, &body, arena);
  3736. if (res != 0) goto failed;
  3737. Py_CLEAR(tmp);
  3738. }
  3739. *out = Expression(body, arena);
  3740. if (*out == NULL) goto failed;
  3741. return 0;
  3742. }
  3743. isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);
  3744. if (isinstance == -1) {
  3745. return 1;
  3746. }
  3747. if (isinstance) {
  3748. asdl_seq* body;
  3749. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  3750. return 1;
  3751. }
  3752. if (tmp == NULL) {
  3753. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
  3754. return 1;
  3755. }
  3756. else {
  3757. int res;
  3758. Py_ssize_t len;
  3759. Py_ssize_t i;
  3760. if (!PyList_Check(tmp)) {
  3761. PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  3762. goto failed;
  3763. }
  3764. len = PyList_GET_SIZE(tmp);
  3765. body = _Py_asdl_seq_new(len, arena);
  3766. if (body == NULL) goto failed;
  3767. for (i = 0; i < len; i++) {
  3768. stmt_ty val;
  3769. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  3770. if (res != 0) goto failed;
  3771. if (len != PyList_GET_SIZE(tmp)) {
  3772. PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
  3773. goto failed;
  3774. }
  3775. asdl_seq_SET(body, i, val);
  3776. }
  3777. Py_CLEAR(tmp);
  3778. }
  3779. *out = Suite(body, arena);
  3780. if (*out == NULL) goto failed;
  3781. return 0;
  3782. }
  3783. PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
  3784. failed:
  3785. Py_XDECREF(tmp);
  3786. return 1;
  3787. }
  3788. int
  3789. obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
  3790. {
  3791. int isinstance;
  3792. PyObject *tmp = NULL;
  3793. int lineno;
  3794. int col_offset;
  3795. if (obj == Py_None) {
  3796. *out = NULL;
  3797. return 0;
  3798. }
  3799. if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) {
  3800. return 1;
  3801. }
  3802. if (tmp == NULL) {
  3803. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
  3804. return 1;
  3805. }
  3806. else {
  3807. int res;
  3808. res = obj2ast_int(tmp, &lineno, arena);
  3809. if (res != 0) goto failed;
  3810. Py_CLEAR(tmp);
  3811. }
  3812. if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) {
  3813. return 1;
  3814. }
  3815. if (tmp == NULL) {
  3816. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
  3817. return 1;
  3818. }
  3819. else {
  3820. int res;
  3821. res = obj2ast_int(tmp, &col_offset, arena);
  3822. if (res != 0) goto failed;
  3823. Py_CLEAR(tmp);
  3824. }
  3825. isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);
  3826. if (isinstance == -1) {
  3827. return 1;
  3828. }
  3829. if (isinstance) {
  3830. identifier name;
  3831. arguments_ty args;
  3832. asdl_seq* body;
  3833. asdl_seq* decorator_list;
  3834. expr_ty returns;
  3835. if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
  3836. return 1;
  3837. }
  3838. if (tmp == NULL) {
  3839. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
  3840. return 1;
  3841. }
  3842. else {
  3843. int res;
  3844. res = obj2ast_identifier(tmp, &name, arena);
  3845. if (res != 0) goto failed;
  3846. Py_CLEAR(tmp);
  3847. }
  3848. if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
  3849. return 1;
  3850. }
  3851. if (tmp == NULL) {
  3852. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
  3853. return 1;
  3854. }
  3855. else {
  3856. int res;
  3857. res = obj2ast_arguments(tmp, &args, arena);
  3858. if (res != 0) goto failed;
  3859. Py_CLEAR(tmp);
  3860. }
  3861. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  3862. return 1;
  3863. }
  3864. if (tmp == NULL) {
  3865. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
  3866. return 1;
  3867. }
  3868. else {
  3869. int res;
  3870. Py_ssize_t len;
  3871. Py_ssize_t i;
  3872. if (!PyList_Check(tmp)) {
  3873. PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  3874. goto failed;
  3875. }
  3876. len = PyList_GET_SIZE(tmp);
  3877. body = _Py_asdl_seq_new(len, arena);
  3878. if (body == NULL) goto failed;
  3879. for (i = 0; i < len; i++) {
  3880. stmt_ty val;
  3881. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  3882. if (res != 0) goto failed;
  3883. if (len != PyList_GET_SIZE(tmp)) {
  3884. PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
  3885. goto failed;
  3886. }
  3887. asdl_seq_SET(body, i, val);
  3888. }
  3889. Py_CLEAR(tmp);
  3890. }
  3891. if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) {
  3892. return 1;
  3893. }
  3894. if (tmp == NULL) {
  3895. PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
  3896. return 1;
  3897. }
  3898. else {
  3899. int res;
  3900. Py_ssize_t len;
  3901. Py_ssize_t i;
  3902. if (!PyList_Check(tmp)) {
  3903. PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  3904. goto failed;
  3905. }
  3906. len = PyList_GET_SIZE(tmp);
  3907. decorator_list = _Py_asdl_seq_new(len, arena);
  3908. if (decorator_list == NULL) goto failed;
  3909. for (i = 0; i < len; i++) {
  3910. expr_ty val;
  3911. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  3912. if (res != 0) goto failed;
  3913. if (len != PyList_GET_SIZE(tmp)) {
  3914. PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
  3915. goto failed;
  3916. }
  3917. asdl_seq_SET(decorator_list, i, val);
  3918. }
  3919. Py_CLEAR(tmp);
  3920. }
  3921. if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) {
  3922. return 1;
  3923. }
  3924. if (tmp == NULL || tmp == Py_None) {
  3925. Py_CLEAR(tmp);
  3926. returns = NULL;
  3927. }
  3928. else {
  3929. int res;
  3930. res = obj2ast_expr(tmp, &returns, arena);
  3931. if (res != 0) goto failed;
  3932. Py_CLEAR(tmp);
  3933. }
  3934. *out = FunctionDef(name, args, body, decorator_list, returns, lineno,
  3935. col_offset, arena);
  3936. if (*out == NULL) goto failed;
  3937. return 0;
  3938. }
  3939. isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type);
  3940. if (isinstance == -1) {
  3941. return 1;
  3942. }
  3943. if (isinstance) {
  3944. identifier name;
  3945. arguments_ty args;
  3946. asdl_seq* body;
  3947. asdl_seq* decorator_list;
  3948. expr_ty returns;
  3949. if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
  3950. return 1;
  3951. }
  3952. if (tmp == NULL) {
  3953. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
  3954. return 1;
  3955. }
  3956. else {
  3957. int res;
  3958. res = obj2ast_identifier(tmp, &name, arena);
  3959. if (res != 0) goto failed;
  3960. Py_CLEAR(tmp);
  3961. }
  3962. if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
  3963. return 1;
  3964. }
  3965. if (tmp == NULL) {
  3966. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
  3967. return 1;
  3968. }
  3969. else {
  3970. int res;
  3971. res = obj2ast_arguments(tmp, &args, arena);
  3972. if (res != 0) goto failed;
  3973. Py_CLEAR(tmp);
  3974. }
  3975. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  3976. return 1;
  3977. }
  3978. if (tmp == NULL) {
  3979. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
  3980. return 1;
  3981. }
  3982. else {
  3983. int res;
  3984. Py_ssize_t len;
  3985. Py_ssize_t i;
  3986. if (!PyList_Check(tmp)) {
  3987. PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  3988. goto failed;
  3989. }
  3990. len = PyList_GET_SIZE(tmp);
  3991. body = _Py_asdl_seq_new(len, arena);
  3992. if (body == NULL) goto failed;
  3993. for (i = 0; i < len; i++) {
  3994. stmt_ty val;
  3995. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  3996. if (res != 0) goto failed;
  3997. if (len != PyList_GET_SIZE(tmp)) {
  3998. PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
  3999. goto failed;
  4000. }
  4001. asdl_seq_SET(body, i, val);
  4002. }
  4003. Py_CLEAR(tmp);
  4004. }
  4005. if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) {
  4006. return 1;
  4007. }
  4008. if (tmp == NULL) {
  4009. PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
  4010. return 1;
  4011. }
  4012. else {
  4013. int res;
  4014. Py_ssize_t len;
  4015. Py_ssize_t i;
  4016. if (!PyList_Check(tmp)) {
  4017. PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4018. goto failed;
  4019. }
  4020. len = PyList_GET_SIZE(tmp);
  4021. decorator_list = _Py_asdl_seq_new(len, arena);
  4022. if (decorator_list == NULL) goto failed;
  4023. for (i = 0; i < len; i++) {
  4024. expr_ty val;
  4025. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  4026. if (res != 0) goto failed;
  4027. if (len != PyList_GET_SIZE(tmp)) {
  4028. PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
  4029. goto failed;
  4030. }
  4031. asdl_seq_SET(decorator_list, i, val);
  4032. }
  4033. Py_CLEAR(tmp);
  4034. }
  4035. if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) {
  4036. return 1;
  4037. }
  4038. if (tmp == NULL || tmp == Py_None) {
  4039. Py_CLEAR(tmp);
  4040. returns = NULL;
  4041. }
  4042. else {
  4043. int res;
  4044. res = obj2ast_expr(tmp, &returns, arena);
  4045. if (res != 0) goto failed;
  4046. Py_CLEAR(tmp);
  4047. }
  4048. *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
  4049. lineno, col_offset, arena);
  4050. if (*out == NULL) goto failed;
  4051. return 0;
  4052. }
  4053. isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);
  4054. if (isinstance == -1) {
  4055. return 1;
  4056. }
  4057. if (isinstance) {
  4058. identifier name;
  4059. asdl_seq* bases;
  4060. asdl_seq* keywords;
  4061. asdl_seq* body;
  4062. asdl_seq* decorator_list;
  4063. if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
  4064. return 1;
  4065. }
  4066. if (tmp == NULL) {
  4067. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
  4068. return 1;
  4069. }
  4070. else {
  4071. int res;
  4072. res = obj2ast_identifier(tmp, &name, arena);
  4073. if (res != 0) goto failed;
  4074. Py_CLEAR(tmp);
  4075. }
  4076. if (_PyObject_LookupAttrId(obj, &PyId_bases, &tmp) < 0) {
  4077. return 1;
  4078. }
  4079. if (tmp == NULL) {
  4080. PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
  4081. return 1;
  4082. }
  4083. else {
  4084. int res;
  4085. Py_ssize_t len;
  4086. Py_ssize_t i;
  4087. if (!PyList_Check(tmp)) {
  4088. PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4089. goto failed;
  4090. }
  4091. len = PyList_GET_SIZE(tmp);
  4092. bases = _Py_asdl_seq_new(len, arena);
  4093. if (bases == NULL) goto failed;
  4094. for (i = 0; i < len; i++) {
  4095. expr_ty val;
  4096. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  4097. if (res != 0) goto failed;
  4098. if (len != PyList_GET_SIZE(tmp)) {
  4099. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
  4100. goto failed;
  4101. }
  4102. asdl_seq_SET(bases, i, val);
  4103. }
  4104. Py_CLEAR(tmp);
  4105. }
  4106. if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) {
  4107. return 1;
  4108. }
  4109. if (tmp == NULL) {
  4110. PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
  4111. return 1;
  4112. }
  4113. else {
  4114. int res;
  4115. Py_ssize_t len;
  4116. Py_ssize_t i;
  4117. if (!PyList_Check(tmp)) {
  4118. PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4119. goto failed;
  4120. }
  4121. len = PyList_GET_SIZE(tmp);
  4122. keywords = _Py_asdl_seq_new(len, arena);
  4123. if (keywords == NULL) goto failed;
  4124. for (i = 0; i < len; i++) {
  4125. keyword_ty val;
  4126. res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena);
  4127. if (res != 0) goto failed;
  4128. if (len != PyList_GET_SIZE(tmp)) {
  4129. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
  4130. goto failed;
  4131. }
  4132. asdl_seq_SET(keywords, i, val);
  4133. }
  4134. Py_CLEAR(tmp);
  4135. }
  4136. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  4137. return 1;
  4138. }
  4139. if (tmp == NULL) {
  4140. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
  4141. return 1;
  4142. }
  4143. else {
  4144. int res;
  4145. Py_ssize_t len;
  4146. Py_ssize_t i;
  4147. if (!PyList_Check(tmp)) {
  4148. PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4149. goto failed;
  4150. }
  4151. len = PyList_GET_SIZE(tmp);
  4152. body = _Py_asdl_seq_new(len, arena);
  4153. if (body == NULL) goto failed;
  4154. for (i = 0; i < len; i++) {
  4155. stmt_ty val;
  4156. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4157. if (res != 0) goto failed;
  4158. if (len != PyList_GET_SIZE(tmp)) {
  4159. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
  4160. goto failed;
  4161. }
  4162. asdl_seq_SET(body, i, val);
  4163. }
  4164. Py_CLEAR(tmp);
  4165. }
  4166. if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) {
  4167. return 1;
  4168. }
  4169. if (tmp == NULL) {
  4170. PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
  4171. return 1;
  4172. }
  4173. else {
  4174. int res;
  4175. Py_ssize_t len;
  4176. Py_ssize_t i;
  4177. if (!PyList_Check(tmp)) {
  4178. PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4179. goto failed;
  4180. }
  4181. len = PyList_GET_SIZE(tmp);
  4182. decorator_list = _Py_asdl_seq_new(len, arena);
  4183. if (decorator_list == NULL) goto failed;
  4184. for (i = 0; i < len; i++) {
  4185. expr_ty val;
  4186. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  4187. if (res != 0) goto failed;
  4188. if (len != PyList_GET_SIZE(tmp)) {
  4189. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
  4190. goto failed;
  4191. }
  4192. asdl_seq_SET(decorator_list, i, val);
  4193. }
  4194. Py_CLEAR(tmp);
  4195. }
  4196. *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
  4197. col_offset, arena);
  4198. if (*out == NULL) goto failed;
  4199. return 0;
  4200. }
  4201. isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);
  4202. if (isinstance == -1) {
  4203. return 1;
  4204. }
  4205. if (isinstance) {
  4206. expr_ty value;
  4207. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  4208. return 1;
  4209. }
  4210. if (tmp == NULL || tmp == Py_None) {
  4211. Py_CLEAR(tmp);
  4212. value = NULL;
  4213. }
  4214. else {
  4215. int res;
  4216. res = obj2ast_expr(tmp, &value, arena);
  4217. if (res != 0) goto failed;
  4218. Py_CLEAR(tmp);
  4219. }
  4220. *out = Return(value, lineno, col_offset, arena);
  4221. if (*out == NULL) goto failed;
  4222. return 0;
  4223. }
  4224. isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);
  4225. if (isinstance == -1) {
  4226. return 1;
  4227. }
  4228. if (isinstance) {
  4229. asdl_seq* targets;
  4230. if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) {
  4231. return 1;
  4232. }
  4233. if (tmp == NULL) {
  4234. PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
  4235. return 1;
  4236. }
  4237. else {
  4238. int res;
  4239. Py_ssize_t len;
  4240. Py_ssize_t i;
  4241. if (!PyList_Check(tmp)) {
  4242. PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4243. goto failed;
  4244. }
  4245. len = PyList_GET_SIZE(tmp);
  4246. targets = _Py_asdl_seq_new(len, arena);
  4247. if (targets == NULL) goto failed;
  4248. for (i = 0; i < len; i++) {
  4249. expr_ty val;
  4250. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  4251. if (res != 0) goto failed;
  4252. if (len != PyList_GET_SIZE(tmp)) {
  4253. PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
  4254. goto failed;
  4255. }
  4256. asdl_seq_SET(targets, i, val);
  4257. }
  4258. Py_CLEAR(tmp);
  4259. }
  4260. *out = Delete(targets, lineno, col_offset, arena);
  4261. if (*out == NULL) goto failed;
  4262. return 0;
  4263. }
  4264. isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);
  4265. if (isinstance == -1) {
  4266. return 1;
  4267. }
  4268. if (isinstance) {
  4269. asdl_seq* targets;
  4270. expr_ty value;
  4271. if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) {
  4272. return 1;
  4273. }
  4274. if (tmp == NULL) {
  4275. PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
  4276. return 1;
  4277. }
  4278. else {
  4279. int res;
  4280. Py_ssize_t len;
  4281. Py_ssize_t i;
  4282. if (!PyList_Check(tmp)) {
  4283. PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4284. goto failed;
  4285. }
  4286. len = PyList_GET_SIZE(tmp);
  4287. targets = _Py_asdl_seq_new(len, arena);
  4288. if (targets == NULL) goto failed;
  4289. for (i = 0; i < len; i++) {
  4290. expr_ty val;
  4291. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  4292. if (res != 0) goto failed;
  4293. if (len != PyList_GET_SIZE(tmp)) {
  4294. PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
  4295. goto failed;
  4296. }
  4297. asdl_seq_SET(targets, i, val);
  4298. }
  4299. Py_CLEAR(tmp);
  4300. }
  4301. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  4302. return 1;
  4303. }
  4304. if (tmp == NULL) {
  4305. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
  4306. return 1;
  4307. }
  4308. else {
  4309. int res;
  4310. res = obj2ast_expr(tmp, &value, arena);
  4311. if (res != 0) goto failed;
  4312. Py_CLEAR(tmp);
  4313. }
  4314. *out = Assign(targets, value, lineno, col_offset, arena);
  4315. if (*out == NULL) goto failed;
  4316. return 0;
  4317. }
  4318. isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);
  4319. if (isinstance == -1) {
  4320. return 1;
  4321. }
  4322. if (isinstance) {
  4323. expr_ty target;
  4324. operator_ty op;
  4325. expr_ty value;
  4326. if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
  4327. return 1;
  4328. }
  4329. if (tmp == NULL) {
  4330. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
  4331. return 1;
  4332. }
  4333. else {
  4334. int res;
  4335. res = obj2ast_expr(tmp, &target, arena);
  4336. if (res != 0) goto failed;
  4337. Py_CLEAR(tmp);
  4338. }
  4339. if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) {
  4340. return 1;
  4341. }
  4342. if (tmp == NULL) {
  4343. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
  4344. return 1;
  4345. }
  4346. else {
  4347. int res;
  4348. res = obj2ast_operator(tmp, &op, arena);
  4349. if (res != 0) goto failed;
  4350. Py_CLEAR(tmp);
  4351. }
  4352. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  4353. return 1;
  4354. }
  4355. if (tmp == NULL) {
  4356. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
  4357. return 1;
  4358. }
  4359. else {
  4360. int res;
  4361. res = obj2ast_expr(tmp, &value, arena);
  4362. if (res != 0) goto failed;
  4363. Py_CLEAR(tmp);
  4364. }
  4365. *out = AugAssign(target, op, value, lineno, col_offset, arena);
  4366. if (*out == NULL) goto failed;
  4367. return 0;
  4368. }
  4369. isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type);
  4370. if (isinstance == -1) {
  4371. return 1;
  4372. }
  4373. if (isinstance) {
  4374. expr_ty target;
  4375. expr_ty annotation;
  4376. expr_ty value;
  4377. int simple;
  4378. if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
  4379. return 1;
  4380. }
  4381. if (tmp == NULL) {
  4382. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
  4383. return 1;
  4384. }
  4385. else {
  4386. int res;
  4387. res = obj2ast_expr(tmp, &target, arena);
  4388. if (res != 0) goto failed;
  4389. Py_CLEAR(tmp);
  4390. }
  4391. if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) {
  4392. return 1;
  4393. }
  4394. if (tmp == NULL) {
  4395. PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
  4396. return 1;
  4397. }
  4398. else {
  4399. int res;
  4400. res = obj2ast_expr(tmp, &annotation, arena);
  4401. if (res != 0) goto failed;
  4402. Py_CLEAR(tmp);
  4403. }
  4404. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  4405. return 1;
  4406. }
  4407. if (tmp == NULL || tmp == Py_None) {
  4408. Py_CLEAR(tmp);
  4409. value = NULL;
  4410. }
  4411. else {
  4412. int res;
  4413. res = obj2ast_expr(tmp, &value, arena);
  4414. if (res != 0) goto failed;
  4415. Py_CLEAR(tmp);
  4416. }
  4417. if (_PyObject_LookupAttrId(obj, &PyId_simple, &tmp) < 0) {
  4418. return 1;
  4419. }
  4420. if (tmp == NULL) {
  4421. PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
  4422. return 1;
  4423. }
  4424. else {
  4425. int res;
  4426. res = obj2ast_int(tmp, &simple, arena);
  4427. if (res != 0) goto failed;
  4428. Py_CLEAR(tmp);
  4429. }
  4430. *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
  4431. arena);
  4432. if (*out == NULL) goto failed;
  4433. return 0;
  4434. }
  4435. isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);
  4436. if (isinstance == -1) {
  4437. return 1;
  4438. }
  4439. if (isinstance) {
  4440. expr_ty target;
  4441. expr_ty iter;
  4442. asdl_seq* body;
  4443. asdl_seq* orelse;
  4444. if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
  4445. return 1;
  4446. }
  4447. if (tmp == NULL) {
  4448. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
  4449. return 1;
  4450. }
  4451. else {
  4452. int res;
  4453. res = obj2ast_expr(tmp, &target, arena);
  4454. if (res != 0) goto failed;
  4455. Py_CLEAR(tmp);
  4456. }
  4457. if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) {
  4458. return 1;
  4459. }
  4460. if (tmp == NULL) {
  4461. PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
  4462. return 1;
  4463. }
  4464. else {
  4465. int res;
  4466. res = obj2ast_expr(tmp, &iter, arena);
  4467. if (res != 0) goto failed;
  4468. Py_CLEAR(tmp);
  4469. }
  4470. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  4471. return 1;
  4472. }
  4473. if (tmp == NULL) {
  4474. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
  4475. return 1;
  4476. }
  4477. else {
  4478. int res;
  4479. Py_ssize_t len;
  4480. Py_ssize_t i;
  4481. if (!PyList_Check(tmp)) {
  4482. PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4483. goto failed;
  4484. }
  4485. len = PyList_GET_SIZE(tmp);
  4486. body = _Py_asdl_seq_new(len, arena);
  4487. if (body == NULL) goto failed;
  4488. for (i = 0; i < len; i++) {
  4489. stmt_ty val;
  4490. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4491. if (res != 0) goto failed;
  4492. if (len != PyList_GET_SIZE(tmp)) {
  4493. PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
  4494. goto failed;
  4495. }
  4496. asdl_seq_SET(body, i, val);
  4497. }
  4498. Py_CLEAR(tmp);
  4499. }
  4500. if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
  4501. return 1;
  4502. }
  4503. if (tmp == NULL) {
  4504. PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
  4505. return 1;
  4506. }
  4507. else {
  4508. int res;
  4509. Py_ssize_t len;
  4510. Py_ssize_t i;
  4511. if (!PyList_Check(tmp)) {
  4512. PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4513. goto failed;
  4514. }
  4515. len = PyList_GET_SIZE(tmp);
  4516. orelse = _Py_asdl_seq_new(len, arena);
  4517. if (orelse == NULL) goto failed;
  4518. for (i = 0; i < len; i++) {
  4519. stmt_ty val;
  4520. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4521. if (res != 0) goto failed;
  4522. if (len != PyList_GET_SIZE(tmp)) {
  4523. PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
  4524. goto failed;
  4525. }
  4526. asdl_seq_SET(orelse, i, val);
  4527. }
  4528. Py_CLEAR(tmp);
  4529. }
  4530. *out = For(target, iter, body, orelse, lineno, col_offset, arena);
  4531. if (*out == NULL) goto failed;
  4532. return 0;
  4533. }
  4534. isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type);
  4535. if (isinstance == -1) {
  4536. return 1;
  4537. }
  4538. if (isinstance) {
  4539. expr_ty target;
  4540. expr_ty iter;
  4541. asdl_seq* body;
  4542. asdl_seq* orelse;
  4543. if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
  4544. return 1;
  4545. }
  4546. if (tmp == NULL) {
  4547. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
  4548. return 1;
  4549. }
  4550. else {
  4551. int res;
  4552. res = obj2ast_expr(tmp, &target, arena);
  4553. if (res != 0) goto failed;
  4554. Py_CLEAR(tmp);
  4555. }
  4556. if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) {
  4557. return 1;
  4558. }
  4559. if (tmp == NULL) {
  4560. PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
  4561. return 1;
  4562. }
  4563. else {
  4564. int res;
  4565. res = obj2ast_expr(tmp, &iter, arena);
  4566. if (res != 0) goto failed;
  4567. Py_CLEAR(tmp);
  4568. }
  4569. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  4570. return 1;
  4571. }
  4572. if (tmp == NULL) {
  4573. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
  4574. return 1;
  4575. }
  4576. else {
  4577. int res;
  4578. Py_ssize_t len;
  4579. Py_ssize_t i;
  4580. if (!PyList_Check(tmp)) {
  4581. PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4582. goto failed;
  4583. }
  4584. len = PyList_GET_SIZE(tmp);
  4585. body = _Py_asdl_seq_new(len, arena);
  4586. if (body == NULL) goto failed;
  4587. for (i = 0; i < len; i++) {
  4588. stmt_ty val;
  4589. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4590. if (res != 0) goto failed;
  4591. if (len != PyList_GET_SIZE(tmp)) {
  4592. PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
  4593. goto failed;
  4594. }
  4595. asdl_seq_SET(body, i, val);
  4596. }
  4597. Py_CLEAR(tmp);
  4598. }
  4599. if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
  4600. return 1;
  4601. }
  4602. if (tmp == NULL) {
  4603. PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
  4604. return 1;
  4605. }
  4606. else {
  4607. int res;
  4608. Py_ssize_t len;
  4609. Py_ssize_t i;
  4610. if (!PyList_Check(tmp)) {
  4611. PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4612. goto failed;
  4613. }
  4614. len = PyList_GET_SIZE(tmp);
  4615. orelse = _Py_asdl_seq_new(len, arena);
  4616. if (orelse == NULL) goto failed;
  4617. for (i = 0; i < len; i++) {
  4618. stmt_ty val;
  4619. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4620. if (res != 0) goto failed;
  4621. if (len != PyList_GET_SIZE(tmp)) {
  4622. PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
  4623. goto failed;
  4624. }
  4625. asdl_seq_SET(orelse, i, val);
  4626. }
  4627. Py_CLEAR(tmp);
  4628. }
  4629. *out = AsyncFor(target, iter, body, orelse, lineno, col_offset, arena);
  4630. if (*out == NULL) goto failed;
  4631. return 0;
  4632. }
  4633. isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);
  4634. if (isinstance == -1) {
  4635. return 1;
  4636. }
  4637. if (isinstance) {
  4638. expr_ty test;
  4639. asdl_seq* body;
  4640. asdl_seq* orelse;
  4641. if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) {
  4642. return 1;
  4643. }
  4644. if (tmp == NULL) {
  4645. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
  4646. return 1;
  4647. }
  4648. else {
  4649. int res;
  4650. res = obj2ast_expr(tmp, &test, arena);
  4651. if (res != 0) goto failed;
  4652. Py_CLEAR(tmp);
  4653. }
  4654. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  4655. return 1;
  4656. }
  4657. if (tmp == NULL) {
  4658. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
  4659. return 1;
  4660. }
  4661. else {
  4662. int res;
  4663. Py_ssize_t len;
  4664. Py_ssize_t i;
  4665. if (!PyList_Check(tmp)) {
  4666. PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4667. goto failed;
  4668. }
  4669. len = PyList_GET_SIZE(tmp);
  4670. body = _Py_asdl_seq_new(len, arena);
  4671. if (body == NULL) goto failed;
  4672. for (i = 0; i < len; i++) {
  4673. stmt_ty val;
  4674. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4675. if (res != 0) goto failed;
  4676. if (len != PyList_GET_SIZE(tmp)) {
  4677. PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
  4678. goto failed;
  4679. }
  4680. asdl_seq_SET(body, i, val);
  4681. }
  4682. Py_CLEAR(tmp);
  4683. }
  4684. if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
  4685. return 1;
  4686. }
  4687. if (tmp == NULL) {
  4688. PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
  4689. return 1;
  4690. }
  4691. else {
  4692. int res;
  4693. Py_ssize_t len;
  4694. Py_ssize_t i;
  4695. if (!PyList_Check(tmp)) {
  4696. PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4697. goto failed;
  4698. }
  4699. len = PyList_GET_SIZE(tmp);
  4700. orelse = _Py_asdl_seq_new(len, arena);
  4701. if (orelse == NULL) goto failed;
  4702. for (i = 0; i < len; i++) {
  4703. stmt_ty val;
  4704. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4705. if (res != 0) goto failed;
  4706. if (len != PyList_GET_SIZE(tmp)) {
  4707. PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
  4708. goto failed;
  4709. }
  4710. asdl_seq_SET(orelse, i, val);
  4711. }
  4712. Py_CLEAR(tmp);
  4713. }
  4714. *out = While(test, body, orelse, lineno, col_offset, arena);
  4715. if (*out == NULL) goto failed;
  4716. return 0;
  4717. }
  4718. isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);
  4719. if (isinstance == -1) {
  4720. return 1;
  4721. }
  4722. if (isinstance) {
  4723. expr_ty test;
  4724. asdl_seq* body;
  4725. asdl_seq* orelse;
  4726. if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) {
  4727. return 1;
  4728. }
  4729. if (tmp == NULL) {
  4730. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
  4731. return 1;
  4732. }
  4733. else {
  4734. int res;
  4735. res = obj2ast_expr(tmp, &test, arena);
  4736. if (res != 0) goto failed;
  4737. Py_CLEAR(tmp);
  4738. }
  4739. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  4740. return 1;
  4741. }
  4742. if (tmp == NULL) {
  4743. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
  4744. return 1;
  4745. }
  4746. else {
  4747. int res;
  4748. Py_ssize_t len;
  4749. Py_ssize_t i;
  4750. if (!PyList_Check(tmp)) {
  4751. PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4752. goto failed;
  4753. }
  4754. len = PyList_GET_SIZE(tmp);
  4755. body = _Py_asdl_seq_new(len, arena);
  4756. if (body == NULL) goto failed;
  4757. for (i = 0; i < len; i++) {
  4758. stmt_ty val;
  4759. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4760. if (res != 0) goto failed;
  4761. if (len != PyList_GET_SIZE(tmp)) {
  4762. PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
  4763. goto failed;
  4764. }
  4765. asdl_seq_SET(body, i, val);
  4766. }
  4767. Py_CLEAR(tmp);
  4768. }
  4769. if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
  4770. return 1;
  4771. }
  4772. if (tmp == NULL) {
  4773. PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
  4774. return 1;
  4775. }
  4776. else {
  4777. int res;
  4778. Py_ssize_t len;
  4779. Py_ssize_t i;
  4780. if (!PyList_Check(tmp)) {
  4781. PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4782. goto failed;
  4783. }
  4784. len = PyList_GET_SIZE(tmp);
  4785. orelse = _Py_asdl_seq_new(len, arena);
  4786. if (orelse == NULL) goto failed;
  4787. for (i = 0; i < len; i++) {
  4788. stmt_ty val;
  4789. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4790. if (res != 0) goto failed;
  4791. if (len != PyList_GET_SIZE(tmp)) {
  4792. PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
  4793. goto failed;
  4794. }
  4795. asdl_seq_SET(orelse, i, val);
  4796. }
  4797. Py_CLEAR(tmp);
  4798. }
  4799. *out = If(test, body, orelse, lineno, col_offset, arena);
  4800. if (*out == NULL) goto failed;
  4801. return 0;
  4802. }
  4803. isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);
  4804. if (isinstance == -1) {
  4805. return 1;
  4806. }
  4807. if (isinstance) {
  4808. asdl_seq* items;
  4809. asdl_seq* body;
  4810. if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) {
  4811. return 1;
  4812. }
  4813. if (tmp == NULL) {
  4814. PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
  4815. return 1;
  4816. }
  4817. else {
  4818. int res;
  4819. Py_ssize_t len;
  4820. Py_ssize_t i;
  4821. if (!PyList_Check(tmp)) {
  4822. PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4823. goto failed;
  4824. }
  4825. len = PyList_GET_SIZE(tmp);
  4826. items = _Py_asdl_seq_new(len, arena);
  4827. if (items == NULL) goto failed;
  4828. for (i = 0; i < len; i++) {
  4829. withitem_ty val;
  4830. res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena);
  4831. if (res != 0) goto failed;
  4832. if (len != PyList_GET_SIZE(tmp)) {
  4833. PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
  4834. goto failed;
  4835. }
  4836. asdl_seq_SET(items, i, val);
  4837. }
  4838. Py_CLEAR(tmp);
  4839. }
  4840. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  4841. return 1;
  4842. }
  4843. if (tmp == NULL) {
  4844. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
  4845. return 1;
  4846. }
  4847. else {
  4848. int res;
  4849. Py_ssize_t len;
  4850. Py_ssize_t i;
  4851. if (!PyList_Check(tmp)) {
  4852. PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4853. goto failed;
  4854. }
  4855. len = PyList_GET_SIZE(tmp);
  4856. body = _Py_asdl_seq_new(len, arena);
  4857. if (body == NULL) goto failed;
  4858. for (i = 0; i < len; i++) {
  4859. stmt_ty val;
  4860. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4861. if (res != 0) goto failed;
  4862. if (len != PyList_GET_SIZE(tmp)) {
  4863. PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
  4864. goto failed;
  4865. }
  4866. asdl_seq_SET(body, i, val);
  4867. }
  4868. Py_CLEAR(tmp);
  4869. }
  4870. *out = With(items, body, lineno, col_offset, arena);
  4871. if (*out == NULL) goto failed;
  4872. return 0;
  4873. }
  4874. isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type);
  4875. if (isinstance == -1) {
  4876. return 1;
  4877. }
  4878. if (isinstance) {
  4879. asdl_seq* items;
  4880. asdl_seq* body;
  4881. if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) {
  4882. return 1;
  4883. }
  4884. if (tmp == NULL) {
  4885. PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
  4886. return 1;
  4887. }
  4888. else {
  4889. int res;
  4890. Py_ssize_t len;
  4891. Py_ssize_t i;
  4892. if (!PyList_Check(tmp)) {
  4893. PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4894. goto failed;
  4895. }
  4896. len = PyList_GET_SIZE(tmp);
  4897. items = _Py_asdl_seq_new(len, arena);
  4898. if (items == NULL) goto failed;
  4899. for (i = 0; i < len; i++) {
  4900. withitem_ty val;
  4901. res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena);
  4902. if (res != 0) goto failed;
  4903. if (len != PyList_GET_SIZE(tmp)) {
  4904. PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
  4905. goto failed;
  4906. }
  4907. asdl_seq_SET(items, i, val);
  4908. }
  4909. Py_CLEAR(tmp);
  4910. }
  4911. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  4912. return 1;
  4913. }
  4914. if (tmp == NULL) {
  4915. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
  4916. return 1;
  4917. }
  4918. else {
  4919. int res;
  4920. Py_ssize_t len;
  4921. Py_ssize_t i;
  4922. if (!PyList_Check(tmp)) {
  4923. PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  4924. goto failed;
  4925. }
  4926. len = PyList_GET_SIZE(tmp);
  4927. body = _Py_asdl_seq_new(len, arena);
  4928. if (body == NULL) goto failed;
  4929. for (i = 0; i < len; i++) {
  4930. stmt_ty val;
  4931. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  4932. if (res != 0) goto failed;
  4933. if (len != PyList_GET_SIZE(tmp)) {
  4934. PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
  4935. goto failed;
  4936. }
  4937. asdl_seq_SET(body, i, val);
  4938. }
  4939. Py_CLEAR(tmp);
  4940. }
  4941. *out = AsyncWith(items, body, lineno, col_offset, arena);
  4942. if (*out == NULL) goto failed;
  4943. return 0;
  4944. }
  4945. isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);
  4946. if (isinstance == -1) {
  4947. return 1;
  4948. }
  4949. if (isinstance) {
  4950. expr_ty exc;
  4951. expr_ty cause;
  4952. if (_PyObject_LookupAttrId(obj, &PyId_exc, &tmp) < 0) {
  4953. return 1;
  4954. }
  4955. if (tmp == NULL || tmp == Py_None) {
  4956. Py_CLEAR(tmp);
  4957. exc = NULL;
  4958. }
  4959. else {
  4960. int res;
  4961. res = obj2ast_expr(tmp, &exc, arena);
  4962. if (res != 0) goto failed;
  4963. Py_CLEAR(tmp);
  4964. }
  4965. if (_PyObject_LookupAttrId(obj, &PyId_cause, &tmp) < 0) {
  4966. return 1;
  4967. }
  4968. if (tmp == NULL || tmp == Py_None) {
  4969. Py_CLEAR(tmp);
  4970. cause = NULL;
  4971. }
  4972. else {
  4973. int res;
  4974. res = obj2ast_expr(tmp, &cause, arena);
  4975. if (res != 0) goto failed;
  4976. Py_CLEAR(tmp);
  4977. }
  4978. *out = Raise(exc, cause, lineno, col_offset, arena);
  4979. if (*out == NULL) goto failed;
  4980. return 0;
  4981. }
  4982. isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type);
  4983. if (isinstance == -1) {
  4984. return 1;
  4985. }
  4986. if (isinstance) {
  4987. asdl_seq* body;
  4988. asdl_seq* handlers;
  4989. asdl_seq* orelse;
  4990. asdl_seq* finalbody;
  4991. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  4992. return 1;
  4993. }
  4994. if (tmp == NULL) {
  4995. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
  4996. return 1;
  4997. }
  4998. else {
  4999. int res;
  5000. Py_ssize_t len;
  5001. Py_ssize_t i;
  5002. if (!PyList_Check(tmp)) {
  5003. PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5004. goto failed;
  5005. }
  5006. len = PyList_GET_SIZE(tmp);
  5007. body = _Py_asdl_seq_new(len, arena);
  5008. if (body == NULL) goto failed;
  5009. for (i = 0; i < len; i++) {
  5010. stmt_ty val;
  5011. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  5012. if (res != 0) goto failed;
  5013. if (len != PyList_GET_SIZE(tmp)) {
  5014. PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
  5015. goto failed;
  5016. }
  5017. asdl_seq_SET(body, i, val);
  5018. }
  5019. Py_CLEAR(tmp);
  5020. }
  5021. if (_PyObject_LookupAttrId(obj, &PyId_handlers, &tmp) < 0) {
  5022. return 1;
  5023. }
  5024. if (tmp == NULL) {
  5025. PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
  5026. return 1;
  5027. }
  5028. else {
  5029. int res;
  5030. Py_ssize_t len;
  5031. Py_ssize_t i;
  5032. if (!PyList_Check(tmp)) {
  5033. PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5034. goto failed;
  5035. }
  5036. len = PyList_GET_SIZE(tmp);
  5037. handlers = _Py_asdl_seq_new(len, arena);
  5038. if (handlers == NULL) goto failed;
  5039. for (i = 0; i < len; i++) {
  5040. excepthandler_ty val;
  5041. res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena);
  5042. if (res != 0) goto failed;
  5043. if (len != PyList_GET_SIZE(tmp)) {
  5044. PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
  5045. goto failed;
  5046. }
  5047. asdl_seq_SET(handlers, i, val);
  5048. }
  5049. Py_CLEAR(tmp);
  5050. }
  5051. if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
  5052. return 1;
  5053. }
  5054. if (tmp == NULL) {
  5055. PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
  5056. return 1;
  5057. }
  5058. else {
  5059. int res;
  5060. Py_ssize_t len;
  5061. Py_ssize_t i;
  5062. if (!PyList_Check(tmp)) {
  5063. PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5064. goto failed;
  5065. }
  5066. len = PyList_GET_SIZE(tmp);
  5067. orelse = _Py_asdl_seq_new(len, arena);
  5068. if (orelse == NULL) goto failed;
  5069. for (i = 0; i < len; i++) {
  5070. stmt_ty val;
  5071. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  5072. if (res != 0) goto failed;
  5073. if (len != PyList_GET_SIZE(tmp)) {
  5074. PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
  5075. goto failed;
  5076. }
  5077. asdl_seq_SET(orelse, i, val);
  5078. }
  5079. Py_CLEAR(tmp);
  5080. }
  5081. if (_PyObject_LookupAttrId(obj, &PyId_finalbody, &tmp) < 0) {
  5082. return 1;
  5083. }
  5084. if (tmp == NULL) {
  5085. PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
  5086. return 1;
  5087. }
  5088. else {
  5089. int res;
  5090. Py_ssize_t len;
  5091. Py_ssize_t i;
  5092. if (!PyList_Check(tmp)) {
  5093. PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5094. goto failed;
  5095. }
  5096. len = PyList_GET_SIZE(tmp);
  5097. finalbody = _Py_asdl_seq_new(len, arena);
  5098. if (finalbody == NULL) goto failed;
  5099. for (i = 0; i < len; i++) {
  5100. stmt_ty val;
  5101. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  5102. if (res != 0) goto failed;
  5103. if (len != PyList_GET_SIZE(tmp)) {
  5104. PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
  5105. goto failed;
  5106. }
  5107. asdl_seq_SET(finalbody, i, val);
  5108. }
  5109. Py_CLEAR(tmp);
  5110. }
  5111. *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
  5112. arena);
  5113. if (*out == NULL) goto failed;
  5114. return 0;
  5115. }
  5116. isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);
  5117. if (isinstance == -1) {
  5118. return 1;
  5119. }
  5120. if (isinstance) {
  5121. expr_ty test;
  5122. expr_ty msg;
  5123. if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) {
  5124. return 1;
  5125. }
  5126. if (tmp == NULL) {
  5127. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
  5128. return 1;
  5129. }
  5130. else {
  5131. int res;
  5132. res = obj2ast_expr(tmp, &test, arena);
  5133. if (res != 0) goto failed;
  5134. Py_CLEAR(tmp);
  5135. }
  5136. if (_PyObject_LookupAttrId(obj, &PyId_msg, &tmp) < 0) {
  5137. return 1;
  5138. }
  5139. if (tmp == NULL || tmp == Py_None) {
  5140. Py_CLEAR(tmp);
  5141. msg = NULL;
  5142. }
  5143. else {
  5144. int res;
  5145. res = obj2ast_expr(tmp, &msg, arena);
  5146. if (res != 0) goto failed;
  5147. Py_CLEAR(tmp);
  5148. }
  5149. *out = Assert(test, msg, lineno, col_offset, arena);
  5150. if (*out == NULL) goto failed;
  5151. return 0;
  5152. }
  5153. isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);
  5154. if (isinstance == -1) {
  5155. return 1;
  5156. }
  5157. if (isinstance) {
  5158. asdl_seq* names;
  5159. if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) {
  5160. return 1;
  5161. }
  5162. if (tmp == NULL) {
  5163. PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
  5164. return 1;
  5165. }
  5166. else {
  5167. int res;
  5168. Py_ssize_t len;
  5169. Py_ssize_t i;
  5170. if (!PyList_Check(tmp)) {
  5171. PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5172. goto failed;
  5173. }
  5174. len = PyList_GET_SIZE(tmp);
  5175. names = _Py_asdl_seq_new(len, arena);
  5176. if (names == NULL) goto failed;
  5177. for (i = 0; i < len; i++) {
  5178. alias_ty val;
  5179. res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena);
  5180. if (res != 0) goto failed;
  5181. if (len != PyList_GET_SIZE(tmp)) {
  5182. PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
  5183. goto failed;
  5184. }
  5185. asdl_seq_SET(names, i, val);
  5186. }
  5187. Py_CLEAR(tmp);
  5188. }
  5189. *out = Import(names, lineno, col_offset, arena);
  5190. if (*out == NULL) goto failed;
  5191. return 0;
  5192. }
  5193. isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);
  5194. if (isinstance == -1) {
  5195. return 1;
  5196. }
  5197. if (isinstance) {
  5198. identifier module;
  5199. asdl_seq* names;
  5200. int level;
  5201. if (_PyObject_LookupAttrId(obj, &PyId_module, &tmp) < 0) {
  5202. return 1;
  5203. }
  5204. if (tmp == NULL || tmp == Py_None) {
  5205. Py_CLEAR(tmp);
  5206. module = NULL;
  5207. }
  5208. else {
  5209. int res;
  5210. res = obj2ast_identifier(tmp, &module, arena);
  5211. if (res != 0) goto failed;
  5212. Py_CLEAR(tmp);
  5213. }
  5214. if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) {
  5215. return 1;
  5216. }
  5217. if (tmp == NULL) {
  5218. PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
  5219. return 1;
  5220. }
  5221. else {
  5222. int res;
  5223. Py_ssize_t len;
  5224. Py_ssize_t i;
  5225. if (!PyList_Check(tmp)) {
  5226. PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5227. goto failed;
  5228. }
  5229. len = PyList_GET_SIZE(tmp);
  5230. names = _Py_asdl_seq_new(len, arena);
  5231. if (names == NULL) goto failed;
  5232. for (i = 0; i < len; i++) {
  5233. alias_ty val;
  5234. res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena);
  5235. if (res != 0) goto failed;
  5236. if (len != PyList_GET_SIZE(tmp)) {
  5237. PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
  5238. goto failed;
  5239. }
  5240. asdl_seq_SET(names, i, val);
  5241. }
  5242. Py_CLEAR(tmp);
  5243. }
  5244. if (_PyObject_LookupAttrId(obj, &PyId_level, &tmp) < 0) {
  5245. return 1;
  5246. }
  5247. if (tmp == NULL || tmp == Py_None) {
  5248. Py_CLEAR(tmp);
  5249. level = 0;
  5250. }
  5251. else {
  5252. int res;
  5253. res = obj2ast_int(tmp, &level, arena);
  5254. if (res != 0) goto failed;
  5255. Py_CLEAR(tmp);
  5256. }
  5257. *out = ImportFrom(module, names, level, lineno, col_offset, arena);
  5258. if (*out == NULL) goto failed;
  5259. return 0;
  5260. }
  5261. isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
  5262. if (isinstance == -1) {
  5263. return 1;
  5264. }
  5265. if (isinstance) {
  5266. asdl_seq* names;
  5267. if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) {
  5268. return 1;
  5269. }
  5270. if (tmp == NULL) {
  5271. PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
  5272. return 1;
  5273. }
  5274. else {
  5275. int res;
  5276. Py_ssize_t len;
  5277. Py_ssize_t i;
  5278. if (!PyList_Check(tmp)) {
  5279. PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5280. goto failed;
  5281. }
  5282. len = PyList_GET_SIZE(tmp);
  5283. names = _Py_asdl_seq_new(len, arena);
  5284. if (names == NULL) goto failed;
  5285. for (i = 0; i < len; i++) {
  5286. identifier val;
  5287. res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena);
  5288. if (res != 0) goto failed;
  5289. if (len != PyList_GET_SIZE(tmp)) {
  5290. PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
  5291. goto failed;
  5292. }
  5293. asdl_seq_SET(names, i, val);
  5294. }
  5295. Py_CLEAR(tmp);
  5296. }
  5297. *out = Global(names, lineno, col_offset, arena);
  5298. if (*out == NULL) goto failed;
  5299. return 0;
  5300. }
  5301. isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type);
  5302. if (isinstance == -1) {
  5303. return 1;
  5304. }
  5305. if (isinstance) {
  5306. asdl_seq* names;
  5307. if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) {
  5308. return 1;
  5309. }
  5310. if (tmp == NULL) {
  5311. PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
  5312. return 1;
  5313. }
  5314. else {
  5315. int res;
  5316. Py_ssize_t len;
  5317. Py_ssize_t i;
  5318. if (!PyList_Check(tmp)) {
  5319. PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5320. goto failed;
  5321. }
  5322. len = PyList_GET_SIZE(tmp);
  5323. names = _Py_asdl_seq_new(len, arena);
  5324. if (names == NULL) goto failed;
  5325. for (i = 0; i < len; i++) {
  5326. identifier val;
  5327. res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena);
  5328. if (res != 0) goto failed;
  5329. if (len != PyList_GET_SIZE(tmp)) {
  5330. PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
  5331. goto failed;
  5332. }
  5333. asdl_seq_SET(names, i, val);
  5334. }
  5335. Py_CLEAR(tmp);
  5336. }
  5337. *out = Nonlocal(names, lineno, col_offset, arena);
  5338. if (*out == NULL) goto failed;
  5339. return 0;
  5340. }
  5341. isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);
  5342. if (isinstance == -1) {
  5343. return 1;
  5344. }
  5345. if (isinstance) {
  5346. expr_ty value;
  5347. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  5348. return 1;
  5349. }
  5350. if (tmp == NULL) {
  5351. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
  5352. return 1;
  5353. }
  5354. else {
  5355. int res;
  5356. res = obj2ast_expr(tmp, &value, arena);
  5357. if (res != 0) goto failed;
  5358. Py_CLEAR(tmp);
  5359. }
  5360. *out = Expr(value, lineno, col_offset, arena);
  5361. if (*out == NULL) goto failed;
  5362. return 0;
  5363. }
  5364. isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);
  5365. if (isinstance == -1) {
  5366. return 1;
  5367. }
  5368. if (isinstance) {
  5369. *out = Pass(lineno, col_offset, arena);
  5370. if (*out == NULL) goto failed;
  5371. return 0;
  5372. }
  5373. isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);
  5374. if (isinstance == -1) {
  5375. return 1;
  5376. }
  5377. if (isinstance) {
  5378. *out = Break(lineno, col_offset, arena);
  5379. if (*out == NULL) goto failed;
  5380. return 0;
  5381. }
  5382. isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);
  5383. if (isinstance == -1) {
  5384. return 1;
  5385. }
  5386. if (isinstance) {
  5387. *out = Continue(lineno, col_offset, arena);
  5388. if (*out == NULL) goto failed;
  5389. return 0;
  5390. }
  5391. PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
  5392. failed:
  5393. Py_XDECREF(tmp);
  5394. return 1;
  5395. }
  5396. int
  5397. obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
  5398. {
  5399. int isinstance;
  5400. PyObject *tmp = NULL;
  5401. int lineno;
  5402. int col_offset;
  5403. if (obj == Py_None) {
  5404. *out = NULL;
  5405. return 0;
  5406. }
  5407. if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) {
  5408. return 1;
  5409. }
  5410. if (tmp == NULL) {
  5411. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
  5412. return 1;
  5413. }
  5414. else {
  5415. int res;
  5416. res = obj2ast_int(tmp, &lineno, arena);
  5417. if (res != 0) goto failed;
  5418. Py_CLEAR(tmp);
  5419. }
  5420. if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) {
  5421. return 1;
  5422. }
  5423. if (tmp == NULL) {
  5424. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
  5425. return 1;
  5426. }
  5427. else {
  5428. int res;
  5429. res = obj2ast_int(tmp, &col_offset, arena);
  5430. if (res != 0) goto failed;
  5431. Py_CLEAR(tmp);
  5432. }
  5433. isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);
  5434. if (isinstance == -1) {
  5435. return 1;
  5436. }
  5437. if (isinstance) {
  5438. boolop_ty op;
  5439. asdl_seq* values;
  5440. if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) {
  5441. return 1;
  5442. }
  5443. if (tmp == NULL) {
  5444. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
  5445. return 1;
  5446. }
  5447. else {
  5448. int res;
  5449. res = obj2ast_boolop(tmp, &op, arena);
  5450. if (res != 0) goto failed;
  5451. Py_CLEAR(tmp);
  5452. }
  5453. if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) {
  5454. return 1;
  5455. }
  5456. if (tmp == NULL) {
  5457. PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
  5458. return 1;
  5459. }
  5460. else {
  5461. int res;
  5462. Py_ssize_t len;
  5463. Py_ssize_t i;
  5464. if (!PyList_Check(tmp)) {
  5465. PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5466. goto failed;
  5467. }
  5468. len = PyList_GET_SIZE(tmp);
  5469. values = _Py_asdl_seq_new(len, arena);
  5470. if (values == NULL) goto failed;
  5471. for (i = 0; i < len; i++) {
  5472. expr_ty val;
  5473. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  5474. if (res != 0) goto failed;
  5475. if (len != PyList_GET_SIZE(tmp)) {
  5476. PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
  5477. goto failed;
  5478. }
  5479. asdl_seq_SET(values, i, val);
  5480. }
  5481. Py_CLEAR(tmp);
  5482. }
  5483. *out = BoolOp(op, values, lineno, col_offset, arena);
  5484. if (*out == NULL) goto failed;
  5485. return 0;
  5486. }
  5487. isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);
  5488. if (isinstance == -1) {
  5489. return 1;
  5490. }
  5491. if (isinstance) {
  5492. expr_ty left;
  5493. operator_ty op;
  5494. expr_ty right;
  5495. if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) {
  5496. return 1;
  5497. }
  5498. if (tmp == NULL) {
  5499. PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
  5500. return 1;
  5501. }
  5502. else {
  5503. int res;
  5504. res = obj2ast_expr(tmp, &left, arena);
  5505. if (res != 0) goto failed;
  5506. Py_CLEAR(tmp);
  5507. }
  5508. if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) {
  5509. return 1;
  5510. }
  5511. if (tmp == NULL) {
  5512. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
  5513. return 1;
  5514. }
  5515. else {
  5516. int res;
  5517. res = obj2ast_operator(tmp, &op, arena);
  5518. if (res != 0) goto failed;
  5519. Py_CLEAR(tmp);
  5520. }
  5521. if (_PyObject_LookupAttrId(obj, &PyId_right, &tmp) < 0) {
  5522. return 1;
  5523. }
  5524. if (tmp == NULL) {
  5525. PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
  5526. return 1;
  5527. }
  5528. else {
  5529. int res;
  5530. res = obj2ast_expr(tmp, &right, arena);
  5531. if (res != 0) goto failed;
  5532. Py_CLEAR(tmp);
  5533. }
  5534. *out = BinOp(left, op, right, lineno, col_offset, arena);
  5535. if (*out == NULL) goto failed;
  5536. return 0;
  5537. }
  5538. isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);
  5539. if (isinstance == -1) {
  5540. return 1;
  5541. }
  5542. if (isinstance) {
  5543. unaryop_ty op;
  5544. expr_ty operand;
  5545. if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) {
  5546. return 1;
  5547. }
  5548. if (tmp == NULL) {
  5549. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
  5550. return 1;
  5551. }
  5552. else {
  5553. int res;
  5554. res = obj2ast_unaryop(tmp, &op, arena);
  5555. if (res != 0) goto failed;
  5556. Py_CLEAR(tmp);
  5557. }
  5558. if (_PyObject_LookupAttrId(obj, &PyId_operand, &tmp) < 0) {
  5559. return 1;
  5560. }
  5561. if (tmp == NULL) {
  5562. PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
  5563. return 1;
  5564. }
  5565. else {
  5566. int res;
  5567. res = obj2ast_expr(tmp, &operand, arena);
  5568. if (res != 0) goto failed;
  5569. Py_CLEAR(tmp);
  5570. }
  5571. *out = UnaryOp(op, operand, lineno, col_offset, arena);
  5572. if (*out == NULL) goto failed;
  5573. return 0;
  5574. }
  5575. isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);
  5576. if (isinstance == -1) {
  5577. return 1;
  5578. }
  5579. if (isinstance) {
  5580. arguments_ty args;
  5581. expr_ty body;
  5582. if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
  5583. return 1;
  5584. }
  5585. if (tmp == NULL) {
  5586. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
  5587. return 1;
  5588. }
  5589. else {
  5590. int res;
  5591. res = obj2ast_arguments(tmp, &args, arena);
  5592. if (res != 0) goto failed;
  5593. Py_CLEAR(tmp);
  5594. }
  5595. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  5596. return 1;
  5597. }
  5598. if (tmp == NULL) {
  5599. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
  5600. return 1;
  5601. }
  5602. else {
  5603. int res;
  5604. res = obj2ast_expr(tmp, &body, arena);
  5605. if (res != 0) goto failed;
  5606. Py_CLEAR(tmp);
  5607. }
  5608. *out = Lambda(args, body, lineno, col_offset, arena);
  5609. if (*out == NULL) goto failed;
  5610. return 0;
  5611. }
  5612. isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);
  5613. if (isinstance == -1) {
  5614. return 1;
  5615. }
  5616. if (isinstance) {
  5617. expr_ty test;
  5618. expr_ty body;
  5619. expr_ty orelse;
  5620. if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) {
  5621. return 1;
  5622. }
  5623. if (tmp == NULL) {
  5624. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
  5625. return 1;
  5626. }
  5627. else {
  5628. int res;
  5629. res = obj2ast_expr(tmp, &test, arena);
  5630. if (res != 0) goto failed;
  5631. Py_CLEAR(tmp);
  5632. }
  5633. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  5634. return 1;
  5635. }
  5636. if (tmp == NULL) {
  5637. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
  5638. return 1;
  5639. }
  5640. else {
  5641. int res;
  5642. res = obj2ast_expr(tmp, &body, arena);
  5643. if (res != 0) goto failed;
  5644. Py_CLEAR(tmp);
  5645. }
  5646. if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
  5647. return 1;
  5648. }
  5649. if (tmp == NULL) {
  5650. PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
  5651. return 1;
  5652. }
  5653. else {
  5654. int res;
  5655. res = obj2ast_expr(tmp, &orelse, arena);
  5656. if (res != 0) goto failed;
  5657. Py_CLEAR(tmp);
  5658. }
  5659. *out = IfExp(test, body, orelse, lineno, col_offset, arena);
  5660. if (*out == NULL) goto failed;
  5661. return 0;
  5662. }
  5663. isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);
  5664. if (isinstance == -1) {
  5665. return 1;
  5666. }
  5667. if (isinstance) {
  5668. asdl_seq* keys;
  5669. asdl_seq* values;
  5670. if (_PyObject_LookupAttrId(obj, &PyId_keys, &tmp) < 0) {
  5671. return 1;
  5672. }
  5673. if (tmp == NULL) {
  5674. PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
  5675. return 1;
  5676. }
  5677. else {
  5678. int res;
  5679. Py_ssize_t len;
  5680. Py_ssize_t i;
  5681. if (!PyList_Check(tmp)) {
  5682. PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5683. goto failed;
  5684. }
  5685. len = PyList_GET_SIZE(tmp);
  5686. keys = _Py_asdl_seq_new(len, arena);
  5687. if (keys == NULL) goto failed;
  5688. for (i = 0; i < len; i++) {
  5689. expr_ty val;
  5690. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  5691. if (res != 0) goto failed;
  5692. if (len != PyList_GET_SIZE(tmp)) {
  5693. PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
  5694. goto failed;
  5695. }
  5696. asdl_seq_SET(keys, i, val);
  5697. }
  5698. Py_CLEAR(tmp);
  5699. }
  5700. if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) {
  5701. return 1;
  5702. }
  5703. if (tmp == NULL) {
  5704. PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
  5705. return 1;
  5706. }
  5707. else {
  5708. int res;
  5709. Py_ssize_t len;
  5710. Py_ssize_t i;
  5711. if (!PyList_Check(tmp)) {
  5712. PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5713. goto failed;
  5714. }
  5715. len = PyList_GET_SIZE(tmp);
  5716. values = _Py_asdl_seq_new(len, arena);
  5717. if (values == NULL) goto failed;
  5718. for (i = 0; i < len; i++) {
  5719. expr_ty val;
  5720. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  5721. if (res != 0) goto failed;
  5722. if (len != PyList_GET_SIZE(tmp)) {
  5723. PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
  5724. goto failed;
  5725. }
  5726. asdl_seq_SET(values, i, val);
  5727. }
  5728. Py_CLEAR(tmp);
  5729. }
  5730. *out = Dict(keys, values, lineno, col_offset, arena);
  5731. if (*out == NULL) goto failed;
  5732. return 0;
  5733. }
  5734. isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);
  5735. if (isinstance == -1) {
  5736. return 1;
  5737. }
  5738. if (isinstance) {
  5739. asdl_seq* elts;
  5740. if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) {
  5741. return 1;
  5742. }
  5743. if (tmp == NULL) {
  5744. PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
  5745. return 1;
  5746. }
  5747. else {
  5748. int res;
  5749. Py_ssize_t len;
  5750. Py_ssize_t i;
  5751. if (!PyList_Check(tmp)) {
  5752. PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5753. goto failed;
  5754. }
  5755. len = PyList_GET_SIZE(tmp);
  5756. elts = _Py_asdl_seq_new(len, arena);
  5757. if (elts == NULL) goto failed;
  5758. for (i = 0; i < len; i++) {
  5759. expr_ty val;
  5760. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  5761. if (res != 0) goto failed;
  5762. if (len != PyList_GET_SIZE(tmp)) {
  5763. PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
  5764. goto failed;
  5765. }
  5766. asdl_seq_SET(elts, i, val);
  5767. }
  5768. Py_CLEAR(tmp);
  5769. }
  5770. *out = Set(elts, lineno, col_offset, arena);
  5771. if (*out == NULL) goto failed;
  5772. return 0;
  5773. }
  5774. isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);
  5775. if (isinstance == -1) {
  5776. return 1;
  5777. }
  5778. if (isinstance) {
  5779. expr_ty elt;
  5780. asdl_seq* generators;
  5781. if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) {
  5782. return 1;
  5783. }
  5784. if (tmp == NULL) {
  5785. PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
  5786. return 1;
  5787. }
  5788. else {
  5789. int res;
  5790. res = obj2ast_expr(tmp, &elt, arena);
  5791. if (res != 0) goto failed;
  5792. Py_CLEAR(tmp);
  5793. }
  5794. if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) {
  5795. return 1;
  5796. }
  5797. if (tmp == NULL) {
  5798. PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
  5799. return 1;
  5800. }
  5801. else {
  5802. int res;
  5803. Py_ssize_t len;
  5804. Py_ssize_t i;
  5805. if (!PyList_Check(tmp)) {
  5806. PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5807. goto failed;
  5808. }
  5809. len = PyList_GET_SIZE(tmp);
  5810. generators = _Py_asdl_seq_new(len, arena);
  5811. if (generators == NULL) goto failed;
  5812. for (i = 0; i < len; i++) {
  5813. comprehension_ty val;
  5814. res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
  5815. if (res != 0) goto failed;
  5816. if (len != PyList_GET_SIZE(tmp)) {
  5817. PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
  5818. goto failed;
  5819. }
  5820. asdl_seq_SET(generators, i, val);
  5821. }
  5822. Py_CLEAR(tmp);
  5823. }
  5824. *out = ListComp(elt, generators, lineno, col_offset, arena);
  5825. if (*out == NULL) goto failed;
  5826. return 0;
  5827. }
  5828. isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);
  5829. if (isinstance == -1) {
  5830. return 1;
  5831. }
  5832. if (isinstance) {
  5833. expr_ty elt;
  5834. asdl_seq* generators;
  5835. if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) {
  5836. return 1;
  5837. }
  5838. if (tmp == NULL) {
  5839. PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
  5840. return 1;
  5841. }
  5842. else {
  5843. int res;
  5844. res = obj2ast_expr(tmp, &elt, arena);
  5845. if (res != 0) goto failed;
  5846. Py_CLEAR(tmp);
  5847. }
  5848. if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) {
  5849. return 1;
  5850. }
  5851. if (tmp == NULL) {
  5852. PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
  5853. return 1;
  5854. }
  5855. else {
  5856. int res;
  5857. Py_ssize_t len;
  5858. Py_ssize_t i;
  5859. if (!PyList_Check(tmp)) {
  5860. PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5861. goto failed;
  5862. }
  5863. len = PyList_GET_SIZE(tmp);
  5864. generators = _Py_asdl_seq_new(len, arena);
  5865. if (generators == NULL) goto failed;
  5866. for (i = 0; i < len; i++) {
  5867. comprehension_ty val;
  5868. res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
  5869. if (res != 0) goto failed;
  5870. if (len != PyList_GET_SIZE(tmp)) {
  5871. PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
  5872. goto failed;
  5873. }
  5874. asdl_seq_SET(generators, i, val);
  5875. }
  5876. Py_CLEAR(tmp);
  5877. }
  5878. *out = SetComp(elt, generators, lineno, col_offset, arena);
  5879. if (*out == NULL) goto failed;
  5880. return 0;
  5881. }
  5882. isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);
  5883. if (isinstance == -1) {
  5884. return 1;
  5885. }
  5886. if (isinstance) {
  5887. expr_ty key;
  5888. expr_ty value;
  5889. asdl_seq* generators;
  5890. if (_PyObject_LookupAttrId(obj, &PyId_key, &tmp) < 0) {
  5891. return 1;
  5892. }
  5893. if (tmp == NULL) {
  5894. PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
  5895. return 1;
  5896. }
  5897. else {
  5898. int res;
  5899. res = obj2ast_expr(tmp, &key, arena);
  5900. if (res != 0) goto failed;
  5901. Py_CLEAR(tmp);
  5902. }
  5903. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  5904. return 1;
  5905. }
  5906. if (tmp == NULL) {
  5907. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
  5908. return 1;
  5909. }
  5910. else {
  5911. int res;
  5912. res = obj2ast_expr(tmp, &value, arena);
  5913. if (res != 0) goto failed;
  5914. Py_CLEAR(tmp);
  5915. }
  5916. if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) {
  5917. return 1;
  5918. }
  5919. if (tmp == NULL) {
  5920. PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
  5921. return 1;
  5922. }
  5923. else {
  5924. int res;
  5925. Py_ssize_t len;
  5926. Py_ssize_t i;
  5927. if (!PyList_Check(tmp)) {
  5928. PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5929. goto failed;
  5930. }
  5931. len = PyList_GET_SIZE(tmp);
  5932. generators = _Py_asdl_seq_new(len, arena);
  5933. if (generators == NULL) goto failed;
  5934. for (i = 0; i < len; i++) {
  5935. comprehension_ty val;
  5936. res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
  5937. if (res != 0) goto failed;
  5938. if (len != PyList_GET_SIZE(tmp)) {
  5939. PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
  5940. goto failed;
  5941. }
  5942. asdl_seq_SET(generators, i, val);
  5943. }
  5944. Py_CLEAR(tmp);
  5945. }
  5946. *out = DictComp(key, value, generators, lineno, col_offset, arena);
  5947. if (*out == NULL) goto failed;
  5948. return 0;
  5949. }
  5950. isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);
  5951. if (isinstance == -1) {
  5952. return 1;
  5953. }
  5954. if (isinstance) {
  5955. expr_ty elt;
  5956. asdl_seq* generators;
  5957. if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) {
  5958. return 1;
  5959. }
  5960. if (tmp == NULL) {
  5961. PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
  5962. return 1;
  5963. }
  5964. else {
  5965. int res;
  5966. res = obj2ast_expr(tmp, &elt, arena);
  5967. if (res != 0) goto failed;
  5968. Py_CLEAR(tmp);
  5969. }
  5970. if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) {
  5971. return 1;
  5972. }
  5973. if (tmp == NULL) {
  5974. PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
  5975. return 1;
  5976. }
  5977. else {
  5978. int res;
  5979. Py_ssize_t len;
  5980. Py_ssize_t i;
  5981. if (!PyList_Check(tmp)) {
  5982. PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  5983. goto failed;
  5984. }
  5985. len = PyList_GET_SIZE(tmp);
  5986. generators = _Py_asdl_seq_new(len, arena);
  5987. if (generators == NULL) goto failed;
  5988. for (i = 0; i < len; i++) {
  5989. comprehension_ty val;
  5990. res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
  5991. if (res != 0) goto failed;
  5992. if (len != PyList_GET_SIZE(tmp)) {
  5993. PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
  5994. goto failed;
  5995. }
  5996. asdl_seq_SET(generators, i, val);
  5997. }
  5998. Py_CLEAR(tmp);
  5999. }
  6000. *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
  6001. if (*out == NULL) goto failed;
  6002. return 0;
  6003. }
  6004. isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type);
  6005. if (isinstance == -1) {
  6006. return 1;
  6007. }
  6008. if (isinstance) {
  6009. expr_ty value;
  6010. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  6011. return 1;
  6012. }
  6013. if (tmp == NULL) {
  6014. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
  6015. return 1;
  6016. }
  6017. else {
  6018. int res;
  6019. res = obj2ast_expr(tmp, &value, arena);
  6020. if (res != 0) goto failed;
  6021. Py_CLEAR(tmp);
  6022. }
  6023. *out = Await(value, lineno, col_offset, arena);
  6024. if (*out == NULL) goto failed;
  6025. return 0;
  6026. }
  6027. isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
  6028. if (isinstance == -1) {
  6029. return 1;
  6030. }
  6031. if (isinstance) {
  6032. expr_ty value;
  6033. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  6034. return 1;
  6035. }
  6036. if (tmp == NULL || tmp == Py_None) {
  6037. Py_CLEAR(tmp);
  6038. value = NULL;
  6039. }
  6040. else {
  6041. int res;
  6042. res = obj2ast_expr(tmp, &value, arena);
  6043. if (res != 0) goto failed;
  6044. Py_CLEAR(tmp);
  6045. }
  6046. *out = Yield(value, lineno, col_offset, arena);
  6047. if (*out == NULL) goto failed;
  6048. return 0;
  6049. }
  6050. isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type);
  6051. if (isinstance == -1) {
  6052. return 1;
  6053. }
  6054. if (isinstance) {
  6055. expr_ty value;
  6056. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  6057. return 1;
  6058. }
  6059. if (tmp == NULL) {
  6060. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
  6061. return 1;
  6062. }
  6063. else {
  6064. int res;
  6065. res = obj2ast_expr(tmp, &value, arena);
  6066. if (res != 0) goto failed;
  6067. Py_CLEAR(tmp);
  6068. }
  6069. *out = YieldFrom(value, lineno, col_offset, arena);
  6070. if (*out == NULL) goto failed;
  6071. return 0;
  6072. }
  6073. isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
  6074. if (isinstance == -1) {
  6075. return 1;
  6076. }
  6077. if (isinstance) {
  6078. expr_ty left;
  6079. asdl_int_seq* ops;
  6080. asdl_seq* comparators;
  6081. if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) {
  6082. return 1;
  6083. }
  6084. if (tmp == NULL) {
  6085. PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
  6086. return 1;
  6087. }
  6088. else {
  6089. int res;
  6090. res = obj2ast_expr(tmp, &left, arena);
  6091. if (res != 0) goto failed;
  6092. Py_CLEAR(tmp);
  6093. }
  6094. if (_PyObject_LookupAttrId(obj, &PyId_ops, &tmp) < 0) {
  6095. return 1;
  6096. }
  6097. if (tmp == NULL) {
  6098. PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
  6099. return 1;
  6100. }
  6101. else {
  6102. int res;
  6103. Py_ssize_t len;
  6104. Py_ssize_t i;
  6105. if (!PyList_Check(tmp)) {
  6106. PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  6107. goto failed;
  6108. }
  6109. len = PyList_GET_SIZE(tmp);
  6110. ops = _Py_asdl_int_seq_new(len, arena);
  6111. if (ops == NULL) goto failed;
  6112. for (i = 0; i < len; i++) {
  6113. cmpop_ty val;
  6114. res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena);
  6115. if (res != 0) goto failed;
  6116. if (len != PyList_GET_SIZE(tmp)) {
  6117. PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
  6118. goto failed;
  6119. }
  6120. asdl_seq_SET(ops, i, val);
  6121. }
  6122. Py_CLEAR(tmp);
  6123. }
  6124. if (_PyObject_LookupAttrId(obj, &PyId_comparators, &tmp) < 0) {
  6125. return 1;
  6126. }
  6127. if (tmp == NULL) {
  6128. PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
  6129. return 1;
  6130. }
  6131. else {
  6132. int res;
  6133. Py_ssize_t len;
  6134. Py_ssize_t i;
  6135. if (!PyList_Check(tmp)) {
  6136. PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  6137. goto failed;
  6138. }
  6139. len = PyList_GET_SIZE(tmp);
  6140. comparators = _Py_asdl_seq_new(len, arena);
  6141. if (comparators == NULL) goto failed;
  6142. for (i = 0; i < len; i++) {
  6143. expr_ty val;
  6144. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  6145. if (res != 0) goto failed;
  6146. if (len != PyList_GET_SIZE(tmp)) {
  6147. PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
  6148. goto failed;
  6149. }
  6150. asdl_seq_SET(comparators, i, val);
  6151. }
  6152. Py_CLEAR(tmp);
  6153. }
  6154. *out = Compare(left, ops, comparators, lineno, col_offset, arena);
  6155. if (*out == NULL) goto failed;
  6156. return 0;
  6157. }
  6158. isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);
  6159. if (isinstance == -1) {
  6160. return 1;
  6161. }
  6162. if (isinstance) {
  6163. expr_ty func;
  6164. asdl_seq* args;
  6165. asdl_seq* keywords;
  6166. if (_PyObject_LookupAttrId(obj, &PyId_func, &tmp) < 0) {
  6167. return 1;
  6168. }
  6169. if (tmp == NULL) {
  6170. PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
  6171. return 1;
  6172. }
  6173. else {
  6174. int res;
  6175. res = obj2ast_expr(tmp, &func, arena);
  6176. if (res != 0) goto failed;
  6177. Py_CLEAR(tmp);
  6178. }
  6179. if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
  6180. return 1;
  6181. }
  6182. if (tmp == NULL) {
  6183. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
  6184. return 1;
  6185. }
  6186. else {
  6187. int res;
  6188. Py_ssize_t len;
  6189. Py_ssize_t i;
  6190. if (!PyList_Check(tmp)) {
  6191. PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  6192. goto failed;
  6193. }
  6194. len = PyList_GET_SIZE(tmp);
  6195. args = _Py_asdl_seq_new(len, arena);
  6196. if (args == NULL) goto failed;
  6197. for (i = 0; i < len; i++) {
  6198. expr_ty val;
  6199. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  6200. if (res != 0) goto failed;
  6201. if (len != PyList_GET_SIZE(tmp)) {
  6202. PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
  6203. goto failed;
  6204. }
  6205. asdl_seq_SET(args, i, val);
  6206. }
  6207. Py_CLEAR(tmp);
  6208. }
  6209. if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) {
  6210. return 1;
  6211. }
  6212. if (tmp == NULL) {
  6213. PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
  6214. return 1;
  6215. }
  6216. else {
  6217. int res;
  6218. Py_ssize_t len;
  6219. Py_ssize_t i;
  6220. if (!PyList_Check(tmp)) {
  6221. PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  6222. goto failed;
  6223. }
  6224. len = PyList_GET_SIZE(tmp);
  6225. keywords = _Py_asdl_seq_new(len, arena);
  6226. if (keywords == NULL) goto failed;
  6227. for (i = 0; i < len; i++) {
  6228. keyword_ty val;
  6229. res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena);
  6230. if (res != 0) goto failed;
  6231. if (len != PyList_GET_SIZE(tmp)) {
  6232. PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
  6233. goto failed;
  6234. }
  6235. asdl_seq_SET(keywords, i, val);
  6236. }
  6237. Py_CLEAR(tmp);
  6238. }
  6239. *out = Call(func, args, keywords, lineno, col_offset, arena);
  6240. if (*out == NULL) goto failed;
  6241. return 0;
  6242. }
  6243. isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type);
  6244. if (isinstance == -1) {
  6245. return 1;
  6246. }
  6247. if (isinstance) {
  6248. expr_ty value;
  6249. int conversion;
  6250. expr_ty format_spec;
  6251. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  6252. return 1;
  6253. }
  6254. if (tmp == NULL) {
  6255. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
  6256. return 1;
  6257. }
  6258. else {
  6259. int res;
  6260. res = obj2ast_expr(tmp, &value, arena);
  6261. if (res != 0) goto failed;
  6262. Py_CLEAR(tmp);
  6263. }
  6264. if (_PyObject_LookupAttrId(obj, &PyId_conversion, &tmp) < 0) {
  6265. return 1;
  6266. }
  6267. if (tmp == NULL || tmp == Py_None) {
  6268. Py_CLEAR(tmp);
  6269. conversion = 0;
  6270. }
  6271. else {
  6272. int res;
  6273. res = obj2ast_int(tmp, &conversion, arena);
  6274. if (res != 0) goto failed;
  6275. Py_CLEAR(tmp);
  6276. }
  6277. if (_PyObject_LookupAttrId(obj, &PyId_format_spec, &tmp) < 0) {
  6278. return 1;
  6279. }
  6280. if (tmp == NULL || tmp == Py_None) {
  6281. Py_CLEAR(tmp);
  6282. format_spec = NULL;
  6283. }
  6284. else {
  6285. int res;
  6286. res = obj2ast_expr(tmp, &format_spec, arena);
  6287. if (res != 0) goto failed;
  6288. Py_CLEAR(tmp);
  6289. }
  6290. *out = FormattedValue(value, conversion, format_spec, lineno,
  6291. col_offset, arena);
  6292. if (*out == NULL) goto failed;
  6293. return 0;
  6294. }
  6295. isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type);
  6296. if (isinstance == -1) {
  6297. return 1;
  6298. }
  6299. if (isinstance) {
  6300. asdl_seq* values;
  6301. if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) {
  6302. return 1;
  6303. }
  6304. if (tmp == NULL) {
  6305. PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
  6306. return 1;
  6307. }
  6308. else {
  6309. int res;
  6310. Py_ssize_t len;
  6311. Py_ssize_t i;
  6312. if (!PyList_Check(tmp)) {
  6313. PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  6314. goto failed;
  6315. }
  6316. len = PyList_GET_SIZE(tmp);
  6317. values = _Py_asdl_seq_new(len, arena);
  6318. if (values == NULL) goto failed;
  6319. for (i = 0; i < len; i++) {
  6320. expr_ty val;
  6321. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  6322. if (res != 0) goto failed;
  6323. if (len != PyList_GET_SIZE(tmp)) {
  6324. PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
  6325. goto failed;
  6326. }
  6327. asdl_seq_SET(values, i, val);
  6328. }
  6329. Py_CLEAR(tmp);
  6330. }
  6331. *out = JoinedStr(values, lineno, col_offset, arena);
  6332. if (*out == NULL) goto failed;
  6333. return 0;
  6334. }
  6335. isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type);
  6336. if (isinstance == -1) {
  6337. return 1;
  6338. }
  6339. if (isinstance) {
  6340. constant value;
  6341. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  6342. return 1;
  6343. }
  6344. if (tmp == NULL) {
  6345. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
  6346. return 1;
  6347. }
  6348. else {
  6349. int res;
  6350. res = obj2ast_constant(tmp, &value, arena);
  6351. if (res != 0) goto failed;
  6352. Py_CLEAR(tmp);
  6353. }
  6354. *out = Constant(value, lineno, col_offset, arena);
  6355. if (*out == NULL) goto failed;
  6356. return 0;
  6357. }
  6358. isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);
  6359. if (isinstance == -1) {
  6360. return 1;
  6361. }
  6362. if (isinstance) {
  6363. expr_ty value;
  6364. identifier attr;
  6365. expr_context_ty ctx;
  6366. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  6367. return 1;
  6368. }
  6369. if (tmp == NULL) {
  6370. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
  6371. return 1;
  6372. }
  6373. else {
  6374. int res;
  6375. res = obj2ast_expr(tmp, &value, arena);
  6376. if (res != 0) goto failed;
  6377. Py_CLEAR(tmp);
  6378. }
  6379. if (_PyObject_LookupAttrId(obj, &PyId_attr, &tmp) < 0) {
  6380. return 1;
  6381. }
  6382. if (tmp == NULL) {
  6383. PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
  6384. return 1;
  6385. }
  6386. else {
  6387. int res;
  6388. res = obj2ast_identifier(tmp, &attr, arena);
  6389. if (res != 0) goto failed;
  6390. Py_CLEAR(tmp);
  6391. }
  6392. if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
  6393. return 1;
  6394. }
  6395. if (tmp == NULL) {
  6396. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
  6397. return 1;
  6398. }
  6399. else {
  6400. int res;
  6401. res = obj2ast_expr_context(tmp, &ctx, arena);
  6402. if (res != 0) goto failed;
  6403. Py_CLEAR(tmp);
  6404. }
  6405. *out = Attribute(value, attr, ctx, lineno, col_offset, arena);
  6406. if (*out == NULL) goto failed;
  6407. return 0;
  6408. }
  6409. isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);
  6410. if (isinstance == -1) {
  6411. return 1;
  6412. }
  6413. if (isinstance) {
  6414. expr_ty value;
  6415. slice_ty slice;
  6416. expr_context_ty ctx;
  6417. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  6418. return 1;
  6419. }
  6420. if (tmp == NULL) {
  6421. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
  6422. return 1;
  6423. }
  6424. else {
  6425. int res;
  6426. res = obj2ast_expr(tmp, &value, arena);
  6427. if (res != 0) goto failed;
  6428. Py_CLEAR(tmp);
  6429. }
  6430. if (_PyObject_LookupAttrId(obj, &PyId_slice, &tmp) < 0) {
  6431. return 1;
  6432. }
  6433. if (tmp == NULL) {
  6434. PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
  6435. return 1;
  6436. }
  6437. else {
  6438. int res;
  6439. res = obj2ast_slice(tmp, &slice, arena);
  6440. if (res != 0) goto failed;
  6441. Py_CLEAR(tmp);
  6442. }
  6443. if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
  6444. return 1;
  6445. }
  6446. if (tmp == NULL) {
  6447. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
  6448. return 1;
  6449. }
  6450. else {
  6451. int res;
  6452. res = obj2ast_expr_context(tmp, &ctx, arena);
  6453. if (res != 0) goto failed;
  6454. Py_CLEAR(tmp);
  6455. }
  6456. *out = Subscript(value, slice, ctx, lineno, col_offset, arena);
  6457. if (*out == NULL) goto failed;
  6458. return 0;
  6459. }
  6460. isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type);
  6461. if (isinstance == -1) {
  6462. return 1;
  6463. }
  6464. if (isinstance) {
  6465. expr_ty value;
  6466. expr_context_ty ctx;
  6467. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  6468. return 1;
  6469. }
  6470. if (tmp == NULL) {
  6471. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
  6472. return 1;
  6473. }
  6474. else {
  6475. int res;
  6476. res = obj2ast_expr(tmp, &value, arena);
  6477. if (res != 0) goto failed;
  6478. Py_CLEAR(tmp);
  6479. }
  6480. if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
  6481. return 1;
  6482. }
  6483. if (tmp == NULL) {
  6484. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
  6485. return 1;
  6486. }
  6487. else {
  6488. int res;
  6489. res = obj2ast_expr_context(tmp, &ctx, arena);
  6490. if (res != 0) goto failed;
  6491. Py_CLEAR(tmp);
  6492. }
  6493. *out = Starred(value, ctx, lineno, col_offset, arena);
  6494. if (*out == NULL) goto failed;
  6495. return 0;
  6496. }
  6497. isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);
  6498. if (isinstance == -1) {
  6499. return 1;
  6500. }
  6501. if (isinstance) {
  6502. identifier id;
  6503. expr_context_ty ctx;
  6504. if (_PyObject_LookupAttrId(obj, &PyId_id, &tmp) < 0) {
  6505. return 1;
  6506. }
  6507. if (tmp == NULL) {
  6508. PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
  6509. return 1;
  6510. }
  6511. else {
  6512. int res;
  6513. res = obj2ast_identifier(tmp, &id, arena);
  6514. if (res != 0) goto failed;
  6515. Py_CLEAR(tmp);
  6516. }
  6517. if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
  6518. return 1;
  6519. }
  6520. if (tmp == NULL) {
  6521. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
  6522. return 1;
  6523. }
  6524. else {
  6525. int res;
  6526. res = obj2ast_expr_context(tmp, &ctx, arena);
  6527. if (res != 0) goto failed;
  6528. Py_CLEAR(tmp);
  6529. }
  6530. *out = Name(id, ctx, lineno, col_offset, arena);
  6531. if (*out == NULL) goto failed;
  6532. return 0;
  6533. }
  6534. isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);
  6535. if (isinstance == -1) {
  6536. return 1;
  6537. }
  6538. if (isinstance) {
  6539. asdl_seq* elts;
  6540. expr_context_ty ctx;
  6541. if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) {
  6542. return 1;
  6543. }
  6544. if (tmp == NULL) {
  6545. PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
  6546. return 1;
  6547. }
  6548. else {
  6549. int res;
  6550. Py_ssize_t len;
  6551. Py_ssize_t i;
  6552. if (!PyList_Check(tmp)) {
  6553. PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  6554. goto failed;
  6555. }
  6556. len = PyList_GET_SIZE(tmp);
  6557. elts = _Py_asdl_seq_new(len, arena);
  6558. if (elts == NULL) goto failed;
  6559. for (i = 0; i < len; i++) {
  6560. expr_ty val;
  6561. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  6562. if (res != 0) goto failed;
  6563. if (len != PyList_GET_SIZE(tmp)) {
  6564. PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
  6565. goto failed;
  6566. }
  6567. asdl_seq_SET(elts, i, val);
  6568. }
  6569. Py_CLEAR(tmp);
  6570. }
  6571. if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
  6572. return 1;
  6573. }
  6574. if (tmp == NULL) {
  6575. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
  6576. return 1;
  6577. }
  6578. else {
  6579. int res;
  6580. res = obj2ast_expr_context(tmp, &ctx, arena);
  6581. if (res != 0) goto failed;
  6582. Py_CLEAR(tmp);
  6583. }
  6584. *out = List(elts, ctx, lineno, col_offset, arena);
  6585. if (*out == NULL) goto failed;
  6586. return 0;
  6587. }
  6588. isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);
  6589. if (isinstance == -1) {
  6590. return 1;
  6591. }
  6592. if (isinstance) {
  6593. asdl_seq* elts;
  6594. expr_context_ty ctx;
  6595. if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) {
  6596. return 1;
  6597. }
  6598. if (tmp == NULL) {
  6599. PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
  6600. return 1;
  6601. }
  6602. else {
  6603. int res;
  6604. Py_ssize_t len;
  6605. Py_ssize_t i;
  6606. if (!PyList_Check(tmp)) {
  6607. PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  6608. goto failed;
  6609. }
  6610. len = PyList_GET_SIZE(tmp);
  6611. elts = _Py_asdl_seq_new(len, arena);
  6612. if (elts == NULL) goto failed;
  6613. for (i = 0; i < len; i++) {
  6614. expr_ty val;
  6615. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  6616. if (res != 0) goto failed;
  6617. if (len != PyList_GET_SIZE(tmp)) {
  6618. PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
  6619. goto failed;
  6620. }
  6621. asdl_seq_SET(elts, i, val);
  6622. }
  6623. Py_CLEAR(tmp);
  6624. }
  6625. if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
  6626. return 1;
  6627. }
  6628. if (tmp == NULL) {
  6629. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
  6630. return 1;
  6631. }
  6632. else {
  6633. int res;
  6634. res = obj2ast_expr_context(tmp, &ctx, arena);
  6635. if (res != 0) goto failed;
  6636. Py_CLEAR(tmp);
  6637. }
  6638. *out = Tuple(elts, ctx, lineno, col_offset, arena);
  6639. if (*out == NULL) goto failed;
  6640. return 0;
  6641. }
  6642. PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
  6643. failed:
  6644. Py_XDECREF(tmp);
  6645. return 1;
  6646. }
  6647. int
  6648. obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
  6649. {
  6650. int isinstance;
  6651. isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
  6652. if (isinstance == -1) {
  6653. return 1;
  6654. }
  6655. if (isinstance) {
  6656. *out = Load;
  6657. return 0;
  6658. }
  6659. isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);
  6660. if (isinstance == -1) {
  6661. return 1;
  6662. }
  6663. if (isinstance) {
  6664. *out = Store;
  6665. return 0;
  6666. }
  6667. isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);
  6668. if (isinstance == -1) {
  6669. return 1;
  6670. }
  6671. if (isinstance) {
  6672. *out = Del;
  6673. return 0;
  6674. }
  6675. isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);
  6676. if (isinstance == -1) {
  6677. return 1;
  6678. }
  6679. if (isinstance) {
  6680. *out = AugLoad;
  6681. return 0;
  6682. }
  6683. isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);
  6684. if (isinstance == -1) {
  6685. return 1;
  6686. }
  6687. if (isinstance) {
  6688. *out = AugStore;
  6689. return 0;
  6690. }
  6691. isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);
  6692. if (isinstance == -1) {
  6693. return 1;
  6694. }
  6695. if (isinstance) {
  6696. *out = Param;
  6697. return 0;
  6698. }
  6699. PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
  6700. return 1;
  6701. }
  6702. int
  6703. obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
  6704. {
  6705. int isinstance;
  6706. PyObject *tmp = NULL;
  6707. if (obj == Py_None) {
  6708. *out = NULL;
  6709. return 0;
  6710. }
  6711. isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);
  6712. if (isinstance == -1) {
  6713. return 1;
  6714. }
  6715. if (isinstance) {
  6716. expr_ty lower;
  6717. expr_ty upper;
  6718. expr_ty step;
  6719. if (_PyObject_LookupAttrId(obj, &PyId_lower, &tmp) < 0) {
  6720. return 1;
  6721. }
  6722. if (tmp == NULL || tmp == Py_None) {
  6723. Py_CLEAR(tmp);
  6724. lower = NULL;
  6725. }
  6726. else {
  6727. int res;
  6728. res = obj2ast_expr(tmp, &lower, arena);
  6729. if (res != 0) goto failed;
  6730. Py_CLEAR(tmp);
  6731. }
  6732. if (_PyObject_LookupAttrId(obj, &PyId_upper, &tmp) < 0) {
  6733. return 1;
  6734. }
  6735. if (tmp == NULL || tmp == Py_None) {
  6736. Py_CLEAR(tmp);
  6737. upper = NULL;
  6738. }
  6739. else {
  6740. int res;
  6741. res = obj2ast_expr(tmp, &upper, arena);
  6742. if (res != 0) goto failed;
  6743. Py_CLEAR(tmp);
  6744. }
  6745. if (_PyObject_LookupAttrId(obj, &PyId_step, &tmp) < 0) {
  6746. return 1;
  6747. }
  6748. if (tmp == NULL || tmp == Py_None) {
  6749. Py_CLEAR(tmp);
  6750. step = NULL;
  6751. }
  6752. else {
  6753. int res;
  6754. res = obj2ast_expr(tmp, &step, arena);
  6755. if (res != 0) goto failed;
  6756. Py_CLEAR(tmp);
  6757. }
  6758. *out = Slice(lower, upper, step, arena);
  6759. if (*out == NULL) goto failed;
  6760. return 0;
  6761. }
  6762. isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);
  6763. if (isinstance == -1) {
  6764. return 1;
  6765. }
  6766. if (isinstance) {
  6767. asdl_seq* dims;
  6768. if (_PyObject_LookupAttrId(obj, &PyId_dims, &tmp) < 0) {
  6769. return 1;
  6770. }
  6771. if (tmp == NULL) {
  6772. PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
  6773. return 1;
  6774. }
  6775. else {
  6776. int res;
  6777. Py_ssize_t len;
  6778. Py_ssize_t i;
  6779. if (!PyList_Check(tmp)) {
  6780. PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  6781. goto failed;
  6782. }
  6783. len = PyList_GET_SIZE(tmp);
  6784. dims = _Py_asdl_seq_new(len, arena);
  6785. if (dims == NULL) goto failed;
  6786. for (i = 0; i < len; i++) {
  6787. slice_ty val;
  6788. res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena);
  6789. if (res != 0) goto failed;
  6790. if (len != PyList_GET_SIZE(tmp)) {
  6791. PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
  6792. goto failed;
  6793. }
  6794. asdl_seq_SET(dims, i, val);
  6795. }
  6796. Py_CLEAR(tmp);
  6797. }
  6798. *out = ExtSlice(dims, arena);
  6799. if (*out == NULL) goto failed;
  6800. return 0;
  6801. }
  6802. isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);
  6803. if (isinstance == -1) {
  6804. return 1;
  6805. }
  6806. if (isinstance) {
  6807. expr_ty value;
  6808. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  6809. return 1;
  6810. }
  6811. if (tmp == NULL) {
  6812. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
  6813. return 1;
  6814. }
  6815. else {
  6816. int res;
  6817. res = obj2ast_expr(tmp, &value, arena);
  6818. if (res != 0) goto failed;
  6819. Py_CLEAR(tmp);
  6820. }
  6821. *out = Index(value, arena);
  6822. if (*out == NULL) goto failed;
  6823. return 0;
  6824. }
  6825. PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
  6826. failed:
  6827. Py_XDECREF(tmp);
  6828. return 1;
  6829. }
  6830. int
  6831. obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
  6832. {
  6833. int isinstance;
  6834. isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
  6835. if (isinstance == -1) {
  6836. return 1;
  6837. }
  6838. if (isinstance) {
  6839. *out = And;
  6840. return 0;
  6841. }
  6842. isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);
  6843. if (isinstance == -1) {
  6844. return 1;
  6845. }
  6846. if (isinstance) {
  6847. *out = Or;
  6848. return 0;
  6849. }
  6850. PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
  6851. return 1;
  6852. }
  6853. int
  6854. obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
  6855. {
  6856. int isinstance;
  6857. isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
  6858. if (isinstance == -1) {
  6859. return 1;
  6860. }
  6861. if (isinstance) {
  6862. *out = Add;
  6863. return 0;
  6864. }
  6865. isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);
  6866. if (isinstance == -1) {
  6867. return 1;
  6868. }
  6869. if (isinstance) {
  6870. *out = Sub;
  6871. return 0;
  6872. }
  6873. isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);
  6874. if (isinstance == -1) {
  6875. return 1;
  6876. }
  6877. if (isinstance) {
  6878. *out = Mult;
  6879. return 0;
  6880. }
  6881. isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type);
  6882. if (isinstance == -1) {
  6883. return 1;
  6884. }
  6885. if (isinstance) {
  6886. *out = MatMult;
  6887. return 0;
  6888. }
  6889. isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);
  6890. if (isinstance == -1) {
  6891. return 1;
  6892. }
  6893. if (isinstance) {
  6894. *out = Div;
  6895. return 0;
  6896. }
  6897. isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);
  6898. if (isinstance == -1) {
  6899. return 1;
  6900. }
  6901. if (isinstance) {
  6902. *out = Mod;
  6903. return 0;
  6904. }
  6905. isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);
  6906. if (isinstance == -1) {
  6907. return 1;
  6908. }
  6909. if (isinstance) {
  6910. *out = Pow;
  6911. return 0;
  6912. }
  6913. isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);
  6914. if (isinstance == -1) {
  6915. return 1;
  6916. }
  6917. if (isinstance) {
  6918. *out = LShift;
  6919. return 0;
  6920. }
  6921. isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);
  6922. if (isinstance == -1) {
  6923. return 1;
  6924. }
  6925. if (isinstance) {
  6926. *out = RShift;
  6927. return 0;
  6928. }
  6929. isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);
  6930. if (isinstance == -1) {
  6931. return 1;
  6932. }
  6933. if (isinstance) {
  6934. *out = BitOr;
  6935. return 0;
  6936. }
  6937. isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);
  6938. if (isinstance == -1) {
  6939. return 1;
  6940. }
  6941. if (isinstance) {
  6942. *out = BitXor;
  6943. return 0;
  6944. }
  6945. isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);
  6946. if (isinstance == -1) {
  6947. return 1;
  6948. }
  6949. if (isinstance) {
  6950. *out = BitAnd;
  6951. return 0;
  6952. }
  6953. isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);
  6954. if (isinstance == -1) {
  6955. return 1;
  6956. }
  6957. if (isinstance) {
  6958. *out = FloorDiv;
  6959. return 0;
  6960. }
  6961. PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
  6962. return 1;
  6963. }
  6964. int
  6965. obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
  6966. {
  6967. int isinstance;
  6968. isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
  6969. if (isinstance == -1) {
  6970. return 1;
  6971. }
  6972. if (isinstance) {
  6973. *out = Invert;
  6974. return 0;
  6975. }
  6976. isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);
  6977. if (isinstance == -1) {
  6978. return 1;
  6979. }
  6980. if (isinstance) {
  6981. *out = Not;
  6982. return 0;
  6983. }
  6984. isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);
  6985. if (isinstance == -1) {
  6986. return 1;
  6987. }
  6988. if (isinstance) {
  6989. *out = UAdd;
  6990. return 0;
  6991. }
  6992. isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);
  6993. if (isinstance == -1) {
  6994. return 1;
  6995. }
  6996. if (isinstance) {
  6997. *out = USub;
  6998. return 0;
  6999. }
  7000. PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
  7001. return 1;
  7002. }
  7003. int
  7004. obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
  7005. {
  7006. int isinstance;
  7007. isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
  7008. if (isinstance == -1) {
  7009. return 1;
  7010. }
  7011. if (isinstance) {
  7012. *out = Eq;
  7013. return 0;
  7014. }
  7015. isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);
  7016. if (isinstance == -1) {
  7017. return 1;
  7018. }
  7019. if (isinstance) {
  7020. *out = NotEq;
  7021. return 0;
  7022. }
  7023. isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);
  7024. if (isinstance == -1) {
  7025. return 1;
  7026. }
  7027. if (isinstance) {
  7028. *out = Lt;
  7029. return 0;
  7030. }
  7031. isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);
  7032. if (isinstance == -1) {
  7033. return 1;
  7034. }
  7035. if (isinstance) {
  7036. *out = LtE;
  7037. return 0;
  7038. }
  7039. isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);
  7040. if (isinstance == -1) {
  7041. return 1;
  7042. }
  7043. if (isinstance) {
  7044. *out = Gt;
  7045. return 0;
  7046. }
  7047. isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);
  7048. if (isinstance == -1) {
  7049. return 1;
  7050. }
  7051. if (isinstance) {
  7052. *out = GtE;
  7053. return 0;
  7054. }
  7055. isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);
  7056. if (isinstance == -1) {
  7057. return 1;
  7058. }
  7059. if (isinstance) {
  7060. *out = Is;
  7061. return 0;
  7062. }
  7063. isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);
  7064. if (isinstance == -1) {
  7065. return 1;
  7066. }
  7067. if (isinstance) {
  7068. *out = IsNot;
  7069. return 0;
  7070. }
  7071. isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);
  7072. if (isinstance == -1) {
  7073. return 1;
  7074. }
  7075. if (isinstance) {
  7076. *out = In;
  7077. return 0;
  7078. }
  7079. isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);
  7080. if (isinstance == -1) {
  7081. return 1;
  7082. }
  7083. if (isinstance) {
  7084. *out = NotIn;
  7085. return 0;
  7086. }
  7087. PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
  7088. return 1;
  7089. }
  7090. int
  7091. obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
  7092. {
  7093. PyObject* tmp = NULL;
  7094. expr_ty target;
  7095. expr_ty iter;
  7096. asdl_seq* ifs;
  7097. int is_async;
  7098. if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
  7099. return 1;
  7100. }
  7101. if (tmp == NULL) {
  7102. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
  7103. return 1;
  7104. }
  7105. else {
  7106. int res;
  7107. res = obj2ast_expr(tmp, &target, arena);
  7108. if (res != 0) goto failed;
  7109. Py_CLEAR(tmp);
  7110. }
  7111. if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) {
  7112. return 1;
  7113. }
  7114. if (tmp == NULL) {
  7115. PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
  7116. return 1;
  7117. }
  7118. else {
  7119. int res;
  7120. res = obj2ast_expr(tmp, &iter, arena);
  7121. if (res != 0) goto failed;
  7122. Py_CLEAR(tmp);
  7123. }
  7124. if (_PyObject_LookupAttrId(obj, &PyId_ifs, &tmp) < 0) {
  7125. return 1;
  7126. }
  7127. if (tmp == NULL) {
  7128. PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
  7129. return 1;
  7130. }
  7131. else {
  7132. int res;
  7133. Py_ssize_t len;
  7134. Py_ssize_t i;
  7135. if (!PyList_Check(tmp)) {
  7136. PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  7137. goto failed;
  7138. }
  7139. len = PyList_GET_SIZE(tmp);
  7140. ifs = _Py_asdl_seq_new(len, arena);
  7141. if (ifs == NULL) goto failed;
  7142. for (i = 0; i < len; i++) {
  7143. expr_ty val;
  7144. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  7145. if (res != 0) goto failed;
  7146. if (len != PyList_GET_SIZE(tmp)) {
  7147. PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
  7148. goto failed;
  7149. }
  7150. asdl_seq_SET(ifs, i, val);
  7151. }
  7152. Py_CLEAR(tmp);
  7153. }
  7154. if (_PyObject_LookupAttrId(obj, &PyId_is_async, &tmp) < 0) {
  7155. return 1;
  7156. }
  7157. if (tmp == NULL) {
  7158. PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
  7159. return 1;
  7160. }
  7161. else {
  7162. int res;
  7163. res = obj2ast_int(tmp, &is_async, arena);
  7164. if (res != 0) goto failed;
  7165. Py_CLEAR(tmp);
  7166. }
  7167. *out = comprehension(target, iter, ifs, is_async, arena);
  7168. return 0;
  7169. failed:
  7170. Py_XDECREF(tmp);
  7171. return 1;
  7172. }
  7173. int
  7174. obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
  7175. {
  7176. int isinstance;
  7177. PyObject *tmp = NULL;
  7178. int lineno;
  7179. int col_offset;
  7180. if (obj == Py_None) {
  7181. *out = NULL;
  7182. return 0;
  7183. }
  7184. if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) {
  7185. return 1;
  7186. }
  7187. if (tmp == NULL) {
  7188. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
  7189. return 1;
  7190. }
  7191. else {
  7192. int res;
  7193. res = obj2ast_int(tmp, &lineno, arena);
  7194. if (res != 0) goto failed;
  7195. Py_CLEAR(tmp);
  7196. }
  7197. if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) {
  7198. return 1;
  7199. }
  7200. if (tmp == NULL) {
  7201. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
  7202. return 1;
  7203. }
  7204. else {
  7205. int res;
  7206. res = obj2ast_int(tmp, &col_offset, arena);
  7207. if (res != 0) goto failed;
  7208. Py_CLEAR(tmp);
  7209. }
  7210. isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);
  7211. if (isinstance == -1) {
  7212. return 1;
  7213. }
  7214. if (isinstance) {
  7215. expr_ty type;
  7216. identifier name;
  7217. asdl_seq* body;
  7218. if (_PyObject_LookupAttrId(obj, &PyId_type, &tmp) < 0) {
  7219. return 1;
  7220. }
  7221. if (tmp == NULL || tmp == Py_None) {
  7222. Py_CLEAR(tmp);
  7223. type = NULL;
  7224. }
  7225. else {
  7226. int res;
  7227. res = obj2ast_expr(tmp, &type, arena);
  7228. if (res != 0) goto failed;
  7229. Py_CLEAR(tmp);
  7230. }
  7231. if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
  7232. return 1;
  7233. }
  7234. if (tmp == NULL || tmp == Py_None) {
  7235. Py_CLEAR(tmp);
  7236. name = NULL;
  7237. }
  7238. else {
  7239. int res;
  7240. res = obj2ast_identifier(tmp, &name, arena);
  7241. if (res != 0) goto failed;
  7242. Py_CLEAR(tmp);
  7243. }
  7244. if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
  7245. return 1;
  7246. }
  7247. if (tmp == NULL) {
  7248. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
  7249. return 1;
  7250. }
  7251. else {
  7252. int res;
  7253. Py_ssize_t len;
  7254. Py_ssize_t i;
  7255. if (!PyList_Check(tmp)) {
  7256. PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  7257. goto failed;
  7258. }
  7259. len = PyList_GET_SIZE(tmp);
  7260. body = _Py_asdl_seq_new(len, arena);
  7261. if (body == NULL) goto failed;
  7262. for (i = 0; i < len; i++) {
  7263. stmt_ty val;
  7264. res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
  7265. if (res != 0) goto failed;
  7266. if (len != PyList_GET_SIZE(tmp)) {
  7267. PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
  7268. goto failed;
  7269. }
  7270. asdl_seq_SET(body, i, val);
  7271. }
  7272. Py_CLEAR(tmp);
  7273. }
  7274. *out = ExceptHandler(type, name, body, lineno, col_offset, arena);
  7275. if (*out == NULL) goto failed;
  7276. return 0;
  7277. }
  7278. PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
  7279. failed:
  7280. Py_XDECREF(tmp);
  7281. return 1;
  7282. }
  7283. int
  7284. obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
  7285. {
  7286. PyObject* tmp = NULL;
  7287. asdl_seq* args;
  7288. arg_ty vararg;
  7289. asdl_seq* kwonlyargs;
  7290. asdl_seq* kw_defaults;
  7291. arg_ty kwarg;
  7292. asdl_seq* defaults;
  7293. if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
  7294. return 1;
  7295. }
  7296. if (tmp == NULL) {
  7297. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
  7298. return 1;
  7299. }
  7300. else {
  7301. int res;
  7302. Py_ssize_t len;
  7303. Py_ssize_t i;
  7304. if (!PyList_Check(tmp)) {
  7305. PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  7306. goto failed;
  7307. }
  7308. len = PyList_GET_SIZE(tmp);
  7309. args = _Py_asdl_seq_new(len, arena);
  7310. if (args == NULL) goto failed;
  7311. for (i = 0; i < len; i++) {
  7312. arg_ty val;
  7313. res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena);
  7314. if (res != 0) goto failed;
  7315. if (len != PyList_GET_SIZE(tmp)) {
  7316. PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
  7317. goto failed;
  7318. }
  7319. asdl_seq_SET(args, i, val);
  7320. }
  7321. Py_CLEAR(tmp);
  7322. }
  7323. if (_PyObject_LookupAttrId(obj, &PyId_vararg, &tmp) < 0) {
  7324. return 1;
  7325. }
  7326. if (tmp == NULL || tmp == Py_None) {
  7327. Py_CLEAR(tmp);
  7328. vararg = NULL;
  7329. }
  7330. else {
  7331. int res;
  7332. res = obj2ast_arg(tmp, &vararg, arena);
  7333. if (res != 0) goto failed;
  7334. Py_CLEAR(tmp);
  7335. }
  7336. if (_PyObject_LookupAttrId(obj, &PyId_kwonlyargs, &tmp) < 0) {
  7337. return 1;
  7338. }
  7339. if (tmp == NULL) {
  7340. PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
  7341. return 1;
  7342. }
  7343. else {
  7344. int res;
  7345. Py_ssize_t len;
  7346. Py_ssize_t i;
  7347. if (!PyList_Check(tmp)) {
  7348. PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  7349. goto failed;
  7350. }
  7351. len = PyList_GET_SIZE(tmp);
  7352. kwonlyargs = _Py_asdl_seq_new(len, arena);
  7353. if (kwonlyargs == NULL) goto failed;
  7354. for (i = 0; i < len; i++) {
  7355. arg_ty val;
  7356. res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena);
  7357. if (res != 0) goto failed;
  7358. if (len != PyList_GET_SIZE(tmp)) {
  7359. PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
  7360. goto failed;
  7361. }
  7362. asdl_seq_SET(kwonlyargs, i, val);
  7363. }
  7364. Py_CLEAR(tmp);
  7365. }
  7366. if (_PyObject_LookupAttrId(obj, &PyId_kw_defaults, &tmp) < 0) {
  7367. return 1;
  7368. }
  7369. if (tmp == NULL) {
  7370. PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
  7371. return 1;
  7372. }
  7373. else {
  7374. int res;
  7375. Py_ssize_t len;
  7376. Py_ssize_t i;
  7377. if (!PyList_Check(tmp)) {
  7378. PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  7379. goto failed;
  7380. }
  7381. len = PyList_GET_SIZE(tmp);
  7382. kw_defaults = _Py_asdl_seq_new(len, arena);
  7383. if (kw_defaults == NULL) goto failed;
  7384. for (i = 0; i < len; i++) {
  7385. expr_ty val;
  7386. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  7387. if (res != 0) goto failed;
  7388. if (len != PyList_GET_SIZE(tmp)) {
  7389. PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
  7390. goto failed;
  7391. }
  7392. asdl_seq_SET(kw_defaults, i, val);
  7393. }
  7394. Py_CLEAR(tmp);
  7395. }
  7396. if (_PyObject_LookupAttrId(obj, &PyId_kwarg, &tmp) < 0) {
  7397. return 1;
  7398. }
  7399. if (tmp == NULL || tmp == Py_None) {
  7400. Py_CLEAR(tmp);
  7401. kwarg = NULL;
  7402. }
  7403. else {
  7404. int res;
  7405. res = obj2ast_arg(tmp, &kwarg, arena);
  7406. if (res != 0) goto failed;
  7407. Py_CLEAR(tmp);
  7408. }
  7409. if (_PyObject_LookupAttrId(obj, &PyId_defaults, &tmp) < 0) {
  7410. return 1;
  7411. }
  7412. if (tmp == NULL) {
  7413. PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
  7414. return 1;
  7415. }
  7416. else {
  7417. int res;
  7418. Py_ssize_t len;
  7419. Py_ssize_t i;
  7420. if (!PyList_Check(tmp)) {
  7421. PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
  7422. goto failed;
  7423. }
  7424. len = PyList_GET_SIZE(tmp);
  7425. defaults = _Py_asdl_seq_new(len, arena);
  7426. if (defaults == NULL) goto failed;
  7427. for (i = 0; i < len; i++) {
  7428. expr_ty val;
  7429. res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
  7430. if (res != 0) goto failed;
  7431. if (len != PyList_GET_SIZE(tmp)) {
  7432. PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
  7433. goto failed;
  7434. }
  7435. asdl_seq_SET(defaults, i, val);
  7436. }
  7437. Py_CLEAR(tmp);
  7438. }
  7439. *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults,
  7440. arena);
  7441. return 0;
  7442. failed:
  7443. Py_XDECREF(tmp);
  7444. return 1;
  7445. }
  7446. int
  7447. obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
  7448. {
  7449. PyObject* tmp = NULL;
  7450. identifier arg;
  7451. expr_ty annotation;
  7452. int lineno;
  7453. int col_offset;
  7454. if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) {
  7455. return 1;
  7456. }
  7457. if (tmp == NULL) {
  7458. PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
  7459. return 1;
  7460. }
  7461. else {
  7462. int res;
  7463. res = obj2ast_identifier(tmp, &arg, arena);
  7464. if (res != 0) goto failed;
  7465. Py_CLEAR(tmp);
  7466. }
  7467. if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) {
  7468. return 1;
  7469. }
  7470. if (tmp == NULL || tmp == Py_None) {
  7471. Py_CLEAR(tmp);
  7472. annotation = NULL;
  7473. }
  7474. else {
  7475. int res;
  7476. res = obj2ast_expr(tmp, &annotation, arena);
  7477. if (res != 0) goto failed;
  7478. Py_CLEAR(tmp);
  7479. }
  7480. if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) {
  7481. return 1;
  7482. }
  7483. if (tmp == NULL) {
  7484. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
  7485. return 1;
  7486. }
  7487. else {
  7488. int res;
  7489. res = obj2ast_int(tmp, &lineno, arena);
  7490. if (res != 0) goto failed;
  7491. Py_CLEAR(tmp);
  7492. }
  7493. if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) {
  7494. return 1;
  7495. }
  7496. if (tmp == NULL) {
  7497. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
  7498. return 1;
  7499. }
  7500. else {
  7501. int res;
  7502. res = obj2ast_int(tmp, &col_offset, arena);
  7503. if (res != 0) goto failed;
  7504. Py_CLEAR(tmp);
  7505. }
  7506. *out = arg(arg, annotation, lineno, col_offset, arena);
  7507. return 0;
  7508. failed:
  7509. Py_XDECREF(tmp);
  7510. return 1;
  7511. }
  7512. int
  7513. obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
  7514. {
  7515. PyObject* tmp = NULL;
  7516. identifier arg;
  7517. expr_ty value;
  7518. if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) {
  7519. return 1;
  7520. }
  7521. if (tmp == NULL || tmp == Py_None) {
  7522. Py_CLEAR(tmp);
  7523. arg = NULL;
  7524. }
  7525. else {
  7526. int res;
  7527. res = obj2ast_identifier(tmp, &arg, arena);
  7528. if (res != 0) goto failed;
  7529. Py_CLEAR(tmp);
  7530. }
  7531. if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
  7532. return 1;
  7533. }
  7534. if (tmp == NULL) {
  7535. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
  7536. return 1;
  7537. }
  7538. else {
  7539. int res;
  7540. res = obj2ast_expr(tmp, &value, arena);
  7541. if (res != 0) goto failed;
  7542. Py_CLEAR(tmp);
  7543. }
  7544. *out = keyword(arg, value, arena);
  7545. return 0;
  7546. failed:
  7547. Py_XDECREF(tmp);
  7548. return 1;
  7549. }
  7550. int
  7551. obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
  7552. {
  7553. PyObject* tmp = NULL;
  7554. identifier name;
  7555. identifier asname;
  7556. if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
  7557. return 1;
  7558. }
  7559. if (tmp == NULL) {
  7560. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
  7561. return 1;
  7562. }
  7563. else {
  7564. int res;
  7565. res = obj2ast_identifier(tmp, &name, arena);
  7566. if (res != 0) goto failed;
  7567. Py_CLEAR(tmp);
  7568. }
  7569. if (_PyObject_LookupAttrId(obj, &PyId_asname, &tmp) < 0) {
  7570. return 1;
  7571. }
  7572. if (tmp == NULL || tmp == Py_None) {
  7573. Py_CLEAR(tmp);
  7574. asname = NULL;
  7575. }
  7576. else {
  7577. int res;
  7578. res = obj2ast_identifier(tmp, &asname, arena);
  7579. if (res != 0) goto failed;
  7580. Py_CLEAR(tmp);
  7581. }
  7582. *out = alias(name, asname, arena);
  7583. return 0;
  7584. failed:
  7585. Py_XDECREF(tmp);
  7586. return 1;
  7587. }
  7588. int
  7589. obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
  7590. {
  7591. PyObject* tmp = NULL;
  7592. expr_ty context_expr;
  7593. expr_ty optional_vars;
  7594. if (_PyObject_LookupAttrId(obj, &PyId_context_expr, &tmp) < 0) {
  7595. return 1;
  7596. }
  7597. if (tmp == NULL) {
  7598. PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
  7599. return 1;
  7600. }
  7601. else {
  7602. int res;
  7603. res = obj2ast_expr(tmp, &context_expr, arena);
  7604. if (res != 0) goto failed;
  7605. Py_CLEAR(tmp);
  7606. }
  7607. if (_PyObject_LookupAttrId(obj, &PyId_optional_vars, &tmp) < 0) {
  7608. return 1;
  7609. }
  7610. if (tmp == NULL || tmp == Py_None) {
  7611. Py_CLEAR(tmp);
  7612. optional_vars = NULL;
  7613. }
  7614. else {
  7615. int res;
  7616. res = obj2ast_expr(tmp, &optional_vars, arena);
  7617. if (res != 0) goto failed;
  7618. Py_CLEAR(tmp);
  7619. }
  7620. *out = withitem(context_expr, optional_vars, arena);
  7621. return 0;
  7622. failed:
  7623. Py_XDECREF(tmp);
  7624. return 1;
  7625. }
  7626. static struct PyModuleDef _astmodule = {
  7627. PyModuleDef_HEAD_INIT, "_ast"
  7628. };
  7629. PyMODINIT_FUNC
  7630. PyInit__ast(void)
  7631. {
  7632. PyObject *m, *d;
  7633. if (!init_types()) return NULL;
  7634. m = PyModule_Create(&_astmodule);
  7635. if (!m) return NULL;
  7636. d = PyModule_GetDict(m);
  7637. if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL;
  7638. if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)
  7639. return NULL;
  7640. if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL;
  7641. if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return
  7642. NULL;
  7643. if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) <
  7644. 0) return NULL;
  7645. if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0)
  7646. return NULL;
  7647. if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return
  7648. NULL;
  7649. if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL;
  7650. if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) <
  7651. 0) return NULL;
  7652. if (PyDict_SetItemString(d, "AsyncFunctionDef",
  7653. (PyObject*)AsyncFunctionDef_type) < 0) return NULL;
  7654. if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
  7655. return NULL;
  7656. if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return
  7657. NULL;
  7658. if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return
  7659. NULL;
  7660. if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return
  7661. NULL;
  7662. if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0)
  7663. return NULL;
  7664. if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0)
  7665. return NULL;
  7666. if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL;
  7667. if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0)
  7668. return NULL;
  7669. if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return
  7670. NULL;
  7671. if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL;
  7672. if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL;
  7673. if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0)
  7674. return NULL;
  7675. if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return
  7676. NULL;
  7677. if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL;
  7678. if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return
  7679. NULL;
  7680. if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return
  7681. NULL;
  7682. if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0)
  7683. return NULL;
  7684. if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return
  7685. NULL;
  7686. if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
  7687. return NULL;
  7688. if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL;
  7689. if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL;
  7690. if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return
  7691. NULL;
  7692. if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
  7693. return NULL;
  7694. if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL;
  7695. if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return
  7696. NULL;
  7697. if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return
  7698. NULL;
  7699. if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return
  7700. NULL;
  7701. if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return
  7702. NULL;
  7703. if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return
  7704. NULL;
  7705. if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL;
  7706. if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL;
  7707. if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
  7708. return NULL;
  7709. if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return
  7710. NULL;
  7711. if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
  7712. return NULL;
  7713. if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) <
  7714. 0) return NULL;
  7715. if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return
  7716. NULL;
  7717. if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return
  7718. NULL;
  7719. if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0)
  7720. return NULL;
  7721. if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return
  7722. NULL;
  7723. if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL;
  7724. if (PyDict_SetItemString(d, "FormattedValue",
  7725. (PyObject*)FormattedValue_type) < 0) return NULL;
  7726. if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0)
  7727. return NULL;
  7728. if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0)
  7729. return NULL;
  7730. if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0)
  7731. return NULL;
  7732. if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0)
  7733. return NULL;
  7734. if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return
  7735. NULL;
  7736. if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL;
  7737. if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL;
  7738. if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return
  7739. NULL;
  7740. if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) <
  7741. 0) return NULL;
  7742. if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL;
  7743. if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return
  7744. NULL;
  7745. if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL;
  7746. if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return
  7747. NULL;
  7748. if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
  7749. return NULL;
  7750. if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return
  7751. NULL;
  7752. if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return
  7753. NULL;
  7754. if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return
  7755. NULL;
  7756. if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
  7757. return NULL;
  7758. if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return
  7759. NULL;
  7760. if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return
  7761. NULL;
  7762. if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL;
  7763. if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL;
  7764. if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
  7765. return NULL;
  7766. if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL;
  7767. if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL;
  7768. if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL;
  7769. if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return
  7770. NULL;
  7771. if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL;
  7772. if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL;
  7773. if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL;
  7774. if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return
  7775. NULL;
  7776. if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return
  7777. NULL;
  7778. if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return
  7779. NULL;
  7780. if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return
  7781. NULL;
  7782. if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return
  7783. NULL;
  7784. if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
  7785. return NULL;
  7786. if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return
  7787. NULL;
  7788. if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return
  7789. NULL;
  7790. if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL;
  7791. if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL;
  7792. if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL;
  7793. if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return
  7794. NULL;
  7795. if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL;
  7796. if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return
  7797. NULL;
  7798. if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL;
  7799. if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL;
  7800. if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL;
  7801. if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL;
  7802. if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL;
  7803. if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return
  7804. NULL;
  7805. if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL;
  7806. if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return
  7807. NULL;
  7808. if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type)
  7809. < 0) return NULL;
  7810. if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type)
  7811. < 0) return NULL;
  7812. if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type)
  7813. < 0) return NULL;
  7814. if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0)
  7815. return NULL;
  7816. if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL;
  7817. if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return
  7818. NULL;
  7819. if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return
  7820. NULL;
  7821. if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0)
  7822. return NULL;
  7823. return m;
  7824. }
  7825. PyObject* PyAST_mod2obj(mod_ty t)
  7826. {
  7827. if (!init_types())
  7828. return NULL;
  7829. return ast2obj_mod(t);
  7830. }
  7831. /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
  7832. mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
  7833. {
  7834. mod_ty res;
  7835. PyObject *req_type[3];
  7836. char *req_name[] = {"Module", "Expression", "Interactive"};
  7837. int isinstance;
  7838. req_type[0] = (PyObject*)Module_type;
  7839. req_type[1] = (PyObject*)Expression_type;
  7840. req_type[2] = (PyObject*)Interactive_type;
  7841. assert(0 <= mode && mode <= 2);
  7842. if (!init_types())
  7843. return NULL;
  7844. isinstance = PyObject_IsInstance(ast, req_type[mode]);
  7845. if (isinstance == -1)
  7846. return NULL;
  7847. if (!isinstance) {
  7848. PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
  7849. req_name[mode], Py_TYPE(ast)->tp_name);
  7850. return NULL;
  7851. }
  7852. if (obj2ast_mod(ast, &res, arena) != 0)
  7853. return NULL;
  7854. else
  7855. return res;
  7856. }
  7857. int PyAST_Check(PyObject* obj)
  7858. {
  7859. if (!init_types())
  7860. return -1;
  7861. return PyObject_IsInstance(obj, (PyObject*)&AST_type);
  7862. }