github.com/nevalang/neva@v0.23.1-0.20240507185603-7696a9bb8dda/internal/compiler/sourcecode/typesystem/trace.go (about) 1 package typesystem 2 3 import ( 4 "github.com/nevalang/neva/internal/compiler/sourcecode/core" 5 ) 6 7 // Linked-list to handle recursive types 8 type Trace struct { 9 prev *Trace 10 cur core.EntityRef 11 } 12 13 // O(2n) 14 func (t Trace) String() string { 15 lastToFirst := []core.EntityRef{} 16 17 tmp := &t 18 for tmp != nil { 19 lastToFirst = append(lastToFirst, tmp.cur) 20 tmp = tmp.prev 21 } 22 23 firstToLast := "[" 24 for i := len(lastToFirst) - 1; i >= 0; i-- { 25 firstToLast += lastToFirst[i].String() 26 if i > 0 { 27 firstToLast += ", " 28 } 29 } 30 31 return firstToLast + "]" 32 } 33 34 func NewTrace(prev *Trace, cur core.EntityRef) Trace { 35 return Trace{ 36 prev: prev, 37 cur: cur, 38 } 39 }