call struct constructor
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 8 Oct 2008 03:36:03 +0000 (20:36 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 8 Oct 2008 03:36:03 +0000 (20:36 -0700)
Cython/Compiler/ExprNodes.py

index ff1494fb9182651cb389bc333d022168f4b4b761..be4389eecab46bf3f024f33eee5201d8f6fd0bfe 100644 (file)
@@ -1862,6 +1862,21 @@ class CallNode(ExprNode):
         # Make sure we're not in a nogil environment
         if env.nogil:
             error(self.pos, "Calling gil-requiring function without gil")
+    
+    def analyse_as_type_constructor(self, env):
+        type = self.function.analyse_as_type(env)
+        if type and type.is_struct_or_union:
+            args, kwds = self.explicit_args_kwds()
+            items = []
+            for arg, member in zip(args, type.scope.var_entries):
+                items.append(DictItemNode(pos=arg.pos, key=NameNode(pos=arg.pos, name=member.name), value=arg))
+            if kwds:
+                items += kwds.key_value_pairs
+            self.key_value_pairs = items
+            self.__class__ = DictNode
+            self.analyse_types(env)
+            self.coerce_to(type, env)
+            return True
 
 
 class SimpleCallNode(CallNode):
@@ -1907,6 +1922,8 @@ class SimpleCallNode(CallNode):
         return self.args, None
 
     def analyse_types(self, env):
+        if self.analyse_as_type_constructor(env):
+            return
         function = self.function
         function.is_called = 1
         self.function.analyse_types(env)
@@ -2142,6 +2159,8 @@ class GeneralCallNode(CallNode):
         return self.positional_args.args, self.keyword_args
 
     def analyse_types(self, env):
+        if self.analyse_as_type_constructor(env):
+            return
         self.function.analyse_types(env)
         self.positional_args.analyse_types(env)
         if self.keyword_args: