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

Side by Side Diff: ppapi/generators/idl_c_proto.py

Issue 8568025: Pnacl ppapi shim generator (from IDL), based on Noel's first cut. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add code to skip wrapping Created 9 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """ Generator for C style prototypes and definitions """ 7 """ Generator for C style prototypes and definitions """
8 8
9 import glob 9 import glob
10 import os 10 import os
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 return 'return' 331 return 'return'
332 332
333 # 333 #
334 # GetComponents 334 # GetComponents
335 # 335 #
336 # Returns the signature components of an object as a tuple of 336 # Returns the signature components of an object as a tuple of
337 # (rtype, name, arrays, callspec) where: 337 # (rtype, name, arrays, callspec) where:
338 # rtype - The store or return type of the object. 338 # rtype - The store or return type of the object.
339 # name - The name of the object. 339 # name - The name of the object.
340 # arrays - A list of array dimensions as [] or [<fixed_num>]. 340 # arrays - A list of array dimensions as [] or [<fixed_num>].
341 # args - None of not a function, otherwise a list of parameters. 341 # args - None if not a function, otherwise a list of parameters.
342 # 342 #
343 def GetComponents(self, node, release, mode): 343 def GetComponents(self, node, release, mode):
344 self.LogEnter('GetComponents mode %s for %s %s' % (mode, node, release)) 344 self.LogEnter('GetComponents mode %s for %s %s' % (mode, node, release))
345 345
346 # Generate passing type by modifying root type 346 # Generate passing type by modifying root type
347 rtype = self.GetTypeByMode(node, release, mode) 347 rtype = self.GetTypeByMode(node, release, mode)
348 if node.IsA('Enum', 'Interface', 'Struct'): 348 if node.IsA('Enum', 'Interface', 'Struct'):
349 rname = node.GetName() 349 rname = node.GetName()
350 else: 350 else:
351 rname = node.GetType(release).GetName() 351 rname = node.GetType(release).GetName()
(...skipping 12 matching lines...) Expand all
364 ptype, pname, parray, pspec = self.GetComponents(param, release, mode) 364 ptype, pname, parray, pspec = self.GetComponents(param, release, mode)
365 callspec.append((ptype, pname, parray, pspec)) 365 callspec.append((ptype, pname, parray, pspec))
366 else: 366 else:
367 callspec = None 367 callspec = None
368 368
369 self.LogExit('GetComponents: %s, %s, %s, %s' % 369 self.LogExit('GetComponents: %s, %s, %s, %s' %
370 (rtype, name, arrayspec, callspec)) 370 (rtype, name, arrayspec, callspec))
371 return (rtype, name, arrayspec, callspec) 371 return (rtype, name, arrayspec, callspec)
372 372
373 373
374 def Compose(self, rtype, name, arrayspec, callspec, prefix, func_as_ptr): 374 def Compose(self, rtype, name, arrayspec, callspec, prefix, func_as_ptr,
375 ptr_prefix, include_name):
375 self.LogEnter('Compose: %s %s' % (rtype, name)) 376 self.LogEnter('Compose: %s %s' % (rtype, name))
376 arrayspec = ''.join(arrayspec) 377 arrayspec = ''.join(arrayspec)
377 name = '%s%s%s' % (prefix, name, arrayspec) 378 if not include_name:
379 name = '%s%s' % (prefix, arrayspec)
380 else:
381 name = '%s%s%s' % (prefix, name, arrayspec)
378 if callspec is None: 382 if callspec is None:
379 out = '%s %s' % (rtype, name) 383 out = '%s %s' % (rtype, name)
380 else: 384 else:
381 params = [] 385 params = []
382 for ptype, pname, parray, pspec in callspec: 386 for ptype, pname, parray, pspec in callspec:
383 params.append(self.Compose(ptype, pname, parray, pspec, '', True)) 387 params.append(self.Compose(ptype, pname, parray, pspec, '', True,
384 if func_as_ptr: name = '(*%s)' % name 388 ptr_prefix='', include_name=True))
389 if func_as_ptr:
390 name = '(%s*%s)' % (ptr_prefix, name)
385 out = '%s %s(%s)' % (rtype, name, ', '.join(params)) 391 out = '%s %s(%s)' % (rtype, name, ', '.join(params))
386 self.LogExit('Exit Compose: %s' % out) 392 self.LogExit('Exit Compose: %s' % out)
387 return out 393 return out
388 394
389 # 395 #
390 # GetSignature 396 # GetSignature
391 # 397 #
392 # Returns the 'C' style signature of the object 398 # Returns the 'C' style signature of the object
393 # prefix - A prefix for the object's name 399 # prefix - A prefix for the object's name
394 # func_as_ptr - Formats a function as a function pointer 400 # func_as_ptr - Formats a function as a function pointer
401 # ptr_prefix - A prefix that goes before the "*" for a function pointer
402 # include_name - If true, include member name in the signature.
403 # If false, leave it out. In any case, prefix and ptr_prefix
404 # are always included.
395 # 405 #
396 def GetSignature(self, node, release, mode, prefix='', func_as_ptr=True): 406 def GetSignature(self, node, release, mode, prefix='', func_as_ptr=True,
397 self.LogEnter('GetSignature %s %s as func=%s' % (node, mode, func_as_ptr)) 407 ptr_prefix='', include_name=True):
408 self.LogEnter('GetSignature %s %s as func=%s' %
409 (node, mode, func_as_ptr))
398 rtype, name, arrayspec, callspec = self.GetComponents(node, release, mode) 410 rtype, name, arrayspec, callspec = self.GetComponents(node, release, mode)
399 out = self.Compose(rtype, name, arrayspec, callspec, prefix, func_as_ptr) 411 out = self.Compose(rtype, name, arrayspec, callspec, prefix,
412 func_as_ptr, ptr_prefix, include_name)
400 self.LogExit('Exit GetSignature: %s' % out) 413 self.LogExit('Exit GetSignature: %s' % out)
401 return out 414 return out
402 415
403 # Define a Typedef. 416 # Define a Typedef.
404 def DefineTypedef(self, node, releases, prefix='', comment=False): 417 def DefineTypedef(self, node, releases, prefix='', comment=False):
405 __pychecker__ = 'unusednames=comment' 418 __pychecker__ = 'unusednames=comment'
406 release = releases[0] 419 release = releases[0]
407 out = 'typedef %s;\n' % self.GetSignature(node, release, 'return', 420 out = 'typedef %s;\n' % self.GetSignature(node, release, 'return',
408 prefix, True) 421 prefix, True)
409 self.Log('DefineTypedef: %s' % out) 422 self.Log('DefineTypedef: %s' % out)
(...skipping 27 matching lines...) Expand all
437 return out 450 return out
438 451
439 def DefineMember(self, node, releases, prefix='', comment=False): 452 def DefineMember(self, node, releases, prefix='', comment=False):
440 __pychecker__ = 'unusednames=prefix,comment' 453 __pychecker__ = 'unusednames=prefix,comment'
441 release = releases[0] 454 release = releases[0]
442 self.LogEnter('DefineMember %s' % node) 455 self.LogEnter('DefineMember %s' % node)
443 out = '%s;' % self.GetSignature(node, release, 'store', '', True) 456 out = '%s;' % self.GetSignature(node, release, 'store', '', True)
444 self.LogExit('Exit DefineMember') 457 self.LogExit('Exit DefineMember')
445 return out 458 return out
446 459
447 def DefineStructInternals(self, node, release, suffix='', comment=True): 460 def GetStructName(self, node, release, include_version=False):
461 suffix = ''
462 if include_version:
463 ver_num = node.GetVersion(release)
464 suffix = ('_%s' % ver_num).replace('.', '_')
465 return node.GetName() + suffix
466
467 def DefineStructInternals(self, node, release,
468 include_version=False, comment=True):
448 out = '' 469 out = ''
449 if node.GetProperty('union'): 470 if node.GetProperty('union'):
450 out += 'union %s%s {\n' % (node.GetName(), suffix) 471 out += 'union %s {\n' % (
472 self.GetStructName(node, release, include_version))
451 else: 473 else:
452 out += 'struct %s%s {\n' % (node.GetName(), suffix) 474 out += 'struct %s {\n' % (
475 self.GetStructName(node, release, include_version))
453 476
454 # Generate Member Functions 477 # Generate Member Functions
455 members = [] 478 members = []
456 for child in node.GetListOf('Member'): 479 for child in node.GetListOf('Member'):
457 member = self.Define(child, [release], tabs=1, comment=comment) 480 member = self.Define(child, [release], tabs=1, comment=comment)
458 if not member: 481 if not member:
459 continue 482 continue
460 members.append(member) 483 members.append(member)
461 out += '%s\n};\n' % '\n'.join(members) 484 out += '%s\n};\n' % '\n'.join(members)
462 return out 485 return out
463 486
464 487
465 def DefineStruct(self, node, releases, prefix='', comment=False): 488 def DefineStruct(self, node, releases, prefix='', comment=False):
466 __pychecker__ = 'unusednames=comment,prefix' 489 __pychecker__ = 'unusednames=comment,prefix'
467 self.LogEnter('DefineStruct %s' % node) 490 self.LogEnter('DefineStruct %s' % node)
468 out = '' 491 out = ''
469 build_list = node.GetUniqueReleases(releases) 492 build_list = node.GetUniqueReleases(releases)
470 493
471 # Build the most recent one with comments 494 # Build the most recent one with comments
472 out = self.DefineStructInternals(node, build_list[-1], comment=True) 495 out = self.DefineStructInternals(node, build_list[-1],
496 include_version=False, comment=True)
473 497
474 # Build the rest without comments and with the version number appended 498 # Build the rest without comments and with the version number appended
475 for rel in build_list[0:-1]: 499 for rel in build_list[0:-1]:
476 ver_num = node.GetVersion(rel) 500 out += '\n' + self.DefineStructInternals(node, rel,
477 ver = ("_%s" % ver_num).replace('.', '_') 501 include_version=True,
478 out += '\n' + self.DefineStructInternals(node, rel, suffix=ver,
479 comment=False) 502 comment=False)
480 503
481 self.LogExit('Exit DefineStruct') 504 self.LogExit('Exit DefineStruct')
482 return out 505 return out
483 506
484 507
485 # 508 #
486 # Copyright and Comment 509 # Copyright and Comment
487 # 510 #
488 # Generate a comment or copyright block 511 # Generate a comment or copyright block
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 if f.GetProperty('ERRORS') > 0: 630 if f.GetProperty('ERRORS') > 0:
608 print 'Skipping %s' % f.GetName() 631 print 'Skipping %s' % f.GetName()
609 continue 632 continue
610 print DefineDepends(node) 633 print DefineDepends(node)
611 for node in f.GetChildren()[2:]: 634 for node in f.GetChildren()[2:]:
612 print Define(node, comment=True, prefix='tst_') 635 print Define(node, comment=True, prefix='tst_')
613 636
614 637
615 if __name__ == '__main__': 638 if __name__ == '__main__':
616 sys.exit(Main(sys.argv[1:])) 639 sys.exit(Main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698