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

Side by Side Diff: mojom/generators/go/templates/templates.go

Issue 2045063002: [New go generator] Implement declaring unions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package templates 5 package templates
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "text/template" 9 "text/template"
10 10
(...skipping 16 matching lines...) Expand all
27 27
28 if err != nil { 28 if err != nil {
29 panic(err) 29 panic(err)
30 } 30 }
31 return src 31 return src
32 } 32 }
33 33
34 func init() { 34 func init() {
35 // We parse the subtemplates only once. 35 // We parse the subtemplates only once.
36 goFileTmpl = template.New("GoFileTemplate") 36 goFileTmpl = template.New("GoFileTemplate")
37
37 template.Must(goFileTmpl.Parse(goFileTemplate)) 38 template.Must(goFileTmpl.Parse(goFileTemplate))
38 template.Must(goFileTmpl.Parse(nonNullableFieldDecodingTmplText))
39 template.Must(goFileTmpl.Parse(fieldDecodingTmplText))
40 39
41 » template.Must(goFileTmpl.Parse(nonNullableFieldEncodingTmplText)) 40 » initEncodingTemplates()
42 » template.Must(goFileTmpl.Parse(fieldEncodingTmplText)) 41 » initDecodingTemplates()
43 » template.Must(goFileTmpl.Parse(structEncodingTmplText)) 42 » initStructTemplates()
44 » template.Must(goFileTmpl.Parse(structDeclTmplText)) 43 » initUnionTemplates()
45 » template.Must(goFileTmpl.Parse(structVersions))
46 » template.Must(goFileTmpl.Parse(structDecodingTmplText))
47 } 44 }
48 45
49 const goFileTemplate = ` 46 const goFileTemplate = `
50 {{- define "FileTemplate" -}} 47 {{- define "FileTemplate" -}}
51 {{- $fileTmpl := . -}} 48 {{- $fileTmpl := . -}}
52 package {{$fileTmpl.PackageName}} 49 package {{$fileTmpl.PackageName}}
53 50
54 import ( 51 import (
55 {{range $import := $fileTmpl.Imports}} 52 {{range $import := $fileTmpl.Imports}}
56 {{$import.PackageName}} "{{$import.PackagePath}}" 53 {{$import.PackageName}} "{{$import.PackagePath}}"
57 {{end}} 54 {{end}}
58 ) 55 )
59 56
60 {{- range $struct := $fileTmpl.Structs}} 57 {{- range $struct := $fileTmpl.Structs}}
61 » {{ template "StructDecl" $struct }} 58 » {{ template "Struct" $struct }}
59 {{- end}}
62 60
63 » {{ template "StructEncodingTmpl" $struct }} 61 {{- range $union := $fileTmpl.Unions}}
64 62 » {{ template "Union" $union }}
65 » {{ template "StructVersions" $struct }}
66
67 » {{ template "StructDecodingTmpl" $struct }}
68 {{- end}} 63 {{- end}}
69 {{- end -}} 64 {{- end -}}
70 ` 65 `
OLDNEW
« no previous file with comments | « mojom/generators/go/templates/structs_test.go ('k') | mojom/generators/go/templates/test_utils.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698