From 635860845790a19bf50bbc51ba8fb66a96dde068 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Thu, 5 Mar 2009 14:34:32 -0800 Subject: auto import from //depot/cupcake/@136594 --- WebCore/dom/make_names.pl | 319 ++++++++++++++++++++++++---------------------- 1 file changed, 169 insertions(+), 150 deletions(-) (limited to 'WebCore/dom/make_names.pl') diff --git a/WebCore/dom/make_names.pl b/WebCore/dom/make_names.pl index c0d0d86..f9eba88 100755 --- a/WebCore/dom/make_names.pl +++ b/WebCore/dom/make_names.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl -w -# Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. +# Copyright (C) 2005, 2006, 2007, 2009 Apple Inc. All rights reserved. +# Copyright (C) 2009, Julien Chaffraix # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -45,8 +46,6 @@ my %attrs = (); my %parameters = (); my $extraDefines = 0; my $preprocessor = "/usr/bin/gcc -E -P -x c++"; -my %svgCustomMappings = (); -my %htmlCustomMappings = (); GetOptions('tags=s' => \$tagsFile, 'attrs=s' => \$attrsFile, @@ -88,9 +87,13 @@ if ($printWrapperFactory) { sub initializeTagPropertyHash { - return ('interfaceName' => upperCaseName($_[0])."Element", - 'applyAudioHack' => 0, - 'exportString' => 0); + return ('constructorNeedsCreatedByParser' => 0, + 'constructorNeedsFormElement' => 0, + 'exportString' => 0, + 'interfaceName' => defaultInterfaceName($_[0]), + # By default, the JSInterfaceName is the same as the interfaceName. + 'JSInterfaceName' => defaultInterfaceName($_[0]), + 'wrapperOnlyIfMediaIsAvailable' => 0); } sub initializeAttrPropertyHash @@ -109,6 +112,12 @@ sub initializeParametersHash 'exportStrings' => 0); } +sub defaultInterfaceName +{ + die "No namespace found" if !$parameters{'namespace'}; + return $parameters{'namespace'} . upperCaseName($_[0]) . "Element" +} + ### Parsing handlers sub tagsHandler @@ -122,6 +131,11 @@ sub tagsHandler if ($property) { die "Unknown property $property for tag $tag\n" if !defined($tags{$tag}{$property}); + # The code rely on JSInterfaceName deriving from interfaceName to check for custom JSInterfaceName. + # So just override JSInterfaceName if it was not already set. + if ($property eq "interfaceName" && $tags{$tag}{'JSInterfaceName'} eq $tags{$tag}{'interfaceName'}) { + $tags{$tag}{'JSInterfaceName'} = $value; + } $tags{$tag}{$property} = $value; } } @@ -205,25 +219,44 @@ sub printMacros sub printConstructors { - my ($F, $namesRef) = @_; - my %names = %$namesRef; + my $F = shift; print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'}; - for my $name (sort keys %names) { - my $ucName = $names{$name}{"interfaceName"}; + for my $name (sort keys %tags) { + my $ucName = $tags{$name}{'interfaceName'}; + + # Print the method signature avoiding unused arguments' name. + print F "static PassRefPtr<$parameters{'namespace'}Element> ${name}Constructor(Document* doc"; + if ($parameters{'namespace'} eq "HTML") { + print F ", HTMLFormElement* formElement"; + if ($tags{$name}{'constructorNeedsFormElement'}) { + print F " formElement"; + } + } + print F ", bool"; + if ($tags{$name}{'constructorNeedsCreatedByParser'}) { + print F " createdByParser"; + } + print F ")\n{\n"; - print F "$parameters{'namespace'}Element* ${name}Constructor(Document* doc, bool createdByParser)\n"; - print F "{\n"; - print F " return new $parameters{'namespace'}${ucName}($parameters{'namespace'}Names::${name}Tag, doc);\n"; - print F "}\n\n"; + # Now call the constructor with the right parameters. + print F " return new ${ucName}($parameters{'namespace'}Names::${name}Tag, doc"; + if ($tags{$name}{'constructorNeedsFormElement'}) { + print F ", formElement"; + } + if ($tags{$name}{'constructorNeedsCreatedByParser'}) { + print F ", createdByParser"; + } + print F ");\n}\n\n"; } print F "#endif\n" if $parameters{'guardFactoryWith'}; } sub printFunctionInits { - my ($F, $namesRef) = @_; - for my $name (sort keys %$namesRef) { + my $F = shift; + + for my $name (sort keys %tags) { print F " gFunctionMap->set($parameters{'namespace'}Names::${name}Tag.localName().impl(), ${name}Constructor);\n"; } } @@ -308,16 +341,23 @@ sub printNamesHeaderFile if (keys %tags) { print F "// Tags\n"; printMacros($F, "extern const WebCore::QualifiedName", "Tag", \%tags); - print F "\n\nWebCore::QualifiedName** get$parameters{'namespace'}Tags(size_t* size);\n"; } if (keys %attrs) { print F "// Attributes\n"; printMacros($F, "extern const WebCore::QualifiedName", "Attr", \%attrs); - print F "\n\nWebCore::QualifiedName** get$parameters{'namespace'}Attr(size_t* size);\n"; } print F "#endif\n\n"; - print F "void init();\n\n"; + + if (keys %tags) { + print F "WebCore::QualifiedName** get$parameters{'namespace'}Tags(size_t* size);\n"; + } + + if (keys %attrs) { + print F "WebCore::QualifiedName** get$parameters{'namespace'}Attrs(size_t* size);\n"; + } + + print F "\nvoid init();\n\n"; print F "} }\n\n"; print F "#endif\n\n"; @@ -425,25 +465,29 @@ print F "\nvoid init() sub printJSElementIncludes { - my ($F, $namesRef) = @_; - my %names = %$namesRef; - for my $name (sort keys %names) { - next if (hasCustomMapping($name)); + my $F = shift; + + my %tagsSeen; + for my $tagName (sort keys %tags) { + my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"}; + next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName); + $tagsSeen{$JSInterfaceName} = 1; - my $ucName = $names{$name}{"interfaceName"}; - print F "#include \"JS$parameters{'namespace'}${ucName}.h\"\n"; + print F "#include \"JS${JSInterfaceName}.h\"\n"; } } sub printElementIncludes { - my ($F, $namesRef, $shouldSkipCustomMappings) = @_; - my %names = %$namesRef; - for my $name (sort keys %names) { - next if ($shouldSkipCustomMappings && hasCustomMapping($name)); + my $F = shift; - my $ucName = $names{$name}{"interfaceName"}; - print F "#include \"$parameters{'namespace'}${ucName}.h\"\n"; + my %tagsSeen; + for my $tagName (sort keys %tags) { + my $interfaceName = $tags{$tagName}{"interfaceName"}; + next if defined($tagsSeen{$interfaceName}); + $tagsSeen{$interfaceName} = 1; + + print F "#include \"${interfaceName}.h\"\n"; } } @@ -515,15 +559,30 @@ print F < using namespace WebCore; -typedef $parameters{'namespace'}Element* (*ConstructorFunc)(Document* doc, bool createdByParser); -typedef WTF::HashMap FunctionMap; +END +; + +print F "typedef PassRefPtr<$parameters{'namespace'}Element> (*ConstructorFunction)(Document*"; + +if ($parameters{'namespace'} eq "HTML") { + print F ", HTMLFormElement* formElement"; +} + +print F ", bool createdByParser);\n"; + +print F < FunctionMap; static FunctionMap* gFunctionMap = 0; @@ -532,7 +591,7 @@ namespace WebCore { END ; -printConstructors($F, \%tags); +printConstructors($F); print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'}; @@ -548,16 +607,18 @@ static inline void createFunctionMapIfNecessary() END ; -printFunctionInits($F, \%tags); +printFunctionInits($F); print F "}\n"; -print F "#endif\n\n" if $parameters{'guardFactoryWith'}; +print F "#endif\n" if $parameters{'guardFactoryWith'}; -print F < $parameters{'namespace'}ElementFactory::create$parameters{'namespace'}Element(const QualifiedName& qName, Document* doc"; + +if ($parameters{"namespace"} eq "HTML") { + print F ", HTMLFormElement* formElement"; +} + +print F ", bool createdByParser)\n{\n"; print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'}; @@ -573,14 +634,19 @@ print F <get(qName.localName().impl()); + ConstructorFunction func = gFunctionMap->get(qName.localName().impl()); if (func) - return func(doc, createdByParser); - - return new $parameters{'namespace'}Element(qName, doc); END ; +if ($parameters{"namespace"} eq "HTML") { + print F " return func(doc, formElement, createdByParser);\n"; +} else { + print F " return func(doc, createdByParser);\n"; +} + +print F " return new $parameters{'namespace'}Element(qName, doc);\n"; + if ($parameters{'guardFactoryWith'}) { print F < -print F " namespace WebCore { class Element; class Document; @@ -625,121 +693,79 @@ namespace WebCore { namespace WebCore { class $parameters{'namespace'}Element; +END +; + +if ($parameters{'namespace'} eq "HTML") { + print F " class HTMLFormElement;\n"; +} +print F< createElement(const WebCore::QualifiedName&, WebCore::Document*, bool createdByParser = true); +END +; +print F " static PassRefPtr<$parameters{'namespace'}Element> create$parameters{'namespace'}Element(const WebCore::QualifiedName&, WebCore::Document*"; + +if ($parameters{'namespace'} eq "HTML") { + print F ", HTMLFormElement* = 0"; +} + +print F ", bool /*createdByParser*/ = true);\n"; + +printf F< '', - 'hkern' => '', - 'mpath' => ''); - %htmlCustomMappings = ('abbr' => '', - 'acronym' => '', - 'address' => '', - 'b' => '', - 'bdo' => '', - 'big' => '', - 'center' => '', - 'cite' => '', - 'code' => '', - 'colgroup' => 'col', - 'dd' => '', - 'dfn' => '', - 'dt' => '', - 'em' => '', - 'h2' => 'h1', - 'h3' => 'h1', - 'h4' => 'h1', - 'h5' => 'h1', - 'h6' => 'h1', - 'i' => '', - 'image' => 'img', - 'ins' => 'del', - 'kbd' => '', - 'keygen' => 'select', - 'listing' => 'pre', - 'layer' => '', - 'nobr' => '', - 'noembed' => '', - 'noframes' => '', - 'nolayer' => '', - 'noscript' => '', - 'plaintext' => '', - 's' => '', - 'samp' => '', - 'small' => '', - 'span' => '', - 'strike' => '', - 'strong' => '', - 'sub' => '', - 'sup' => '', - 'tfoot' => 'tbody', - 'th' => 'td', - 'thead' => 'tbody', - 'tt' => '', - 'u' => '', - 'var' => '', - 'wbr' => '', - 'xmp' => 'pre'); - } -} - -sub hasCustomMapping +sub usesDefaultJSWrapper { my $name = shift; - initializeCustomMappings(); - return 1 if $parameters{'namespace'} eq "HTML" && exists($htmlCustomMappings{$name}); - return 1 if $parameters{'namespace'} eq "SVG" && exists($svgCustomMappings{$name}); - return 0; + + # A tag reuses the default wrapper if its JSInterfaceName matches the default namespace Element. + return $tags{$name}{'JSInterfaceName'} eq $parameters{"namespace"} . "Element"; } sub printWrapperFunctions { - my ($F, $namesRef) = @_; - my %names = %$namesRef; - for my $name (sort keys %names) { - # Custom mapping do not need a JS wrapper - next if (hasCustomMapping($name)); + my $F = shift; + + my %tagsSeen; + for my $tagName (sort keys %tags) { + # Avoid defining the same wrapper method twice. + my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"}; + next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName); + $tagsSeen{$JSInterfaceName} = 1; - my $ucName = $names{$name}{"interfaceName"}; # Hack for the media tags - if ($names{$name}{"applyAudioHack"}) { + if ($tags{$tagName}{"wrapperOnlyIfMediaIsAvailable"}) { print F < element) +static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element) { if (!MediaPlayer::isAvailable()) return CREATE_DOM_NODE_WRAPPER(exec, $parameters{'namespace'}Element, element.get()); - return CREATE_DOM_NODE_WRAPPER(exec, $parameters{'namespace'}${ucName}, element.get()); + return CREATE_DOM_NODE_WRAPPER(exec, ${JSInterfaceName}, element.get()); } END ; } else { print F < element) +static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element) { - return CREATE_DOM_NODE_WRAPPER(exec, $parameters{'namespace'}${ucName}, element.get()); + return CREATE_DOM_NODE_WRAPPER(exec, ${JSInterfaceName}, element.get()); } END @@ -762,12 +788,14 @@ sub printWrapperFactoryCppFile print F "#include \"JS$parameters{'namespace'}ElementWrapperFactory.h\"\n"; - printJSElementIncludes($F, \%tags); + printJSElementIncludes($F); print F "\n#include \"$parameters{'namespace'}Names.h\"\n\n"; - printElementIncludes($F, \%tags, 1); + printElementIncludes($F); + print F "\n#include \n\n"; + print F < element) { - static HashMap map; + typedef HashMap FunctionMap; + DEFINE_STATIC_LOCAL(FunctionMap, map, ()); if (map.isEmpty()) { END ; for my $tag (sort keys %tags) { - next if (hasCustomMapping($tag)); + # Do not add the name to the map if it does not have a JS wrapper constructor or uses the default wrapper. + next if usesDefaultJSWrapper($tag, \%tags); - my $ucTag = $tags{$tag}{"interfaceName"}; + my $ucTag = $tags{$tag}{"JSInterfaceName"}; print F " map.set(${tag}Tag.localName().impl(), create${ucTag}Wrapper);\n"; } - if ($parameters{'namespace'} eq "HTML") { - for my $tag (sort keys %htmlCustomMappings) { - next if !$htmlCustomMappings{$tag}; - - my $ucCustomTag = $tags{$htmlCustomMappings{$tag}}{"interfaceName"}; - print F " map.set(${tag}Tag.localName().impl(), create${ucCustomTag}Wrapper);\n"; - } - } - - # Currently SVG has no need to add custom map.set as it only has empty elements - print F <localName().impl()); -- cgit v1.1