github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/tools/oracle/serial/serial.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package serial defines the oracle's schema for structured data 6 // serialization using JSON, XML, etc. 7 package serial 8 9 // All 'pos' strings are of the form "file:line:col". 10 // TODO(adonovan): improve performance by sharing filename strings. 11 // TODO(adonovan): improve precision by providing the start/end 12 // interval when available. 13 // 14 // TODO(adonovan): consider richer encodings of types, functions, 15 // methods, etc. 16 17 // A Peers is the result of a 'peers' query. 18 // If Allocs is empty, the selected channel can't point to anything. 19 type Peers struct { 20 Pos string `json:"pos"` // location of the selected channel op (<-) 21 Type string `json:"type"` // type of the selected channel 22 Allocs []string `json:"allocs,omitempty"` // locations of aliased make(chan) ops 23 Sends []string `json:"sends,omitempty"` // locations of aliased ch<-x ops 24 Receives []string `json:"receives,omitempty"` // locations of aliased <-ch ops 25 Closes []string `json:"closes,omitempty"` // locations of aliased close(ch) ops 26 } 27 28 // A Referrers is the result of a 'referrers' query. 29 type Referrers struct { 30 Pos string `json:"pos"` // location of the query reference 31 ObjPos string `json:"objpos,omitempty"` // location of the definition 32 Desc string `json:"desc"` // description of the denoted object 33 Refs []string `json:"refs,omitempty"` // locations of all references 34 } 35 36 // A Definition is the result of a 'definition' query. 37 type Definition struct { 38 ObjPos string `json:"objpos,omitempty"` // location of the definition 39 Desc string `json:"desc"` // description of the denoted object 40 } 41 42 type CalleesItem struct { 43 Name string `json:"name"` // full name of called function 44 Pos string `json:"pos"` // location of called function 45 } 46 47 // A Callees is the result of a 'callees' query. 48 // 49 // Callees is nonempty unless the call was a dynamic call on a 50 // provably nil func or interface value. 51 type Callees struct { 52 Pos string `json:"pos"` // location of selected call site 53 Desc string `json:"desc"` // description of call site 54 Callees []*CalleesItem `json:"callees,omitempty"` // set of possible call targets 55 } 56 57 // A Caller is one element of the slice returned by a 'callers' query. 58 // (Callstack also contains a similar slice.) 59 // 60 // The root of the callgraph has an unspecified "Caller" string. 61 type Caller struct { 62 Pos string `json:"pos,omitempty"` // location of the calling function 63 Desc string `json:"desc"` // description of call site 64 Caller string `json:"caller"` // full name of calling function 65 } 66 67 // A CallStack is the result of a 'callstack' query. 68 // It indicates an arbitrary path from the root of the callgraph to 69 // the query function. 70 // 71 // If the Callers slice is empty, the function was unreachable in this 72 // analysis scope. 73 type CallStack struct { 74 Pos string `json:"pos"` // location of the selected function 75 Target string `json:"target"` // the selected function 76 Callers []Caller `json:"callers"` // enclosing calls, innermost first. 77 } 78 79 // A FreeVar is one element of the slice returned by a 'freevars' 80 // query. Each one identifies an expression referencing a local 81 // identifier defined outside the selected region. 82 type FreeVar struct { 83 Pos string `json:"pos"` // location of the identifier's definition 84 Kind string `json:"kind"` // one of {var,func,type,const,label} 85 Ref string `json:"ref"` // referring expression (e.g. "x" or "x.y.z") 86 Type string `json:"type"` // type of the expression 87 } 88 89 // An Implements contains the result of an 'implements' query. 90 // It describes the queried type, the set of named non-empty interface 91 // types to which it is assignable, and the set of named/*named types 92 // (concrete or non-empty interface) which may be assigned to it. 93 // 94 type Implements struct { 95 T ImplementsType `json:"type,omitempty"` // the queried type 96 AssignableTo []ImplementsType `json:"to,omitempty"` // types assignable to T 97 AssignableFrom []ImplementsType `json:"from,omitempty"` // interface types assignable from T 98 AssignableFromPtr []ImplementsType `json:"fromptr,omitempty"` // interface types assignable only from *T 99 100 // The following fields are set only if the query was a method. 101 // Assignable{To,From,FromPtr}Method[i] is the corresponding 102 // method of type Assignable{To,From,FromPtr}[i], or blank 103 // {"",""} if that type lacks the method. 104 Method *DescribeMethod `json:"method,omitempty"` // the queried method 105 AssignableToMethod []DescribeMethod `json:"to_method,omitempty"` 106 AssignableFromMethod []DescribeMethod `json:"from_method,omitempty"` 107 AssignableFromPtrMethod []DescribeMethod `json:"fromptr_method,omitempty"` 108 } 109 110 // An ImplementsType describes a single type as part of an 'implements' query. 111 type ImplementsType struct { 112 Name string `json:"name"` // full name of the type 113 Pos string `json:"pos"` // location of its definition 114 Kind string `json:"kind"` // "basic", "array", etc 115 } 116 117 // A SyntaxNode is one element of a stack of enclosing syntax nodes in 118 // a "what" query. 119 type SyntaxNode struct { 120 Description string `json:"desc"` // description of syntax tree 121 Start int `json:"start"` // start byte offset, 0-based 122 End int `json:"end"` // end byte offset 123 } 124 125 // A What is the result of the "what" query, which quickly identifies 126 // the selection, parsing only a single file. It is intended for use 127 // in low-latency GUIs. 128 type What struct { 129 Enclosing []SyntaxNode `json:"enclosing"` // enclosing nodes of syntax tree 130 Modes []string `json:"modes"` // query modes enabled for this selection. 131 SrcDir string `json:"srcdir,omitempty"` // $GOROOT src directory containing queried package 132 ImportPath string `json:"importpath,omitempty"` // import path of queried package 133 } 134 135 // A PointsToLabel describes a pointer analysis label. 136 // 137 // A "label" is an object that may be pointed to by a pointer, map, 138 // channel, 'func', slice or interface. Labels include: 139 // - functions 140 // - globals 141 // - arrays created by literals (e.g. []byte("foo")) and conversions ([]byte(s)) 142 // - stack- and heap-allocated variables (including composite literals) 143 // - arrays allocated by append() 144 // - channels, maps and arrays created by make() 145 // - and their subelements, e.g. "alloc.y[*].z" 146 // 147 type PointsToLabel struct { 148 Pos string `json:"pos"` // location of syntax that allocated the object 149 Desc string `json:"desc"` // description of the label 150 } 151 152 // A PointsTo is one element of the result of a 'pointsto' query on an 153 // expression. It describes a single pointer: its type and the set of 154 // "labels" it points to. 155 // 156 // If the pointer is of interface type, it will have one PTS entry 157 // describing each concrete type that it may contain. For each 158 // concrete type that is a pointer, the PTS entry describes the labels 159 // it may point to. The same is true for reflect.Values, except the 160 // dynamic types needn't be concrete. 161 // 162 type PointsTo struct { 163 Type string `json:"type"` // (concrete) type of the pointer 164 NamePos string `json:"namepos,omitempty"` // location of type defn, if Named 165 Labels []PointsToLabel `json:"labels,omitempty"` // pointed-to objects 166 } 167 168 // A DescribeValue is the additional result of a 'describe' query 169 // if the selection indicates a value or expression. 170 type DescribeValue struct { 171 Type string `json:"type"` // type of the expression 172 Value string `json:"value,omitempty"` // value of the expression, if constant 173 ObjPos string `json:"objpos,omitempty"` // location of the definition, if an Ident 174 } 175 176 type DescribeMethod struct { 177 Name string `json:"name"` // method name, as defined by types.Selection.String() 178 Pos string `json:"pos"` // location of the method's definition 179 } 180 181 // A DescribeType is the additional result of a 'describe' query 182 // if the selection indicates a type. 183 type DescribeType struct { 184 Type string `json:"type"` // the string form of the type 185 NamePos string `json:"namepos,omitempty"` // location of definition of type, if named 186 NameDef string `json:"namedef,omitempty"` // underlying definition of type, if named 187 Methods []DescribeMethod `json:"methods,omitempty"` // methods of the type 188 } 189 190 type DescribeMember struct { 191 Name string `json:"name"` // name of member 192 Type string `json:"type,omitempty"` // type of member (underlying, if 'type') 193 Value string `json:"value,omitempty"` // value of member (if 'const') 194 Pos string `json:"pos"` // location of definition of member 195 Kind string `json:"kind"` // one of {var,const,func,type} 196 Methods []DescribeMethod `json:"methods,omitempty"` // methods (if member is a type) 197 } 198 199 // A DescribePackage is the additional result of a 'describe' if 200 // the selection indicates a package. 201 type DescribePackage struct { 202 Path string `json:"path"` // import path of the package 203 Members []*DescribeMember `json:"members,omitempty"` // accessible members of the package 204 } 205 206 // A Describe is the result of a 'describe' query. 207 // It may contain an element describing the selected semantic entity 208 // in detail. 209 type Describe struct { 210 Desc string `json:"desc"` // description of the selected syntax node 211 Pos string `json:"pos"` // location of the selected syntax node 212 Detail string `json:"detail,omitempty"` // one of {package, type, value}, or "". 213 214 // At most one of the following fields is populated: 215 // the one specified by 'detail'. 216 Package *DescribePackage `json:"package,omitempty"` 217 Type *DescribeType `json:"type,omitempty"` 218 Value *DescribeValue `json:"value,omitempty"` 219 } 220 221 // A WhichErrs is the result of a 'whicherrs' query. 222 // It contains the position of the queried error and the possible globals, 223 // constants, and types it may point to. 224 type WhichErrs struct { 225 ErrPos string `json:"errpos,omitempty"` // location of queried error 226 Globals []string `json:"globals,omitempty"` // locations of globals 227 Constants []string `json:"constants,omitempty"` // locations of constants 228 Types []WhichErrsType `json:"types,omitempty"` // Types 229 } 230 231 type WhichErrsType struct { 232 Type string `json:"type,omitempty"` 233 Position string `json:"position,omitempty"` 234 } 235 236 // A Result is the common result of any oracle query. 237 // It contains a query-specific result element. 238 // 239 // TODO(adonovan): perhaps include other info such as: analysis scope, 240 // raw query position, stack of ast nodes, query package, etc. 241 type Result struct { 242 Mode string `json:"mode"` // mode of the query 243 244 // Exactly one of the following fields is populated: 245 // the one specified by 'mode'. 246 Callees *Callees `json:"callees,omitempty"` 247 Callers []Caller `json:"callers,omitempty"` 248 Callstack *CallStack `json:"callstack,omitempty"` 249 Definition *Definition `json:"definition,omitempty"` 250 Describe *Describe `json:"describe,omitempty"` 251 Freevars []*FreeVar `json:"freevars,omitempty"` 252 Implements *Implements `json:"implements,omitempty"` 253 Peers *Peers `json:"peers,omitempty"` 254 PointsTo []PointsTo `json:"pointsto,omitempty"` 255 Referrers *Referrers `json:"referrers,omitempty"` 256 What *What `json:"what,omitempty"` 257 WhichErrs *WhichErrs `json:"whicherrs,omitempty"` 258 }