Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
asdl_c.ObjVisitor Class Reference
Inheritance diagram for asdl_c.ObjVisitor:
Inheritance graph
[legend]
Collaboration diagram for asdl_c.ObjVisitor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def func_begin
def func_end
def visitSum
def simpleSum
def visitProduct
def visitConstructor
def visitField
def emitSeq
def set
def visitModule
def visitType
def visitConstructor
def visitField
def emit
def visit

Public Attributes

 file
 cache
 skip
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

Definition at line 967 of file asdl_c.py.


Member Function Documentation

def asdl_c.EmitVisitor.emit (   self,
  s,
  depth,
  reflow = True 
) [inherited]

Definition at line 89 of file asdl_c.py.

00089 
00090     def emit(self, s, depth, reflow=True):
00091         # XXX reflow long lines?
00092         if reflow:
00093             lines = reflow_lines(s, depth)
00094         else:
00095             lines = [s]
00096         for line in lines:
00097             line = (" " * TABSIZE * depth) + line + "\n"
00098             self.file.write(line)
00099 

Here is the call graph for this function:

def asdl_c.ObjVisitor.emitSeq (   self,
  field,
  value,
  depth,
  emit 
)

Definition at line 1054 of file asdl_c.py.

01054 
01055     def emitSeq(self, field, value, depth, emit):
01056         emit("seq = %s;" % value, 0)
01057         emit("n = asdl_seq_LEN(seq);", 0)
01058         emit("value = PyList_New(n);", 0)
01059         emit("if (!value) goto failed;", 0)
01060         emit("for (i = 0; i < n; i++) {", 0)
01061         self.set("value", field, "asdl_seq_GET(seq, i)", depth + 1)
01062         emit("if (!value1) goto failed;", 1)
01063         emit("PyList_SET_ITEM(value, i, value1);", 1)
01064         emit("value1 = NULL;", 1)
01065         emit("}", 0)

Here is the call graph for this function:

def asdl_c.ObjVisitor.func_begin (   self,
  name 
)

Definition at line 969 of file asdl_c.py.

00969 
00970     def func_begin(self, name):
00971         ctype = get_c_type(name)
00972         self.emit("PyObject*", 0)
00973         self.emit("ast2obj_%s(void* _o)" % (name), 0)
00974         self.emit("{", 0)
00975         self.emit("%s o = (%s)_o;" % (ctype, ctype), 1)
00976         self.emit("PyObject *result = NULL, *value = NULL;", 1)
00977         self.emit('if (!o) {', 1)
00978         self.emit("Py_INCREF(Py_None);", 2)
00979         self.emit('return Py_None;', 2)
00980         self.emit("}", 1)
00981         self.emit('', 0)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 982 of file asdl_c.py.

00982 
00983     def func_end(self):
00984         self.emit("return result;", 1)
00985         self.emit("failed:", 0)
00986         self.emit("Py_XDECREF(value);", 1)
00987         self.emit("Py_XDECREF(result);", 1)
00988         self.emit("return NULL;", 1)
00989         self.emit("}", 0)
00990         self.emit("", 0)

Here is the call graph for this function:

Here is the caller graph for this function:

def asdl_c.ObjVisitor.set (   self,
  field,
  value,
  depth 
)

Definition at line 1066 of file asdl_c.py.

01066 
01067     def set(self, field, value, depth):
01068         if field.seq:
01069             # XXX should really check for is_simple, but that requires a symbol table
01070             if field.type.value == "cmpop":
01071                 # While the sequence elements are stored as void*,
01072                 # ast2obj_cmpop expects an enum
01073                 self.emit("{", depth)
01074                 self.emit("int i, n = asdl_seq_LEN(%s);" % value, depth+1)
01075                 self.emit("value = PyList_New(n);", depth+1)
01076                 self.emit("if (!value) goto failed;", depth+1)
01077                 self.emit("for(i = 0; i < n; i++)", depth+1)
01078                 # This cannot fail, so no need for error handling
01079                 self.emit("PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(%s, i)));" % value,
01080                           depth+2, reflow=False)
01081                 self.emit("}", depth)
01082             else:
01083                 self.emit("value = ast2obj_list(%s, ast2obj_%s);" % (value, field.type), depth)
01084         else:
01085             ctype = get_c_type(field.type)
01086             self.emit("value = ast2obj_%s(%s);" % (field.type, value), depth, reflow=False)
01087 

Here is the call graph for this function:

Here is the caller graph for this function:

def asdl_c.ObjVisitor.simpleSum (   self,
  sum,
  name 
)

Definition at line 1009 of file asdl_c.py.

01009 
01010     def simpleSum(self, sum, name):
01011         self.emit("PyObject* ast2obj_%s(%s_ty o)" % (name, name), 0)
01012         self.emit("{", 0)
01013         self.emit("switch(o) {", 1)
01014         for t in sum.types:
01015             self.emit("case %s:" % t.name, 2)
01016             self.emit("Py_INCREF(%s_singleton);" % t.name, 3)
01017             self.emit("return %s_singleton;" % t.name, 3)
01018         self.emit("default:" % name, 2)
01019         self.emit('/* should never happen, but just in case ... */', 3)
01020         code = "PyErr_Format(PyExc_SystemError, \"unknown %s found\");" % name
01021         self.emit(code, 3, reflow=False)
01022         self.emit("return NULL;", 3)
01023         self.emit("}", 1)
01024         self.emit("}", 0)

