cython-devel
changeset 1213:302abc2245aa
lists as literal structs
| author | Robert Bradshaw <robertwb@math.washington.edu> |
|---|---|
| date | Tue Oct 07 15:02:54 2008 -0700 (4 years ago) |
| parents | c086038b5c07 |
| children | fd38efcd7236 |
| files | Cython/Compiler/ExprNodes.py Cython/Compiler/PyrexTypes.py |
line diff
1.1 --- a/Cython/Compiler/ExprNodes.py Tue Oct 07 14:20:09 2008 -0700
1.2 +++ b/Cython/Compiler/ExprNodes.py Tue Oct 07 15:02:54 2008 -0700
1.3 @@ -2680,6 +2680,15 @@
1.4 for i in range(len(self.args)):
1.5 arg = self.args[i]
1.6 self.args[i] = arg.coerce_to(base_type, env)
1.7 + elif dst_type.is_struct:
1.8 + if len(self.args) > len(dst_type.scope.var_entries):
1.9 + error(self.pos, "Too may members for '%s'" % dst_type)
1.10 + else:
1.11 + if len(self.args) < len(dst_type.scope.var_entries):
1.12 + warning(self.pos, "Too few members for '%s'" % dst_type, 1)
1.13 + for i, (arg, member) in enumerate(zip(self.args, dst_type.scope.var_entries)):
1.14 + self.args[i] = arg.coerce_to(member.type, env)
1.15 + self.type = dst_type
1.16 else:
1.17 self.type = error_type
1.18 error(self.pos, "Cannot coerce list to type '%s'" % dst_type)
1.19 @@ -2703,13 +2712,19 @@
1.20 (self.result(),
1.21 i,
1.22 arg.py_result()))
1.23 - else:
1.24 + elif self.type.is_ptr:
1.25 code.putln("%s = (%s[]) {" % (self.result(), self.type.base_type))
1.26 - for i, arg in enumerate(self.args):
1.27 + for arg in self.args:
1.28 code.put(arg.result())
1.29 code.put(", ")
1.30 code.putln();
1.31 code.putln("};")
1.32 + else:
1.33 + for arg, member in zip(self.args, self.type.scope.var_entries):
1.34 + code.putln("%s.%s = %s;" % (
1.35 + self.result(),
1.36 + member.cname,
1.37 + arg.result()))
1.38
1.39 def generate_subexpr_disposal_code(self, code):
1.40 # We call generate_post_assignment_code here instead
2.1 --- a/Cython/Compiler/PyrexTypes.py Tue Oct 07 14:20:09 2008 -0700
2.2 +++ b/Cython/Compiler/PyrexTypes.py Tue Oct 07 15:02:54 2008 -0700
2.3 @@ -37,6 +37,7 @@
2.4 # is_null_ptr boolean Is the type of NULL
2.5 # is_cfunction boolean Is a C function type
2.6 # is_struct_or_union boolean Is a C struct or union type
2.7 + # is_struct boolean Is a C struct type
2.8 # is_enum boolean Is a C enum type
2.9 # is_typedef boolean Is a typedef type
2.10 # is_string boolean Is a C char * type
2.11 @@ -88,6 +89,7 @@
2.12 is_null_ptr = 0
2.13 is_cfunction = 0
2.14 is_struct_or_union = 0
2.15 + is_struct = 0
2.16 is_enum = 0
2.17 is_typedef = 0
2.18 is_string = 0
2.19 @@ -929,6 +931,7 @@
2.20 self.kind = kind
2.21 self.scope = scope
2.22 self.typedef_flag = typedef_flag
2.23 + self.is_struct = kind == 'struct'
2.24
2.25 def __repr__(self):
2.26 return "<CStructOrUnionType %s %s%s>" % (self.name, self.cname,
