Exemple #1
0
func (g *javaGen) javaBasicType(T *types.Basic) string {
	switch T.Kind() {
	case types.Bool, types.UntypedBool:
		return "boolean"
	case types.Int:
		return "long"
	case types.Int8:
		return "byte"
	case types.Int16:
		return "short"
	case types.Int32, types.UntypedRune: // types.Rune
		return "int"
	case types.Int64, types.UntypedInt:
		return "long"
	case types.Uint8: // types.Byte
		// TODO(crawshaw): Java bytes are signed, so this is
		// questionable, but vital.
		return "byte"
	// TODO(crawshaw): case types.Uint, types.Uint16, types.Uint32, types.Uint64:
	case types.Float32:
		return "float"
	case types.Float64, types.UntypedFloat:
		return "double"
	case types.String, types.UntypedString:
		return "String"
	default:
		g.errorf("unsupported basic type: %s", T)
		return "TODO"
	}
}
Exemple #2
0
func (c *converter) convertBasic(v *gotypes.Basic) *types.Basic {
	if v == nil {
		return nil
	}
	if v, ok := c.converted[v]; ok {
		return v.(*types.Basic)
	}
	var ret *types.Basic
	for i, b := range gotypes.Typ {
		if v == b {
			ret = types.Typ[i]
			break
		}
	}
	switch v.Kind() {
	case gotypes.Byte:
		ret = types.ByteType
	case gotypes.Rune:
		ret = types.RuneType
	}
	if ret == nil {
		panic(fmt.Sprintf("unknown basic type %v", v))
	}
	c.converted[v] = ret
	return ret
}
Exemple #3
0
func toJavaScriptType(t *types.Basic) string {
	switch t.Kind() {
	case types.UntypedInt:
		return "Int"
	case types.Byte:
		return "Uint8"
	case types.Rune:
		return "Int32"
	case types.UnsafePointer:
		return "UnsafePointer"
	default:
		name := t.String()
		return strings.ToUpper(name[:1]) + name[1:]
	}
}
Exemple #4
0
func (c *funcContext) fixNumber(value *expression, basic *types.Basic) *expression {
	switch basic.Kind() {
	case types.Int8:
		return c.formatParenExpr("%s << 24 >> 24", value)
	case types.Uint8:
		return c.formatParenExpr("%s << 24 >>> 24", value)
	case types.Int16:
		return c.formatParenExpr("%s << 16 >> 16", value)
	case types.Uint16:
		return c.formatParenExpr("%s << 16 >>> 16", value)
	case types.Int32, types.Int, types.UntypedInt:
		return c.formatParenExpr("%s >> 0", value)
	case types.Uint32, types.Uint, types.Uintptr:
		return c.formatParenExpr("%s >>> 0", value)
	case types.Float32:
		return c.formatExpr("$fround(%s)", value)
	case types.Float64:
		return value
	default:
		panic(fmt.Sprintf("fixNumber: unhandled basic.Kind(): %s", basic.String()))
	}
}
Exemple #5
0
func basicKindString(b *types.Basic) string {
	switch b.Kind() {

	case types.Invalid:
		return "invalid"

	case types.Bool:
		return "bool"
	case types.Int:
		return "int"
	case types.Int8:
		return "int8"
	case types.Int16:
		return "int16"
	case types.Int32:
		return "int32"
	case types.Int64:
		return "int64"
	case types.Uint:
		return "uint"
	case types.Uint8:
		return "uint8"
	case types.Uint16:
		return "uint16"
	case types.Uint32:
		return "uint32"
	case types.Uint64:
		return "uint64"
	case types.Uintptr:
		return "uintptr"
	case types.Float32:
		return "float32"
	case types.Float64:
		return "float64"
	case types.Complex64:
		return "complex64"
	case types.Complex128:
		return "complex128"
	case types.String:
		return "string"
	case types.UnsafePointer:
		return "unsafepointer"

		// types for untyped values
	case types.UntypedBool:
		return "bool"
	case types.UntypedInt:
		return "int"
	case types.UntypedRune:
		return "rune"
	case types.UntypedFloat:
		return "float"
	case types.UntypedComplex:
		return "complex"
	case types.UntypedString:
		return "string"
	case types.UntypedNil:
		return "nil"

	default:
		return "unsupported"
	}
}
Exemple #6
0
func isUnsigned(t *types.Basic) bool {
	return t.Info()&types.IsUnsigned != 0
}
Exemple #7
0
func isString(t *types.Basic) bool {
	return t.Info()&types.IsString != 0
}
Exemple #8
0
func isNumeric(t *types.Basic) bool {
	return t.Info()&types.IsNumeric != 0
}
Exemple #9
0
func isInteger(t *types.Basic) bool {
	return t.Info()&types.IsInteger != 0
}
Exemple #10
0
func isFloat(t *types.Basic) bool {
	return t.Info()&types.IsFloat != 0
}
Exemple #11
0
func isComplex(t *types.Basic) bool {
	return t.Info()&types.IsComplex != 0
}
Exemple #12
0
func isBoolean(t *types.Basic) bool {
	return t.Info()&types.IsBoolean != 0
}
Exemple #13
0
func is64Bit(t *types.Basic) bool {
	return t.Kind() == types.Int64 || t.Kind() == types.Uint64
}