-
Notifications
You must be signed in to change notification settings - Fork 7
/
misc.go
60 lines (53 loc) · 1.35 KB
/
misc.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
package gotype
import (
"go/ast"
"go/token"
"strings"
)
type importer interface {
appendError(err error)
Import(path string, src string) (Type, error)
ImportName(path string, src string) (name string, goroot bool)
}
// typeName Parses the expression to get the type name and whether it is imported
func typeName(x ast.Expr) (name string, imported bool) {
switch t := x.(type) {
case *ast.Ident: // Defined by the current package
return t.Name, false
case *ast.SelectorExpr: // Defined by the imported
if _, ok := t.X.(*ast.Ident); ok {
return t.Sel.Name, true
}
case *ast.StarExpr:
return typeName(t.X)
}
return
}
func init() {
for i := predeclaredTypesBeg + 1; i != predeclaredTypesEnd; i++ {
k := strings.ToLower(i.String())
predeclaredTypes[k] = i
}
}
var predeclaredTypes = map[string]Kind{}
var tokenTypes = map[token.Token]Kind{
token.INT: Int,
token.FLOAT: Float64,
token.IMAG: Complex128,
token.CHAR: Int32,
token.STRING: String,
}
var builtinFunc = map[string]builtinfunc{
"append": builtinfuncItem,
"close": builtinfuncVoid,
"delete": builtinfuncVoid,
"panic": builtinfuncVoid,
"recover": builtinfuncInterface,
"imag": builtinfuncInt,
"real": builtinfuncInt,
"make": builtinfuncItem,
"new": builtinfuncPtrItem,
"cap": builtinfuncInt,
"copy": builtinfuncInt,
"len": builtinfuncInt,
}