Skip to content

Commit fd56e4b

Browse files
authored
internal/parser:parse unexpose type (#506)
* internal/parser:case for #497 * with unexpose type use canonicalyype * cl:case with #497
1 parent 7f8de48 commit fd56e4b

File tree

7 files changed

+231
-1
lines changed

7 files changed

+231
-1
lines changed

_xtool/internal/parser/parser.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ func (ct *Converter) ProcessType(t clang.Type) ast.Expr {
297297
typeName, typeKind := getTypeDesc(t)
298298
ct.logln("ProcessType: TypeName:", typeName, "TypeKind:", typeKind)
299299

300+
if t.Kind == clang.TypeUnexposed {
301+
// https://github.com/goplus/llcppg/issues/497
302+
return ct.ProcessType(t.CanonicalType())
303+
}
304+
300305
if t.Kind >= clang.TypeFirstBuiltin && t.Kind <= clang.TypeLastBuiltin {
301306
return ct.ProcessBuiltinType(t)
302307
}

_xtool/internal/parser/parser_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
func TestParser(t *testing.T) {
23-
cases := []string{"class", "comment", "enum", "func", "scope", "struct", "typedef", "union", "macro", "forwarddecl1", "forwarddecl2", "include"}
23+
cases := []string{"class", "comment", "enum", "func", "scope", "struct", "typedef", "union", "macro", "forwarddecl1", "forwarddecl2", "include", "typeof"}
2424
// https://github.com/goplus/llgo/issues/1114
2525
// todo(zzy):use os.ReadDir
2626
for _, folder := range cases {
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"_Type": "File",
3+
"decls": [
4+
{
5+
"Doc": {
6+
"List": [
7+
{
8+
"Text": "// https://github.com/goplus/llcppg/issues/497\n",
9+
"_Type": "Comment"
10+
}
11+
],
12+
"_Type": "CommentGroup"
13+
},
14+
"Loc": {
15+
"File": "testdata/typeof/temp.h",
16+
"_Type": "Location"
17+
},
18+
"Name": {
19+
"Name": "spi_mem_dev_t",
20+
"_Type": "Ident"
21+
},
22+
"Parent": null,
23+
"Type": {
24+
"Fields": {
25+
"List": [
26+
{
27+
"Access": 1,
28+
"Comment": null,
29+
"Doc": null,
30+
"IsStatic": false,
31+
"Names": [
32+
{
33+
"Name": "x",
34+
"_Type": "Ident"
35+
}
36+
],
37+
"Type": {
38+
"Flags": 0,
39+
"Kind": 6,
40+
"_Type": "BuiltinType"
41+
},
42+
"_Type": "Field"
43+
},
44+
{
45+
"Access": 1,
46+
"Comment": null,
47+
"Doc": null,
48+
"IsStatic": false,
49+
"Names": [
50+
{
51+
"Name": "clock",
52+
"_Type": "Ident"
53+
}
54+
],
55+
"Type": {
56+
"Fields": {
57+
"List": [
58+
{
59+
"Access": 1,
60+
"Comment": null,
61+
"Doc": null,
62+
"IsStatic": false,
63+
"Names": [
64+
{
65+
"Name": "val",
66+
"_Type": "Ident"
67+
}
68+
],
69+
"Type": {
70+
"Flags": 4,
71+
"Kind": 6,
72+
"_Type": "BuiltinType"
73+
},
74+
"_Type": "Field"
75+
}
76+
],
77+
"_Type": "FieldList"
78+
},
79+
"Methods": null,
80+
"Tag": 1,
81+
"_Type": "RecordType"
82+
},
83+
"_Type": "Field"
84+
}
85+
],
86+
"_Type": "FieldList"
87+
},
88+
"Methods": null,
89+
"Tag": 0,
90+
"_Type": "RecordType"
91+
},
92+
"_Type": "TypeDecl"
93+
},
94+
{
95+
"Doc": null,
96+
"Loc": {
97+
"File": "testdata/typeof/temp.h",
98+
"_Type": "Location"
99+
},
100+
"Name": {
101+
"Name": "gpspi_flash_ll_clock_reg_t",
102+
"_Type": "Ident"
103+
},
104+
"Parent": null,
105+
"Type": {
106+
"Flags": 4,
107+
"Kind": 6,
108+
"_Type": "BuiltinType"
109+
},
110+
"_Type": "TypedefDecl"
111+
},
112+
{
113+
"Doc": null,
114+
"Loc": {
115+
"File": "testdata/typeof/temp.h",
116+
"_Type": "Location"
117+
},
118+
"Name": {
119+
"Name": "gpspi_flash_ll_dev_t",
120+
"_Type": "Ident"
121+
},
122+
"Parent": null,
123+
"Type": {
124+
"Fields": {
125+
"List": [
126+
{
127+
"Access": 1,
128+
"Comment": null,
129+
"Doc": null,
130+
"IsStatic": false,
131+
"Names": [
132+
{
133+
"Name": "clock",
134+
"_Type": "Ident"
135+
}
136+
],
137+
"Type": {
138+
"Name": "gpspi_flash_ll_clock_reg_t",
139+
"_Type": "Ident"
140+
},
141+
"_Type": "Field"
142+
}
143+
],
144+
"_Type": "FieldList"
145+
},
146+
"Methods": null,
147+
"Tag": 1,
148+
"_Type": "RecordType"
149+
},
150+
"_Type": "TypeDecl"
151+
}
152+
],
153+
"includes": null,
154+
"macros": null
155+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://github.com/goplus/llcppg/issues/497
2+
typedef struct {
3+
int x;
4+
union {
5+
long val;
6+
} clock;
7+
} spi_mem_dev_t;
8+
9+
extern spi_mem_dev_t GPSPI2_t;
10+
11+
typedef typeof(GPSPI2_t.clock.val) gpspi_flash_ll_clock_reg_t;
12+
13+
typedef union {
14+
gpspi_flash_ll_clock_reg_t clock;
15+
} gpspi_flash_ll_dev_t;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "typeof",
3+
"include": [
4+
"temp.h"
5+
],
6+
"libs": "$(pkg-config --libs xxx)",
7+
"cplusplus": false
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
===== temp.go =====
2+
package typeof
3+
4+
import (
5+
"github.com/goplus/lib/c"
6+
_ "unsafe"
7+
)
8+
9+
// https://github.com/goplus/llcppg/issues/497
10+
type SpiMemDevT struct {
11+
X c.Int
12+
Clock struct {
13+
Val c.Long
14+
}
15+
}
16+
type GpspiFlashLlClockRegT c.Long
17+
18+
type GpspiFlashLlDevT struct {
19+
Clock GpspiFlashLlClockRegT
20+
}
21+
22+
===== typeof_autogen_link.go =====
23+
package typeof
24+
25+
import _ "github.com/goplus/lib/c"
26+
27+
const LLGoPackage string = "link: $(pkg-config --libs xxx);"
28+
29+
===== llcppg.pub =====
30+
gpspi_flash_ll_clock_reg_t GpspiFlashLlClockRegT
31+
gpspi_flash_ll_dev_t GpspiFlashLlDevT
32+
spi_mem_dev_t SpiMemDevT
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://github.com/goplus/llcppg/issues/497
2+
typedef struct {
3+
int x;
4+
union {
5+
long val;
6+
} clock;
7+
} spi_mem_dev_t;
8+
9+
extern spi_mem_dev_t GPSPI2_t;
10+
11+
typedef typeof(GPSPI2_t.clock.val) gpspi_flash_ll_clock_reg_t;
12+
13+
typedef union {
14+
gpspi_flash_ll_clock_reg_t clock;
15+
} gpspi_flash_ll_dev_t;

0 commit comments

Comments
 (0)