Back to index

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

List of all members.

Public Member Functions

def visitModule
def visitType
def visitSum
def sum_with_constructors
def visitConstructor
def visitField
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 typdefs for AST.

Definition at line 138 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.StructVisitor.sum_with_constructors (   self,
  sum,
  name,
  depth 
)

Definition at line 152 of file asdl_c.py.

00152 
00153     def sum_with_constructors(self, sum, name, depth):
00154         def emit(s, depth=depth):
00155             self.emit(s % sys._getframe(1).f_locals, depth)
00156         enum = []
00157         for i in range(len(sum.types)):
00158             type = sum.types[i]
00159             enum.append("%s_kind=%d" % (type.name, i + 1))
00160 
00161         emit("enum _%(name)s_kind {" + ", ".join(enum) + "};")
00162 
00163         emit("struct _%(name)s {")
00164         emit("enum _%(name)s_kind kind;", depth + 1)
00165         emit("union {", depth + 1)
00166         for t in sum.types:
00167             self.visit(t, depth + 2)
00168         emit("} v;", depth + 1)
00169         for field in sum.attributes:
00170             # rudimentary attribute handling
00171             type = str(field.type)
00172             assert type in asdl.builtin_types, type
00173             emit("%s %s;" % (type, field.name), depth + 1);
00174         emit("};")
00175         emit("")

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.StructVisitor.visitConstructor (   self,
  cons,
  depth 
)

Definition at line 176 of file asdl_c.py.

00176 
00177     def visitConstructor(self, cons, depth):
00178         if cons.fields:
00179             self.emit("struct {", depth)
00180             for f in cons.fields:
00181                 self.visit(f, depth + 1)
00182             self.emit("} %s;" % cons.name, depth)
00183             self.emit("", depth)
00184         else:
00185             # XXX not sure what I want here, nothing is probably fine
00186             pass

Here is the call graph for this function:

Here is the caller graph for this function:

def asdl_c.StructVisitor.visitField (   self,
  field,
  depth 
)

Definition at line 187 of file asdl_c.py.

00187 
00188     def visitField(self, field, depth):
00189         # XXX need to lookup field.type, because it might be something
00190         # like a builtin...
00191         ctype = get_c_type(field.type)
00192         name = field.name
00193         if field.seq:
00194             if field.type.value in ('cmpop',):
00195                 self.emit("asdl_int_seq *%(name)s;" % locals(), depth)
00196             else:
00197                 self.emit("asdl_seq *%(name)s;" % locals(), depth)
00198         else:
00199             self.emit("%(ctype)s %(name)s;" % locals(), depth)

Here is the call graph for this function:

Here is the caller graph for this function:

def asdl_c.StructVisitor.visitModule (   self,
  mod 
)

Definition at line 141 of file asdl_c.py.

00141 
00142     def visitModule(self, mod):
00143         for dfn in mod.dfns:
00144             self.visit(dfn)

Here is the call graph for this function:

def asdl_c.StructVisitor.visitProduct (   self,
  product,
  name,
  depth 
)

Definition at line 200 of file asdl_c.py.

00200 
00201     def visitProduct(self, product, name, depth):
00202         self.emit("struct _%(name)s {" % locals(), depth)
00203         for f in product.fields:
00204             self.visit(f, depth + 1)
00205         self.emit("};", depth)
00206         self.emit("", depth)
00207 

Here is the call graph for this function:

def asdl_c.StructVisitor.visitSum (   self,
  sum,
  name,
  depth 
)

Definition at line 148 of file asdl_c.py.

00148 
00149     def visitSum(self, sum, name, depth):
00150         if not is_simple(sum):
00151             self.sum_with_constructors(sum, name, depth)

Here is the call graph for this function:

def asdl_c.StructVisitor.visitType (   self,
  type,
  depth = 0 
)

Definition at line 145 of file asdl_c.py.

00145 
00146     def visitType(self, type, depth=0):
00147         self.visit(type.value, type.name, depth)

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: