Changeset 159312 in webkit


Ignore:
Timestamp:
Nov 14, 2013 2:20:04 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

generate-message-receiver.py can't handle nested #ifs
https://bugs.webkit.org/show_bug.cgi?id=121877

Patch by Gergo Balogh <geryxyz@inf.u-szeged.hu> on 2013-11-14
Reviewed by Darin Adler.

parser.py was modifieded to collect and combine conditions of nested #ifs.
messages_unittest.py extended to check these modifications.

  • Scripts/webkit2/messages_unittest.py:

(LoadSomething):
(std):
(AddEvent):
(LoadSomethingElse):

  • Scripts/webkit2/parser.py:

(combine_condition):
(bracket_if_needed):
(parse):

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r159309 r159312  
     12013-11-14  Gergo Balogh  <geryxyz@inf.u-szeged.hu>
     2
     3        generate-message-receiver.py can't handle nested #ifs
     4        https://bugs.webkit.org/show_bug.cgi?id=121877
     5
     6        Reviewed by Darin Adler.
     7
     8        parser.py was modifieded to collect and combine conditions of nested #ifs.
     9        messages_unittest.py extended to check these modifications.
     10
     11        * Scripts/webkit2/messages_unittest.py:
     12        (LoadSomething):
     13        (std):
     14        (AddEvent):
     15        (LoadSomethingElse):
     16        * Scripts/webkit2/parser.py:
     17        (combine_condition):
     18        (bracket_if_needed):
     19        (parse):
     20
    1212013-11-14  Dan Bernstein  <mitz@apple.com>
    222
  • trunk/Source/WebKit2/Scripts/webkit2/messages_unittest.py

    r159201 r159312  
    5050
    5151#if ENABLE(WEBKIT2)
     52#if NESTED_MASTER_CONDITION || MASTER_OR && MASTER_AND
    5253
    5354messages -> WebPage LegacyReceiver {
    5455    LoadURL(WTF::String url)
    5556#if ENABLE(TOUCH_EVENTS)
     57    LoadSomething(WTF::String url)
     58#if NESTED_MESSAGE_CONDITION || SOME_OTHER_MESSAGE_CONDITION
    5659    TouchEvent(WebKit::WebTouchEvent event)
     60#endif
     61#if NESTED_MESSAGE_CONDITION && SOME_OTHER_MESSAGE_CONDITION
     62    AddEvent(WebKit::WebTouchEvent event)
     63#endif
     64    LoadSomethingElse(WTF::String url)
    5765#endif
    5866    DidReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction)
     
    93101
    94102#endif
     103#endif
    95104"""
    96105
    97106_expected_results = {
    98107    'name': 'WebPage',
    99     'conditions': ('ENABLE(WEBKIT2)'),
     108    'conditions': ('(ENABLE(WEBKIT2) && (NESTED_MASTER_CONDITION || MASTER_OR && MASTER_AND))'),
    100109    'messages': (
    101110        {
     
    107116        },
    108117        {
     118            'name': 'LoadSomething',
     119            'parameters': (
     120                ('WTF::String', 'url'),
     121            ),
     122            'conditions': ('ENABLE(TOUCH_EVENTS)'),
     123        },
     124        {
    109125            'name': 'TouchEvent',
    110126            'parameters': (
    111127                ('WebKit::WebTouchEvent', 'event'),
     128            ),
     129            'conditions': ('(ENABLE(TOUCH_EVENTS) && (NESTED_MESSAGE_CONDITION || SOME_OTHER_MESSAGE_CONDITION))'),
     130        },
     131        {
     132            'name': 'AddEvent',
     133            'parameters': (
     134                ('WebKit::WebTouchEvent', 'event'),
     135            ),
     136            'conditions': ('(ENABLE(TOUCH_EVENTS) && (NESTED_MESSAGE_CONDITION && SOME_OTHER_MESSAGE_CONDITION))'),
     137        },
     138        {
     139            'name': 'LoadSomethingElse',
     140            'parameters': (
     141                ('WTF::String', 'url'),
    112142            ),
    113143            'conditions': ('ENABLE(TOUCH_EVENTS)'),
     
    311341#define WebPageMessages_h
    312342
    313 #if ENABLE(WEBKIT2)
     343#if (ENABLE(WEBKIT2) && (NESTED_MASTER_CONDITION || MASTER_OR && MASTER_AND))
    314344
    315345#include "Arguments.h"
     
    371401
    372402#if ENABLE(TOUCH_EVENTS)
     403class LoadSomething {
     404public:
     405    typedef std::tuple<WTF::String> DecodeType;
     406
     407    static CoreIPC::StringReference receiverName() { return messageReceiverName(); }
     408    static CoreIPC::StringReference name() { return CoreIPC::StringReference("LoadSomething"); }
     409    static const bool isSync = false;
     410
     411    explicit LoadSomething(const WTF::String& url)
     412        : m_arguments(url)
     413    {
     414    }
     415
     416    const std::tuple<const WTF::String&> arguments() const
     417    {
     418        return m_arguments;
     419    }
     420
     421private:
     422    std::tuple<const WTF::String&> m_arguments;
     423};
     424#endif
     425
     426#if (ENABLE(TOUCH_EVENTS) && (NESTED_MESSAGE_CONDITION || SOME_OTHER_MESSAGE_CONDITION))
    373427class TouchEvent {
    374428public:
     
    391445private:
    392446    std::tuple<const WebKit::WebTouchEvent&> m_arguments;
     447};
     448#endif
     449
     450#if (ENABLE(TOUCH_EVENTS) && (NESTED_MESSAGE_CONDITION && SOME_OTHER_MESSAGE_CONDITION))
     451class AddEvent {
     452public:
     453    typedef std::tuple<WebKit::WebTouchEvent> DecodeType;
     454
     455    static CoreIPC::StringReference receiverName() { return messageReceiverName(); }
     456    static CoreIPC::StringReference name() { return CoreIPC::StringReference("AddEvent"); }
     457    static const bool isSync = false;
     458
     459    explicit AddEvent(const WebKit::WebTouchEvent& event)
     460        : m_arguments(event)
     461    {
     462    }
     463
     464    const std::tuple<const WebKit::WebTouchEvent&> arguments() const
     465    {
     466        return m_arguments;
     467    }
     468
     469private:
     470    std::tuple<const WebKit::WebTouchEvent&> m_arguments;
     471};
     472#endif
     473
     474#if ENABLE(TOUCH_EVENTS)
     475class LoadSomethingElse {
     476public:
     477    typedef std::tuple<WTF::String> DecodeType;
     478
     479    static CoreIPC::StringReference receiverName() { return messageReceiverName(); }
     480    static CoreIPC::StringReference name() { return CoreIPC::StringReference("LoadSomethingElse"); }
     481    static const bool isSync = false;
     482
     483    explicit LoadSomethingElse(const WTF::String& url)
     484        : m_arguments(url)
     485    {
     486    }
     487
     488    const std::tuple<const WTF::String&> arguments() const
     489    {
     490        return m_arguments;
     491    }
     492
     493private:
     494    std::tuple<const WTF::String&> m_arguments;
    393495};
    394496#endif
     
    775877} // namespace Messages
    776878
    777 #endif // ENABLE(WEBKIT2)
     879#endif // (ENABLE(WEBKIT2) && (NESTED_MASTER_CONDITION || MASTER_OR && MASTER_AND))
    778880
    779881#endif // WebPageMessages_h
     
    806908#include "config.h"
    807909
    808 #if ENABLE(WEBKIT2)
     910#if (ENABLE(WEBKIT2) && (NESTED_MASTER_CONDITION || MASTER_OR && MASTER_AND))
    809911
    810912#include "WebPage.h"
     
    822924#include "Plugin.h"
    823925#include "WebCoreArgumentCoders.h"
    824 #if ENABLE(TOUCH_EVENTS)
     926#if (ENABLE(TOUCH_EVENTS) && (NESTED_MESSAGE_CONDITION && SOME_OTHER_MESSAGE_CONDITION)) || (ENABLE(TOUCH_EVENTS) && (NESTED_MESSAGE_CONDITION || SOME_OTHER_MESSAGE_CONDITION))
    825927#include "WebEvent.h"
    826928#endif
     
    892994    }
    893995#if ENABLE(TOUCH_EVENTS)
     996    if (decoder.messageName() == Messages::WebPage::LoadSomething::name()) {
     997        CoreIPC::handleMessage<Messages::WebPage::LoadSomething>(decoder, this, &WebPage::loadSomething);
     998        return;
     999    }
     1000#endif
     1001#if (ENABLE(TOUCH_EVENTS) && (NESTED_MESSAGE_CONDITION || SOME_OTHER_MESSAGE_CONDITION))
    8941002    if (decoder.messageName() == Messages::WebPage::TouchEvent::name()) {
    8951003        CoreIPC::handleMessage<Messages::WebPage::TouchEvent>(decoder, this, &WebPage::touchEvent);
     1004        return;
     1005    }
     1006#endif
     1007#if (ENABLE(TOUCH_EVENTS) && (NESTED_MESSAGE_CONDITION && SOME_OTHER_MESSAGE_CONDITION))
     1008    if (decoder.messageName() == Messages::WebPage::AddEvent::name()) {
     1009        CoreIPC::handleMessage<Messages::WebPage::AddEvent>(decoder, this, &WebPage::addEvent);
     1010        return;
     1011    }
     1012#endif
     1013#if ENABLE(TOUCH_EVENTS)
     1014    if (decoder.messageName() == Messages::WebPage::LoadSomethingElse::name()) {
     1015        CoreIPC::handleMessage<Messages::WebPage::LoadSomethingElse>(decoder, this, &WebPage::loadSomethingElse);
    8961016        return;
    8971017    }
     
    9791099} // namespace WebKit
    9801100
    981 #endif // ENABLE(WEBKIT2)
     1101#endif // (ENABLE(WEBKIT2) && (NESTED_MASTER_CONDITION || MASTER_OR && MASTER_AND))
    9821102"""
    9831103
  • trunk/Source/WebKit2/Scripts/webkit2/parser.py

    r157243 r159312  
    2222
    2323import re
    24 import sys
    2524
    2625from webkit2 import model
     26
     27
     28def combine_condition(conditions):
     29    if conditions:
     30        if len(conditions) == 1:
     31            return conditions[0]
     32        else:
     33            return bracket_if_needed(' && '.join(map(bracket_if_needed, conditions)))
     34    else:
     35        return None
     36
     37
     38def bracket_if_needed(condition):
     39    if re.match(r'.*(&&|\|\|).*', condition):
     40        return '(%s)' % condition
     41    else:
     42        return condition
    2743
    2844
     
    3147    destination = None
    3248    messages = []
    33     condition = None
     49    conditions = []
    3450    master_condition = None
    3551    for line in file:
     
    3854            receiver_attributes = parse_attributes_string(match.group('attributes'))
    3955
    40             if condition:
    41                 master_condition = condition
    42                 condition = None
     56            if conditions:
     57                master_condition = conditions
     58                conditions = []
    4359            destination = match.group('destination')
    4460            continue
    4561        if line.startswith('#'):
    4662            if line.startswith('#if '):
    47                 if condition:
    48                     # FIXME: generate-message-receiver.py can't handle nested ifs
    49                     # https://bugs.webkit.org/show_bug.cgi?id=121877
    50                     sys.stderr.write("ERROR: Nested #ifs aren't supported, please fix %s\n" % file.name)
    51                     sys.exit(1)
    52                 condition = line.rstrip()[4:]
    53             elif line.startswith('#endif'):
    54                 condition = None
     63                conditions.append(line.rstrip()[4:])
     64            elif line.startswith('#endif') and conditions:
     65                conditions.pop()
    5566            continue
    5667        match = re.search(r'([A-Za-z_0-9]+)\((.*?)\)(?:(?:\s+->\s+)\((.*?)\))?(?:\s+(.*))?', line)
     
    6071                parameters = parse_parameters_string(parameters_string)
    6172                for parameter in parameters:
    62                     parameter.condition = condition
     73                    parameter.condition = combine_condition(conditions)
    6374            else:
    6475                parameters = []
     
    6980                reply_parameters = parse_parameters_string(reply_parameters_string)
    7081                for reply_parameter in reply_parameters:
    71                     reply_parameter.condition = condition
     82                    reply_parameter.condition = combine_condition(conditions)
    7283            elif reply_parameters_string == '':
    7384                reply_parameters = []
     
    7586                reply_parameters = None
    7687
    77             messages.append(model.Message(name, parameters, reply_parameters, attributes, condition))
    78     return model.MessageReceiver(destination, receiver_attributes, messages, master_condition)
     88            messages.append(model.Message(name, parameters, reply_parameters, attributes, combine_condition(conditions)))
     89    return model.MessageReceiver(destination, receiver_attributes, messages, combine_condition(master_condition))
    7990
    8091
Note: See TracChangeset for help on using the changeset viewer.