MCPcopy Create free account
hub / github.com/dlclark/regexp2 / OpcodeDescription

Method OpcodeDescription

syntax/code.go:279–356  ·  view source on GitHub ↗

OpcodeDescription is a humman readable string of the specific offset

(offset int)

Source from the content-addressed store, hash-verified

277
278// OpcodeDescription is a humman readable string of the specific offset
279func (c *Code) OpcodeDescription(offset int) string {
280 buf := &bytes.Buffer{}
281
282 op := InstOp(c.Codes[offset])
283 fmt.Fprintf(buf, "%06d ", offset)
284
285 if opcodeBacktracks(op & Mask) {
286 buf.WriteString("*")
287 } else {
288 buf.WriteString(" ")
289 }
290 buf.WriteString(operatorDescription(op))
291 buf.WriteString("(")
292 op &= Mask
293
294 switch op {
295 case One, Notone, Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy,
296 Oneloopatomic, Notoneloopatomic:
297 buf.WriteString("Ch = ")
298 buf.WriteString(CharDescription(rune(c.Codes[offset+1])))
299
300 case Set, Setrep, Setloop, Setlazy, Setloopatomic:
301 buf.WriteString("Set = ")
302 buf.WriteString(c.Sets[c.Codes[offset+1]].String())
303
304 case Dispatch:
305 tableIndex := c.Codes[offset+1]
306 fmt.Fprintf(buf, "Table = %d", tableIndex)
307 if tableIndex >= 0 && tableIndex < len(c.Dispatches) {
308 table := &c.Dispatches[tableIndex]
309 for i, setIndex := range table.Sets {
310 fmt.Fprintf(buf, ", %s -> %d", c.Sets[setIndex].String(), table.Branches[i])
311 }
312 }
313
314 case Multi:
315 fmt.Fprintf(buf, "String = %s", string(c.Strings[c.Codes[offset+1]]))
316
317 case Ref, Testref, ResetCapture:
318 fmt.Fprintf(buf, "Index = %d", c.Codes[offset+1])
319
320 case Capturemark:
321 fmt.Fprintf(buf, "Index = %d", c.Codes[offset+1])
322 if c.Codes[offset+2] != -1 {
323 fmt.Fprintf(buf, ", Unindex = %d", c.Codes[offset+2])
324 }
325
326 case Nullcount, Setcount:
327 fmt.Fprintf(buf, "Value = %d", c.Codes[offset+1])
328
329 case Goto, Lazybranch, Branchmark, Lazybranchmark, Branchcount, Lazybranchcount:
330 fmt.Fprintf(buf, "Addr = %d", c.Codes[offset+1])
331 }
332
333 switch op {
334 case Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy, Setrep, Setloop, Setlazy,
335 Oneloopatomic, Notoneloopatomic, Setloopatomic:
336 buf.WriteString(", Rep = ")

Callers 2

DumpMethod · 0.95
dumpStateMethod · 0.80

Calls 5

InstOpTypeAlias · 0.85
opcodeBacktracksFunction · 0.85
operatorDescriptionFunction · 0.85
CharDescriptionFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected