Changeset 142835 in webkit


Ignore:
Timestamp:
Feb 13, 2013 5:49:31 PM (11 years ago)
Author:
andersca@apple.com
Message:

Message generation should handle nested templates
https://bugs.webkit.org/show_bug.cgi?id=109771

Reviewed by Ryosuke Niwa.

Make it possible to have nested class template types as message parameters and
correctly gather all the needed headers and argument coder headers.

  • Scripts/webkit2/messages.py:

(class_template_headers):
Recursively figure out the types and template headers needed for a given type.

(argument_coder_headers_for_type):
(headers_for_type):
Call class_template_headers.

  • Scripts/webkit2/messages_unittest.py:

(CoreIPC):

  • Scripts/webkit2/parser.py:

(split_parameters_string):
(parse_parameters_string):

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r142830 r142835  
     12013-02-13  Anders Carlsson  <andersca@apple.com>
     2
     3        Message generation should handle nested templates
     4        https://bugs.webkit.org/show_bug.cgi?id=109771
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Make it possible to have nested class template types as message parameters and
     9        correctly gather all the needed headers and argument coder headers.
     10
     11        * Scripts/webkit2/messages.py:
     12        (class_template_headers):
     13        Recursively figure out the types and template headers needed for a given type.
     14
     15        (argument_coder_headers_for_type):
     16        (headers_for_type):
     17        Call class_template_headers.
     18
     19        * Scripts/webkit2/messages_unittest.py:
     20        (CoreIPC):
     21        * Scripts/webkit2/parser.py:
     22        (split_parameters_string):
     23        (parse_parameters_string):
     24
    1252013-02-13  David Farler  <dfarler@apple.com>
    226
  • trunk/Source/WebKit2/Scripts/webkit2/messages.py

    r142783 r142835  
    337337
    338338
     339def class_template_headers(template_string):
     340    template_string = template_string.strip()
     341
     342    class_template_types = {
     343        # FIXME: Remove the unprefixed versions.
     344        'Vector': {'headers': ['<wtf/Vector.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
     345        'HashMap': {'headers': ['<wtf/HashMap.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
     346
     347        'WTF::Vector': {'headers': ['<wtf/Vector.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
     348        'WTF::HashMap': {'headers': ['<wtf/HashMap.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
     349        'std::pair': {'headers': ['<utility>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
     350    }
     351
     352    match = re.match('(?P<template_name>.+?)<(?P<parameter_string>.+)>', template_string)
     353    if not match:
     354        return {'header_infos':[], 'types':[template_string]}
     355    header_infos = [class_template_types[match.groupdict()['template_name']]]
     356    types = []
     357
     358    for parameter in parser.split_parameters_string(match.groupdict()['parameter_string']):
     359        parameter_header_infos_and_types = class_template_headers(parameter)
     360
     361        header_infos += parameter_header_infos_and_types['header_infos'];
     362        types += parameter_header_infos_and_types['types']
     363
     364    return {'header_infos':header_infos, 'types':types}
     365
     366
    339367def argument_coder_headers_for_type(type):
    340     # Check for Vector.
    341     match = re.search(r'Vector<(.+)>', type)
    342     if match:
    343         element_type = match.groups()[0].strip()
    344         return ['"ArgumentCoders.h"'] + argument_coder_headers_for_type(element_type)
     368    header_infos_and_types = class_template_headers(type)
    345369
    346370    special_cases = {
     
    350374    }
    351375
    352     if type in special_cases:
    353         return [special_cases[type]]
    354 
    355     split = type.split('::')
    356     if len(split) < 2:
    357         return []
    358     if split[0] == 'WebCore':
    359         return ['"WebCoreArgumentCoders.h"']
    360 
    361     return []
    362 
     376    headers = []
     377    for header_info in header_infos_and_types['header_infos']:
     378        headers += header_info['argument_coder_headers']
     379
     380    for type in header_infos_and_types['types']:
     381        if type in special_cases:
     382            headers.append(special_cases[type])
     383            continue
     384
     385        split = type.split('::')
     386        if len(split) < 2:
     387            continue
     388        if split[0] == 'WebCore':
     389            headers.append('"WebCoreArgumentCoders.h"')
     390
     391    return headers
    363392
    364393def headers_for_type(type):
    365     # Check for Vector.
    366     match = re.search(r'Vector<(.+)>', type)
    367     if match:
    368         element_type = match.groups()[0].strip()
    369         return ['<wtf/Vector.h>'] + headers_for_type(element_type)
     394    header_infos_and_types = class_template_headers(type)
    370395
    371396    special_cases = {
     
    389414        'WebKit::WebWheelEvent': ['"WebEvent.h"'],
    390415    }
    391     if type in special_cases:
    392         return special_cases[type]
    393 
    394     # We assume that we must include a header for a type iff it has a scope
    395     # resolution operator (::).
    396     split = type.split('::')
    397     if len(split) < 2:
    398         return []
    399     if split[0] == 'WebKit' or split[0] == 'CoreIPC':
    400         return ['"%s.h"' % split[1]]
    401     return ['<%s/%s.h>' % tuple(split)]
    402 
     416
     417    headers = []
     418    for header_info in header_infos_and_types['header_infos']:
     419        headers += header_info['headers']
     420
     421    for type in header_infos_and_types['types']:
     422        if type in special_cases:
     423            headers += special_cases[type]
     424            continue
     425
     426        # We assume that we must include a header for a type iff it has a scope
     427        # resolution operator (::).
     428        split = type.split('::')
     429        if len(split) < 2:
     430            continue
     431
     432        if split[0] == 'WebKit' or split[0] == 'CoreIPC':
     433            headers.append('"%s.h"' % split[1])
     434        else:
     435            headers.append('<%s/%s.h>' % tuple(split))
     436
     437    return headers
    403438
    404439def generate_message_handler(file):
  • trunk/Source/WebKit2/Scripts/webkit2/messages_unittest.py

    r142783 r142835  
    7474    TestParameterAttributes([AttributeOne AttributeTwo] uint64_t foo, double bar, [AttributeThree] double baz)
    7575
     76    TemplateTest(WTF::HashMap<String, std::pair<String, uint64_t> > a)
     77
    7678#if PLATFORM(MAC)
    7779    DidCreateWebProcessConnection(CoreIPC::MachPort connectionIdentifier)
     
    204206                ('double', 'bar'),
    205207                ('double', 'baz', ('AttributeThree',)),
     208            ),
     209            'conditions': (None),
     210        },
     211        {
     212            'name': 'TemplateTest',
     213            'parameters': (
     214                ('WTF::HashMap<String, std::pair<String, uint64_t> >', 'a'),
    206215            ),
    207216            'conditions': (None),
     
    313322#include <WebCore/KeyboardEvent.h>
    314323#include <WebCore/PluginData.h>
     324#include <utility>
     325#include <wtf/HashMap.h>
    315326#include <wtf/ThreadSafeRefCounted.h>
    316327#include <wtf/Vector.h>
     
    512523    TestParameterAttributes(uint64_t foo, double bar, double baz)
    513524        : CoreIPC::Arguments3<uint64_t, double, double>(foo, bar, baz)
     525    {
     526    }
     527};
     528
     529struct TemplateTest : CoreIPC::Arguments1<const WTF::HashMap<String, std::pair<String, uint64_t> >&> {
     530    static CoreIPC::StringReference receiverName() { return messageReceiverName(); }
     531    static CoreIPC::StringReference name() { return CoreIPC::StringReference("TemplateTest"); }
     532    static const bool isSync = false;
     533
     534    typedef CoreIPC::Arguments1<const WTF::HashMap<String, std::pair<String, uint64_t> >&> DecodeType;
     535    explicit TemplateTest(const WTF::HashMap<String, std::pair<String, uint64_t> >& a)
     536        : CoreIPC::Arguments1<const WTF::HashMap<String, std::pair<String, uint64_t> >&>(a)
    514537    {
    515538    }
     
    632655#endif
    633656#include <WebCore/PluginData.h>
     657#include <utility>
     658#include <wtf/HashMap.h>
    634659#include <wtf/Vector.h>
    635660#include <wtf/text/WTFString.h>
     
    720745        return;
    721746    }
     747    if (decoder.messageName() == Messages::WebPage::TemplateTest::name()) {
     748        CoreIPC::handleMessage<Messages::WebPage::TemplateTest>(decoder, this, &WebPage::templateTest);
     749        return;
     750    }
    722751#if PLATFORM(MAC)
    723752    if (decoder.messageName() == Messages::WebPage::DidCreateWebProcessConnection::name()) {
  • trunk/Source/WebKit2/Scripts/webkit2/parser.py

    r140605 r142835  
    7979
    8080
     81def split_parameters_string(parameters_string):
     82    parameters = []
     83    current_parameter_string = ''
     84
     85    nest_level = 0
     86    for character in parameters_string:
     87        if character == ',' and nest_level == 0:
     88            parameters.append(current_parameter_string)
     89            current_parameter_string = ''
     90            continue
     91
     92        if character == '<':
     93            nest_level += 1
     94        elif character == '>':
     95            nest_level -= 1
     96
     97        current_parameter_string += character
     98
     99    parameters.append(current_parameter_string)
     100    return parameters
     101
    81102def parse_parameters_string(parameters_string):
    82103    parameters = []
    83     for parameter_string in parameters_string.split(', '):
     104
     105    for parameter_string in split_parameters_string(parameters_string):
    84106        match = re.search(r'\s*(?:\[(?P<attributes>.*?)\]\s+)?(?P<type_and_name>.*)', parameter_string)
    85107        attributes_string, type_and_name_string = match.group('attributes', 'type_and_name')
Note: See TracChangeset for help on using the changeset viewer.