-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathenumeration-member.go
56 lines (45 loc) · 1.14 KB
/
enumeration-member.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
package generate
import (
"strings"
"unicode"
"unicode/utf8"
"github.com/pekim/jennifer/jen"
)
type Member struct {
Namespace *Namespace
Name string `xml:"name,attr"`
Blacklist bool `xml:"blacklist,attr"`
Value int `xml:"value,attr"`
CIdentifier string `xml:"http://www.gtk.org/introspection/c/1.0 identifier,attr"`
GlibNick string `xml:"http://www.gtk.org/introspection/glib/1.0 nick,attr"`
Doc *Doc `xml:"doc"`
ns *Namespace
name string
goName string
}
func (m *Member) init(ns *Namespace, namePrefix string) {
m.ns = ns
name := strings.TrimPrefix(m.CIdentifier, namePrefix)
firstRune, _ := utf8.DecodeRuneInString(name)
if unicode.IsDigit(firstRune) {
// Make name a legal Go identifier (cannot start with a digit).
name = "_" + name
}
m.name = name
m.goName = name
}
func (m *Member) mergeAddenda(addenda *Member) {
m.Blacklist = addenda.Blacklist
}
func (m *Member) generate(g *jen.Group, goTypeName string) {
if m.Blacklist {
g.Commentf("Blacklisted member : %s", m.CIdentifier)
return
}
// declare a member constant
g.
Id(m.goName).
Id(goTypeName).
Op("=").
Lit(m.Value)
}