// IsPtrArrayPtr returns true if FieldInfo is pointer of pointer array, otherwise returns false.
162708
func (f *FieldInfo) IsPtrArrayPtr() bool {
	star, ok := f.Type.(*ast.StarExpr)
	if !ok {
		return false
	}
	array, ok := star.X.(*ast.ArrayType)
	if !ok {
		return false
	}
	_, ok = array.Elt.(*ast.StarExpr)
	return ok
}
731103
func isOutputPtrOfPrim(fnName string, p bg.Parameter) bool {
	if !isOutput(fnName, p) && !isIO(fnName, p) {
		return false
	}
	if !p.IsPointer() {
		return false
	}
	return isBuiltin(depointerize(nameOfType(p.Type())))
}
691398
func NewStringPtr(val string) *string {
	ptrValue := new(string)
	*ptrValue = val
	return ptrValue
}
483693
func (f *formatState) formatPtr(v reflect.Value) {
	// Display nil if top level pointer is nil.
	showTypes := f.fs.Flag('#')
	if v.IsNil() && (!showTypes || f.ignoreNextType) {
		f.fs.Write(nilAngleBytes)
		return
	}

	// Remove pointers at or below the current depth from map used to detect
	// circular refs.
	for k, depth := range f.pointers {
		if depth >= f.depth {
			delete(f.pointers, k)
		}
	}

	// Keep list of all dereferenced pointers to possibly show later.
	pointerChain := make([]uintptr, 0)

	// Figure out how many levels of indirection there are by derferencing
	// pointers and unpacking interfaces down the chain while detecting circular
	// references.
	nilFound := false
	cycleFound := false
	indirects := 0
	ve := v
	for ve.Kind() == reflect.Ptr {
		if ve.IsNil() {
			nilFound = true
			break
		}
		indirects++
		addr := ve.Pointer()
		pointerChain = append(pointerChain, addr)
		if pd, ok := f.pointers[addr]; ok && pd < f.depth {
			cycleFound = true
			indirects--
			break
		}
		f.pointers[addr] = f.depth

		ve = ve.Elem()
		if ve.Kind() == reflect.Interface {
			if ve.IsNil() {
				nilFound = true
				break
			}
			ve = ve.Elem()
		}
	}

	// Display type or indirection level depending on flags.
	if showTypes && !f.ignoreNextType {
		f.fs.Write(openParenBytes)
		f.fs.Write(bytes.Repeat(asteriskBytes, indirects))
		f.fs.Write([]byte(ve.Type().String()))
		f.fs.Write(closeParenBytes)
	} else {
		if nilFound || cycleFound {
			indirects += strings.Count(ve.Type().String(), "*")
		}
		f.fs.Write(openAngleBytes)
		f.fs.Write([]byte(strings.Repeat("*", indirects)))
		f.fs.Write(closeAngleBytes)
	}

	// Display pointer information depending on flags.
	if f.fs.Flag('+') && (len(pointerChain) > 0) {
		f.fs.Write(openParenBytes)
		for i, addr := range pointerChain {
			if i > 0 {
				f.fs.Write(pointerChainBytes)
			}
			printHexPtr(f.fs, addr)
		}
		f.fs.Write(closeParenBytes)
	}

	// Display dereferenced value.
	switch {
	case nilFound:
		f.fs.Write(nilAngleBytes)

	case cycleFound:
		f.fs.Write(circularShortBytes)

	default:
		f.ignoreNextType = true
		f.format(ve)
	}
}
1083963
func EnforcePtr(obj interface{}) (reflect.Value, error) {
	v := reflect.ValueOf(obj)
	if v.Kind() != reflect.Ptr {
		if v.Kind() == reflect.Invalid {
			return reflect.Value{}, fmt.Errorf("expected pointer, but got invalid kind")
		}
		return reflect.Value{}, fmt.Errorf("expected pointer, but got %v type", v.Type())
	}
	if v.IsNil() {
		return reflect.Value{}, fmt.Errorf("expected pointer, but got nil")
	}
	return v.Elem(), nil
}
212471
func toAddrPointer(i *interface{}, isptr, deref bool) pointer {
	v := reflect.ValueOf(*i)
	u := reflect.New(v.Type())
	u.Elem().Set(v)
	if deref {
		u = u.Elem()
	}
	return pointer{v: u}
}
615165
func UintptrArray(name string, values []uintptr) FieldOpt {
	inType := inTypeNull
	var writeItem func(*eventData, uintptr)
	switch unsafe.Sizeof(values[0]) {
	case 4:
		inType = inTypeHexInt32
		writeItem = func(ed *eventData, item uintptr) { ed.writeUint32(uint32(item)) }
	case 8:
		inType = inTypeHexInt64
		writeItem = func(ed *eventData, item uintptr) { ed.writeUint64(uint64(item)) }
	default:
		panic("Unsupported uintptr size")
	}

	return func(em *eventMetadata, ed *eventData) {
		em.writeArray(name, inType, outTypeDefault, 0)
		ed.writeUint16(uint16(len(values)))
		for _, v := range values {
			writeItem(ed, v)
		}
	}
}
385290
func CastToBoolPtr(value interface{}) (*bool, bool) {
	castedValue, ok := CastToBool(value)
	if !ok {
		return nil, false
	}
	return pointers.NewBoolPtr(castedValue), true
}
330540
func (f *FieldInfo) IsArrayPtr() bool {
	array, ok := f.Type.(*ast.ArrayType)
	if !ok {
		return false
	}
	_, ok = array.Elt.(*ast.StarExpr)
	return ok
}
828963
func IntArray(name string, values []int) FieldOpt {
	inType := inTypeNull
	var writeItem func(*eventData, int)
	switch unsafe.Sizeof(values[0]) {
	case 4:
		inType = inTypeInt32
		writeItem = func(ed *eventData, item int) { ed.writeInt32(int32(item)) }
	case 8:
		inType = inTypeInt64
		writeItem = func(ed *eventData, item int) { ed.writeInt64(int64(item)) }
	default:
		panic("Unsupported int size")
	}

	return func(em *eventMetadata, ed *eventData) {
		em.writeArray(name, inType, outTypeDefault, 0)
		ed.writeUint16(uint16(len(values)))
		for _, v := range values {
			writeItem(ed, v)
		}
	}
}
844277
func IsArrContainStr(arr []string, s string) bool {
	for _, record := range arr {
		if record == s {
			return true
		}
	}
	return false
}
990346
func (a *AttributeDefinition) IsPrimitivePointer(attName string) bool {
	if !a.Type.IsObject() {
		panic("checking pointer field on non-object") // bug
	}
	att := a.Type.ToObject()[attName]
	if att == nil {
		return false
	}
	if att.Type.IsPrimitive() {
		return (!a.IsRequired(attName) && !a.HasDefaultValue(attName) && !a.IsNonZero(attName) && !a.IsInterface(attName)) || a.IsFile(attName)
	}
	return false
}
546732
func AllocStructPtrs(val reflect.Value) {
	switch val.Kind() {
	case reflect.Struct:
		for i := 0; i < val.Type().NumField(); i++ {
			field := val.Field(i)
			AllocStructPtrs(field)
		}
	case reflect.Ptr:
		v := MakeNewType(val.Type(), 0)
		//TODO: Make recursivy better, include val.Type == v.Type....
		if isRecursive(v) {
			//panic(fmt.Sprintf("struct %v have a field of the same type of this struct", NameOf(v.Type())))
			return
		}
		if val.Type() == v.Type() {
			return
		}
		AllocStructPtrs(v.Elem())
		if val.CanSet() {
			val.Set(v)
		}
	case reflect.Slice:
		v := MakeNewType(val.Type(), 0)
		elem := v.Type().Elem()
		if elem.Kind() == reflect.Ptr && elem.Elem() == v.Type() {
			return
		}
		if val.CanSet() {
			val.Set(v)
		}
	}
}
1134924
func (ua *Uint64Array) Uint64ArrayOr(or []uint64) []uint64 {
	switch {
	case ua == nil:
		return or
	case !ua.Valid:
		return or
	default:
		return ua.Uint64Array
	}
}
692168
func IsArrayType(t string) bool {
	tip := raml.Type{
		Type: t,
	}
	return tip.IsArray()
}
971388
func CastToMapStringInterfacePtr(value interface{}) (*map[string]interface{}, bool) {
	casted, ok := CastToMapStringInterface(value)
	if !ok {
		return nil, false
	}
	return pointers.NewMapStringInterfacePtr(casted), true
}
450867
func (ba *BoolArray) BoolArrayOr(or []bool) []bool {
	switch {
	case ba == nil:
		return or
	case !ba.Valid:
		return or
	default:
		return ba.BoolArray
	}
}