-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathconfig.go
More file actions
102 lines (82 loc) · 2.36 KB
/
config.go
File metadata and controls
102 lines (82 loc) · 2.36 KB
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
package config
import (
"encoding/json"
"fmt"
"github.com/goplus/llcppg/ast"
)
const LLCPPG_CFG = "llcppg.cfg"
const LLCPPG_SYMB = "llcppg.sym.json"
const LLCPPG_SIGFETCH = "llcppg.sigfetch.json"
const LLCPPG_PUB = "llcppg.pub"
type Condition struct {
OS []string `json:"os"`
Arch []string `json:"arch"`
}
type ImplFiles struct {
Files []string `json:"files"`
Cond Condition `json:"cond"`
}
// Config represents a configuration for the llcppg tool.
type Config struct {
Name string `json:"name"`
CFlags string `json:"cflags"`
// NOTE(MeterosLiu): libs can be empty when we're in headerOnly mode
Libs string `json:"libs,omitempty"`
Include []string `json:"include"`
TrimPrefixes []string `json:"trimPrefixes,omitempty"`
Cplusplus bool `json:"cplusplus,omitempty"`
Deps []string `json:"deps,omitempty"`
KeepUnderScore bool `json:"keepUnderScore,omitempty"`
Impl []ImplFiles `json:"impl,omitempty"`
Mix bool `json:"mix,omitempty"`
SymMap map[string]string `json:"symMap,omitempty"`
TypeMap map[string]string `json:"typeMap,omitempty"`
StaticLib bool `json:"staticLib,omitempty"`
HeaderOnly bool `json:"headerOnly,omitempty"`
}
// json middleware for validating
func (c *Config) UnmarshalJSON(data []byte) error {
// create a new type here to avoid unmarshalling infinite loop.
type newConfig Config
var config newConfig
err := json.Unmarshal(data, &config)
if err != nil {
return err
}
*c = Config(config)
// do some check
// when headeronly mode is disabled, libs must not be empty.
if c.Libs == "" && !c.HeaderOnly {
return fmt.Errorf("%w: libs must not be empty", ErrConfig)
}
return nil
}
func NewDefault() *Config {
return &Config{}
}
type SymbolInfo struct {
Mangle string `json:"mangle"` // C++ Symbol
CPP string `json:"c++"` // C++ function name
Go string `json:"go"` // Go function name
}
// for better debug
func (s *SymbolInfo) String() string {
if s == nil {
return "<nil>"
}
return fmt.Sprintf("Go: %s CPP: %s Mangle: %s", s.Go, s.CPP, s.Mangle)
}
type FileType uint
const (
Inter FileType = iota + 1
Impl
Third
Plat
)
type FileInfo struct {
FileType FileType
}
type Pkg struct {
File *ast.File
FileMap map[string]*FileInfo
}