Exemple #1
0
// primType dereferences an array to get the base type.
func primType(typ types.Type) types.Type {
	for {
		typ = typ.Underlying()
		switch p := typ.(type) {
		case *types.Array:
			typ = p.Elem()
		default:
			return typ
		}
	}
}
Exemple #2
0
// isRecord returns if a type is a record.
// The drillDown flag is used to determine if the function
// should keep dereferencing arrays/pointers to get to the base
// type or if it should only go down one level.
func isRecord(typ types.Type, drillDown bool) bool {
loop:
	for {
		typ = typ.Underlying()
		switch x := typ.(type) {
		case *types.Pointer:
			typ = x.Elem().Underlying()
		case *types.Array:
			typ = x.Elem().Underlying()
		default:
			break loop
		}
		if !drillDown {
			break
		}
	}
	_, ok := typ.Underlying().(*types.Record)
	return ok
}
Exemple #3
0
// isArray returns if a type is an array.
func isArray(typ types.Type) bool {
	_, ok := typ.Underlying().(*types.Array)
	return ok
}
Exemple #4
0
// isPointer returns if a type is a pointer.
func isPointer(typ types.Type) bool {
	_, ok := typ.Underlying().(*types.Pointer)
	return ok
}