// compileTypeReference compiles the given AST type reference into a TypeSpec.
//
// The returned TypeSpec may need to be linked eventually.
430041
func compileTypeReference(typ ast.Type) (TypeSpec, error) {
	if typ == nil {
		return nil, nil
	}
	switch t := typ.(type) {
	case ast.BaseType:
		return compileBaseType(t)
	case ast.MapType:
		return compileMapType(t)
	case ast.ListType:
		return compileListType(t)
	case ast.SetType:
		return compileSetType(t)
	case ast.TypeReference:
		return typeSpecReference(t), nil
	default:
		panic(fmt.Sprintf("unknown type %v", typ))
	}
}
662295
func (b *OpenAPI3Builder) typeForSchemaOrReference(value *openapiv3.SchemaOrReference) (kind FieldKind, typeName, format string) {
	if value.GetSchema() != nil {
		return b.typeForSchema(value.GetSchema())
	}
	if value.GetReference() != nil {
		return FieldKind_SCALAR, typeForRef(value.GetReference().XRef), ""
	}
	return FieldKind_SCALAR, "todo", ""
}
542566
func (fg FieldGroup) ForEachTypeReference(f func(TypeSpec) error) error {
	for _, field := range fg {
		if err := f(field.Type); err != nil {
			return err
		}
	}
	return nil
}
770784
func compileModelSpec(typ reflect.Type) (*modelSpec, error) {
	ms := &modelSpec{
		name:         getDefaultModelSpecName(typ),
		fieldsByName: map[string]*fieldSpec{},
		typ:          typ,
	}

	// Iterate through fields
	elem := typ.Elem()
	numFields := elem.NumField()
	for i := 0; i < numFields; i++ {
		field := elem.Field(i)
		// Skip unexported fields. Prior to go 1.6, field.PkgPath won't give us
		// the behavior we want. Unlike packages such as encoding/json and
		// encoding/gob, Zoom does not save unexported embedded structs with
		// exported fields. So instead, we check if the first character of the
		// field name is lowercase.
		if strings.ToLower(field.Name[0:1]) == field.Name[0:1] {
			continue
		}

		// Skip the RandomID field
		if field.Type == reflect.TypeOf(RandomID{}) {
			continue
		}

		// Parse the "redis" tag
		tag := field.Tag
		redisTag := tag.Get("redis")
		if redisTag == "-" {
			continue // skip field
		}
		fs := &fieldSpec{name: field.Name, typ: field.Type}
		ms.fieldsByName[fs.name] = fs
		ms.fields = append(ms.fields, fs)
		if redisTag != "" {
			fs.redisName = redisTag
		} else {
			fs.redisName = fs.name
		}

		// Parse the "zoom" tag (currently only "index" is supported)
		zoomTag := tag.Get("zoom")
		shouldIndex := false
		if zoomTag != "" {
			options := strings.Split(zoomTag, ",")
			for _, op := range options {
				switch op {
				case "index":
					shouldIndex = true
				default:
					return nil, fmt.Errorf("zoom: unrecognized option specified in struct tag: %s", op)
				}
			}
		}

		// Detect the kind of the field and (if applicable) the kind of the index
		if typeIsPrimative(field.Type) {
			// Primitive
			fs.kind = primativeField
			if shouldIndex {
				if err := setIndexKind(fs, field.Type); err != nil {
					return nil, err
				}
			}
		} else if field.Type.Kind() == reflect.Ptr && typeIsPrimative(field.Type.Elem()) {
			// Pointer to a primitive
			fs.kind = pointerField
			if shouldIndex {
				if err := setIndexKind(fs, field.Type.Elem()); err != nil {
					return nil, err
				}
			}
		} else {
			// All other types are considered inconvertible
			if shouldIndex {
				return nil, fmt.Errorf("zoom: Requested index on unsupported type %s", field.Type)
			}
			fs.kind = inconvertibleField
		}
	}
	return ms, nil
}
1323762
func (r typeSpecReference) ForEachTypeReference(func(TypeSpec) error) error {
	panic(fmt.Sprintf(
		"ForEachTypeReference() called on unresolved TypeSpec reference %v."+
			"Make sure you called Link().", r,
	))
}
377761
func Convert_v1_TypedLocalObjectReference_To_core_TypedLocalObjectReference(in *v1.TypedLocalObjectReference, out *core.TypedLocalObjectReference, s conversion.Scope) error {
	return autoConvert_v1_TypedLocalObjectReference_To_core_TypedLocalObjectReference(in, out, s)
}
1073161
func Base(compiler *ast.Compiler, x interface{}) ([]ast.Ref, error) {
	baseRefs, err := base(compiler, x)
	if err != nil {
		return nil, err
	}

	return dedup(baseRefs), nil
}
455747
func (l *fsLoader) JsonReference() (gojsonreference.JsonReference, error) { // nolint: golint
	return gojsonreference.NewJsonReference(l.JsonSource().(string))
}
980920
func compileMapType(src ast.MapType) (*MapSpec, error) {
	annots, err := compileAnnotations(src.Annotations)
	if err != nil {
		return nil, err
	}

	keySpec, err := compileTypeReference(src.KeyType)
	if err != nil {
		return nil, err
	}

	valueSpec, err := compileTypeReference(src.ValueType)
	if err != nil {
		return nil, err
	}

	return &MapSpec{
		KeySpec:     keySpec,
		ValueSpec:   valueSpec,
		Annotations: annots,
	}, nil
}
248188
func compileConstant(file string, src *ast.Constant) (*Constant, error) {
	typ, err := compileTypeReference(src.Type)
	if err != nil {
		return nil, err
	}

	return &Constant{
		Name:  src.Name,
		File:  file,
		Type:  typ,
		Doc:   src.Doc,
		Value: compileConstantValue(src.Value),
	}, nil
}
538521
func (c *unaryMinusFunctionClass) typeInfer(ctx sessionctx.Context, argExpr Expression) (types.EvalType, bool) {
	tp := argExpr.GetType().EvalType()
	if tp != types.ETInt && tp != types.ETDecimal {
		tp = types.ETReal
	}

	sc := ctx.GetSessionVars().StmtCtx
	overflow := false
	// TODO: Handle float overflow.
	if arg, ok := argExpr.(*Constant); sc.InSelectStmt && ok && tp == types.ETInt {
		overflow = c.handleIntOverflow(arg)
		if overflow {
			tp = types.ETDecimal
		}
	}
	return tp, overflow
}
1213947
func compileListType(src ast.ListType) (*ListSpec, error) {
	annots, err := compileAnnotations(src.Annotations)
	if err != nil {
		return nil, err
	}

	valueSpec, err := compileTypeReference(src.ValueType)
	if err != nil {
		return nil, err
	}

	return &ListSpec{
		ValueSpec:   valueSpec,
		Annotations: annots,
	}, nil
}
531036
func compileConstantValue(v ast.ConstantValue) ConstantValue {
	if v == nil {
		return nil
	}

	// TODO(abg): Support typedefs

	switch src := v.(type) {
	case ast.ConstantReference:
		return constantReference(src)
	case ast.ConstantMap:
		return compileConstantMap(src)
	case ast.ConstantList:
		return compileConstantList(src)
	case ast.ConstantBoolean:
		return ConstantBool(src)
	case ast.ConstantInteger:
		return ConstantInt(src)
	case ast.ConstantString:
		return ConstantString(src)
	case ast.ConstantDouble:
		return ConstantDouble(src)
	default:
		panic(fmt.Sprintf("unknown constant value of type %T: %v", src, src))
	}
}
824412
func FindReference(refs []types.ManagedObjectReference, match ...types.ManagedObjectReference) *types.ManagedObjectReference {
	for _, ref := range refs {
		for _, m := range match {
			if ref == m {
				return &ref
			}
		}
	}

	return nil
}
80706
func NewHeadersOrReferences(in interface{}, context *compiler.Context) (*HeadersOrReferences, error) {
	errors := make([]error, 0)
	x := &HeadersOrReferences{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		// repeated NamedHeaderOrReference additional_properties = 1;
		// MAP: HeaderOrReference
		x.AdditionalProperties = make([]*NamedHeaderOrReference, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				pair := &NamedHeaderOrReference{}
				pair.Name = k
				var err error
				pair.Value, err = NewHeaderOrReference(v, compiler.NewContext(k, context))
				if err != nil {
					errors = append(errors, err)
				}
				x.AdditionalProperties = append(x.AdditionalProperties, pair)
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
1213410
func IsComponentReference(s string) error {
	if len(s) == 0 {
		return fmt.Errorf("empty string provided to component reference check")
	}
	all := strings.Split(s, "+")
	_, _, _, err := componentWithSource(all[0])
	return err
}
441552
func (domain *Domain) typeNameForReference(reference string) string {
	parts := strings.Split(reference, "/")
	first := parts[0]
	last := parts[len(parts)-1]
	if first == "#" {
		return domain.TypeNameForStub(last)
	}
	return "Schema"
}