mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
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).
This commit is contained in:
parent
d080d4b047
commit
0db62aaf09
3 changed files with 30 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* File automatically generated by Parser/asdl_c.py */
|
/* File automatically generated by Parser/asdl_c.py. */
|
||||||
|
|
||||||
#include "asdl.h"
|
#include "asdl.h"
|
||||||
|
|
||||||
|
|
|
@ -525,6 +525,9 @@ static PyObject* ast2obj_int(bool b)
|
||||||
(cons.name, cons.name), 1)
|
(cons.name, cons.name), 1)
|
||||||
self.emit("if (!%s_singleton) return 0;" % cons.name, 1)
|
self.emit("if (!%s_singleton) return 0;" % cons.name, 1)
|
||||||
|
|
||||||
|
def parse_version(mod):
|
||||||
|
return mod.version.value[12:-3]
|
||||||
|
|
||||||
class ASTModuleVisitor(PickleVisitor):
|
class ASTModuleVisitor(PickleVisitor):
|
||||||
|
|
||||||
def visitModule(self, mod):
|
def visitModule(self, mod):
|
||||||
|
@ -540,7 +543,8 @@ class ASTModuleVisitor(PickleVisitor):
|
||||||
self.emit('if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)', 1)
|
self.emit('if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)', 1)
|
||||||
self.emit("return;", 2)
|
self.emit("return;", 2)
|
||||||
# Value of version: "$Revision$"
|
# Value of version: "$Revision$"
|
||||||
self.emit('if (PyModule_AddStringConstant(m, "__version__", "%s") < 0)' % mod.version.value[12:-3], 1)
|
self.emit('if (PyModule_AddStringConstant(m, "__version__", "%s") < 0)'
|
||||||
|
% parse_version(mod), 1)
|
||||||
self.emit("return;", 2)
|
self.emit("return;", 2)
|
||||||
for dfn in mod.dfns:
|
for dfn in mod.dfns:
|
||||||
self.visit(dfn)
|
self.visit(dfn)
|
||||||
|
@ -721,11 +725,23 @@ class ChainOfVisitors:
|
||||||
v.visit(object)
|
v.visit(object)
|
||||||
v.emit("", 0)
|
v.emit("", 0)
|
||||||
|
|
||||||
|
common_msg = "/* File automatically generated by %s. */\n"
|
||||||
|
|
||||||
|
c_file_msg = """
|
||||||
|
/*
|
||||||
|
__version__ %s.
|
||||||
|
|
||||||
|
This module must be committed separately after each AST grammar change;
|
||||||
|
The __version__ number is set to the revision number of the commit
|
||||||
|
containing the grammar change.
|
||||||
|
*/
|
||||||
|
"""
|
||||||
|
|
||||||
def main(srcfile):
|
def main(srcfile):
|
||||||
argv0 = sys.argv[0]
|
argv0 = sys.argv[0]
|
||||||
components = argv0.split(os.sep)
|
components = argv0.split(os.sep)
|
||||||
argv0 = os.sep.join(components[-2:])
|
argv0 = os.sep.join(components[-2:])
|
||||||
auto_gen_msg = '/* File automatically generated by %s */\n' % argv0
|
auto_gen_msg = common_msg % argv0
|
||||||
mod = asdl.parse(srcfile)
|
mod = asdl.parse(srcfile)
|
||||||
if not asdl.check(mod):
|
if not asdl.check(mod):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -746,6 +762,7 @@ def main(srcfile):
|
||||||
p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")
|
p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")
|
||||||
f = open(p, "wb")
|
f = open(p, "wb")
|
||||||
print >> f, auto_gen_msg
|
print >> f, auto_gen_msg
|
||||||
|
print >> f, c_file_msg % parse_version(mod)
|
||||||
print >> f, '#include "Python.h"'
|
print >> f, '#include "Python.h"'
|
||||||
print >> f, '#include "%s-ast.h"' % mod.name
|
print >> f, '#include "%s-ast.h"' % mod.name
|
||||||
print >> f
|
print >> f
|
||||||
|
|
|
@ -1,4 +1,13 @@
|
||||||
/* File automatically generated by Parser/asdl_c.py */
|
/* File automatically generated by Parser/asdl_c.py. */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
__version__ 53731.
|
||||||
|
|
||||||
|
This module must be committed separately after each AST grammar change;
|
||||||
|
The __version__ number is set to the revision number of the commit
|
||||||
|
containing the grammar change.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "Python-ast.h"
|
#include "Python-ast.h"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue