aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/representation.go
blob: 2d33a45e96db6bc9239b74a74d4de361e9761ab0 (plain)
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
package main

type Protocol struct {
	Name         string
	ExtXName     string
	ExtName      string
	MajorVersion string
	MinorVersion string

	Imports  []*Protocol
	Types    []Type
	Requests []*Request
}

// Initialize traverses all structures, looks for 'Translation' type,
// and looks up the real type in the namespace. It also sets the source
// name for all relevant fields/structures.
// This is necessary because we don't traverse the XML in order initially.
func (p *Protocol) Initialize() {
	for _, typ := range p.Types {
		typ.Initialize(p)
	}
	for _, req := range p.Requests {
		req.Initialize(p)
	}
}

type Request struct {
	srcName string
	xmlName string
	Opcode  int
	Combine bool
	Fields  []Field
	Reply   *Reply
}

func (r *Request) Initialize(p *Protocol) {
	r.srcName = SrcName(r.xmlName)
	if r.Reply != nil {
		r.Reply.Initialize(p)
	}
	for _, field := range r.Fields {
		field.Initialize(p)
	}
}

type Reply struct {
	Fields []Field
}

func (r *Reply) Initialize(p *Protocol) {
	for _, field := range r.Fields {
		field.Initialize(p)
	}
}