Don't pollute namespace as bad as before. All the types are static now.

This commit is contained in:
Neal Norwitz 2006-02-28 22:47:29 +00:00
parent 8ae1295c5b
commit 53d960c010
2 changed files with 159 additions and 159 deletions

View file

@ -347,18 +347,18 @@ class MarshalPrototypeVisitor(PickleVisitor):
class PyTypesDeclareVisitor(PickleVisitor): class PyTypesDeclareVisitor(PickleVisitor):
def visitProduct(self, prod, name): def visitProduct(self, prod, name):
self.emit("PyTypeObject *%s_type;" % name, 0) self.emit("static PyTypeObject *%s_type;" % name, 0)
self.emit("static PyObject* ast2obj_%s(void*);" % name, 0) self.emit("static PyObject* ast2obj_%s(void*);" % name, 0)
if prod.fields: if prod.fields:
self.emit("char *%s_fields[]={" % name,0) self.emit("static char *%s_fields[]={" % name,0)
for f in prod.fields: for f in prod.fields:
self.emit('"%s",' % f.name, 1) self.emit('"%s",' % f.name, 1)
self.emit("};", 0) self.emit("};", 0)
def visitSum(self, sum, name): def visitSum(self, sum, name):
self.emit("PyTypeObject *%s_type;" % name, 0) self.emit("static PyTypeObject *%s_type;" % name, 0)
if sum.attributes: if sum.attributes:
self.emit("char *%s_attributes[] = {" % name, 0) self.emit("static char *%s_attributes[] = {" % name, 0)
for a in sum.attributes: for a in sum.attributes:
self.emit('"%s",' % a.name, 1) self.emit('"%s",' % a.name, 1)
self.emit("};", 0) self.emit("};", 0)
@ -375,9 +375,9 @@ class PyTypesDeclareVisitor(PickleVisitor):
self.visitConstructor(t, name) self.visitConstructor(t, name)
def visitConstructor(self, cons, name): def visitConstructor(self, cons, name):
self.emit("PyTypeObject *%s_type;" % cons.name, 0) self.emit("static PyTypeObject *%s_type;" % cons.name, 0)
if cons.fields: if cons.fields:
self.emit("char *%s_fields[]={" % cons.name, 0) self.emit("static char *%s_fields[]={" % cons.name, 0)
for t in cons.fields: for t in cons.fields:
self.emit('"%s",' % t.name, 1) self.emit('"%s",' % t.name, 1)
self.emit("};",0) self.emit("};",0)
@ -736,7 +736,7 @@ def main(srcfile):
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
print >>f, "PyTypeObject* AST_type;" print >>f, "static PyTypeObject* AST_type;"
v = ChainOfVisitors( v = ChainOfVisitors(
PyTypesDeclareVisitor(f), PyTypesDeclareVisitor(f),
PyTypesVisitor(f), PyTypesVisitor(f),

View file

@ -3,350 +3,350 @@
#include "Python.h" #include "Python.h"
#include "Python-ast.h" #include "Python-ast.h"
PyTypeObject* AST_type; static PyTypeObject* AST_type;
PyTypeObject *mod_type; static PyTypeObject *mod_type;
static PyObject* ast2obj_mod(void*); static PyObject* ast2obj_mod(void*);
PyTypeObject *Module_type; static PyTypeObject *Module_type;
char *Module_fields[]={ static char *Module_fields[]={
"body", "body",
}; };
PyTypeObject *Interactive_type; static PyTypeObject *Interactive_type;
char *Interactive_fields[]={ static char *Interactive_fields[]={
"body", "body",
}; };
PyTypeObject *Expression_type; static PyTypeObject *Expression_type;
char *Expression_fields[]={ static char *Expression_fields[]={
"body", "body",
}; };
PyTypeObject *Suite_type; static PyTypeObject *Suite_type;
char *Suite_fields[]={ static char *Suite_fields[]={
"body", "body",
}; };
PyTypeObject *stmt_type; static PyTypeObject *stmt_type;
char *stmt_attributes[] = { static char *stmt_attributes[] = {
"lineno", "lineno",
}; };
static PyObject* ast2obj_stmt(void*); static PyObject* ast2obj_stmt(void*);
PyTypeObject *FunctionDef_type; static PyTypeObject *FunctionDef_type;
char *FunctionDef_fields[]={ static char *FunctionDef_fields[]={
"name", "name",
"args", "args",
"body", "body",
"decorators", "decorators",
}; };
PyTypeObject *ClassDef_type; static PyTypeObject *ClassDef_type;
char *ClassDef_fields[]={ static char *ClassDef_fields[]={
"name", "name",
"bases", "bases",
"body", "body",
}; };
PyTypeObject *Return_type; static PyTypeObject *Return_type;
char *Return_fields[]={ static char *Return_fields[]={
"value", "value",
}; };
PyTypeObject *Delete_type; static PyTypeObject *Delete_type;
char *Delete_fields[]={ static char *Delete_fields[]={
"targets", "targets",
}; };
PyTypeObject *Assign_type; static PyTypeObject *Assign_type;
char *Assign_fields[]={ static char *Assign_fields[]={
"targets", "targets",
"value", "value",
}; };
PyTypeObject *AugAssign_type; static PyTypeObject *AugAssign_type;
char *AugAssign_fields[]={ static char *AugAssign_fields[]={
"target", "target",
"op", "op",
"value", "value",
}; };
PyTypeObject *Print_type; static PyTypeObject *Print_type;
char *Print_fields[]={ static char *Print_fields[]={
"dest", "dest",
"values", "values",
"nl", "nl",
}; };
PyTypeObject *For_type; static PyTypeObject *For_type;
char *For_fields[]={ static char *For_fields[]={
"target", "target",
"iter", "iter",
"body", "body",
"orelse", "orelse",
}; };
PyTypeObject *While_type; static PyTypeObject *While_type;
char *While_fields[]={ static char *While_fields[]={
"test", "test",
"body", "body",
"orelse", "orelse",
}; };
PyTypeObject *If_type; static PyTypeObject *If_type;
char *If_fields[]={ static char *If_fields[]={
"test", "test",
"body", "body",
"orelse", "orelse",
}; };
PyTypeObject *With_type; static PyTypeObject *With_type;
char *With_fields[]={ static char *With_fields[]={
"context_expr", "context_expr",
"optional_vars", "optional_vars",
"body", "body",
}; };
PyTypeObject *Raise_type; static PyTypeObject *Raise_type;
char *Raise_fields[]={ static char *Raise_fields[]={
"type", "type",
"inst", "inst",
"tback", "tback",
}; };
PyTypeObject *TryExcept_type; static PyTypeObject *TryExcept_type;
char *TryExcept_fields[]={ static char *TryExcept_fields[]={
"body", "body",
"handlers", "handlers",
"orelse", "orelse",
}; };
PyTypeObject *TryFinally_type; static PyTypeObject *TryFinally_type;
char *TryFinally_fields[]={ static char *TryFinally_fields[]={
"body", "body",
"finalbody", "finalbody",
}; };
PyTypeObject *Assert_type; static PyTypeObject *Assert_type;
char *Assert_fields[]={ static char *Assert_fields[]={
"test", "test",
"msg", "msg",
}; };
PyTypeObject *Import_type; static PyTypeObject *Import_type;
char *Import_fields[]={ static char *Import_fields[]={
"names", "names",
}; };
PyTypeObject *ImportFrom_type; static PyTypeObject *ImportFrom_type;
char *ImportFrom_fields[]={ static char *ImportFrom_fields[]={
"module", "module",
"names", "names",
"level", "level",
}; };
PyTypeObject *Exec_type; static PyTypeObject *Exec_type;
char *Exec_fields[]={ static char *Exec_fields[]={
"body", "body",
"globals", "globals",
"locals", "locals",
}; };
PyTypeObject *Global_type; static PyTypeObject *Global_type;
char *Global_fields[]={ static char *Global_fields[]={
"names", "names",
}; };
PyTypeObject *Expr_type; static PyTypeObject *Expr_type;
char *Expr_fields[]={ static char *Expr_fields[]={
"value", "value",
}; };
PyTypeObject *Pass_type; static PyTypeObject *Pass_type;
PyTypeObject *Break_type; static PyTypeObject *Break_type;
PyTypeObject *Continue_type; static PyTypeObject *Continue_type;
PyTypeObject *expr_type; static PyTypeObject *expr_type;
char *expr_attributes[] = { static char *expr_attributes[] = {
"lineno", "lineno",
}; };
static PyObject* ast2obj_expr(void*); static PyObject* ast2obj_expr(void*);
PyTypeObject *BoolOp_type; static PyTypeObject *BoolOp_type;
char *BoolOp_fields[]={ static char *BoolOp_fields[]={
"op", "op",
"values", "values",
}; };
PyTypeObject *BinOp_type; static PyTypeObject *BinOp_type;
char *BinOp_fields[]={ static char *BinOp_fields[]={
"left", "left",
"op", "op",
"right", "right",
}; };
PyTypeObject *UnaryOp_type; static PyTypeObject *UnaryOp_type;
char *UnaryOp_fields[]={ static char *UnaryOp_fields[]={
"op", "op",
"operand", "operand",
}; };
PyTypeObject *Lambda_type; static PyTypeObject *Lambda_type;
char *Lambda_fields[]={ static char *Lambda_fields[]={
"args", "args",
"body", "body",
}; };
PyTypeObject *IfExp_type; static PyTypeObject *IfExp_type;
char *IfExp_fields[]={ static char *IfExp_fields[]={
"test", "test",
"body", "body",
"orelse", "orelse",
}; };
PyTypeObject *Dict_type; static PyTypeObject *Dict_type;
char *Dict_fields[]={ static char *Dict_fields[]={
"keys", "keys",
"values", "values",
}; };
PyTypeObject *ListComp_type; static PyTypeObject *ListComp_type;
char *ListComp_fields[]={ static char *ListComp_fields[]={
"elt", "elt",
"generators", "generators",
}; };
PyTypeObject *GeneratorExp_type; static PyTypeObject *GeneratorExp_type;
char *GeneratorExp_fields[]={ static char *GeneratorExp_fields[]={
"elt", "elt",
"generators", "generators",
}; };
PyTypeObject *Yield_type; static PyTypeObject *Yield_type;
char *Yield_fields[]={ static char *Yield_fields[]={
"value", "value",
}; };
PyTypeObject *Compare_type; static PyTypeObject *Compare_type;
char *Compare_fields[]={ static char *Compare_fields[]={
"left", "left",
"ops", "ops",
"comparators", "comparators",
}; };
PyTypeObject *Call_type; static PyTypeObject *Call_type;
char *Call_fields[]={ static char *Call_fields[]={
"func", "func",
"args", "args",
"keywords", "keywords",
"starargs", "starargs",
"kwargs", "kwargs",
}; };
PyTypeObject *Repr_type; static PyTypeObject *Repr_type;
char *Repr_fields[]={ static char *Repr_fields[]={
"value", "value",
}; };
PyTypeObject *Num_type; static PyTypeObject *Num_type;
char *Num_fields[]={ static char *Num_fields[]={
"n", "n",
}; };
PyTypeObject *Str_type; static PyTypeObject *Str_type;
char *Str_fields[]={ static char *Str_fields[]={
"s", "s",
}; };
PyTypeObject *Attribute_type; static PyTypeObject *Attribute_type;
char *Attribute_fields[]={ static char *Attribute_fields[]={
"value", "value",
"attr", "attr",
"ctx", "ctx",
}; };
PyTypeObject *Subscript_type; static PyTypeObject *Subscript_type;
char *Subscript_fields[]={ static char *Subscript_fields[]={
"value", "value",
"slice", "slice",
"ctx", "ctx",
}; };
PyTypeObject *Name_type; static PyTypeObject *Name_type;
char *Name_fields[]={ static char *Name_fields[]={
"id", "id",
"ctx", "ctx",
}; };
PyTypeObject *List_type; static PyTypeObject *List_type;
char *List_fields[]={ static char *List_fields[]={
"elts", "elts",
"ctx", "ctx",
}; };
PyTypeObject *Tuple_type; static PyTypeObject *Tuple_type;
char *Tuple_fields[]={ static char *Tuple_fields[]={
"elts", "elts",
"ctx", "ctx",
}; };
PyTypeObject *expr_context_type; static PyTypeObject *expr_context_type;
static PyObject *Load_singleton, *Store_singleton, *Del_singleton, static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
*AugLoad_singleton, *AugStore_singleton, *Param_singleton; *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
static PyObject* ast2obj_expr_context(expr_context_ty); static PyObject* ast2obj_expr_context(expr_context_ty);
PyTypeObject *Load_type; static PyTypeObject *Load_type;
PyTypeObject *Store_type; static PyTypeObject *Store_type;
PyTypeObject *Del_type; static PyTypeObject *Del_type;
PyTypeObject *AugLoad_type; static PyTypeObject *AugLoad_type;
PyTypeObject *AugStore_type; static PyTypeObject *AugStore_type;
PyTypeObject *Param_type; static PyTypeObject *Param_type;
PyTypeObject *slice_type; static PyTypeObject *slice_type;
static PyObject* ast2obj_slice(void*); static PyObject* ast2obj_slice(void*);
PyTypeObject *Ellipsis_type; static PyTypeObject *Ellipsis_type;
PyTypeObject *Slice_type; static PyTypeObject *Slice_type;
char *Slice_fields[]={ static char *Slice_fields[]={
"lower", "lower",
"upper", "upper",
"step", "step",
}; };
PyTypeObject *ExtSlice_type; static PyTypeObject *ExtSlice_type;
char *ExtSlice_fields[]={ static char *ExtSlice_fields[]={
"dims", "dims",
}; };
PyTypeObject *Index_type; static PyTypeObject *Index_type;
char *Index_fields[]={ static char *Index_fields[]={
"value", "value",
}; };
PyTypeObject *boolop_type; static PyTypeObject *boolop_type;
static PyObject *And_singleton, *Or_singleton; static PyObject *And_singleton, *Or_singleton;
static PyObject* ast2obj_boolop(boolop_ty); static PyObject* ast2obj_boolop(boolop_ty);
PyTypeObject *And_type; static PyTypeObject *And_type;
PyTypeObject *Or_type; static PyTypeObject *Or_type;
PyTypeObject *operator_type; static PyTypeObject *operator_type;
static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
*FloorDiv_singleton; *FloorDiv_singleton;
static PyObject* ast2obj_operator(operator_ty); static PyObject* ast2obj_operator(operator_ty);
PyTypeObject *Add_type; static PyTypeObject *Add_type;
PyTypeObject *Sub_type; static PyTypeObject *Sub_type;
PyTypeObject *Mult_type; static PyTypeObject *Mult_type;
PyTypeObject *Div_type; static PyTypeObject *Div_type;
PyTypeObject *Mod_type; static PyTypeObject *Mod_type;
PyTypeObject *Pow_type; static PyTypeObject *Pow_type;
PyTypeObject *LShift_type; static PyTypeObject *LShift_type;
PyTypeObject *RShift_type; static PyTypeObject *RShift_type;
PyTypeObject *BitOr_type; static PyTypeObject *BitOr_type;
PyTypeObject *BitXor_type; static PyTypeObject *BitXor_type;
PyTypeObject *BitAnd_type; static PyTypeObject *BitAnd_type;
PyTypeObject *FloorDiv_type; static PyTypeObject *FloorDiv_type;
PyTypeObject *unaryop_type; static PyTypeObject *unaryop_type;
static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
*USub_singleton; *USub_singleton;
static PyObject* ast2obj_unaryop(unaryop_ty); static PyObject* ast2obj_unaryop(unaryop_ty);
PyTypeObject *Invert_type; static PyTypeObject *Invert_type;
PyTypeObject *Not_type; static PyTypeObject *Not_type;
PyTypeObject *UAdd_type; static PyTypeObject *UAdd_type;
PyTypeObject *USub_type; static PyTypeObject *USub_type;
PyTypeObject *cmpop_type; static PyTypeObject *cmpop_type;
static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
*NotIn_singleton; *NotIn_singleton;
static PyObject* ast2obj_cmpop(cmpop_ty); static PyObject* ast2obj_cmpop(cmpop_ty);
PyTypeObject *Eq_type; static PyTypeObject *Eq_type;
PyTypeObject *NotEq_type; static PyTypeObject *NotEq_type;
PyTypeObject *Lt_type; static PyTypeObject *Lt_type;
PyTypeObject *LtE_type; static PyTypeObject *LtE_type;
PyTypeObject *Gt_type; static PyTypeObject *Gt_type;
PyTypeObject *GtE_type; static PyTypeObject *GtE_type;
PyTypeObject *Is_type; static PyTypeObject *Is_type;
PyTypeObject *IsNot_type; static PyTypeObject *IsNot_type;
PyTypeObject *In_type; static PyTypeObject *In_type;
PyTypeObject *NotIn_type; static PyTypeObject *NotIn_type;
PyTypeObject *comprehension_type; static PyTypeObject *comprehension_type;
static PyObject* ast2obj_comprehension(void*); static PyObject* ast2obj_comprehension(void*);
char *comprehension_fields[]={ static char *comprehension_fields[]={
"target", "target",
"iter", "iter",
"ifs", "ifs",
}; };
PyTypeObject *excepthandler_type; static PyTypeObject *excepthandler_type;
static PyObject* ast2obj_excepthandler(void*); static PyObject* ast2obj_excepthandler(void*);
char *excepthandler_fields[]={ static char *excepthandler_fields[]={
"type", "type",
"name", "name",
"body", "body",
}; };
PyTypeObject *arguments_type; static PyTypeObject *arguments_type;
static PyObject* ast2obj_arguments(void*); static PyObject* ast2obj_arguments(void*);
char *arguments_fields[]={ static char *arguments_fields[]={
"args", "args",
"vararg", "vararg",
"kwarg", "kwarg",
"defaults", "defaults",
}; };
PyTypeObject *keyword_type; static PyTypeObject *keyword_type;
static PyObject* ast2obj_keyword(void*); static PyObject* ast2obj_keyword(void*);
char *keyword_fields[]={ static char *keyword_fields[]={
"arg", "arg",
"value", "value",
}; };
PyTypeObject *alias_type; static PyTypeObject *alias_type;
static PyObject* ast2obj_alias(void*); static PyObject* ast2obj_alias(void*);
char *alias_fields[]={ static char *alias_fields[]={
"name", "name",
"asname", "asname",
}; };