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

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

Issue 238923007: PPAPI: Format ppapi/thunk using clang-format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 6 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 | « ppapi/generators/idl_outfile.py ('k') | ppapi/thunk/ppb_audio_buffer_thunk.cc » ('j') | 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 (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ Generator for C++ style thunks """ 6 """ Generator for C++ style thunks """
7 7
8 import glob 8 import glob
9 import os 9 import os
10 import re 10 import re
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 return False 429 return False
430 430
431 thunk_out = IDLOutFile(savename) 431 thunk_out = IDLOutFile(savename)
432 body, meta = self.GenerateBody(thunk_out, filenode, releases, options) 432 body, meta = self.GenerateBody(thunk_out, filenode, releases, options)
433 # TODO(teravest): How do we handle repeated values? 433 # TODO(teravest): How do we handle repeated values?
434 if filenode.GetProperty('thunk_include'): 434 if filenode.GetProperty('thunk_include'):
435 meta.AddInclude(filenode.GetProperty('thunk_include')) 435 meta.AddInclude(filenode.GetProperty('thunk_include'))
436 self.WriteHead(thunk_out, filenode, releases, options, meta) 436 self.WriteHead(thunk_out, filenode, releases, options, meta)
437 thunk_out.Write('\n\n'.join(body)) 437 thunk_out.Write('\n\n'.join(body))
438 self.WriteTail(thunk_out, filenode, releases, options) 438 self.WriteTail(thunk_out, filenode, releases, options)
439 thunk_out.ClangFormat()
439 return thunk_out.Close() 440 return thunk_out.Close()
440 441
441 def WriteHead(self, out, filenode, releases, options, meta): 442 def WriteHead(self, out, filenode, releases, options, meta):
442 __pychecker__ = 'unusednames=options' 443 __pychecker__ = 'unusednames=options'
443 cgen = CGen() 444 cgen = CGen()
444 445
445 cright_node = filenode.GetChildren()[0] 446 cright_node = filenode.GetChildren()[0]
446 assert(cright_node.IsA('Copyright')) 447 assert(cright_node.IsA('Copyright'))
447 out.Write('%s\n' % cgen.Copyright(cright_node, cpp_style=True)) 448 out.Write('%s\n' % cgen.Copyright(cright_node, cpp_style=True))
448 449
449 # Wrap the From ... modified ... comment if it would be >80 characters.
450 from_text = 'From %s' % ( 450 from_text = 'From %s' % (
451 filenode.GetProperty('NAME').replace(os.sep,'/')) 451 filenode.GetProperty('NAME').replace(os.sep,'/'))
452 modified_text = 'modified %s.' % ( 452 modified_text = 'modified %s.' % (
453 filenode.GetProperty('DATETIME')) 453 filenode.GetProperty('DATETIME'))
454 if len(from_text) + len(modified_text) < 74: 454 out.Write('// %s %s\n\n' % (from_text, modified_text))
455 out.Write('// %s %s\n\n' % (from_text, modified_text))
456 else:
457 out.Write('// %s,\n// %s\n\n' % (from_text, modified_text))
458 455
459 if meta.BuiltinIncludes(): 456 if meta.BuiltinIncludes():
460 for include in sorted(meta.BuiltinIncludes()): 457 for include in sorted(meta.BuiltinIncludes()):
461 out.Write('#include <%s>\n' % include) 458 out.Write('#include <%s>\n' % include)
462 out.Write('\n') 459 out.Write('\n')
463 460
464 # TODO(teravest): Don't emit includes we don't need. 461 # TODO(teravest): Don't emit includes we don't need.
465 includes = ['ppapi/c/pp_errors.h', 462 includes = ['ppapi/c/pp_errors.h',
466 'ppapi/shared_impl/tracked_callback.h', 463 'ppapi/shared_impl/tracked_callback.h',
467 'ppapi/thunk/enter.h', 464 'ppapi/thunk/enter.h',
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 out.Write('\n\n') 519 out.Write('\n\n')
523 for node in filenode.GetListOf('Interface'): 520 for node in filenode.GetListOf('Interface'):
524 build_list = node.GetUniqueReleases(releases) 521 build_list = node.GetUniqueReleases(releases)
525 for build in build_list: 522 for build in build_list:
526 version = node.GetVersion(build).replace('.', '_') 523 version = node.GetVersion(build).replace('.', '_')
527 thunk_name = 'g_' + node.GetName().lower() + '_thunk_' + \ 524 thunk_name = 'g_' + node.GetName().lower() + '_thunk_' + \
528 version 525 version
529 thunk_type = '_'.join((node.GetName(), version)) 526 thunk_type = '_'.join((node.GetName(), version))
530 version_list.append((thunk_type, thunk_name)) 527 version_list.append((thunk_type, thunk_name))
531 528
532 declare_line = 'const %s %s = {' % (thunk_type, thunk_name) 529 out.Write('const %s %s = {\n' % (thunk_type, thunk_name))
533 if len(declare_line) > 80:
534 declare_line = 'const %s\n %s = {' % (thunk_type, thunk_name)
535 out.Write('%s\n' % declare_line)
536 generated_functions = [] 530 generated_functions = []
537 members = node.GetListOf('Member') 531 members = node.GetListOf('Member')
538 for child in members: 532 for child in members:
539 rtype, name, arrays, args = cgen.GetComponents( 533 rtype, name, arrays, args = cgen.GetComponents(
540 child, build, 'return') 534 child, build, 'return')
541 if child.InReleases([build]): 535 if child.InReleases([build]):
542 if not _IsNewestMember(child, members, releases): 536 if not _IsNewestMember(child, members, releases):
543 version = child.GetVersion( 537 version = child.GetVersion(
544 child.first_release[build]).replace('.', '_') 538 child.first_release[build]).replace('.', '_')
545 name += '_' + version 539 name += '_' + version
546 generated_functions.append(name) 540 generated_functions.append(name)
547 out.Write(',\n'.join([' &%s' % f for f in generated_functions])) 541 out.Write(',\n'.join([' &%s' % f for f in generated_functions]))
548 out.Write('\n};\n\n') 542 out.Write('\n};\n\n')
549 543
550 out.Write('} // namespace\n') 544 out.Write('} // namespace\n')
551 out.Write('\n') 545 out.Write('\n')
552 for thunk_type, thunk_name in version_list: 546 for thunk_type, thunk_name in version_list:
553 thunk_decl = ('PPAPI_THUNK_EXPORT const %s* Get%s_Thunk() {\n' % 547 out.Write('PPAPI_THUNK_EXPORT const %s* Get%s_Thunk() {\n' %
554 (thunk_type, thunk_type)) 548 (thunk_type, thunk_type))
555 if len(thunk_decl) > 80:
556 thunk_decl = ('PPAPI_THUNK_EXPORT const %s*\n Get%s_Thunk() {\n' %
557 (thunk_type, thunk_type))
558 out.Write(thunk_decl)
559 out.Write(' return &%s;\n' % thunk_name) 549 out.Write(' return &%s;\n' % thunk_name)
560 out.Write('}\n') 550 out.Write('}\n')
561 out.Write('\n') 551 out.Write('\n')
562 out.Write('} // namespace thunk\n') 552 out.Write('} // namespace thunk\n')
563 out.Write('} // namespace ppapi\n') 553 out.Write('} // namespace ppapi\n')
564 554
565 555
566 tgen = TGen() 556 tgen = TGen()
567 557
568 558
(...skipping 13 matching lines...) Expand all
582 print "Golden file for M13-M15 failed." 572 print "Golden file for M13-M15 failed."
583 failed = 1 573 failed = 1
584 else: 574 else:
585 print "Golden file for M13-M15 passed." 575 print "Golden file for M13-M15 passed."
586 576
587 return failed 577 return failed
588 578
589 579
590 if __name__ == '__main__': 580 if __name__ == '__main__':
591 sys.exit(Main(sys.argv[1:])) 581 sys.exit(Main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « ppapi/generators/idl_outfile.py ('k') | ppapi/thunk/ppb_audio_buffer_thunk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698