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

Unified Diff: mojo/public/tools/bindings/generators/mojom_dart_generator.py

Issue 1753013002: Mojom runtime type info: New implementation for Dart. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: No changes to sha1s 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/mojom_dart_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_dart_generator.py b/mojo/public/tools/bindings/generators/mojom_dart_generator.py
index 1ff635867b8695d23b1a817ba70664a3afd4e4d3..2bcd65123aa9a2005ef717366a73de741a7f0f9f 100644
--- a/mojo/public/tools/bindings/generators/mojom_dart_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_dart_generator.py
@@ -123,30 +123,6 @@ _kind_to_dart_decl_type = {
mojom.NULLABLE_STRING: "String"
}
-_kind_to_mojom_type = {
- mojom.BOOL: "bool",
- mojom.INT8: "int8",
- mojom.UINT8: "uint8",
- mojom.INT16: "int16",
- mojom.UINT16: "uint16",
- mojom.INT32: "int32",
- mojom.UINT32: "uint32",
- mojom.FLOAT: "float",
- mojom.HANDLE: "unspecified",
- mojom.DCPIPE: "dataPipeConsumer",
- mojom.DPPIPE: "dataPipeProducer",
- mojom.MSGPIPE: "messagePipe",
- mojom.SHAREDBUFFER: "sharedBuffer",
- mojom.NULLABLE_HANDLE: "unspecified",
- mojom.NULLABLE_DCPIPE: "dataPipeConsumer",
- mojom.NULLABLE_DPPIPE: "dataPipeProducer",
- mojom.NULLABLE_MSGPIPE: "messagePipe",
- mojom.NULLABLE_SHAREDBUFFER: "sharedBuffer",
- mojom.INT64: "int64",
- mojom.UINT64: "uint64",
- mojom.DOUBLE: "double"
-}
-
_spec_to_decode_method = {
mojom.BOOL.spec: 'decodeBool',
mojom.DCPIPE.spec: 'decodeConsumerHandle',
@@ -259,9 +235,6 @@ def DartDeclType(kind):
if mojom.IsEnumKind(kind):
return GetDartType(kind)
-def GetSimpleMojomTypeName(kind):
- return _kind_to_mojom_type[kind]
-
def NameToComponent(name):
# insert '_' between anything and a Title name (e.g, HTTPEntry2FooBar ->
# HTTP_Entry2_FooBar). Numbers terminate a string of lower-case characters.
@@ -485,6 +458,27 @@ def GetImportUri(module):
def RaiseHelper(msg):
raise Exception(msg)
+def GetSerializedRuntimeTypeInfoLiteral(module, enabled):
+ """ Constructs a string that represents a literal definition in Dart of
+ an array of bytes corresponding to |module.serialized_runtime_type_info|.
+
+ Args:
+ module: {mojom.Module} the module being processed.
+ enabled: {bool} Is this feature enabled.
+
+ Returns: A string of the form 'b0, b1, b2,...' where the 'bi' are
+ the decimal representation of the bytes of
+ |module.serialized_runtime_type_info| or the empty string if either
+ |enabled| is false or |module.serialized_runtime_type_info| is None.
+ Furthermore the returned string will have embedded newline characters inserted
+ every 1000 characters to make the generated source code more tractable.
+ """
+ if not enabled or not module.serialized_runtime_type_info:
+ return ''
+ return '%s' % ','.join('%s%d' %
+ ('\n' if index > 0 and index%1000 == 0 else '', b)
+ for index, b in enumerate(module.serialized_runtime_type_info))
+
class Generator(generator.Generator):
dart_filters = {
@@ -493,10 +487,6 @@ class Generator(generator.Generator):
'decode_method': DecodeMethod,
'default_value': DartDefaultValue,
'encode_method': EncodeMethod,
- 'fullidentifier': mojom.GetMojomTypeFullIdentifier,
- 'simple_mojom_type_name': GetSimpleMojomTypeName,
- 'mojom_type_name': mojom.GetMojomTypeName,
- 'mojom_type_identifier': mojom.GetMojomTypeIdentifier,
'is_imported_kind': IsImportedKind,
'is_array_kind': mojom.IsArrayKind,
'is_map_kind': mojom.IsMapKind,
@@ -545,6 +535,9 @@ class Generator(generator.Generator):
"interfaces": self.GetInterfaces(),
"imported_interfaces": self.GetImportedInterfaces(),
"imported_from": self.ImportedFrom(),
+ "serialized_runtime_type_info_literal" : (
+ GetSerializedRuntimeTypeInfoLiteral(self.module,
+ self.should_gen_mojom_types)),
"typepkg": '%s.' % _mojom_types_pkg_short,
"descpkg": '%s.' % _service_describer_pkg_short,
"mojom_types_import": 'import \'%s\' as %s;' % \

Powered by Google App Engine
This is Rietveld 408576698