Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(30)

Side by Side Diff: src/pkg/xgb/go_client.py

Issue 180074: code review 180074: Updated the XGB python script to generate semicolon-free (Closed)
Patch Set: code review 180074: Updated the XGB python script to generate semicolon-free Created 15 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2009 The Go Authors. All rights reserved. 2 # Copyright 2009 The Go Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style 3 # Use of this source code is governed by a BSD-style
4 # license that can be found in the LICENSE file. 4 # license that can be found in the LICENSE file.
5 5
6 from xml.etree.cElementTree import * 6 from xml.etree.cElementTree import *
7 from os.path import basename, exists 7 from os.path import basename, exists
8 import getopt 8 import getopt
9 import sys 9 import sys
10 import re 10 import re
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if self.is_union: 180 if self.is_union:
181 go('type %s struct /*union */ {', self.c_type) 181 go('type %s struct /*union */ {', self.c_type)
182 else: 182 else:
183 go('type %s struct {', self.c_type) 183 go('type %s struct {', self.c_type)
184 if not fieldlist: 184 if not fieldlist:
185 fieldlist = self.fields 185 fieldlist = self.fields
186 for field in fieldlist: 186 for field in fieldlist:
187 if field.type.is_pad: 187 if field.type.is_pad:
188 continue 188 continue
189 if field.wire and field.type.fixed_size(): 189 if field.wire and field.type.fixed_size():
190 » » » go('» %s %s%s;', field.c_field_name, field.c_subscript , field.c_field_type) 190 » » » go('» %s %s%s', field.c_field_name, field.c_subscript, field.c_field_type)
191 if field.wire and not field.type.fixed_size(): 191 if field.wire and not field.type.fixed_size():
192 » » » go('» %s []%s;', field.c_field_name, field.c_field_typ e) 192 » » » go('» %s []%s', field.c_field_name, field.c_field_type )
193 go('}') 193 go('}')
194 go('') 194 go('')
195 195
196 def go_get(dst, ofs, typename, typesize): 196 def go_get(dst, ofs, typename, typesize):
197 dst = "v." + dst 197 dst = "v." + dst
198 if typesize == 1: 198 if typesize == 1:
199 if typename == 'byte': 199 if typename == 'byte':
200 » » » go('%s = b[%s];', dst, ofs) 200 » » » go('%s = b[%s]', dst, ofs)
201 else: 201 else:
202 » » » go('%s = %s(b[%s]);', dst, typename, ofs) 202 » » » go('%s = %s(b[%s])', dst, typename, ofs)
203 elif typesize == 2: 203 elif typesize == 2:
204 if typename == 'uint16': 204 if typename == 'uint16':
205 » » » go('%s = get16(b[%s:]);', dst, ofs) 205 » » » go('%s = get16(b[%s:])', dst, ofs)
206 else: 206 else:
207 » » » go('%s = %s(get16(b[%s:]));', dst, typename, ofs) 207 » » » go('%s = %s(get16(b[%s:]))', dst, typename, ofs)
208 elif typesize == 4: 208 elif typesize == 4:
209 if typename == 'uint32': 209 if typename == 'uint32':
210 » » » go('%s = get32(b[%s:]);', dst, ofs) 210 » » » go('%s = get32(b[%s:])', dst, ofs)
211 else: 211 else:
212 » » » go('%s = %s(get32(b[%s:]));', dst, typename, ofs) 212 » » » go('%s = %s(get32(b[%s:]))', dst, typename, ofs)
213 else: 213 else:
214 » » go('get%s(b[%s:], &%s);', typename, ofs, dst) 214 » » go('get%s(b[%s:], &%s)', typename, ofs, dst)
215 215
216 def go_get_list(dst, ofs, typename, typesize, count): 216 def go_get_list(dst, ofs, typename, typesize, count):
217 if typesize == 1 and typename == 'byte': 217 if typesize == 1 and typename == 'byte':
218 » » go('copy(v.%s[0:%s], b[%s:]);', dst, count, ofs) 218 » » go('copy(v.%s[0:%s], b[%s:])', dst, count, ofs)
219 else: 219 else:
220 go('for i := 0; i < %s; i++ {', count) 220 go('for i := 0; i < %s; i++ {', count)
221 go_get(dst + "[i]", ofs + "+i*" + str(typesize), typename, types ize) 221 go_get(dst + "[i]", ofs + "+i*" + str(typesize), typename, types ize)
222 go('}') 222 go('}')
223 223
224 224
225 def go_complex_reader_help(self, fieldlist): 225 def go_complex_reader_help(self, fieldlist):
226 firstvar = 1 226 firstvar = 1
227 total = 0 227 total = 0
228 for field in fieldlist: 228 for field in fieldlist:
229 fieldname = field.c_field_name 229 fieldname = field.c_field_name
230 fieldtype = field.c_field_type 230 fieldtype = field.c_field_type
231 if field.wire and field.type.fixed_size(): 231 if field.wire and field.type.fixed_size():
232 total = field.c_offset + field.type.size * field.type.nm emb 232 total = field.c_offset + field.type.size * field.type.nm emb
233 if field.type.is_pad: 233 if field.type.is_pad:
234 continue 234 continue
235 if field.type.nmemb == 1: 235 if field.type.nmemb == 1:
236 go_get(fieldname, field.c_offset, fieldtype, fie ld.type.size) 236 go_get(fieldname, field.c_offset, fieldtype, fie ld.type.size)
237 else: 237 else:
238 go_get_list(fieldname, field.c_offset, fieldtype , field.type.size, field.type.nmemb) 238 go_get_list(fieldname, field.c_offset, fieldtype , field.type.size, field.type.nmemb)
239 if field.wire and not field.type.fixed_size(): 239 if field.wire and not field.type.fixed_size():
240 lenstr = go_accessor_expr(field.type.expr, 'v', False) 240 lenstr = go_accessor_expr(field.type.expr, 'v', False)
241 if firstvar: 241 if firstvar:
242 firstvar = 0 242 firstvar = 0
243 » » » » go('offset := %d;', field.c_offset); 243 » » » » go('offset := %d', field.c_offset)
244 else: 244 else:
245 » » » » go('offset = pad(offset);') 245 » » » » go('offset = pad(offset)')
246 » » » go('v.%s = make([]%s, %s);', fieldname, fieldtype, lenst r) 246 » » » go('v.%s = make([]%s, %s)', fieldname, fieldtype, lenstr )
247 if fieldtype in sizeoftab: 247 if fieldtype in sizeoftab:
248 go_get_list(fieldname, "offset", fieldtype, size oftab[fieldtype], "len(v."+fieldname+")") 248 go_get_list(fieldname, "offset", fieldtype, size oftab[fieldtype], "len(v."+fieldname+")")
249 » » » » go('offset += len(v.%s) * %d;', fieldname, sizeo ftab[fieldtype]) 249 » » » » go('offset += len(v.%s) * %d', fieldname, sizeof tab[fieldtype])
250 else: 250 else:
251 go('for i := 0; i < %s; i++ {', lenstr) 251 go('for i := 0; i < %s; i++ {', lenstr)
252 » » » » go('» offset += get%s(b[offset:], &v.%s[i]);', fieldtype, fieldname) 252 » » » » go('» offset += get%s(b[offset:], &v.%s[i])', fieldtype, fieldname)
253 go('}') 253 go('}')
254 if not firstvar: 254 if not firstvar:
255 return 'offset' 255 return 'offset'
256 return str(total) 256 return str(total)
257 257
258 def go_complex_reader(self): 258 def go_complex_reader(self):
259 go('func get%s(b []byte, v *%s) int {', self.c_type, self.c_type) 259 go('func get%s(b []byte, v *%s) int {', self.c_type, self.c_type)
260 » go('» return %s;', go_complex_reader_help(self, self.fields)) 260 » go('» return %s', go_complex_reader_help(self, self.fields))
261 go('}') 261 go('}')
262 go('') 262 go('')
263 ········ 263 ········
264 def structsize(fieldlist): 264 def structsize(fieldlist):
265 fixedtotal = 0 265 fixedtotal = 0
266 for field in fieldlist: 266 for field in fieldlist:
267 if field.wire and field.type.fixed_size(): 267 if field.wire and field.type.fixed_size():
268 fixedtotal += field.type.size * field.type.nmemb 268 fixedtotal += field.type.size * field.type.nmemb
269 return fixedtotal 269 return fixedtotal
270 270
271 def go_put(src, ofs, typename, typesize): 271 def go_put(src, ofs, typename, typesize):
272 if typesize == 1: 272 if typesize == 1:
273 if typename == 'byte': 273 if typename == 'byte':
274 » » » go('b[%s] = %s;', ofs, src) 274 » » » go('b[%s] = %s', ofs, src)
275 else: 275 else:
276 » » » go('b[%s] = byte(%s);', ofs, src) 276 » » » go('b[%s] = byte(%s)', ofs, src)
277 elif typesize == 2: 277 elif typesize == 2:
278 if typename == 'uint16': 278 if typename == 'uint16':
279 » » » go('put16(b[%s:], %s);', ofs, src) 279 » » » go('put16(b[%s:], %s)', ofs, src)
280 else: 280 else:
281 » » » go('put16(b[%s:], uint16(%s));', ofs, src) 281 » » » go('put16(b[%s:], uint16(%s))', ofs, src)
282 elif typesize == 4: 282 elif typesize == 4:
283 if typename == 'uint32': 283 if typename == 'uint32':
284 » » » go('put32(b[%s:], %s);', ofs, src) 284 » » » go('put32(b[%s:], %s)', ofs, src)
285 else: 285 else:
286 » » » go('put32(b[%s:], uint32(%s));', ofs, src) 286 » » » go('put32(b[%s:], uint32(%s))', ofs, src)
287 else: 287 else:
288 » » go('put%s(b[%s:], %s);', typename, ofs, src) 288 » » go('put%s(b[%s:], %s)', typename, ofs, src)
289 289
290 290
291 def go_complex_writer_help(fieldlist, prefix=''): 291 def go_complex_writer_help(fieldlist, prefix=''):
292 prefarrow = '' if prefix == '' else prefix + '.' 292 prefarrow = '' if prefix == '' else prefix + '.'
293 for field in fieldlist: 293 for field in fieldlist:
294 fieldname = prefarrow + field.c_field_name 294 fieldname = prefarrow + field.c_field_name
295 fieldtype = field.c_field_type 295 fieldtype = field.c_field_type
296 if fieldname.endswith("Len"): 296 if fieldname.endswith("Len"):
297 fieldname = "len(%s)" % fieldname[:-3] 297 fieldname = "len(%s)" % fieldname[:-3]
298 fieldtype = "(exp)" 298 fieldtype = "(exp)"
299 if not field.type.fixed_size(): 299 if not field.type.fixed_size():
300 continue 300 continue
301 if field.type.is_expr: 301 if field.type.is_expr:
302 expstr = go_accessor_expr(field.type.expr, prefix, True) 302 expstr = go_accessor_expr(field.type.expr, prefix, True)
303 go_put(expstr, field.c_offset, "(exp)", field.type.size) 303 go_put(expstr, field.c_offset, "(exp)", field.type.size)
304 elif not field.type.is_pad: 304 elif not field.type.is_pad:
305 if field.type.nmemb == 1: 305 if field.type.nmemb == 1:
306 go_put(fieldname, field.c_offset, fieldtype, fie ld.type.size) 306 go_put(fieldname, field.c_offset, fieldtype, fie ld.type.size)
307 else: 307 else:
308 » » » » go('» copy(b[%d:%d], %s);', field.c_offset, fi eld.c_offset + field.type.nmemb, fieldname) 308 » » » » go('» copy(b[%d:%d], %s)', field.c_offset, fie ld.c_offset + field.type.nmemb, fieldname)
309 309
310 def go_complex_writer_arguments(param_fields): 310 def go_complex_writer_arguments(param_fields, endstr):
311 out = [] 311 out = []
312 for field in param_fields: 312 for field in param_fields:
313 namestr = field.c_field_name 313 namestr = field.c_field_name
314 typestr = field.c_pointer + t(field.field_type) 314 typestr = field.c_pointer + t(field.field_type)
315 if typestr == '[]byte' and namestr == 'Name': 315 if typestr == '[]byte' and namestr == 'Name':
316 typestr = 'string' 316 typestr = 'string'
317 out.append(namestr + ' ' + typestr) 317 out.append(namestr + ' ' + typestr)
318 » go('» ' + ', '.join(out)) 318 » go('» ' + ', '.join(out) + ')' + endstr)
319 319
320 def go_complex_writer_arguments_names(param_fields): 320 def go_complex_writer_arguments_names(param_fields):
321 out = [] 321 out = []
322 for field in param_fields: 322 for field in param_fields:
323 out.append(field.c_field_name) 323 out.append(field.c_field_name)
324 return ', '.join(out) 324 return ', '.join(out)
325 325
326 def go_complex_writer(self, name, void): 326 def go_complex_writer(self, name, void):
327 func_name = self.c_request_name 327 func_name = self.c_request_name
328 328
329 param_fields = [] 329 param_fields = []
330 wire_fields = [] 330 wire_fields = []
331 for field in self.fields: 331 for field in self.fields:
332 if field.visible: 332 if field.visible:
333 # _len is taken from the list directly 333 # _len is taken from the list directly
334 if not field.field_name.endswith("_len"): 334 if not field.field_name.endswith("_len"):
335 # The field should appear as a call parameter 335 # The field should appear as a call parameter
336 param_fields.append(field) 336 param_fields.append(field)
337 if field.wire and not field.auto: 337 if field.wire and not field.auto:
338 # We need to set the field up in the structure 338 # We need to set the field up in the structure
339 wire_fields.append(field) 339 wire_fields.append(field)
340 ········ 340 ········
341 if void: 341 if void:
342 go('func (c *Conn) %s(', func_name) 342 go('func (c *Conn) %s(', func_name)
343 » » go_complex_writer_arguments(param_fields) 343 » » go_complex_writer_arguments(param_fields, "{")
344 » » go(') {')
345 else: 344 else:
346 go('func (c *Conn) %sRequest(', func_name) 345 go('func (c *Conn) %sRequest(', func_name)
347 » » go_complex_writer_arguments(param_fields) 346 » » go_complex_writer_arguments(param_fields, "Cookie {")
348 » » go(') Cookie {')
349 ········ 347 ········
350 fixedtotal = structsize(self.fields) 348 fixedtotal = structsize(self.fields)
351 if fixedtotal <= 32: 349 if fixedtotal <= 32:
352 » » go('» b := c.scratch[0:%d];', fixedtotal) 350 » » go('» b := c.scratch[0:%d]', fixedtotal)
353 else: 351 else:
354 » » go('» b := make([]byte, %d);', fixedtotal) 352 » » go('» b := make([]byte, %d)', fixedtotal)
355 firstvar = 0 353 firstvar = 0
356 for field in wire_fields: 354 for field in wire_fields:
357 if not field.type.fixed_size(): 355 if not field.type.fixed_size():
358 if not firstvar: 356 if not firstvar:
359 firstvar = 1 357 firstvar = 1
360 » » » » go('» n := %d;', fixedtotal) 358 » » » » go('» n := %d', fixedtotal)
361 » » » go('» n += pad(%s * %d);', go_accessor_expr(field.type .expr, '', True), field.type.size) 359 » » » go('» n += pad(%s * %d)', go_accessor_expr(field.type. expr, '', True), field.type.size)
362 if not firstvar: 360 if not firstvar:
363 » » go('» put16(b[2:], %d);', fixedtotal / 4) 361 » » go('» put16(b[2:], %d)', fixedtotal / 4)
364 else: 362 else:
365 » » go('» put16(b[2:], uint16(n / 4));') 363 » » go('» put16(b[2:], uint16(n / 4))')
366 » go('» b[0] = %s;', self.opcode) 364 » go('» b[0] = %s', self.opcode)
367 go_complex_writer_help(wire_fields) 365 go_complex_writer_help(wire_fields)
368 if not void: 366 if not void:
369 if firstvar: 367 if firstvar:
370 » » » go('» cookie := c.sendRequest(b);') 368 » » » go('» cookie := c.sendRequest(b)')
371 else: 369 else:
372 » » » go('» return c.sendRequest(b);') 370 » » » go('» return c.sendRequest(b)')
373 else: 371 else:
374 » » go('» c.sendRequest(b);') 372 » » go('» c.sendRequest(b)')
375 ········ 373 ········
376 # send extra data 374 # send extra data
377 for field in param_fields: 375 for field in param_fields:
378 if not field.type.fixed_size(): 376 if not field.type.fixed_size():
379 if field.type.is_list: 377 if field.type.is_list:
380 fieldname = field.c_field_name 378 fieldname = field.c_field_name
381 lenstr = go_accessor_expr(field.type.expr, '', T rue) 379 lenstr = go_accessor_expr(field.type.expr, '', T rue)
382 if t(field.field_type) == 'byte': 380 if t(field.field_type) == 'byte':
383 if fieldname == 'Name': 381 if fieldname == 'Name':
384 » » » » » » go('» c.sendString(%s);', fiel dname) 382 » » » » » » go('» c.sendString(%s)', field name)
385 else: 383 else:
386 » » » » » » go('» c.sendBytes(%s[0:%s]);', fieldname, lenstr) 384 » » » » » » go('» c.sendBytes(%s[0:%s])', fieldname, lenstr)
387 elif t(field.field_type) == 'uint32': 385 elif t(field.field_type) == 'uint32':
388 » » » » » go('» c.sendUInt32List(%s[0:%s]);', fi eldname, lenstr) 386 » » » » » go('» c.sendUInt32List(%s[0:%s])', fie ldname, lenstr)
389 else: 387 else:
390 » » » » » go('» c.send%sList(%s, %s);', t(field. field_type), fieldname, lenstr) 388 » » » » » go('» c.send%sList(%s, %s)', t(field.f ield_type), fieldname, lenstr)
391 ········ 389 ········
392 if not void and firstvar: 390 if not void and firstvar:
393 » » go('» return cookie;') 391 » » go('» return cookie')
394 go('}') 392 go('}')
395 go('') 393 go('')
396 ········ 394 ········
397 if not void: 395 if not void:
398 args = go_complex_writer_arguments_names(param_fields) 396 args = go_complex_writer_arguments_names(param_fields)
399 go('func (c *Conn) %s(', func_name) 397 go('func (c *Conn) %s(', func_name)
400 » » go_complex_writer_arguments(param_fields) 398 » » go_complex_writer_arguments(param_fields, '(*%s, os.Error) {' % self.c_reply_type)
401 » » go(') (*%s, os.Error) {', self.c_reply_type) 399 » » go('» return c.%sReply(c.%sRequest(%s))', func_name, func_name , args)
402 » » go('» return c.%sReply(c.%sRequest(%s));', func_name, func_nam e, args)
403 go('}') 400 go('}')
404 go('') 401 go('')
405 402
406 # 403 #
407 # Struct definitions, readers and writers 404 # Struct definitions, readers and writers
408 # 405 #
409 406
410 def go_struct(self, name): 407 def go_struct(self, name):
411 go_type_setup(self, name, ()) 408 go_type_setup(self, name, ())
412 if symbols and t(name) not in symbols: 409 if symbols and t(name) not in symbols:
(...skipping 13 matching lines...) Expand all
426 if self.c_type == 'SetupInfo': return 423 if self.c_type == 'SetupInfo': return
427 if self.c_type == 'ScreenInfo': return 424 if self.c_type == 'ScreenInfo': return
428 ········ 425 ········
429 # omit variable length struct writers, they're never used 426 # omit variable length struct writers, they're never used
430 if not self.fixed_size(): 427 if not self.fixed_size():
431 go('// omitting variable length send%s', self.c_type) 428 go('// omitting variable length send%s', self.c_type)
432 go('') 429 go('')
433 return 430 return
434 ········ 431 ········
435 go('func (c *Conn) send%sList(list []%s, count int) {', self.c_type, sel f.c_type) 432 go('func (c *Conn) send%sList(list []%s, count int) {', self.c_type, sel f.c_type)
436 » go('» b0 := make([]byte, %d * count);', structsize(self.fields)) 433 » go('» b0 := make([]byte, %d * count)', structsize(self.fields))
437 go(' for k := 0; k < count; k++ {') 434 go(' for k := 0; k < count; k++ {')
438 » go('» b := b0[k * %d:];', structsize(self.fields)) 435 » go('» b := b0[k * %d:]', structsize(self.fields))
439 go_complex_writer_help(self.fields, 'list[k]') 436 go_complex_writer_help(self.fields, 'list[k]')
440 go(' }') 437 go(' }')
441 » go('» c.sendBytes(b0);') 438 » go('» c.sendBytes(b0)')
442 go('}') 439 go('}')
443 go('') 440 go('')
444 441
445 def go_union(self, name): 442 def go_union(self, name):
446 pass 443 pass
447 444
448 # 445 #
449 # Request writers with reply structs and readers where needed 446 # Request writers with reply structs and readers where needed
450 # 447 #
451 448
452 def replyfields(self): 449 def replyfields(self):
453 l = [] 450 l = []
454 for field in self.fields: 451 for field in self.fields:
455 if field.type.is_pad or not field.wire: continue 452 if field.type.is_pad or not field.wire: continue
456 if field.field_name == 'response_type': continue 453 if field.field_name == 'response_type': continue
457 if field.field_name == 'sequence': continue 454 if field.field_name == 'sequence': continue
458 if field.field_name == 'length': 455 if field.field_name == 'length':
459 if self.c_reply_name != 'GetImageReply' and self.c_reply _name != 'GetKeyboardMappingReply': 456 if self.c_reply_name != 'GetImageReply' and self.c_reply _name != 'GetKeyboardMappingReply':
460 continue 457 continue
461 l.append(field) 458 l.append(field)
462 return l 459 return l
463 460
464 def go_reply(self, name): 461 def go_reply(self, name):
465 ''' 462 '''
466 Declares the function that returns the reply structure. 463 Declares the function that returns the reply structure.
467 ''' 464 '''
468 fields = replyfields(self.reply) 465 fields = replyfields(self.reply)
469 go_complex(self.reply, fields) 466 go_complex(self.reply, fields)
470 go('func (c *Conn) %s(cookie Cookie) (*%s, os.Error) {', self.c_reply_na me, self.c_reply_type) 467 go('func (c *Conn) %s(cookie Cookie) (*%s, os.Error) {', self.c_reply_na me, self.c_reply_type)
471 » go('» b, error := c.waitForReply(cookie);') 468 » go('» b, error := c.waitForReply(cookie)')
472 go(' if error != nil { return nil, error }') 469 go(' if error != nil { return nil, error }')
473 » go('» v := new(%s);', self.c_reply_type) 470 » go('» v := new(%s)', self.c_reply_type)
474 go_complex_reader_help(self.reply, fields) 471 go_complex_reader_help(self.reply, fields)
475 » go('» return v, nil;') 472 » go('» return v, nil')
476 go('}') 473 go('}')
477 go('') 474 go('')
478 475
479 def go_request(self, name): 476 def go_request(self, name):
480 ''' 477 '''
481 Exported function that handles request declarations. 478 Exported function that handles request declarations.
482 ''' 479 '''
483 go_type_setup(self, name, ('Request',)) 480 go_type_setup(self, name, ('Request',))
484 if symbols and n(name) not in symbols: 481 if symbols and n(name) not in symbols:
485 go('// excluding request %s\n', n(name)) 482 go('// excluding request %s\n', n(name))
(...skipping 18 matching lines...) Expand all
504 if field.field_name == 'sequence': continue 501 if field.field_name == 'sequence': continue
505 l.append(field) 502 l.append(field)
506 return l 503 return l
507 504
508 eventlist = [] 505 eventlist = []
509 506
510 def dumpeventlist(): 507 def dumpeventlist():
511 go('func parseEvent(buf []byte) (Event, os.Error) {') 508 go('func parseEvent(buf []byte) (Event, os.Error) {')
512 go(' switch buf[0] {') 509 go(' switch buf[0] {')
513 for event in eventlist: 510 for event in eventlist:
514 » » go('» case %s: return get%sEvent(buf), nil;', event, event) 511 » » go('» case %s: return get%sEvent(buf), nil', event, event)
515 go(' }') 512 go(' }')
516 » go('» return nil, os.NewError("unknown event type");') 513 » go('» return nil, os.NewError("unknown event type")')
517 go('}') 514 go('}')
518 515
519 def go_event(self, name): 516 def go_event(self, name):
520 ''' 517 '''
521 Exported function that handles event declarations. 518 Exported function that handles event declarations.
522 ''' 519 '''
523 go_type_setup(self, name, ('Event',)) 520 go_type_setup(self, name, ('Event',))
524 if symbols and t(name) not in symbols: 521 if symbols and t(name) not in symbols:
525 go('// excluding event %s\n', t(name)) 522 go('// excluding event %s\n', t(name))
526 return 523 return
527 ········ 524 ········
528 eventlist.append(n(name)) 525 eventlist.append(n(name))
529 ········ 526 ········
530 go('const %s = %s', t(name), self.opcodes[name]) 527 go('const %s = %s', t(name), self.opcodes[name])
531 go('') 528 go('')
532 fields = eventfields(self) 529 fields = eventfields(self)
533 if self.name == name: 530 if self.name == name:
534 # Structure definition 531 # Structure definition
535 go_complex(self, fields) 532 go_complex(self, fields)
536 go('func get%s(b []byte) %s {', self.c_type, self.c_type) 533 go('func get%s(b []byte) %s {', self.c_type, self.c_type)
537 » » go('» var v %s;', self.c_type) 534 » » go('» var v %s', self.c_type)
538 go_complex_reader_help(self, fields) 535 go_complex_reader_help(self, fields)
539 » » go('» return v;') 536 » » go('» return v')
540 go('}') 537 go('}')
541 go('') 538 go('')
542 else: 539 else:
543 # maybe skip this depending on how it interacts with type switch ing on interfaces 540 # maybe skip this depending on how it interacts with type switch ing on interfaces
544 go('type %s %s', n(name + ('Event',)), n(self.name + ('Event',)) ) 541 go('type %s %s', n(name + ('Event',)), n(self.name + ('Event',)) )
545 go('') 542 go('')
546 go('func get%s(b []byte) %s {', self.c_type, self.c_type) 543 go('func get%s(b []byte) %s {', self.c_type, self.c_type)
547 » » go('» return (%s)(get%s(b));', n(name + ('Event',)), n(self.na me + ('Event',))) 544 » » go('» return (%s)(get%s(b))', n(name + ('Event',)), n(self.nam e + ('Event',)))
548 go('}') 545 go('}')
549 go('') 546 go('')
550 547
551 # 548 #
552 # Map simple types to primitive types 549 # Map simple types to primitive types
553 # 550 #
554 551
555 def go_simple(self, name): 552 def go_simple(self, name):
556 ''' 553 '''
557 Exported function that handles cardinal type declarations. 554 Exported function that handles cardinal type declarations.
(...skipping 29 matching lines...) Expand all
587 for (enam, eval) in self.values: 584 for (enam, eval) in self.values:
588 if str(eval) == '': 585 if str(eval) == '':
589 iota = iota + 1 586 iota = iota + 1
590 eval = iota 587 eval = iota
591 else: 588 else:
592 iota = int(eval) 589 iota = int(eval)
593 if name[1] == 'Atom': 590 if name[1] == 'Atom':
594 s = name[1] + "".join([x.capitalize() for x in enam.spli t("_")]) 591 s = name[1] + "".join([x.capitalize() for x in enam.spli t("_")])
595 else: 592 else:
596 s = n(name + (enam,)) 593 s = n(name + (enam,))
597 » » go('» %s = %s;', s, eval) 594 » » go('» %s = %s', s, eval)
598 go(')') 595 go(')')
599 go('') 596 go('')
600 597
601 errorlist = [] 598 errorlist = []
602 599
603 def dumperrorlist(): 600 def dumperrorlist():
604 go('var errorNames = map[byte]string{') 601 go('var errorNames = map[byte]string{')
605 for error in errorlist: 602 for error in errorlist:
606 go(' Bad%s: "%s",', error, error) 603 go(' Bad%s: "%s",', error, error)
607 go('}') 604 go('}')
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 print 'Failed to load the xcbgen Python package!' 692 print 'Failed to load the xcbgen Python package!'
696 print 'Make sure that xcb/proto installed it on your Python path,' 693 print 'Make sure that xcb/proto installed it on your Python path,'
697 print 'or pass the path with -p.' 694 print 'or pass the path with -p.'
698 print '' 695 print ''
699 raise 696 raise
700 697
701 module = Module(args[0], output) 698 module = Module(args[0], output)
702 module.register() 699 module.register()
703 module.resolve() 700 module.resolve()
704 module.generate() 701 module.generate()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b