OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 {% macro define(enum) %} | 5 {% import "mojom_type_macros.tmpl" as mojom_type_macros %} |
6 {% import "mojom_util_macros.tmpl" as util %} | |
7 | |
8 {% macro define(enum, typepkg, package) %} | |
6 type {{enum|name}} int32 | 9 type {{enum|name}} int32 |
7 | 10 |
8 const ( | 11 const ( |
9 {% for field in enum.fields %} | 12 {% for field in enum.fields %} |
10 {% if field.value %} | 13 {% if field.value %} |
11 {{enum|name}}_{{field|name}} = {{field.value|expression_to_text}} | 14 {{enum|name}}_{{field|name}} = {{field.value|expression_to_text}} |
12 {% elif loop.first %} | 15 {% elif loop.first %} |
13 {{enum|name}}_{{field|name}} = 0 | 16 {{enum|name}}_{{field|name}} = 0 |
14 {% else %} | 17 {% else %} |
15 {{enum|name}}_{{field|name}} = {{enum|name}}_{{enum.fields[loop.index0 - 1]|name}} + 1; | 18 {{enum|name}}_{{field|name}} = {{enum|name}}_{{enum.fields[loop.index0 - 1]|name}} + 1; |
16 {% endif %} | 19 {% endif %} |
17 {% endfor %} | 20 {% endfor %} |
18 ) | 21 ) |
19 | 22 |
23 // String names and labels used by the MojomEnum types. | |
24 var ( | |
azani
2015/10/12 21:13:07
Could you create a new jinja file and put all thos
alexfandrianto
2015/10/16 21:25:49
I combined them into a macro (writeMojomTypeDef) i
| |
25 enumName_{{enum|name}} = "{{enum|name}}" | |
26 {% for field in enum.fields %} | |
27 enumFieldName_{{enum|name}}_{{field|name}} = "{{field|name}}" | |
28 {% endfor %} | |
29 ) | |
30 | |
31 func {{util.typeName(enum, typepkg, package)}}() {{typepkg}}MojomEnum { | |
32 return {{ mojom_type_macros.writeMojomType(typepkg, enum, package, exported) } } | |
33 } | |
34 | |
20 {% endmacro %} | 35 {% endmacro %} |
OLD | NEW |