2011-09-15 Adam Roben <aroben@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 <aroben@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.
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
'conditions': (None),
},
{
+ 'name': 'TestParameterAttributes',
+ 'parameters': (
+ ('uint64_t', 'foo', ('AttributeOne', 'AttributeTwo')),
+ ('double', 'bar'),
+ ('double', 'baz', ('AttributeThree',)),
+ ),
+ 'conditions': (None),
+ },
+ {
'name': 'DidCreateWebProcessConnection',
'parameters': (
('CoreIPC::MachPort', 'connectionIdentifier'),
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])
GetPluginProcessConnectionID,
TestMultipleAttributesID,
TestConnectionQueueID,
+ TestParameterAttributesID,
#if PLATFORM(MAC)
DidCreateWebProcessConnectionID,
#endif
}
};
+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;
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);
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 == '':
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