Support for empty struct/union
This commit is contained in:
parent
c89a741095
commit
6584a304d5
3 changed files with 11 additions and 5 deletions
|
|
@ -183,7 +183,10 @@ proc initGrammar() =
|
|||
break
|
||||
|
||||
if gStateRT.types.addNewIdentifer(nname):
|
||||
gStateRT.typeStr &= &" {nname}* {{.importc: \"{prefix}{name}\", header: {gStateRT.currentHeader}, bycopy.}} = object{union}\n"
|
||||
if gStateRT.data.len == 1:
|
||||
gStateRT.typeStr &= &" {nname}* {{.bycopy.}} = object{union}\n"
|
||||
else:
|
||||
gStateRT.typeStr &= &" {nname}* {{.importc: \"{prefix}{name}\", header: {gStateRT.currentHeader}, bycopy.}} = object{union}\n"
|
||||
|
||||
var
|
||||
i = fstart
|
||||
|
|
@ -273,7 +276,7 @@ proc initGrammar() =
|
|||
"""
|
||||
|
||||
fieldListGrammar = &"""
|
||||
(field_declaration_list
|
||||
(field_declaration_list?
|
||||
(field_declaration+
|
||||
{typeGrammar}
|
||||
(pointer_declarator!
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ extern "C" {
|
|||
typedef uint8_t PRIMTYPE;
|
||||
typedef PRIMTYPE CUSTTYPE;
|
||||
|
||||
struct STRUCT0;
|
||||
|
||||
struct STRUCT1 {
|
||||
int field1;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ var
|
|||
pt: PRIMTYPE
|
||||
ct: CUSTTYPE
|
||||
|
||||
s: STRUCT1
|
||||
s0: STRUCT0
|
||||
s1: STRUCT1
|
||||
s2: STRUCT2
|
||||
s3: STRUCT3
|
||||
s4: STRUCT4
|
||||
|
|
@ -52,7 +53,7 @@ var
|
|||
pt = 3
|
||||
ct = 4
|
||||
|
||||
s.field1 = 5
|
||||
s1.field1 = 5
|
||||
s2.field1 = 6
|
||||
s3.field1 = 7
|
||||
s4.field2[2] = 5
|
||||
|
|
@ -80,7 +81,7 @@ i = 5
|
|||
check test_call_int() == 5
|
||||
check test_call_param(5).field1 == 5
|
||||
check test_call_param2(5, s2).field1 == 11
|
||||
check test_call_param3(5, s).field1 == 10
|
||||
check test_call_param3(5, s1).field1 == 10
|
||||
# error: assigning to 'enum ENUM' from incompatible type 'NI' (aka 'long long')
|
||||
when defined(cpp):
|
||||
discard # TODO
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue