Changeset 63109 in webkit


Ignore:
Timestamp:
Jul 12, 2010 1:50:45 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-07-10 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

make_names.pl should always generate all names in Names.* files
https://bugs.webkit.org/show_bug.cgi?id=42023

Only the *ElementFactory files need to have conditional contents
based on enabled features. WebCore should always have all known
names for SVG, MathML, XML, XLink, HTML, etc. generated in the
various *Names files, even if features are disabled.

make_names.pl is kinda a big hack at this point. I tried to clean
up a little as I went. The way I made *Names include all names was to
read the .in files twice, once using the preprocessor and once without.

  • dom/make_names.pl:
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63102 r63109  
     12010-07-10  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        make_names.pl should always generate all names in Names.* files
     6        https://bugs.webkit.org/show_bug.cgi?id=42023
     7
     8        Only the *ElementFactory files need to have conditional contents
     9        based on enabled features.  WebCore should always have all known
     10        names for SVG, MathML, XML, XLink, HTML, etc. generated in the
     11        various *Names files, even if features are disabled.
     12
     13        make_names.pl is kinda a big hack at this point.  I tried to clean
     14        up a little as I went.  The way I made *Names include all names was to
     15        read the .in files twice, once using the preprocessor and once without.
     16
     17        * dom/make_names.pl:
     18
    1192010-07-12  Andreas Kling  <andreas.kling@nokia.com>
    220
  • trunk/WebCore/dom/make_names.pl

    r60570 r63109  
    3838use Switch;
    3939
     40sub readTags($$);
     41sub readAttrs($$);
     42
    4043my $printFactory = 0;
    4144my $printWrapperFactory = 0;
     
    4447my $attrsFile = "";
    4548my $outputDir = ".";
    46 my %tags = ();
    47 my %attrs = ();
     49my %parsedTags = ();
     50my %parsedAttrs = ();
     51my %enabledTags = ();
     52my %enabledAttrs = ();
     53my %allTags = ();
     54my %allAttrs = ();
    4855my %parameters = ();
    4956my $extraDefines = 0;
     57
    5058require Config;
     59
    5160my $gccLocation = "";
    5261if ($ENV{CC}) {
     
    7281die "You must specify at least one of --tags <file> or --attrs <file>" unless (length($tagsFile) || length($attrsFile));
    7382
    74 readNames($tagsFile, "tags") if length($tagsFile);
    75 readNames($attrsFile, "attrs") if length($attrsFile);
     83if (length($tagsFile)) {
     84    %allTags = %{readTags($tagsFile, 0)};
     85    %enabledTags = %{readTags($tagsFile, 1)};
     86}
     87
     88if (length($attrsFile)) {
     89    %allAttrs = %{readAttrs($attrsFile, 0)};
     90    %enabledAttrs = %{readAttrs($attrsFile, 1)};
     91}
    7692
    7793die "You must specify a namespace (e.g. SVG) for <namespace>Names.h" unless $parameters{namespace};
     
    150166
    151167    # Initialize default property values.
    152     $tags{$tag} = { defaultTagPropertyHash($tag) } if !defined($tags{$tag});
     168    $parsedTags{$tag} = { defaultTagPropertyHash($tag) } if !defined($parsedTags{$tag});
    153169
    154170    if ($property) {
    155         die "Unknown property $property for tag $tag\n" if !defined($tags{$tag}{$property});
     171        die "Unknown property $property for tag $tag\n" if !defined($parsedTags{$tag}{$property});
    156172
    157173        # The code relies on JSInterfaceName deriving from interfaceName to check for custom JSInterfaceName.
    158174        # So override JSInterfaceName if it was not already set.
    159         $tags{$tag}{JSInterfaceName} = $value if $property eq "interfaceName" && $tags{$tag}{JSInterfaceName} eq $tags{$tag}{interfaceName};
    160 
    161         $tags{$tag}{$property} = $value;
     175        $parsedTags{$tag}{JSInterfaceName} = $value if $property eq "interfaceName" && $parsedTags{$tag}{JSInterfaceName} eq $parsedTags{$tag}{interfaceName};
     176
     177        $parsedTags{$tag}{$property} = $value;
    162178    }
    163179}
     
    170186
    171187    # Initialize default properties' values.
    172     $attrs{$attr} = {} if !defined($attrs{$attr});
     188    $parsedAttrs{$attr} = {} if !defined($parsedAttrs{$attr});
    173189
    174190    if ($property) {
    175         die "Unknown property $property for attribute $attr\n" if !defined($attrs{$attr}{$property});
    176         $attrs{$attr}{$property} = $value;
     191        die "Unknown property $property for attribute $attr\n" if !defined($parsedAttrs{$attr}{$property});
     192        $parsedAttrs{$attr}{$property} = $value;
    177193    }
    178194}
     
    191207## Support routines
    192208
    193 sub readNames
    194 {
    195     my ($namesFile, $type) = @_;
     209sub preprocessorCommand()
     210{
     211    return $preprocessor if $extraDefines eq 0;
     212    return $preprocessor . " -D" . join(" -D", split(" ", $extraDefines));
     213}
     214
     215sub readNames($$$$)
     216{
     217    my ($namesFile, $hashToFillRef, $handler, $usePreprocessor) = @_;
    196218
    197219    my $names = new IO::File;
    198 
    199     if ($extraDefines eq 0) {
    200         open($names, $preprocessor . " " . $namesFile . "|") or die "Failed to open file: $namesFile";
     220    if ($usePreprocessor) {
     221        open($names, preprocessorCommand() . " " . $namesFile . "|") or die "Failed to open file: $namesFile";
    201222    } else {
    202         open($names, $preprocessor . " -D" . join(" -D", split(" ", $extraDefines)) . " " . $namesFile . "|") or die "Failed to open file: $namesFile";
    203     }
    204 
    205     # Store hashes keys count to know if some insertion occured.
    206     my $tagsCount = keys %tags;
    207     my $attrsCount = keys %attrs;
     223        open($names, $namesFile) or die "Failed to open file: $namesFile";
     224    }
    208225
    209226    my $InParser = InFilesParser->new();
    210 
    211     switch ($type) {
    212         case "tags" {
    213             $InParser->parse($names, \&parametersHandler, \&tagsHandler);
    214         }
    215         case "attrs" {
    216             $InParser->parse($names, \&parametersHandler, \&attrsHandler);
    217         }
    218         else {
    219             die "Do not know how to parse $type";
    220         }
    221     }
     227    $InParser->parse($names, \&parametersHandler, $handler);
    222228
    223229    close($names);
    224 
    225     die "Failed to read names from file: $namesFile" if ((keys %tags == $tagsCount) && (keys %attrs == $attrsCount));
     230    die "Failed to read names from file: $namesFile" if (keys %{$hashToFillRef} == 0);
     231    return $hashToFillRef;
     232}
     233
     234sub readAttrs($$)
     235{
     236    my ($namesFile, $usePreprocessor) = @_;
     237    %parsedAttrs = ();
     238    return readNames($namesFile, \%parsedAttrs, \&attrsHandler, $usePreprocessor);
     239}
     240
     241sub readTags($$)
     242{
     243    my ($namesFile, $usePreprocessor) = @_;
     244    %parsedTags = ();
     245    return readNames($namesFile, \%parsedTags, \&tagsHandler, $usePreprocessor);
    226246}
    227247
     
    247267{
    248268    my %tagConstructorMap = ();
    249     for my $tagName (keys %tags) {
    250         my $interfaceName = $tags{$tagName}{interfaceName};
     269    for my $tagName (keys %enabledTags) {
     270        my $interfaceName = $enabledTags{$tagName}{interfaceName};
    251271        next if (usesDefaultWrapper($interfaceName));
    252272
    253         if ($tags{$tagName}{mapToTagName}) {
    254             die "Cannot handle multiple mapToTagName for $tagName\n" if $tags{$tags{$tagName}{mapToTagName}}{mapToTagName};
    255             $interfaceName = $tags{ $tags{$tagName}{mapToTagName} }{interfaceName};
     273        if ($enabledTags{$tagName}{mapToTagName}) {
     274            die "Cannot handle multiple mapToTagName for $tagName\n" if $enabledTags{$enabledTags{$tagName}{mapToTagName}}{mapToTagName};
     275            $interfaceName = $enabledTags{ $enabledTags{$tagName}{mapToTagName} }{interfaceName};
    256276        }
    257277
     
    273293    if ($parameters{namespace} eq "HTML") {
    274294        print F ", HTMLFormElement*";
    275         print F " formElement" if $tags{$tagName}{constructorNeedsFormElement};
     295        print F " formElement" if $enabledTags{$tagName}{constructorNeedsFormElement};
    276296    }
    277297    print F ", bool";
    278     print F " createdByParser" if $tags{$tagName}{constructorNeedsCreatedByParser};
     298    print F " createdByParser" if $enabledTags{$tagName}{constructorNeedsCreatedByParser};
    279299    print F ")\n{\n";
    280300}
     
    288308
    289309    # Handle media elements.
    290     if ($tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {
     310    if ($enabledTags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {
    291311        print F <<END
    292312    Settings* settings = document->settings();
     
    301321    my $createSuffix = "::create";
    302322
    303     if ($tags{$tagName}{createWithNew}) {
     323    if ($enabledTags{$tagName}{createWithNew}) {
    304324        $newPrefix = "new ";
    305325        $createSuffix = "";
     
    308328    # Call the constructor with the right parameters.
    309329    print F "    return $newPrefix$interfaceName${createSuffix}($constructorTagName, document";
    310     print F ", formElement" if $tags{$tagName}{constructorNeedsFormElement};
    311     print F ", createdByParser" if $tags{$tagName}{constructorNeedsCreatedByParser};
     330    print F ", formElement" if $enabledTags{$tagName}{constructorNeedsFormElement};
     331    print F ", createdByParser" if $enabledTags{$tagName}{constructorNeedsCreatedByParser};
    312332    print F ");\n}\n\n";
    313333}
     
    323343    my %uniqueTags = ();
    324344    for my $tagName (sort keys %tagConstructorMap) {
    325         my $interfaceName = $tags{$tagName}{interfaceName};
     345        my $interfaceName = $enabledTags{$tagName}{interfaceName};
    326346
    327347        # Ignore the mapped tag
    328348        # FIXME: It could be moved inside this loop but was split for readibility.
    329         next if (defined($uniqueTags{$interfaceName}) || $tags{$tagName}{mapToTagName});
     349        next if (defined($uniqueTags{$interfaceName}) || $enabledTags{$tagName}{mapToTagName});
    330350
    331351        $uniqueTags{$interfaceName} = '1';
    332352
    333         my $conditional = $tags{$tagName}{conditional};
     353        my $conditional = $enabledTags{$tagName}{conditional};
    334354        if ($conditional) {
    335355            my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
     
    347367    # Mapped tag name uses a special wrapper to keep their prefix and namespaceURI while using the mapped localname.
    348368    for my $tagName (sort keys %tagConstructorMap) {
    349         if ($tags{$tagName}{mapToTagName}) {
    350             my $mappedName = $tags{$tagName}{mapToTagName};
     369        if ($enabledTags{$tagName}{mapToTagName}) {
     370            my $mappedName = $enabledTags{$tagName}{mapToTagName};
    351371            printConstructorSignature($F, $mappedName, $mappedName . "To" . $tagName, "tagName");
    352             printConstructorInterior($F, $mappedName, $tags{$mappedName}{interfaceName}, "QualifiedName(tagName.prefix(), ${mappedName}Tag.localName(), tagName.namespaceURI())");
     372            printConstructorInterior($F, $mappedName, $enabledTags{$mappedName}{interfaceName}, "QualifiedName(tagName.prefix(), ${mappedName}Tag.localName(), tagName.namespaceURI())");
    353373        }
    354374    }
     
    364384    for my $tagName (sort keys %tagConstructorMap) {
    365385
    366         my $conditional = $tags{$tagName}{conditional};
     386        my $conditional = $enabledTags{$tagName}{conditional};
    367387        if ($conditional) {
    368388            my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
     
    370390        }
    371391
    372         if ($tags{$tagName}{mapToTagName}) {
    373             print F "    addTag(${tagName}Tag, $tags{$tagName}{mapToTagName}To${tagName}Constructor);\n";
     392        if ($enabledTags{$tagName}{mapToTagName}) {
     393            print F "    addTag(${tagName}Tag, $enabledTags{$tagName}{mapToTagName}To${tagName}Constructor);\n";
    374394        } else {
    375395            print F "    addTag(${tagName}Tag, $tagConstructorMap{$tagName}Constructor);\n";
     
    457477    print F "extern const WebCore::AtomicString ${lowerNamespace}NamespaceURI;\n\n";
    458478
    459     if (keys %tags) {
     479    if (keys %allTags) {
    460480        print F "// Tags\n";
    461         printMacros($F, "extern const WebCore::QualifiedName", "Tag", \%tags);
     481        printMacros($F, "extern const WebCore::QualifiedName", "Tag", \%allTags);
    462482    }
    463483   
    464     if (keys %attrs) {
     484    if (keys %allAttrs) {
    465485        print F "// Attributes\n";
    466         printMacros($F, "extern const WebCore::QualifiedName", "Attr", \%attrs);
     486        printMacros($F, "extern const WebCore::QualifiedName", "Attr", \%allAttrs);
    467487    }
    468488    print F "#endif\n\n";
    469489
    470     if (keys %tags) {
     490    if (keys %allTags) {
    471491        print F "WebCore::QualifiedName** get$parameters{namespace}Tags(size_t* size);\n";
    472492    }
    473493
    474     if (keys %attrs) {
     494    if (keys %allAttrs) {
    475495        print F "WebCore::QualifiedName** get$parameters{namespace}Attrs(size_t* size);\n";
    476496    }
     
    512532";
    513533
    514     if (keys %tags) {
     534    if (keys %allTags) {
    515535        print F "// Tags\n";
    516         for my $name (sort keys %tags) {
     536        for my $name (sort keys %allTags) {
    517537            print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Tag, nullAtom, \"$name\", ${lowerNamespace}NamespaceURI);\n";
    518538        }
     
    520540        print F "\n\nWebCore::QualifiedName** get$parameters{namespace}Tags(size_t* size)\n";
    521541        print F "{\n    static WebCore::QualifiedName* $parameters{namespace}Tags[] = {\n";
    522         for my $name (sort keys %tags) {
     542        for my $name (sort keys %allTags) {
    523543            print F "        (WebCore::QualifiedName*)&${name}Tag,\n";
    524544        }
    525545        print F "    };\n";
    526         print F "    *size = ", scalar(keys %tags), ";\n";
     546        print F "    *size = ", scalar(keys %allTags), ";\n";
    527547        print F "    return $parameters{namespace}Tags;\n";
    528548        print F "}\n";
    529549    }
    530550
    531     if (keys %attrs) {
     551    if (keys %allAttrs) {
    532552        print F "\n// Attributes\n";
    533         for my $name (sort keys %attrs) {
     553        for my $name (sort keys %allAttrs) {
    534554            print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Attr, nullAtom, \"$name\", ${lowerNamespace}NamespaceURI);\n";
    535555        }
    536556        print F "\n\nWebCore::QualifiedName** get$parameters{namespace}Attrs(size_t* size)\n";
    537557        print F "{\n    static WebCore::QualifiedName* $parameters{namespace}Attr[] = {\n";
    538         for my $name (sort keys %attrs) {
     558        for my $name (sort keys %allAttrs) {
    539559            print F "        (WebCore::QualifiedName*)&${name}Attr,\n";
    540560        }
    541561        print F "    };\n";
    542         print F "    *size = ", scalar(keys %attrs), ";\n";
     562        print F "    *size = ", scalar(keys %allAttrs), ";\n";
    543563        print F "    return $parameters{namespace}Attr;\n";
    544564        print F "}\n";
     
    561581    print(F "    // Namespace\n");
    562582    print(F "    new ((void*)&${lowerNamespace}NamespaceURI) AtomicString(${lowerNamespace}NS);\n\n");
    563     if (keys %tags) {
     583    if (keys %allTags) {
    564584        my $tagsNamespace = $parameters{tagsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS";
    565         printDefinitions($F, \%tags, "tags", $tagsNamespace);
    566     }
    567     if (keys %attrs) {
     585        printDefinitions($F, \%allTags, "tags", $tagsNamespace);
     586    }
     587    if (keys %allAttrs) {
    568588        my $attrsNamespace = $parameters{attrsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS";
    569         printDefinitions($F, \%attrs, "attributes", $attrsNamespace);
     589        printDefinitions($F, \%allAttrs, "attributes", $attrsNamespace);
    570590    }
    571591
     
    580600
    581601    my %tagsSeen;
    582     for my $tagName (sort keys %tags) {
    583         my $JSInterfaceName = $tags{$tagName}{JSInterfaceName};
     602    for my $tagName (sort keys %enabledTags) {
     603        my $JSInterfaceName = $enabledTags{$tagName}{JSInterfaceName};
    584604        next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName);
    585605        $tagsSeen{$JSInterfaceName} = 1;
     
    594614
    595615    my %tagsSeen;
    596     for my $tagName (sort keys %tags) {
    597         my $interfaceName = $tags{$tagName}{interfaceName};
     616    for my $tagName (sort keys %enabledTags) {
     617        my $interfaceName = $enabledTags{$tagName}{interfaceName};
    598618        next if defined($tagsSeen{$interfaceName});
    599619        $tagsSeen{$interfaceName} = 1;
     
    816836
    817837    # A tag reuses the default wrapper if its JSInterfaceName matches the default namespace Element.
    818     return $tags{$name}{JSInterfaceName} eq $parameters{namespace} . "Element" || $tags{$name}{JSInterfaceName} eq "HTMLNoScriptElement";
     838    return $enabledTags{$name}{JSInterfaceName} eq $parameters{namespace} . "Element" || $enabledTags{$name}{JSInterfaceName} eq "HTMLNoScriptElement";
    819839}
    820840
     
    825845
    826846    my %tagsSeen;
    827     for my $tagName (sort keys %tags) {
     847    for my $tagName (sort keys %enabledTags) {
    828848        # Avoid defining the same wrapper method twice.
    829         my $JSInterfaceName = $tags{$tagName}{JSInterfaceName};
     849        my $JSInterfaceName = $enabledTags{$tagName}{JSInterfaceName};
    830850        next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName);
    831851        $tagsSeen{$JSInterfaceName} = 1;
    832852
    833         my $conditional = $tags{$tagName}{conditional};
     853        my $conditional = $enabledTags{$tagName}{conditional};
    834854        if ($conditional) {
    835855            my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
     
    840860            # Hack for the media tags
    841861            # FIXME: This should have been done via a CustomWrapper attribute and a separate *Custom file.
    842             if ($tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {
     862            if ($enabledTags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {
    843863                print F <<END
    844864static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element)
     
    863883            }
    864884        } elsif ($wrapperFactoryType eq "V8") {
    865             if ($tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {
     885            if ($enabledTags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {
    866886                print F <<END
    867887static v8::Handle<v8::Value> create${JSInterfaceName}Wrapper($parameters{namespace}Element* element)
     
    9851005    }
    9861006
    987     for my $tag (sort keys %tags) {
     1007    for my $tag (sort keys %enabledTags) {
    9881008        # Do not add the name to the map if it does not have a JS wrapper constructor or uses the default wrapper.
    989         next if usesDefaultJSWrapper($tag, \%tags);
    990 
    991         my $conditional = $tags{$tag}{conditional};
     1009        next if usesDefaultJSWrapper($tag, \%enabledTags);
     1010
     1011        my $conditional = $enabledTags{$tag}{conditional};
    9921012        if ($conditional) {
    9931013            my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
     
    9951015        }
    9961016
    997         my $ucTag = $tags{$tag}{JSInterfaceName};
     1017        my $ucTag = $enabledTags{$tag}{JSInterfaceName};
    9981018        print F "       map.set(${tag}Tag.localName().impl(), create${ucTag}Wrapper);\n";
    9991019
Note: See TracChangeset for help on using the changeset viewer.