Changeset 95298 in webkit


Ignore:
Timestamp:
Sep 16, 2011 9:57:50 AM (13 years ago)
Author:
Adam Roben
Message:

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.
Location:
trunk/Source/WebKit2
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r95283 r95298  
     12011-09-15  Adam Roben  <aroben@apple.com>
     2
     3        Split some of the message-generation code into separate modules
     4
     5        This is in preparation for making these modules scripts usable by other projects.
     6
     7        Fixes <http://webkit.org/b/68217> Model and parsing functionality for WebKit2's
     8        message-generation scripts is trapped inside a much larger module
     9
     10        Reviewed by Darin Adler.
     11
     12        * DerivedSources.make:
     13        * DerivedSources.pro:
     14        * GNUmakefile.am:
     15        * WebKit2.xcodeproj/project.pbxproj:
     16        * win/WebKit2.vcproj:
     17        * win/WebKit2Generated.vcproj:
     18        Added new files.
     19
     20        * Scripts/webkit2/messages.py: Moved some code from here...
     21
     22        * Scripts/webkit2/model.py: Added.
     23        * Scripts/webkit2/parser.py: Added.
     24        ...to here. MessageReceiver.parse was split out into a function in the new parser module.
     25
     26        * Scripts/webkit2/messages_unittest.py: Updated for renames.
     27
    1282011-09-16  Martin Robinson  <mrobinson@igalia.com>
    229
  • trunk/Source/WebKit2/DerivedSources.make

    r94456 r95298  
    8787    $(WebKit2)/Scripts/webkit2/__init__.py \
    8888    $(WebKit2)/Scripts/webkit2/messages.py \
     89    $(WebKit2)/Scripts/webkit2/model.py \
     90    $(WebKit2)/Scripts/webkit2/parser.py \
    8991#
    9092
  • trunk/Source/WebKit2/DerivedSources.pro

    r94519 r95298  
    136136    $$PWD/Scripts/generate-messages-header.py \
    137137    $$PWD/Scripts/webkit2/__init__.py \
    138     $$PWD/Scripts/webkit2/messages.py
     138    $$PWD/Scripts/webkit2/messages.py \
     139    $$PWD/Scripts/webkit2/model.py \
     140    $$PWD/Scripts/webkit2/parser.py
    139141
    140142message_header_generator.commands = $${PYTHON} $${SRC_ROOT_DIR}/Source/WebKit2/Scripts/generate-messages-header.py ${QMAKE_FILE_IN} > ${QMAKE_FILE_OUT}
  • trunk/Source/WebKit2/GNUmakefile.am

    r95283 r95298  
    950950        $(WebKit2)/Scripts/generate-messages-header.py \
    951951        $(WebKit2)/Scripts/webkit2/__init__.py \
    952         $(WebKit2)/Scripts/webkit2/messages.py
     952        $(WebKit2)/Scripts/webkit2/messages.py \
     953        $(WebKit2)/Scripts/webkit2/model.py \
     954        $(WebKit2)/Scripts/webkit2/parser.py
    953955
    954956# Message header generation
  • trunk/Source/WebKit2/Scripts/webkit2/messages.py

    r95195 r95298  
    1 # Copyright (C) 2010 Apple Inc. All rights reserved.
     1# Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2222
    2323import collections
    24 import itertools
    2524import re
     25
     26import parser
    2627
    2728
     
    5455
    5556"""
    56 
    57 class MessageReceiver(object):
    58     def __init__(self, name, messages, condition):
    59         self.name = name
    60         self.messages = messages
    61         self.condition = condition
    62 
    63     def iterparameters(self):
    64         return itertools.chain((parameter for message in self.messages for parameter in message.parameters),
    65             (reply_parameter for message in self.messages if message.reply_parameters for reply_parameter in message.reply_parameters))
    66 
    67     @classmethod
    68     def parse(cls, file):
    69         destination = None
    70         messages = []
    71         condition = None
    72         master_condition = None
    73         for line in file:
    74             match = re.search(r'messages -> ([A-Za-z_0-9]+) {', line)
    75             if match:
    76                 if condition:
    77                     master_condition = condition
    78                     condition = None
    79                 destination = match.group(1)
    80                 continue
    81             if line.startswith('#'):
    82                 if line.startswith('#if '):
    83                     condition = line.rstrip()[4:]
    84                 elif line.startswith('#endif'):
    85                     condition = None
    86                 continue
    87             match = re.search(r'([A-Za-z_0-9]+)\((.*?)\)(?:(?:\s+->\s+)\((.*?)\))?(?:\s+(.*))?', line)
    88             if match:
    89                 name, parameters_string, reply_parameters_string, attributes_string = match.groups()
    90                 if parameters_string:
    91                     parameters = parse_parameter_string(parameters_string)
    92                     for parameter in parameters:
    93                         parameter.condition = condition
    94                 else:
    95                     parameters = []
    96 
    97                 if attributes_string:
    98                     attributes = frozenset(attributes_string.split())
    99                 else:
    100                     attributes = None
    101 
    102                 if reply_parameters_string:
    103                     reply_parameters = parse_parameter_string(reply_parameters_string)
    104                     for reply_parameter in reply_parameters:
    105                         reply_parameter.condition = condition
    106                 elif reply_parameters_string == '':
    107                     reply_parameters = []
    108                 else:
    109                     reply_parameters = None
    110 
    111                 messages.append(Message(name, parameters, reply_parameters, attributes, condition))
    112         return MessageReceiver(destination, messages, master_condition)
    113 
    114 
    115 class Message(object):
    116     def __init__(self, name, parameters, reply_parameters, attributes, condition):
    117         self.name = name
    118         self.parameters = parameters
    119         self.reply_parameters = reply_parameters
    120         self.attributes = frozenset(attributes or [])
    121         self.condition = condition
    122 
    123     def id(self):
    124         return '%sID' % self.name
    125 
    126     def has_attribute(self, attribute):
    127         return attribute in self.attributes
    128 
    129 
    130 class Parameter(object):
    131     def __init__(self, type, name, condition=None):
    132         self.type = type
    133         self.name = name
    134         self.condition = condition
    135 
    136 
    137 def parse_parameter_string(parameter_string):
    138     return [Parameter(*type_and_name.rsplit(' ', 1)) for type_and_name in parameter_string.split(', ')]
    13957
    14058
     
    345263
    346264def generate_messages_header(file):
    347     receiver = MessageReceiver.parse(file)
     265    receiver = parser.parse(file)
    348266    header_guard = messages_header_filename(receiver).replace('.', '_')
    349267
     
    483401
    484402def generate_message_handler(file):
    485     receiver = MessageReceiver.parse(file)
     403    receiver = parser.parse(file)
    486404    headers = {
    487405        '"%s"' % messages_header_filename(receiver): [None],
  • trunk/Source/WebKit2/Scripts/webkit2/messages_unittest.py

    r89140 r95298  
    2525
    2626import messages
     27import parser
    2728
    2829_messages_file_contents = """# Copyright (C) 2010 Apple Inc. All rights reserved.
     
    240241class MessagesTest(unittest.TestCase):
    241242    def setUp(self):
    242         self.receiver = messages.MessageReceiver.parse(StringIO(_messages_file_contents))
     243        self.receiver = parser.parse(StringIO(_messages_file_contents))
    243244
    244245
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r94456 r95298  
    17481748                C0CE73391247F70E00BC0EC4 /* __init__.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = __init__.py; sourceTree = "<group>"; };
    17491749                C0CE734612480B7D00BC0EC4 /* messages.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = messages.py; sourceTree = "<group>"; };
     1750                C0D04E8313EC74940041EFD6 /* model.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = model.py; sourceTree = "<group>"; };
     1751                C0D04E8413EC74940041EFD6 /* parser.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = parser.py; sourceTree = "<group>"; };
    17501752                C0E3AA441209E2BA00A49D01 /* Module.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Module.h; sourceTree = "<group>"; };
    17511753                C0E3AA451209E2BA00A49D01 /* Module.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Module.cpp; sourceTree = "<group>"; };
     
    33863388                                C0CE734612480B7D00BC0EC4 /* messages.py */,
    33873389                                C08FDE87124A851C007645BD /* messages_unittest.py */,
     3390                                C0D04E8313EC74940041EFD6 /* model.py */,
     3391                                C0D04E8413EC74940041EFD6 /* parser.py */,
    33883392                        );
    33893393                        path = webkit2;
  • trunk/Source/WebKit2/win/WebKit2.vcproj

    r94115 r95298  
    42384238                                        >
    42394239                                </File>
     4240                                <File
     4241                                        RelativePath="..\Scripts\webkit2\model.py"
     4242                                        >
     4243                                </File>
     4244                                <File
     4245                                        RelativePath="..\Scripts\webkit2\parser.py"
     4246                                        >
     4247                                </File>
    42404248                        </Filter>
    42414249                </Filter>
  • trunk/Source/WebKit2/win/WebKit2Generated.vcproj

    r82477 r95298  
    100100                                        >
    101101                                </File>
     102                                <File
     103                                        RelativePath="..\Scripts\webkit2\model.py"
     104                                        >
     105                                </File>
     106                                <File
     107                                        RelativePath="..\Scripts\webkit2\parser.py"
     108                                        >
     109                                </File>
    102110                        </Filter>
    103111                </Filter>
Note: See TracChangeset for help on using the changeset viewer.