diff options
author | Ayke van Laethem <[email protected]> | 2019-11-06 12:08:31 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-11-06 17:46:20 +0100 |
commit | 76c9f13e133e09e5633917aecabfe44137f5a4ba (patch) | |
tree | e2fd78ba8d13b677264c30ae2d2b2bf21fe68050 /cgo | |
parent | d31deda1b509a96a43e4b8ea433fba8e65ef789d (diff) | |
download | tinygo-76c9f13e133e09e5633917aecabfe44137f5a4ba.tar.gz tinygo-76c9f13e133e09e5633917aecabfe44137f5a4ba.zip |
cgo: include all enums in the CGo Go AST
Not all enums may be used as a type anywhere, which was previously the
only way to include an enum in the AST. This commit makes sure all enums
are included.
Diffstat (limited to 'cgo')
-rw-r--r-- | cgo/libclang.go | 5 | ||||
-rw-r--r-- | cgo/testdata/types.go | 3 | ||||
-rw-r--r-- | cgo/testdata/types.out.go | 2 |
3 files changed, 10 insertions, 0 deletions
diff --git a/cgo/libclang.go b/cgo/libclang.go index 1cbc78c44..514e5326f 100644 --- a/cgo/libclang.go +++ b/cgo/libclang.go @@ -255,6 +255,11 @@ func tinygo_clang_globals_visitor(c, parent C.GoCXCursor, client_data C.CXClient // Parsing was successful. p.constants[name] = constantInfo{expr, pos} } + case C.CXCursor_EnumDecl: + // Visit all enums, because the fields may be used even when the enum + // type itself is not. + typ := C.tinygo_clang_getCursorType(c) + p.makeASTType(typ, pos) } return C.CXChildVisit_Continue } diff --git a/cgo/testdata/types.go b/cgo/testdata/types.go index d7276dcb2..08d8bb0e6 100644 --- a/cgo/testdata/types.go +++ b/cgo/testdata/types.go @@ -38,6 +38,9 @@ typedef enum option { optionF, optionG, } option_t; +enum unused { + unused1 = 5, +}; // Anonymous enum. typedef enum { diff --git a/cgo/testdata/types.out.go b/cgo/testdata/types.out.go index bdc2e57f7..0f632b88f 100644 --- a/cgo/testdata/types.out.go +++ b/cgo/testdata/types.out.go @@ -12,6 +12,7 @@ const C.optionD = -4 const C.optionE = 10 const C.optionF = 11 const C.optionG = 12 +const C.unused1 = 5 type C.int16_t = int16 type C.int32_t = int32 @@ -81,3 +82,4 @@ type C.struct_type1 struct { } type C.struct_type2 struct{ _type C.int } type C.enum_option C.int +type C.enum_unused C.uint |