OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 {%- macro writeMojomTypeDef(type, typepkg, pkg) -%} | |
6 {%- if should_gen_mojom_types -%} | |
7 {%- if type|is_enum_kind -%} | |
8 {{typepkg}}MojomEnum {{type|mojom_type_identifier}}() { | |
9 return {{ writeMojomType(type, typepkg, pkg) }}; | |
10 } | |
11 {%- elif type|is_struct_kind -%} | |
12 {{typepkg}}MojomStruct {{type|mojom_type_identifier}}() { | |
13 return {{ writeMojomType(type, typepkg, pkg) }}; | |
14 } | |
15 {%- elif type|is_union_kind -%} | |
16 {{typepkg}}MojomUnion {{type|mojom_type_identifier}}() { | |
17 return {{ writeMojomType(type, typepkg, pkg) }}; | |
18 } | |
19 {%- elif type|is_interface_kind -%} | |
20 {{typepkg}}MojomInterface {{type|mojom_type_identifier}}() { | |
21 return new {{typepkg}}MojomInterface() | |
22 ..declData = (new {{typepkg}}DeclarationData() | |
23 ..shortName = '{{type|name}}' | |
24 ..fullIdentifier = '{{type|fullidentifier}}') | |
25 ..interfaceName = '{{type|name}}' | |
26 ..methods = <int, {{typepkg}}MojomMethod>{ | |
27 {% for method in type.methods -%} | |
28 _{{type|name}}_{{method|name}}Name: new {{typepkg}}MojomMethod() | |
29 ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{method|na me|upper_camel}}') | |
zra
2016/01/15 21:01:34
Usually we don't have much control over line lengt
zra
2016/01/15 23:33:17
So, method|name can do arbitrary things to make me
alexfandrianto
2016/01/15 23:49:00
While Mojo does do method matching based on index,
alexfandrianto
2016/01/20 00:08:29
Done.
| |
30 ..ordinal = _{{type|name}}_{{method|name}}Name | |
31 {%- if method.response_parameters != None %} | |
32 ..responseParams = {{method.response_param_struct|mojom_type_identifier} }() | |
33 {%- endif -%} | |
34 ..parameters = {{method.param_struct|mojom_type_identifier}}(), | |
35 {%- endfor %} | |
36 }; | |
37 } | |
38 | |
39 {%- else -%} | |
40 {{ raise("Bad type name given") }} | |
zra
2016/01/15 21:01:34
Maybe append the name that was bad here.
alexfandrianto
2016/01/20 00:08:29
Done.
| |
41 {%- endif -%} | |
42 {%- endif -%} | |
43 {%- endmacro -%} | |
44 | |
45 | |
46 {%- macro writeMojomType(type, typepkg, pkg, topLevel=true) -%} | |
47 {%- if type|mojom_type_value(typepkg) != "" -%}{#- simple kind case -#} | |
48 {{type|mojom_type_value(typepkg)}} | |
49 {%- elif type|is_array_kind -%} | |
50 {{writeTypeArrayType(type, typepkg, pkg)}} | |
51 {%- elif type|is_map_kind -%} | |
52 {{writeTypeMapType(type, typepkg, pkg)}} | |
53 {%- elif type|is_enum_kind or type|is_struct_kind or type|is_union_kind -%} | |
54 {%- if topLevel -%} | |
55 {%- if type|is_enum_kind -%} | |
56 {{writeMojomEnumType(type, typepkg, pkg)}} | |
57 {%- elif type|is_struct_kind -%} | |
58 {{writeMojomStructType(type, typepkg, pkg)}} | |
59 {%- else -%} {#- Must be a union -#} | |
60 {{writeMojomUnionType(type, typepkg, pkg)}} | |
61 {%- endif -%} | |
62 {%- else -%} | |
63 {{writeTypeTypeReference(type, typepkg, pkg)}} | |
64 {%- endif -%} | |
65 {%- elif type|is_interface_kind or type|is_interface_request_kind -%} | |
66 {{writeTypeTypeReference(type, typepkg, pkg)}} | |
67 {%- else -%} | |
68 {{ raise("Unsupported type") }} | |
zra
2016/01/15 21:01:34
Maybe append the type here.
alexfandrianto
2016/01/20 00:08:29
Done.
| |
69 {%- endif -%} | |
70 {%- endmacro -%} | |
71 | |
72 | |
73 {%- macro writeTypeArrayType(type, typepkg, pkg) -%} | |
74 new {{typepkg}}Type()..arrayType = (new {{typepkg}}ArrayType() | |
75 {%- if type|is_nullable_kind %} | |
76 ..nullable = true | |
77 {% endif -%} | |
78 {%- if type.length is not none -%} | |
79 ..fixedLength = {{type.length}} | |
80 {%- endif %} | |
81 ..elementType = ({{writeMojomType(type.kind, typepkg, pkg, false)}})) | |
82 {%- endmacro -%} | |
83 | |
84 {%- macro writeTypeMapType(type, typepkg, pkg) -%} | |
85 new {{typepkg}}Type()..mapType = (new {{typepkg}}MapType() | |
86 {%- if type|is_nullable_kind %} | |
87 ..nullable = true | |
88 {% endif %} | |
89 ..keyType = ({{writeMojomType(type.key_kind, typepkg, pkg, false)}}) | |
90 ..valueType = ({{writeMojomType(type.value_kind, typepkg, pkg, false)}})) | |
91 {%- endmacro -%} | |
92 | |
93 {%- macro writeMojomEnumType(type, typepkg, pkg) -%} | |
94 new {{typepkg}}MojomEnum() | |
95 ..declData = (new {{typepkg}}DeclarationData() | |
96 ..shortName = '{{type|name}}' | |
97 ..fullIdentifier = '{{type|fullidentifier}}') | |
98 ..values = <{{typepkg}}EnumValue>[ | |
99 {%- for field in type.fields -%} | |
100 new {{typepkg}}EnumValue() | |
101 ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{field|nam e|upper_camel}}') | |
zra
2016/01/15 21:01:34
ditto re upper_camel.
| |
102 ..enumTypeKey = {{writePackagedTypeID(type)}} | |
103 ..intValue = {{field.numeric_value}}, | |
104 {%- endfor -%} | |
105 ] | |
106 {%- endmacro -%} | |
107 | |
108 | |
109 {%- macro writeTypeTypeReference(type, typepkg, pkg) -%} | |
110 new {{typepkg}}Type() | |
111 ..typeReference = ({{writeTypeReference(type, typepkg, pkg)}}) | |
112 {%- endmacro -%} | |
113 | |
114 {%- macro writeTypeReference(type, typepkg, pkg) -%} | |
115 new {{typepkg}}TypeReference() | |
116 {%- if type|is_nullable_kind %} | |
117 ..nullable = true | |
118 {% endif %} | |
119 {% if type|is_interface_request_kind %}{# Interface request collapses to inter face. #} | |
120 ..isInterfaceRequest = true | |
121 ..identifier = {{writePackagedTypeID(type.kind)}} | |
122 ..typeKey = {{writePackagedTypeID(type.kind)}} | |
123 {% else %} | |
124 ..identifier = {{writePackagedTypeID(type)}} | |
125 ..typeKey = {{writePackagedTypeID(type)}} | |
126 {% endif -%} | |
127 {%- endmacro -%} | |
128 | |
129 {%- macro writePackagedTypeID(type) -%} | |
130 '{{type|mojom_type_identifier}}' | |
131 {%- endmacro -%} | |
132 | |
133 {%- macro writeMojomStructType(type, typepkg, pkg) -%} | |
134 new {{typepkg}}MojomStruct() | |
135 ..declData = (new {{typepkg}}DeclarationData() | |
136 ..shortName = '{{type|name}}' | |
137 ..fullIdentifier = '{{type|fullidentifier}}') | |
138 {%- if type|is_nullable_kind %} | |
139 ..nullable = true | |
140 {% endif %} | |
141 ..fields = <{{typepkg}}StructField>[ | |
142 {%- for field in type.fields %} | |
143 new {{typepkg}}StructField() | |
144 ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{field|nam e|upper_camel}}') | |
zra
2016/01/15 21:01:34
ditto
| |
145 ..type = ({{writeMojomType(field.kind, typepkg, pkg, false)}}), | |
146 {% endfor -%} | |
147 ] | |
148 {%- endmacro -%} | |
149 | |
150 {%- macro writeMojomUnionType(type, typepkg, pkg) -%} | |
151 new {{typepkg}}MojomUnion() | |
152 ..declData = (new {{typepkg}}DeclarationData() | |
153 ..shortName = '{{type|name}}' | |
154 ..fullIdentifier = '{{type|fullidentifier}}') | |
155 {%- if type|is_nullable_kind %} | |
156 ..nullable = true | |
157 {% endif %} | |
158 ..fields = <{{typepkg}}UnionField>[ | |
159 {%- for field in type.fields %} | |
160 new {{typepkg}}UnionField() | |
161 ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{field|nam e|upper_camel}}') | |
zra
2016/01/15 21:01:34
ditto
| |
162 ..type = ({{writeMojomType(field.kind, typepkg, pkg, false)}}) | |
163 ..tag = {{field.ordinal}}, | |
164 {% endfor -%} | |
165 ] | |
166 {%- endmacro -%} | |
OLD | NEW |