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

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(nonNullableFieldDecodingTmplText))
39 template.Must(goFileTmpl.Parse(fieldDecodingTmplText)) 40 template.Must(goFileTmpl.Parse(fieldDecodingTmplText))
40 41
41 template.Must(goFileTmpl.Parse(nonNullableFieldEncodingTmplText)) 42 template.Must(goFileTmpl.Parse(nonNullableFieldEncodingTmplText))
42 template.Must(goFileTmpl.Parse(fieldEncodingTmplText)) 43 template.Must(goFileTmpl.Parse(fieldEncodingTmplText))
43 template.Must(goFileTmpl.Parse(structEncodingTmplText)) 44 template.Must(goFileTmpl.Parse(structEncodingTmplText))
44 template.Must(goFileTmpl.Parse(structDeclTmplText)) 45 template.Must(goFileTmpl.Parse(structDeclTmplText))
45 template.Must(goFileTmpl.Parse(structVersions)) 46 template.Must(goFileTmpl.Parse(structVersions))
46 template.Must(goFileTmpl.Parse(structDecodingTmplText)) 47 template.Must(goFileTmpl.Parse(structDecodingTmplText))
48
49 template.Must(goFileTmpl.Parse(unionDeclTmplText))
50 template.Must(goFileTmpl.Parse(unionInterfaceDeclTmplText))
51 template.Must(goFileTmpl.Parse(unionFieldDeclTmplText))
52 template.Must(goFileTmpl.Parse(unknownUnionFieldDeclTmplText))
47 } 53 }
48 54
49 const goFileTemplate = ` 55 const goFileTemplate = `
50 {{- define "FileTemplate" -}} 56 {{- define "FileTemplate" -}}
51 {{- $fileTmpl := . -}} 57 {{- $fileTmpl := . -}}
52 package {{$fileTmpl.PackageName}} 58 package {{$fileTmpl.PackageName}}
53 59
54 import ( 60 import (
55 {{range $import := $fileTmpl.Imports}} 61 {{range $import := $fileTmpl.Imports}}
56 {{$import.PackageName}} "{{$import.PackagePath}}" 62 {{$import.PackageName}} "{{$import.PackagePath}}"
57 {{end}} 63 {{end}}
58 ) 64 )
59 65
60 {{- range $struct := $fileTmpl.Structs}} 66 {{- range $struct := $fileTmpl.Structs}}
61 {{ template "StructDecl" $struct }} 67 {{ template "StructDecl" $struct }}
62 68
63 {{ template "StructEncodingTmpl" $struct }} 69 {{ template "StructEncodingTmpl" $struct }}
64 70
65 {{ template "StructVersions" $struct }} 71 {{ template "StructVersions" $struct }}
66 72
67 {{ template "StructDecodingTmpl" $struct }} 73 {{ template "StructDecodingTmpl" $struct }}
68 {{- end}} 74 {{- end}}
75
76 {{- range $union := $fileTmpl.Imports}}
vardhan 2016/06/08 20:45:47 hm.. did you mean $fileTmpl.Unions? and below thi
azani 2016/06/08 23:51:48 Done.
77 {{ template "UnionDecl" $struct }}
78 {{- end}}
69 {{- end -}} 79 {{- end -}}
70 ` 80 `
OLDNEW
« no previous file with comments | « mojom/generators/go/templates/declarations_test.go ('k') | mojom/generators/go/translator/mojom_file.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698