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.

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