Commit cd9b22bf authored by Stefan Behnel's avatar Stefan Behnel

Join '*' and '**' parsing in declarators to avoid differences for 'const' parsing etc.

parent d941d208
......@@ -2858,31 +2858,24 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
assignable, nonempty):
pos = s.position()
calling_convention = p_calling_convention(s)
if s.sy == '*':
if s.sy in ('*', '**'):
# scanner returns '**' as a single token
is_ptrptr = s.sy == '**'
s.next()
if s.systring == 'const':
const_pos = s.position()
s.next()
const_base = p_c_declarator(s, ctx, empty = empty,
is_type = is_type,
cmethod_flag = cmethod_flag,
assignable = assignable,
nonempty = nonempty)
base = Nodes.CConstDeclaratorNode(const_pos, base = const_base)
else:
base = p_c_declarator(s, ctx, empty = empty, is_type = is_type,
cmethod_flag = cmethod_flag,
assignable = assignable, nonempty = nonempty)
result = Nodes.CPtrDeclaratorNode(pos,
base = base)
elif s.sy == '**': # scanner returns this as a single token
s.next()
base = p_c_declarator(s, ctx, empty = empty, is_type = is_type,
cmethod_flag = cmethod_flag,
assignable = assignable, nonempty = nonempty)
result = Nodes.CPtrDeclaratorNode(pos,
base = Nodes.CPtrDeclaratorNode(pos,
base = base))
is_const = s.systring == 'const' and s.sy == 'IDENT'
if is_const:
s.next()
base = p_c_declarator(s, ctx, empty=empty, is_type=is_type,
cmethod_flag=cmethod_flag,
assignable=assignable, nonempty=nonempty)
if is_const:
base = Nodes.CConstDeclaratorNode(const_pos, base=base)
if is_ptrptr:
base = Nodes.CPtrDeclaratorNode(pos, base=base)
result = Nodes.CPtrDeclaratorNode(pos, base=base)
elif s.sy == '&':
s.next()
base = p_c_declarator(s, ctx, empty = empty, is_type = is_type,
......
# mode: compile
cdef const_args(const int a, const int *b, const (int*) c, int *const d):
cdef const_args(const int a, const int *b, const (int*) c, int *const d, int **const e, int *const *f):
print a
print b[0]
b = NULL # OK, the pointer itself is not const
c[0] = 4 # OK, the value is not const
d[0] = 7 # OK, the value is not const
e[0][0] = 1 # OK, the value is not const
e[0] = NULL # OK, the pointed pointer is not const
f[0][0] = 1 # OK, the value is not const
f = NULL # OK, the pointer is not const
def call_const_args(x):
cdef int k = x
const_args(x, &k, &k, &k)
cdef int* arr = [x]
const_args(x, &k, &k, &k, &arr, &arr)
......@@ -10,13 +10,19 @@ cdef const int x = 10
cdef struct S:
int member
cdef func(const int a, const int* b, const (int*) c, const S s, int *const d,
cdef func(const int a, const int* b, const (int*) c, const S s, int *const d, int **const e, int *const *f,
const S *const t):
a = 10
c = NULL
b[0] = 100
s.member = 1000
d = NULL
e[0][0] = 1 # ok
e[0] = NULL # ok
e = NULL # nok
f[0][0] = 1 # ok
f[0] = NULL # nok
f = NULL # ok
t = &s
cdef volatile object v
......@@ -30,6 +36,8 @@ _ERRORS = """
17:5: Assignment to const dereference
18:5: Assignment to const attribute 'member'
19:4: Assignment to const 'd'
20:4: Assignment to const 't'
22:5: Const/volatile base type cannot be a Python object
22:4: Assignment to const 'e'
24:5: Assignment to const dereference
26:4: Assignment to const 't'
28:5: Const/volatile base type cannot be a Python object
"""
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