コード例 #1
0
ファイル: visit.go プロジェクト: nickng/dingo-hunter
func visitChangeType(instr *ssa.ChangeType, infer *TypeInfer, ctx *Context) {
	inst, ok := ctx.F.locals[instr.X]
	if !ok {
		infer.Logger.Fatalf("changetype: %s: %v → %v", ErrUnknownValue, instr.X, instr)
		return
	}
	ctx.F.locals[instr] = inst
	if a, ok := ctx.F.arrays[ctx.F.locals[instr.X]]; ok {
		ctx.F.arrays[ctx.F.locals[instr]] = a
	}
	if s, ok := ctx.F.structs[ctx.F.locals[instr.X]]; ok {
		ctx.F.structs[ctx.F.locals[instr]] = s
	}
	if m, ok := ctx.F.maps[ctx.F.locals[instr.X]]; ok {
		ctx.F.maps[ctx.F.locals[instr]] = m
	}
	infer.Logger.Print(ctx.F.Sprintf(ValSymbol+"%s = %s (type: %s ← %s)", instr.Name(), instr.X.Name(), fmtType(instr.Type()), fmtType(instr.X.Type().Underlying())))
	ctx.F.revlookup[instr.Name()] = instr.X.Name()
	if indirect, ok := ctx.F.revlookup[instr.X.Name()]; ok {
		ctx.F.revlookup[instr.Name()] = indirect
	}
	return
}