[Python-checkins] python/nondist/sandbox/ast asdl_c.py,1.8,1.9
jhylton@sourceforge.net
jhylton@sourceforge.net
Mon, 15 Apr 2002 20:22:57 -0700
Update of /cvsroot/python/python/nondist/sandbox/ast
In directory usw-pr-cvs1:/tmp/cvs-serv17724
Modified Files:
asdl_c.py
Log Message:
Generate code to handle sequences and optional types.
A sequence is implemented by asdl_seq.
An optional type can be NULL.
For all non-optional types, raise ValueError if the argument is NULL.
Index: asdl_c.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/ast/asdl_c.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** asdl_c.py 12 Apr 2002 15:50:36 -0000 1.8
--- asdl_c.py 16 Apr 2002 03:22:54 -0000 1.9
***************
*** 71,77 ****
super(EmitVisitor, self).__init__()
! def emit(self, s, depth):
# XXX reflow long lines?
! lines = reflow_lines(s, depth)
for line in lines:
line = (" " * TABSIZE * depth) + line + "\n"
--- 71,80 ----
super(EmitVisitor, self).__init__()
! def emit(self, s, depth, reflow=1):
# XXX reflow long lines?
! if reflow:
! lines = reflow_lines(s, depth)
! else:
! lines = [s]
for line in lines:
line = (" " * TABSIZE * depth) + line + "\n"
***************
*** 172,176 ****
ctype = get_c_type(field.type)
name = field.name
! self.emit("%(ctype)s %(name)s;" % locals(), depth)
def visitProduct(self, product, name, depth):
--- 175,182 ----
ctype = get_c_type(field.type)
name = field.name
! if field.seq:
! self.emit("asdl_seq *%(name)s;" % locals(), depth)
! else:
! self.emit("%(ctype)s %(name)s;" % locals(), depth)
def visitProduct(self, product, name, depth):
***************
*** 216,220 ****
else:
name = f.name
! args.append((get_c_type(f.type), name))
ctype = get_c_type(type)
self.emit_function(cons.name, ctype, args)
--- 222,231 ----
else:
name = f.name
! # XXX should extend get_c_type() to handle this
! if f.seq:
! ctype = "asdl_seq *"
! else:
! ctype = get_c_type(f.type)
! args.append((ctype, name, f.opt))
ctype = get_c_type(type)
self.emit_function(cons.name, ctype, args)
***************
*** 223,227 ****
if args:
argstr = ", ".join(["%s %s" % (atype, aname)
! for atype, aname in args])
else:
argstr = "void"
--- 234,238 ----
if args:
argstr = ", ".join(["%s %s" % (atype, aname)
! for atype, aname, opt in args])
else:
argstr = "void"
***************
*** 236,242 ****
def emit_function(self, name, ctype, args):
! def emit(s, depth=0):
! self.emit(s, depth)
! argstr = ", ".join(["%s %s" % (atype, aname) for atype, aname in args])
self.emit("%s" % ctype, 0)
emit("%s(%s)" % (name, argstr))
--- 247,254 ----
def emit_function(self, name, ctype, args):
! def emit(s, depth=0, reflow=1):
! self.emit(s, depth, reflow)
! argstr = ", ".join(["%s %s" % (atype, aname)
! for atype, aname, opt in args])
self.emit("%s" % ctype, 0)
emit("%s(%s)" % (name, argstr))
***************
*** 248,252 ****
emit("}", 1)
emit("p->kind = %s_kind;" % name, 1)
! for argtype, argname in args:
emit("p->v.%s.%s = %s;" % (name, argname, argname), 1)
emit("return p;", 1)
--- 260,272 ----
emit("}", 1)
emit("p->kind = %s_kind;" % name, 1)
! for argtype, argname, opt in args:
! if not opt:
! emit("if (!%s) {" % argname, 1)
! emit("PyErr_SetString(PyExc_ValueError,", 2)
! msg = "field %s is required for %s" % (argname, name)
! emit(' "%s");' % msg,
! 2, reflow=0)
! emit('return NULL;', 2)
! emit('}', 1)
emit("p->v.%s.%s = %s;" % (name, argname, argname), 1)
emit("return p;", 1)