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

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

Issue 459873003: Mojom generator: move Is.*Kind() functions into module.py and use them from all mojom_.*_generator.… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix java compilation Created 6 years, 4 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_js_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_js_generator.py b/mojo/public/tools/bindings/generators/mojom_js_generator.py
index 15881cd090315fedf62c376b2e0fb67fc50297b1..3e2f1c888ac97d4c0c45e2bd50f4d94be36a4258 100644
--- a/mojo/public/tools/bindings/generators/mojom_js_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_js_generator.py
@@ -10,42 +10,48 @@ import mojom.generate.pack as pack
from mojom.generate.template_expander import UseJinja
_kind_to_javascript_default_value = {
- mojom.BOOL: "false",
- mojom.INT8: "0",
- mojom.UINT8: "0",
- mojom.INT16: "0",
- mojom.UINT16: "0",
- mojom.INT32: "0",
- mojom.UINT32: "0",
- mojom.FLOAT: "0",
- mojom.HANDLE: "null",
- mojom.DCPIPE: "null",
- mojom.DPPIPE: "null",
- mojom.MSGPIPE: "null",
- mojom.SHAREDBUFFER: "null",
- mojom.INT64: "0",
- mojom.UINT64: "0",
- mojom.DOUBLE: "0",
- mojom.STRING: '""',
+ mojom.BOOL: "false",
+ mojom.INT8: "0",
+ mojom.UINT8: "0",
+ mojom.INT16: "0",
+ mojom.UINT16: "0",
+ mojom.INT32: "0",
+ mojom.UINT32: "0",
+ mojom.FLOAT: "0",
+ mojom.HANDLE: "null",
+ mojom.DCPIPE: "null",
+ mojom.DPPIPE: "null",
+ mojom.MSGPIPE: "null",
+ mojom.SHAREDBUFFER: "null",
+ mojom.NULLABLE_HANDLE: "null",
+ mojom.NULLABLE_DCPIPE: "null",
+ mojom.NULLABLE_DPPIPE: "null",
+ mojom.NULLABLE_MSGPIPE: "null",
+ mojom.NULLABLE_SHAREDBUFFER: "null",
+ mojom.INT64: "0",
+ mojom.UINT64: "0",
+ mojom.DOUBLE: "0",
+ mojom.STRING: '""',
+ mojom.NULLABLE_STRING: '""'
}
def JavaScriptDefaultValue(field):
if field.default:
- if isinstance(field.kind, mojom.Struct):
+ if mojom.IsStructKind(field.kind):
assert field.default == "default"
return "new %s()" % JavascriptType(field.kind)
return ExpressionToText(field.default)
if field.kind in mojom.PRIMITIVES:
return _kind_to_javascript_default_value[field.kind]
- if isinstance(field.kind, mojom.Struct):
+ if mojom.IsStructKind(field.kind):
return "null"
- if isinstance(field.kind, mojom.Array):
+ if mojom.IsArrayKind(field.kind):
return "null"
- if isinstance(field.kind, mojom.Interface) or \
- isinstance(field.kind, mojom.InterfaceRequest):
+ if mojom.IsInterfaceKind(field.kind) or \
+ mojom.IsInterfaceRequestKind(field.kind):
return _kind_to_javascript_default_value[mojom.MSGPIPE]
- if isinstance(field.kind, mojom.Enum):
+ if mojom.IsEnumKind(field.kind):
return "0"
@@ -60,39 +66,44 @@ def JavaScriptPayloadSize(packed):
_kind_to_codec_type = {
- mojom.BOOL: "codec.Uint8",
- mojom.INT8: "codec.Int8",
- mojom.UINT8: "codec.Uint8",
- mojom.INT16: "codec.Int16",
- mojom.UINT16: "codec.Uint16",
- mojom.INT32: "codec.Int32",
- mojom.UINT32: "codec.Uint32",
- mojom.FLOAT: "codec.Float",
- mojom.HANDLE: "codec.Handle",
- mojom.DCPIPE: "codec.Handle",
- mojom.DPPIPE: "codec.Handle",
- mojom.MSGPIPE: "codec.Handle",
- mojom.SHAREDBUFFER: "codec.Handle",
- mojom.INT64: "codec.Int64",
- mojom.UINT64: "codec.Uint64",
- mojom.DOUBLE: "codec.Double",
- mojom.STRING: "codec.String",
+ mojom.BOOL: "codec.Uint8",
+ mojom.INT8: "codec.Int8",
+ mojom.UINT8: "codec.Uint8",
+ mojom.INT16: "codec.Int16",
+ mojom.UINT16: "codec.Uint16",
+ mojom.INT32: "codec.Int32",
+ mojom.UINT32: "codec.Uint32",
+ mojom.FLOAT: "codec.Float",
+ mojom.HANDLE: "codec.Handle",
+ mojom.DCPIPE: "codec.Handle",
+ mojom.DPPIPE: "codec.Handle",
+ mojom.MSGPIPE: "codec.Handle",
+ mojom.SHAREDBUFFER: "codec.Handle",
+ mojom.NULLABLE_HANDLE: "codec.Handle",
+ mojom.NULLABLE_DCPIPE: "codec.Handle",
+ mojom.NULLABLE_DPPIPE: "codec.Handle",
+ mojom.NULLABLE_MSGPIPE: "codec.Handle",
+ mojom.NULLABLE_SHAREDBUFFER: "codec.Handle",
+ mojom.INT64: "codec.Int64",
+ mojom.UINT64: "codec.Uint64",
+ mojom.DOUBLE: "codec.Double",
+ mojom.STRING: "codec.String",
+ mojom.NULLABLE_STRING: "codec.String",
}
def CodecType(kind):
if kind in mojom.PRIMITIVES:
return _kind_to_codec_type[kind]
- if isinstance(kind, mojom.Struct):
+ if mojom.IsStructKind(kind):
return "new codec.PointerTo(%s)" % CodecType(kind.name)
- if isinstance(kind, mojom.Array) and kind.kind == mojom.BOOL:
+ if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
return "new codec.ArrayOfBoolArrayPointers()"
- if isinstance(kind, mojom.Array):
+ if mojom.IsArrayKind(kind):
return "new codec.ArrayOf(%s)" % CodecType(kind.kind)
- if isinstance(kind, mojom.Interface) or \
- isinstance(kind, mojom.InterfaceRequest):
+ if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
return CodecType(mojom.MSGPIPE)
- if isinstance(kind, mojom.Enum):
+ if mojom.IsEnumKind(kind):
return _kind_to_codec_type[mojom.INT32]
return kind
@@ -100,32 +111,30 @@ def CodecType(kind):
def JavaScriptDecodeSnippet(kind):
if kind in mojom.PRIMITIVES:
return "decodeStruct(%s)" % CodecType(kind)
- if isinstance(kind, mojom.Struct):
+ if mojom.IsStructKind(kind):
return "decodeStructPointer(%s)" % CodecType(kind.name)
- if isinstance(kind, mojom.Array) and kind.kind == mojom.BOOL:
+ if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
return "decodeBoolArrayPointer()"
- if isinstance(kind, mojom.Array):
+ if mojom.IsArrayKind(kind):
return "decodeArrayPointer(%s)" % CodecType(kind.kind)
- if isinstance(kind, mojom.Interface) or \
- isinstance(kind, mojom.InterfaceRequest):
+ if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
return JavaScriptDecodeSnippet(mojom.MSGPIPE)
- if isinstance(kind, mojom.Enum):
+ if mojom.IsEnumKind(kind):
return JavaScriptDecodeSnippet(mojom.INT32)
def JavaScriptEncodeSnippet(kind):
if kind in mojom.PRIMITIVES:
return "encodeStruct(%s, " % CodecType(kind)
- if isinstance(kind, mojom.Struct):
+ if mojom.IsStructKind(kind):
return "encodeStructPointer(%s, " % CodecType(kind.name)
- if isinstance(kind, mojom.Array) and kind.kind == mojom.BOOL:
+ if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
return "encodeBoolArrayPointer(";
- if isinstance(kind, (mojom.Array, mojom.FixedArray)):
+ if mojom.IsAnyArrayKind(kind):
return "encodeArrayPointer(%s, " % CodecType(kind.kind)
- if isinstance(kind, mojom.Interface) or \
- isinstance(kind, mojom.InterfaceRequest):
+ if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
return JavaScriptEncodeSnippet(mojom.MSGPIPE)
- if isinstance(kind, mojom.Enum):
+ if mojom.IsEnumKind(kind):
return JavaScriptEncodeSnippet(mojom.INT32)

Powered by Google App Engine
This is Rietveld 408576698