Commit 573f3fe4 authored by Stefan Behnel's avatar Stefan Behnel

Allow the short form "cdef struct xyz: pass" instead of always requiring a block for it.

Closes #2802.
parent 0907d71f
...@@ -3184,18 +3184,22 @@ def p_c_struct_or_union_definition(s, pos, ctx): ...@@ -3184,18 +3184,22 @@ def p_c_struct_or_union_definition(s, pos, ctx):
attributes = None attributes = None
if s.sy == ':': if s.sy == ':':
s.next() s.next()
s.expect('NEWLINE')
s.expect_indent()
attributes = [] attributes = []
body_ctx = Ctx() if s.sy == 'pass':
while s.sy != 'DEDENT': s.next()
if s.sy != 'pass': s.expect_newline("Expected a newline", ignore_semicolon=True)
attributes.append( else:
p_c_func_or_var_declaration(s, s.position(), body_ctx)) s.expect('NEWLINE')
else: s.expect_indent()
s.next() body_ctx = Ctx()
s.expect_newline("Expected a newline") while s.sy != 'DEDENT':
s.expect_dedent() if s.sy != 'pass':
attributes.append(
p_c_func_or_var_declaration(s, s.position(), body_ctx))
else:
s.next()
s.expect_newline("Expected a newline")
s.expect_dedent()
else: else:
s.expect_newline("Syntax error in struct or union definition") s.expect_newline("Syntax error in struct or union definition")
return Nodes.CStructOrUnionDefNode(pos, return Nodes.CStructOrUnionDefNode(pos,
......
cdef extern from "cdefemptysue.h":
cdef struct spam:
pass
ctypedef union eggs:
pass
cdef enum ham:
pass
cdef extern spam s
cdef extern eggs e
cdef extern ham h
# mode: compile
# tag: struct, union, enum, cdefextern
cdef extern from *:
"""
struct spam { int a; };
struct flat_spam { int a; };
typedef struct { int a; } flat_spam_type;
typedef union { int a; long b; } eggs;
typedef union { int a; long b; } flat_eggs;
enum ham { TOAST };
enum flat_ham { FLAT_TOAST };
"""
cdef struct spam:
pass
cdef struct flat_spam: pass
ctypedef struct flat_spam_type: pass
ctypedef union eggs:
pass
ctypedef union flat_eggs: pass
cdef enum ham:
pass
cdef enum flat_ham: pass
cdef extern spam s
cdef extern flat_spam fs
cdef extern flat_spam_type fst
cdef extern eggs e
cdef extern flat_eggs fe
cdef extern ham h
cdef extern flat_ham fh
# mode: compile
# tag: struct, union, enum, cdefextern
cdef extern from "cheese.h": cdef extern from "cheese.h":
ctypedef int camembert ctypedef int camembert
...@@ -9,11 +12,12 @@ cdef extern from "cheese.h": ...@@ -9,11 +12,12 @@ cdef extern from "cheese.h":
void cheddar() void cheddar()
class external.runny [object runny_obj]: # FIXME: find a real declaration here.
cdef int a #class external.runny [object runny_obj]:
def __init__(self): # cdef int a
pass # def __init__(self):
# pass
cdef runny r #cdef runny r = runny()
r = x #r.a = 42
r.a = 42
...@@ -8,8 +8,21 @@ ctypedef union eggs: ...@@ -8,8 +8,21 @@ ctypedef union eggs:
cdef enum ham: cdef enum ham:
pass pass
cdef struct flat_spam: pass
ctypedef union flat_eggs: pass
cdef enum flat_ham: pass
_ERRORS = u""" _ERRORS = u"""
3:5: Empty struct or union definition not allowed outside a 'cdef extern from' block 3:5: Empty struct or union definition not allowed outside a 'cdef extern from' block
6:0: Empty struct or union definition not allowed outside a 'cdef extern from' block 6:0: Empty struct or union definition not allowed outside a 'cdef extern from' block
9:5: Empty enum definition not allowed outside a 'cdef extern from' block 9:5: Empty enum definition not allowed outside a 'cdef extern from' block
13:5: Empty struct or union definition not allowed outside a 'cdef extern from' block
15:0: Empty struct or union definition not allowed outside a 'cdef extern from' block
17:5: Empty enum definition not allowed outside a 'cdef extern from' block
""" """
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