OLD | NEW |
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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 out = '%s\n%s\n} %s;\n' % (out, ',\n'.join(enumlist), name) | 391 out = '%s\n%s\n} %s;\n' % (out, ',\n'.join(enumlist), name) |
392 return out | 392 return out |
393 | 393 |
394 def DefineMember(self, node, releases, prefix='', comment=False): | 394 def DefineMember(self, node, releases, prefix='', comment=False): |
395 release = releases[0] | 395 release = releases[0] |
396 self.LogEnter('DefineMember %s' % node) | 396 self.LogEnter('DefineMember %s' % node) |
397 out = '%s;' % self.GetSignature(node, release, 'store', '', True) | 397 out = '%s;' % self.GetSignature(node, release, 'store', '', True) |
398 self.LogExit('Exit DefineMember') | 398 self.LogExit('Exit DefineMember') |
399 return out | 399 return out |
400 | 400 |
401 # Define a Struct. | 401 def DefineStructInternals(self, node, release, suffix='', comment=True): |
402 def DefineStruct(self, node, releases, prefix='', comment=False): | |
403 out = '' | 402 out = '' |
404 | |
405 self.LogEnter('DefineStruct %s' % node) | |
406 if node.GetProperty('union'): | 403 if node.GetProperty('union'): |
407 out += 'union %s%s {\n' % (prefix, node.GetName()) | 404 out += 'union %s%s {\n' % (node.GetName(), suffix) |
408 else: | 405 else: |
409 out += 'struct %s%s {\n' % (prefix, node.GetName()) | 406 out += 'struct %s%s {\n' % (node.GetName(), suffix) |
410 | 407 |
411 # Generate Member Functions | 408 # Generate Member Functions |
412 members = [] | 409 members = [] |
413 for child in node.GetListOf('Member'): | 410 for child in node.GetListOf('Member'): |
414 member = self.Define(child, releases, tabs=1, comment=comment) | 411 member = self.Define(child, [release], tabs=1, comment=comment) |
415 if not member: | 412 if not member: |
416 continue | 413 continue |
417 members.append(member) | 414 members.append(member) |
418 out += '%s\n};\n' % '\n'.join(members) | 415 out += '%s\n};\n' % '\n'.join(members) |
| 416 return out |
| 417 |
| 418 |
| 419 def DefineStruct(self, node, releases, prefix='', comment=False): |
| 420 self.LogEnter('DefineStruct %s' % node) |
| 421 out = '' |
| 422 build_list = node.GetUniqueReleases(releases) |
| 423 |
| 424 # Build the most recent one with comments |
| 425 out = self.DefineStructInternals(node, build_list[-1], comment=True) |
| 426 |
| 427 # Build the rest without comments and with the version number appended |
| 428 for rel in build_list[0:-1]: |
| 429 ver_num = node.GetVersion(rel) |
| 430 ver = ("_%s" % ver_num).replace('.', '_') |
| 431 out += '\n' + self.DefineStructInternals(node, rel, suffix=ver, |
| 432 comment=False) |
| 433 |
419 self.LogExit('Exit DefineStruct') | 434 self.LogExit('Exit DefineStruct') |
420 return out | 435 return out |
421 | 436 |
| 437 |
422 # | 438 # |
423 # Copyright and Comment | 439 # Copyright and Comment |
424 # | 440 # |
425 # Generate a comment or copyright block | 441 # Generate a comment or copyright block |
426 # | 442 # |
427 def Copyright(self, node, tabs=0): | 443 def Copyright(self, node, tabs=0): |
428 lines = node.GetName().split('\n') | 444 lines = node.GetName().split('\n') |
429 return CommentLines(lines, tabs) | 445 return CommentLines(lines, tabs) |
430 | 446 |
431 | 447 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 print 'Skipping %s' % f.GetName() | 561 print 'Skipping %s' % f.GetName() |
546 continue | 562 continue |
547 print DefineDepends(node) | 563 print DefineDepends(node) |
548 for node in f.GetChildren()[2:]: | 564 for node in f.GetChildren()[2:]: |
549 print Define(node, comment=True, prefix='tst_') | 565 print Define(node, comment=True, prefix='tst_') |
550 | 566 |
551 | 567 |
552 if __name__ == '__main__': | 568 if __name__ == '__main__': |
553 sys.exit(Main(sys.argv[1:])) | 569 sys.exit(Main(sys.argv[1:])) |
554 | 570 |
OLD | NEW |