Пример #1
0
func (d *DIBuilder) descriptorSlice(t *types.Slice, name string) llvm.Value {
	sliceStruct := types.NewStruct([]*types.Var{
		types.NewVar(0, nil, "ptr", types.NewPointer(t.Elem())),
		types.NewVar(0, nil, "len", types.Typ[types.Int]),
		types.NewVar(0, nil, "cap", types.Typ[types.Int]),
	}, nil)
	return d.typeDebugDescriptor(sliceStruct, name)
}
Пример #2
0
func (c *funcContext) translateArgs(sig *types.Signature, argExprs []ast.Expr, ellipsis, clone bool) []string {
	if len(argExprs) == 1 {
		if tuple, isTuple := c.p.TypeOf(argExprs[0]).(*types.Tuple); isTuple {
			tupleVar := c.newVariable("_tuple")
			c.Printf("%s = %s;", tupleVar, c.translateExpr(argExprs[0]))
			argExprs = make([]ast.Expr, tuple.Len())
			for i := range argExprs {
				argExprs[i] = c.newIdent(c.formatExpr("%s[%d]", tupleVar, i).String(), tuple.At(i).Type())
			}
		}
	}

	paramsLen := sig.Params().Len()

	var varargType *types.Slice
	if sig.Variadic() && !ellipsis {
		varargType = sig.Params().At(paramsLen - 1).Type().(*types.Slice)
	}

	preserveOrder := false
	for i := 1; i < len(argExprs); i++ {
		preserveOrder = preserveOrder || c.Blocking[argExprs[i]]
	}

	args := make([]string, len(argExprs))
	for i, argExpr := range argExprs {
		var argType types.Type
		switch {
		case varargType != nil && i >= paramsLen-1:
			argType = varargType.Elem()
		default:
			argType = sig.Params().At(i).Type()
		}

		var arg string
		switch {
		case clone:
			arg = c.translateImplicitConversionWithCloning(argExpr, argType).String()
		default:
			arg = c.translateImplicitConversion(argExpr, argType).String()
		}

		if preserveOrder && c.p.Types[argExpr].Value == nil {
			argVar := c.newVariable("_arg")
			c.Printf("%s = %s;", argVar, arg)
			arg = argVar
		}

		args[i] = arg
	}

	if varargType != nil {
		return append(args[:paramsLen-1], fmt.Sprintf("new %s([%s])", c.typeName(varargType), strings.Join(args[paramsLen-1:], ", ")))
	}
	return args
}
Пример #3
0
func Slice(path string, st reflect.StructTag, u *types.Slice) IObj {
	und := u.Elem()
	if p, ok := und.(*types.Pointer); ok {
		und = p.Elem()
	}

	rv := ISlice{}
	rv.name = strings.Split(st.Get("json"), ",")[0]
	rv.typ = "[]" + typefmt(und)
	rv.description = st.Get("description")
	rv.path = pathAppend(path, rv.name)
	c := dump(rv.path, und, reflect.StructTag(""))
	if st, ok := c.(IStruct); ok {
		rv.items = st.items
	} else {
		rv.valtyp = typefmt(und)
	}

	return rv
}