// ConvertFunction converts from gosym.Func to
// api.Function.
771035
func ConvertFunction(fn *proc.Function) *Function {
	if fn == nil {
		return nil
	}

	// fn here used to be a *gosym.Func, the fields Type and GoType below
	// corresponded to the homonymous field of gosym.Func. Since the contents of
	// those fields is not documented their value was replaced with 0 when
	// gosym.Func was replaced by debug_info entries.
	return &Function{
		Name_:     fn.Name,
		Type:      0,
		Value:     fn.Entry,
		GoType:    0,
		Optimized: fn.Optimized(),
	}
}
559833
func tryConvert(convertor runtime.ObjectConvertor, object runtime.Object, versions ...string) (runtime.Object, error) {
	var last error
	for _, version := range versions {
		if len(version) == 0 {
			return object, nil
		}
		obj, err := convertor.ConvertToVersion(object, version)
		if err != nil {
			last = err
			continue
		}
		return obj, nil
	}
	return nil, last
}
730398
func (c ConversionFuncs) Add(fns ...interface{}) error {
	for _, fn := range fns {
		fv := reflect.ValueOf(fn)
		ft := fv.Type()
		if err := verifyConversionFunctionSignature(ft); err != nil {
			return err
		}
		c.fns[typePair{ft.In(0).Elem(), ft.In(1).Elem()}] = fv
	}
	return nil
}
1023162
func (conn *ProtectedConn) convert() error {
	conn.mutex.Lock()
	file := os.NewFile(uintptr(conn.socketFd), "")
	// dup the fd and return a copy
	fileConn, err := net.FileConn(file)
	// closes the original fd
	file.Close()
	conn.socketFd = socketError
	if err != nil {
		conn.mutex.Unlock()
		return err
	}
	conn.Conn = fileConn
	conn.mutex.Unlock()
	return nil
}
605044
func convertMap(in map[interface{}]interface{}) map[string]interface{} {
  rtn := make(map[string]interface{})
  for key, val := range in {
    // if the value is a map of interface interfaces
    // make sure to convert them as well    
    var newValue interface{}
    switch val.(type) {
      case []interface{}:
        newValue = convertArray(val.([]interface{}))
      case map[interface{}]interface{}:
        newValue = convertMap(val.(map[interface{}]interface{}))
      default:
        newValue = val
    }

    switch key.(type) {
    case string:
      rtn[key.(string)] = newValue
    }
  }

  return rtn  
}
1053380
func convertVMFunctionToType(rv reflect.Value, rt reflect.Type) (reflect.Value, error) {
	// only translates runVMFunction type
	if !checkIfRunVMFunction(rv.Type()) {
		return rv, fmt.Errorf("invalid type conversion")
	}

	// create runVMConvertFunction to match reflect.Type
	// this function is being called by the Go function
	runVMConvertFunction := func(in []reflect.Value) []reflect.Value {
		// note: this function is being called by another reflect Call
		// only way to pass along any errors is by panic

		// make the reflect.Value slice of each of the VM reflect.Value
		args := make([]reflect.Value, 0, rt.NumIn()+1)
		// for runVMFunction first arg is always context
		// TOFIX: use normal context
		args = append(args, reflect.ValueOf(context.Background()))
		for i := 0; i < rt.NumIn(); i++ {
			// have to do the double reflect.ValueOf that runVMFunction expects
			args = append(args, reflect.ValueOf(in[i]))
		}

		// Call runVMFunction
		rvs := rv.Call(args)

		// call processCallReturnValues to process runVMFunction return values
		// returns normal VM reflect.Value form
		rv, err := processCallReturnValues(rvs, true, false)
		if err != nil {
			panic("function run error: " + err.Error())
		}

		if rt.NumOut() < 1 {
			// Go function does not want any return values, so give it none
			return []reflect.Value{}
		}
		if rt.NumOut() < 2 {
			// Go function wants one return value
			// will try to covert to reflect.Value correct type and return
			rv, err = convertReflectValueToType(rv, rt.Out(0))
			if err != nil {
				panic("function wants return type " + rt.Out(0).String() + " but received type " + rv.Type().String())
			}
			return []reflect.Value{rv}
		}

		// Go function wants more than one return value
		// make sure we have a slice/array with enought values

		if rv.Kind() != reflect.Slice && rv.Kind() != reflect.Array {
			panic(fmt.Sprintf("function wants %v return values but received %v", rt.NumOut(), rv.Kind().String()))
		}
		if rv.Len() < rt.NumOut() {
			panic(fmt.Sprintf("function wants %v return values but received %v values", rt.NumOut(), rv.Len()))
		}

		// try to covert each value in slice to wanted type and put into a reflect.Value slice
		rvs = make([]reflect.Value, rt.NumOut())
		for i := 0; i < rv.Len(); i++ {
			rvs[i], err = convertReflectValueToType(rv.Index(i), rt.Out(i))
			if err != nil {
				panic("function wants return type " + rt.Out(i).String() + " but received type " + rvs[i].Type().String())
			}
		}

		// return created reflect.Value slice
		return rvs
	}

	// make the reflect.Value function that calls runVMConvertFunction
	return reflect.MakeFunc(rt, runVMConvertFunction), nil
}
1188203
func ConvertType(args ...interface{}) string {
	t := args[0].(string)
	p := args[1].(string)

	// Convert softlayer types to golang types
	switch t {
	case "unsignedLong", "unsignedInt":
		return "uint"
	case "boolean":
		return "bool"
	case "dateTime":
		if p != "datatypes" {
			return "datatypes.Time"
		} else {
			return "Time"
		}
	case "decimal", "float":
		if p != "datatypes" {
			return "datatypes.Float64"
		} else {
			return "Float64"
		}
	case "base64Binary":
		return "[]byte"
	case "json", "enum":
		return "string"
	}

	if strings.HasPrefix(t, "SoftLayer_") {
		t = RemovePrefix(t)
		if p != "datatypes" {
			return "datatypes." + t
		}
		return t
	}

	if strings.HasPrefix(t, "McAfee_") {
		if p != "datatypes" {
			return "datatypes." + t
		}
		return t
	}

	return t
}
1192554
func AggregateFunction(metric, stat, cntCol string) string {
	switch stat {
	case "cnt", "sum":
		return fmt.Sprintf("SUM(%s_%s)", metric, stat)
	case "min":
		return fmt.Sprintf("MIN(%s_%s)", metric, stat)
	case "max":
		return fmt.Sprintf("MAX(%s_%s)", metric, stat)
	case "med", "median", "p5", "p95", "pct_95":
		return fmt.Sprintf("AVG(%s_%s)", metric, stat)
	case "avg":
		return fmt.Sprintf("SUM(%s_sum)/SUM(%s)", metric, cntCol)
	default:
		return ""
	}
}
21797
func (s *scope) Convert(src, dest interface{}, flags FieldMatchingFlags) error {
	return s.converter.Convert(src, dest, flags, s.meta)
}
875899
func ConvertFilterParameters(filters []Filter) url.Values {
	params := url.Values{"q": []string{}}
	for _, filter := range filters {
		params["q"] = append(params["q"], filter.format())
	}

	return params
}
1084441
func (a Access) Convert() (C.CFTypeRef, error) {
	return createAccess(a.Label, a.TrustedApplications)
}
797077
func (orig *HogeJSON) Convert() (*Hoge, error) {
	ret := &Hoge{}

	b := NewHogeJSONBuilder().AddAll()
	for _, info := range b._properties {
		if err := info.Decoder(orig, ret); err != nil {
			return nil, err
		}
	}

	return ret, nil
}
556565
func Convert(output, input image.Image, filter Filter) error {
	cfg, err := PrepareConversion(output, input)
	if err != nil {
		return err
	}
	converter, err := NewConverter(cfg, filter)
	if err != nil {
		return err
	}
	return converter.Convert(output, input)
}
872200
func convert(i interface{}) interface{} {
	switch x := i.(type) {
	case map[interface{}]interface{}:
		m2 := map[string]interface{}{}
		for k, v := range x {
			m2[k.(string)] = convert(v)
		}
		return m2
	case []interface{}:
		for i, v := range x {
			x[i] = convert(v)
		}
	}
	return i
}
416324
func (s *Scheme) Convert(in, out interface{}) error {
	return s.raw.Convert(in, out)
}
860238
func (c *Converter) RegisterGeneratedConversionFunc(conversionFunc interface{}) error {
	fv := reflect.ValueOf(conversionFunc)
	ft := fv.Type()
	if err := verifyConversionFunctionSignature(ft); err != nil {
		return err
	}
	c.generatedConversionFuncs[typePair{ft.In(0).Elem(), ft.In(1).Elem()}] = fv
	return nil
}
101438
func GetFunction(function interface{}) *runtime.Func {
	return runtime.FuncForPC(reflect.ValueOf(function).Pointer())
}