// AddStructType adds a new structure type to debug_info. Call TagClose to
// finish adding fields.
// Will write a DW_TAG_struct_type, followed by a DW_AT_byte_size.
4512
func (b *Builder) AddStructType(typename string, byteSz uint16) dwarf.Offset {
	r := b.TagOpen(dwarf.TagStructType, typename)
	b.Attr(dwarf.AttrByteSize, byteSz)
	return r
}
284644
func tableFromStructType(structName string, structType *ast.StructType, packagePrefix string) (*Table, error) {
	normalizedName, err := NormalizeName(structName)
	if err != nil {
		// TODO: This isn't correct, someone could override the name later
		return nil, errors.Wrapf(err, "struct name is invalid")
	}

	t := &Table{
		StructName: structName,
		EntityDefinition: EntityDefinition{
			Name:    normalizedName,
			Columns: []*ColumnDefinition{},
			Indexes: map[string]*IndexDefinition{},
		},
		ColToField: map[string]string{},
		FieldToCol: map[string]string{},
	}
	for _, field := range structType.Fields.List {
		var dosaTag string
		if field.Tag != nil {
			entityTag := reflect.StructTag(strings.Trim(field.Tag.Value, "`"))
			dosaTag = strings.TrimSpace(entityTag.Get(dosaTagKey))
		}
		if dosaTag == "-" { // skip explicitly ignored fields
			continue
		}

		kind, err := parseASTType(field.Type)
		if err != nil {
			return nil, err
		}

		if kind == packagePrefix+"."+entityName || (packagePrefix == "" && kind == entityName) {
			var err error
			if t.EntityDefinition.Name, t.TTL, t.ETL, t.Key, err = parseEntityTag(structName, dosaTag); err != nil {
				return nil, err
			}
		} else {
			for _, fieldName := range field.Names {
				name := fieldName.Name
				if kind == packagePrefix+"."+indexName || (packagePrefix == "" && kind == indexName) {
					indexName, indexKey, err := parseIndexTag(name, dosaTag)
					if err != nil {
						return nil, err
					}
					if _, exist := t.Indexes[indexName]; exist {
						return nil, errors.Errorf("index name is duplicated: %s", indexName)
					}
					t.Indexes[indexName] = &IndexDefinition{Key: indexKey}
				} else {
					firstRune, _ := utf8.DecodeRuneInString(name)
					if unicode.IsLower(firstRune) {
						// skip unexported fields
						continue
					}
					typ, isPointer := stringToDosaType(kind, packagePrefix)
					if typ == Invalid {
						return nil, fmt.Errorf("Column %q has invalid type %q", name, kind)
					}
					cd, err := parseField(typ, isPointer, name, dosaTag)
					if err != nil {
						return nil, errors.Wrapf(err, "column %q", name)
					}
					t.Columns = append(t.Columns, cd)
					t.ColToField[cd.Name] = name
					t.FieldToCol[name] = cd.Name
				}
			}

			if len(field.Names) == 0 {
				if kind == packagePrefix+"."+indexName || (packagePrefix == "" && kind == indexName) {
					indexName, indexKey, err := parseIndexTag("", dosaTag)
					if err != nil {
						return nil, err
					}
					if _, exist := t.Indexes[indexName]; exist {
						return nil, errors.Errorf("index name is duplicated: %s", indexName)
					}
					t.Indexes[indexName] = &IndexDefinition{Key: indexKey}
				}
			}
		}
	}

	if t.Key == nil {
		return nil, errors.Errorf("cannot find dosa.Entity in object %s", t.StructName)
	}

	translateKeyName(t)
	if err := t.EnsureValid(); err != nil {
		return nil, errors.Wrap(err, "failed to parse dosa object")
	}
	return t, nil
}
782356
func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper) (string, []interface{}, error) {
	bound, names, err := compileNamedQuery([]byte(query), bindType)
	if err != nil {
		return "", []interface{}{}, err
	}

	arglist, err := bindArgs(names, arg, m)
	if err != nil {
		return "", []interface{}{}, err
	}

	return bound, arglist, nil
}
301518
func parseStruct(r reflect.Value, node *XMLNode, tag reflect.StructTag) error {
	t := r.Type()
	if r.Kind() == reflect.Ptr {
		if r.IsNil() { // create the structure if it's nil
			s := reflect.New(r.Type().Elem())
			r.Set(s)
			r = s
		}

		r = r.Elem()
		t = t.Elem()
	}

	// unwrap any payloads
	if payload := tag.Get("payload"); payload != "" {
		field, _ := t.FieldByName(payload)
		return parseStruct(r.FieldByName(payload), node, field.Tag)
	}

	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		if c := field.Name[0:1]; strings.ToLower(c) == c {
			continue // ignore unexported fields
		}

		// figure out what this field is called
		name := field.Name
		if field.Tag.Get("flattened") != "" && field.Tag.Get("locationNameList") != "" {
			name = field.Tag.Get("locationNameList")
		} else if locName := field.Tag.Get("locationName"); locName != "" {
			name = locName
		}

		// try to find the field by name in elements
		elems := node.Children[name]

		if elems == nil { // try to find the field in attributes
			if val, ok := node.findElem(name); ok {
				elems = []*XMLNode{{Text: val}}
			}
		}

		member := r.FieldByName(field.Name)
		for _, elem := range elems {
			err := parse(member, elem, field.Tag)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
568837
func ReflectStruct(dest interface{}, src interface{}) (err error) {
	if dest == nil || src == nil {
		return
	}

	return reflectField(
		reflect.ValueOf(dest),
		reflect.ValueOf(src),
	)
}
457903
func NewStructLogger(cfg *LogConfig) *StructLogger {
	logger := &StructLogger{
		changedValues: make(map[common.Address]Storage),
	}
	if cfg != nil {
		logger.cfg = *cfg
	}
	return logger
}
745214
func (b Builder) Add(elems ...int) {
	if b.done {
		return
	}
	for _, elem := range elems {
		b.result.elems[elem] = struct{}{}
	}
}
873279
func AppendStruct(args []interface{}, src interface{}) []interface{} {
	v := reflect.ValueOf(src)
	if v.Kind() == reflect.Ptr {
		if v.IsNil() {
			panic("redigo: FormatStruct argument must not be nil")
		}
		v = v.Elem()
	}
	if v.Kind() != reflect.Struct {
		panic("redigo: FormatStruct argument must be a struct or pointer to a struct")
	}
	ss := structSpecForType(v.Type())
	for _, fs := range ss.l {
		fv := v.FieldByIndex(fs.index)
		args = append(args, fs.name, fv.Interface())
	}
	return args
}
163400
func newStruct(name string, def ast.Node) *Struct {
	return &Struct{
		symbol: symbol{
			name: name,
			def:  def,
		},
	}
}
877111
func getDataStruct(xr *XorRand) *dataStruct {
	var ds *dataStruct
	switch binDataType {
	case "B":
		ds = &dataStruct{B: randBytes(binDataSize, xr)}
	case "S":
		ds = &dataStruct{S: string(randBytes(binDataSize, xr))}
	default:
		ds = &dataStruct{I: xr.Int64()}
	}

	return ds
}
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()
}
254834
func LoadStruct(obj interface{}, m map[string]interface{}, tagname string, ignoreUndefined bool) error {
	structValue := reflect.ValueOf(obj).Elem()
	for i := 0; i < structValue.NumField(); i++ {
		valueField := structValue.Field(i)
		structField := structValue.Type().Field(i)

		dest := structField.Tag.Get(tagname)
		if dest == "" {
			dest = structField.Name
		}
		if !valueField.IsValid() {
			return fmt.Errorf("No such field: %s in obj", structField.Name)
		}
		if !valueField.CanSet() {
			return fmt.Errorf("Cannot set %s field value", structField.Name)
		}
		importedValue, ok := m[dest]
		if !ok && !ignoreUndefined {
			return fmt.Errorf("input map[%v] is undefined", dest)
		}
		if importedValue == nil {
			if ignoreUndefined {
				continue
			}
			return fmt.Errorf("set value (named %v) can not be nil", dest)
		}
		newValue := reflect.ValueOf(importedValue)
		if structField.Type != newValue.Type() {
			invalidTypeError := errors.New("Provided value type didn't match obj field type")
			return invalidTypeError
		}
		valueField.Set(newValue)
	}
	return nil
}
872534
func Struct(name string, opts ...FieldOpt) FieldOpt {
	return func(em *eventMetadata, ed *eventData) {
		em.writeStruct(name, uint8(len(opts)), 0)
		for _, opt := range opts {
			opt(em, ed)
		}
	}
}
1145099
func (m *Table) AddFieldType(name string, valType value.ValueType) {
	m.AddField(&Field{FieldPb: FieldPb{Type: uint32(valType), Name: name}})
}
1336138
func getStructTypeDecl(decl ast.Decl, fset *token.FileSet) (spec *ast.TypeSpec, found bool) {
	genDecl, ok := decl.(*ast.GenDecl)
	if !ok {
		return
	}

	if genDecl.Tok != token.TYPE {
		return
	}

	if len(genDecl.Specs) == 0 {
		utils.Logger.Warn("Warn: Surprising: %s:%d Decl contains no specifications", fset.Position(decl.Pos()).Filename, fset.Position(decl.Pos()).Line)
		return
	}

	spec = genDecl.Specs[0].(*ast.TypeSpec)
	_, found = spec.Type.(*ast.StructType)

	return
}
264690
func RegisterStructTags(vals ...interface{}) {
	tags := mkTags(vals...)
	for k, v := range tags {
		tagsForType[k] = v
	}
}
535313
func (p *TCompactProtocol) WriteStructBegin(name string) error {
	p.lastField = append(p.lastField, p.lastFieldId)
	p.lastFieldId = 0
	return nil
}