Here is the call graph for this function:

Here is the caller graph for this function:

def asdl.VisitorBase.visit (   self,
  object,
  args 
) [inherited]

Definition at line 319 of file asdl.py.

00319 
00320     def visit(self, object, *args):
00321         meth = self._dispatch(object)
00322         if meth is None:
00323             return
00324         try:
00325             meth(object, *args)
00326         except Exception:
00327             output("Error visiting" + repr(object))
00328             output(str(sys.exc_info()[1]))
00329             traceback.print_exc()
00330             # XXX hack
00331             if hasattr(self, 'file'):
00332                 self.file.flush()
00333             os._exit(1)

Here is the call graph for this function:

Here is the caller graph for this function:

def asdl_c.PickleVisitor.visitConstructor (   self,
  cons,
  name 
) [inherited]

Reimplemented in asdl_c.ASTModuleVisitor, and asdl_c.PyTypesDeclareVisitor.

Definition at line 347 of file asdl_c.py.

00347 
00348     def visitConstructor(self, cons, name):
00349         pass

Here is the caller graph for this function:

def asdl_c.ObjVisitor.visitConstructor (   self,
  cons,
  enum,
  name 
)

Definition at line 1033 of file asdl_c.py.

01033 
01034     def visitConstructor(self, cons, enum, name):
01035         self.emit("case %s_kind:" % cons.name, 1)
01036         self.emit("result = PyType_GenericNew(%s_type, NULL, NULL);" % cons.name, 2);
01037         self.emit("if (!result) goto failed;", 2)
01038         for f in cons.fields:
01039             self.visitField(f, cons.name, 2, False)
01040         self.emit("break;", 2)

Here is the call graph for this function:

def asdl_c.PickleVisitor.visitField (   self,
  sum 
) [inherited]

Definition at line 350 of file asdl_c.py.

00350 
00351     def visitField(self, sum):
00352         pass
00353 

Here is the caller graph for this function:

def asdl_c.ObjVisitor.visitField (   self,
  field,
  name,
  depth,
  product 
)

Definition at line 1041 of file asdl_c.py.

01041 
01042     def visitField(self, field, name, depth, product):
01043         def emit(s, d):
01044             self.emit(s, depth + d)
01045         if product:
01046             value = "o->%s" % field.name
01047         else:
01048             value = "o->v.%s.%s" % (name, field.name)
01049         self.set(field, value, depth)
01050         emit("if (!value) goto failed;", 0)
01051         emit('if (PyObject_SetAttrString(result, "%s", value) == -1)' % field.name, 0)
01052         emit("goto failed;", 1)
01053         emit("Py_DECREF(value);", 0)

Here is the call graph for this function:

def asdl_c.PickleVisitor.visitModule (   self,
  mod 
) [inherited]

Reimplemented in asdl_c.ASTModuleVisitor, and asdl_c.PyTypesVisitor.

Definition at line 334 of file asdl_c.py.

00334 
00335     def visitModule(self, mod):
00336         for dfn in mod.dfns:
00337             self.visit(dfn)

Here is the call graph for this function:

def asdl_c.ObjVisitor.visitProduct (   self,
  prod,
  name 
)

Reimplemented from asdl_c.PickleVisitor.

Definition at line 1025 of file asdl_c.py.

01025 
01026     def visitProduct(self, prod, name):
01027         self.func_begin(name)
01028         self.emit("result = PyType_GenericNew(%s_type, NULL, NULL);" % name, 1);
01029         self.emit("if (!result) return NULL;", 1)
01030         for field in prod.fields:
01031             self.visitField(field, name, 1, True)
01032         self.func_end()

Here is the call graph for this function:

def asdl_c.ObjVisitor.visitSum (   self,
  sum,
  name 
)

Reimplemented from asdl_c.PickleVisitor.

Definition at line 991 of file asdl_c.py.

00991 
00992     def visitSum(self, sum, name):
00993         if is_simple(sum):
00994             self.simpleSum(sum, name)
00995             return
00996         self.func_begin(name)
00997         self.emit("switch (o->kind) {", 1)
00998         for i in range(len(sum.types)):
00999             t = sum.types[i]
01000             self.visitConstructor(t, i + 1, name)
01001         self.emit("}", 1)
01002         for a in sum.attributes:
01003             self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1)
01004             self.emit("if (!value) goto failed;", 1)
01005             self.emit('if (PyObject_SetAttrString(result, "%s", value) < 0)' % a.name, 1)
01006             self.emit('goto failed;', 2)
01007             self.emit('Py_DECREF(value);', 1)
01008         self.func_end()

Here is the call graph for this function:

def asdl_c.PickleVisitor.visitType (   self,
  type 
) [inherited]

Definition at line 338 of file asdl_c.py.

00338 
00339     def visitType(self, type):
00340         self.visit(type.value, type.name)

Here is the call graph for this function:


Member Data Documentation

Definition at line 316 of file asdl.py.

Definition at line 86 of file asdl_c.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

asdl.VisitorBase.skip [inherited]

Definition at line 317 of file asdl.py.


The documentation for this class was generated from the following file: