Allow enum guards to be generated from the replay json files
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jun 2014 10:10:51 +0000 (10:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jun 2014 10:10:51 +0000 (10:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133399

Patch by Zsolt Borbely <zsborbely.u-szeged@partner.samsung.com> on 2014-06-12
Reviewed by Csaba Osztrogon√°c.

* replay/scripts/CodeGeneratorReplayInputs.py:
(Type.__init__):
(InputsModel.parse_type_with_framework_name):
(Generator.generate_header):
(Generator.generate_implementation):
* replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.cpp: Added.
(Test::HandleWheelEvent::HandleWheelEvent):
(Test::HandleWheelEvent::~HandleWheelEvent):
(JSC::InputTraits<Test::HandleWheelEvent>::type):
(JSC::InputTraits<Test::HandleWheelEvent>::encode):
(JSC::InputTraits<Test::HandleWheelEvent>::decode):
(JSC::EncodingTraits<WebCore::PlatformWheelEventPhase>::encodeValue):
(JSC::EncodingTraits<WebCore::PlatformWheelEventPhase>::decodeValue):
* replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.h: Added.
(JSC::InputTraits<Test::HandleWheelEvent>::queue):
(Test::HandleWheelEvent::platformEvent):
* replay/scripts/tests/generate-enum-with-guard.json: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169889 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/replay/scripts/CodeGeneratorReplayInputs.py
Source/JavaScriptCore/replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.cpp [new file with mode: 0644]
Source/JavaScriptCore/replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.h [new file with mode: 0644]
Source/JavaScriptCore/replay/scripts/tests/generate-enum-with-guard.json [new file with mode: 0644]

index 6fa78ae..e7a97cf 100644 (file)
@@ -1,3 +1,28 @@
+2014-06-12  Zsolt Borbely  <zsborbely.u-szeged@partner.samsung.com>
+
+        Allow enum guards to be generated from the replay json files
+        https://bugs.webkit.org/show_bug.cgi?id=133399
+
+        Reviewed by Csaba Osztrogon√°c.
+
+        * replay/scripts/CodeGeneratorReplayInputs.py:
+        (Type.__init__):
+        (InputsModel.parse_type_with_framework_name):
+        (Generator.generate_header):
+        (Generator.generate_implementation):
+        * replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.cpp: Added.
+        (Test::HandleWheelEvent::HandleWheelEvent):
+        (Test::HandleWheelEvent::~HandleWheelEvent):
+        (JSC::InputTraits<Test::HandleWheelEvent>::type):
+        (JSC::InputTraits<Test::HandleWheelEvent>::encode):
+        (JSC::InputTraits<Test::HandleWheelEvent>::decode):
+        (JSC::EncodingTraits<WebCore::PlatformWheelEventPhase>::encodeValue):
+        (JSC::EncodingTraits<WebCore::PlatformWheelEventPhase>::decodeValue):
+        * replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.h: Added.
+        (JSC::InputTraits<Test::HandleWheelEvent>::queue):
+        (Test::HandleWheelEvent::platformEvent):
+        * replay/scripts/tests/generate-enum-with-guard.json: Added.
+
 2014-06-12  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix GTK+ build after r169823.
index a9a65cd..e6c82e2 100644 (file)
@@ -281,7 +281,7 @@ class TypeModes:
 
 
 class Type:
-    def __init__(self, name, mode, framework, header, enclosing_class, values, guard_values_map, underlying_storage, flags):
+    def __init__(self, name, mode, framework, header, enclosing_class, values, guard_values_map, underlying_storage, flags, guard=None):
         self._name = name
         self.mode = mode
         self.framework = framework
@@ -291,6 +291,7 @@ class Type:
         self.guard_values_map = guard_values_map
         self.underlying_storage = underlying_storage
         self._flags = flags
+        self.guard = guard
 
     def __eq__(self, other):
         return self.type_name() == other.type_name() and self.mode == other.mode
@@ -449,7 +450,8 @@ class InputsModel:
         guarded_enum_values = json.get('guarded_values', {})
         type_storage = json.get('storage')
         type_flags = json.get('flags', [])
-        _type = Type(type_name, type_mode, framework, header, enclosing_class, enum_values, guarded_enum_values, type_storage, type_flags)
+        guard = json.get('guard', None)
+        _type = Type(type_name, type_mode, framework, header, enclosing_class, enum_values, guarded_enum_values, type_storage, type_flags, guard)
         if _type.is_enum() or _type.is_enum_class():
             check_for_required_properties(['values'], json, 'enum')
             if not isinstance(json['values'], list) or len(_type.values) == 0:
@@ -597,7 +599,7 @@ class Generator:
             'inputForwardDeclarations': "\n".join([wrap_with_guard("class %s;", _input.guard) % _input.name for _input in self._model.inputs]),
             'inputClassDeclarations': "\n\n".join([self.generate_class_declaration(_input) for _input in self._model.inputs]),
             'inputTraitDeclarations': "\n\n".join([self.generate_input_trait_declaration(_input) for _input in self._model.inputs]),
-            'enumTraitDeclarations': "\n\n".join([self.generate_enum_trait_declaration(_type) for _type in self._model.enum_types()]),
+            'enumTraitDeclarations': "\n\n".join([wrap_with_guard(self.generate_enum_trait_declaration(_type), _type.guard) for _type in self._model.enum_types()]),
             'forEachMacro': self.generate_for_each_macro(),
         }
 
@@ -613,7 +615,7 @@ class Generator:
             'includes': self.generate_includes(defaults=self.setting('implIncludes'), includes_for_types=True),
             'inputClassImplementations': "\n\n".join([self.generate_class_implementation(_input) for _input in self._model.inputs]),
             'inputTraitImplementations': "\n\n".join([self.generate_input_trait_implementation(_input) for _input in self._model.inputs]),
-            'enumTraitImplementations': "\n\n".join([self.generate_enum_trait_implementation(_type) for _type in self._model.enum_types()]),
+            'enumTraitImplementations': "\n\n".join([wrap_with_guard(self.generate_enum_trait_implementation(_type), _type.guard) for _type in self._model.enum_types()]),
         }
 
         return Template(Templates.ImplementationSkeleton).substitute(template_arguments)
