Enable non expression-like types for templates.
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 10 Feb 2010 07:42:32 +0000 (23:42 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 10 Feb 2010 07:42:32 +0000 (23:42 -0800)
Cython/Compiler/Parsing.py
Cython/Compiler/Tests/TestBuffer.py

index 58b582f334c0f0c1c636e555daaca14c35fac3ab..310f37395620f74e9853068c09695d8f642f93ad 100644 (file)
@@ -1732,6 +1732,8 @@ def p_positional_and_keyword_args(s, end_sy_set, type_positions=(), type_keyword
     type_positions and type_keywords specifies which argument
     positions and/or names which should be interpreted as
     types. Other arguments will be treated as expressions.
+    A value of None indicates all positions/keywords 
+    (respectively) will be treated as types. 
 
     Returns: (positional_args, keyword_args)
     """
@@ -1754,8 +1756,11 @@ def p_positional_and_keyword_args(s, end_sy_set, type_positions=(), type_keyword
             if s.sy == '=':
                 s.next()
                 # Is keyword arg
-                if ident in type_keywords:
-                    arg = p_c_base_type(s)
+                if type_keywords is None or ident in type_keywords:
+                    base_type = p_c_base_type(s)
+                    declarator = p_c_declarator(s, empty = 1)
+                    arg = Nodes.CComplexBaseTypeNode(base_type.pos, 
+                        base_type = base_type, declarator = declarator)
                     parsed_type = True
                 else:
                     arg = p_simple_expr(s)
@@ -1767,8 +1772,11 @@ def p_positional_and_keyword_args(s, end_sy_set, type_positions=(), type_keyword
                 s.put_back('IDENT', ident)
                 
         if not was_keyword:
-            if pos_idx in type_positions:
-                arg = p_c_base_type(s)
+            if type_positions is None or pos_idx in type_positions:
+                base_type = p_c_base_type(s)
+                declarator = p_c_declarator(s, empty = 1)
+                arg = Nodes.CComplexBaseTypeNode(base_type.pos, 
+                    base_type = base_type, declarator = declarator)
                 parsed_type = True
             else:
                 arg = p_simple_expr(s)
@@ -1890,8 +1898,10 @@ def p_buffer_or_template(s, base_type_node):
     # s.sy == '['
     pos = s.position()
     s.next()
+    # Note that buffer_positional_options_count=1, so the only positional argument is dtype. 
+    # For templated types, all parameters are types. 
     positional_args, keyword_args = (
-        p_positional_and_keyword_args(s, (']',), (0,), ('dtype',))
+        p_positional_and_keyword_args(s, (']',), None, ('dtype',))
     )
     s.expect(']')
 
index 6a012c0e21c9378911fb57568d905e45952e8e8b..44caa446b2e14b4e7debeca1241bf86d8a1d53ae 100644 (file)
@@ -36,10 +36,6 @@ class TestBufferParsing(CythonTest):
         self.not_parseable("Expected: expression",
                            u"cdef object[foo2=short unsigned int] x")
 
-    def test_notype_as_expr2(self):
-        self.not_parseable("Expected: expression",
-                           u"cdef object[int, short unsigned int] x")
-
     def test_pos_after_key(self):
         self.not_parseable("Non-keyword arg following keyword arg",
                            u"cdef object[foo=1, 2] x")