Skip to content

Commit

Permalink
type trace
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jul 20, 2021
1 parent 20e719f commit 86ace58
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
13 changes: 12 additions & 1 deletion func.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package gox

import (
"fmt"
"go/ast"
"go/token"
"go/types"
Expand Down Expand Up @@ -61,7 +62,17 @@ type Func struct {
// BodyStart func
func (p *Func) BodyStart(pkg *Package) *CodeBuilder {
if debugInstr {
log.Println("NewFunc", p.Name(), p.Type())
var recv string
tag := "NewFunc "
name := p.Name()
sig := p.Type().(*types.Signature)
if v := sig.Recv(); v != nil {
recv = fmt.Sprintf(" (%v)", v.Type())
}
if name == "" {
tag = "NewClosure"
}
log.Printf("%v%v%v %v\n", tag, name, recv, sig)
}
return pkg.cb.startFuncBody(p, &p.old)
}
Expand Down
6 changes: 3 additions & 3 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (p *TemplateParamType) Underlying() types.Type {
}

func (p *TemplateParamType) String() string {
panic("TemplateParamType")
return fmt.Sprintf("TemplateParamType{name: %v}", p.name)
}

func (p *TemplateParamType) idx() int {
Expand Down Expand Up @@ -76,7 +76,7 @@ func (p *unboundFuncParam) Underlying() types.Type {
}

func (p *unboundFuncParam) String() string {
return fmt.Sprintf("*unboundFuncParam{typ: %v}", p.tBound)
return fmt.Sprintf("unboundFuncParam{typ: %v}", p.tBound)
}

type unboundProxyParam struct {
Expand All @@ -88,7 +88,7 @@ func (p *unboundProxyParam) Underlying() types.Type {
}

func (p *unboundProxyParam) String() string {
return fmt.Sprintf("*unboundProxyParam{typ: %v}", p.real)
return fmt.Sprintf("unboundProxyParam{typ: %v}", p.real)
}

func boundType(pkg *Package, arg, param types.Type) error {
Expand Down
12 changes: 6 additions & 6 deletions type_var_and_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (p *refType) Underlying() types.Type {
}

func (p *refType) String() string {
panic("ref type")
return fmt.Sprintf("refType{typ: %v}", p.typ)
}

// unboundType: unbound type
Expand All @@ -305,7 +305,7 @@ func (p *unboundType) Underlying() types.Type {
}

func (p *unboundType) String() string {
return fmt.Sprintf("*unboundType{typ: %v}", p.tBound)
return fmt.Sprintf("unboundType{typ: %v}", p.tBound)
}

func realType(typ types.Type) types.Type {
Expand All @@ -332,7 +332,7 @@ func (p *unboundMapElemType) Underlying() types.Type {
}

func (p *unboundMapElemType) String() string {
return fmt.Sprintf("*unboundMapElemType{key: %v}", p.key)
return fmt.Sprintf("unboundMapElemType{key: %v}", p.key)
}

// ----------------------------------------------------------------------------
Expand All @@ -347,7 +347,7 @@ func (p *overloadFuncType) Underlying() types.Type {
}

func (p *overloadFuncType) String() string {
return fmt.Sprintf("*overloadFuncType{funcs: %v}", p.funcs)
return fmt.Sprintf("overloadFuncType{funcs: %v}", p.funcs)
}

type instructionType struct {
Expand All @@ -359,7 +359,7 @@ func (p *instructionType) Underlying() types.Type {
}

func (p *instructionType) String() string {
return fmt.Sprintf("*instructionType{instr: %v}", reflect.TypeOf(p.instr))
return fmt.Sprintf("instructionType{instr: %v}", reflect.TypeOf(p.instr))
}

func isType(t types.Type) bool {
Expand Down Expand Up @@ -391,7 +391,7 @@ func (p *TypeType) Underlying() types.Type {
}

func (p *TypeType) String() string {
return fmt.Sprintf("*TypeType{typ: %v}", p.typ)
return fmt.Sprintf("TypeType{typ: %v}", p.typ)
}

// ----------------------------------------------------------------------------

0 comments on commit 86ace58

Please sign in to comment.