github.com/jmigpin/editor@v1.6.0/core/godebug/debug/structs.go (about) 1 package debug 2 3 import ( 4 "fmt" 5 ) 6 7 func RegisterStructsForEncodeDecode(encoderId string) { 8 reg := func(v interface{}) { 9 registerForEncodeDecode(encoderId, v) 10 } 11 12 reg(&ReqFilesDataMsg{}) 13 reg(&FilesDataMsg{}) 14 reg(&ReqStartMsg{}) 15 reg(&LineMsg{}) 16 reg([]*LineMsg{}) 17 18 reg(&ItemValue{}) 19 reg(&ItemList{}) 20 reg(&ItemList2{}) 21 reg(&ItemAssign{}) 22 reg(&ItemSend{}) 23 reg(&ItemCall{}) 24 reg(&ItemCallEnter{}) 25 reg(&ItemIndex{}) 26 reg(&ItemIndex2{}) 27 reg(&ItemKeyValue{}) 28 reg(&ItemSelector{}) 29 reg(&ItemTypeAssert{}) 30 reg(&ItemBinary{}) 31 reg(&ItemUnary{}) 32 reg(&ItemUnaryEnter{}) 33 reg(&ItemParen{}) 34 reg(&ItemLiteral{}) 35 reg(&ItemBranch{}) 36 reg(&ItemStep{}) 37 reg(&ItemAnon{}) 38 reg(&ItemLabel{}) 39 reg(&ItemNotAnn{}) 40 } 41 42 //---------- 43 44 type ReqFilesDataMsg struct{} 45 type ReqStartMsg struct{} 46 47 //---------- 48 49 type LineMsg struct { 50 FileIndex int 51 DebugIndex int 52 Offset int 53 Item Item 54 } 55 56 type FilesDataMsg struct { 57 Data []*AnnotatorFileData 58 } 59 60 type AnnotatorFileData struct { 61 FileIndex int 62 DebugLen int 63 Filename string 64 FileSize int 65 FileHash []byte 66 } 67 68 //---------- 69 70 type Item interface { 71 isItem() 72 } 73 74 type ItemValue struct { 75 Item 76 Str string 77 } 78 79 type ItemList struct { // separated by "," 80 Item 81 List []Item 82 } 83 type ItemList2 struct { // separated by ";" 84 Item 85 List []Item 86 } 87 type ItemAssign struct { 88 Item 89 Lhs *ItemList 90 Op int 91 Rhs *ItemList 92 } 93 type ItemSend struct { 94 Item 95 Chan, Value Item 96 } 97 type ItemCallEnter struct { 98 Item 99 Fun Item 100 Args *ItemList 101 } 102 type ItemCall struct { 103 Item 104 Enter *ItemCallEnter 105 Result Item 106 } 107 type ItemIndex struct { 108 Item 109 Expr Item 110 Index Item 111 Result Item 112 } 113 type ItemIndex2 struct { 114 Item 115 Expr Item 116 Low, High, Max Item 117 Slice3 bool // 2 colons present 118 Result Item 119 } 120 type ItemKeyValue struct { 121 Item 122 Key Item 123 Value Item 124 } 125 type ItemSelector struct { 126 Item 127 X Item 128 Sel Item 129 } 130 type ItemTypeAssert struct { 131 Item 132 X Item 133 Type Item 134 } 135 type ItemBinary struct { 136 Item 137 X Item 138 Op int 139 Y Item 140 Result Item 141 } 142 type ItemUnaryEnter struct { 143 Item 144 Op int 145 X Item 146 } 147 type ItemUnary struct { 148 Item 149 Enter *ItemUnaryEnter 150 Result Item 151 } 152 type ItemLiteral struct { 153 Item 154 Fields *ItemList 155 } 156 type ItemParen struct { 157 Item 158 X Item 159 } 160 type ItemLabel struct { 161 Item 162 Reason string // ex: "for" init not debugged 163 } 164 type ItemNotAnn struct { 165 Item 166 Reason string // not annotated (ex: String(), Error()) 167 } 168 type ItemBranch struct { 169 Item 170 } 171 type ItemStep struct { 172 Item 173 } 174 type ItemAnon struct { 175 Item 176 } 177 178 //---------- 179 180 // ItemValue: interface (ex: int=1, string="1") 181 func IVi(v interface{}) Item { 182 return &ItemValue{Str: stringify(v)} 183 } 184 185 // ItemValue: string (ex: value of "?" is presented without quotes) 186 func IVs(s string) Item { 187 return &ItemValue{Str: s} 188 } 189 190 // ItemValue: typeof 191 func IVt(v interface{}) Item { 192 s := fmt.Sprintf("%T", v) 193 return &ItemValue{Str: s} 194 } 195 196 // ItemValue: range 197 func IVr(v int) Item { 198 s := fmt.Sprintf("range(%v=len())", v) 199 return &ItemValue{Str: s} 200 } 201 202 //// ItemValue: printf 203 //// usage: f(ctx,"IVp", basicLitStringQ("%v"), basicLitInt(1)) 204 //func IVp(format string, args ...interface{}) Item { 205 // return &ItemValue{Str: fmt.Sprintf(format, args...)} 206 //} 207 208 // ItemList ("," and ";") 209 func IL(u ...Item) *ItemList { 210 return &ItemList{List: u} 211 } 212 func IL2(u ...Item) Item { 213 return &ItemList2{List: u} 214 } 215 216 // ItemAssign 217 func IA(lhs *ItemList, op int, rhs *ItemList) Item { 218 return &ItemAssign{Lhs: lhs, Op: op, Rhs: rhs} 219 } 220 221 // ItemSend 222 func IS(ch, value Item) Item { 223 return &ItemSend{Chan: ch, Value: value} 224 } 225 226 // ItemCall: enter 227 func ICe(fun Item, args *ItemList) Item { 228 return &ItemCallEnter{Fun: fun, Args: args} 229 } 230 231 // ItemCall 232 func IC(enter Item, result Item) Item { 233 u := enter.(*ItemCallEnter) 234 return &ItemCall{Enter: u, Result: result} 235 } 236 237 // ItemIndex 238 func II(expr, index, result Item) Item { 239 return &ItemIndex{Expr: expr, Index: index, Result: result} 240 } 241 func II2(expr, low, high, max Item, slice3 bool, result Item) Item { 242 return &ItemIndex2{Expr: expr, Low: low, High: high, Max: max, Slice3: slice3, Result: result} 243 } 244 245 // ItemKeyValue 246 func IKV(key, value Item) Item { 247 return &ItemKeyValue{Key: key, Value: value} 248 } 249 250 // ItemSelector 251 func ISel(x, sel Item) Item { 252 return &ItemSelector{X: x, Sel: sel} 253 } 254 255 // ItemTypeAssert 256 func ITA(x, t Item) Item { 257 return &ItemTypeAssert{X: x, Type: t} 258 } 259 260 // ItemBinary 261 func IB(x Item, op int, y Item, result Item) Item { 262 return &ItemBinary{X: x, Op: op, Y: y, Result: result} 263 } 264 265 // ItemUnary: enter 266 func IUe(op int, x Item) Item { 267 return &ItemUnaryEnter{Op: op, X: x} 268 } 269 270 // ItemUnary 271 func IU(enter Item, result Item) Item { 272 u := enter.(*ItemUnaryEnter) 273 return &ItemUnary{Enter: u, Result: result} 274 } 275 276 // ItemParen 277 func IP(x Item) Item { 278 return &ItemParen{X: x} 279 } 280 281 // ItemLiteral 282 func ILit(fields *ItemList) Item { 283 return &ItemLiteral{Fields: fields} 284 } 285 286 // ItemBranch 287 func IBr() Item { 288 return &ItemBranch{} 289 } 290 291 // ItemStep 292 func ISt() Item { 293 return &ItemStep{} 294 } 295 296 // ItemAnon 297 func IAn() Item { 298 return &ItemAnon{} 299 } 300 301 // ItemLabel 302 func ILa(reason string) Item { 303 return &ItemLabel{Reason: reason} 304 } 305 306 // ItemNotAnn 307 func INAnn(reason string) Item { 308 return &ItemNotAnn{Reason: reason} 309 }