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.

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