From 6916083427da6df7e641fa765f60787f0d65fd91 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 9 Feb 2010 23:42:32 -0800 Subject: [PATCH] Enable non expression-like types for templates. --- Cython/Compiler/Parsing.py | 20 +++++++++++++++----- Cython/Compiler/Tests/TestBuffer.py | 4 ---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 58b582f3..310f3739 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -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(']') diff --git a/Cython/Compiler/Tests/TestBuffer.py b/Cython/Compiler/Tests/TestBuffer.py index 6a012c0e..44caa446 100644 --- a/Cython/Compiler/Tests/TestBuffer.py +++ b/Cython/Compiler/Tests/TestBuffer.py @@ -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") -- 2.26.2