Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: third_party/go/src/golang.org/x/mobile/bind/seq.go

Issue 1275153002: Remove third_party/golang.org/x/mobile as it is no longer used with Go 1.5. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Remove golang.org/x/mobile Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 package bind
2
3 import (
4 "fmt"
5
6 "golang.org/x/tools/go/types"
7 )
8
9 // seqType returns a string that can be used for reading and writing a
10 // type using the seq library.
11 // TODO(hyangah): avoid panic; gobind needs to output the problematic code locat ion.
12 func seqType(t types.Type) string {
13 if isErrorType(t) {
14 return "UTF16"
15 }
16 switch t := t.(type) {
17 case *types.Basic:
18 switch t.Kind() {
19 case types.Int:
20 return "Int"
21 case types.Int8:
22 return "Int8"
23 case types.Int16:
24 return "Int16"
25 case types.Int32:
26 return "Int32"
27 case types.Int64:
28 return "Int64"
29 case types.Uint8: // Byte.
30 // TODO(crawshaw): questionable, but vital?
31 return "Byte"
32 // TODO(crawshaw): case types.Uint, types.Uint16, types.Uint32, types.Uint64:
33 case types.Float32:
34 return "Float32"
35 case types.Float64:
36 return "Float64"
37 case types.String:
38 return "UTF16"
39 default:
40 // Should be caught earlier in processing.
41 panic(fmt.Sprintf("unsupported basic seqType: %s", t))
42 }
43 case *types.Named:
44 switch u := t.Underlying().(type) {
45 case *types.Interface:
46 return "Ref"
47 default:
48 panic(fmt.Sprintf("unsupported named seqType: %s / %T", u, u))
49 }
50 case *types.Slice:
51 switch e := t.Elem().(type) {
52 case *types.Basic:
53 switch e.Kind() {
54 case types.Uint8: // Byte.
55 return "ByteArray"
56 default:
57 panic(fmt.Sprintf("unsupported seqType: %s(%s) / %T(%T)", t, e, t, e))
58 }
59 default:
60 panic(fmt.Sprintf("unsupported seqType: %s(%s) / %T(%T)" , t, e, t, e))
61 }
62 // TODO: let the types.Array case handled like types.Slice?
63 case *types.Pointer:
64 if _, ok := t.Elem().(*types.Named); ok {
65 return "Ref"
66 }
67 panic(fmt.Sprintf("not supported yet, pointer type: %s / %T", t, t))
68
69 default:
70 panic(fmt.Sprintf("unsupported seqType: %s / %T", t, t))
71 }
72 }
73
74 func seqRead(o types.Type) string {
75 t := seqType(o)
76 return t + "()"
77 }
78
79 func seqWrite(o types.Type, name string) string {
80 t := seqType(o)
81 if t == "Ref" {
82 // TODO(crawshaw): do something cleaner, i.e. genWrite.
83 return t + "(" + name + ".ref())"
84 }
85 return t + "(" + name + ")"
86 }
OLDNEW
« no previous file with comments | « third_party/go/src/golang.org/x/mobile/bind/printer.go ('k') | third_party/go/src/golang.org/x/mobile/bind/seq/buffer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698