Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.

Commit 1c1bac7

Browse files
authored
Merge pull request chapel-lang#6498 from Spartee/fwDec_c2chap
implemented a fix for Struct forward declarations in c2chapel. Added testing to empty struct and typedef structs. reviewer = [Ben Harshbarger]
2 parents 38924eb + d71cd4e commit 1c1bac7

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

tools/c2chapel/c2chapel.py

+5
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ def genStruct(struct, name=""):
314314

315315
ret = "extern record " + name + " {"
316316
foundTypes.add(name)
317+
318+
# Forward Declaration
319+
if not struct.decls:
320+
print()
321+
return
317322

318323
members = ""
319324
warnKeyword = False

tools/c2chapel/test/miscTypedef.chpl

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ extern proc retStruct(a : my_int, b : my_int, r : renamedStruct) : fancyStruct;
1717

1818
extern proc tdPointer(ref a : fancyStruct, ref b : c_ptr(renamedStruct)) : void;
1919

20+
21+
22+
extern record forwardStruct {
23+
var a : c_int;
24+
var b : c_int;
25+
}
26+
2027
// ==== c2chapel typedefs ====
2128

2229
extern record fancyStruct {
@@ -26,6 +33,8 @@ extern record fancyStruct {
2633
var d : simpleStruct;
2734
}
2835

36+
extern type fwdStruct = forwardStruct;
37+
2938
extern type my_int = c_int;
3039

3140
extern type my_string = c_string;

tools/c2chapel/test/miscTypedef.h

+11
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ typedef struct {
3030
int i;
3131
char c;
3232
} *recp;
33+
34+
struct empty_struct;
35+
36+
struct forwardStruct;
37+
typedef struct forwardStruct fwdStruct;
38+
39+
struct forwardStruct {
40+
int a;
41+
int b;
42+
};
43+

0 commit comments

Comments
 (0)