Commit ae5f161d authored by jchaffraix@webkit.org's avatar jchaffraix@webkit.org

2009-01-06 Julien Chaffraix <jchaffraix@webkit.org>

        Reviewed by Nikolas Zimmermann.

        Bug 22858: Simplify make_names.pl code for avoiding multiple definitions or inclusions
        https://bugs.webkit.org/show_bug.cgi?id=22858

        I had introduced an awkward situation using hasCustomJSWrapper and
        sometimes boolean parameter in order to ensure JS wrapper generated once
        or header included once.

        Simplified the code by using a %seenTag hash to detect multiple definitions
        or inclusions and skipping it.

        Also cleaned up a bit make_names.pl by using more explicit names and moving
        code to where it belongs.

        * dom/make_names.pl:
        * html/HTMLTagNames.in: Necessary changes that were not detected by
        the previous syntax but will be required for autogenerating HTMLElementFactory.




git-svn-id: http://svn.webkit.org/repository/webkit/trunk@39666 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4eab1d36
2009-01-06 Julien Chaffraix <jchaffraix@webkit.org>
Reviewed by Nikolas Zimmermann.
Bug 22858: Simplify make_names.pl code for avoiding multiple definitions or inclusions
https://bugs.webkit.org/show_bug.cgi?id=22858
I had introduced an awkward situation using hasCustomJSWrapper and
sometimes boolean parameter in order to ensure JS wrapper generated once
or header included once.
Simplified the code by using a %seenTag hash to detect multiple definitions
or inclusions and skipping it.
Also cleaned up a bit make_names.pl by using more explicit names and moving
code to where it belongs.
* dom/make_names.pl:
* html/HTMLTagNames.in: Necessary changes that were not detected by
the previous syntax but will be required for autogenerating HTMLElementFactory.
2009-01-06 Anders Carlsson <andersca@apple.com> 2009-01-06 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig. Reviewed by Sam Weinig.
...@@ -110,6 +110,12 @@ sub initializeParametersHash ...@@ -110,6 +110,12 @@ sub initializeParametersHash
'exportStrings' => 0); 'exportStrings' => 0);
} }
sub defaultInterfaceName
{
die "No namespace found" if !$parameters{'namespace'};
return $parameters{'namespace'} . upperCaseName($_[0]) . "Element"
}
### Parsing handlers ### Parsing handlers
sub tagsHandler sub tagsHandler
...@@ -436,23 +442,28 @@ print F "\nvoid init() ...@@ -436,23 +442,28 @@ print F "\nvoid init()
sub printJSElementIncludes sub printJSElementIncludes
{ {
my $F = shift; my $F = shift;
for my $name (sort keys %tags) {
next if hasCustomJSInterfaceName($name);
my $ucName = $tags{$name}{"JSInterfaceName"}; my %tagsSeen;
print F "#include \"JS${ucName}.h\"\n"; for my $tagName (sort keys %tags) {
my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"};
next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName);
$tagsSeen{$JSInterfaceName} = 1;
print F "#include \"JS${JSInterfaceName}.h\"\n";
} }
} }
sub printElementIncludes sub printElementIncludes
{ {
my ($F, $shouldSkipCustomMappings) = @_; my $F = shift;
for my $name (sort keys %tags) { my %tagsSeen;
next if ($shouldSkipCustomMappings && hasCustomJSInterfaceName($name)); for my $tagName (sort keys %tags) {
my $interfaceName = $tags{$tagName}{"interfaceName"};
next if defined($tagsSeen{$interfaceName});
$tagsSeen{$interfaceName} = 1;
my $ucName = $tags{$name}{"interfaceName"}; print F "#include \"${interfaceName}.h\"\n";
print F "#include \"${ucName}.h\"\n";
} }
} }
...@@ -524,7 +535,7 @@ print F <<END ...@@ -524,7 +535,7 @@ print F <<END
END END
; ;
printElementIncludes($F, 0); printElementIncludes($F);
print F <<END print F <<END
#include <wtf/HashMap.h> #include <wtf/HashMap.h>
...@@ -656,23 +667,7 @@ END ...@@ -656,23 +667,7 @@ END
## Wrapper Factory routines ## Wrapper Factory routines
sub defaultInterfaceName sub usesDefaultJSWrapper
{
die "No namespace found" if !$parameters{'namespace'};
return $parameters{'namespace'} . upperCaseName($_[0]) . "Element"
}
sub hasCustomJSInterfaceName
{
my $tag = shift;
# We have a custom JSInterface if the JSInterfaceName is not the same as the interfaceName.
# FIXME: The 'img' tag matches completely the 'image' tag and cannot be distinguished
# so we have to check for it.
return !($tags{$tag}{'JSInterfaceName'} eq $tags{$tag}{'interfaceName'}) || $tag eq "img";
}
sub usesDefaultWrapper
{ {
my $name = shift; my $name = shift;
...@@ -684,28 +679,30 @@ sub printWrapperFunctions ...@@ -684,28 +679,30 @@ sub printWrapperFunctions
{ {
my $F = shift; my $F = shift;
for my $name (sort keys %tags) { my %tagsSeen;
# A custom JSInterface means that we reuse another tag's constructor. for my $tagName (sort keys %tags) {
next if hasCustomJSInterfaceName($name) || usesDefaultWrapper($name); # Avoid defining the same wrapper method twice.
my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"};
next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName);
$tagsSeen{$JSInterfaceName} = 1;
my $ucName = $tags{$name}{"JSInterfaceName"};
# Hack for the media tags # Hack for the media tags
if ($tags{$name}{"wrapperOnlyIfMediaIsAvailable"}) { if ($tags{$tagName}{"wrapperOnlyIfMediaIsAvailable"}) {
print F <<END print F <<END
static JSNode* create${ucName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element) static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element)
{ {
if (!MediaPlayer::isAvailable()) if (!MediaPlayer::isAvailable())
return CREATE_DOM_NODE_WRAPPER(exec, $parameters{'namespace'}Element, element.get()); return CREATE_DOM_NODE_WRAPPER(exec, $parameters{'namespace'}Element, element.get());
return CREATE_DOM_NODE_WRAPPER(exec, ${ucName}, element.get()); return CREATE_DOM_NODE_WRAPPER(exec, ${JSInterfaceName}, element.get());
} }
END END
; ;
} else { } else {
print F <<END print F <<END
static JSNode* create${ucName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element) static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element)
{ {
return CREATE_DOM_NODE_WRAPPER(exec, ${ucName}, element.get()); return CREATE_DOM_NODE_WRAPPER(exec, ${JSInterfaceName}, element.get());
} }
END END
...@@ -732,7 +729,7 @@ sub printWrapperFactoryCppFile ...@@ -732,7 +729,7 @@ sub printWrapperFactoryCppFile
print F "\n#include \"$parameters{'namespace'}Names.h\"\n\n"; print F "\n#include \"$parameters{'namespace'}Names.h\"\n\n";
printElementIncludes($F, 1); printElementIncludes($F);
print F "\n#include <wtf/StdLibExtras.h>\n\n"; print F "\n#include <wtf/StdLibExtras.h>\n\n";
...@@ -761,7 +758,7 @@ END ...@@ -761,7 +758,7 @@ END
for my $tag (sort keys %tags) { for my $tag (sort keys %tags) {
# Do not add the name to the map if it does not have a JS wrapper constructor or uses the default wrapper. # Do not add the name to the map if it does not have a JS wrapper constructor or uses the default wrapper.
next if usesDefaultWrapper($tag, \%tags); next if usesDefaultJSWrapper($tag, \%tags);
my $ucTag = $tags{$tag}{"JSInterfaceName"}; my $ucTag = $tags{$tag}{"JSInterfaceName"};
print F " map.set(${tag}Tag.localName().impl(), create${ucTag}Wrapper);\n"; print F " map.set(${tag}Tag.localName().impl(), create${ucTag}Wrapper);\n";
......
...@@ -3,38 +3,38 @@ namespacePrefix="xhtml" ...@@ -3,38 +3,38 @@ namespacePrefix="xhtml"
namespaceURI="http://www.w3.org/1999/xhtml" namespaceURI="http://www.w3.org/1999/xhtml"
a interfaceName=HTMLAnchorElement a interfaceName=HTMLAnchorElement
abbr JSInterfaceName=HTMLElement abbr interfaceName=HTMLElement
acronym JSInterfaceName=HTMLElement acronym interfaceName=HTMLElement
address JSInterfaceName=HTMLElement address interfaceName=HTMLElement
applet applet
area area
#if ENABLE_VIDEO #if ENABLE_VIDEO
audio wrapperOnlyIfMediaIsAvailable=1 audio wrapperOnlyIfMediaIsAvailable=1
#endif #endif
b JSInterfaceName=HTMLElement b interfaceName=HTMLElement
base base
basefont interfaceName=HTMLBaseFontElement basefont interfaceName=HTMLBaseFontElement
bdo JSInterfaceName=HTMLElement bdo interfaceName=HTMLElement
big JSInterfaceName=HTMLElement big interfaceName=HTMLElement
blockquote blockquote
body body
br interfaceName=HTMLBRElement br interfaceName=HTMLBRElement
button button
canvas canvas
caption interfaceName=HTMLTableCaptionElement caption interfaceName=HTMLTableCaptionElement
center JSInterfaceName=HTMLElement center interfaceName=HTMLElement
cite JSInterfaceName=HTMLElement cite interfaceName=HTMLElement
code JSInterfaceName=HTMLElement code interfaceName=HTMLElement
col interfaceName=HTMLTableColElement col interfaceName=HTMLTableColElement
colgroup JSInterfaceName=HTMLTableColElement colgroup interfaceName=HTMLTableColElement
dd JSInterfaceName=HTMLElement dd interfaceName=HTMLElement
del interfaceName=HTMLModElement del interfaceName=HTMLModElement
dfn JSInterfaceName=HTMLElement dfn interfaceName=HTMLElement
dir interfaceName=HTMLDirectoryElement dir interfaceName=HTMLDirectoryElement
div div
dl interfaceName=HTMLDListElement dl interfaceName=HTMLDListElement
dt JSInterfaceName=HTMLElement dt interfaceName=HTMLElement
em JSInterfaceName=HTMLElement em interfaceName=HTMLElement
embed embed
fieldset interfaceName=HTMLFieldSetElement fieldset interfaceName=HTMLFieldSetElement
font font
...@@ -43,75 +43,75 @@ frame constructorNeedsCreatedByParser=1 ...@@ -43,75 +43,75 @@ frame constructorNeedsCreatedByParser=1
frameset interfaceName=HTMLFrameSetElement frameset interfaceName=HTMLFrameSetElement
head head
h1 interfaceName=HTMLHeadingElement h1 interfaceName=HTMLHeadingElement
h2 JSInterfaceName=HTMLHeadingElement h2 interfaceName=HTMLHeadingElement
h3 JSInterfaceName=HTMLHeadingElement h3 interfaceName=HTMLHeadingElement
h4 JSInterfaceName=HTMLHeadingElement h4 interfaceName=HTMLHeadingElement
h5 JSInterfaceName=HTMLHeadingElement h5 interfaceName=HTMLHeadingElement
h6 JSInterfaceName=HTMLHeadingElement h6 interfaceName=HTMLHeadingElement
hr interfaceName=HTMLHRElement hr interfaceName=HTMLHRElement
html html
i JSInterfaceName=HTMLElement i interfaceName=HTMLElement
iframe interfaceName=HTMLIFrameElement, constructorNeedsCreatedByParser=1 iframe interfaceName=HTMLIFrameElement, constructorNeedsCreatedByParser=1
image image
img interfaceName=HTMLImageElement img interfaceName=HTMLImageElement
input input
ins JSInterfaceName=HTMLModElement ins interfaceName=HTMLModElement
isindex interfaceName=HTMLIsIndexElement isindex interfaceName=HTMLIsIndexElement
kbd JSInterfaceName=HTMLElement kbd interfaceName=HTMLElement
keygen JSInterfaceName=HTMLSelectElement keygen JSInterfaceName=HTMLSelectElement
label label
layer JSInterfaceName=HTMLElement layer interfaceName=HTMLElement
legend legend
li interfaceName=HTMLLIElement li interfaceName=HTMLLIElement
link constructorNeedsCreatedByParser=1 link constructorNeedsCreatedByParser=1
listing JSInterfaceName=HTMLPreElement listing interfaceName=HTMLPreElement
map map
marquee marquee
menu menu
meta meta
nobr JSInterfaceName=HTMLElement nobr interfaceName=HTMLElement
noembed JSInterfaceName=HTMLElement noembed interfaceName=HTMLElement
noframes JSInterfaceName=HTMLElement noframes interfaceName=HTMLElement
nolayer JSInterfaceName=HTMLElement nolayer interfaceName=HTMLElement
noscript JSInterfaceName=HTMLElement noscript interfaceName=HTMLElement
object object
ol interfaceName=HTMLOListElement ol interfaceName=HTMLOListElement
optgroup interfaceName=HTMLOptGroupElement optgroup interfaceName=HTMLOptGroupElement
option option
p interfaceName=HTMLParagraphElement p interfaceName=HTMLParagraphElement
param param
plaintext JSInterfaceName=HTMLElement plaintext interfaceName=HTMLElement
pre pre
q interfaceName=HTMLQuoteElement q interfaceName=HTMLQuoteElement
s JSInterfaceName=HTMLElement s interfaceName=HTMLElement
samp JSInterfaceName=HTMLElement samp interfaceName=HTMLElement
script constructorNeedsCreatedByParser=1 script constructorNeedsCreatedByParser=1
select select
small JSInterfaceName=HTMLElement small interfaceName=HTMLElement
#if ENABLE_VIDEO #if ENABLE_VIDEO
source wrapperOnlyIfMediaIsAvailable=1 source wrapperOnlyIfMediaIsAvailable=1
#endif #endif
span JSInterfaceName=HTMLElement span interfaceName=HTMLElement
strike JSInterfaceName=HTMLElement strike interfaceName=HTMLElement
strong JSInterfaceName=HTMLElement strong interfaceName=HTMLElement
style constructorNeedsCreatedByParser=1 style constructorNeedsCreatedByParser=1
sub JSInterfaceName=HTMLElement sub interfaceName=HTMLElement
sup JSInterfaceName=HTMLElement sup interfaceName=HTMLElement
table table
tbody interfaceName=HTMLTableSectionElement tbody interfaceName=HTMLTableSectionElement
td interfaceName=HTMLTableCellElement td interfaceName=HTMLTableCellElement
textarea interfaceName=HTMLTextAreaElement textarea interfaceName=HTMLTextAreaElement
tfoot JSInterfaceName=HTMLTableSectionElement tfoot interfaceName=HTMLTableSectionElement
th JSInterfaceName=HTMLTableCellElement th interfaceName=HTMLTableCellElement
thead JSInterfaceName=HTMLTableSectionElement thead interfaceName=HTMLTableSectionElement
title title
tr interfaceName=HTMLTableRowElement tr interfaceName=HTMLTableRowElement
tt JSInterfaceName=HTMLElement tt interfaceName=HTMLElement
u JSInterfaceName=HTMLElement u interfaceName=HTMLElement
ul interfaceName=HTMLUListElement ul interfaceName=HTMLUListElement
var JSInterfaceName=HTMLElement var interfaceName=HTMLElement
#if ENABLE_VIDEO #if ENABLE_VIDEO
video wrapperOnlyIfMediaIsAvailable=1 video wrapperOnlyIfMediaIsAvailable=1
#endif #endif
wbr JSInterfaceName=HTMLElement wbr interfaceName=HTMLElement
xmp JSInterfaceName=HTMLPreElement xmp interfaceName=HTMLPreElement
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment