Revert "Generate some of the C++ bindings for mojom tagged unions." This reverts commit 518d1f58c19aebdb0f09736a5f9016b8d9c4ea1b. The generated code does not compile on VC2013. See for example: http://build.chromium.org/p/tryserver.chromium.win/builders/win8_chromium_gn_rel/builds/141/steps/compile/logs/stdio BUG=None R=jamesr@chromium.org TBR=azani@chromium.org Review URL: https://codereview.chromium.org/844433003
diff --git a/mojo/public/cpp/bindings/tests/BUILD.gn b/mojo/public/cpp/bindings/tests/BUILD.gn index b267e4e..0051270 100644 --- a/mojo/public/cpp/bindings/tests/BUILD.gn +++ b/mojo/public/cpp/bindings/tests/BUILD.gn
@@ -24,7 +24,6 @@ "string_unittest.cc", "struct_unittest.cc", "type_conversion_unittest.cc", - "union_unittest.cc", "validation_unittest.cc", ]
diff --git a/mojo/public/interfaces/bindings/tests/BUILD.gn b/mojo/public/interfaces/bindings/tests/BUILD.gn index f68b113..2b99728 100644 --- a/mojo/public/interfaces/bindings/tests/BUILD.gn +++ b/mojo/public/interfaces/bindings/tests/BUILD.gn
@@ -19,7 +19,6 @@ "sample_service.mojom", "serialization_test_structs.mojom", "test_structs.mojom", - "test_unions.mojom", "validation_test_interfaces.mojom", ] }
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl index d9a398a..116e86a 100644 --- a/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl +++ b/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl
@@ -32,11 +32,6 @@ class {{struct.name}}; {%- endfor %} -{#--- Wrapper forward declarations for unions #} -{% for union in unions %} -class {{union.name}}; -{%- endfor %} - namespace internal { {#--- Internal forward declarations #} @@ -44,10 +39,6 @@ class {{struct.name}}_Data; {%- endfor %} -{% for union in unions %} -class {{union.name}}_Data; -{%- endfor %} - #pragma pack(push, 1) {#--- Class declarations #} @@ -55,10 +46,6 @@ {% include "struct_declaration.tmpl" %} {%- endfor %} -{% for union in unions %} -{% include "union_declaration.tmpl" %} -{%- endfor %} - #pragma pack(pop) } // namespace internal
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module.cc.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module.cc.tmpl index 96fa4f9..1ddcc45 100644 --- a/mojo/public/tools/bindings/generators/cpp_templates/module.cc.tmpl +++ b/mojo/public/tools/bindings/generators/cpp_templates/module.cc.tmpl
@@ -24,7 +24,6 @@ #include "mojo/public/cpp/bindings/lib/string_serialization.h" #include "mojo/public/cpp/bindings/lib/validate_params.h" #include "mojo/public/cpp/bindings/lib/validation_errors.h" -#include "mojo/public/cpp/bindings/lib/union_accessor.h" #include "mojo/public/cpp/environment/logging.h" {%- for namespace in namespaces_as_array %} @@ -64,11 +63,6 @@ {%- include "struct_definition.tmpl" %} {%- endfor %} -{#--- Union definitions #} -{% for union in unions %} -{%- include "union_definition.tmpl" %} -{%- endfor %} - } // namespace internal {#--- Struct Constants #} @@ -83,11 +77,6 @@ {%- include "wrapper_class_definition.tmpl" %} {%- endfor %} -{#--- Union builder definitions #} -{%- for union in unions %} -{%- include "wrapper_union_class_definition.tmpl" %} -{%- endfor %} - {#--- Interface definitions #} {%- for interface in interfaces %} {%- include "interface_definition.tmpl" %} @@ -98,11 +87,6 @@ {%- include "struct_serialization_definition.tmpl" %} {%- endfor %} -{#--- Union Serialization Helpers #} -{%- for union in unions %} -{%- include "union_serialization_definition.tmpl" %} -{%- endfor %} - {%- for namespace in namespaces_as_array|reverse %} } // namespace {{namespace}} {%- endfor %}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl index 58a1e9f..3da6c32 100644 --- a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl +++ b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
@@ -53,16 +53,6 @@ {% endif %} {% endfor %} -{#--- Union Forward Declarations -#} -{% for union in unions %} -class {{union.name}}; -{% if union|should_inline %} -typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr; -{% else %} -typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr; -{% endif %} -{%- endfor %} - {#--- NOTE: Non-inlined structs may have pointers to inlined structs, so we #} {#--- need to fully define inlined structs ahead of the others. #} @@ -80,11 +70,6 @@ {% endif %} {%- endfor %} -{#--- Unions #} -{% for union in unions %} -{% include "wrapper_union_class_declaration.tmpl" %} -{%- endfor %} - {#--- Interfaces -#} {% for interface in interfaces %} {% include "interface_declaration.tmpl" %} @@ -110,18 +95,10 @@ {% include "interface_response_validator_declaration.tmpl" %} {%- endfor %} -{%- import "serialization_macros.tmpl" as serialization_macros %} {#--- Struct Serialization Helpers -#} {% if structs %} {% for struct in structs %} -{{ serialization_macros.declare_serialization(struct.name) }} -{%- endfor %} -{%- endif %} - -{#--- Union Serialization Helpers -#} -{% if unions %} -{% for union in unions %} -{{ serialization_macros.declare_serialization(union.name) }} +{% include "struct_serialization_declaration.tmpl" %} {%- endfor %} {%- endif %}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/serialization_macros.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/serialization_macros.tmpl deleted file mode 100644 index 2be038c..0000000 --- a/mojo/public/tools/bindings/generators/cpp_templates/serialization_macros.tmpl +++ /dev/null
@@ -1,7 +0,0 @@ -{%- macro declare_serialization(name) %} -size_t GetSerializedSize_(const {{name}}Ptr& input); -void Serialize_({{name}}Ptr input, mojo::internal::Buffer* buffer, - internal::{{name}}_Data** output); -void Deserialize_(internal::{{name}}_Data* input, - {{name}}Ptr* output); -{%- endmacro %}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl new file mode 100644 index 0000000..604be86 --- /dev/null +++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
@@ -0,0 +1,5 @@ +size_t GetSerializedSize_(const {{struct.name}}Ptr& input); +void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buffer, + internal::{{struct.name}}_Data** output); +void Deserialize_(internal::{{struct.name}}_Data* input, + {{struct.name}}Ptr* output);
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl deleted file mode 100644 index 5ff7172..0000000 --- a/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl +++ /dev/null
@@ -1,35 +0,0 @@ -{%- set class_name = union.name ~ "_Data" -%} -{%- set enum_name = union.name ~ "_Tag" -%} -{%- set union_name = union.name ~ "_Union" -%} - -class {{class_name}} { - public: - static {{class_name}}* New(mojo::internal::Buffer* buf); - - static bool Validate(const void* data, - mojo::internal::BoundsChecker* bounds_checker); - - enum class {{enum_name}} : uint64_t { -{% for field in union.fields %} - {{field.name|upper}}, -{%- endfor %} - }; - - union MOJO_ALIGNAS(8) {{union_name}} { -{% for field in union.fields %} - {{field.kind|cpp_field_type}} {{field.name}}; -{%- endfor %} - }; - - {{enum_name}} tag; - {{union_name}} data; - - void EncodePointersAndHandles(std::vector<mojo::Handle>* handles); - void DecodePointersAndHandles(std::vector<mojo::Handle>* handles); - - private: - {{class_name}}(); - ~{{class_name}}() = delete; -}; -static_assert(sizeof({{class_name}}) == 16, - "Bad sizeof({{class_name}})");
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl deleted file mode 100644 index ef18598..0000000 --- a/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl +++ /dev/null
@@ -1,26 +0,0 @@ -{%- set class_name = union.name ~ "_Data" %} - -// static -{{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { - return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); -} - -// static -bool {{class_name}}::Validate(const void* data, - mojo::internal::BoundsChecker* bounds_checker) { - // TODO(azani): Implement validation. - return true; -} - -{{class_name}}::{{class_name}}() { -} - -void {{class_name}}::EncodePointersAndHandles( - std::vector<mojo::Handle>* handles) { - // TODO(azani): Implement pointers and handles. -} - -void {{class_name}}::DecodePointersAndHandles( - std::vector<mojo::Handle>* handles) { - // TODO(azani): Implement pointers and handles. -}
diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py index 03c9b6c..34bba30 100644 --- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py +++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -283,9 +283,6 @@ return False return True -def ShouldInlineUnion(union): - return not all(not mojom.IsMoveOnlyKind(field.kind) for field in union.fields) - def GetArrayValidateParams(kind): if (not mojom.IsArrayKind(kind) and not mojom.IsMapKind(kind) and not mojom.IsStringKind(kind)): @@ -337,7 +334,6 @@ "get_pad": pack.GetPad, "has_callbacks": mojom.HasCallbacks, "should_inline": ShouldInlineStruct, - "should_inline_union": ShouldInlineUnion, "is_array_kind": mojom.IsArrayKind, "is_cloneable_kind": mojom.IsCloneableKind, "is_enum_kind": mojom.IsEnumKind, @@ -351,13 +347,11 @@ "is_string_kind": mojom.IsStringKind, "is_struct_kind": mojom.IsStructKind, "is_struct_with_handles": IsStructWithHandles, - "is_union_kind": mojom.IsUnionKind, "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, "struct_from_method": generator.GetStructFromMethod, "response_struct_from_method": generator.GetResponseStructFromMethod, "stylize_method": generator.StudlyCapsToCamel, "to_all_caps": generator.CamelCaseToAllCaps, - "under_to_camel": generator.UnderToCamel, } def GetJinjaExports(self): @@ -369,7 +363,6 @@ "kinds": self.module.kinds, "enums": self.module.enums, "structs": self.GetStructs(), - "unions": self.module.unions, "interfaces": self.module.interfaces, }
diff --git a/mojo/public/tools/bindings/mojom.gni b/mojo/public/tools/bindings/mojom.gni index 6e50df7..d267fc9 100644 --- a/mojo/public/tools/bindings/mojom.gni +++ b/mojo/public/tools/bindings/mojom.gni
@@ -61,18 +61,13 @@ "$generator_root/generators/cpp_templates/module.h.tmpl", "$generator_root/generators/cpp_templates/module-internal.h.tmpl", "$generator_root/generators/cpp_templates/params_definition.tmpl", - "$generator_root/generators/cpp_templates/serialization_macros.tmpl", "$generator_root/generators/cpp_templates/struct_declaration.tmpl", "$generator_root/generators/cpp_templates/struct_definition.tmpl", + "$generator_root/generators/cpp_templates/struct_serialization_declaration.tmpl", "$generator_root/generators/cpp_templates/struct_serialization_definition.tmpl", "$generator_root/generators/cpp_templates/struct_macros.tmpl", "$generator_root/generators/cpp_templates/wrapper_class_declaration.tmpl", "$generator_root/generators/cpp_templates/wrapper_class_definition.tmpl", - "$generator_root/generators/cpp_templates/union_declaration.tmpl", - "$generator_root/generators/cpp_templates/union_definition.tmpl", - "$generator_root/generators/cpp_templates/union_serialization_definition.tmpl", - "$generator_root/generators/cpp_templates/wrapper_union_class_declaration.tmpl", - "$generator_root/generators/cpp_templates/wrapper_union_class_definition.tmpl", "$generator_root/generators/dart_templates/enum_definition.tmpl", "$generator_root/generators/dart_templates/interface_definition.tmpl", "$generator_root/generators/dart_templates/module.lib.tmpl",
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/data.py b/mojo/public/tools/bindings/pylib/mojom/generate/data.py index fd8af7b..6d34a40 100644 --- a/mojo/public/tools/bindings/pylib/mojom/generate/data.py +++ b/mojo/public/tools/bindings/pylib/mojom/generate/data.py
@@ -384,7 +384,7 @@ module.structs = map( lambda struct: StructFromData(module, struct), data['structs']) module.unions = map( - lambda union: UnionFromData(module, union), data.get('unions', [])) + lambda union: UnionFromData(module, struct), data.get('unions', [])) module.interfaces = map( lambda interface: InterfaceFromData(module, interface), data['interfaces'])
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/generator.py b/mojo/public/tools/bindings/pylib/mojom/generate/generator.py index 8d02359..af14ead 100644 --- a/mojo/public/tools/bindings/pylib/mojom/generate/generator.py +++ b/mojo/public/tools/bindings/pylib/mojom/generate/generator.py
@@ -47,10 +47,6 @@ return '_'.join( word for word in re.split(r'([A-Z][^A-Z]+)', camel_case) if word).upper() -def UnderToCamel(under): - """Converts underscore_separated strings to CamelCase strings.""" - return ''.join(word.capitalize() for word in under.split('_')) - def WriteFile(contents, full_path): # Make sure the containing directory exists. full_dir = os.path.dirname(full_path)
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/module.py b/mojo/public/tools/bindings/pylib/mojom/generate/module.py index bfa5863..8e52924 100644 --- a/mojo/public/tools/bindings/pylib/mojom/generate/module.py +++ b/mojo/public/tools/bindings/pylib/mojom/generate/module.py
@@ -422,10 +422,6 @@ return isinstance(kind, Struct) -def IsUnionKind(kind): - return isinstance(kind, Union) - - def IsArrayKind(kind): return isinstance(kind, Array) @@ -456,7 +452,7 @@ def IsObjectKind(kind): return (IsStructKind(kind) or IsArrayKind(kind) or IsStringKind(kind) or - IsMapKind(kind) or IsUnionKind(kind)) + IsMapKind(kind)) def IsNonInterfaceHandleKind(kind): @@ -487,7 +483,7 @@ return True if IsArrayKind(kind): return ContainsHandles(kind.kind, visited_kinds) - if IsStructKind(kind) or IsUnionKind(kind): + if IsStructKind(kind): for field in kind.fields: if ContainsHandles(field.kind, visited_kinds): return True
diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/translate.py b/mojo/public/tools/bindings/pylib/mojom/parse/translate.py index aa34125..88bd269 100644 --- a/mojo/public/tools/bindings/pylib/mojom/parse/translate.py +++ b/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
@@ -152,7 +152,7 @@ _AttributeListToDict(tree.module.attribute_list) if tree.module else {} self.mojom['structs'] = \ _MapTreeForType(StructToDict, tree.definition_list, ast.Struct) - self.mojom['unions'] = \ + self.mojom['union'] = \ _MapTreeForType(UnionToDict, tree.definition_list, ast.Union) self.mojom['interfaces'] = \ _MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface)
diff --git a/mojo/public/tools/bindings/pylib/mojom_tests/generate/generator_unittest.py b/mojo/public/tools/bindings/pylib/mojom_tests/generate/generator_unittest.py deleted file mode 100644 index a684773..0000000 --- a/mojo/public/tools/bindings/pylib/mojom_tests/generate/generator_unittest.py +++ /dev/null
@@ -1,37 +0,0 @@ -# Copyright 2014 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import imp -import os.path -import sys -import unittest - -def _GetDirAbove(dirname): - """Returns the directory "above" this file containing |dirname| (which must - also be "above" this file).""" - path = os.path.abspath(__file__) - while True: - path, tail = os.path.split(path) - assert tail - if tail == dirname: - return path - -try: - imp.find_module("mojom") -except ImportError: - sys.path.append(os.path.join(_GetDirAbove("pylib"), "pylib")) -from mojom.generate import generator - - -class StringManipulationTest(unittest.TestCase): - """generator contains some string utilities, this tests only those.""" - - def testUnderToCamel(self): - """Tests UnderToCamel which converts underscore_separated to CamelCase.""" - self.assertEquals("CamelCase", generator.UnderToCamel("camel_case")) - self.assertEquals("CamelCase", generator.UnderToCamel("CAMEL_CASE")) - -if __name__ == "__main__": - unittest.main() -
diff --git a/mojo/public/tools/bindings/pylib/mojom_tests/parse/translate_unittest.py b/mojo/public/tools/bindings/pylib/mojom_tests/parse/translate_unittest.py index 35434ad..9f2d985 100644 --- a/mojo/public/tools/bindings/pylib/mojom_tests/parse/translate_unittest.py +++ b/mojo/public/tools/bindings/pylib/mojom_tests/parse/translate_unittest.py
@@ -58,7 +58,7 @@ {"kind": "i32", "name": "a", "ordinal": None}, {"kind": "s", "name": "b", "ordinal": None}]}] actual = translate.Translate(tree, "mojom_tree") - self.assertEquals(actual["unions"], expected) + self.assertEquals(actual["union"], expected) if __name__ == "__main__":