From: Ben Pfaff Date: Tue, 14 Dec 2021 06:19:19 +0000 (-0800) Subject: member variable X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d68154ddeabad7ef16592209a0b56d14bbdacf4;p=pspp member variable --- diff --git a/src/language/expressions/generate.py b/src/language/expressions/generate.py index d76e2e6bd9..9d404de61a 100644 --- a/src/language/expressions/generate.py +++ b/src/language/expressions/generate.py @@ -125,17 +125,21 @@ Types with role "fixed" require: 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 @@ -143,15 +147,13 @@ class Type: 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 @@ -159,17 +161,6 @@ def init_type(type_): 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 # Input parsing. @@ -600,12 +591,12 @@ def generate_evaluate_h(): 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'] @@ -614,7 +605,7 @@ def generate_evaluate_h(): 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) @@ -632,10 +623,10 @@ def generate_evaluate_inc(): 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': @@ -644,7 +635,7 @@ def generate_evaluate_inc(): 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 @@ -655,8 +646,7 @@ def generate_evaluate_inc(): 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] @@ -746,17 +736,17 @@ def generate_optimize_inc(): 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") @@ -786,7 +776,7 @@ def generate_optimize_inc(): 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)