示例#1
0
文件: importer.go 项目: tcard/sgo
func (c *converter) convertConstantValue(v goconstant.Value) constant.Value {
	if v == nil {
		return nil
	}
	if v, ok := c.converted[v]; ok {
		return v.(constant.Value)
	}
	var ret constant.Value
	switch v.Kind() {
	case goconstant.Bool:
		ret = constant.MakeBool(goconstant.BoolVal(v))
	case goconstant.String:
		ret = constant.MakeString(goconstant.StringVal(v))
	case goconstant.Int:
		ret = constant.MakeFromLiteral(v.String(), token.INT, 0)
	case goconstant.Float:
		ret = constant.MakeFromLiteral(v.String(), token.FLOAT, 0)
	case goconstant.Complex:
		ret = constant.MakeFromLiteral(v.String(), token.IMAG, 0)
	}
	c.converted[v] = ret
	return ret
}
示例#2
0
文件: operand.go 项目: tcard/sgo
// setConst sets x to the untyped constant for literal lit.
func (x *operand) setConst(tok token.Token, lit string) {
	var kind BasicKind
	switch tok {
	case token.INT:
		kind = UntypedInt
	case token.FLOAT:
		kind = UntypedFloat
	case token.IMAG:
		kind = UntypedComplex
	case token.CHAR:
		kind = UntypedRune
	case token.STRING:
		kind = UntypedString
	default:
		unreachable()
	}

	x.mode = constant_
	x.typ = Typ[kind]
	x.val = constant.MakeFromLiteral(lit, tok, 0)
}