/
model_declaration.go
73 lines (65 loc) · 1.12 KB
/
model_declaration.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
package translator
import (
"bytes"
"fmt"
"modernc.org/token"
)
type CTypeKind int
const (
TypeKind CTypeKind = iota
PlainTypeKind
StructKind
OpaqueStructKind
UnionKind
FunctionKind
EnumKind
)
type CType interface {
GetBase() string
GetTag() string
SetRaw(x string)
CGoName() string
GetPointers() uint8
SetPointers(uint8)
AddOuterArr(uint64)
AddInnerArr(uint64)
OuterArrays() ArraySpec
InnerArrays() ArraySpec
OuterArraySizes() []ArraySizeSpec
InnerArraySizes() []ArraySizeSpec
//
IsConst() bool
IsOpaque() bool
IsComplete() bool
Kind() CTypeKind
String() string
Copy() CType
AtLevel(level int) CType
}
type (
Value interface{}
)
type CDecl struct {
Spec CType
Name string
Value Value
Expression string
IsStatic bool
IsTypedef bool
IsDefine bool
Position token.Position
Src string
}
func (c CDecl) String() string {
buf := new(bytes.Buffer)
switch {
case len(c.Name) > 0:
fmt.Fprintf(buf, "%s %s", c.Spec, c.Name)
default:
buf.WriteString(c.Spec.String())
}
if len(c.Expression) > 0 {
fmt.Fprintf(buf, " = %s", string(c.Expression))
}
return buf.String()
}