Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(666)

Delta Between Two Patch Sets: oracle/callees.go

Issue 13270045: code review 13270045: go.tools/oracle: add option to output results in JSON s... (Closed)
Left Patch Set: diff -r 7c53df5c9267 https://code.google.com/p/go.tools Created 10 years, 6 months ago
Right Patch Set: diff -r 07183b5c385c https://code.google.com/p/go.tools Created 10 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/oracle/main.go ('k') | oracle/callers.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2013 The Go Authors. All rights reserved. 1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package oracle 5 package oracle
6 6
7 import ( 7 import (
8 "go/ast" 8 "go/ast"
9 "go/token" 9 "go/token"
10 "sort" 10 "sort"
11 11
12 "code.google.com/p/go.tools/go/types" 12 "code.google.com/p/go.tools/go/types"
13 "code.google.com/p/go.tools/oracle/json"
13 "code.google.com/p/go.tools/pointer" 14 "code.google.com/p/go.tools/pointer"
14 "code.google.com/p/go.tools/ssa" 15 "code.google.com/p/go.tools/ssa"
15 ) 16 )
16 17
17 // Callees reports the possible callees of the function call site 18 // Callees reports the possible callees of the function call site
18 // identified by the specified source location. 19 // identified by the specified source location.
19 // 20 //
20 // TODO(adonovan): if a callee is a wrapper, show the callee's callee. 21 // TODO(adonovan): if a callee is a wrapper, show the callee's callee.
21 // 22 //
22 func callees(o *oracle) (queryResult, error) { 23 func callees(o *oracle) (queryResult, error) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // dynamic call on a provably nil func/interface 104 // dynamic call on a provably nil func/interface
104 printf(r.site, "%s on nil value", r.site.Description()) 105 printf(r.site, "%s on nil value", r.site.Description())
105 } else { 106 } else {
106 printf(r.site, "this %s dispatches to:", r.site.Description()) 107 printf(r.site, "this %s dispatches to:", r.site.Description())
107 for _, callee := range r.funcs { 108 for _, callee := range r.funcs {
108 printf(callee, "\t%s", callee) 109 printf(callee, "\t%s", callee)
109 } 110 }
110 } 111 }
111 } 112 }
112 113
113 func (r *calleesResult) toJSON(res *ResultJSON, fset *token.FileSet) { 114 func (r *calleesResult) toJSON(res *json.Result, fset *token.FileSet) {
114 » j := &CalleesJSON{ 115 » j := &json.Callees{
115 Pos: r.site.Caller().Func().Prog.Fset.Position(r.site.Pos()).St ring(), 116 Pos: r.site.Caller().Func().Prog.Fset.Position(r.site.Pos()).St ring(),
116 Desc: r.site.Description(), 117 Desc: r.site.Description(),
117 } 118 }
118 for _, callee := range r.funcs { 119 for _, callee := range r.funcs {
119 » » j.Callees = append(j.Callees, &CalleesItemJSON{ 120 » » j.Callees = append(j.Callees, &json.CalleesItem{
120 Name: callee.String(), 121 Name: callee.String(),
121 Pos: callee.Prog.Fset.Position(callee.Pos()).String(), 122 Pos: callee.Prog.Fset.Position(callee.Pos()).String(),
122 }) 123 })
123 } 124 }
124 res.Callees = j 125 res.Callees = j
125 } 126 }
126 127
127 type byFuncPos []*ssa.Function 128 type byFuncPos []*ssa.Function
128 129
129 func (a byFuncPos) Len() int { return len(a) } 130 func (a byFuncPos) Len() int { return len(a) }
130 func (a byFuncPos) Less(i, j int) bool { return a[i].Pos() < a[j].Pos() } 131 func (a byFuncPos) Less(i, j int) bool { return a[i].Pos() < a[j].Pos() }
131 func (a byFuncPos) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 132 func (a byFuncPos) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b