// MutRowFromTypes creates a MutRow from a FieldType slice, each column is initialized to zero value.
514250
func MutRowFromTypes(types []*types.FieldType) MutRow {
	c := &Chunk{columns: make([]*column, 0, len(types))}
	for _, tp := range types {
		col := makeMutRowColumn(zeroValForType(tp))
		c.columns = append(c.columns, col)
	}
	return MutRow{c: c, idx: 0}
}
4995
func (p *gc_parser) parse_struct_type() ast.Expr {
	var fields []*ast.Field
	parse_field := func() {
		fld := p.parse_field()
		fields = append(fields, fld)
	}

	p.expect_keyword("struct")
	p.expect('{')
	if p.tok != '}' {
		parse_field()
		for p.tok == ';' {
			p.next()
			parse_field()
		}
	}
	p.expect('}')
	return &ast.StructType{Fields: &ast.FieldList{List: fields}}
}
336727
func (s *mysql) DataTypeOf(field *StructField) string {
	var dataValue, sqlType, size, additionalType = ParseFieldStructForDialect(field, s)

	// MySQL allows only one auto increment column per table, and it must
	// be a KEY column.
	if _, ok := field.TagSettingsGet("AUTO_INCREMENT"); ok {
		if _, ok = field.TagSettingsGet("INDEX"); !ok && !field.IsPrimaryKey {
			field.TagSettingsDelete("AUTO_INCREMENT")
		}
	}

	if sqlType == "" {
		switch dataValue.Kind() {
		case reflect.Bool:
			sqlType = "boolean"
		case reflect.Int8:
			if s.fieldCanAutoIncrement(field) {
				field.TagSettingsSet("AUTO_INCREMENT", "AUTO_INCREMENT")
				sqlType = "tinyint AUTO_INCREMENT"
			} else {
				sqlType = "tinyint"
			}
		case reflect.Int, reflect.Int16, reflect.Int32:
			if s.fieldCanAutoIncrement(field) {
				field.TagSettingsSet("AUTO_INCREMENT", "AUTO_INCREMENT")
				sqlType = "int AUTO_INCREMENT"
			} else {
				sqlType = "int"
			}
		case reflect.Uint8:
			if s.fieldCanAutoIncrement(field) {
				field.TagSettingsSet("AUTO_INCREMENT", "AUTO_INCREMENT")
				sqlType = "tinyint unsigned AUTO_INCREMENT"
			} else {
				sqlType = "tinyint unsigned"
			}
		case reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uintptr:
			if s.fieldCanAutoIncrement(field) {
				field.TagSettingsSet("AUTO_INCREMENT", "AUTO_INCREMENT")
				sqlType = "int unsigned AUTO_INCREMENT"
			} else {
				sqlType = "int unsigned"
			}
		case reflect.Int64:
			if s.fieldCanAutoIncrement(field) {
				field.TagSettingsSet("AUTO_INCREMENT", "AUTO_INCREMENT")
				sqlType = "bigint AUTO_INCREMENT"
			} else {
				sqlType = "bigint"
			}
		case reflect.Uint64:
			if s.fieldCanAutoIncrement(field) {
				field.TagSettingsSet("AUTO_INCREMENT", "AUTO_INCREMENT")
				sqlType = "bigint unsigned AUTO_INCREMENT"
			} else {
				sqlType = "bigint unsigned"
			}
		case reflect.Float32, reflect.Float64:
			sqlType = "double"
		case reflect.String:
			if size > 0 && size < 65532 {
				sqlType = fmt.Sprintf("varchar(%d)", size)
			} else {
				sqlType = "longtext"
			}
		case reflect.Struct:
			if _, ok := dataValue.Interface().(time.Time); ok {
				precision := ""
				if p, ok := field.TagSettingsGet("PRECISION"); ok {
					precision = fmt.Sprintf("(%s)", p)
				}

				if _, ok := field.TagSettingsGet("NOT NULL"); ok || field.IsPrimaryKey {
					sqlType = fmt.Sprintf("timestamp%v", precision)
				} else {
					sqlType = fmt.Sprintf("timestamp%v NULL", precision)
				}
			}
		default:
			if IsByteArrayOrSlice(dataValue) {
				if size > 0 && size < 65532 {
					sqlType = fmt.Sprintf("varbinary(%d)", size)
				} else {
					sqlType = "longblob"
				}
			}
		}
	}

	if sqlType == "" {
		panic(fmt.Sprintf("invalid sql type %s (%s) for mysql", dataValue.Type().Name(), dataValue.Kind().String()))
	}

	if strings.TrimSpace(additionalType) == "" {
		return sqlType
	}
	return fmt.Sprintf("%v %v", sqlType, additionalType)
}
82728
func FSTypeSimpleValueOf(s string) (FSType, error) {
	obj, err := simpleValueOf("fs_type", FSType_value, s)
	return FSType(obj), err
}
1138264
func TypeFromString(s string) (Type, error) {
	for t, str := range toString {
		if s == str {
			return t, nil
		}
	}
	return NoError, fmt.Errorf("invalid Type: %s", s)
}
854986
func DiffuseMapTyped(data map[string]interface{}, fieldJoiner string, typePrefixSeparator string) (map[string]interface{}, []error) {
    errs   := make([]error, 0)
    output := make(map[string]interface{})

//  get the list of keys and sort them because order in a map is undefined
    dataKeys := StringKeys(data)
    sort.Strings(dataKeys)

//  for each data item
    for _, key := range dataKeys {
        var keyParts []string

        value, _ := data[key]

    //  handle "typed" maps in which the type information is embedded
        if typePrefixSeparator != "" {
            typeKeyPair := strings.SplitN(key, typePrefixSeparator, 2)

            if len(typeKeyPair) == 2 {
                key = typeKeyPair[1]

                if v, err := coerceIntoType(value, typeKeyPair[0]); err == nil {
                    value = v
                }else{
                    errs = append(errs, err)
                }
            }else{
                if v, err := coerceIntoType(value, `str`); err == nil {
                    value = v
                }else{
                    errs = append(errs, err)
                }
            }

        }

        keyParts = strings.Split(key, fieldJoiner)

        output = DeepSet(output, keyParts, value).(map[string]interface{})
    }

    return output, errs
}
17711
func findFieldOfType(reply reflect.Type, fieldName string) (reflect.StructField, bool) {
	for reply.Kind() == reflect.Ptr {
		reply = reply.Elem()
	}
	if reply.Kind() == reflect.Struct {
		field, found := reply.FieldByName(fieldName)
		return field, found
	}
	return reflect.StructField{}, false
}
1057273
func MapsFrom(utd *design.UserTypeDefinition, field string) {
	if f, ok := relationalFieldDefinition(true); ok {
		md := gorma.NewMapDefinition()
		md.RemoteField = field
		md.RemoteType = utd
		f.Mappings[utd.TypeName] = md

	}
}
1068915
func generateType(ctx *context, w io.Writer, typ *Type) {
	name := camelCaseName(typ.Name)

	logf(" writing type %q (%s) with %d fields", typ.Name, name, len(typ.Fields))

	// generate struct comment
	generateComment(ctx, w, name, typ.Name, "type")

	// generate struct definition
	fmt.Fprintf(w, "type %s struct {\n", name)

	// generate struct fields
	for i, field := range typ.Fields {
		// skip internal fields
		switch strings.ToLower(field.Name) {
		case crcField, msgIdField:
			continue
		}

		generateField(ctx, w, typ.Fields, i)
	}

	// generate end of the struct
	fmt.Fprintln(w, "}")

	// generate name getter
	generateTypeNameGetter(w, name, typ.Name)

	// generate CRC getter
	generateCrcGetter(w, name, typ.CRC)

	fmt.Fprintln(w)
}
404346
func GetFieldTypes(db *sql.DB, dbName string, tableName string) []FieldType {
	fields := GetFields(db, dbName, tableName)
	if fields == nil {
		return nil
	}
	types := make([]FieldType, len(fields))
	for i, f := range fields {
		types[i] = f.Type
	}
	return types
}
1242889
func CoalesceMapTyped(data map[string]interface{}, fieldJoiner string, typePrefixSeparator string) (map[string]interface{}, []error) {
    errs := make([]error, 0)
    rv := make(map[string]interface{})

    for k, v := range deepGetValues([]string{}, fieldJoiner, data) {
        if stringVal, err := stringutil.ToString(v); err == nil {
            rv[prepareCoalescedKey(k, v, typePrefixSeparator)] = stringVal
        }else{
            errs = append(errs, err)
        }
    }

    return rv, errs
}
1265889
func DataTypeFromString(s string) DataType {
	switch s {
	case "float":
		return Float
	case "integer":
		return Integer
	case "unsigned":
		return Unsigned
	case "string":
		return String
	case "boolean":
		return Boolean
	case "time":
		return Time
	case "duration":
		return Duration
	case "tag":
		return Tag
	case "field":
		return AnyField
	default:
		return Unknown
	}
}
124413
func (s *Shape) GoStructType(name string, ref *ShapeRef) string {
	if (ref.Streaming || ref.Shape.Streaming) && s.Payload == name {
		rtype := "io.ReadSeeker"
		if strings.HasSuffix(s.ShapeName, "Output") {
			rtype = "io.ReadCloser"
		}

		s.API.imports["io"] = true
		return rtype
	}

	if ref.JSONValue {
		s.API.AddSDKImport("aws")
		return "aws.JSONValue"
	}

	for _, v := range s.Validations {
		// TODO move this to shape validation resolution
		if (v.Ref.Shape.Type == "map" || v.Ref.Shape.Type == "list") && v.Type == ShapeValidationNested {
			s.API.imports["fmt"] = true
		}
	}

	return ref.GoType()
}
1350805
func (mc MongoClient) ValueDescriptorsByType(t string) ([]contract.ValueDescriptor, error) {
	return mapValueDescriptors(mc.getValueDescriptors(bson.M{"type": t}))
}
245186
func writeTypes(args *internal.ArgType) error {
	var err error

	out := internal.TBufSlice(args.Generated)

	// sort segments
	sort.Sort(out)

	// loop, writing in order
	for _, t := range out {
		var f *os.File

		// skip when in append and type is XO
		if args.Append && t.TemplateType == internal.XOTemplate {
			continue
		}

		// check if generated template is only whitespace/empty
		bufStr := strings.TrimSpace(t.Buf.String())
		if len(bufStr) == 0 {
			continue
		}

		// get file and filename
		f, err = getFile(args, &t)
		if err != nil {
			return err
		}

		// should only be nil when type == xo
		if f == nil {
			continue
		}

		// write segment
		if !args.Append || (t.TemplateType != internal.TypeTemplate && t.TemplateType != internal.QueryTypeTemplate) {
			_, err = t.Buf.WriteTo(f)
			if err != nil {
				return err
			}
		}
	}

	// build goimports parameters, closing files
	params := []string{"-w"}
	for k, f := range files {
		params = append(params, k)

		// close
		err = f.Close()
		if err != nil {
			return err
		}
	}

	// process written files with goimports
	output, err := exec.Command("goimports", params...).CombinedOutput()
	if err != nil {
		return errors.New(string(output))
	}

	return nil
}
524820
func typeFor(s string) (t reflect.Type) {
	err, _ := validSingle(s, 0)
	if err != nil {
		panic(err)
	}

	if t, ok := sigToType[s[0]]; ok {
		return t
	}
	switch s[0] {
	case 'a':
		if s[1] == '{' {
			i := strings.LastIndex(s, "}")
			t = reflect.MapOf(sigToType[s[2]], typeFor(s[3:i]))
		} else {
			t = reflect.SliceOf(typeFor(s[1:]))
		}
	case '(':
		t = interfacesType
	}
	return
}
984942
func deepRecvType(sel *types.Selection) types.Type {
	var offset int
	offset = 1
	if sel.Kind() == types.MethodVal || sel.Kind() == types.MethodExpr {
		offset = 0
	}

	typ := sel.Recv()
	idx := sel.Index()
	for k, i := range idx[:len(idx)-offset] {
		final := k == len(idx)-offset-1
		t := getMethod(typ, i, final, sel.Kind() != types.FieldVal)
		if t == nil {
			log.Printf("failed to get method/field at index %v on recv %s", idx, typ)
			return nil
		}
		typ = t.Type()
	}
	return typ
}