diff --git a/Source/JavaScriptCore/replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.cpp b/Source/JavaScriptCore/replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.cpp
new file mode 100644 (file)
index 0000000..9a6d84a
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from generate-enum-with-guard.json
+// by the script: JavaScriptCore/replay/scripts/CodeGeneratorReplayInputs.py
+
+#include "config.h"
+#include "generate-enum-with-guard.json-TestReplayInputs.h"
+
+#if ENABLE(WEB_REPLAY)
+#include "InternalNamespaceImplIncludeDummy.h"
+#include <platform/ExternalNamespaceImplIncludeDummy.h>
+#include <platform/PlatformWheelEvent.h>
+
+namespace Test {
+HandleWheelEvent::HandleWheelEvent(std::unique_ptr<PlatformWheelEvent> platformEvent)
+    : EventLoopInput<HandleWheelEvent>()
+    , m_platformEvent(std::move(platformEvent))
+{
+}
+
+HandleWheelEvent::~HandleWheelEvent()
+{
+}
+} // namespace Test
+
+namespace JSC {
+const AtomicString& InputTraits<Test::HandleWheelEvent>::type()
+{
+    static NeverDestroyed<const AtomicString> type("HandleWheelEvent", AtomicString::ConstructFromLiteral);
+    return type;
+}
+
+void InputTraits<Test::HandleWheelEvent>::encode(EncodedValue& encodedValue, const Test::HandleWheelEvent& input)
+{
+    encodedValue.put<WebCore::PlatformWheelEvent>(ASCIILiteral("platformEvent"), input.platformEvent());
+}
+
+bool InputTraits<Test::HandleWheelEvent>::decode(EncodedValue& encodedValue, std::unique_ptr<Test::HandleWheelEvent>& input)
+{
+    std::unique_ptr<WebCore::PlatformWheelEvent> platformEvent;
+    if (!encodedValue.get<WebCore::PlatformWheelEvent>(ASCIILiteral("platformEvent"), platformEvent))
+        return false;
+
+    input = std::make_unique<Test::HandleWheelEvent>(std::move(platformEvent));
+    return true;
+}
+#if ENABLE(DUMMY_FEATURE)
+EncodedValue EncodingTraits<WebCore::PlatformWheelEventPhase>::encodeValue(const WebCore::PlatformWheelEventPhase& enumValue)
+{
+    EncodedValue encodedValue = EncodedValue::createArray();
+    if (enumValue & WebCore::PlatformWheelEventPhaseNone) {
+        encodedValue.append<String>(ASCIILiteral("PlatformWheelEventPhaseNone"));
+        if (enumValue == WebCore::PlatformWheelEventPhaseNone)
+            return encodedValue;
+    }
+    return encodedValue;
+}
+
+bool EncodingTraits<WebCore::PlatformWheelEventPhase>::decodeValue(EncodedValue& encodedValue, WebCore::PlatformWheelEventPhase& enumValue)
+{
+    Vector<String> enumStrings;
+    if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings))
+        return false;
+
+    for (String enumString : enumStrings) {
+        if (enumString == "PlatformWheelEventPhaseNone")
+            enumValue = static_cast<WebCore::PlatformWheelEventPhase>(enumValue | WebCore::PlatformWheelEventPhaseNone);
+    }
+
+    return true;
+}
+#endif // ENABLE(DUMMY_FEATURE)
+} // namespace JSC
+
+#endif // ENABLE(WEB_REPLAY)
diff --git a/Source/JavaScriptCore/replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.h b/Source/JavaScriptCore/replay/scripts/tests/expected/generate-enum-with-guard.json-TestReplayInputs.h
new file mode 100644 (file)
index 0000000..81826a6
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from generate-enum-with-guard.json
+// by the script: JavaScriptCore/replay/scripts/CodeGeneratorReplayInputs.py
+
+#ifndef generate_enum_with_guard_json_TestReplayInputs_h
+#define generate_enum_with_guard_json_TestReplayInputs_h
+
+#if ENABLE(WEB_REPLAY)
+#include "InternalNamespaceHeaderIncludeDummy.h"
+#include <platform/ExternalNamespaceHeaderIncludeDummy.h>
+
+namespace WebCore {
+class PlatformWheelEvent;
+enum PlatformWheelEventPhase : uint64_t;
+}
+
+
+namespace Test {
+class HandleWheelEvent;
+} // namespace Test
+
+namespace JSC {
+template<> struct InputTraits<Test::HandleWheelEvent> {
+    static InputQueue queue() { return InputQueue::EventLoopInput; }
+    static const AtomicString& type();
+
+    static void encode(JSC::EncodedValue&, const Test::HandleWheelEvent&);
+    static bool decode(JSC::EncodedValue&, std::unique_ptr<Test::HandleWheelEvent>&);
+};
+#if ENABLE(DUMMY_FEATURE)
+template<> struct EncodingTraits<WebCore::PlatformWheelEventPhase> {
+    typedef WebCore::PlatformWheelEventPhase DecodedType;
+
+    static EncodedValue encodeValue(const WebCore::PlatformWheelEventPhase& value);
+    static bool decodeValue(EncodedValue&, WebCore::PlatformWheelEventPhase& value);
+};
+#endif // ENABLE(DUMMY_FEATURE)
+} // namespace JSC
+
+namespace Test {
+class HandleWheelEvent : public EventLoopInput<HandleWheelEvent> {
+public:
+    HandleWheelEvent(std::unique_ptr<PlatformWheelEvent> platformEvent);
+    virtual ~HandleWheelEvent();
+
+    // EventLoopInput API
+    virtual void dispatch(ReplayController&) override final;
+    const PlatformWheelEvent& platformEvent() const { return *m_platformEvent; }
+private:
+    std::unique_ptr<PlatformWheelEvent> m_platformEvent;
+};
+} // namespace Test
+
+#define TEST_REPLAY_INPUT_NAMES_FOR_EACH(macro) \
+    macro(HandleWheelEvent) \
+    \
+// end of TEST_REPLAY_INPUT_NAMES_FOR_EACH
+
+#endif // ENABLE(WEB_REPLAY)
+
+#endif // generate-enum-with-guard.json-TestReplayInputs_h
diff --git a/Source/JavaScriptCore/replay/scripts/tests/generate-enum-with-guard.json b/Source/JavaScriptCore/replay/scripts/tests/generate-enum-with-guard.json
new file mode 100644 (file)
index 0000000..680e320
--- /dev/null
@@ -0,0 +1,31 @@
+{
+    "types": {
+        "Global": [
+            { "name": "uint64_t", "mode": "SCALAR" }
+        ],
+        "WebCore": [
+            {
+                "name": "PlatformWheelEvent", "mode": "OWNED",
+                "header": "platform/PlatformWheelEvent.h"
+            },
+            {
+                "name": "PlatformWheelEventPhase", "mode": "SCALAR", "storage": "uint64_t",
+                "flags": ["ENUM"],
+                "guard": "ENABLE(DUMMY_FEATURE)",
+                "values": ["PlatformWheelEventPhaseNone"],
+                "header": "platform/PlatformWheelEvent.h"
+            }
+        ]
+    },
+
+    "inputs": [
+        {
+            "name": "HandleWheelEvent",
+            "description": "",
+            "queue": "EVENT_LOOP",
+            "members": [
+                { "name": "platformEvent", "type": "PlatformWheelEvent" }
+            ]
+        }
+    ]
+}