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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/module.py

Issue 1539673003: Generate Mojom Types in Dart (Take 2) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Merge with master Created 4 years, 10 months 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
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_go_generator.py ('k') | 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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 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 # This module's classes provide an interface to mojo modules. Modules are 5 # This module's classes provide an interface to mojo modules. Modules are
6 # collections of interfaces and structs to be used by mojo ipc clients and 6 # collections of interfaces and structs to be used by mojo ipc clients and
7 # servers. 7 # servers.
8 # 8 #
9 # A simple interface would be created this way: 9 # A simple interface would be created this way:
10 # module = mojom.generate.module.Module('Foo') 10 # module = mojom.generate.module.Module('Foo')
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 def AddStruct(self, name, attributes=None): 453 def AddStruct(self, name, attributes=None):
454 struct = Struct(name, self, attributes) 454 struct = Struct(name, self, attributes)
455 self.structs.append(struct) 455 self.structs.append(struct)
456 return struct 456 return struct
457 457
458 def AddUnion(self, name, attributes=None): 458 def AddUnion(self, name, attributes=None):
459 union = Union(name, self, attributes) 459 union = Union(name, self, attributes)
460 self.unions.append(union) 460 self.unions.append(union)
461 return union 461 return union
462 462
463 def GetMojomTypeName(kind):
464 """Get the mojom type's name from its kind."""
465 # Note: InterfaceRequest's should use the Interface inside them.
466 if IsInterfaceRequestKind(kind):
467 return kind.kind.name
468 elif hasattr(kind, 'name'):
469 return kind.name
470 else:
471 # These kinds (e.g., simple kinds, maps, and arrays) lack names.
472 raise Exception('Unexpected kind: %s' % kind)
473
474 def GetPackageName(kind):
475 """Get the package name from the given kind's module."""
476 return kind.module.name.split('.')[0]
477
478 def GetMojomTypeIdentifier(kind):
479 """Get the mojom type's unique identifier from the kind's package and name."""
480 # Note: InterfaceRequest's should use the Interface inside them.
481 if hasattr(kind, 'module'):
482 package = GetPackageName(kind)
483 elif IsInterfaceRequestKind(kind):
484 package = GetPackageName(kind.kind)
485 else:
486 # These kinds (e.g., simple kinds and fields) lack identifiers.
487 raise Exception('Unexpected kind: %s' % kind)
488 return "%s_%s__" % (package, GetMojomTypeName(kind))
489
490
491 # Returns a string of the form package.path.TypeName - the full identifier
492 # for an element.
493 def GetMojomTypeFullIdentifier(kind, exported=True):
494 """Get the Full Identifier for a Mojom Type. Format: package.path.TypeName"""
495 return '%s.%s' % (kind.module.namespace, GetMojomTypeName(kind))
496
463 497
464 def IsBoolKind(kind): 498 def IsBoolKind(kind):
465 return kind.spec == BOOL.spec 499 return kind.spec == BOOL.spec
466 500
467 501
468 def IsFloatKind(kind): 502 def IsFloatKind(kind):
469 return kind.spec == FLOAT.spec 503 return kind.spec == FLOAT.spec
470 504
471 505
506 def IsDoubleKind(kind):
507 return kind.spec == DOUBLE.spec
508
509
472 def IsIntegralKind(kind): 510 def IsIntegralKind(kind):
473 return (kind.spec == BOOL.spec or 511 return (kind.spec == BOOL.spec or
474 kind.spec == INT8.spec or 512 kind.spec == INT8.spec or
475 kind.spec == INT16.spec or 513 kind.spec == INT16.spec or
476 kind.spec == INT32.spec or 514 kind.spec == INT32.spec or
477 kind.spec == INT64.spec or 515 kind.spec == INT64.spec or
478 kind.spec == UINT8.spec or 516 kind.spec == UINT8.spec or
479 kind.spec == UINT16.spec or 517 kind.spec == UINT16.spec or
480 kind.spec == UINT32.spec or 518 kind.spec == UINT32.spec or
481 kind.spec == UINT64.spec) 519 kind.spec == UINT64.spec)
482 520
521 def IsNumericalKind(kind):
522 return (IsBoolKind(kind) or
523 IsFloatKind(kind) or
524 IsDoubleKind(kind) or
525 IsIntegralKind(kind))
483 526
484 def IsStringKind(kind): 527 def IsStringKind(kind):
485 return kind.spec == STRING.spec or kind.spec == NULLABLE_STRING.spec 528 return kind.spec == STRING.spec or kind.spec == NULLABLE_STRING.spec
486 529
487 530
488 def IsGenericHandleKind(kind): 531 def IsGenericHandleKind(kind):
489 return kind.spec == HANDLE.spec or kind.spec == NULLABLE_HANDLE.spec 532 return kind.spec == HANDLE.spec or kind.spec == NULLABLE_HANDLE.spec
490 533
491 534
492 def IsDataPipeConsumerKind(kind): 535 def IsDataPipeConsumerKind(kind):
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 return False 631 return False
589 632
590 return not ContainsHandles(kind, set()) 633 return not ContainsHandles(kind, set())
591 634
592 635
593 def HasCallbacks(interface): 636 def HasCallbacks(interface):
594 for method in interface.methods: 637 for method in interface.methods:
595 if method.response_parameters != None: 638 if method.response_parameters != None:
596 return True 639 return True
597 return False 640 return False
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_go_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698