FIXED_VALUE: Expression used for the value of this type.
"""
class Type:
- def __init__(self, name, role, human_name):
+ def __init__(self, name, role, human_name, c_type=None):
self.name = name
self.role = role
self.human_name = human_name
+ if c_type:
+ if c_type.endswith('*'):
+ self.c_type = c_type
+ else:
+ self.c_type = c_type + ' '
def new_atom(name):
return Type(name, 'atom', name)
def new_any(name, c_type, atom, mangle, human_name, stack, missing_value):
- new = Type(name, 'any', human_name)
- new.c_type = c_type
+ new = Type(name, 'any', human_name, c_type)
new.atom = atom
new.mangle = mangle
new.stack = stack
return new
def new_leaf(name, c_type, atom, mangle, human_name):
- new = Type(name, 'leaf', human_name)
- new.c_type = c_type
+ new = Type(name, 'leaf', human_name, c_type)
new.atom = atom
new.mangle = mangle
return new
def new_fixed(name, c_type, fixed_value):
- new = Type(name, 'fixed', name)
- new.c_type = c_type
+ new = Type(name, 'fixed', name, c_type)
new.fixed_value = fixed_value
return new
global types
types[type_.name] = type_
-# c_type(type).
-#
-def c_type(type_):
- """Returns the C type of the given type as a string designed to be
- prepended to a variable name to produce a declaration. (That
- won't work in general but it works well enough for our types.)
- """
- c_type = type_.c_type
- if not c_type.endswith('*'):
- c_type += ' '
- return c_type
\f
# Input parsing.
args = []
for arg in op.args:
if arg.idx is None:
- args += [c_type(arg.type_) + arg.name]
+ args += [arg.type_.c_type + arg.name]
else:
- args += [c_type(arg.type_) + arg.name + '[]']
+ args += [arg.type_.c_type + arg.name + '[]']
args += ['size_t %s' % arg.idx]
for aux in op.aux:
- args += [c_type(aux['TYPE']) + aux['NAME']]
+ args += [aux['TYPE'].c_type + aux['NAME']]
if not args:
args += ['void']
else:
statements = " return %s;\n" % op.expression
- out_file.write("static inline %s\n" % c_type (op.returns))
+ out_file.write("static inline %s\n" % op.returns.c_type)
out_file.write("eval_%s (%s)\n" % (opname, ', '.join(args)))
out_file.write("{\n")
out_file.write(statements)
args = []
for arg in op.args:
type_ = arg.type_
- ctype = c_type(type_)
+ c_type = type_.c_type
args += ['arg_%s' % arg.name]
if arg.idx is None:
- decl = '%sarg_%s' % (ctype, arg.name)
+ decl = '%sarg_%s' % (c_type, arg.name)
if type_.role == 'any':
decls = ['%s = *--%s' % (decl, type_.stack)] + decls
elif type_.role == 'leaf':
assert False
else:
idx = arg.idx
- decls = ['%s*arg_%s = %s -= arg_%s' % (ctype, arg.name, type_.stack, idx)] + decls
+ decls = ['%s*arg_%s = %s -= arg_%s' % (c_type, arg.name, type_.stack, idx)] + decls
decls = ['size_t arg_%s = op++->integer' % idx] + decls
idx = 'arg_%s' % idx
type_ = aux['TYPE']
name = aux['NAME']
if type_.role == 'leaf':
- ctype = c_type(type_)
- decls += ['%saux_%s = op++->%s' % (ctype, name, type_.atom)]
+ decls += ['%saux_%s = op++->%s' % (type_.c_type, name, type_.atom)]
args += ['aux_%s' % name]
elif type_.role == 'fixed':
args += [type_.fixed_value]
for arg in op.args:
name = arg.name
type_ = arg.type_
- ctype = c_type(type_)
+ c_type = type_.c_type
if arg.idx is None:
func = "get_%s_arg" % type_.atom
- decls += ["%sarg_%s = %s (node, %s)" % (ctype, name, func, arg_idx)]
+ decls += ["%sarg_%s = %s (node, %s)" % (c_type, name, func, arg_idx)]
else:
decl = "size_t arg_%s = node->n_args" % arg.idx
if arg_idx > 0:
decl += " - %s" % arg_idx
decls += [decl]
- decls += ["%s*arg_%s = get_%s_args (node, %s, arg_%s, e)" % (ctype, name, type_.atom, arg_idx, arg.idx)]
+ decls += ["%s*arg_%s = get_%s_args (node, %s, arg_%s, e)" % (c_type, name, type_.atom, arg_idx, arg.idx)]
arg_idx += 1
sysmis_cond = make_sysmis_decl (op, "node->min_valid")
result = "eval_%s (%s)" % (op.opname, ', '.join(args))
if decls and sysmis_cond is not None:
miss_ret = op.returns.missing_value
- decls += ['%sresult = force_sysmis ? %s : %s' % (c_type(op.returns), miss_ret, result)]
+ decls += ['%sresult = force_sysmis ? %s : %s' % (op.returns.c_type, miss_ret, result)]
result = 'result'
out_file.write("case %s:\n" % opname)