LEFT | RIGHT |
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/token" | 8 "go/token" |
9 | 9 |
| 10 "code.google.com/p/go.tools/oracle/json" |
10 "code.google.com/p/go.tools/pointer" | 11 "code.google.com/p/go.tools/pointer" |
11 "code.google.com/p/go.tools/ssa" | 12 "code.google.com/p/go.tools/ssa" |
12 ) | 13 ) |
13 | 14 |
14 // Callers reports the possible callers of the function | 15 // Callers reports the possible callers of the function |
15 // immediately enclosing the specified source location. | 16 // immediately enclosing the specified source location. |
16 // | 17 // |
17 // TODO(adonovan): if a caller is a wrapper, show the caller's caller. | 18 // TODO(adonovan): if a caller is a wrapper, show the caller's caller. |
18 // | 19 // |
19 func callers(o *oracle) (queryResult, error) { | 20 func callers(o *oracle) (queryResult, error) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 for _, site := range r.calls { | 66 for _, site := range r.calls { |
66 if site.Caller() == r.root { | 67 if site.Caller() == r.root { |
67 printf(r.target, "the root of the call graph") | 68 printf(r.target, "the root of the call graph") |
68 } else { | 69 } else { |
69 printf(site, "\t%s from %s", site.Description(),
site.Caller().Func()) | 70 printf(site, "\t%s from %s", site.Description(),
site.Caller().Func()) |
70 } | 71 } |
71 } | 72 } |
72 } | 73 } |
73 } | 74 } |
74 | 75 |
75 func (r *callersResult) toJSON(res *ResultJSON, fset *token.FileSet) { | 76 func (r *callersResult) toJSON(res *json.Result, fset *token.FileSet) { |
76 » var callers []CallerJSON | 77 » var callers []json.Caller |
77 for _, site := range r.calls { | 78 for _, site := range r.calls { |
78 » » var c CallerJSON | 79 » » var c json.Caller |
79 c.Caller = site.Caller().Func().String() | 80 c.Caller = site.Caller().Func().String() |
80 if site.Caller() == r.root { | 81 if site.Caller() == r.root { |
81 c.Desc = "synthetic call" | 82 c.Desc = "synthetic call" |
82 } else { | 83 } else { |
83 c.Pos = site.Caller().Func().Prog.Fset.Position(site.Pos
()).String() | 84 c.Pos = site.Caller().Func().Prog.Fset.Position(site.Pos
()).String() |
84 c.Desc = site.Description() | 85 c.Desc = site.Description() |
85 } | 86 } |
86 callers = append(callers, c) | 87 callers = append(callers, c) |
87 } | 88 } |
88 res.Callers = callers | 89 res.Callers = callers |
89 } | 90 } |
LEFT | RIGHT |