github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/compiler/natives/src/internal/reflectlite/utils.go (about) 1 //go:build js 2 // +build js 3 4 package reflectlite 5 6 import ( 7 "unsafe" 8 ) 9 10 type ChanDir int 11 12 const ( 13 RecvDir ChanDir = 1 << iota // <-chan 14 SendDir // chan<- 15 BothDir = RecvDir | SendDir // chan 16 ) 17 18 type errorString struct { 19 s string 20 } 21 22 func (e *errorString) Error() string { 23 return e.s 24 } 25 26 var ErrSyntax = &errorString{"invalid syntax"} 27 28 func unquote(s string) (string, error) { 29 if len(s) < 2 { 30 return s, nil 31 } 32 if s[0] == '\'' || s[0] == '"' { 33 if s[len(s)-1] == s[0] { 34 return s[1 : len(s)-1], nil 35 } 36 return "", ErrSyntax 37 } 38 return s, nil 39 } 40 41 // Method represents a single method. 42 type Method struct { 43 // Name is the method name. 44 // PkgPath is the package path that qualifies a lower case (unexported) 45 // method name. It is empty for upper case (exported) method names. 46 // The combination of PkgPath and Name uniquely identifies a method 47 // in a method set. 48 // See https://golang.org/ref/spec#Uniqueness_of_identifiers 49 Name string 50 PkgPath string 51 52 Type Type // method type 53 Func Value // func with receiver as first argument 54 Index int // index for Type.Method 55 } 56 57 // A SelectDir describes the communication direction of a select case. 58 type SelectDir int 59 60 // NOTE: These values must match ../runtime/select.go:/selectDir. 61 62 const ( 63 _ SelectDir = iota 64 SelectSend // case Chan <- Send 65 SelectRecv // case <-Chan: 66 SelectDefault // default 67 ) 68 69 // A runtimeSelect is a single case passed to rselect. 70 // This must match ../runtime/select.go:/runtimeSelect 71 type runtimeSelect struct { 72 dir SelectDir // SelectSend, SelectRecv or SelectDefault 73 typ *rtype // channel type 74 ch unsafe.Pointer // channel 75 val unsafe.Pointer // ptr to data (SendDir) or ptr to receive buffer (RecvDir) 76 } 77 78 func (f flag) mustBe(expected Kind) { 79 // TODO(mvdan): use f.kind() again once mid-stack inlining gets better 80 if Kind(f&flagKindMask) != expected { 81 panic(&ValueError{methodName(), f.kind()}) 82 } 83 } 84 85 // A StructTag is the tag string in a struct field. 86 // 87 // By convention, tag strings are a concatenation of 88 // optionally space-separated key:"value" pairs. 89 // Each key is a non-empty string consisting of non-control 90 // characters other than space (U+0020 ' '), quote (U+0022 '"'), 91 // and colon (U+003A ':'). Each value is quoted using U+0022 '"' 92 // characters and Go string literal syntax. 93 type StructTag string 94 95 func typesMustMatch(what string, t1, t2 Type) { 96 if t1 != t2 { 97 panic(what + ": " + t1.String() + " != " + t2.String()) 98 } 99 }