Title: [95300] trunk/Source/WebKit2
Revision
95300
Author
aro...@apple.com
Date
2011-09-16 09:58:38 -0700 (Fri, 16 Sep 2011)

Log Message

Add support for attributes on message parameters

Parameter attributes are specified as a space-separated list inside square brackets before
the parameter's type. WebKit2 doesn't use this, but other projects that use these scripts
would like to.

Fixes <http://webkit.org/b/68219> Would like a way to specify attributes on message
parameters

Reviewed by Sam Weinig.

* Scripts/webkit2/messages_unittest.py: Added tests for parameter attributes.

* Scripts/webkit2/model.py:
(Parameter.__init__): Added a new attributes parameter, which is stored in the self.attributes
property.
(Parameter.has_attribute): Added. Returns true if this parameter has the given attribute.

* Scripts/webkit2/parser.py:
(parse): Moved attributes-parsing code from here...
(parse_attributes_string): ...to here.
(parse_parameters_string): Renamed from parse_parameter_string. Now also parses parameter
attributes.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (95299 => 95300)


--- trunk/Source/WebKit2/ChangeLog	2011-09-16 16:58:14 UTC (rev 95299)
+++ trunk/Source/WebKit2/ChangeLog	2011-09-16 16:58:38 UTC (rev 95300)
@@ -1,5 +1,31 @@
 2011-09-15  Adam Roben  <aro...@apple.com>
 
+        Add support for attributes on message parameters
+
+        Parameter attributes are specified as a space-separated list inside square brackets before
+        the parameter's type. WebKit2 doesn't use this, but other projects that use these scripts
+        would like to.
+
+        Fixes <http://webkit.org/b/68219> Would like a way to specify attributes on message
+        parameters
+
+        Reviewed by Sam Weinig.
+
+        * Scripts/webkit2/messages_unittest.py: Added tests for parameter attributes.
+
+        * Scripts/webkit2/model.py:
+        (Parameter.__init__): Added a new attributes parameter, which is stored in the self.attributes
+        property.
+        (Parameter.has_attribute): Added. Returns true if this parameter has the given attribute.
+
+        * Scripts/webkit2/parser.py:
+        (parse): Moved attributes-parsing code from here...
+        (parse_attributes_string): ...to here.
+        (parse_parameters_string): Renamed from parse_parameter_string. Now also parses parameter
+        attributes.
+
+2011-09-15  Adam Roben  <aro...@apple.com>
+
         Make WebKit2's message-generation model and parser scripts accessible to other projects
 
         We copy them into the build products directory so other projects can find them.

Modified: trunk/Source/WebKit2/Scripts/webkit2/messages_unittest.py (95299 => 95300)


--- trunk/Source/WebKit2/Scripts/webkit2/messages_unittest.py	2011-09-16 16:58:14 UTC (rev 95299)
+++ trunk/Source/WebKit2/Scripts/webkit2/messages_unittest.py	2011-09-16 16:58:38 UTC (rev 95300)
@@ -72,6 +72,8 @@
     TestMultipleAttributes() -> () DispatchOnConnectionQueue Delayed
     TestConnectionQueue(uint64_t pluginID) DispatchOnConnectionQueue
 
+    TestParameterAttributes([AttributeOne AttributeTwo] uint64_t foo, double bar, [AttributeThree] double baz)
+
 #if PLATFORM(MAC)
     DidCreateWebProcessConnection(CoreIPC::MachPort connectionIdentifier)
 #endif
@@ -204,6 +206,15 @@
             'conditions': (None),
         },
         {
+            'name': 'TestParameterAttributes',
+            'parameters': (
+                ('uint64_t', 'foo', ('AttributeOne', 'AttributeTwo')),
+                ('double', 'bar'),
+                ('double', 'baz', ('AttributeThree',)),
+            ),
+            'conditions': (None),
+        },
+        {
             'name': 'DidCreateWebProcessConnection',
             'parameters': (
                 ('CoreIPC::MachPort', 'connectionIdentifier'),
@@ -248,8 +259,15 @@
         self.assertEquals(message.name, expected_message['name'])
         self.assertEquals(len(message.parameters), len(expected_message['parameters']))
         for index, parameter in enumerate(message.parameters):
-            self.assertEquals(parameter.type, expected_message['parameters'][index][0])
-            self.assertEquals(parameter.name, expected_message['parameters'][index][1])
+            expected_parameter = expected_message['parameters'][index]
+            self.assertEquals(parameter.type, expected_parameter[0])
+            self.assertEquals(parameter.name, expected_parameter[1])
+            if len(expected_parameter) > 2:
+                self.assertEquals(parameter.attributes, frozenset(expected_parameter[2]))
+                for attribute in expected_parameter[2]:
+                    self.assertTrue(parameter.has_attribute(attribute))
+            else:
+                self.assertEquals(parameter.attributes, frozenset())
         if message.reply_parameters != None:
             for index, parameter in enumerate(message.reply_parameters):
                 self.assertEquals(parameter.type, expected_message['reply_parameters'][index][0])
@@ -340,6 +358,7 @@
     GetPluginProcessConnectionID,
     TestMultipleAttributesID,
     TestConnectionQueueID,
+    TestParameterAttributesID,
 #if PLATFORM(MAC)
     DidCreateWebProcessConnectionID,
 #endif
@@ -492,6 +511,15 @@
     }
 };
 
