github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/tools/trim/debug.go (about) 1 // Copyright 2021 CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package trim 16 17 import ( 18 "fmt" 19 "strings" 20 21 "github.com/joomcode/cue/internal/core/adt" 22 ) 23 24 func (t *trimmer) trace(v *adt.Vertex) (*trimmer, *adt.Vertex) { 25 if t.debug { 26 t.indent++ 27 fmt.Fprintf(t.w, "%s%s {\n", 28 strings.Repeat("..", t.indent), 29 v.Label.SelectorString(t.ctx)) 30 } 31 return t, v 32 } 33 34 func un(t *trimmer, v *adt.Vertex) { 35 if !t.debug { 36 return 37 } 38 fmt.Fprintf(t.w, "%s}\n", 39 strings.Repeat("..", t.indent)) 40 t.indent-- 41 } 42 43 func (t *trimmer) logf(format string, args ...interface{}) { 44 if !t.debug { 45 return 46 } 47 fmt.Fprint(t.w, strings.Repeat("..", t.indent+1)) 48 fmt.Fprintf(t.w, format, args...) 49 fmt.Fprintln(t.w) 50 }