Title: [204739] trunk/Source/WebKit2
Revision
204739
Author
[email protected]
Date
2016-08-22 14:31:55 -0700 (Mon, 22 Aug 2016)

Log Message

Simplify the generated message structs
https://bugs.webkit.org/show_bug.cgi?id=161057

Reviewed by Geoffrey Garen.

Use a class template to transform the Reply and Argument tuple types for encoding/decoding
instead of generating them for each message.

* Platform/IPC/HandleMessage.h:
(IPC::handleMessage):
(IPC::handleMessageDelayed):
* Scripts/webkit/messages.py:
(reply_type):
(message_to_struct_declaration):
(decode_type): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (204738 => 204739)


--- trunk/Source/WebKit2/ChangeLog	2016-08-22 21:21:57 UTC (rev 204738)
+++ trunk/Source/WebKit2/ChangeLog	2016-08-22 21:31:55 UTC (rev 204739)
@@ -1,3 +1,21 @@
+2016-08-22  Anders Carlsson  <[email protected]>
+
+        Simplify the generated message structs
+        https://bugs.webkit.org/show_bug.cgi?id=161057
+
+        Reviewed by Geoffrey Garen.
+
+        Use a class template to transform the Reply and Argument tuple types for encoding/decoding
+        instead of generating them for each message.
+
+        * Platform/IPC/HandleMessage.h:
+        (IPC::handleMessage):
+        (IPC::handleMessageDelayed):
+        * Scripts/webkit/messages.py:
+        (reply_type):
+        (message_to_struct_declaration):
+        (decode_type): Deleted.
+
 2016-08-19  Anders Carlsson  <[email protected]>
 
         Remove MessageRecorder

Modified: trunk/Source/WebKit2/Platform/IPC/HandleMessage.h (204738 => 204739)


--- trunk/Source/WebKit2/Platform/IPC/HandleMessage.h	2016-08-22 21:21:57 UTC (rev 204738)
+++ trunk/Source/WebKit2/Platform/IPC/HandleMessage.h	2016-08-22 21:31:55 UTC (rev 204739)
@@ -80,10 +80,20 @@
 
 // Main dispatch functions
 
+template<typename T>
+struct CodingType {
+    typedef std::remove_const_t<std::remove_reference_t<T>> Type;
+};
+
+template<typename... Ts>
+struct CodingType<std::tuple<Ts...>> {
+    typedef std::tuple<typename CodingType<Ts>::Type...> Type;
+};
+
 template<typename T, typename C, typename MF>
 void handleMessage(Decoder& decoder, C* object, MF function)
 {
-    typename T::DecodeType arguments;
+    typename CodingType<typename T::Arguments>::Type arguments;
     if (!decoder.decode(arguments)) {
         ASSERT(decoder.isInvalid());
         return;
@@ -95,13 +105,13 @@
 template<typename T, typename C, typename MF>
 void handleMessage(Decoder& decoder, Encoder& replyEncoder, C* object, MF function)
 {
-    typename T::DecodeType arguments;
+    typename CodingType<typename T::Arguments>::Type arguments;
     if (!decoder.decode(arguments)) {
         ASSERT(decoder.isInvalid());
         return;
     }
 
-    typename T::Reply::ValueType replyArguments;
+    typename CodingType<typename T::Reply>::Type replyArguments;
     callMemberFunction(WTFMove(arguments), replyArguments, object, function);
     replyEncoder << replyArguments;
 }
@@ -109,13 +119,13 @@
 template<typename T, typename C, typename MF>
 void handleMessage(Connection& connection, Decoder& decoder, Encoder& replyEncoder, C* object, MF function)
 {
-    typename T::DecodeType arguments;
+    typename CodingType<typename T::Arguments>::Type arguments;
     if (!decoder.decode(arguments)) {
         ASSERT(decoder.isInvalid());
         return;
     }
 
-    typename T::Reply::ValueType replyArguments;
+    typename CodingType<typename T::Reply>::Type replyArguments;
     callMemberFunction(connection, WTFMove(arguments), replyArguments, object, function);
     replyEncoder << replyArguments;
 }
@@ -123,7 +133,7 @@
 template<typename T, typename C, typename MF>
 void handleMessage(Connection& connection, Decoder& decoder, C* object, MF function)
 {
-    typename T::DecodeType arguments;
+    typename CodingType<typename T::Arguments>::Type arguments;
     if (!decoder.decode(arguments)) {
         ASSERT(decoder.isInvalid());
         return;
@@ -134,7 +144,7 @@
 template<typename T, typename C, typename MF>
 void handleMessageDelayed(Connection& connection, Decoder& decoder, std::unique_ptr<Encoder>& replyEncoder, C* object, MF function)
 {
-    typename T::DecodeType arguments;
+    typename CodingType<typename T::Arguments>::Type arguments;
     if (!decoder.decode(arguments)) {
         ASSERT(decoder.isInvalid());
         return;

Modified: trunk/Source/WebKit2/Scripts/webkit/messages.py (204738 => 204739)


--- trunk/Source/WebKit2/Scripts/webkit/messages.py	2016-08-22 21:21:57 UTC (rev 204738)
+++ trunk/Source/WebKit2/Scripts/webkit/messages.py	2016-08-22 21:31:55 UTC (rev 204739)
@@ -97,19 +97,15 @@
 
 
 def reply_type(message):
-    return 'IPC::Arguments<%s>' % (', '.join(reply_parameter_type(parameter.type) for parameter in message.reply_parameters))
+    return 'std::tuple<%s>' % (', '.join(reply_parameter_type(parameter.type) for parameter in message.reply_parameters))
 
 
-def decode_type(message):
-    return 'std::tuple<%s>' % ', '.join(parameter.type for parameter in message.parameters)
-
-
 def message_to_struct_declaration(message):
     result = []
     function_parameters = [(function_parameter_type(x.type), x.name) for x in message.parameters]
     result.append('class %s {\n' % message.name)
     result.append('public:\n')
-    result.append('    typedef %s DecodeType;\n' % decode_type(message))
+    result.append('    typedef %s Arguments;\n' % arguments_type(message))
     result.append('\n')
     result.append('    static IPC::StringReference receiverName() { return messageReceiverName(); }\n')
     result.append('    static IPC::StringReference name() { return IPC::StringReference("%s"); }\n' % message.name)
@@ -136,13 +132,13 @@
         result.append('\n        : m_arguments(%s)\n' % ', '.join([x[1] for x in function_parameters]))
         result.append('    {\n')
         result.append('    }\n\n')
-    result.append('    const %s& arguments() const\n' % arguments_type(message))
+    result.append('    const Arguments& arguments() const\n')
     result.append('    {\n')
     result.append('        return m_arguments;\n')
     result.append('    }\n')
     result.append('\n')
     result.append('private:\n')
-    result.append('    %s m_arguments;\n' % arguments_type(message))
+    result.append('    Arguments m_arguments;\n')
     result.append('};\n')
     return surround_in_condition(''.join(result), message.condition)
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to