this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

all: make use of stringer in more places

This replaces about 100 lines of manually maintained code
with about 190 lines of automatically generated code with stringer.
The strings are now the constant names themselves, or in the case
of `stringer -linecomment`, in inline comments following the names.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I90e0463fcf82ebe2d6cfd43f90aed4442f71eb16
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199854
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+196 -111
+8 -12
cue/token/position.go
··· 115 115 // RelPos indicates the relative position of token to the previous token. 116 116 type RelPos int 117 117 118 + //go:generate go run golang.org/x/tools/cmd/stringer -type=RelPos -linecomment 119 + 118 120 const ( 119 121 // NoRelPos indicates no relative position is specified. 120 - NoRelPos RelPos = iota 122 + NoRelPos RelPos = iota // invalid 121 123 122 124 // Elided indicates that the token for which this position is defined is 123 125 // not rendered at all. 124 - Elided 126 + Elided // elided 125 127 126 128 // NoSpace indicates there is no whitespace before this token. 127 - NoSpace 129 + NoSpace // nospace 128 130 129 131 // Blank means there is horizontal space before this token. 130 - Blank 132 + Blank // blank 131 133 132 134 // Newline means there is a single newline before this token. 133 - Newline 135 + Newline // newline 134 136 135 137 // NewSection means there are two or more newlines before this token. 136 - NewSection 138 + NewSection // section 137 139 138 140 relMask = 0xf 139 141 relShift = 4 140 142 ) 141 - 142 - var relNames = []string{ 143 - "invalid", "elided", "nospace", "blank", "newline", "section", 144 - } 145 - 146 - func (p RelPos) String() string { return relNames[p] } 147 143 148 144 func (p RelPos) Pos() Pos { 149 145 return Pos{nil, int(p)}
+28
cue/token/relpos_string.go
··· 1 + // Code generated by "stringer -type=RelPos -linecomment"; DO NOT EDIT. 2 + 3 + package token 4 + 5 + import "strconv" 6 + 7 + func _() { 8 + // An "invalid array index" compiler error signifies that the constant values have changed. 9 + // Re-run the stringer command to generate them again. 10 + var x [1]struct{} 11 + _ = x[NoRelPos-0] 12 + _ = x[Elided-1] 13 + _ = x[NoSpace-2] 14 + _ = x[Blank-3] 15 + _ = x[Newline-4] 16 + _ = x[NewSection-5] 17 + } 18 + 19 + const _RelPos_name = "invalidelidednospaceblanknewlinesection" 20 + 21 + var _RelPos_index = [...]uint8{0, 7, 13, 20, 25, 32, 39} 22 + 23 + func (i RelPos) String() string { 24 + if i < 0 || i >= RelPos(len(_RelPos_index)-1) { 25 + return "RelPos(" + strconv.FormatInt(int64(i), 10) + ")" 26 + } 27 + return _RelPos_name[_RelPos_index[i]:_RelPos_index[i+1]] 28 + }
+2 -19
internal/core/adt/composite.go
··· 499 499 // vertexStatus indicates the evaluation progress of a Vertex. 500 500 type vertexStatus int8 501 501 502 + //go:generate go run golang.org/x/tools/cmd/stringer -type=vertexStatus 503 + 502 504 const ( 503 505 // unprocessed indicates a Vertex has not been processed before. 504 506 // Value must be nil. ··· 528 530 // are save to use without further consideration. 529 531 finalized 530 532 ) 531 - 532 - func (s vertexStatus) String() string { 533 - switch s { 534 - case unprocessed: 535 - return "unprocessed" 536 - case evaluating: 537 - return "evaluating" 538 - case partial: 539 - return "partial" 540 - case conjuncts: 541 - return "conjuncts" 542 - case evaluatingArcs: 543 - return "evaluatingArcs" 544 - case finalized: 545 - return "finalized" 546 - default: 547 - return "unknown" 548 - } 549 - } 550 533 551 534 func (v *Vertex) Status() vertexStatus { 552 535 return v.status
+2 -31
internal/core/adt/debug.go
··· 152 152 // dependencies are balanced. 153 153 type depKind int 154 154 155 + //go:generate go run golang.org/x/tools/cmd/stringer -type=depKind 156 + 155 157 const ( 156 158 // PARENT dependencies are used to track the completion of parent 157 159 // closedContexts within the closedness tree. ··· 199 201 // TEST is used for testing notifications. 200 202 TEST // Always refers to self. 201 203 ) 202 - 203 - func (k depKind) String() string { 204 - switch k { 205 - case PARENT: 206 - return "PARENT" 207 - case ARC: 208 - return "ARC" 209 - case NOTIFY: 210 - return "NOTIFY" 211 - case TASK: 212 - return "TASK" 213 - case DISJUNCT: 214 - return "DISJUNCT" 215 - case EVAL: 216 - return "EVAL" 217 - case COMP: 218 - return "COMP" 219 - case ROOT: 220 - return "ROOT" 221 - 222 - case INIT: 223 - return "INIT" 224 - case DEFER: 225 - return "DEFER" 226 - case SHARED: 227 - return "SHARED" 228 - case TEST: 229 - return "TEST" 230 - } 231 - panic("unreachable") 232 - } 233 204 234 205 // ccDep is used to record counters which is used for debugging only. 235 206 // It is purpose is to be precise about matching inc/dec as well as to be able
+35
internal/core/adt/depkind_string.go
··· 1 + // Code generated by "stringer -type=depKind"; DO NOT EDIT. 2 + 3 + package adt 4 + 5 + import "strconv" 6 + 7 + func _() { 8 + // An "invalid array index" compiler error signifies that the constant values have changed. 9 + // Re-run the stringer command to generate them again. 10 + var x [1]struct{} 11 + _ = x[PARENT-1] 12 + _ = x[ARC-2] 13 + _ = x[NOTIFY-3] 14 + _ = x[TASK-4] 15 + _ = x[DISJUNCT-5] 16 + _ = x[EVAL-6] 17 + _ = x[COMP-7] 18 + _ = x[ROOT-8] 19 + _ = x[INIT-9] 20 + _ = x[DEFER-10] 21 + _ = x[SHARED-11] 22 + _ = x[TEST-12] 23 + } 24 + 25 + const _depKind_name = "PARENTARCNOTIFYTASKDISJUNCTEVALCOMPROOTINITDEFERSHAREDTEST" 26 + 27 + var _depKind_index = [...]uint8{0, 6, 9, 15, 19, 27, 31, 35, 39, 43, 48, 54, 58} 28 + 29 + func (i depKind) String() string { 30 + i -= 1 31 + if i < 0 || i >= depKind(len(_depKind_index)-1) { 32 + return "depKind(" + strconv.FormatInt(int64(i+1), 10) + ")" 33 + } 34 + return _depKind_name[_depKind_index[i]:_depKind_index[i+1]] 35 + }
+27
internal/core/adt/errorcode_string.go
··· 1 + // Code generated by "stringer -type=ErrorCode -linecomment"; DO NOT EDIT. 2 + 3 + package adt 4 + 5 + import "strconv" 6 + 7 + func _() { 8 + // An "invalid array index" compiler error signifies that the constant values have changed. 9 + // Re-run the stringer command to generate them again. 10 + var x [1]struct{} 11 + _ = x[EvalError-0] 12 + _ = x[UserError-1] 13 + _ = x[StructuralCycleError-2] 14 + _ = x[IncompleteError-3] 15 + _ = x[CycleError-4] 16 + } 17 + 18 + const _ErrorCode_name = "evaluserstructural cycleincompletecycle" 19 + 20 + var _ErrorCode_index = [...]uint8{0, 4, 8, 24, 34, 39} 21 + 22 + func (i ErrorCode) String() string { 23 + if i < 0 || i >= ErrorCode(len(_ErrorCode_index)-1) { 24 + return "ErrorCode(" + strconv.FormatInt(int64(i), 10) + ")" 25 + } 26 + return _ErrorCode_name[_ErrorCode_index[i]:_ErrorCode_index[i+1]] 27 + }
+7 -21
internal/core/adt/errors.go
··· 42 42 // control flow. No other aspects of an error may influence control flow. 43 43 type ErrorCode int8 44 44 45 + //go:generate go run golang.org/x/tools/cmd/stringer -type=ErrorCode -linecomment 46 + 45 47 const ( 46 48 // An EvalError is a fatal evaluation error. 47 - EvalError ErrorCode = iota 49 + EvalError ErrorCode = iota // eval 48 50 49 51 // A UserError is a fatal error originating from the user. 50 - UserError 52 + UserError // user 51 53 52 54 // StructuralCycleError means a structural cycle was found. Structural 53 55 // cycles are permanent errors, but they are not passed up recursively, 54 56 // as a unification of a value with a structural cycle with one that 55 57 // doesn't may still give a useful result. 56 - StructuralCycleError 58 + StructuralCycleError // structural cycle 57 59 58 60 // IncompleteError means an evaluation could not complete because of 59 61 // insufficient information that may still be added later. 60 - IncompleteError 62 + IncompleteError // incomplete 61 63 62 64 // A CycleError indicates a reference error. It is considered to be 63 65 // an incomplete error, as reference errors may be broken by providing 64 66 // a concrete value. 65 - CycleError 67 + CycleError // cycle 66 68 ) 67 - 68 - func (c ErrorCode) String() string { 69 - switch c { 70 - case EvalError: 71 - return "eval" 72 - case UserError: 73 - return "user" 74 - case StructuralCycleError: 75 - return "structural cycle" 76 - case IncompleteError: 77 - return "incomplete" 78 - case CycleError: 79 - return "cycle" 80 - } 81 - return "unknown" 82 - } 83 69 84 70 // Bottom represents an error or bottom symbol. 85 71 //
+27
internal/core/adt/runmode_string.go
··· 1 + // Code generated by "stringer -type=runMode"; DO NOT EDIT. 2 + 3 + package adt 4 + 5 + import "strconv" 6 + 7 + func _() { 8 + // An "invalid array index" compiler error signifies that the constant values have changed. 9 + // Re-run the stringer command to generate them again. 10 + var x [1]struct{} 11 + _ = x[ignore-1] 12 + _ = x[attemptOnly-2] 13 + _ = x[yield-3] 14 + _ = x[finalize-4] 15 + } 16 + 17 + const _runMode_name = "ignoreattemptOnlyyieldfinalize" 18 + 19 + var _runMode_index = [...]uint8{0, 6, 17, 22, 30} 20 + 21 + func (i runMode) String() string { 22 + i -= 1 23 + if i >= runMode(len(_runMode_index)-1) { 24 + return "runMode(" + strconv.FormatInt(int64(i+1), 10) + ")" 25 + } 26 + return _runMode_name[_runMode_index[i]:_runMode_index[i+1]] 27 + }
+2 -14
internal/core/adt/sched.go
··· 176 176 // runMode indicates how to proceed after a condition could not be met. 177 177 type runMode uint8 178 178 179 + //go:generate go run golang.org/x/tools/cmd/stringer -type=runMode 180 + 179 181 const ( 180 182 // ignore indicates that the new evaluator should not do any processing. 181 183 // This is mostly used in the transition from old to new evaluator and ··· 195 197 // complete the evaluation of a Vertex. 196 198 finalize 197 199 ) 198 - 199 - func (r runMode) String() string { 200 - switch r { 201 - case ignore: 202 - return "ignore" 203 - case attemptOnly: 204 - return "attemptOnly" 205 - case yield: 206 - return "yield" 207 - case finalize: 208 - return "finalize" 209 - } 210 - return "unknown" 211 - } 212 200 213 201 // condition is a bit mask of states that a task may depend on. 214 202 //
+28
internal/core/adt/vertexstatus_string.go
··· 1 + // Code generated by "stringer -type=vertexStatus"; DO NOT EDIT. 2 + 3 + package adt 4 + 5 + import "strconv" 6 + 7 + func _() { 8 + // An "invalid array index" compiler error signifies that the constant values have changed. 9 + // Re-run the stringer command to generate them again. 10 + var x [1]struct{} 11 + _ = x[unprocessed-0] 12 + _ = x[evaluating-1] 13 + _ = x[partial-2] 14 + _ = x[conjuncts-3] 15 + _ = x[evaluatingArcs-4] 16 + _ = x[finalized-5] 17 + } 18 + 19 + const _vertexStatus_name = "unprocessedevaluatingpartialconjunctsevaluatingArcsfinalized" 20 + 21 + var _vertexStatus_index = [...]uint8{0, 11, 21, 28, 37, 51, 60} 22 + 23 + func (i vertexStatus) String() string { 24 + if i < 0 || i >= vertexStatus(len(_vertexStatus_index)-1) { 25 + return "vertexStatus(" + strconv.FormatInt(int64(i), 10) + ")" 26 + } 27 + return _vertexStatus_name[_vertexStatus_index[i]:_vertexStatus_index[i+1]] 28 + }
+5 -14
internal/httplog/event.go
··· 13 13 14 14 type EventKind int 15 15 16 + //go:generate go run golang.org/x/tools/cmd/stringer -type=EventKind -linecomment 17 + 16 18 const ( 17 - NoEvent EventKind = iota 18 - KindClientSendRequest 19 - KindClientRecvResponse 19 + NoEvent EventKind = iota 20 + KindClientSendRequest // http client-> 21 + KindClientRecvResponse // http client<- 20 22 21 23 // TODO KindServerRecvRequest 22 24 // TODO KindServerSendResponse 23 25 ) 24 - 25 - func (k EventKind) String() string { 26 - switch k { 27 - case KindClientSendRequest: 28 - return "http client->" 29 - case KindClientRecvResponse: 30 - return "http client<-" 31 - default: 32 - return "unknown" 33 - } 34 - } 35 26 36 27 // Request represents an HTTP request. 37 28 type Request struct {
+25
internal/httplog/eventkind_string.go
··· 1 + // Code generated by "stringer -type=EventKind -linecomment"; DO NOT EDIT. 2 + 3 + package httplog 4 + 5 + import "strconv" 6 + 7 + func _() { 8 + // An "invalid array index" compiler error signifies that the constant values have changed. 9 + // Re-run the stringer command to generate them again. 10 + var x [1]struct{} 11 + _ = x[NoEvent-0] 12 + _ = x[KindClientSendRequest-1] 13 + _ = x[KindClientRecvResponse-2] 14 + } 15 + 16 + const _EventKind_name = "NoEventhttp client->http client<-" 17 + 18 + var _EventKind_index = [...]uint8{0, 7, 20, 33} 19 + 20 + func (i EventKind) String() string { 21 + if i < 0 || i >= EventKind(len(_EventKind_index)-1) { 22 + return "EventKind(" + strconv.FormatInt(int64(i), 10) + ")" 23 + } 24 + return _EventKind_name[_EventKind_index[i]:_EventKind_index[i+1]] 25 + }