Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: Source/core/scripts/make_names.pl

Issue 23991004: Generate toFooElement() functions from tagname data (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/html/HTMLTrackElement.h ('k') | Source/core/svg/SVGCircleElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/perl -w 1 #!/usr/bin/perl -w
2 2
3 # Copyright (C) 2005, 2006, 2007, 2009 Apple Inc. All rights reserved. 3 # Copyright (C) 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
4 # Copyright (C) 2009, Julien Chaffraix <jchaffraix@webkit.org> 4 # Copyright (C) 2009, Julien Chaffraix <jchaffraix@webkit.org>
5 # Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmob ile.com/) 5 # Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmob ile.com/)
6 # Copyright (C) 2011 Ericsson AB. All rights reserved. 6 # Copyright (C) 2011 Ericsson AB. All rights reserved.
7 # Copyright (C) 2013 Samsung Electronics. All rights reserved.
7 # 8 #
8 # Redistribution and use in source and binary forms, with or without 9 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions 10 # modification, are permitted provided that the following conditions
10 # are met: 11 # are met:
11 # 12 #
12 # 1. Redistributions of source code must retain the above copyright 13 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer. 14 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright 15 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the 16 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution. 17 # documentation and/or other materials provided with the distribution.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 %enabledAttrs = %{readAttrs($attrsFile, 1)}; 111 %enabledAttrs = %{readAttrs($attrsFile, 1)};
111 namesToStrings(\%allAttrs, \%allStrings); 112 namesToStrings(\%allAttrs, \%allStrings);
112 } 113 }
113 114
114 die "You must specify a namespace (e.g. SVG) for <namespace>Names.h" unless $par ameters{namespace}; 115 die "You must specify a namespace (e.g. SVG) for <namespace>Names.h" unless $par ameters{namespace};
115 die "You must specify a namespaceURI (e.g. http://www.w3.org/2000/svg)" unless $ parameters{namespaceURI}; 116 die "You must specify a namespaceURI (e.g. http://www.w3.org/2000/svg)" unless $ parameters{namespaceURI};
116 117
117 $parameters{namespacePrefix} = $parameters{namespace} unless $parameters{namespa cePrefix}; 118 $parameters{namespacePrefix} = $parameters{namespace} unless $parameters{namespa cePrefix};
118 $parameters{fallbackJSInterfaceName} = $parameters{fallbackInterfaceName} unless $parameters{fallbackJSInterfaceName}; 119 $parameters{fallbackJSInterfaceName} = $parameters{fallbackInterfaceName} unless $parameters{fallbackJSInterfaceName};
119 120
121 my $typeHelpersBasePath = "$outputDir/$parameters{namespace}ElementTypeHelpers";
120 my $namesBasePath = "$outputDir/$parameters{namespace}Names"; 122 my $namesBasePath = "$outputDir/$parameters{namespace}Names";
121 my $factoryBasePath = "$outputDir/$parameters{namespace}ElementFactory"; 123 my $factoryBasePath = "$outputDir/$parameters{namespace}ElementFactory";
122 my $wrapperFactoryFileName = "$parameters{namespace}ElementWrapperFactory"; 124 my $wrapperFactoryFileName = "$parameters{namespace}ElementWrapperFactory";
123 125
124 printNamesHeaderFile("$namesBasePath.h"); 126 printNamesHeaderFile("$namesBasePath.h");
125 printNamesCppFile("$namesBasePath.cpp"); 127 printNamesCppFile("$namesBasePath.cpp");
128 printTypeHelpersHeaderFile("$typeHelpersBasePath.h");
126 129
127 if ($printFactory) { 130 if ($printFactory) {
128 printFactoryCppFile("$factoryBasePath.cpp"); 131 printFactoryCppFile("$factoryBasePath.cpp");
129 printFactoryHeaderFile("$factoryBasePath.h"); 132 printFactoryHeaderFile("$factoryBasePath.h");
130 } 133 }
131 134
132 printWrapperFactoryCppFile($outputDir, $wrapperFactoryFileName); 135 printWrapperFactoryCppFile($outputDir, $wrapperFactoryFileName);
133 printWrapperFactoryHeaderFile($outputDir, $wrapperFactoryFileName); 136 printWrapperFactoryHeaderFile($outputDir, $wrapperFactoryFileName);
134 137
135 ### Hash initialization 138 ### Hash initialization
136 139
137 sub defaultTagPropertyHash 140 sub defaultTagPropertyHash
138 { 141 {
139 return ( 142 return (
140 'constructorNeedsCreatedByParser' => 0, 143 'constructorNeedsCreatedByParser' => 0,
141 'constructorNeedsFormElement' => 0, 144 'constructorNeedsFormElement' => 0,
142 'noConstructor' => 0, 145 'noConstructor' => 0,
143 'interfaceName' => defaultInterfaceName($_[0]), 146 'interfaceName' => defaultInterfaceName($_[0]),
144 # By default, the JSInterfaceName is the same as the interfaceName. 147 # By default, the JSInterfaceName is the same as the interfaceName.
145 'JSInterfaceName' => defaultInterfaceName($_[0]), 148 'JSInterfaceName' => defaultInterfaceName($_[0]),
146 'mapToTagName' => '', 149 'mapToTagName' => '',
147 'wrapperOnlyIfMediaIsAvailable' => 0, 150 'wrapperOnlyIfMediaIsAvailable' => 0,
148 'conditional' => 0, 151 'conditional' => 0,
149 'contextConditional' => 0, 152 'contextConditional' => 0,
150 'runtimeConditional' => 0 153 'runtimeConditional' => 0,
154 'generateTypeHelpers' => 0
151 ); 155 );
152 } 156 }
153 157
154 sub defaultParametersHash 158 sub defaultParametersHash
155 { 159 {
156 return ( 160 return (
157 'namespace' => '', 161 'namespace' => '',
158 'namespacePrefix' => '', 162 'namespacePrefix' => '',
159 'namespaceURI' => '', 163 'namespaceURI' => '',
160 'guardFactoryWith' => '', 164 'guardFactoryWith' => '',
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 567 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
564 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 568 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
565 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 569 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
566 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 570 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
567 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 571 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
568 */ 572 */
569 573
570 "; 574 ";
571 } 575 }
572 576
577 sub printTypeHelpers
578 {
579 my ($F, $namesRef) = @_;
580 my %names = %$namesRef;
581
582 for my $name (sort keys %names) {
583 if (!$parsedTags{$name}{generateTypeHelpers}) {
584 next;
585 }
586
587 my $class = $parsedTags{$name}{interfaceName};
588 my $castingHelper = "to$class";
589
590 print F "class $class;\n";
591 print F "inline $class* $castingHelper(Node* node) { ASSERT_WITH_SECURIT Y_IMPLICATION(!node || node->hasTagName(".$parameters{namespace}."Names::".$name ."Tag)); return reinterpret_cast<".$class."*>(node); }\n";
tkent 2013/09/09 05:53:39 If we used reinterpret_cast<>, we should have a wa
592 print F "inline $class* $castingHelper(Element* element) { ASSERT_WITH_S ECURITY_IMPLICATION(!element || element->hasTagName(".$parameters{namespace}."Na mes::".$name."Tag)); return reinterpret_cast<".$class."*>(element); }\n";
593
594 print F "\n";
595 }
596 }
597
598 sub printTypeHelpersHeaderFile
599 {
600 my ($headerPath) = shift;
601 my $F;
602 open F, ">$headerPath";
603 printLicenseHeader($F);
604
605 print F "#ifndef ".$parameters{namespace}."ElementTypeHelpers_h\n";
606 print F "#define ".$parameters{namespace}."ElementTypeHelpers_h\n\n";
607 print F "#include \"".$parameters{namespace}."Names.h\"\n";
608 print F "#include \"core/dom/Element.h\"\n";
609 print F "#include \"core/dom/Node.h\"\n\n";
610 print F "namespace WebCore {\n";
611
612 printTypeHelpers($F, \%allTags);
613
614 print F "}\n\n";
615 print F "#endif\n";
616
617 close F;
618 }
619
573 sub printNamesHeaderFile 620 sub printNamesHeaderFile
574 { 621 {
575 my ($headerPath) = shift; 622 my ($headerPath) = shift;
576 my $F; 623 my $F;
577 open F, ">$headerPath"; 624 open F, ">$headerPath";
578 625
579 printLicenseHeader($F); 626 printLicenseHeader($F);
580 printHeaderHead($F, "DOM", $parameters{namespace}, "#include \"core/dom/Qual ifiedName.h\""); 627 printHeaderHead($F, "DOM", $parameters{namespace}, "#include \"core/dom/Qual ifiedName.h\"");
581 628
582 my $lowerNamespace = lc($parameters{namespacePrefix}); 629 my $lowerNamespace = lc($parameters{namespacePrefix});
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 print F StaticString::GenerateStringImpls(\%parameters); 1320 print F StaticString::GenerateStringImpls(\%parameters);
1274 1321
1275 while ( my ($name, $identifier) = each %parameters ) { 1322 while ( my ($name, $identifier) = each %parameters ) {
1276 print F " new ((void*)&$name) AtomicString(${name}Impl);\n"; 1323 print F " new ((void*)&$name) AtomicString(${name}Impl);\n";
1277 } 1324 }
1278 1325
1279 print F "}\n}\n}\n"; 1326 print F "}\n}\n}\n";
1280 close F; 1327 close F;
1281 exit 0; 1328 exit 0;
1282 } 1329 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLTrackElement.h ('k') | Source/core/svg/SVGCircleElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698