// BoolTmpVarCode returns source code for bool temp variable.
550880
func (p *Param) BoolTmpVarCode() string {
	const code = `var %s uint32
	if %s {
		%s = 1
	} else {
		%s = 0
	}`
	tmp := p.tmpVar()
	return fmt.Sprintf(code, tmp, p.Name, tmp, tmp)
}
479750
func ValidLangCode(c string) bool {
	for d := range LangCodes {
		if c == d {
			return true
		}
	}
	return false
}
800838
func safeArrayGetVartype(safearray *SafeArray) (varType uint16, err error) {
	err = convertHresultToError(
		procSafeArrayGetVartype.Call(
			uintptr(unsafe.Pointer(safearray)),
			uintptr(unsafe.Pointer(&varType))))
	return
}
245838
func jsonnet_tla_code(vmRef *C.struct_JsonnetVm, key, value *C.char) {
	vm := getVM(vmRef)
	vm.TLACode(C.GoString(key), C.GoString(value))
}
728437
func (s *VariableService) CreateVariable(ctx context.Context, m *platform.Variable) error {
	if err := m.Valid(); err != nil {
		return &platform.Error{
			Code: platform.EInvalid,
			Err:  err,
		}
	}

	url, err := newURL(s.Addr, variablePath)
	if err != nil {
		return err
	}

	octets, err := json.Marshal(m)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", url.String(), bytes.NewReader(octets))
	if err != nil {
		return err
	}

	req.Header.Set("Content-Type", "application/json")
	SetToken(s.Token, req)

	hc := newClient(url.Scheme, s.InsecureSkipVerify)

	resp, err := hc.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	if err := CheckError(resp); err != nil {
		return err
	}

	return json.NewDecoder(resp.Body).Decode(m)
}
860435
func (x *genRunner) encVar(varname string, t reflect.Type) {
	// fmt.Printf(">>>>>> varname: %s, t: %v\n", varname, t)
	var checkNil bool
	switch t.Kind() {
	case reflect.Ptr, reflect.Interface, reflect.Slice, reflect.Map, reflect.Chan:
		checkNil = true
	}
	if checkNil {
		x.linef("if %s == nil { r.EncodeNil() } else { ", varname)
	}

	switch t.Kind() {
	case reflect.Ptr:
		telem := t.Elem()
		tek := telem.Kind()
		if tek == reflect.Array || (tek == reflect.Struct && telem != timeTyp) {
			x.enc(varname, genNonPtr(t))
			break
		}
		i := x.varsfx()
		x.line(genTempVarPfx + i + " := *" + varname)
		x.enc(genTempVarPfx+i, genNonPtr(t))
	case reflect.Struct, reflect.Array:
		if t == timeTyp {
			x.enc(varname, t)
			break
		}
		i := x.varsfx()
		x.line(genTempVarPfx + i + " := &" + varname)
		x.enc(genTempVarPfx+i, t)
	default:
		x.enc(varname, t)
	}

	if checkNil {
		x.line("}")
	}

}
149806
func (sv ShapeValidation) GoCode() string {
	var err error

	w := &bytes.Buffer{}
	switch sv.Type {
	case ShapeValidationRequired:
		err = validationGoCodeTmpls.ExecuteTemplate(w, "requiredValue", sv)
	case ShapeValidationMinVal:
		switch sv.Ref.Shape.Type {
		case "list", "map", "blob":
			err = validationGoCodeTmpls.ExecuteTemplate(w, "minLen", sv)
		case "string":
			err = validationGoCodeTmpls.ExecuteTemplate(w, "minLenString", sv)
		case "integer", "long", "float", "double":
			err = validationGoCodeTmpls.ExecuteTemplate(w, "minVal", sv)
		default:
			panic(fmt.Sprintf("ShapeValidation.GoCode, %s's type %s, no min value handling",
				sv.Name, sv.Ref.Shape.Type))
		}
	case ShapeValidationNested:
		switch sv.Ref.Shape.Type {
		case "map", "list":
			err = validationGoCodeTmpls.ExecuteTemplate(w, "nestedMapList", sv)
		default:
			err = validationGoCodeTmpls.ExecuteTemplate(w, "nestedStruct", sv)
		}
	default:
		panic(fmt.Sprintf("ShapeValidation.GoCode, %s's type %d, unknown validation type",
			sv.Name, sv.Type))
	}

	if err != nil {
		panic(fmt.Sprintf("ShapeValidation.GoCode failed, err: %v", err))
	}

	return w.String()
}
720824
func boolFromInterface(val interface{}) (bool, error) {
	switch val.(type) {
	case bool:
		return val.(bool), nil
	}
	return false, fmt.Errorf("Expected boolean value for Bool, got \"%v\"\n", val)
}
1286374
func (fv FlagValues) Bool(name string, defaultValue bool) (bool, error) {
	value, found := fv[name]
	if !found {
		return defaultValue, nil
	}
	switch value {
	case "", "t", "T", "true", "True", "1":
		return true, nil
	case "f", "F", "false", "False", "0":
		return false, nil
	}
	return false, fmt.Errorf("flag %q: cannot parse boolean from %q", name, value)
}
435046
func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
	f.VarP(newBoolValue(value, p), name, shorthand, usage)
}
360513
func (p *Param) StringTmpVarCode() string {
	errvar := p.fn.Rets.ErrorVarName()
	if errvar == "" {
		errvar = "_"
	}
	tmp := p.tmpVar()
	const code = `var %s %s
	%s, %s = %s(%s)`
	s := fmt.Sprintf(code, tmp, p.fn.StrconvType(), tmp, errvar, p.fn.StrconvFunc(), p.Name)
	if errvar == "-" {
		return s
	}
	const morecode = `
	if %s != nil {
		return
	}`
	return s + fmt.Sprintf(morecode, errvar)
}
672786
func (x *jsonSource) BoolT(name string) (bool, error) {
	return false, fmt.Errorf("unsupported type BoolT for JSONSource")
}
385023
func (vm *VM) TLACode(key string, val string) {
	vm.tla[key] = vmExt{value: val, isCode: true}
}
342710
func (_m *Source) SourceCode(repository string, path string, revision string, submodule bool) error {
	ret := _m.Called(repository, path, revision, submodule)

	var r0 error
	if rf, ok := ret.Get(0).(func(string, string, string, bool) error); ok {
		r0 = rf(repository, path, revision, submodule)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
793738
func BooleanArrayEncodeAll(src []bool, b []byte) ([]byte, error) {
	sz := 1 + 8 + ((len(src) + 7) / 8) // Header + Num bools + bool data.
	if len(b) < sz && cap(b) > sz {
		b = b[:sz]
	} else if len(b) < sz {
		b = append(b, make([]byte, sz)...)
	}

	// Store the encoding type in the 4 high bits of the first byte
	b[0] = byte(booleanCompressedBitPacked) << 4
	n := uint64(8) // Current bit in current byte.

	// Encode the number of booleans written.
	i := binary.PutUvarint(b[n>>3:], uint64(len(src)))
	n += uint64(i * 8)

	for _, v := range src {
		if v {
			b[n>>3] |= 128 >> (n & 7) // Set current bit on current byte.
		} else {
			b[n>>3] &^= 128 >> (n & 7) // Clear current bit on current byte.
		}
		n++
	}

	length := n >> 3
	if n&7 > 0 {
		length++ // Add an extra byte to capture overflowing bits.
	}
	return b[:length], nil
}
903153
func (g *GitScm) SourceCode(repository, path, revision string, submodule bool) error {
	if err := gitcheck(repository, g.Config.PublicKey, g.Config.PrivateKey); err != nil {
		return err
	}

	var repo *git.Repository
	var err error
	if strings.Contains(repository, "https://") {
		repo, err = git.Clone(repository, path, &git.CloneOptions{})
	} else {
		credentialsCallback := func(url, username string, allowedTypes git.CredType) (git.ErrorCode, *git.Cred) {
			ret, cred := git.NewCredSshKey(username, g.Config.PublicKey, g.Config.PrivateKey, "")
			return git.ErrorCode(ret), &cred
		}
		cloneOpts := &git.CloneOptions{
			FetchOptions: &git.FetchOptions{
				RemoteCallbacks: git.RemoteCallbacks{
					CredentialsCallback:      credentialsCallback,
					CertificateCheckCallback: certificateCheckCallback,
				},
			},
		}
		repo, err = git.Clone(repository, path, cloneOpts)
	}
	if err != nil {
		return err
	}
	defer repo.Free()

	if err := repo.CheckoutHead(nil); err != nil {
		return err
	}

	object, err := repo.RevparseSingle(revision)
	if err != nil {
		return err
	}
	defer object.Free()

	object, err = object.Peel(git.ObjectCommit)
	if err != nil {
		return err
	}

	commit, err := object.AsCommit()
	if err != nil {
		return err
	}
	defer commit.Free()

	tree, err := commit.Tree()
	if err != nil {
		return err
	}
	defer tree.Free()

	if err := repo.CheckoutTree(tree, &git.CheckoutOpts{Strategy: git.CheckoutSafe}); err != nil {
		return err
	}
	log.Infof("[SourceCode] Fetch repo %s", repository)
	log.Infof("[SourceCode] Checkout to commit %v", commit.Id())

	// Prepare submodules
	if submodule {
		repo.Submodules.Foreach(func(sub *git.Submodule, name string) int {
			sub.Init(true)
			err := sub.Update(true, &git.SubmoduleUpdateOptions{
				CheckoutOpts: &git.CheckoutOpts{
					Strategy: git.CheckoutForce | git.CheckoutUpdateSubmodules,
				},
				FetchOptions: &git.FetchOptions{},
			})
			if err != nil {
				log.Errorln(err)
			}
			return 0
		})
	}
	return nil
}
1049781
func checkBoolExpType(op BooleanOperation, lhs Expression, rhs interface{}, invert bool) BooleanExpression {
	if rhs == nil {
		op = IS_OP
	} else {
		switch reflect.Indirect(reflect.ValueOf(rhs)).Kind() {
		case reflect.Bool:
			op = IS_OP
		case reflect.Slice:
			//if its a slice of bytes dont treat as an IN
			if _, ok := rhs.([]byte); !ok {
				op = IN_OP
			}
		case reflect.Struct:
			switch rhs.(type) {
			case SqlExpression:
				op = IN_OP
			case *regexp.Regexp:
				return checkLikeExp(LIKE_OP, lhs, rhs, invert)
			}
		}
	}
	if invert {
		op = operator_inversions[op]
	}
	return boolean{op: op, lhs: lhs, rhs: rhs}
}