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

Side by Side Diff: mojo/public/tools/bindings/generators/go_templates/enum.tmpl

Issue 1943643002: Go bindings: Change generated enum value constants to be typed as the enum type. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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 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 {% import "runtime_type_macros.tmpl" as runtime_type_macros %} 5 {% import "runtime_type_macros.tmpl" as runtime_type_macros %}
6 6
7 {% macro define(enum, typepkg, package) %} 7 {% macro define(enum, typepkg, package) %}
8 type {{enum|name}} int32 8 type {{enum|name}} int32
9 9
10 const ( 10 const (
11 {% for field in enum.fields %} 11 {% for field in enum.fields %}
12 {% if field.value %} 12 {% if loop.first %}
13 {% if field.value %}
14 » {{enum|name}}_{{field|name}} {{enum|name}} = {{field.value|expression_to _text}}
15 {% else %}
16 » {{enum|name}}_{{field|name}} {{enum|name}} = 0
17 {% endif %}
18 {% elif field.value %}
13 {{enum|name}}_{{field|name}} = {{field.value|expression_to_text}} 19 {{enum|name}}_{{field|name}} = {{field.value|expression_to_text}}
14 {% elif loop.first %}
15 {{enum|name}}_{{field|name}} = 0
16 {% else %} 20 {% else %}
17 {{enum|name}}_{{field|name}} = {{enum|name}}_{{enum.fields[loop.index0 - 1]|name}} + 1; 21 {{enum|name}}_{{field|name}} = {{enum|name}}_{{enum.fields[loop.index0 - 1]|name}} + 1;
18 {% endif %} 22 {% endif%}
19 {% endfor %} 23 {% endfor %}
20 ) 24 )
21 25
22 {%- set type_name = enum|name(exported) %} 26 {%- set type_name = enum|name(exported) %}
23 {{runtime_type_macros.maybeWriteStaticMojomTypeAccessor(typepkg, enum)}} 27 {{runtime_type_macros.maybeWriteStaticMojomTypeAccessor(typepkg, enum)}}
24 {{runtime_type_macros.maybeWriteMojomTypeAccessor(typepkg, enum,type_name)}} 28 {{runtime_type_macros.maybeWriteMojomTypeAccessor(typepkg, enum,type_name)}}
25 29
26 {% endmacro %} 30 {% endmacro %}
OLDNEW
« no previous file with comments | « mojo/public/interfaces/bindings/tests/test_enums.mojom ('k') | mojo/public/tools/bindings/generators/mojom_go_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698