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.

8165 lines
265 KiB

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