q/src/types/ByName.go

36 lines
642 B
Go

package types
import (
"strings"
)
// ByName returns the type with the given name or `nil` if it doesn't exist.
func ByName(name string, pkg string, structs map[string]*Struct) Type {
if strings.HasPrefix(name, "*") {
to := strings.TrimPrefix(name, "*")
return &Pointer{To: ByName(to, pkg, structs)}
}
switch name {
case "Int":
return Int
case "Int64":
return Int64
case "Int32":
return Int32
case "Int16":
return Int16
case "Int8":
return Int8
case "Float":
return Float
case "Float64":
return Float64
case "Float32":
return Float32
case "Pointer":
return PointerAny
}
return structs[pkg+"."+name]
}