Fix empty multi-dimensional array declarations.
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 19 Feb 2010 01:49:10 +0000 (17:49 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 19 Feb 2010 01:49:10 +0000 (17:49 -0800)
Cython/Compiler/Nodes.py

index fd4460cbb49f44c48d0241dc7c70e1e09e4e9e96..4302b999a7683e345cb07892e0411141cc6a6c27 100644 (file)
@@ -661,6 +661,17 @@ class CArgDeclNode(Node):
             base_type = self.base_type.analyse(env, could_be_name = could_be_name)
             if hasattr(self.base_type, 'arg_name') and self.base_type.arg_name:
                 self.declarator.name = self.base_type.arg_name
+            # The parser is unable to resolve the ambiguity of [] as part of the 
+            # type (e.g. in buffers) or empty declarator (as with arrays). 
+            # This is only arises for empty multi-dimensional arrays.
+            if (base_type.is_array 
+                    and isinstance(self.base_type, TemplatedTypeNode) 
+                    and isinstance(self.declarator, CArrayDeclaratorNode)):
+                declarator = self.declarator
+                while isinstance(declarator.base, CArrayDeclaratorNode):
+                    declarator = declarator.base
+                declarator.base = self.base_type.array_declarator
+                base_type = base_type.base_type
             return self.declarator.analyse(base_type, env, nonempty = nonempty)
         else:
             return self.name_declarator, self.type
@@ -821,7 +832,7 @@ class TemplatedTypeNode(CBaseTypeNode):
         
         else:
             # Array
-            empty_declarator = CNameDeclaratorNode(self.pos, name="")
+            empty_declarator = CNameDeclaratorNode(self.pos, name="", cname=None)
             if len(self.positional_args) > 1 or self.keyword_args.key_value_pairs:
                 error(self.pos, "invalid array declaration")
                 self.type = PyrexTypes.error_type
@@ -832,9 +843,10 @@ class TemplatedTypeNode(CBaseTypeNode):
                     dimension = None
                 else:
                     dimension = self.positional_args[0]
-                self.type = CArrayDeclaratorNode(self.pos, 
+                self.array_declarator = CArrayDeclaratorNode(self.pos, 
                     base = empty_declarator, 
-                    dimension = dimension).analyse(base_type, env)[1]
+                    dimension = dimension)
+                self.type = self.array_declarator.analyse(base_type, env)[1]
         
         return self.type