+struct TestParameterAttributes : CoreIPC::Arguments3<uint64_t, double, double> {
+    static const Kind messageID = TestParameterAttributesID;
+    typedef CoreIPC::Arguments3<uint64_t, double, double> DecodeType;
+    TestParameterAttributes(uint64_t foo, double bar, double baz)
+        : CoreIPC::Arguments3<uint64_t, double, double>(foo, bar, baz)
+    {
+    }
+};
+
 #if PLATFORM(MAC)
 struct DidCreateWebProcessConnection : CoreIPC::Arguments1<const CoreIPC::MachPort&> {
     static const Kind messageID = DidCreateWebProcessConnectionID;
@@ -701,6 +729,9 @@
     case Messages::WebPage::SendIntsID:
         CoreIPC::handleMessage<Messages::WebPage::SendInts>(arguments, this, &WebPage::sendInts);
         return;
+    case Messages::WebPage::TestParameterAttributesID:
+        CoreIPC::handleMessage<Messages::WebPage::TestParameterAttributes>(arguments, this, &WebPage::testParameterAttributes);
+        return;
 #if PLATFORM(MAC)
     case Messages::WebPage::DidCreateWebProcessConnectionID:
         CoreIPC::handleMessage<Messages::WebPage::DidCreateWebProcessConnection>(arguments, this, &WebPage::didCreateWebProcessConnection);

Modified: trunk/Source/WebKit2/Scripts/webkit2/model.py (95299 => 95300)


--- trunk/Source/WebKit2/Scripts/webkit2/model.py	2011-09-16 16:58:14 UTC (rev 95299)
+++ trunk/Source/WebKit2/Scripts/webkit2/model.py	2011-09-16 16:58:38 UTC (rev 95300)
@@ -50,7 +50,11 @@
 
 
 class Parameter(object):
-    def __init__(self, type, name, condition=None):
+    def __init__(self, type, name, attributes=None, condition=None):
         self.type = type
         self.name = name
+        self.attributes = frozenset(attributes or [])
         self.condition = condition
+
+    def has_attribute(self, attribute):
+        return attribute in self.attributes

Modified: trunk/Source/WebKit2/Scripts/webkit2/parser.py (95299 => 95300)


--- trunk/Source/WebKit2/Scripts/webkit2/parser.py	2011-09-16 16:58:14 UTC (rev 95299)
+++ trunk/Source/WebKit2/Scripts/webkit2/parser.py	2011-09-16 16:58:38 UTC (rev 95300)
@@ -48,19 +48,16 @@
         if match:
             name, parameters_string, reply_parameters_string, attributes_string = match.groups()
             if parameters_string:
-                parameters = parse_parameter_string(parameters_string)
+                parameters = parse_parameters_string(parameters_string)
                 for parameter in parameters:
                     parameter.condition = condition
             else:
                 parameters = []
 
-            if attributes_string:
-                attributes = frozenset(attributes_string.split())
-            else:
-                attributes = None
+            attributes = parse_attributes_string(attributes_string)
 
             if reply_parameters_string:
-                reply_parameters = parse_parameter_string(reply_parameters_string)
+                reply_parameters = parse_parameters_string(reply_parameters_string)
                 for reply_parameter in reply_parameters:
                     reply_parameter.condition = condition
             elif reply_parameters_string == '':
@@ -72,5 +69,17 @@
     return model.MessageReceiver(destination, messages, master_condition)
 
 
-def parse_parameter_string(parameter_string):
-    return [model.Parameter(*type_and_name.rsplit(' ', 1)) for type_and_name in parameter_string.split(', ')]
+def parse_attributes_string(attributes_string):
+    if not attributes_string:
+        return None
+    return attributes_string.split()
+
+
+def parse_parameters_string(parameters_string):
+    parameters = []
+    for parameter_string in parameters_string.split(', '):
+        match = re.search(r'\s*(?:\[(?P<attributes>.*?)\]\s+)?(?P<type_and_name>.*)', parameter_string)
+        attributes_string, type_and_name_string = match.group('attributes', 'type_and_name')
+        parameter_type, parameter_name = type_and_name_string.rsplit(' ', 1)
+        parameters.append(model.Parameter(type=parameter_type, name=parameter_name, attributes=parse_attributes_string(attributes_string)))
+    return parameters
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to