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

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

Issue 55133009: mojom: Minor cleanup to template code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: A little more cleanup Created 7 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 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 """Generates C++ source files from a mojom.Module.""" 5 """Generates C++ source files from a mojom.Module."""
6 6
7 import datetime 7 import datetime
8 import mojom 8 import mojom
9 import mojom_pack 9 import mojom_pack
10 import os 10 import os
11 import sys 11 import sys
12 12
13 from string import Template 13 from string import Template
14 14
15 # mojom_cpp_generator provides a way to generate c++ code from a mojom.Module. 15 # mojom_cpp_generator provides a way to generate c++ code from a mojom.Module.
16 # cpp = mojom_cpp_generator.CPPGenerator(module) 16 # cpp = mojom_cpp_generator.CPPGenerator(module)
17 # cpp.GenerateFiles("/tmp/g") 17 # cpp.GenerateFiles("/tmp/g")
18 def ReadTemplate(filename): 18 def ReadTemplate(filename):
19 """Reads a string.Template from |filename|.""" 19 """Reads a string.Template from |filename|."""
20 dir = os.path.dirname(__file__) 20 dir = os.path.dirname(__file__)
21 with open(dir + '/' + filename, 'r') as file: 21 with open(dir + '/' + filename, 'r') as file:
22 return Template(file.read()) 22 return Template(file.read())
23 23
24 24
25 def AddForward(forwards, kind): 25 class Forwards(object):
26 """Adds a forward class declaration line to the |forwards| set.""" 26 """Helper class to maintain unique set of forward declarations."""
27 if isinstance(kind, mojom.Struct): 27 def __init__(self):
28 forwards.add("class %s;" % kind.name.capitalize()) 28 self.forwards = set()
29 if isinstance(kind, mojom.Array): 29
30 AddForward(forwards, kind.kind) 30 def Add(self, kind):
31 if isinstance(kind, mojom.Struct):
32 self.forwards.add("class %s;" % kind.name.capitalize())
33 if isinstance(kind, mojom.Array):
34 self.Add(kind.kind)
35
36 def __repr__(self):
37 if len(self.forwards) > 0:
38 return '\n'.join(sorted(self.forwards)) + '\n'
39 return ""
31 40
32 41
33 def GetForwards(forwards): 42 class Lines(object):
34 """Returns a string suitable for substituting into a $FORWARDS section.""" 43 """Helper class to maintain list of template expanded lines."""
35 if len(forwards) > 0: 44 def __init__(self, template):
36 return '\n'.join(sorted(forwards)) + '\n' 45 self.template = template
37 return "" 46 self.lines = []
47
48 def Add(self, map = {}, **substitutions):
49 if len(substitutions) > 0:
50 map = map.copy()
51 map.update(substitutions)
52
53 self.lines.append(self.template.substitute(map))
54
55 def __repr__(self):
56 return '\n'.join(self.lines)
38 57
39 58
40 class CPPGenerator(object): 59 class CPPGenerator(object):
41 60
42 struct_header_template = ReadTemplate("module_struct.h") 61 struct_header_template = ReadTemplate("module_struct.h")
43 struct_source_template = ReadTemplate("module_struct.cc") 62 struct_source_template = ReadTemplate("module_struct.cc")
44 struct_serialization_header_template = \ 63 struct_serialization_header_template = \
45 ReadTemplate("module_struct_serialization.h") 64 ReadTemplate("module_struct_serialization.h")
46 struct_serialization_source_template = \ 65 struct_serialization_source_template = \
47 ReadTemplate("module_struct_serialization.cc") 66 ReadTemplate("module_struct_serialization.cc")
48 struct_serialization_compute_template = \ 67 struct_serialization_compute_template = \
49 Template(" +\n mojo::internal::ComputeSizeOf($NAME->$FIELD())") 68 Template(" +\n mojo::internal::ComputeSizeOf($NAME->$FIELD())")
50 struct_serialization_clone_template = Template( 69 struct_serialization_clone_template = Template(
51 " clone->set_$FIELD(mojo::internal::Clone($NAME->$FIELD(), buf));") 70 " clone->set_$FIELD(mojo::internal::Clone($NAME->$FIELD(), buf));")
52 struct_serialization_encode_template = Template( 71 struct_serialization_encode_template = Template(
53 " Encode(&$NAME->${FIELD}_, handles);") 72 " Encode(&$NAME->${FIELD}_, handles);")
54 struct_serialization_decode_template = Template( 73 struct_serialization_decode_template = Template(
55 " if (!Decode(&$NAME->${FIELD}_, message))\n return false;") 74 " if (!Decode(&$NAME->${FIELD}_, message))\n return false;")
56 interface_header_template = ReadTemplate("module_interface.h") 75 interface_header_template = ReadTemplate("module_interface.h")
57 interface_stub_header_template = ReadTemplate("module_interface_stub.h") 76 interface_stub_header_template = ReadTemplate("module_interface_stub.h")
58 interface_stub_source_template = ReadTemplate("module_interface_stub.cc") 77 interface_stub_source_template = ReadTemplate("module_interface_stub.cc")
59 interface_stub_case_template = ReadTemplate("module_interface_stub_case") 78 interface_stub_case_template = ReadTemplate("module_interface_stub_case")
60 field_template = Template(" $itype ${field}_;") 79 field_template = Template(" $TYPE ${FIELD}_;")
61 bool_field_template = Template(" uint8_t ${field}_ : 1;") 80 bool_field_template = Template(" uint8_t ${FIELD}_ : 1;")
62 setter_template = \ 81 setter_template = \
63 Template(" void set_$field($stype $field) { ${field}_ = $field; }") 82 Template(" void set_$FIELD($TYPE $FIELD) { ${FIELD}_ = $FIELD; }")
64 getter_template = \ 83 getter_template = \
65 Template(" $gtype $field() const { return ${field}_; }") 84 Template(" $TYPE $FIELD() const { return ${FIELD}_; }")
66 ptr_getter_template = \ 85 ptr_getter_template = \
67 Template(" $gtype $field() const { return ${field}_.ptr; }") 86 Template(" $TYPE $FIELD() const { return ${FIELD}_.ptr; }")
68 pad_template = Template(" uint8_t _pad${count}_[$pad];") 87 pad_template = Template(" uint8_t _pad${COUNT}_[$PAD];")
69 HEADER_SIZE = 8 88 HEADER_SIZE = 8
70 89
71 kind_to_type = { 90 kind_to_type = {
72 mojom.BOOL: "bool", 91 mojom.BOOL: "bool",
73 mojom.INT8: "int8_t", 92 mojom.INT8: "int8_t",
74 mojom.UINT8: "uint8_t", 93 mojom.UINT8: "uint8_t",
75 mojom.INT16: "int16_t", 94 mojom.INT16: "int16_t",
76 mojom.UINT16: "uint16_t", 95 mojom.UINT16: "uint16_t",
77 mojom.INT32: "int32_t", 96 mojom.INT32: "int32_t",
78 mojom.UINT32: "uint32_t", 97 mojom.UINT32: "uint32_t",
(...skipping 26 matching lines...) Expand all
105 124
106 @classmethod 125 @classmethod
107 def GetGetterLine(cls, pf): 126 def GetGetterLine(cls, pf):
108 kind = pf.field.kind 127 kind = pf.field.kind
109 template = None 128 template = None
110 gtype = cls.GetConstType(kind) 129 gtype = cls.GetConstType(kind)
111 if isinstance(kind, (mojom.Struct, mojom.Array)) or kind.spec == 's': 130 if isinstance(kind, (mojom.Struct, mojom.Array)) or kind.spec == 's':
112 template = cls.ptr_getter_template 131 template = cls.ptr_getter_template
113 else: 132 else:
114 template = cls.getter_template 133 template = cls.getter_template
115 return template.substitute(field=pf.field.name, gtype=gtype) 134 return template.substitute(FIELD=pf.field.name, TYPE=gtype)
116 135
117 @classmethod 136 @classmethod
118 def GetSetterLine(cls, pf): 137 def GetSetterLine(cls, pf):
119 stype = cls.GetType(pf.field.kind) 138 stype = cls.GetType(pf.field.kind)
120 return cls.setter_template.substitute(field=pf.field.name, stype=stype) 139 return cls.setter_template.substitute(FIELD=pf.field.name, TYPE=stype)
121 140
122 @classmethod 141 @classmethod
123 def GetFieldLine(cls, pf): 142 def GetFieldLine(cls, pf):
124 kind = pf.field.kind 143 kind = pf.field.kind
125 if kind.spec == 'b': 144 if kind.spec == 'b':
126 return cls.bool_field_template.substitute(field=pf.field.name) 145 return cls.bool_field_template.substitute(FIELD=pf.field.name)
127 itype = None 146 itype = None
128 if isinstance(kind, mojom.Struct): 147 if isinstance(kind, mojom.Struct):
129 itype = "mojo::internal::StructPointer<%s>" % kind.name.capitalize() 148 itype = "mojo::internal::StructPointer<%s>" % kind.name.capitalize()
130 elif isinstance(kind, mojom.Array): 149 elif isinstance(kind, mojom.Array):
131 itype = "mojo::internal::StructPointer<%s>" % cls.GetType(kind.kind) 150 itype = "mojo::internal::StructPointer<%s>" % cls.GetType(kind.kind)
132 elif kind.spec == 's': 151 elif kind.spec == 's':
133 itype = "mojo::internal::StringPointer" 152 itype = "mojo::internal::StringPointer"
134 else: 153 else:
135 itype = cls.kind_to_type[kind] 154 itype = cls.kind_to_type[kind]
136 return cls.field_template.substitute(field=pf.field.name, itype=itype) 155 return cls.field_template.substitute(FIELD=pf.field.name, TYPE=itype)
137 156
138 @classmethod 157 @classmethod
139 def GetCaseLine(cls, interface, method): 158 def GetCaseLine(cls, interface, method):
140 method_call = "%s(" % method.name 159 params = map(lambda param: "params->%s()" % param.name, method.parameters)
141 first_param = True 160 method_call = "%s(%s);" % (method.name, ", ".join(params))
142 for param in method.parameters:
143 if first_param:
144 first_param = False
145 else:
146 method_call += ", "
147 method_call += "params->%s()" % param.name
148 method_call += ");"
149 return cls.interface_stub_case_template.substitute( 161 return cls.interface_stub_case_template.substitute(
150 CLASS = interface.name, 162 CLASS = interface.name,
151 METHOD = method.name, 163 METHOD = method.name,
152 METHOD_CALL = method_call); 164 METHOD_CALL = method_call);
153 165
154 @classmethod 166 @classmethod
155 def GetSerializedFields(cls, ps): 167 def GetSerializedFields(cls, ps):
156 fields = [] 168 fields = []
157 for pf in ps.packed_fields: 169 for pf in ps.packed_fields:
158 if isinstance(pf.field.kind, (mojom.Struct, mojom.Array)) or \ 170 if isinstance(pf.field.kind, (mojom.Struct, mojom.Array)) or \
(...skipping 12 matching lines...) Expand all
171 "%s_%s.h" % (self.module.name.lower(), component_string.lower())) 183 "%s_%s.h" % (self.module.name.lower(), component_string.lower()))
172 184
173 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all files 185 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all files
174 # to stdout. 186 # to stdout.
175 def __init__(self, module, header_dir, output_dir=None): 187 def __init__(self, module, header_dir, output_dir=None):
176 self.module = module 188 self.module = module
177 self.header_dir = header_dir 189 self.header_dir = header_dir
178 self.output_dir = output_dir 190 self.output_dir = output_dir
179 191
180 def WriteTemplateToFile(self, template, name, ext, **substitutions): 192 def WriteTemplateToFile(self, template, name, ext, **substitutions):
193 substitutions['YEAR'] = datetime.date.today().year
194 substitutions['NAMESPACE'] = self.module.namespace
181 if self.output_dir is None: 195 if self.output_dir is None:
182 file = sys.stdout 196 file = sys.stdout
183 else: 197 else:
184 filename = "%s_%s.%s" % \ 198 filename = "%s_%s.%s" % \
185 (self.module.name.lower(), name.lower(), ext) 199 (self.module.name.lower(), name.lower(), ext)
186 file = open(os.path.join(self.output_dir, filename), "w+") 200 file = open(os.path.join(self.output_dir, filename), "w+")
187 try: 201 try:
188 file.write(template.substitute(substitutions)) 202 file.write(template.substitute(substitutions))
189 finally: 203 finally:
190 if self.output_dir is not None: 204 if self.output_dir is not None:
191 file.close() 205 file.close()
192 206
193 def GenerateStructHeader(self, ps): 207 def GenerateStructHeader(self, ps):
194 struct = ps.struct 208 struct = ps.struct
195 fields = [] 209 fields = []
196 setters = [] 210 setters = []
197 getters = [] 211 getters = []
198 forwards = set() 212 forwards = Forwards()
199 213
200 pad_count = 0 214 pad_count = 0
201 num_fields = len(ps.packed_fields) 215 num_fields = len(ps.packed_fields)
202 for i in xrange(num_fields): 216 for i in xrange(num_fields):
203 pf = ps.packed_fields[i] 217 pf = ps.packed_fields[i]
204 fields.append(self.GetFieldLine(pf)) 218 fields.append(self.GetFieldLine(pf))
205 AddForward(forwards, pf.field.kind) 219 forwards.Add(pf.field.kind)
206 if i < (num_fields - 2): 220 if i < (num_fields - 2):
207 next_pf = ps.packed_fields[i+1] 221 next_pf = ps.packed_fields[i+1]
208 pad = next_pf.offset - (pf.offset + pf.size) 222 pad = next_pf.offset - (pf.offset + pf.size)
209 if pad > 0: 223 if pad > 0:
210 fields.append(self.pad_template.substitute(count=pad_count, pad=pad)) 224 fields.append(self.pad_template.substitute(COUNT=pad_count, PAD=pad))
211 pad_count += 1 225 pad_count += 1
212 setters.append(self.GetSetterLine(pf)) 226 setters.append(self.GetSetterLine(pf))
213 getters.append(self.GetGetterLine(pf)) 227 getters.append(self.GetGetterLine(pf))
214 228
215 if num_fields > 0: 229 if num_fields > 0:
216 last_field = ps.packed_fields[num_fields - 1] 230 last_field = ps.packed_fields[num_fields - 1]
217 offset = last_field.offset + last_field.size 231 offset = last_field.offset + last_field.size
218 pad = mojom_pack.GetPad(offset, 8) 232 pad = mojom_pack.GetPad(offset, 8)
219 if pad > 0: 233 if pad > 0:
220 fields.append(self.pad_template.substitute(count=pad_count, pad=pad)) 234 fields.append(self.pad_template.substitute(COUNT=pad_count, PAD=pad))
221 pad_count += 1 235 pad_count += 1
222 size = offset + pad 236 size = offset + pad
223 else: 237 else:
224 size = 0 238 size = 0
225 239
226 self.WriteTemplateToFile(self.struct_header_template, struct.name, 'h', 240 self.WriteTemplateToFile(self.struct_header_template, struct.name, 'h',
227 YEAR = datetime.date.today().year,
228 HEADER_GUARD = self.GetHeaderGuard(struct.name), 241 HEADER_GUARD = self.GetHeaderGuard(struct.name),
229 NAMESPACE = self.module.namespace,
230 CLASS = struct.name.capitalize(), 242 CLASS = struct.name.capitalize(),
231 SIZE = size + self.HEADER_SIZE, 243 SIZE = size + self.HEADER_SIZE,
232 FORWARDS = GetForwards(forwards), 244 FORWARDS = forwards,
233 SETTERS = '\n'.join(setters), 245 SETTERS = '\n'.join(setters),
234 GETTERS = '\n'.join(getters), 246 GETTERS = '\n'.join(getters),
235 FIELDS = '\n'.join(fields)) 247 FIELDS = '\n'.join(fields))
236 248
237 def GenerateStructSource(self, ps): 249 def GenerateStructSource(self, ps):
238 struct = ps.struct 250 struct = ps.struct
239 header = self.GetHeaderFile(struct.name) 251 header = self.GetHeaderFile(struct.name)
240 self.WriteTemplateToFile(self.struct_source_template, struct.name, 'cc', 252 self.WriteTemplateToFile(self.struct_source_template, struct.name, 'cc',
241 YEAR = datetime.date.today().year,
242 NAMESPACE = self.module.namespace,
243 CLASS = struct.name.capitalize(), 253 CLASS = struct.name.capitalize(),
244 NUM_FIELDS = len(struct.fields), 254 NUM_FIELDS = len(struct.fields),
245 HEADER = header) 255 HEADER = header)
246 256
247 def GenerateStructSerializationHeader(self, ps): 257 def GenerateStructSerializationHeader(self, ps):
248 struct = ps.struct 258 struct = ps.struct
249 header = self.GetHeaderFile(struct.name, "serialization") 259 header = self.GetHeaderFile(struct.name, "serialization")
250 self.WriteTemplateToFile( 260 self.WriteTemplateToFile(
251 self.struct_serialization_header_template, 261 self.struct_serialization_header_template,
252 struct.name + "_serialization", 262 struct.name + "_serialization",
253 'h', 263 'h',
254 YEAR = datetime.date.today().year,
255 HEADER_GUARD = self.GetHeaderGuard(struct.name + "_SERIALIZATION"), 264 HEADER_GUARD = self.GetHeaderGuard(struct.name + "_SERIALIZATION"),
256 NAMESPACE = self.module.namespace,
257 CLASS = struct.name.capitalize(), 265 CLASS = struct.name.capitalize(),
258 FULL_CLASS = "%s::%s" % \ 266 FULL_CLASS = "%s::%s" % \
259 (self.module.namespace, struct.name.capitalize()), 267 (self.module.namespace, struct.name.capitalize()),
260 HEADER = header) 268 HEADER = header)
261 269
262 def GenerateStructSerializationSource(self, ps): 270 def GenerateStructSerializationSource(self, ps):
263 struct = ps.struct 271 struct = ps.struct
264 serialization_header = self.GetHeaderFile(struct.name, "serialization") 272 serialization_header = self.GetHeaderFile(struct.name, "serialization")
265 class_header = self.GetHeaderFile(struct.name) 273 class_header = self.GetHeaderFile(struct.name)
266 clones = [] 274 clones = Lines(self.struct_serialization_clone_template)
267 encodes = [] 275 encodes = Lines(self.struct_serialization_encode_template)
268 decodes = [] 276 decodes = Lines(self.struct_serialization_decode_template)
269 sizes = " return sizeof(*%s)" % struct.name.lower() 277 sizes = " return sizeof(*%s)" % struct.name.lower()
270 fields = self.GetSerializedFields(ps) 278 fields = self.GetSerializedFields(ps)
271 for field in fields: 279 for field in fields:
272 substitutions = {'NAME': struct.name.lower(), 'FIELD': field.name.lower()} 280 substitutions = {'NAME': struct.name.lower(), 'FIELD': field.name.lower()}
273 sizes += \ 281 sizes += \
274 self.struct_serialization_compute_template.substitute(substitutions) 282 self.struct_serialization_compute_template.substitute(substitutions)
275 clones.append( 283 clones.Add(substitutions)
276 self.struct_serialization_clone_template.substitute(substitutions)) 284 encodes.Add(substitutions)
277 encodes.append( 285 decodes.Add(substitutions)
278 self.struct_serialization_encode_template.substitute(substitutions))
279 decodes.append(
280 self.struct_serialization_decode_template.substitute(substitutions))
281 sizes += ";" 286 sizes += ";"
282 self.WriteTemplateToFile( 287 self.WriteTemplateToFile(
283 self.struct_serialization_source_template, 288 self.struct_serialization_source_template,
284 struct.name + "_serialization", 289 struct.name + "_serialization",
285 'cc', 290 'cc',
286 YEAR = datetime.date.today().year,
287 NAME = struct.name.lower(), 291 NAME = struct.name.lower(),
288 FULL_CLASS = "%s::%s" % \ 292 FULL_CLASS = "%s::%s" % \
289 (self.module.namespace, struct.name.capitalize()), 293 (self.module.namespace, struct.name.capitalize()),
290 SERIALIZATION_HEADER = serialization_header, 294 SERIALIZATION_HEADER = serialization_header,
291 CLASS_HEADER = class_header, 295 CLASS_HEADER = class_header,
292 SIZES = sizes, 296 SIZES = sizes,
293 CLONES = '\n'.join(clones), 297 CLONES = clones,
294 ENCODES = '\n'.join(encodes), 298 ENCODES = encodes,
295 DECODES = '\n'.join(decodes)) 299 DECODES = decodes)
296 300
297 def GenerateInterfaceHeader(self, interface): 301 def GenerateInterfaceHeader(self, interface):
298 cpp_methods = [] 302 cpp_methods = []
299 forwards = set() 303 forwards = Forwards()
300 for method in interface.methods: 304 for method in interface.methods:
301 cpp_method = " virtual void %s(" % method.name 305 cpp_method = " virtual void %s(" % method.name
302 first_param = True 306 params = []
303 for param in method.parameters: 307 for param in method.parameters:
304 if first_param == True: 308 forwards.Add(param.kind)
305 first_param = False 309 params.append("%s %s" % (self.GetConstType(param.kind), param.name))
306 else: 310 cpp_methods.append(
307 cpp_method += ", " 311 " virtual void %s(%s) = 0" % (method.name, ", ".join(params)))
308 AddForward(forwards, param.kind)
309 cpp_method += "%s %s" % (self.GetConstType(param.kind), param.name)
310 cpp_method += ") = 0;"
311 cpp_methods.append(cpp_method)
312 312
313 self.WriteTemplateToFile( 313 self.WriteTemplateToFile(
314 self.interface_header_template, 314 self.interface_header_template,
315 interface.name, 315 interface.name,
316 'h', 316 'h',
317 YEAR = datetime.date.today().year,
318 HEADER_GUARD = self.GetHeaderGuard(interface.name), 317 HEADER_GUARD = self.GetHeaderGuard(interface.name),
319 NAMESPACE = self.module.namespace,
320 CLASS = interface.name.capitalize(), 318 CLASS = interface.name.capitalize(),
321 FORWARDS = GetForwards(forwards), 319 FORWARDS = forwards,
322 METHODS = '\n'.join(cpp_methods)) 320 METHODS = '\n'.join(cpp_methods))
323 321
324 def GenerateInterfaceStubHeader(self, interface): 322 def GenerateInterfaceStubHeader(self, interface):
325 header = self.GetHeaderFile(interface.name) 323 header = self.GetHeaderFile(interface.name)
326 self.WriteTemplateToFile( 324 self.WriteTemplateToFile(
327 self.interface_stub_header_template, 325 self.interface_stub_header_template,
328 interface.name + "_stub", 326 interface.name + "_stub",
329 'h', 327 'h',
330 YEAR = datetime.date.today().year,
331 HEADER_GUARD = self.GetHeaderGuard(interface.name + "_STUB"), 328 HEADER_GUARD = self.GetHeaderGuard(interface.name + "_STUB"),
332 NAMESPACE = self.module.namespace,
333 CLASS = interface.name.capitalize(), 329 CLASS = interface.name.capitalize(),
334 HEADER = header) 330 HEADER = header)
335 331
336 def GenerateInterfaceStubSource(self, interface): 332 def GenerateInterfaceStubSource(self, interface):
337 stub_header = self.GetHeaderFile(interface.name, "stub") 333 stub_header = self.GetHeaderFile(interface.name, "stub")
338 serialization_header = self.GetHeaderFile(interface.name, "serialization") 334 serialization_header = self.GetHeaderFile(interface.name, "serialization")
339 cases = [] 335 cases = []
340 for method in interface.methods: 336 for method in interface.methods:
341 cases.append(self.GetCaseLine(interface, method)) 337 cases.append(self.GetCaseLine(interface, method))
342 self.WriteTemplateToFile( 338 self.WriteTemplateToFile(
343 self.interface_stub_source_template, 339 self.interface_stub_source_template,
344 interface.name + "_stub", 340 interface.name + "_stub",
345 'cc', 341 'cc',
346 YEAR = datetime.date.today().year,
347 NAMESPACE = self.module.namespace,
348 CLASS = interface.name.capitalize(), 342 CLASS = interface.name.capitalize(),
349 CASES = '\n'.join(cases), 343 CASES = '\n'.join(cases),
350 STUB_HEADER = stub_header, 344 STUB_HEADER = stub_header,
351 SERIALIZATION_HEADER = serialization_header) 345 SERIALIZATION_HEADER = serialization_header)
352 346
353 def GenerateFiles(self): 347 def GenerateFiles(self):
354 for struct in self.module.structs: 348 for struct in self.module.structs:
355 ps = mojom_pack.PackedStruct(struct) 349 ps = mojom_pack.PackedStruct(struct)
356 self.GenerateStructHeader(ps) 350 self.GenerateStructHeader(ps)
357 self.GenerateStructSource(ps) 351 self.GenerateStructSource(ps)
358 self.GenerateStructSerializationHeader(ps) 352 self.GenerateStructSerializationHeader(ps)
359 self.GenerateStructSerializationSource(ps) 353 self.GenerateStructSerializationSource(ps)
360 for interface in self.module.interfaces: 354 for interface in self.module.interfaces:
361 self.GenerateInterfaceHeader(interface) 355 self.GenerateInterfaceHeader(interface)
362 self.GenerateInterfaceStubHeader(interface) 356 self.GenerateInterfaceStubHeader(interface)
363 self.GenerateInterfaceStubSource(interface) 357 self.GenerateInterfaceStubSource(interface)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698