Changeset 63109 in webkit
- Timestamp:
- Jul 12, 2010 1:50:45 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r63102 r63109 1 2010-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 1 19 2010-07-12 Andreas Kling <andreas.kling@nokia.com> 2 20 -
trunk/WebCore/dom/make_names.pl
r60570 r63109 38 38 use Switch; 39 39 40 sub readTags($$); 41 sub readAttrs($$); 42 40 43 my $printFactory = 0; 41 44 my $printWrapperFactory = 0; … … 44 47 my $attrsFile = ""; 45 48 my $outputDir = "."; 46 my %tags = (); 47 my %attrs = (); 49 my %parsedTags = (); 50 my %parsedAttrs = (); 51 my %enabledTags = (); 52 my %enabledAttrs = (); 53 my %allTags = (); 54 my %allAttrs = (); 48 55 my %parameters = (); 49 56 my $extraDefines = 0; 57 50 58 require Config; 59 51 60 my $gccLocation = ""; 52 61 if ($ENV{CC}) { … … 72 81 die "You must specify at least one of --tags <file> or --attrs <file>" unless (length($tagsFile) || length($attrsFile)); 73 82 74 readNames($tagsFile, "tags") if length($tagsFile); 75 readNames($attrsFile, "attrs") if length($attrsFile); 83 if (length($tagsFile)) { 84 %allTags = %{readTags($tagsFile, 0)}; 85 %enabledTags = %{readTags($tagsFile, 1)}; 86 } 87 88 if (length($attrsFile)) { 89 %allAttrs = %{readAttrs($attrsFile, 0)}; 90 %enabledAttrs = %{readAttrs($attrsFile, 1)}; 91 } 76 92 77 93 die "You must specify a namespace (e.g. SVG) for <namespace>Names.h" unless $parameters{namespace}; … … 150 166 151 167 # Initialize default property values. 152 $ tags{$tag} = { defaultTagPropertyHash($tag) } if !defined($tags{$tag});168 $parsedTags{$tag} = { defaultTagPropertyHash($tag) } if !defined($parsedTags{$tag}); 153 169 154 170 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}); 156 172 157 173 # The code relies on JSInterfaceName deriving from interfaceName to check for custom JSInterfaceName. 158 174 # 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; 162 178 } 163 179 } … … 170 186 171 187 # Initialize default properties' values. 172 $ attrs{$attr} = {} if !defined($attrs{$attr});188 $parsedAttrs{$attr} = {} if !defined($parsedAttrs{$attr}); 173 189 174 190 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; 177 193 } 178 194 } … … 191 207 ## Support routines 192 208 193 sub readNames 194 { 195 my ($namesFile, $type) = @_; 209 sub preprocessorCommand() 210 { 211 return $preprocessor if $extraDefines eq 0; 212 return $preprocessor . " -D" . join(" -D", split(" ", $extraDefines)); 213 } 214 215 sub readNames($$$$) 216 { 217 my ($namesFile, $hashToFillRef, $handler, $usePreprocessor) = @_; 196 218 197 219 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"; 201 222 } 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 } 208 225 209 226 my $InParser = InFilesParser->new(); 210 211 switch ($type) { 212 case "tags" { 213 $InParser->parse($names, \¶metersHandler, \&tagsHandler); 214 } 215 case "attrs" { 216 $InParser->parse($names, \¶metersHandler, \&attrsHandler); 217 } 218 else { 219 die "Do not know how to parse $type"; 220 } 221 } 227 $InParser->parse($names, \¶metersHandler, $handler); 222 228 223 229 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 234 sub readAttrs($$) 235 { 236 my ($namesFile, $usePreprocessor) = @_; 237 %parsedAttrs = (); 238 return readNames($namesFile, \%parsedAttrs, \&attrsHandler, $usePreprocessor); 239 } 240 241 sub readTags($$) 242 { 243 my ($namesFile, $usePreprocessor) = @_; 244 %parsedTags = (); 245 return readNames($namesFile, \%parsedTags, \&tagsHandler, $usePreprocessor); 226 246 } 227 247 … … 247 267 { 248 268 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}; 251 271 next if (usesDefaultWrapper($interfaceName)); 252 272 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}; 256 276 } 257 277 … … 273 293 if ($parameters{namespace} eq "HTML") { 274 294 print F ", HTMLFormElement*"; 275 print F " formElement" if $ tags{$tagName}{constructorNeedsFormElement};295 print F " formElement" if $enabledTags{$tagName}{constructorNeedsFormElement}; 276 296 } 277 297 print F ", bool"; 278 print F " createdByParser" if $ tags{$tagName}{constructorNeedsCreatedByParser};298 print F " createdByParser" if $enabledTags{$tagName}{constructorNeedsCreatedByParser}; 279 299 print F ")\n{\n"; 280 300 } … … 288 308 289 309 # Handle media elements. 290 if ($ tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {310 if ($enabledTags{$tagName}{wrapperOnlyIfMediaIsAvailable}) { 291 311 print F <<END 292 312 Settings* settings = document->settings(); … … 301 321 my $createSuffix = "::create"; 302 322 303 if ($ tags{$tagName}{createWithNew}) {323 if ($enabledTags{$tagName}{createWithNew}) { 304 324 $newPrefix = "new "; 305 325 $createSuffix = ""; … … 308 328 # Call the constructor with the right parameters. 309 329 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}; 312 332 print F ");\n}\n\n"; 313 333 } … … 323 343 my %uniqueTags = (); 324 344 for my $tagName (sort keys %tagConstructorMap) { 325 my $interfaceName = $ tags{$tagName}{interfaceName};345 my $interfaceName = $enabledTags{$tagName}{interfaceName}; 326 346 327 347 # Ignore the mapped tag 328 348 # 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}); 330 350 331 351 $uniqueTags{$interfaceName} = '1'; 332 352 333 my $conditional = $ tags{$tagName}{conditional};353 my $conditional = $enabledTags{$tagName}{conditional}; 334 354 if ($conditional) { 335 355 my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")"; … … 347 367 # Mapped tag name uses a special wrapper to keep their prefix and namespaceURI while using the mapped localname. 348 368 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}; 351 371 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())"); 353 373 } 354 374 } … … 364 384 for my $tagName (sort keys %tagConstructorMap) { 365 385 366 my $conditional = $ tags{$tagName}{conditional};386 my $conditional = $enabledTags{$tagName}{conditional}; 367 387 if ($conditional) { 368 388 my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")"; … … 370 390 } 371 391 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"; 374 394 } else { 375 395 print F " addTag(${tagName}Tag, $tagConstructorMap{$tagName}Constructor);\n"; … … 457 477 print F "extern const WebCore::AtomicString ${lowerNamespace}NamespaceURI;\n\n"; 458 478 459 if (keys % tags) {479 if (keys %allTags) { 460 480 print F "// Tags\n"; 461 printMacros($F, "extern const WebCore::QualifiedName", "Tag", \% tags);481 printMacros($F, "extern const WebCore::QualifiedName", "Tag", \%allTags); 462 482 } 463 483 464 if (keys %a ttrs) {484 if (keys %allAttrs) { 465 485 print F "// Attributes\n"; 466 printMacros($F, "extern const WebCore::QualifiedName", "Attr", \%a ttrs);486 printMacros($F, "extern const WebCore::QualifiedName", "Attr", \%allAttrs); 467 487 } 468 488 print F "#endif\n\n"; 469 489 470 if (keys % tags) {490 if (keys %allTags) { 471 491 print F "WebCore::QualifiedName** get$parameters{namespace}Tags(size_t* size);\n"; 472 492 } 473 493 474 if (keys %a ttrs) {494 if (keys %allAttrs) { 475 495 print F "WebCore::QualifiedName** get$parameters{namespace}Attrs(size_t* size);\n"; 476 496 } … … 512 532 "; 513 533 514 if (keys % tags) {534 if (keys %allTags) { 515 535 print F "// Tags\n"; 516 for my $name (sort keys % tags) {536 for my $name (sort keys %allTags) { 517 537 print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Tag, nullAtom, \"$name\", ${lowerNamespace}NamespaceURI);\n"; 518 538 } … … 520 540 print F "\n\nWebCore::QualifiedName** get$parameters{namespace}Tags(size_t* size)\n"; 521 541 print F "{\n static WebCore::QualifiedName* $parameters{namespace}Tags[] = {\n"; 522 for my $name (sort keys % tags) {542 for my $name (sort keys %allTags) { 523 543 print F " (WebCore::QualifiedName*)&${name}Tag,\n"; 524 544 } 525 545 print F " };\n"; 526 print F " *size = ", scalar(keys % tags), ";\n";546 print F " *size = ", scalar(keys %allTags), ";\n"; 527 547 print F " return $parameters{namespace}Tags;\n"; 528 548 print F "}\n"; 529 549 } 530 550 531 if (keys %a ttrs) {551 if (keys %allAttrs) { 532 552 print F "\n// Attributes\n"; 533 for my $name (sort keys %a ttrs) {553 for my $name (sort keys %allAttrs) { 534 554 print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Attr, nullAtom, \"$name\", ${lowerNamespace}NamespaceURI);\n"; 535 555 } 536 556 print F "\n\nWebCore::QualifiedName** get$parameters{namespace}Attrs(size_t* size)\n"; 537 557 print F "{\n static WebCore::QualifiedName* $parameters{namespace}Attr[] = {\n"; 538 for my $name (sort keys %a ttrs) {558 for my $name (sort keys %allAttrs) { 539 559 print F " (WebCore::QualifiedName*)&${name}Attr,\n"; 540 560 } 541 561 print F " };\n"; 542 print F " *size = ", scalar(keys %a ttrs), ";\n";562 print F " *size = ", scalar(keys %allAttrs), ";\n"; 543 563 print F " return $parameters{namespace}Attr;\n"; 544 564 print F "}\n"; … … 561 581 print(F " // Namespace\n"); 562 582 print(F " new ((void*)&${lowerNamespace}NamespaceURI) AtomicString(${lowerNamespace}NS);\n\n"); 563 if (keys % tags) {583 if (keys %allTags) { 564 584 my $tagsNamespace = $parameters{tagsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS"; 565 printDefinitions($F, \% tags, "tags", $tagsNamespace);566 } 567 if (keys %a ttrs) {585 printDefinitions($F, \%allTags, "tags", $tagsNamespace); 586 } 587 if (keys %allAttrs) { 568 588 my $attrsNamespace = $parameters{attrsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS"; 569 printDefinitions($F, \%a ttrs, "attributes", $attrsNamespace);589 printDefinitions($F, \%allAttrs, "attributes", $attrsNamespace); 570 590 } 571 591 … … 580 600 581 601 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}; 584 604 next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName); 585 605 $tagsSeen{$JSInterfaceName} = 1; … … 594 614 595 615 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}; 598 618 next if defined($tagsSeen{$interfaceName}); 599 619 $tagsSeen{$interfaceName} = 1; … … 816 836 817 837 # 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"; 819 839 } 820 840 … … 825 845 826 846 my %tagsSeen; 827 for my $tagName (sort keys % tags) {847 for my $tagName (sort keys %enabledTags) { 828 848 # Avoid defining the same wrapper method twice. 829 my $JSInterfaceName = $ tags{$tagName}{JSInterfaceName};849 my $JSInterfaceName = $enabledTags{$tagName}{JSInterfaceName}; 830 850 next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName); 831 851 $tagsSeen{$JSInterfaceName} = 1; 832 852 833 my $conditional = $ tags{$tagName}{conditional};853 my $conditional = $enabledTags{$tagName}{conditional}; 834 854 if ($conditional) { 835 855 my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")"; … … 840 860 # Hack for the media tags 841 861 # 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}) { 843 863 print F <<END 844 864 static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element) … … 863 883 } 864 884 } elsif ($wrapperFactoryType eq "V8") { 865 if ($ tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {885 if ($enabledTags{$tagName}{wrapperOnlyIfMediaIsAvailable}) { 866 886 print F <<END 867 887 static v8::Handle<v8::Value> create${JSInterfaceName}Wrapper($parameters{namespace}Element* element) … … 985 1005 } 986 1006 987 for my $tag (sort keys % tags) {1007 for my $tag (sort keys %enabledTags) { 988 1008 # 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}; 992 1012 if ($conditional) { 993 1013 my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")"; … … 995 1015 } 996 1016 997 my $ucTag = $ tags{$tag}{JSInterfaceName};1017 my $ucTag = $enabledTags{$tag}{JSInterfaceName}; 998 1018 print F " map.set(${tag}Tag.localName().impl(), create${ucTag}Wrapper);\n"; 999 1019
Note: See TracChangeset
for help on using the changeset viewer.