Chromium Code Reviews| Index: Source/core/scripts/make_names.pl |
| diff --git a/Source/core/scripts/make_names.pl b/Source/core/scripts/make_names.pl |
| index 1b4b2b4bcdb5604a72e1c827f3fc092939962b5e..c8f71d36ca67613f4f7df5f0f04abba8e8b91e6a 100755 |
| --- a/Source/core/scripts/make_names.pl |
| +++ b/Source/core/scripts/make_names.pl |
| @@ -4,6 +4,7 @@ |
| # Copyright (C) 2009, Julien Chaffraix <jchaffraix@webkit.org> |
| # Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
| # Copyright (C) 2011 Ericsson AB. All rights reserved. |
| +# Copyright (C) 2013 Samsung Electronics. All rights reserved. |
| # |
| # Redistribution and use in source and binary forms, with or without |
| # modification, are permitted provided that the following conditions |
| @@ -117,12 +118,14 @@ die "You must specify a namespaceURI (e.g. http://www.w3.org/2000/svg)" unless $ |
| $parameters{namespacePrefix} = $parameters{namespace} unless $parameters{namespacePrefix}; |
| $parameters{fallbackJSInterfaceName} = $parameters{fallbackInterfaceName} unless $parameters{fallbackJSInterfaceName}; |
| +my $typeHelpersBasePath = "$outputDir/$parameters{namespace}ElementTypeHelpers"; |
| my $namesBasePath = "$outputDir/$parameters{namespace}Names"; |
| my $factoryBasePath = "$outputDir/$parameters{namespace}ElementFactory"; |
| my $wrapperFactoryFileName = "$parameters{namespace}ElementWrapperFactory"; |
| printNamesHeaderFile("$namesBasePath.h"); |
| printNamesCppFile("$namesBasePath.cpp"); |
| +printTypeHelpersHeaderFile("$typeHelpersBasePath.h"); |
| if ($printFactory) { |
| printFactoryCppFile("$factoryBasePath.cpp"); |
| @@ -147,7 +150,8 @@ sub defaultTagPropertyHash |
| 'wrapperOnlyIfMediaIsAvailable' => 0, |
| 'conditional' => 0, |
| 'contextConditional' => 0, |
| - 'runtimeConditional' => 0 |
| + 'runtimeConditional' => 0, |
| + 'generateTypeHelpers' => 0 |
| ); |
| } |
| @@ -570,6 +574,49 @@ sub printLicenseHeader |
| "; |
| } |
| +sub printTypeHelpers |
| +{ |
| + my ($F, $namesRef) = @_; |
| + my %names = %$namesRef; |
| + |
| + for my $name (sort keys %names) { |
| + if (!$parsedTags{$name}{generateTypeHelpers}) { |
| + next; |
| + } |
| + |
| + my $class = $parsedTags{$name}{interfaceName}; |
| + my $castingHelper = "to$class"; |
| + |
| + print F "class $class;\n"; |
| + print F "inline $class* $castingHelper(Node* node) { ASSERT_WITH_SECURITY_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
|
| + print F "inline $class* $castingHelper(Element* element) { ASSERT_WITH_SECURITY_IMPLICATION(!element || element->hasTagName(".$parameters{namespace}."Names::".$name."Tag)); return reinterpret_cast<".$class."*>(element); }\n"; |
| + |
| + print F "\n"; |
| + } |
| +} |
| + |
| +sub printTypeHelpersHeaderFile |
| +{ |
| + my ($headerPath) = shift; |
| + my $F; |
| + open F, ">$headerPath"; |
| + printLicenseHeader($F); |
| + |
| + print F "#ifndef ".$parameters{namespace}."ElementTypeHelpers_h\n"; |
| + print F "#define ".$parameters{namespace}."ElementTypeHelpers_h\n\n"; |
| + print F "#include \"".$parameters{namespace}."Names.h\"\n"; |
| + print F "#include \"core/dom/Element.h\"\n"; |
| + print F "#include \"core/dom/Node.h\"\n\n"; |
| + print F "namespace WebCore {\n"; |
| + |
| + printTypeHelpers($F, \%allTags); |
| + |
| + print F "}\n\n"; |
| + print F "#endif\n"; |
| + |
| + close F; |
| +} |
| + |
| sub printNamesHeaderFile |
| { |
| my ($headerPath) = shift; |