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.

8487 lines
263 KiB

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