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.
Этот коммит содержится в:
Ayke van Laethem 2019-11-06 12:08:31 +01:00 коммит произвёл Ron Evans
родитель d31deda1b5
коммит 76c9f13e13
3 изменённых файлов: 10 добавлений и 0 удалений

Просмотреть файл

@ -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
}

3
cgo/testdata/types.go предоставленный
Просмотреть файл

@ -38,6 +38,9 @@ typedef enum option {
optionF,
optionG,
} option_t;
enum unused {
unused1 = 5,
};
// Anonymous enum.
typedef enum {

2
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