From 76c9f13e133e09e5633917aecabfe44137f5a4ba Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 6 Nov 2019 12:08:31 +0100 Subject: [PATCH] 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. --- cgo/libclang.go | 5 +++++ cgo/testdata/types.go | 3 +++ cgo/testdata/types.out.go | 2 ++ 3 files changed, 10 insertions(+) diff --git a/cgo/libclang.go b/cgo/libclang.go index 1cbc78c4..514e5326 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 d7276dcb..08d8bb0e 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 bdc2e57f..0f632b88 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