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

Side by Side Diff: mojo/public/bindings/generators/mojom_data.py

Issue 99623010: Add support for enums within structs and interfaces to mojom. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 mojom 5 import mojom
6 6
7 # mojom_data provides a mechanism to turn mojom Modules to dictionaries and 7 # mojom_data provides a mechanism to turn mojom Modules to dictionaries and
8 # back again. This can be used to persist a mojom Module created progromatically 8 # back again. This can be used to persist a mojom Module created progromatically
9 # or to read a dictionary from code or a file. 9 # or to read a dictionary from code or a file.
10 # Example: 10 # Example:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 istr(0, 'name'): struct.name, 59 istr(0, 'name'): struct.name,
60 istr(1, 'fields'): map(FieldToData, struct.fields) 60 istr(1, 'fields'): map(FieldToData, struct.fields)
61 } 61 }
62 62
63 def StructFromData(kinds, data): 63 def StructFromData(kinds, data):
64 struct = mojom.Struct() 64 struct = mojom.Struct()
65 struct.name = data['name'] 65 struct.name = data['name']
66 struct.spec = 'x:' + struct.name 66 struct.spec = 'x:' + struct.name
67 kinds[struct.spec] = struct 67 kinds[struct.spec] = struct
68 struct.fields = map(lambda field: FieldFromData(kinds, field), data['fields']) 68 struct.fields = map(lambda field: FieldFromData(kinds, field), data['fields'])
69 struct.enums = map(lambda enum: EnumFromData(kinds, enum), data['enums'])
69 return struct 70 return struct
70 71
71 def FieldToData(field): 72 def FieldToData(field):
72 data = { 73 data = {
73 istr(0, 'name'): field.name, 74 istr(0, 'name'): field.name,
74 istr(1, 'kind'): KindToData(field.kind) 75 istr(1, 'kind'): KindToData(field.kind)
75 } 76 }
76 if field.ordinal != None: 77 if field.ordinal != None:
77 data[istr(2, 'ordinal')] = field.ordinal 78 data[istr(2, 'ordinal')] = field.ordinal
78 if field.default != None: 79 if field.default != None:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 istr(1, 'peer'): interface.peer, 131 istr(1, 'peer'): interface.peer,
131 istr(2, 'methods'): map(MethodToData, interface.methods) 132 istr(2, 'methods'): map(MethodToData, interface.methods)
132 } 133 }
133 134
134 def InterfaceFromData(kinds, data): 135 def InterfaceFromData(kinds, data):
135 interface = mojom.Interface() 136 interface = mojom.Interface()
136 interface.name = data['name'] 137 interface.name = data['name']
137 interface.peer = data['peer'] 138 interface.peer = data['peer']
138 interface.methods = map( 139 interface.methods = map(
139 lambda method: MethodFromData(kinds, method), data['methods']) 140 lambda method: MethodFromData(kinds, method), data['methods'])
141 interface.enums = map(lambda enum: EnumFromData(kinds, enum), data['enums'])
140 return interface 142 return interface
141 143
142 def EnumFieldFromData(kinds, data): 144 def EnumFieldFromData(kinds, data):
143 field = mojom.EnumField() 145 field = mojom.EnumField()
144 field.name = data['name'] 146 field.name = data['name']
145 field.value = data['value'] 147 field.value = data['value']
146 return field 148 return field
147 149
148 def EnumFromData(kinds, data): 150 def EnumFromData(kinds, data):
149 enum = mojom.Enum() 151 enum = mojom.Enum()
(...skipping 29 matching lines...) Expand all
179 def OrderedModuleFromData(data): 181 def OrderedModuleFromData(data):
180 module = ModuleFromData(data) 182 module = ModuleFromData(data)
181 next_interface_ordinal = 0 183 next_interface_ordinal = 0
182 for interface in module.interfaces: 184 for interface in module.interfaces:
183 next_ordinal = 0 185 next_ordinal = 0
184 for method in interface.methods: 186 for method in interface.methods:
185 if method.ordinal is None: 187 if method.ordinal is None:
186 method.ordinal = next_ordinal 188 method.ordinal = next_ordinal
187 next_ordinal = method.ordinal + 1 189 next_ordinal = method.ordinal + 1
188 return module 190 return module
OLDNEW
« no previous file with comments | « mojo/public/bindings/generators/js_templates/struct_definition.tmpl ('k') | mojo/public/bindings/parse/mojo_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698