github.com/tardisgo/tardisgo@v0.0.0-20161119180838-e0dd9a7e46b5/haxe/overload.go (about) 1 // Copyright 2014 Elliott Stoneham and The TARDIS Go Authors 2 // Use of this source code is governed by an MIT-style 3 // license that can be found in the LICENSE file. 4 5 package haxe 6 7 import ( 8 "go/ast" 9 10 "golang.org/x/tools/go/ssa" 11 ) 12 13 var builtinOverloadMap = map[string]string{ 14 //Go Math functions 15 //built into Haxe: 16 //"math_Abs": "Math.abs", 17 //"math_Acos": "Math.acos", 18 //"math_Asin": "Math.asin", 19 //"math_Atan": "Math.atan", 20 //"math_Ceil": "Math.fceil", 21 //"math_Cos": "Math.cos", 22 //"math_Exp": "Math.exp", // use Go version to make tests work 23 //"math_Floor": "Math.ffloor", 24 //"math_Log": "Math.log", 25 //"math_Sin": "Math.sin", 26 //"math_Sqrt": "Math.sqrt", 27 //"math_Tan": "Math.tan", 28 29 //Type of an interface value 30 //runtime 31 //"runtime_typestring": "TypeInfo.typeString", 32 } 33 34 var fnOverloadMap = map[string]string{ 35 //Go Math functions 36 //emulated in Go standard maths package: 37 //"math_Frexp": "Go_math_frexp.call", 38 //"math_Modf": "Go_math_modf.call", 39 //"math_Mod": "Go_math_mod.call", 40 //"math_Sincos": "Go_math_sincos.call", 41 //"math_Log1p": "Go_math_log1p.call", 42 //"math_Ldexp": "Go_math_ldexp.call", 43 //"math_Hypot": "Go_math_hypot.call", 44 //"math_Atan2": "Go_math_atan2.call", 45 //"math_Max": "Go_math_max.call", 46 //"math_Min": "Go_math_min.call", 47 //"math_Log2": "Go_math_log2.call", 48 //"math_Log10": "Go_math_log10.call", 49 //"math_Expm1": "Go_math_expm1.call", 50 //"math_Trunc": "Go_math_trunc.call", 51 //"math_Remainder": "Go_math_remainder.call", 52 //"math_Dim": "Go_math_dim.call", 53 //"math_Exp": "Go_math_exp.call", 54 55 //emulated in golibruntime/math 56 //"math_Float32bits": "Go_tgoaddmath_glrFloat32bits.call", 57 //"math_Float32frombits": "Go_tgoaddmath_glrFloat32frombits.call", 58 //"math_Float64bits": "Go_tgoaddmath_glrFloat64bits.call", 59 //"math_Float64frombits": "Go_tgoaddmath_glrFloat64frombits.call", 60 } 61 62 var fnToVarOverloadMap = map[string]string{ 63 //built into Haxe as variables: 64 //Go Math functions 65 //"math_NaN": "Math.NaN", 66 } 67 68 func (l langType) FunctionOverloaded(pkg, fun string) bool { 69 //fmt.Printf("DEBUG fn ov :%s:%s:\n", pkg, fun) 70 _, ok := fnOverloadMap[pkg+"_"+fun] 71 if ok { 72 return true 73 } 74 _, ok = fnToVarOverloadMap[pkg+"_"+fun] 75 if ok { 76 return true 77 } 78 _, ok = builtinOverloadMap[pkg+"_"+fun] 79 return ok 80 } 81 82 func (l langType) FuncName(fnx *ssa.Function) string { 83 pn := "" 84 if fnx.Signature.Recv() != nil { 85 pn = fnx.Signature.Recv().Type().String() // NOTE no use of underlying here 86 } else { 87 pn, _ = l.PogoComp().FuncPathName(fnx) //fmt.Sprintf("fn%d", fnx.Pos()) 88 fn := ssa.EnclosingFunction(fnx.Package(), []ast.Node{fnx.Syntax()}) 89 if fn == nil { 90 fn = fnx 91 } 92 if fn.Pkg != nil { 93 if fn.Pkg.Pkg != nil { 94 pn = fn.Pkg.Pkg.Path() // was .Name() 95 } 96 } else { 97 if fn.Object() != nil { 98 if fn.Object().Pkg() != nil { 99 pn = fn.Object().Pkg().Path() // was .Name() 100 } 101 } 102 } 103 } 104 return l.LangName(pn, fnx.Name()) 105 }