Split some of the message-generation code into separate modules
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Sep 2011 16:57:50 +0000 (16:57 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Sep 2011 16:57:50 +0000 (16:57 +0000)
This is in preparation for making these modules scripts usable by other projects.

Fixes <http://webkit.org/b/68217> Model and parsing functionality for WebKit2's
message-generation scripts is trapped inside a much larger module

Reviewed by Darin Adler.

* DerivedSources.make:
* DerivedSources.pro:
* GNUmakefile.am:
* WebKit2.xcodeproj/project.pbxproj:
* win/WebKit2.vcproj:
* win/WebKit2Generated.vcproj:
Added new files.

* Scripts/webkit2/messages.py: Moved some code from here...

* Scripts/webkit2/model.py: Added.
* Scripts/webkit2/parser.py: Added.
...to here. MessageReceiver.parse was split out into a function in the new parser module.

* Scripts/webkit2/messages_unittest.py: Updated for renames.

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

Source/WebKit2/ChangeLog
Source/WebKit2/DerivedSources.make
Source/WebKit2/DerivedSources.pro
Source/WebKit2/GNUmakefile.am
Source/WebKit2/Scripts/webkit2/messages.py
Source/WebKit2/Scripts/webkit2/messages_unittest.py
Source/WebKit2/Scripts/webkit2/model.py [new file with mode: 0644]
Source/WebKit2/Scripts/webkit2/parser.py [new file with mode: 0644]
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/win/WebKit2.vcproj
Source/WebKit2/win/WebKit2Generated.vcproj

index 7dd7a20..d377b2f 100644 (file)
@@ -1,3 +1,30 @@
+2011-09-15  Adam Roben  <aroben@apple.com>
+
+        Split some of the message-generation code into separate modules
+
+        This is in preparation for making these modules scripts usable by other projects.
+
+        Fixes <http://webkit.org/b/68217> Model and parsing functionality for WebKit2's
+        message-generation scripts is trapped inside a much larger module
+
+        Reviewed by Darin Adler.
+
+        * DerivedSources.make:
+        * DerivedSources.pro:
+        * GNUmakefile.am:
+        * WebKit2.xcodeproj/project.pbxproj:
+        * win/WebKit2.vcproj:
+        * win/WebKit2Generated.vcproj:
+        Added new files.
+
+        * Scripts/webkit2/messages.py: Moved some code from here...
+
+        * Scripts/webkit2/model.py: Added.
+        * Scripts/webkit2/parser.py: Added.
+        ...to here. MessageReceiver.parse was split out into a function in the new parser module.
+
+        * Scripts/webkit2/messages_unittest.py: Updated for renames.
+
 2011-09-16  Martin Robinson  <mrobinson@igalia.com>
 
         [GTK] Disable WebKit2 by default in configure.ac, but enable it with build-webkit
index ca16771..4cd11ae 100644 (file)
@@ -86,6 +86,8 @@ SCRIPTS = \
     $(WebKit2)/Scripts/generate-messages-header.py \
     $(WebKit2)/Scripts/webkit2/__init__.py \
     $(WebKit2)/Scripts/webkit2/messages.py \
+    $(WebKit2)/Scripts/webkit2/model.py \
+    $(WebKit2)/Scripts/webkit2/parser.py \
 #
 
 .PHONY : all
index c4512c5..993db4b 100644 (file)
@@ -135,7 +135,9 @@ SCRIPTS = \
     $$PWD/Scripts/generate-message-receiver.py \
     $$PWD/Scripts/generate-messages-header.py \
     $$PWD/Scripts/webkit2/__init__.py \
-    $$PWD/Scripts/webkit2/messages.py
+    $$PWD/Scripts/webkit2/messages.py \
+    $$PWD/Scripts/webkit2/model.py \
+    $$PWD/Scripts/webkit2/parser.py
 
 message_header_generator.commands = $${PYTHON} $${SRC_ROOT_DIR}/Source/WebKit2/Scripts/generate-messages-header.py ${QMAKE_FILE_IN} > ${QMAKE_FILE_OUT}
 message_header_generator.input = MESSAGE_RECEIVERS
index 9fa8c4b..d850774 100644 (file)
@@ -949,7 +949,9 @@ message_gen_scripts = \
        $(WebKit2)/Scripts/generate-message-receiver.py \
        $(WebKit2)/Scripts/generate-messages-header.py \
        $(WebKit2)/Scripts/webkit2/__init__.py \
-       $(WebKit2)/Scripts/webkit2/messages.py
+       $(WebKit2)/Scripts/webkit2/messages.py \
+       $(WebKit2)/Scripts/webkit2/model.py \
+       $(WebKit2)/Scripts/webkit2/parser.py
 
 # Message header generation
 DerivedSources/WebKit2/%MessageReceiver.cpp: %.messages.in $(message_gen_scripts)
index ca24d06..b85da98 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 Apple Inc. All rights reserved.
+# Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import collections
-import itertools
 import re
 
+import parser
+
 
 DELAYED_ATTRIBUTE = 'Delayed'
 DISPATCH_ON_CONNECTION_QUEUE_ATTRIBUTE = 'DispatchOnConnectionQueue'
@@ -54,89 +55,6 @@ _license_header = """/*
 
 """
 
-class MessageReceiver(object):
-    def __init__(self, name, messages, condition):
-        self.name = name
-        self.messages = messages
-        self.condition = condition
-
-    def iterparameters(self):
-        return itertools.chain((parameter for message in self.messages for parameter in message.parameters),
-            (reply_parameter for message in self.messages if message.reply_parameters for reply_parameter in message.reply_parameters))
-
-    @classmethod
-    def parse(cls, file):
-        destination = None
-        messages = []
-        condition = None
-        master_condition = None
-        for line in file:
-            match = re.search(r'messages -> ([A-Za-z_0-9]+) {', line)
-            if match:
-                if condition:
-                    master_condition = condition
-                    condition = None
-                destination = match.group(1)
-                continue
-            if line.startswith('#'):
-                if line.startswith('#if '):
-                    condition = line.rstrip()[4:]
-                elif line.startswith('#endif'):
-                    condition = None
-                continue
-            match = re.search(r'([A-Za-z_0-9]+)\((.*?)\)(?:(?:\s+->\s+)\((.*?)\))?(?:\s+(.*))?', line)
-            if match:
-                name, parameters_string, reply_parameters_string, attributes_string = match.groups()
-                if parameters_string:
-                    parameters = parse_parameter_string(parameters_string)
-                    for parameter in parameters:
-                        parameter.condition = condition
-                else:
-                    parameters = []
-
-                if attributes_string:
-                    attributes = frozenset(attributes_string.split())
-                else:
-                    attributes = None
-
-                if reply_parameters_string:
-                    reply_parameters = parse_parameter_string(reply_parameters_string)
-                    for reply_parameter in reply_parameters:
-                        reply_parameter.condition = condition
-                elif reply_parameters_string == '':
-                    reply_parameters = []
-                else:
-                    reply_parameters = None
-
-                messages.append(Message(name, parameters, reply_parameters, attributes, condition))
-        return MessageReceiver(destination, messages, master_condition)
-
-
-class Message(object):
-    def __init__(self, name, parameters, reply_parameters, attributes, condition):
-        self.name = name
-        self.parameters = parameters
-        self.reply_parameters = reply_parameters
-        self.attributes = frozenset(attributes or [])
-        self.condition = condition
-
-    def id(self):
-        return '%sID' % self.name
-
-    def has_attribute(self, attribute):
-        return attribute in self.attributes
-
-
-class Parameter(object):
-    def __init__(self, type, name, condition=None):
-        self.type = type
-        self.name = name
-        self.condition = condition
-
-
-def parse_parameter_string(parameter_string):
-    return [Parameter(*type_and_name.rsplit(' ', 1)) for type_and_name in parameter_string.split(', ')]
-
 
 def messages_header_filename(receiver):
     return '%sMessages.h' % receiver.name
@@ -344,7 +262,7 @@ def forward_declarations_and_headers(receiver):
     return (forward_declarations, headers)
 
 def generate_messages_header(file):
-    receiver = MessageReceiver.parse(file)
+    receiver = parser.parse(file)
     header_guard = messages_header_filename(receiver).replace('.', '_')
 
     result = []
@@ -482,7 +400,7 @@ def headers_for_type(type):
 
 
 def generate_message_handler(file):
-    receiver = MessageReceiver.parse(file)
+    receiver = parser.parse(file)
     headers = {
         '"%s"' % messages_header_filename(receiver): [None],
         '"HandleMessage.h"': [None],
index bca66e0..555d488 100644 (file)
@@ -24,6 +24,7 @@ import unittest
 from StringIO import StringIO
 
 import messages
+import parser
 
 _messages_file_contents = """# Copyright (C) 2010 Apple Inc. All rights reserved.
 #
@@ -239,7 +240,7 @@ _expected_results = {
 
 class MessagesTest(unittest.TestCase):
     def setUp(self):
-        self.receiver = messages.MessageReceiver.parse(StringIO(_messages_file_contents))
+        self.receiver = parser.parse(StringIO(_messages_file_contents))
 
 
 class ParsingTest(MessagesTest):
diff --git a/Source/WebKit2/Scripts/webkit2/model.py b/Source/WebKit2/Scripts/webkit2/model.py
new file mode 100644 (file)
index 0000000..f1ea2e2
--- /dev/null
@@ -0,0 +1,56 @@
+# Copyright (C) 2010, 2011 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 APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
+
+import itertools
+
+
+class MessageReceiver(object):
+    def __init__(self, name, messages, condition):
+        self.name = name
+        self.messages = messages
+        self.condition = condition
+
+    def iterparameters(self):
+        return itertools.chain((parameter for message in self.messages for parameter in message.parameters),
+            (reply_parameter for message in self.messages if message.reply_parameters for reply_parameter in message.reply_parameters))
+
+
+class Message(object):
+    def __init__(self, name, parameters, reply_parameters, attributes, condition):
+        self.name = name
+        self.parameters = parameters
+        self.reply_parameters = reply_parameters
+        self.attributes = frozenset(attributes or [])
+        self.condition = condition
+
+    def id(self):
+        return '%sID' % self.name
+
+    def has_attribute(self, attribute):
+        return attribute in self.attributes
+
+
+class Parameter(object):
+    def __init__(self, type, name, condition=None):
+        self.type = type
+        self.name = name
+        self.condition = condition
diff --git a/Source/WebKit2/Scripts/webkit2/parser.py b/Source/WebKit2/Scripts/webkit2/parser.py
new file mode 100644 (file)
index 0000000..7835a6c
--- /dev/null
@@ -0,0 +1,76 @@
+# Copyright (C) 2010, 2011 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 APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
+
+import re
+
+import model
+
+
+def parse(file):
+    destination = None
+    messages = []
+    condition = None
+    master_condition = None
+    for line in file:
+        match = re.search(r'messages -> ([A-Za-z_0-9]+) {', line)
+        if match:
+            if condition:
+                master_condition = condition
+                condition = None
+            destination = match.group(1)
+            continue
+        if line.startswith('#'):
+            if line.startswith('#if '):
+                condition = line.rstrip()[4:]
+            elif line.startswith('#endif'):
+                condition = None
+            continue
+        match = re.search(r'([A-Za-z_0-9]+)\((.*?)\)(?:(?:\s+->\s+)\((.*?)\))?(?:\s+(.*))?', line)
+        if match:
+            name, parameters_string, reply_parameters_string, attributes_string = match.groups()
+            if parameters_string:
+                parameters = parse_parameter_string(parameters_string)
+                for parameter in parameters:
+                    parameter.condition = condition
+            else:
+                parameters = []
+
+            if attributes_string:
+                attributes = frozenset(attributes_string.split())
+            else:
+                attributes = None
+
+            if reply_parameters_string:
+                reply_parameters = parse_parameter_string(reply_parameters_string)
+                for reply_parameter in reply_parameters:
+                    reply_parameter.condition = condition
+            elif reply_parameters_string == '':
+                reply_parameters = []
+            else:
+                reply_parameters = None
+
+            messages.append(model.Message(name, parameters, reply_parameters, attributes, condition))
+    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(', ')]
index 677f922..7eada67 100644 (file)
                C0CE73371247F70E00BC0EC4 /* generate-messages-header.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = "generate-messages-header.py"; sourceTree = "<group>"; };
                C0CE73391247F70E00BC0EC4 /* __init__.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = __init__.py; sourceTree = "<group>"; };
                C0CE734612480B7D00BC0EC4 /* messages.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = messages.py; sourceTree = "<group>"; };
+               C0D04E8313EC74940041EFD6 /* model.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = model.py; sourceTree = "<group>"; };
+               C0D04E8413EC74940041EFD6 /* parser.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = parser.py; sourceTree = "<group>"; };
                C0E3AA441209E2BA00A49D01 /* Module.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Module.h; sourceTree = "<group>"; };
                C0E3AA451209E2BA00A49D01 /* Module.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Module.cpp; sourceTree = "<group>"; };
                C0E3AA481209E45000A49D01 /* ModuleMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ModuleMac.mm; sourceTree = "<group>"; };
                                C0CE73391247F70E00BC0EC4 /* __init__.py */,
                                C0CE734612480B7D00BC0EC4 /* messages.py */,
                                C08FDE87124A851C007645BD /* messages_unittest.py */,
+                               C0D04E8313EC74940041EFD6 /* model.py */,
+                               C0D04E8413EC74940041EFD6 /* parser.py */,
                        );
                        path = webkit2;
                        sourceTree = "<group>";
index e0b0599..9e49854 100755 (executable)
                                        RelativePath="..\Scripts\webkit2\messages_unittest.py"
                                        >
                                </File>
+                               <File
+                                       RelativePath="..\Scripts\webkit2\model.py"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\Scripts\webkit2\parser.py"
+                                       >
+                               </File>
                        </Filter>
                </Filter>
                <File
index 75ea918..ad46ac4 100755 (executable)
                                        RelativePath="..\Scripts\webkit2\messages_unittest.py"
                                        >
                                </File>
+                               <File
+                                       RelativePath="..\Scripts\webkit2\model.py"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\Scripts\webkit2\parser.py"
+                                       >
+                               </File>
                        </Filter>
                </Filter>
                <File