Back to index

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

List of all members.

Public Member Functions

def emit_function
def emit_body_union
def emit_body_struct
def visitModule
def visitType
def visitSum
def get_args
def visitConstructor
def visitProduct
def emit
def visit

Public Attributes

 file
 cache
 skip
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

Visitor to generate constructor functions for AST.

Definition at line 278 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.FunctionVisitor.emit_body_struct (   self,
  name,
  args,
  attrs 
)

Definition at line 324 of file asdl_c.py.

00324 
00325     def emit_body_struct(self, name, args, attrs):
00326         def emit(s, depth=0, reflow=True):
00327             self.emit(s, depth, reflow)
00328         for argtype, argname, opt in args:
00329             emit("p->%s = %s;" % (argname, argname), 1)
00330         assert not attrs
00331 

Here is the call graph for this function:

Here is the caller graph for this function:

def asdl_c.FunctionVisitor.emit_body_union (   self,
  name,
  args,
  attrs 
)

Definition at line 315 of file asdl_c.py.

00315 
00316     def emit_body_union(self, name, args, attrs):
00317         def emit(s, depth=0, reflow=True):
00318             self.emit(s, depth, reflow)
00319         emit("p->kind = %s_kind;" % name, 1)
00320         for argtype, argname, opt in args:
00321             emit("p->v.%s.%s = %s;" % (name, argname, argname), 1)
00322         for argtype, argname, opt in attrs:
00323             emit("p->%s = %s;" % (argname, argname), 1)

Here is the call graph for this function:

Here is the caller graph for this function:

def asdl_c.FunctionVisitor.emit_function (   self,
  name,
  ctype,
  args,
  attrs,
  union = True 
)

Reimplemented from asdl_c.PrototypeVisitor.

Definition at line 281 of file asdl_c.py.

00281 
00282     def emit_function(self, name, ctype, args, attrs, union=True):
00283         def emit(s, depth=0, reflow=True):
00284             self.emit(s, depth, reflow)
00285         argstr = ", ".join(["%s %s" % (atype, aname)
00286                             for atype, aname, opt in args + attrs])
00287         if argstr:
00288             argstr += ", PyArena *arena"
00289         else:
00290             argstr = "PyArena *arena"
00291         self.emit("%s" % ctype, 0)
00292         emit("%s(%s)" % (name, argstr))
00293         emit("{")
00294         emit("%s p;" % ctype, 1)
00295         for argtype, argname, opt in args:
00296             if not opt and argtype != "int":
00297                 emit("if (!%s) {" % argname, 1)
00298                 emit("PyErr_SetString(PyExc_ValueError,", 2)
00299                 msg = "field %s is required for %s" % (argname, name)
00300                 emit('                "%s");' % msg,
00301                      2, reflow=False)
00302                 emit('return NULL;', 2)
00303                 emit('}', 1)
00304 
00305         emit("p = (%s)PyArena_Malloc(arena, sizeof(*p));" % ctype, 1);
00306         emit("if (!p)", 1)
00307         emit("return NULL;", 2)
00308         if union:
00309             self.emit_body_union(name, args, attrs)
00310         else:
00311             self.emit_body_struct(name, args, attrs)
00312         emit("return p;", 1)
00313         emit("}")
00314         emit("")

Here is the call graph for this function:

def asdl_c.PrototypeVisitor.get_args (   self,
  fields 
) [inherited]
Return list of C argument into, one for each field.

Argument info is 3-tuple of a C type, variable name, and flag
that is true if type can be NULL.

Definition at line 225 of file asdl_c.py.

00225 
00226     def get_args(self, fields):
00227         """Return list of C argument into, one for each field.
00228 
00229         Argument info is 3-tuple of a C type, variable name, and flag
00230         that is true if type can be NULL.
00231         """
00232         args = []
00233         unnamed = {}
00234         for f in fields:
00235             if f.name is None:
00236                 name = f.type
00237                 c = unnamed[name] = unnamed.get(name, 0) + 1
00238                 if c > 1:
00239                     name = "name%d" % (c - 1)
00240             else:
00241                 name = f.name
00242             # XXX should extend get_c_type() to handle this
00243             if f.seq:
00244                 if f.type.value in ('cmpop',):
00245                     ctype = "asdl_int_seq *"
00246                 else:
00247                     ctype = "asdl_seq *"
00248             else:
00249                 ctype = get_c_type(f.type)
00250             args.append((ctype, name, f.opt or f.seq))
00251         return args

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.PrototypeVisitor.visitConstructor (   self,
  cons,
  type,
  attrs 
) [inherited]

Definition at line 252 of file asdl_c.py.

00252 
00253     def visitConstructor(self, cons, type, attrs):
00254         args = self.get_args(cons.fields)
00255         attrs = self.get_args(attrs)
00256         ctype = get_c_type(type)
00257         self.emit_function(cons.name, ctype, args, attrs)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 211 of file asdl_c.py.

00211 
00212     def visitModule(self, mod):
00213         for dfn in mod.dfns:
00214             self.visit(dfn)

Here is the call graph for this function:

def asdl_c.PrototypeVisitor.visitProduct (   self,
  prod,
  name 
) [inherited]

Definition at line 273 of file asdl_c.py.

00273 
00274     def visitProduct(self, prod, name):
00275         self.emit_function(name, get_c_type(name),
00276                            self.get_args(prod.fields), [], union=False)
00277 

Here is the call graph for this function:

def asdl_c.PrototypeVisitor.visitSum (   self,
  sum,
  name 
) [inherited]

Definition at line 218 of file asdl_c.py.

00218 
00219     def visitSum(self, sum, name):
00220         if is_simple(sum):
00221             pass # XXX
00222         else:
00223             for t in sum.types:
00224                 self.visit(t, name, sum.attributes)

Here is the call graph for this function:

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

Definition at line 215 of file asdl_c.py.

00215 
00216     def visitType(self, type):
00217         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: