// inherit sets any blank fields in dst to their equivalent values in fields in src that have matching json tags.
// The dst parameter must be a pointer to a struct.
481956
func inherit(dst, src interface{}) {
	for tag := range tags(dst) {
		setFieldByTag(dst, tag, fieldByTag(src, tag), false)
	}
}
312605
func (r *Resource) inheritResourceType(resourceTypes map[string]ResourceType, apiDef *APIDefinition) error {
	// get resource type object to inherit
	rt, err := r.getResourceType(resourceTypes)
	if rt == nil || err != nil {
		return err
	}

	// initialize dicts
	dicts := initResourceTypeDicts(r, r.Type.Parameters)

	r.Description = substituteParams(r.Description, rt.Description, dicts)

	// uri parameters
	if len(r.URIParameters) == 0 {
		r.URIParameters = map[string]NamedParameter{}
	}
	for name, up := range rt.URIParameters {
		p, ok := r.URIParameters[name]
		if !ok {
			p = NamedParameter{}
		}
		p.inherit(up, dicts)
		r.URIParameters[name] = p
	}

	// methods
	r.inheritMethods(rt, apiDef)

	return nil
}
648596
func Copy(dst, src string) error {
	return FilterTo(dst, src, true, nil)
}
739613
func (js *JSONSchema) Inherit(parents []JSONSchema) {
	// inherit `properties` and `required`
	// only inherit if the property name not exist in
	// child properties
	oriProps := map[string]interface{}{}
	for name, prop := range js.Properties {
		oriProps[name] = prop
	}

	for _, parent := range parents {
		for name, prop := range parent.Properties {
			if _, exist := oriProps[name]; !exist {
				js.Properties[name] = prop
			}
		}
		for _, name := range parent.Required {
			if _, exist := oriProps[name]; !exist {
				if !js.isRequired(name) {
					js.Required = append(js.Required, name)
				}
			}
		}
	}

}
1133696
func (cmd *CLI) InheritFlags(names ...string) {
	for _, name := range names {
		cmd.InheritFlag(name)
	}
}
1189714
func Connect(dst, src interface{}) error {
	vd := reflect.ValueOf(dst).Elem()
	td := vd.Type()
	vs := reflect.ValueOf(src)
	ts := vs.Type()
	for i := 0; i < td.NumField(); i++ {
		sf := td.Field(i)
		if sf.Type.Kind() != reflect.Func {
			continue
		}

		m := vs.MethodByName(sf.Name)
		if !m.IsValid() {
			return errors.Format("type [%s] doesn't contain method [%s]", ts.Name(), sf.Name)
		}

		f := vd.Field(i)
		if !m.Type().ConvertibleTo(f.Type()) {
			return errors.Format("%s: %v is not assignable to %v", sf.Name, m.Type(), f.Type())
		}
		f.Set(m)
	}
	return nil
}
74571
func (dst *pguint32) Set(src interface{}) error {
	switch value := src.(type) {
	case int64:
		if value < 0 {
			return errors.Errorf("%d is less than minimum value for pguint32", value)
		}
		if value > math.MaxUint32 {
			return errors.Errorf("%d is greater than maximum value for pguint32", value)
		}
		*dst = pguint32{Uint: uint32(value), Status: Present}
	case uint32:
		*dst = pguint32{Uint: value, Status: Present}
	default:
		return errors.Errorf("cannot convert %v to pguint32", value)
	}

	return nil
}
84954
func Trait(name string, val ...func()) {
	if a, ok := apiDefinition(); ok {
		if len(val) < 1 {
			dslengine.ReportError("missing trait DSL for %s", name)
			return
		} else if len(val) > 1 {
			dslengine.ReportError("too many arguments given to Trait")
			return
		}
		if _, ok := design.Design.Traits[name]; ok {
			dslengine.ReportError("multiple definitions for trait %s%s", name, design.Design.Context())
			return
		}
		trait := &dslengine.TraitDefinition{Name: name, DSLFunc: val[0]}
		if a.Traits == nil {
			a.Traits = make(map[string]*dslengine.TraitDefinition)
		}
		a.Traits[name] = trait
	}
}
1084850
func assign(dst, src interface{}) (bool, error) {
	dstrv := indirectAlloc(reflect.ValueOf(dst))
	switch srct := src.(type) {
	case Float:
		if dstrv.Kind() != reflect.Float64 {
			return false, assignError(dstrv, src)
		}
		dstrv.SetFloat(float64(srct))
	case String:
		if dstrv.Kind() != reflect.String {
			return false, assignError(dstrv, src)
		}
		dstrv.SetString(string(srct))
	case Map:
		switch dstrv.Interface().(type) {
		case Map:
			dstrv.Set(reflect.ValueOf(srct))
		default:
			return false, assignError(dstrv, src)
		}
	case Slice:
		switch dstrv.Interface().(type) {
		case Slice:
			dstrv.Set(reflect.ValueOf(srct))
		default:
			return false, assignError(dstrv, src)
		}
	case Array:
		switch dstrv.Interface().(type) {
		case Array:
			dstrv.Set(reflect.ValueOf(srct))
		default:
			switch dstrv.Interface().(type) {
			case Array:
				dstrv.Set(reflect.ValueOf(srct))
			default:
				return false, assignError(dstrv, src)
			}
		}
	case Binary:
		if dstrv.Kind() != reflect.Slice && dstrv.Elem().Kind() != reflect.Uint8 {
			return false, assignError(dstrv, src)
		}
		dstrv.SetBytes([]byte(srct))
	case Undefined:
		// Nothing to do.
	case ObjectId:
		if dstrv.Kind() != reflect.Slice && dstrv.Elem().Kind() != reflect.Uint8 {
			return false, assignError(dstrv, src)
		}
		dstrv.SetBytes([]byte(srct))
	case Bool:
		if dstrv.Kind() != reflect.Bool {
			return false, assignError(dstrv, src)
		}
		dstrv.SetBool(bool(srct))
	case UTCDateTime:
		switch dstrv.Interface().(type) {
		case time.Time:
			// BSON time is milliseconds since unix epoch.
			// Go time is nanoseconds since unix epoch.
			dstrv.Set(reflect.ValueOf(time.Unix(0, int64(srct)*1e3)))
		default:
			if dstrv.Kind() != reflect.Int64 {
				return false, assignError(dstrv, src)
			}
			dstrv.SetInt(int64(srct))
		}
	case Null:
		// Nothing to do.
	case Regexp:
		switch dstrv.Interface().(type) {
		case Regexp:
			dstrv.Set(reflect.ValueOf(srct))
		default:
			return false, assignError(dstrv, src)
		}
	case DBPointer:
			switch dstrv.Interface().(type) {
			case DBPointer:
				dstrv.Set(reflect.ValueOf(srct))
			default:
				return false, assignError(dstrv, src)
			}
	case Javascript:
		if dstrv.Kind() != reflect.String {
			return false, assignError(dstrv, src)
		}
		dstrv.SetString(string(srct))
	case Symbol:
		if dstrv.Kind() != reflect.String {
			return false, assignError(dstrv, src)
		}
		dstrv.SetString(string(srct))
	case JavascriptScope:
		switch dstrv.Interface().(type) {
		case JavascriptScope:
			dstrv.Set(reflect.ValueOf(srct))
		default:
			return false, assignError(dstrv, src)
		}
	case Int32:
		if dstrv.Kind() != reflect.Int32 && dstrv.Kind() != reflect.Int64 {
			return false, assignError(dstrv, src)
		}
		dstrv.SetInt(int64(srct))
	case Timestamp:
		switch dstrv.Interface().(type) {
		case time.Time:
			// BSON time is milliseconds since unix epoch.
			// Go time is nanoseconds since unix epoch.
			dstrv.Set(reflect.ValueOf(time.Unix(0, int64(srct)*1e3)))
		default:
			if dstrv.Kind() != reflect.Int64 {
				return false, assignError(dstrv, src)
			}
			dstrv.SetInt(int64(srct))
		}
	case Int64:
		if dstrv.Kind() != reflect.Int64 {
			return false, assignError(dstrv, src)
		}
		dstrv.SetInt(int64(srct))
	case MinKey:
		// Nothing to do.
	case MaxKey:
		// Nothing to do.
	}
	return true, nil
}
853139
func (s *Statement) Copy(dst Code, src Code) *Statement {
	g := &Group{
		close:     ")",
		items:     []Code{dst, src},
		multi:     false,
		name:      "copy",
		open:      "copy(",
		separator: ",",
	}
	*s = append(*s, g)
	return s
}
698942
func (resp *Response) inherit(parent Response, dicts map[string]interface{}, rtName string,
	apiDef *APIDefinition) {
	resp.Description = substituteParams(resp.Description, parent.Description, dicts)
	resp.Bodies.inherit(parent.Bodies, dicts, rtName, apiDef)
	resp.Headers = inheritHeaders(resp.Headers, parent.Headers, dicts)
}
947723
func NewStructType(fields []StructField) *StructType {
	// Start by looking up just the types
	fts := make([]Type, len(fields))
	for i, f := range fields {
		fts[i] = f.Type
	}
	tMapI := structTypes.Get(fts)
	if tMapI == nil {
		tMapI = structTypes.Put(fts, make(map[string]*StructType))
	}
	tMap := tMapI.(map[string]*StructType)

	// Construct key for field names
	key := ""
	for _, f := range fields {
		// XXX(Spec) It's not clear if struct { T } and struct
		// { T T } are either identical or compatible.  The
		// "Struct Types" section says that the name of that
		// field is "T", which suggests that they are
		// identical, but it really means that it's the name
		// for the purpose of selector expressions and nothing
		// else.  We decided that they should be neither
		// identical or compatible.
		if f.Anonymous {
			key += "!"
		}
		key += f.Name + " "
	}

	// XXX(Spec) Do the tags also have to be identical for the
	// types to be identical?  I certainly hope so, because
	// otherwise, this is the only case where two distinct type
	// objects can represent identical types.

	t, ok := tMap[key]
	if !ok {
		// Create new struct type
		t = &StructType{commonType{}, fields}
		tMap[key] = t
	}
	return t
}
1346006
func (m *Method) inheritProtocols(parent []string) {
	for _, p := range parent {
		m.Protocols = appendStrNotExist(p, m.Protocols)
	}
}
1031220
func baseMutate(ctx context.Context, table, key []byte, values map[string]map[string][]byte,
	options ...func(Call) error) (*Mutate, error) {
	m := &Mutate{
		base: base{
			table:    table,
			key:      key,
			ctx:      ctx,
			resultch: make(chan RPCResult, 1),
		},
		values:    values,
		timestamp: MaxTimestamp,
	}
	err := applyOptions(m, options...)
	if err != nil {
		return nil, err
	}
	return m, nil
}
1018685
func (s RefSpec) Dst(n plumbing.ReferenceName) plumbing.ReferenceName {
	spec := string(s)
	start := strings.Index(spec, refSpecSeparator) + 1
	dst := spec[start:]
	src := s.Src()

	if !s.IsWildcard() {
		return plumbing.ReferenceName(dst)
	}

	name := n.String()
	ws := strings.Index(src, refSpecWildcard)
	wd := strings.Index(dst, refSpecWildcard)
	match := name[ws : len(name)-(len(src)-(ws+1))]

	return plumbing.ReferenceName(dst[0:wd] + match + dst[wd+1:])
}
360684
func emitLiteral(dst, lit []byte) int {
	i, n := 0, uint(len(lit)-1)
	switch {
	case n < 60:
		dst[0] = uint8(n)<<2 | tagLiteral
		i = 1
	case n < 1<<8:
		dst[0] = 60<<2 | tagLiteral
		dst[1] = uint8(n)
		i = 2
	default:
		dst[0] = 61<<2 | tagLiteral
		dst[1] = uint8(n)
		dst[2] = uint8(n >> 8)
		i = 3
	}
	return i + copy(dst[i:], lit)
}
515299
func (ref Ref) Extend(other Ref) Ref {
	dst := make(Ref, len(ref)+len(other))
	for i := range ref {
		dst[i] = ref[i]
	}
	head := other[0].Copy()
	head.Value = String(head.Value.(Var))
	offset := len(ref)
	dst[offset] = head
	for i := range other[1:] {
		dst[offset+i+1] = other[i+1]
	}
	return dst
}