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.

8329 lines
266 KiB

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