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 type|is_enum_kind -%} | |
7 {{typepkg}}MojomEnum _{{type|mojom_type_identifier|lower_camel}}() { | |
8 return {{ writeMojomType(type, typepkg, pkg) }}; | |
9 } | |
10 {%- elif type|is_struct_kind -%} | |
11 {{typepkg}}MojomStruct _{{type|mojom_type_identifier|lower_camel}}() { | |
12 return {{ writeMojomType(type, typepkg, pkg) }}; | |
13 } | |
14 {%- elif type|is_union_kind -%} | |
15 {{typepkg}}MojomUnion _{{type|mojom_type_identifier|lower_camel}}() { | |
16 return {{ writeMojomType(type, typepkg, pkg) }}; | |
17 } | |
18 {%- elif type|is_interface_kind -%} | |
19 {{typepkg}}MojomInterface _{{type|mojom_type_identifier|lower_camel}}() { | |
20 return new {{typepkg}}MojomInterface() | |
21 ..declData = (new {{typepkg}}DeclarationData() | |
22 ..shortName = '{{type|mojom_type_name|upper_camel}}' | |
23 ..fullIdentifier = '{{type|fullidentifier}}') | |
24 ..serviceName_ = '{{type|name}}' | |
25 ..methods = <int, {{typepkg}}MojomMethod>{ | |
26 {%- for method in type.methods %} | |
27 _{{type|name}}_{{method|name}}Name: new {{typepkg}}MojomMethod() | |
28 ..declData = (new {{typepkg}}DeclarationData() | |
29 ..shortName = '{{method|mojom_type_name|upper_camel}}') | |
30 ..ordinal = _{{type|name}}_{{method|name}}Name | |
31 {%- if method.response_parameters != None %} | |
32 ..responseParams = _{{method.response_param_struct|mojom_type_identifier
|lower_camel}}() | |
33 {%- endif %} | |
34 ..parameters = _{{method.param_struct|mojom_type_identifier|lower_camel}
}(), | |
35 {%- endfor %} | |
36 }; | |
37 } | |
38 {%- else -%} | |
39 {{ raise("Bad type name given: {{type|name}}") }} | |
40 {%- endif -%} | |
41 {%- endmacro -%} | |
42 | |
43 | |
44 {%- macro writeMojomType(type, typepkg, pkg, topLevel=true) -%} | |
45 {%- if type|is_numerical_kind -%}{#- bool, int, and uint case -#} | |
46 new {{typepkg}}Type() | |
47 ..simpleType = {{typepkg}}SimpleType.{{type|simple_mojom_type_name}} | |
48 {%- elif type|is_any_handle_kind and not type|is_interface_request_kind -%} | |
49 new {{typepkg}}Type() | |
50 ..handleType = (new {{typepkg}}HandleType() | |
51 ..kind = {{typepkg}}HandleTypeKind.{{type|simple_mojom_type_name}} | |
52 {%- if type|is_nullable_kind %} | |
53 ..nullable = true | |
54 {% endif %}) | |
55 {%- elif type|is_string_kind -%} | |
56 new {{typepkg}}Type() | |
57 ..stringType = (new {{typepkg}}StringType() | |
58 {%- if type|is_nullable_kind %} | |
59 ..nullable = true | |
60 {% endif %}) | |
61 {%- elif type|is_array_kind -%} | |
62 {{writeTypeArrayType(type, typepkg, pkg)}} | |
63 {%- elif type|is_map_kind -%} | |
64 {{writeTypeMapType(type, typepkg, pkg)}} | |
65 {%- elif type|is_enum_kind or type|is_struct_kind or type|is_union_kind -%} | |
66 {%- if topLevel -%} | |
67 {%- if type|is_enum_kind -%} | |
68 {{writeMojomEnumType(type, typepkg, pkg)}} | |
69 {%- elif type|is_struct_kind -%} | |
70 {{writeMojomStructType(type, typepkg, pkg)}} | |
71 {%- else -%} {#- Must be a union -#} | |
72 {{writeMojomUnionType(type, typepkg, pkg)}} | |
73 {%- endif -%} | |
74 {%- else -%} | |
75 {{writeTypeTypeReference(type, typepkg, pkg)}} | |
76 {%- endif -%} | |
77 {%- elif type|is_interface_kind or type|is_interface_request_kind -%} | |
78 {{writeTypeTypeReference(type, typepkg, pkg)}} | |
79 {%- else -%} | |
80 {{ raise("Unsupported type: {{type|name}}") }} | |
81 {%- endif -%} | |
82 {%- endmacro -%} | |
83 | |
84 {%- macro writeTypeArrayType(type, typepkg, pkg) -%} | |
85 new {{typepkg}}Type() | |
86 ..arrayType = (new {{typepkg}}ArrayType() | |
87 {%- if type|is_nullable_kind %} | |
88 ..nullable = true | |
89 {%- endif %} | |
90 {%- if type.length is not none %} | |
91 ..fixedLength = {{type.length}} | |
92 {%- endif %} | |
93 ..elementType = ({{writeMojomType(type.kind, typepkg, pkg, false)|indent(1
0)}})) | |
94 {%- endmacro -%} | |
95 | |
96 {%- macro writeTypeMapType(type, typepkg, pkg) -%} | |
97 new {{typepkg}}Type() | |
98 ..mapType = (new {{typepkg}}MapType() | |
99 {%- if type|is_nullable_kind %} | |
100 ..nullable = true | |
101 {% endif %} | |
102 ..keyType = ({{writeMojomType(type.key_kind, typepkg, pkg, false)|indent(1
0)}}) | |
103 ..valueType = ({{writeMojomType(type.value_kind, typepkg, pkg, false)|inde
nt(10)}})) | |
104 {%- endmacro -%} | |
105 | |
106 {%- macro writeMojomEnumType(type, typepkg, pkg) -%} | |
107 new {{typepkg}}MojomEnum() | |
108 ..declData = (new {{typepkg}}DeclarationData() | |
109 ..shortName = '{{type|mojom_type_name|upper_camel}}' | |
110 ..fullIdentifier = '{{type|fullidentifier}}') | |
111 ..values = <{{typepkg}}EnumValue>[ | |
112 {%- for field in type.fields %} | |
113 new {{typepkg}}EnumValue() | |
114 ..declData = (new {{typepkg}}DeclarationData() | |
115 ..shortName = '{{field|mojom_type_name|upper_camel}}') | |
116 ..enumTypeKey = {{writePackagedTypeID(type)}} | |
117 ..intValue = {{field.numeric_value}}, | |
118 {%- endfor -%} | |
119 ] | |
120 {%- endmacro -%} | |
121 | |
122 | |
123 {%- macro writeTypeTypeReference(type, typepkg, pkg) -%} | |
124 new {{typepkg}}Type() | |
125 ..typeReference = ({{writeTypeReference(type, typepkg, pkg)}}) | |
126 {%- endmacro -%} | |
127 | |
128 {%- macro writeTypeReference(type, typepkg, pkg) -%} | |
129 new {{typepkg}}TypeReference() | |
130 {%- if type|is_nullable_kind %} | |
131 ..nullable = true | |
132 {% endif %} | |
133 {%- if type|is_interface_request_kind %}{# Interface request collapses to inte
rface. #} | |
134 ..isInterfaceRequest = true | |
135 ..identifier = {{writePackagedTypeID(type.kind)}} | |
136 ..typeKey = {{writePackagedTypeID(type.kind)}} | |
137 {% else %} | |
138 ..identifier = {{writePackagedTypeID(type)}} | |
139 ..typeKey = {{writePackagedTypeID(type)}} | |
140 {% endif -%} | |
141 {%- endmacro -%} | |
142 | |
143 {%- macro writePackagedTypeID(type) -%} | |
144 '{{type|mojom_type_identifier}}' | |
145 {%- endmacro -%} | |
146 | |
147 {%- macro writeMojomStructType(type, typepkg, pkg) -%} | |
148 new {{typepkg}}MojomStruct() | |
149 ..declData = (new {{typepkg}}DeclarationData() | |
150 ..shortName = '{{type|mojom_type_name|upper_camel}}' | |
151 ..fullIdentifier = '{{type|fullidentifier}}') | |
152 {%- if type|is_nullable_kind %} | |
153 ..nullable = true | |
154 {% endif %} | |
155 ..fields = <{{typepkg}}StructField>[ | |
156 {%- for field in type.fields %} | |
157 new {{typepkg}}StructField() | |
158 ..declData = (new {{typepkg}}DeclarationData() | |
159 ..shortName = '{{field|mojom_type_name|upper_camel}}') | |
160 ..type = ({{writeMojomType(field.kind, typepkg, pkg, false)|indent(6)}})
, | |
161 {%- endfor -%} | |
162 ] | |
163 {%- endmacro -%} | |
164 | |
165 {%- macro writeMojomUnionType(type, typepkg, pkg) -%} | |
166 new {{typepkg}}MojomUnion() | |
167 ..declData = (new {{typepkg}}DeclarationData() | |
168 ..shortName = '{{type|mojom_type_name|upper_camel}}' | |
169 ..fullIdentifier = '{{type|fullidentifier}}') | |
170 {%- if type|is_nullable_kind %} | |
171 ..nullable = true | |
172 {% endif %} | |
173 ..fields = <{{typepkg}}UnionField>[ | |
174 {%- for field in type.fields %} | |
175 new {{typepkg}}UnionField() | |
176 ..declData = (new {{typepkg}}DeclarationData() | |
177 ..shortName = '{{field|name|upper_camel}}') | |
178 ..type = ({{writeMojomType(field.kind, typepkg, pkg, false)|indent(6)}}) | |
179 ..tag = {{field.ordinal}}, | |
180 {%- endfor -%} | |
181 ] | |
182 {%- endmacro -%} | |
OLD | NEW |