Changeset 63561 in webkit


Ignore:
Timestamp:
Jul 16, 2010 10:16:56 AM (14 years ago)
Author:
loislo@chromium.org
Message:

2010-07-16 Ilya Tikhonovsky <loislo@chromium.org>

Reviewed by Yury Semikhatsky.

WebInspector: The current implementation of generator is not ready
for generation Backend part of Inspector interface. The full patch
with Backend is quite big and I've split it.
https://bugs.webkit.org/show_bug.cgi?id=42462

  • inspector/CodeGeneratorInspector.pm:
  • inspector/Inspector.idl:
  • inspector/InspectorValues.cpp: (WebCore::InspectorArray::get):
  • inspector/InspectorValues.h: (WebCore::InspectorArray::length):
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63560 r63561  
     12010-07-16  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Reviewed by Yury Semikhatsky.
     4
     5        WebInspector: The current implementation of generator is not ready
     6        for generation Backend part of Inspector interface. The full patch
     7        with Backend is quite big and I've split it.
     8        https://bugs.webkit.org/show_bug.cgi?id=42462
     9
     10        * inspector/CodeGeneratorInspector.pm:
     11        * inspector/Inspector.idl:
     12        * inspector/InspectorValues.cpp:
     13        (WebCore::InspectorArray::get):
     14        * inspector/InspectorValues.h:
     15        (WebCore::InspectorArray::length):
     16
    1172010-07-15  Rob Buis  <rwlbuis@gmail.com>
    218
  • trunk/WebCore/inspector/CodeGeneratorInspector.pm

    r63198 r63561  
    77use strict;
    88
     9use Class::Struct;
    910use File::stat;
    1011
     
    2223    "forward" => "InspectorObject",
    2324    "header" => "InspectorValues.h",
    24     "push" => "push"
     25    "accessorSuffix" => ""
    2526};
    2627$typeTransform{"Array"} = {
     
    2930    "forward" => "InspectorArray",
    3031    "header" => "InspectorValues.h",
    31     "push" => "push"
     32    "accessorSuffix" => ""
    3233};
    3334$typeTransform{"Value"} = {
     
    3637    "forward" => "InspectorValue",
    3738    "header" => "InspectorValues.h",
    38     "push" => "push"
     39    "accessorSuffix" => ""
    3940};
    4041$typeTransform{"String"} = {
     
    4344    "forward" => "String",
    4445    "header" => "PlatformString.h",
    45     "push" => "pushString"
     46    "accessorSuffix" => "String"
    4647};
    4748$typeTransform{"long"} = {
     
    5051    "forward" => "",
    5152    "header" => "",
    52     "push" => "pushNumber"
     53    "accessorSuffix" => "Number"
    5354};
    5455$typeTransform{"int"} = {
     
    5758    "forward" => "",
    5859    "header" => "",
    59     "push" => "pushNumber"
     60    "accessorSuffix" => "Number",
    6061};
    6162$typeTransform{"unsigned long"} = {
     
    6465    "forward" => "",
    6566    "header" => "",
    66     "push" => "pushNumber"
     67    "accessorSuffix" => "Number"
    6768};
    6869$typeTransform{"boolean"} = {
     
    7172    "forward" => "",
    7273    "header" => "",
    73     "push" => "pushBool"
     74    "accessorSuffix" => "Bool"
    7475};
    7576$typeTransform{"void"} = {
     
    9394
    9495my $namespace;
     96
    9597my $frontendClassName;
    96 my %discoveredTypes;
    97 my %generatedFunctions;
    98 
    99 my @frontendClassDeclaration;
    100 my @functionDefinitions;
    101 
    102 sub typeSpec
    103 {
    104     my $param = shift;
    105     my $retValue = shift;
    106 
    107     my $type = $typeTransform{$param->type}->{$retValue ? "retVal" : "param"};
    108     $discoveredTypes{$param->type} = 1;
    109     $type or die "invalid type specification \"" . $param->type ."\"";
    110     return $type;
    111 }
     98my %frontendTypes;
     99my %frontendMethods;
     100my @frontendMethodsImpl;
     101my $frontendConstructor;
     102my $frontendFooter;
     103
     104my $callId = new domSignature(); # it is just structure for describing parameters from IDLStructure.pm.
     105$callId->type("long");
     106$callId->name("callId");
    112107
    113108# Default constructor
     
    146141
    147142    my $className = $interface->name;
     143
    148144    $frontendClassName = "Remote" . $className . "Frontend";
    149 
    150     $discoveredTypes{"String"} = 1;
    151     $discoveredTypes{"InspectorClient"} = 1;
    152     $discoveredTypes{"PassRefPtr"} = 1;
    153 
    154     push(@frontendClassDeclaration, "class $frontendClassName {");
    155     push(@frontendClassDeclaration, "public:");
    156     push(@frontendClassDeclaration, "    $frontendClassName(InspectorClient* inspectorClient) : m_inspectorClient(inspectorClient) { }");
    157     push(@frontendClassDeclaration, "");
    158     push(@frontendClassDeclaration, generateFunctions($interface, $frontendClassName));
    159     push(@frontendClassDeclaration, "");
    160     push(@frontendClassDeclaration, "private:");
    161     push(@frontendClassDeclaration, "    InspectorClient* m_inspectorClient;");
    162     push(@frontendClassDeclaration, "};");
     145    $frontendConstructor = "    ${frontendClassName}(InspectorClient* inspectorClient) : m_inspectorClient(inspectorClient) { }";
     146    $frontendFooter = "    InspectorClient* m_inspectorClient;";
     147    $frontendTypes{"String"} = 1;
     148    $frontendTypes{"InspectorClient"} = 1;
     149    $frontendTypes{"PassRefPtr"} = 1;
     150
     151    generateFunctions($interface);
    163152}
    164153
     
    166155{
    167156    my $interface = shift;
     157
     158    foreach my $function (@{$interface->functions}) {
     159        generateFrontendFunction($function);
     160    }
     161}
     162
     163sub generateFrontendFunction
     164{
     165    my $function = shift;
     166
     167    my $functionName;
     168    my $notify = $function->signature->extendedAttributes->{"notify"};
     169    if ($notify) {
     170        $functionName = $function->signature->name;
     171    } else {
     172        my $customResponse = $function->signature->extendedAttributes->{"customResponse"};
     173        $functionName = $customResponse ? $customResponse : "did" . ucfirst($function->signature->name);
     174    }
     175
     176    my @argsFiltered = grep($_->direction eq "out", @{$function->parameters}); # just keep only out parameters for frontend interface.
     177    unshift(@argsFiltered, $callId) if !$notify; # Add callId as the first argument for all frontend did* methods.
     178    map($frontendTypes{$_->type} = 1, @argsFiltered); # register required types.
     179    my $arguments = join(", ", map($typeTransform{$_->type}->{"param"} . " " . $_->name, @argsFiltered)); # prepare arguments for function signature.
     180    my @pushArguments = map("    arguments->push" . $typeTransform{$_->type}->{"accessorSuffix"} . "(" . $_->name . ");", @argsFiltered);
     181
     182    my $signature = "    void ${functionName}(${arguments});";
     183    if (!$frontendMethods{${signature}}) {
     184        $frontendMethods{${signature}} = 1;
     185
     186        my @function;
     187        push(@function, "void ${frontendClassName}::${functionName}(${arguments})");
     188        push(@function, "{");
     189        push(@function, "    RefPtr<InspectorArray> arguments = InspectorArray::create();");
     190        push(@function, "    arguments->pushString(\"$functionName\");");
     191        push(@function, @pushArguments);
     192        push(@function, "    m_inspectorClient->sendMessageToFrontend(arguments->toJSONString());");
     193        push(@function, "}");
     194        push(@function, "");
     195        push(@frontendMethodsImpl, @function);
     196    }
     197}
     198
     199sub generateHeader
     200{
    168201    my $className = shift;
    169 
    170     my @functionDeclarations;
    171     foreach my $function (@{$interface->functions}) {
    172         my $functionName;
    173         my $argumentsDirectionFilter;
    174         my $arguments;
    175         my @functionBody;
    176         push(@functionBody, "    RefPtr<InspectorArray> arguments = InspectorArray::create();");
    177         if ($function->signature->extendedAttributes->{"notify"}) {
    178             $functionName = $function->signature->name;
    179             $argumentsDirectionFilter = "in";
    180             $arguments = "";
    181             push(@functionBody, "    arguments->pushString(\"$functionName\");");
    182         } else {
    183             my $customResponse = $function->signature->extendedAttributes->{"customResponse"};
    184             $functionName = $customResponse ? $customResponse : "did" . ucfirst($function->signature->name);
    185             $argumentsDirectionFilter = "out";
    186             $arguments = "long callId";
    187             push(@functionBody, "    arguments->pushString(\"$functionName\");");
    188             push(@functionBody, "    arguments->pushNumber(callId);");
    189         }
    190 
    191         foreach my $parameter (@{$function->parameters}) {
    192             if ($parameter->direction eq $argumentsDirectionFilter) {
    193                 $parameter->name or die "empty argument name specified for function ${frontendClassName}::$functionName and argument type " . $parameter->type;
    194                 $arguments = $arguments . ", " if ($arguments);
    195                 $arguments = $arguments . typeSpec($parameter) . " " . $parameter->name;
    196                 my $pushFunctionName =  $typeTransform{$parameter->type}->{"push"};
    197                 push(@functionBody, "    arguments->$pushFunctionName(" . $parameter->name . ");");
    198             }
    199         }
    200         push(@functionBody, "    m_inspectorClient->sendMessageToFrontend(arguments->toJSONString());");
    201 
    202         my $signature = "    " . typeSpec($function->signature, 1) . " $functionName($arguments);";
    203         if (!$generatedFunctions{${signature}}) {
    204             $generatedFunctions{${signature}} = 1;
    205             push(@functionDeclarations, $signature);
    206 
    207             my @function;
    208             push(@function, typeSpec($function->signature, 1) . " " . $className . "::" . $functionName . "(" . $arguments . ")");
    209             push(@function, "{");
    210             push(@function, @functionBody);
    211             push(@function, "}");
    212             push(@function, "");
    213             push(@functionDefinitions, @function);
    214         }
    215     }
    216     return @functionDeclarations;
    217 }
    218 
    219 sub generateHeader
    220 {
    221     my @headerContent = split("\r", $licenseTemplate);
    222     push(@headerContent, "#ifndef ${frontendClassName}_h");
    223     push(@headerContent, "#define ${frontendClassName}_h");
    224     push(@headerContent, "");
    225 
    226     my @forwardHeaders;
    227     foreach my $type (keys %discoveredTypes) {
    228         push(@forwardHeaders, "#include <" . $typeTransform{$type}->{"forwardHeader"} . ">") if !$typeTransform{$type}->{"forwardHeader"} eq  "";
    229     }
    230     push(@headerContent, sort @forwardHeaders);
    231     push(@headerContent, "");
    232     push(@headerContent, "namespace $namespace {");
    233     push(@headerContent, "");
    234 
    235     my @forwardDeclarations;
    236     foreach my $type (keys %discoveredTypes) {
    237         push(@forwardDeclarations, "class " . $typeTransform{$type}->{"forward"} . ";") if !$typeTransform{$type}->{"forward"} eq  "";
    238     }
    239     push(@headerContent, sort @forwardDeclarations);
    240 
    241     push(@headerContent, "");
    242     push(@headerContent, @frontendClassDeclaration);
    243     push(@headerContent, "");
    244     push(@headerContent, "} // namespace $namespace");
    245     push(@headerContent, "");
    246     push(@headerContent, "#endif // !defined(${frontendClassName}_h)");
    247     push(@headerContent, "");
    248     return @headerContent;
     202    my $types = shift;
     203    my $constructor = shift;
     204    my $methods = shift;
     205    my $footer = shift;
     206
     207    my $forwardHeaders = join("\n", sort(map("#include <" . $typeTransform{$_}->{"forwardHeader"} . ">", grep($typeTransform{$_}->{"forwardHeader"}, keys %{$types}))));
     208    my $forwardDeclarations = join("\n", sort(map("class " . $typeTransform{$_}->{"forward"} . ";", grep($typeTransform{$_}->{"forward"}, keys %{$types}))));
     209    my $methodsDeclarations = join("\n", keys %{$methods});
     210
     211    my $headerBody = << "EOF";
     212// Copyright (c) 2010 The Chromium Authors. All rights reserved.
     213// Use of this source code is governed by a BSD-style license that can be
     214// found in the LICENSE file.
     215#ifndef ${className}_h
     216#define ${className}_h
     217
     218${forwardHeaders}
     219
     220namespace $namespace {
     221
     222$forwardDeclarations
     223
     224class $className {
     225public:
     226$constructor
     227
     228$methodsDeclarations
     229
     230private:
     231$footer
     232};
     233
     234} // namespace $namespace
     235#endif // !defined(${className}_h)
     236
     237EOF
     238    return $headerBody;
    249239}
    250240
    251241sub generateSource
    252242{
     243    my $className = shift;
     244    my $types = shift;
     245    my $methods = shift;
     246
    253247    my @sourceContent = split("\r", $licenseTemplate);
    254248    push(@sourceContent, "\n#include \"config.h\"");
    255     push(@sourceContent, "#include \"$frontendClassName.h\"");
     249    push(@sourceContent, "#include \"$className.h\"");
    256250    push(@sourceContent, "");
    257251    push(@sourceContent, "#if ENABLE(INSPECTOR)");
     
    259253
    260254    my %headers;
    261     foreach my $type (keys %discoveredTypes) {
     255    foreach my $type (keys %{$types}) {
    262256        $headers{"#include \"" . $typeTransform{$type}->{"header"} . "\""} = 1 if !$typeTransform{$type}->{"header"} eq  "";
    263257    }
     
    266260    push(@sourceContent, "namespace $namespace {");
    267261    push(@sourceContent, "");
    268     push(@sourceContent, @functionDefinitions);
     262    push(@sourceContent, @{$methods});
    269263    push(@sourceContent, "");
    270264    push(@sourceContent, "} // namespace $namespace");
     
    280274
    281275    open(my $SOURCE, ">$outputDir/$frontendClassName.cpp") || die "Couldn't open file $outputDir/$frontendClassName.cpp";
    282     open(my $HEADER, ">$outputDir/$frontendClassName.h") || die "Couldn't open file $outputDir/$frontendClassName.h";
    283 
    284     print $SOURCE join("\n", generateSource());
     276    print $SOURCE join("\n", generateSource($frontendClassName, \%frontendTypes, \@frontendMethodsImpl));
    285277    close($SOURCE);
    286278    undef($SOURCE);
    287279
    288     print $HEADER join("\n", generateHeader());
     280    open(my $HEADER, ">$outputDir/$frontendClassName.h") || die "Couldn't open file $outputDir/$frontendClassName.h";
     281    print $HEADER generateHeader($frontendClassName, \%frontendTypes, $frontendConstructor, \%frontendMethods, $frontendFooter);
    289282    close($HEADER);
    290283    undef($HEADER);
     284
    291285}
    292286
  • trunk/WebCore/inspector/Inspector.idl

    r63309 r63561  
    3333module core {
    3434    interface [Conditional=INSPECTOR] Inspector {
    35         [notify] void addRecordToTimeline(in Object record);
    36         [notify] void addNodesToSearchResult(in Array nodeIds);
    37         [notify] void attributesUpdated(in long id, in Array attributes);
    38         [notify] void childNodeCountUpdated(in long id, in int newValue);
    39         [notify] void childNodeInserted(in long parentId, in long prevId, in Object node);
    40         [notify] void childNodeRemoved(in long parentId, in long id);
    41         [notify] void setChildNodes(in long parentId, in Array nodes);
    42         [notify] void setDetachedRoot(in Object root);
    43         [notify] void setDocument(in Value root);
     35        [notify] void addRecordToTimeline(out Object record);
     36        [notify] void addNodesToSearchResult(out Array nodeIds);
     37        [notify] void attributesUpdated(out long id, out Array attributes);
     38        [notify] void childNodeCountUpdated(out long id, out int newValue);
     39        [notify] void childNodeInserted(out long parentId, out long prevId, out Object node);
     40        [notify] void childNodeRemoved(out long parentId, out long id);
     41        [notify] void setChildNodes(out long parentId, out Array nodes);
     42        [notify] void setDetachedRoot(out Object root);
     43        [notify] void setDocument(out Value root);
    4444
    4545        void storeLastActivePanel(in String panelName);
     
    5656        void enableResourceTracking(in boolean always);
    5757        void disableResourceTracking(in boolean always);
    58         void getResourceContent(in unsigned long identifier);
     58        void getResourceContent(in long callId, in unsigned long identifier);
    5959        void reloadPage();
    6060
     
    6666        void disableDebugger(in boolean always);
    6767
    68         void setBreakpoint(in String sourceID, in unsigned long lineNumber, in boolean enabled, in String condition);
     68        void setBreakpoint(in long callId, in String sourceID, in unsigned long lineNumber, in boolean enabled, in String condition);
    6969        void removeBreakpoint(in String sourceID, in unsigned long lineNumber);
    7070        void activateBreakpoints();
     
    8080        void setPauseOnExceptionsState(in long pauseOnExceptionsState);
    8181
    82         void editScriptSource(in String sourceID, in String newContent);
    83         void getScriptSource(in String sourceID);
     82        void editScriptSource(in long callId, in String sourceID, in String newContent);
     83        void getScriptSource(in long callId, in String sourceID);
    8484
    8585        void enableProfiler(in boolean always);
     
    8989        void stopProfiling();
    9090
    91         void getProfileHeaders();
    92         void getProfile(in unsigned long uid);
     91        void getProfileHeaders(in long callId);
     92        void getProfile(in long callId, in unsigned long uid);
    9393
    9494        void removeProfile(in unsigned long uid);
     
    9898#endif
    9999        void setInjectedScriptSource(in String scriptSource);
    100         void dispatchOnInjectedScript(in long injectedScriptId, in String methodName, in String arguments, in boolean async);
     100        void dispatchOnInjectedScript(in long callId, in long injectedScriptId, in String methodName, in String arguments, in boolean async);
    101101
    102102        void addScriptToEvaluateOnLoad(in String scriptSource);
    103103        void removeAllScriptsToEvaluateOnLoad();
    104104
    105         void getChildNodes(in long nodeId);
    106         [customResponse=didApplyDomChange] void setAttribute(in long elementId, in String name, in String value, out boolean success);
    107         [customResponse=didApplyDomChange] void removeAttribute(in long elementId, in String name, out boolean success);
    108         void setTextNodeValue(in long nodeId, in String value);
    109         void getEventListenersForNode(in long nodeId, out long nodeId, out Array listenersArray);
     105        void getChildNodes(in long callId, in long nodeId);
     106        [customResponse=didApplyDomChange] void setAttribute(in long callId, in long elementId, in String name, in String value, out boolean success);
     107        [customResponse=didApplyDomChange] void removeAttribute(in long callId, in long elementId, in String name, out boolean success);
     108        void setTextNodeValue(in long callId, in long nodeId, in String value);
     109        void getEventListenersForNode(in long callId, in long nodeId, out long nodeId, out Array listenersArray);
    110110        void copyNode(in long nodeId);
    111         void removeNode(in long nodeId, out long nodeId);
    112         void changeTagName(in long nodeId, in String newTagName, out long nodeId);
    113         void getOuterHTML(in long nodeId, out String outerHTML);
    114         void setOuterHTML(in long nodeId, in String outerHTML, out long nodeId);
     111        void removeNode(in long callId, in long nodeId, out long nodeId);
     112        void changeTagName(in long callId, in long nodeId, in String newTagName, out long nodeId);
     113        void getOuterHTML(in long callId, in long nodeId, out String outerHTML);
     114        void setOuterHTML(in long callId, in long nodeId, in String outerHTML, out long nodeId);
    115115        void addInspectedNode(in long nodeId);
    116116        void performSearch(in String query, in boolean runSynchronously);
    117117        void searchCanceled();
    118         void pushNodeByPathToFrontend(in String path, out long nodeId);
     118        void pushNodeByPathToFrontend(in long callId, in String path, out long nodeId);
    119119
    120120        void clearConsoleMessages();
     
    123123        void hideDOMNodeHighlight();
    124124
    125         void getStyles(in long nodeId, in boolean authOnly, out Value styles);
    126         void getAllStyles(out Array styles);
    127         void getInlineStyle(in long nodeId, out Value style);
    128         void getComputedStyle(in long nodeId, out Value style);
    129         void getStyleSheet(in long styleSheetId, out Value styleSheet);
    130         void getRuleRangesForStyleSheetId(in long styleSheetId);
    131         void applyStyleText(in long styleId, in String styleText, in String propertyName, out boolean success, out Value style, out Array changedProperties);
    132         void setStyleText(in long styleId, in String styleText, out boolean success);
    133         void setStyleProperty(in long styleId, in String name, in String value, out boolean success);
    134         void toggleStyleEnabled(in long styleId, in String propertyName, in boolean disabled, out Value style);
    135         void setRuleSelector(in long ruleId, in String selector, in long selectedNodeId, out Value rule, out boolean selectorAffectsNode);
    136         void addRule(in String selector, in long selectedNodeId, out Value rule, out boolean selectorAffectsNode);
     125        void getStyles(in long callId, in long nodeId, in boolean authOnly, out Value styles);
     126        void getAllStyles(in long callId, out Array styles);
     127        void getInlineStyle(in long callId, in long nodeId, out Value style);
     128        void getComputedStyle(in long callId, in long nodeId, out Value style);
     129        void getStyleSheet(in long callId, in long styleSheetId, out Value styleSheet);
     130        void getRuleRangesForStyleSheetId(in long callId, in long styleSheetId);
     131        void applyStyleText(in long callId, in long styleId, in String styleText, in String propertyName, out boolean success, out Value style, out Array changedProperties);
     132        void setStyleText(in long callId, in long styleId, in String styleText, out boolean success);
     133        void setStyleProperty(in long callId, in long styleId, in String name, in String value, out boolean success);
     134        void toggleStyleEnabled(in long callId, in long styleId, in String propertyName, in boolean disabled, out Value style);
     135        void setRuleSelector(in long callId, in long ruleId, in String selector, in long selectedNodeId, out Value rule, out boolean selectorAffectsNode);
     136        void addRule(in long callId, in String selector, in long selectedNodeId, out Value rule, out boolean selectorAffectsNode);
    137137
    138         void getCookies();
     138        void getCookies(in long callId);
    139139        void deleteCookie(in String cookieName, in String domain);
    140140
    141141#if defined(ENABLE_OFFLINE_WEB_APPLICATIONS) && ENABLE_OFFLINE_WEB_APPLICATIONS
    142         void getApplicationCaches();
     142        void getApplicationCaches(in long callId);
    143143#endif
    144144
    145145        void releaseWrapperObjectGroup(in long injectedScriptId, in String objectGroup);
    146         void didEvaluateForTestInFrontend(in String jsonResult);
     146        void didEvaluateForTestInFrontend(in long callId, in String jsonResult);
    147147
    148148#if defined(ENABLE_DATABASE) && ENABLE_DATABASE
    149         void getDatabaseTableNames(in long databaseId);
     149        void getDatabaseTableNames(in long callId, in long databaseId);
    150150#endif
    151151
    152152#if defined(ENABLE_DOM_STORAGE) && ENABLE_DOM_STORAGE
    153         void getDOMStorageEntries(in long storageId);
    154         void setDOMStorageItem(in long storageId, in String key, in String value);
    155         void removeDOMStorageItem(in long storageId, in String key);
     153        void getDOMStorageEntries(in long callId, in long storageId);
     154        void setDOMStorageItem(in long callId, in long storageId, in String key, in String value);
     155        void removeDOMStorageItem(in long callId, in long storageId, in String key);
    156156#endif
    157157    };
  • trunk/WebCore/inspector/InspectorValues.cpp

    r61414 r63561  
    651651}
    652652
     653PassRefPtr<InspectorValue> InspectorArray::get(size_t index)
     654{
     655    ASSERT(index < m_data.size());
     656    return m_data[index];
     657}
     658
    653659} // namespace WebCore
    654660
  • trunk/WebCore/inspector/InspectorValues.h

    r61414 r63561  
    199199    void pushString(const String&);
    200200    void push(PassRefPtr<InspectorValue>);
    201     unsigned length() { return m_data.size(); }
     201    unsigned length() const { return m_data.size(); }
     202
     203    PassRefPtr<InspectorValue> get(size_t index);
    202204
    203205    virtual void writeJSON(Vector<UChar>* output) const;
Note: See TracChangeset for help on using the changeset viewer.