Back to index

python3.2  3.2.2
Classes | Functions | Variables
asdl_c Namespace Reference

Classes

class  EmitVisitor
class  TypeDefVisitor
class  StructVisitor
class  PrototypeVisitor
class  FunctionVisitor
class  PickleVisitor
class  Obj2ModPrototypeVisitor
class  Obj2ModVisitor
class  MarshalPrototypeVisitor
class  PyTypesDeclareVisitor
class  PyTypesVisitor
class  ASTModuleVisitor
class  StaticVisitor
class  ObjVisitor
class  PartingShots
class  ChainOfVisitors

Functions

def get_c_type
def reflow_lines
def is_simple
def find_sequence
def has_sequence
def main

Variables

int TABSIZE = 8
int MAX_COL = 80
tuple _SPECIALIZED_SEQUENCES = ('stmt', 'expr')
string common_msg = "/* File automatically generated by %s. */\n\n"
string c_file_msg
string INC_DIR = ''
string SRC_DIR = ''

Function Documentation

def asdl_c.find_sequence (   fields,
  doing_specialization 
)
Return True if any field uses a sequence.

Definition at line 943 of file asdl_c.py.

00943 
00944 def find_sequence(fields, doing_specialization):
00945     """Return True if any field uses a sequence."""
00946     for f in fields:
00947         if f.seq:
00948             if not doing_specialization:
00949                 return True
00950             if str(f.type) not in _SPECIALIZED_SEQUENCES:
00951                 return True
00952     return False

Here is the caller graph for this function:

def asdl_c.get_c_type (   name)
Return a string for the C name of the type.

This function special cases the default types provided by asdl:
identifier, string, int.

Definition at line 14 of file asdl_c.py.

00014 
00015 def get_c_type(name):
00016     """Return a string for the C name of the type.
00017 
00018     This function special cases the default types provided by asdl:
00019     identifier, string, int.
00020     """
00021     # XXX ack!  need to figure out where Id is useful and where string
00022     if isinstance(name, asdl.Id):
00023         name = name.value
00024     if name in asdl.builtin_types:
00025         return name
00026     else:
00027         return "%s_ty" % name

Here is the caller graph for this function:

def asdl_c.has_sequence (   types,
  doing_specialization 
)

Definition at line 953 of file asdl_c.py.

00953 
00954 def has_sequence(types, doing_specialization):
00955     for t in types:
00956         if find_sequence(t.fields, doing_specialization):
00957             return True
00958     return False
00959 

Here is the call graph for this function:

def asdl_c.is_simple (   sum)
Return True if a sum is a simple.

A sum is simple if its types have no fields, e.g.
unaryop = Invert | Not | UAdd | USub

Definition at line 70 of file asdl_c.py.

00070 
00071 def is_simple(sum):
00072     """Return True if a sum is a simple.
00073 
00074     A sum is simple if its types have no fields, e.g.
00075     unaryop = Invert | Not | UAdd | USub
00076     """
00077     for t in sum.types:
00078         if t.fields:
00079             return False
00080     return True
00081 

Here is the caller graph for this function:

def asdl_c.main (   srcfile)

Definition at line 1152 of file asdl_c.py.

01152 
01153 def main(srcfile):
01154     argv0 = sys.argv[0]
01155     components = argv0.split(os.sep)
01156     argv0 = os.sep.join(components[-2:])
01157     auto_gen_msg = common_msg % argv0
01158     mod = asdl.parse(srcfile)
01159     mod.version = "82163"
01160     if not asdl.check(mod):
01161         sys.exit(1)
01162     if INC_DIR:
01163         p = "%s/%s-ast.h" % (INC_DIR, mod.name)
01164         f = open(p, "w")
01165         f.write(auto_gen_msg)
01166         f.write('#include "asdl.h"\n\n')
01167         c = ChainOfVisitors(TypeDefVisitor(f),
01168                             StructVisitor(f),
01169                             PrototypeVisitor(f),
01170                             )
01171         c.visit(mod)
01172         f.write("PyObject* PyAST_mod2obj(mod_ty t);\n")
01173         f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
01174         f.write("int PyAST_Check(PyObject* obj);\n")
01175         f.close()
01176 
01177     if SRC_DIR:
01178         p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")
01179         f = open(p, "w")
01180         f.write(auto_gen_msg)
01181         f.write(c_file_msg % mod.version)
01182         f.write('#include "Python.h"\n')
01183         f.write('#include "%s-ast.h"\n' % mod.name)
01184         f.write('\n')
01185         f.write("static PyTypeObject AST_type;\n")
01186         v = ChainOfVisitors(
01187             PyTypesDeclareVisitor(f),
01188             PyTypesVisitor(f),
01189             Obj2ModPrototypeVisitor(f),
01190             FunctionVisitor(f),
01191             ObjVisitor(f),
01192             Obj2ModVisitor(f),
01193             ASTModuleVisitor(f),
01194             PartingShots(f),
01195             )
01196         v.visit(mod)
01197         f.close()

Here is the call graph for this function:

def asdl_c.reflow_lines (   s,
  depth 
)
Reflow the line s indented depth tabs.

Return a sequence of lines where no line extends beyond MAX_COL
when properly indented.  The first line is properly indented based
exclusively on depth * TABSIZE.  All following lines -- these are
the reflowed lines generated by this function -- start at the same
column as the first character beyond the opening { in the first
line.

Definition at line 28 of file asdl_c.py.

00028 
00029 def reflow_lines(s, depth):
00030     """Reflow the line s indented depth tabs.
00031 
00032     Return a sequence of lines where no line extends beyond MAX_COL
00033     when properly indented.  The first line is properly indented based
00034     exclusively on depth * TABSIZE.  All following lines -- these are
00035     the reflowed lines generated by this function -- start at the same
00036     column as the first character beyond the opening { in the first
00037     line.
00038     """
00039     size = MAX_COL - depth * TABSIZE
00040     if len(s) < size:
00041         return [s]
00042 
00043     lines = []
00044     cur = s
00045     padding = ""
00046     while len(cur) > size:
00047         i = cur.rfind(' ', 0, size)
00048         # XXX this should be fixed for real
00049         if i == -1 and 'GeneratorExp' in cur:
00050             i = size + 3
00051         assert i != -1, "Impossible line %d to reflow: %r" % (size, s)
00052         lines.append(padding + cur[:i])
00053         if len(lines) == 1:
00054             # find new size based on brace
00055             j = cur.find('{', 0, i)
00056             if j >= 0:
00057                 j += 2 # account for the brace and the space after it
00058                 size -= j
00059                 padding = " " * j
00060             else:
00061                 j = cur.find('(', 0, i)
00062                 if j >= 0:
00063                     j += 1 # account for the paren (no space after it)
00064                     size -= j
00065                     padding = " " * j
00066         cur = cur[i+1:]
00067     else:
00068         lines.append(padding + cur)
00069     return lines

Here is the caller graph for this function:


Variable Documentation

Definition at line 941 of file asdl_c.py.

Initial value:
00001 """
00002 /*
00003    __version__ %s.
00004 
00005    This module must be committed separately after each AST grammar change;
00006    The __version__ number is set to the revision number of the commit
00007    containing the grammar change.
00008 */
00009 
00010 """

Definition at line 1141 of file asdl_c.py.

string asdl_c.common_msg = "/* File automatically generated by %s. */\n\n"

Definition at line 1139 of file asdl_c.py.

Definition at line 1202 of file asdl_c.py.

Definition at line 12 of file asdl_c.py.

Definition at line 1203 of file asdl_c.py.

Definition at line 11 of file asdl_c.py.