Commit 5361eb62 authored by Robert Bradshaw's avatar Robert Bradshaw

lists as literal structs

parent fc97fc88
......@@ -2680,6 +2680,15 @@ class ListNode(SequenceNode):
for i in range(len(self.args)):
arg = self.args[i]
self.args[i] = arg.coerce_to(base_type, env)
elif dst_type.is_struct:
if len(self.args) > len(dst_type.scope.var_entries):
error(self.pos, "Too may members for '%s'" % dst_type)
else:
if len(self.args) < len(dst_type.scope.var_entries):
warning(self.pos, "Too few members for '%s'" % dst_type, 1)
for i, (arg, member) in enumerate(zip(self.args, dst_type.scope.var_entries)):
self.args[i] = arg.coerce_to(member.type, env)
self.type = dst_type
else:
self.type = error_type
error(self.pos, "Cannot coerce list to type '%s'" % dst_type)
......@@ -2703,13 +2712,19 @@ class ListNode(SequenceNode):
(self.result(),
i,
arg.py_result()))
else:
elif self.type.is_ptr:
code.putln("%s = (%s[]) {" % (self.result(), self.type.base_type))
for i, arg in enumerate(self.args):
for arg in self.args:
code.put(arg.result())
code.put(", ")
code.putln();
code.putln("};")
else:
for arg, member in zip(self.args, self.type.scope.var_entries):
code.putln("%s.%s = %s;" % (
self.result(),
member.cname,
arg.result()))
def generate_subexpr_disposal_code(self, code):
# We call generate_post_assignment_code here instead
......
......@@ -37,6 +37,7 @@ class PyrexType(BaseType):
# is_null_ptr boolean Is the type of NULL
# is_cfunction boolean Is a C function type
# is_struct_or_union boolean Is a C struct or union type
# is_struct boolean Is a C struct type
# is_enum boolean Is a C enum type
# is_typedef boolean Is a typedef type
# is_string boolean Is a C char * type
......@@ -88,6 +89,7 @@ class PyrexType(BaseType):
is_null_ptr = 0
is_cfunction = 0
is_struct_or_union = 0
is_struct = 0
is_enum = 0
is_typedef = 0
is_string = 0
......@@ -929,6 +931,7 @@ class CStructOrUnionType(CType):
self.kind = kind
self.scope = scope
self.typedef_flag = typedef_flag
self.is_struct = kind == 'struct'
def __repr__(self):
return "<CStructOrUnionType %s %s%s>" % (self.name, self.cname,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment