-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathpresets.go
103 lines (98 loc) · 4.58 KB
/
presets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import "strings"
// Preset is a set of rules iperative to XXX_templates/ json files.
// They are used to manually set some properties of the generator.
type Preset struct {
// SkipFuncs functions (from definitions.json) to be skipped
// e.g. they are temporarily hard-coded
SkipFuncs map[CIdentifier]bool
// SkipStructs allows to specify struct names that will be skipped.
SkipStructs map[CIdentifier]bool
// SkipMethods struct names from structs_and_enums.json.
// structures that's METHODS should be skipped
SkipMethods map[CIdentifier]bool
// SkipTypedefs typedefs from typedefs_dict.json to be skipped
// e.g. for hardcoded typedefs or typedefs which are obvious (e.g. ImU16 becomes uint16 without extra type information)
SkipTypedefs map[CIdentifier]bool
// TypedefsPoolSize sets a default size for callbacks pool.
// Rembmber to set this as it defaults to 0 and you'll get no callbacks!
TypedefsPoolSize int
// TypedefsCustomPoolSizes allows to override TypedefsPoolSize for certain types.
TypedefsCustomPoolSizes map[CIdentifier]int
// Replace is a map for C -> Go names conversion.
// It allows you to force-rename anything (including functions and enums)
Replace map[CIdentifier]GoIdentifier
// TrimPrefix allows to remove unwanted prefixes from everything during C->Go renaming.
// NOTE: order sensitive!
// NOTE: Case sensitive
TrimPrefix []string
// OriginReplace allows to force-replace function name with some other name.
// Introduced to replace TextEditor_GetText -> TextEditor_GetText_alloc
// but could be re-used to force use of another function than json tells us to use.
//
// It differs from Replace - Replace renames an identifier in general (changes its name but refers to the same function).
// This allows to absolutely abandon the source C function and use some OTHER C function.
OriginReplace map[CIdentifier]CIdentifier
// DefaultArgReplace is used in C-side default args generation (gencpp.go).
// cimgui-go uses this to change FLT_MIN with igGet_FLT_MIN()
// NOTE: Iterated randomly!
DefaultArgReplace map[CIdentifier]CIdentifier
// DefaultArgArbitraryValue is similar to the above DefaultArgReplace, but
// associates default arg name with any arbitrary value.
// cimgui-go uses this to set text_end to 0
DefaultArgArbitraryValue map[CIdentifier]CIdentifier
// ExtraCGOPreamble allows to specify additional C code elements in Go files.
// For example could be used to Include extra files.
// For ease of use, its in form of []string. These lines will be merged and prefixed (if appliable) with '//'
ExtraCGOPreamble []string
// InternalFiles allows to specify files that are considered Internal.
// If an identifier is found in such a file, it will be generated but its
// name will be prefixed with InternalPrefix
InternalFiles []string
// InternalPrefix is a prefix for identifiers from InternalFiles.
InternalPrefix string
// PackagePath is an import path of the package.
// This is base path. flags.PackageName will be added.
// Example:
// "github.com/AllenDang/cimgui-go"
// If enerated with -pkg imgui, import path
// is supposed to be "github.com/AllenDang/cimgui-go/imgui"
PackagePath string
// SimpleTypes are used for simple (go-convertable) custom types (wrappers will be generated by simpleW/simpleR).
// Example:
// ImS16 is defined as short in C code, so Go can easily convert it via int16()
// Expected format is:
// "ImS16": ["int16", "C.ImS16", "pkgname"]
// where:
// - ImS16 is a C type name
// - int16 is a Go-friendly type name
// - C.ImS16 is a cgo compatible type name
// - pkgname is a source package for the type (in this case int16 is a builtin so it should be empty)
// See also: simpleW
SimpleTypes map[CIdentifier][3]GoIdentifier
// SimplePtrTypes are just like SimpleTypes but for pointer types.
// Example:
// "ImS16": ["int16", "C.ImS16", "pkgname"]
SimplePtrTypes map[CIdentifier][3]GoIdentifier
// WrappableTypes are types that implement a special interface
// github.com/AllenDang/cimgui-go/internal.WrappableType[CTYPE, SELF]
// In short they are supposed to have 2 methods:
// - ToC() CTYPE which returns SELF converted to CTYPE
// - FromC(CTYPE) SELF which restores SELF from CTYPE.
//
// Key is a C type name, value is a list:
// - Go name
// - C name
// - package where the type is defined
// Example syntax:
// "ImVec2": ["Vec2", "C.ImVec2", "imgui"]
WrappableTypes map[CIdentifier][3]GoIdentifier
}
func (p *Preset) MergeCGoPreamble() string {
result := ""
for _, line := range p.ExtraCGOPreamble {
result += "// " + line + "\n"
}
result = strings.TrimSuffix(result, "\n")
return result
}