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