2 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
4 # Copyright (C) 2006, 2007 Samuel Weinig <sam@webkit.org>
5 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
6 # Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
8 # Copyright (C) 2010 Google Inc.
9 # Copyright (C) Research In Motion Limited 2010. All rights reserved.
11 # This library is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU Library General Public
13 # License as published by the Free Software Foundation; either
14 # version 2 of the License, or (at your option) any later version.
16 # This library is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 # Library General Public License for more details.
21 # You should have received a copy of the GNU Library General Public License
22 # along with this library; see the file COPYING.LIB. If not, write to
23 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 # Boston, MA 02110-1301, USA.
27 package CodeGeneratorObjC;
34 my $writeDependencies = 0;
35 my %publicInterfaces = ();
36 my $newPublicClass = 0;
37 my $interfaceAvailabilityVersion = "";
41 my @headerContentHeader = ();
42 my @headerContent = ();
43 my %headerForwardDeclarations = ();
44 my %headerForwardDeclarationsForProtocols = ();
46 my @privateHeaderContentHeader = ();
47 my @privateHeaderContent = ();
48 my %privateHeaderForwardDeclarations = ();
49 my %privateHeaderForwardDeclarationsForProtocols = ();
51 my @internalHeaderContent = ();
53 my @implContentHeader = ();
55 my %implIncludes = ();
59 my %protocolTypeHash = ("XPathNSResolver" => 1, "EventListener" => 1, "EventTarget" => 1, "NodeFilter" => 1,
60 "SVGLocatable" => 1, "SVGTransformable" => 1, "SVGStylable" => 1, "SVGFilterPrimitiveStandardAttributes" => 1,
61 "SVGTests" => 1, "SVGLangSpace" => 1, "SVGExternalResourcesRequired" => 1, "SVGURIReference" => 1,
62 "SVGZoomAndPan" => 1, "SVGFitToViewBox" => 1, "SVGAnimatedPathData" => 1, "ElementTimeControl" => 1);
63 my %nativeObjCTypeHash = ("URL" => 1, "Color" => 1);
65 # FIXME: this should be replaced with a function that recurses up the tree
66 # to find the actual base type.
67 my %baseTypeHash = ("Object" => 1, "Node" => 1, "NodeList" => 1, "NamedNodeMap" => 1, "DOMImplementation" => 1,
68 "Event" => 1, "CSSRule" => 1, "CSSValue" => 1, "StyleSheet" => 1, "MediaList" => 1,
69 "Counter" => 1, "Rect" => 1, "RGBColor" => 1, "XPathExpression" => 1, "XPathResult" => 1,
70 "NodeIterator" => 1, "TreeWalker" => 1, "AbstractView" => 1, "Blob" => 1,
71 "SVGAngle" => 1, "SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1, "SVGAnimatedEnumeration" => 1,
72 "SVGAnimatedInteger" => 1, "SVGAnimatedLength" => 1, "SVGAnimatedLengthList" => 1,
73 "SVGAnimatedNumber" => 1, "SVGAnimatedNumberList" => 1,
74 "SVGAnimatedPreserveAspectRatio" => 1, "SVGAnimatedRect" => 1, "SVGAnimatedString" => 1,
75 "SVGAnimatedTransformList" => 1, "SVGLength" => 1, "SVGLengthList" => 1, "SVGMatrix" => 1,
76 "SVGNumber" => 1, "SVGNumberList" => 1, "SVGPathSeg" => 1, "SVGPathSegList" => 1, "SVGPoint" => 1,
77 "SVGPointList" => 1, "SVGPreserveAspectRatio" => 1, "SVGRect" => 1, "SVGRenderingIntent" => 1,
78 "SVGStringList" => 1, "SVGTransform" => 1, "SVGTransformList" => 1, "SVGUnitTypes" => 1);
81 my $buildingForTigerOrEarlier = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} <= 10.4;
82 my $buildingForLeopardOrLater = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} >= 10.5;
83 my $exceptionInit = "WebCore::ExceptionCode ec = 0;";
84 my $jsContextSetter = "WebCore::JSMainThreadNullState state;";
85 my $exceptionRaiseOnError = "WebCore::raiseOnDOMError(ec);";
86 my $assertMainThread = "{ DOM_ASSERT_MAIN_THREAD(); WebCoreThreadViolationCheckRoundOne(); }";
88 my %conflictMethod = (
89 # FIXME: Add C language keywords?
90 # FIXME: Add other predefined types like "id"?
92 "callWebScriptMethod:withArguments:" => "WebScriptObject",
93 "evaluateWebScript:" => "WebScriptObject",
94 "removeWebScriptKey:" => "WebScriptObject",
95 "setException:" => "WebScriptObject",
96 "setWebScriptValueAtIndex:value:" => "WebScriptObject",
97 "stringRepresentation" => "WebScriptObject",
98 "webScriptValueAtIndex:" => "WebScriptObject",
100 "autorelease" => "NSObject",
101 "awakeAfterUsingCoder:" => "NSObject",
102 "class" => "NSObject",
103 "classForCoder" => "NSObject",
104 "conformsToProtocol:" => "NSObject",
105 "copy" => "NSObject",
106 "copyWithZone:" => "NSObject",
107 "dealloc" => "NSObject",
108 "description" => "NSObject",
109 "doesNotRecognizeSelector:" => "NSObject",
110 "encodeWithCoder:" => "NSObject",
111 "finalize" => "NSObject",
112 "forwardInvocation:" => "NSObject",
113 "hash" => "NSObject",
114 "init" => "NSObject",
115 "initWithCoder:" => "NSObject",
116 "isEqual:" => "NSObject",
117 "isKindOfClass:" => "NSObject",
118 "isMemberOfClass:" => "NSObject",
119 "isProxy" => "NSObject",
120 "methodForSelector:" => "NSObject",
121 "methodSignatureForSelector:" => "NSObject",
122 "mutableCopy" => "NSObject",
123 "mutableCopyWithZone:" => "NSObject",
124 "performSelector:" => "NSObject",
125 "release" => "NSObject",
126 "replacementObjectForCoder:" => "NSObject",
127 "respondsToSelector:" => "NSObject",
128 "retain" => "NSObject",
129 "retainCount" => "NSObject",
130 "self" => "NSObject",
131 "superclass" => "NSObject",
132 "zone" => "NSObject",
137 # Default License Templates
138 my $headerLicenseTemplate = << "EOF";
140 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
141 * Copyright (C) 2006 Samuel Weinig <sam.weinig\@gmail.com>
143 * Redistribution and use in source and binary forms, with or without
144 * modification, are permitted provided that the following conditions
146 * 1. Redistributions of source code must retain the above copyright
147 * notice, this list of conditions and the following disclaimer.
148 * 2. Redistributions in binary form must reproduce the above copyright
149 * notice, this list of conditions and the following disclaimer in the
150 * documentation and/or other materials provided with the distribution.
152 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
153 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
154 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
155 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
156 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
157 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
158 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
159 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
160 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
161 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
162 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
166 my $implementationLicenseTemplate = << "EOF";
168 * This file is part of the WebKit open source project.
169 * This file has been generated by generate-bindings.pl. DO NOT MODIFY!
171 * Redistribution and use in source and binary forms, with or without
172 * modification, are permitted provided that the following conditions
174 * 1. Redistributions of source code must retain the above copyright
175 * notice, this list of conditions and the following disclaimer.
176 * 2. Redistributions in binary form must reproduce the above copyright
177 * notice, this list of conditions and the following disclaimer in the
178 * documentation and/or other materials provided with the distribution.
180 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
181 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
183 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
184 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
185 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
186 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
187 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
188 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
189 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
190 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
194 # Default constructor
200 $codeGenerator = shift;
202 shift; # $outputHeadersDir
203 shift; # $useLayerOnTop
204 shift; # $preprocessor
205 $writeDependencies = shift;
207 bless($reference, $object);
216 sub ReadPublicInterfaces
219 my $superClass = shift;
221 my $isProtocol = shift;
224 my $actualSuperClass;
225 %publicInterfaces = ();
227 my $fileName = "WebCore/bindings/objc/PublicDOMInterfaces.h";
228 my $gccLocation = "";
230 $gccLocation = $ENV{CC};
231 } elsif (($Config::Config{'osname'}) =~ /solaris/i) {
232 $gccLocation = "/usr/sfw/bin/gcc";
234 $gccLocation = "/usr/bin/gcc";
236 open FILE, "-|", $gccLocation, "-E", "-P", "-x", "objective-c",
237 (map { "-D$_" } split(/ +/, $defines)), "-DOBJC_CODE_GENERATION", $fileName or die "Could not open $fileName";
238 my @documentContent = <FILE>;
241 foreach $line (@documentContent) {
242 if (!$isProtocol && $line =~ /^\s*\@interface\s*$class\s*:\s*(\w+)\s*([A-Z0-9_]*)/) {
243 if ($superClass ne $1) {
244 warn "Public API change. Superclass for \"$class\" differs ($1 != $superClass)";
248 $interfaceAvailabilityVersion = $2 if defined $2;
251 } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*<[^>]+>\s*([A-Z0-9_]*)/) {
252 $interfaceAvailabilityVersion = $1 if defined $1;
257 last if $found and $line =~ /^\s?\@end\s?$/;
264 my $availabilityMacro = "";
265 $line =~ s/\s([A-Z0-9_]+)\s*;$/;/;
266 $availabilityMacro = $1 if defined $1;
268 $publicInterfaces{$line} = $availabilityMacro if length $line;
272 # If this class was not found in PublicDOMInterfaces.h then it should be considered as an entirely new public class.
273 $newPublicClass = !$found;
274 $interfaceAvailabilityVersion = "WEBKIT_VERSION_LATEST" if $newPublicClass;
277 sub GenerateConditionalString
280 my $conditional = $node->extendedAttributes->{"Conditional"};
282 if ($conditional =~ /&/) {
283 return "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
284 } elsif ($conditional =~ /\|/) {
285 return "ENABLE(" . join(") || ENABLE(", split(/\|/, $conditional)) . ")";
287 return "ENABLE(" . $conditional . ")";
294 # Params: 'domClass' struct
295 sub GenerateInterface
298 my $dataNode = shift;
303 my $name = $dataNode->name;
304 my $className = GetClassName($name);
305 my $parentClassName = "DOM" . GetParentImplClassName($dataNode);
306 $isProtocol = $dataNode->extendedAttributes->{ObjCProtocol};
307 $noImpl = $dataNode->extendedAttributes->{ObjCCustomImplementation} || $isProtocol;
309 ReadPublicInterfaces($className, $parentClassName, $defines, $isProtocol);
311 # Start actual generation..
312 $object->GenerateHeader($dataNode);
313 $object->GenerateImplementation($dataNode) unless $noImpl;
316 $object->WriteData("DOM" . $name);
318 # Check for missing public API
319 if (keys %publicInterfaces > 0) {
320 my $missing = join("\n", keys %publicInterfaces);
321 warn "Public API change. There are missing public properties and/or methods from the \"$className\" class.\n$missing\n";
328 # Params: 'idlDocument' struct
332 my $dataNode = shift;
334 $module = $dataNode->module;
339 my $name = $codeGenerator->StripModule(shift);
342 return "NSString" if $codeGenerator->IsStringType($name) or $name eq "SerializedScriptValue";
343 return "NS$name" if IsNativeObjCType($name);
344 return "BOOL" if $name eq "boolean";
345 return "unsigned" if $name eq "unsigned long";
346 return "int" if $name eq "long";
347 return "NSTimeInterval" if $name eq "Date";
348 return "DOMAbstractView" if $name eq "DOMWindow";
349 return $name if $codeGenerator->IsPrimitiveType($name) or $name eq "DOMImplementation" or $name eq "DOMTimeStamp";
351 # Default, assume Objective-C type has the same type name as
352 # idl type prefixed with "DOM".
356 sub GetClassHeaderName
360 return "DOMDOMImplementation" if $name eq "DOMImplementation";
366 my $name = $codeGenerator->StripModule(shift);
368 return "DOMImplementationFront" if $name eq "DOMImplementation";
369 return "DOMWindow" if $name eq "AbstractView";
373 sub GetParentImplClassName
375 my $dataNode = shift;
377 return "Object" if @{$dataNode->parents} eq 0;
379 my $parent = $codeGenerator->StripModule($dataNode->parents(0));
382 return "Object" if $parent eq "HTMLCollection";
387 sub GetParentAndProtocols
389 my $dataNode = shift;
390 my $numParents = @{$dataNode->parents};
394 if ($numParents eq 0) {
396 push(@protocols, "NSObject");
397 push(@protocols, "NSCopying") if $dataNode->name eq "EventTarget";
399 $parent = "DOMObject";
401 } elsif ($numParents eq 1) {
402 my $parentName = $codeGenerator->StripModule($dataNode->parents(0));
404 die "Parents of protocols must also be protocols." unless IsProtocolType($parentName);
405 push(@protocols, "DOM" . $parentName);
407 if (IsProtocolType($parentName)) {
408 push(@protocols, "DOM" . $parentName);
409 } elsif ($parentName eq "HTMLCollection") {
410 $parent = "DOMObject";
412 $parent = "DOM" . $parentName;
416 my @parents = @{$dataNode->parents};
417 my $firstParent = $codeGenerator->StripModule(shift(@parents));
418 if (IsProtocolType($firstParent)) {
419 push(@protocols, "DOM" . $firstParent);
421 $parent = "DOMObject";
424 $parent = "DOM" . $firstParent;
427 foreach my $parentName (@parents) {
428 $parentName = $codeGenerator->StripModule($parentName);
429 die "Everything past the first class should be a protocol!" unless IsProtocolType($parentName);
431 push(@protocols, "DOM" . $parentName);
435 return ($parent, @protocols);
442 return $parent if $parent eq "Object" or IsBaseType($parent);
443 return "Event" if $parent eq "UIEvent";
444 return "CSSValue" if $parent eq "SVGColor" or $parent eq "CSSValueList";
452 return 1 if $baseTypeHash{$type};
460 return 1 if $protocolTypeHash{$type};
468 return 1 if $nativeObjCTypeHash{$type};
475 my $name = GetClassName($type);
477 return "id <$name>" if IsProtocolType($type);
478 return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
479 return "unsigned short" if $type eq "CompareHow" or $type eq "SVGPaintType";
483 sub GetPropertyAttributes
485 my $type = $codeGenerator->StripModule(shift);
486 my $readOnly = shift;
490 push(@attributes, "readonly") if $readOnly;
492 # FIXME: <rdar://problem/5049934> Consider using 'nonatomic' on the DOM @property declarations.
493 if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) {
494 push(@attributes, "copy");
495 } elsif ($codeGenerator->IsPodType($type) || $codeGenerator->IsSVGAnimatedType($type)) {
496 push(@attributes, "retain");
497 } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow" && $type ne "SVGPaintType") {
498 push(@attributes, "retain");
501 return "" unless @attributes > 0;
502 return "(" . join(", ", @attributes) . ")";
507 my $type = $codeGenerator->StripModule(shift);
509 return !$codeGenerator->IsNonPointerType($type) && !$codeGenerator->IsStringType($type) && !IsNativeObjCType($type);
512 sub GetObjCTypeGetter
515 my $type = $codeGenerator->StripModule(shift);
517 return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
518 return $argName . "Node" if $type eq "EventTarget";
519 return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow";
520 return "static_cast<WebCore::SVGPaint::SVGPaintType>($argName)" if $type eq "SVGPaintType";
521 return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener";
522 return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter";
523 return "WTF::getPtr(nativeResolver)" if $type eq "XPathNSResolver";
525 if ($type eq "SerializedScriptValue") {
526 $implIncludes{"SerializedScriptValue.h"} = 1;
527 return "WebCore::SerializedScriptValue::create(WTF::String($argName))";
529 return "core($argName)";
532 sub AddForwardDeclarationsForType
534 my $type = $codeGenerator->StripModule(shift);
537 return if $codeGenerator->IsNonPointerType($type) ;
539 my $class = GetClassName($type);
541 if (IsProtocolType($type)) {
542 $headerForwardDeclarationsForProtocols{$class} = 1 if $public;
543 $privateHeaderForwardDeclarationsForProtocols{$class} = 1 if !$public and !$headerForwardDeclarationsForProtocols{$class};
547 $headerForwardDeclarations{$class} = 1 if $public;
549 # Private headers include the public header, so only add a forward declaration to the private header
550 # if the public header does not already have the same forward declaration.
551 $privateHeaderForwardDeclarations{$class} = 1 if !$public and !$headerForwardDeclarations{$class};
554 sub AddIncludesForType
556 my $type = $codeGenerator->StripModule(shift);
558 return if $codeGenerator->IsNonPointerType($type);
560 if (IsNativeObjCType($type)) {
561 if ($type eq "Color") {
562 $implIncludes{"ColorMac.h"} = 1;
567 if ($codeGenerator->IsStringType($type)) {
568 $implIncludes{"KURL.h"} = 1;
572 if ($type eq "DOMWindow") {
573 $implIncludes{"DOMAbstractViewInternal.h"} = 1;
574 $implIncludes{"DOMWindow.h"} = 1;
578 if ($type eq "DOMImplementation") {
579 $implIncludes{"DOMDOMImplementationInternal.h"} = 1;
580 $implIncludes{"DOMImplementationFront.h"} = 1;
584 if ($type eq "EventTarget") {
585 $implIncludes{"Node.h"} = 1;
586 $implIncludes{"DOMEventTarget.h"} = 1;
590 if ($codeGenerator->IsSVGNewStyleAnimatedType($type)) {
591 $implIncludes{"${type}.h"} = 1;
592 $implIncludes{"DOM${type}Internal.h"} = 1;
596 if ($codeGenerator->IsSVGAnimatedType($type)) {
597 $implIncludes{"DeprecatedSVGAnimatedTemplate.h"} = 1;
598 $implIncludes{"DOM${type}Internal.h"} = 1;
602 if ($type eq "SVGMatrix") {
603 $implIncludes{"AffineTransform.h"} = 1;
604 $implIncludes{"DOMSVGMatrixInternal.h"} = 1;
605 $implIncludes{"SVGException.h"} = 1;
609 if ($type =~ /(\w+)(Abs|Rel)$/) {
610 $implIncludes{"$1.h"} = 1;
611 $implIncludes{"DOM${type}Internal.h"} = 1;
615 if ($type eq "NodeFilter") {
616 $implIncludes{"NodeFilter.h"} = 1;
617 $implIncludes{"ObjCNodeFilterCondition.h"} = 1;
621 if ($type eq "EventListener") {
622 $implIncludes{"EventListener.h"} = 1;
623 $implIncludes{"ObjCEventListener.h"} = 1;
627 if ($type eq "XPathNSResolver") {
628 $implIncludes{"DOMCustomXPathNSResolver.h"} = 1;
629 $implIncludes{"XPathNSResolver.h"} = 1;
633 if ($type eq "SerializedScriptValue") {
634 $implIncludes{"SerializedScriptValue.h"} = 1;
638 # FIXME: won't compile without these
639 $implIncludes{"CSSMutableStyleDeclaration.h"} = 1 if $type eq "CSSStyleDeclaration";
640 $implIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList";
642 # Default, include the same named file (the implementation) and the same name prefixed with "DOM".
643 $implIncludes{"$type.h"} = 1 if not $codeGenerator->AvoidInclusionOfType($type);
644 $implIncludes{"DOM${type}Internal.h"} = 1;
647 sub GetSVGTypeWithNamespace
650 my $typeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($type);
652 # Special case for DOMSVGNumber
653 $typeWithNamespace =~ s/</\<WebCore::/ unless $type eq "SVGNumber";
654 return $typeWithNamespace;
657 sub GetSVGPropertyTypes
659 my $implType = shift;
662 my $svgListPropertyType;
665 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $implType =~ /SVG/;
667 $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($implType);
668 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType;
670 # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType>
671 $svgNativeType = "WebCore::$svgNativeType ";
672 $svgNativeType =~ s/</\<WebCore::/ if not $svgNativeType =~ /float/;
674 my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implType);
675 if ($svgNativeType =~ /SVGPropertyTearOff/) {
676 if ($svgWrappedNativeType eq "float") {
677 # Special case for DOMSVGNumber
678 $svgPropertyType = $svgWrappedNativeType;
680 $svgPropertyType = "WebCore::$svgWrappedNativeType";
681 $svgPropertyType =~ s/</\<WebCore::/;
683 } elsif ($svgNativeType =~ /SVGListPropertyTearOff/ or $svgNativeType =~ /SVGStaticListPropertyTearOff/) {
684 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
685 $svgListPropertyType =~ s/</\<WebCore::/;
688 return ($svgPropertyType, $svgListPropertyType, $svgNativeType);
694 my $dataNode = shift;
696 my $interfaceName = $dataNode->name;
697 my $className = GetClassName($interfaceName);
700 my @protocolsToImplement = ();
701 ($parentName, @protocolsToImplement) = GetParentAndProtocols($dataNode);
703 my $numConstants = @{$dataNode->constants};
704 my $numAttributes = @{$dataNode->attributes};
705 my $numFunctions = @{$dataNode->functions};
707 # - Add default header template
708 @headerContentHeader = split("\r", $headerLicenseTemplate);
709 push(@headerContentHeader, "\n");
712 my $includedWebKitAvailabilityHeader = 0;
713 unless ($isProtocol) {
714 my $parentHeaderName = GetClassHeaderName($parentName);
715 push(@headerContentHeader, "#import <WebCore/$parentHeaderName.h>\n");
716 $includedWebKitAvailabilityHeader = 1;
719 foreach my $parentProtocol (@protocolsToImplement) {
720 next if $parentProtocol =~ /^NS/;
721 $parentProtocol = GetClassHeaderName($parentProtocol);
722 push(@headerContentHeader, "#import <WebCore/$parentProtocol.h>\n");
723 $includedWebKitAvailabilityHeader = 1;
726 # Special case needed for legacy support of DOMRange
727 if ($interfaceName eq "Range") {
728 push(@headerContentHeader, "#import <WebCore/DOMCore.h>\n");
729 push(@headerContentHeader, "#import <WebCore/DOMDocument.h>\n");
730 push(@headerContentHeader, "#import <WebCore/DOMRangeException.h>\n");
731 $includedWebKitAvailabilityHeader = 1;
734 push(@headerContentHeader, "#import <JavaScriptCore/WebKitAvailability.h>\n") unless $includedWebKitAvailabilityHeader;
736 my $interfaceAvailabilityVersionCheck = "#if WEBKIT_VERSION_MAX_ALLOWED >= $interfaceAvailabilityVersion\n\n";
738 push(@headerContentHeader, "\n");
739 push(@headerContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
742 if ($numConstants > 0) {
743 my @headerConstants = ();
745 # FIXME: we need a way to include multiple enums.
746 foreach my $constant (@{$dataNode->constants}) {
747 my $constantName = $constant->name;
748 my $constantValue = $constant->value;
750 my $output = " DOM_" . $constantName . " = " . $constantValue;
751 push(@headerConstants, $output);
754 my $combinedConstants = join(",\n", @headerConstants);
756 # FIXME: the formatting of the enums should line up the equal signs.
757 # FIXME: enums are unconditionally placed in the public header.
758 push(@headerContent, "enum {\n");
759 push(@headerContent, $combinedConstants);
760 push(@headerContent, "\n};\n\n");
763 # - Begin @interface or @protocol
764 my $interfaceDeclaration = ($isProtocol ? "\@protocol $className" : "\@interface $className : $parentName");
765 $interfaceDeclaration .= " <" . join(", ", @protocolsToImplement) . ">" if @protocolsToImplement > 0;
766 $interfaceDeclaration .= "\n";
768 push(@headerContent, $interfaceDeclaration);
770 my @headerAttributes = ();
771 my @privateHeaderAttributes = ();
773 # - Add attribute getters/setters.
774 if ($numAttributes > 0) {
775 foreach my $attribute (@{$dataNode->attributes}) {
776 my $attributeName = $attribute->signature->name;
778 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
779 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
780 $attributeName .= "Name";
781 } elsif ($attributeName eq "frame") {
782 # Special case attribute frame to be frameBorders.
783 $attributeName .= "Borders";
786 my $attributeType = GetObjCType($attribute->signature->type);
787 my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
789 my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attributeIsReadonly);
790 # Some SVGFE*Element.idl use 'operator' as attribute name, rewrite as '_operator' to avoid clashes with C/C++
791 $attributeName =~ s/operator/_operator/ if ($attributeName =~ /operator/);
792 $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName;
794 my $publicInterfaceKey = $property . ";";
796 my $availabilityMacro = "";
797 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
798 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
801 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
803 my $declarationSuffix = ";\n";
804 $declarationSuffix = " $availabilityMacro;\n" if length $availabilityMacro;
806 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
807 delete $publicInterfaces{$publicInterfaceKey};
809 AddForwardDeclarationsForType($attribute->signature->type, $public);
811 my $setterName = "set" . ucfirst($attributeName) . ":";
813 my $conflict = $conflictMethod{$attributeName};
815 warn "$className conflicts with $conflict method $attributeName\n";
819 $conflict = $conflictMethod{$setterName};
821 warn "$className conflicts with $conflict method $setterName\n";
825 if ($buildingForLeopardOrLater) {
826 $property .= $declarationSuffix;
827 push(@headerAttributes, $property) if $public;
828 push(@privateHeaderAttributes, $property) unless $public;
830 my $attributeConditionalString = GenerateConditionalString($attribute->signature);
831 if ($attributeConditionalString) {
832 push(@headerAttributes, "#if ${attributeConditionalString}\n") if $public;
833 push(@privateHeaderAttributes, "#if ${attributeConditionalString}\n") unless $public;
837 my $getter = "- (" . $attributeType . ")" . $attributeName . $declarationSuffix;
838 push(@headerAttributes, $getter) if $public;
839 push(@privateHeaderAttributes, $getter) unless $public;
842 if (!$attributeIsReadonly) {
843 my $setter = "- (void)$setterName(" . $attributeType . ")new" . ucfirst($attributeName) . $declarationSuffix;
844 push(@headerAttributes, $setter) if $public;
845 push(@privateHeaderAttributes, $setter) unless $public;
848 if ($attributeConditionalString) {
849 push(@headerAttributes, "#endif\n") if $public;
850 push(@privateHeaderAttributes, "#endif\n") unless $public;
855 push(@headerContent, @headerAttributes) if @headerAttributes > 0;
858 my @headerFunctions = ();
859 my @privateHeaderFunctions = ();
860 my @deprecatedHeaderFunctions = ();
863 if ($numFunctions > 0) {
864 foreach my $function (@{$dataNode->functions}) {
865 my $functionName = $function->signature->name;
867 my $returnType = GetObjCType($function->signature->type);
868 my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"});
869 my $numberOfParameters = @{$function->parameters};
870 my %typesToForwardDeclare = ($function->signature->type => 1);
872 my $parameterIndex = 0;
873 my $functionSig = "- ($returnType)$functionName";
874 my $methodName = $functionName;
875 foreach my $param (@{$function->parameters}) {
876 my $paramName = $param->name;
877 my $paramType = GetObjCType($param->type);
879 $typesToForwardDeclare{$param->type} = 1;
881 if ($parameterIndex >= 1) {
882 my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
883 $paramPrefix = $paramName unless defined($paramPrefix);
884 $functionSig .= " $paramPrefix";
885 $methodName .= $paramPrefix;
888 $functionSig .= ":($paramType)$paramName";
894 my $publicInterfaceKey = $functionSig . ";";
896 my $conflict = $conflictMethod{$methodName};
898 warn "$className conflicts with $conflict method $methodName\n";
902 if ($isProtocol && !$newPublicClass && !defined $publicInterfaces{$publicInterfaceKey}) {
903 warn "Protocol method $publicInterfaceKey is not in PublicDOMInterfaces.h. Protocols require all methods to be public";
907 my $availabilityMacro = "";
908 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
909 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
912 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
914 my $functionDeclaration = $functionSig;
915 $functionDeclaration .= " " . $availabilityMacro if length $availabilityMacro;
916 $functionDeclaration .= ";\n";
918 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
919 delete $publicInterfaces{$publicInterfaceKey};
921 foreach my $type (keys %typesToForwardDeclare) {
922 # add any forward declarations to the public header if a deprecated version will be generated
923 AddForwardDeclarationsForType($type, 1) if $needsDeprecatedVersion;
924 AddForwardDeclarationsForType($type, $public) unless $public and $needsDeprecatedVersion;
927 push(@headerFunctions, $functionDeclaration) if $public;
928 push(@privateHeaderFunctions, $functionDeclaration) unless $public;
930 # generate the old style method names with un-named parameters, these methods are deprecated
931 if ($needsDeprecatedVersion) {
932 my $deprecatedFunctionSig = $functionSig;
933 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
935 $publicInterfaceKey = $deprecatedFunctionSig . ";";
937 my $availabilityMacro = "AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0";
938 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
939 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
942 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if $buildingForTigerOrEarlier;
944 $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
946 push(@deprecatedHeaderFunctions, $functionDeclaration);
948 unless (defined $publicInterfaces{$publicInterfaceKey}) {
949 warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the OldStyleObjC IDL attribute removed";
953 delete $publicInterfaces{$publicInterfaceKey};
957 if (@headerFunctions > 0) {
958 push(@headerContent, "\n") if $buildingForLeopardOrLater and @headerAttributes > 0;
959 push(@headerContent, @headerFunctions);
963 if (@deprecatedHeaderFunctions > 0 && $isProtocol) {
964 push(@headerContent, @deprecatedHeaderFunctions);
967 # - End @interface or @protocol
968 push(@headerContent, "\@end\n");
970 if (@deprecatedHeaderFunctions > 0 && !$isProtocol) {
971 # - Deprecated category @interface
972 push(@headerContent, "\n\@interface $className (" . $className . "Deprecated)\n");
973 push(@headerContent, @deprecatedHeaderFunctions);
974 push(@headerContent, "\@end\n");
977 push(@headerContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
979 my %alwaysGenerateForNoSVGBuild = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement);
981 if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0 or exists $alwaysGenerateForNoSVGBuild{$className}) {
982 # - Private category @interface
983 @privateHeaderContentHeader = split("\r", $headerLicenseTemplate);
984 push(@privateHeaderContentHeader, "\n");
986 my $classHeaderName = GetClassHeaderName($className);
987 push(@privateHeaderContentHeader, "#import <WebCore/$classHeaderName.h>\n\n");
988 push(@privateHeaderContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
990 @privateHeaderContent = ();
991 push(@privateHeaderContent, "\@interface $className (" . $className . "Private)\n");
992 push(@privateHeaderContent, @privateHeaderAttributes) if @privateHeaderAttributes > 0;
993 push(@privateHeaderContent, "\n") if $buildingForLeopardOrLater and @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0;
994 push(@privateHeaderContent, @privateHeaderFunctions) if @privateHeaderFunctions > 0;
995 push(@privateHeaderContent, "\@end\n");
997 push(@privateHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
1000 unless ($isProtocol) {
1001 # Generate internal interfaces
1002 my $podType = $dataNode->extendedAttributes->{"PODType"};
1003 my $podTypeWithNamespace;
1004 my $implClassName = GetImplClassName($interfaceName);
1005 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
1007 my $implType = $implClassNameWithNamespace;
1008 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
1009 $implType = $svgNativeType if $svgNativeType;
1012 $podTypeWithNamespace = ($podType eq "float") ? "$podType" : "WebCore::$podType";
1015 # Generate interface definitions.
1016 @internalHeaderContent = split("\r", $implementationLicenseTemplate);
1018 push(@internalHeaderContent, "\n#import <WebCore/$className.h>\n\n");
1019 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedPropertyTearOff.h>\n\n") if $svgPropertyType;
1020 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedListPropertyTearOff.h>\n\n") if $svgListPropertyType;
1021 push(@internalHeaderContent, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
1023 if ($interfaceName eq "Node") {
1024 push(@internalHeaderContent, "\@protocol DOMEventTarget;\n\n");
1027 my $startedNamespace = 0;
1029 if ($codeGenerator->IsSVGNewStyleAnimatedType($interfaceName)) {
1030 push(@internalHeaderContent, "#import <WebCore/$implClassName.h>\n\n");
1031 } elsif ($codeGenerator->IsSVGAnimatedType($interfaceName)) {
1032 push(@internalHeaderContent, "#import <WebCore/DeprecatedSVGAnimatedTemplate.h>\n\n");
1034 push(@internalHeaderContent, "namespace WebCore {\n");
1035 $startedNamespace = 1;
1036 if ($podType and $podType ne "float") {
1037 push(@internalHeaderContent, " class $podType;\n");
1038 } elsif ($interfaceName eq "Node") {
1039 push(@internalHeaderContent, " class EventTarget;\n class Node;\n");
1041 push(@internalHeaderContent, " class $implClassName;\n");
1043 push(@internalHeaderContent, "}\n\n");
1047 push(@internalHeaderContent, "$podTypeWithNamespace core($className *);\n");
1048 push(@internalHeaderContent, "$className *kit($podTypeWithNamespace);\n");
1050 push(@internalHeaderContent, "$implType* core($className *);\n");
1051 push(@internalHeaderContent, "$className *kit($implType*);\n");
1054 if ($dataNode->extendedAttributes->{Polymorphic}) {
1055 push(@internalHeaderContent, "Class kitClass($implType*);\n");
1058 if ($interfaceName eq "Node") {
1059 push(@internalHeaderContent, "id <DOMEventTarget> kit(WebCore::EventTarget*);\n");
1062 push(@internalHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
1066 sub GenerateImplementation
1069 my $dataNode = shift;
1071 my @ancestorInterfaceNames = ();
1073 if (@{$dataNode->parents} > 1) {
1074 $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@ancestorInterfaceNames);
1077 my $interfaceName = $dataNode->name;
1078 my $className = GetClassName($interfaceName);
1079 my $implClassName = GetImplClassName($interfaceName);
1080 my $parentImplClassName = GetParentImplClassName($dataNode);
1081 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
1082 my $baseClass = GetBaseClass($parentImplClassName);
1083 my $classHeaderName = GetClassHeaderName($className);
1085 my $numAttributes = @{$dataNode->attributes};
1086 my $numFunctions = @{$dataNode->functions};
1088 my $podType = $dataNode->extendedAttributes->{"PODType"};
1089 my $podTypeWithNamespace;
1090 my $implType = $implClassNameWithNamespace;
1092 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
1093 $implType = $svgNativeType if $svgNativeType;
1096 $podTypeWithNamespace = ($podType eq "float") ? "$podType" : "WebCore::$podType";
1099 # - Add default header template.
1100 @implContentHeader = split("\r", $implementationLicenseTemplate);
1103 push(@implContentHeader, "\n#import \"config.h\"\n");
1105 my $conditionalString = GenerateConditionalString($dataNode);
1106 push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString;
1108 push(@implContentHeader, "#import \"DOMInternal.h\"\n\n");
1109 push(@implContentHeader, "#import \"$classHeaderName.h\"\n\n");
1111 $implIncludes{"ExceptionHandlers.h"} = 1;
1112 $implIncludes{"ThreadCheck.h"} = 1;
1113 $implIncludes{"JSMainThreadExecState.h"} = 1;
1114 $implIncludes{"WebScriptObjectPrivate.h"} = 1;
1115 $implIncludes{$classHeaderName . "Internal.h"} = 1;
1117 # FIXME: These includes are only needed when the class is a subclass of one of these polymorphic classes.
1118 $implIncludes{"DOMBlobInternal.h"} = 1;
1119 $implIncludes{"DOMCSSRuleInternal.h"} = 1;
1120 $implIncludes{"DOMCSSValueInternal.h"} = 1;
1121 $implIncludes{"DOMEventInternal.h"} = 1;
1122 $implIncludes{"DOMNodeInternal.h"} = 1;
1123 $implIncludes{"DOMStyleSheetInternal.h"} = 1;
1125 $implIncludes{"DOMSVGPathSegInternal.h"} = 1 if $interfaceName =~ /^SVGPathSeg.+/;
1127 if ($codeGenerator->IsSVGAnimatedType($interfaceName) and !$codeGenerator->IsSVGNewStyleAnimatedType($interfaceName)) {
1128 $implIncludes{"DeprecatedSVGAnimatedTemplate.h"} = 1;
1129 } elsif ($interfaceName =~ /(\w+)(Abs|Rel)$/) {
1130 $implIncludes{"$1.h"} = 1;
1133 if (!$codeGenerator->AvoidInclusionOfType($implClassName)) {
1134 $implIncludes{"$implClassName.h"} = 1 ;
1135 } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($implClassName)) {
1136 my $includeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implClassName);
1137 $implIncludes{"${includeType}.h"} = 1;
1140 $implIncludes{"$podType.h"} = 1 unless $podType eq "float";
1146 push(@implContent, "#import <wtf/GetPtr.h>\n\n");
1148 # add implementation accessor
1150 push(@implContent, "#define IMPL reinterpret_cast<$podTypeWithNamespace*>(_internal)\n\n");
1151 } elsif ($parentImplClassName eq "Object") {
1152 push(@implContent, "#define IMPL reinterpret_cast<$implType*>(_internal)\n\n");
1154 my $baseClassWithNamespace = "WebCore::$baseClass";
1155 push(@implContent, "#define IMPL static_cast<$implClassNameWithNamespace*>(reinterpret_cast<$baseClassWithNamespace*>(_internal))\n\n");
1158 # START implementation
1159 push(@implContent, "\@implementation $className\n\n");
1161 # Only generate 'dealloc' and 'finalize' methods for direct subclasses of DOMObject.
1162 if ($parentImplClassName eq "Object") {
1163 $implIncludes{"WebCoreObjCExtras.h"} = 1;
1164 push(@implContent, "- (void)dealloc\n");
1165 push(@implContent, "{\n");
1166 push(@implContent, " if (WebCoreObjCScheduleDeallocateOnMainThread([$className class], self))\n");
1167 push(@implContent, " return;\n");
1168 push(@implContent, "\n");
1169 if ($interfaceName eq "NodeIterator") {
1170 push(@implContent, " if (_internal) {\n");
1171 push(@implContent, " [self detach];\n");
1172 push(@implContent, " IMPL->deref();\n");
1173 push(@implContent, " };\n");
1174 } elsif ($podType) {
1175 push(@implContent, " delete IMPL;\n");
1177 push(@implContent, " if (_internal)\n");
1178 push(@implContent, " IMPL->deref();\n");
1180 push(@implContent, " [super dealloc];\n");
1181 push(@implContent, "}\n\n");
1183 push(@implContent, "- (void)finalize\n");
1184 push(@implContent, "{\n");
1185 if ($interfaceName eq "NodeIterator") {
1186 push(@implContent, " if (_internal) {\n");
1187 push(@implContent, " [self detach];\n");
1188 push(@implContent, " IMPL->deref();\n");
1189 push(@implContent, " };\n");
1190 } elsif ($podType) {
1191 push(@implContent, " delete IMPL;\n");
1193 push(@implContent, " if (_internal)\n");
1194 push(@implContent, " IMPL->deref();\n");
1196 push(@implContent, " [super finalize];\n");
1197 push(@implContent, "}\n\n");
1201 %attributeNames = ();
1204 if ($numAttributes > 0) {
1205 foreach my $attribute (@{$dataNode->attributes}) {
1206 AddIncludesForType($attribute->signature->type);
1208 my $idlType = $codeGenerator->StripModule($attribute->signature->type);
1210 my $attributeName = $attribute->signature->name;
1211 my $attributeType = GetObjCType($attribute->signature->type);
1212 my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
1213 my $attributeClassName = GetClassName($attribute->signature->type);
1215 my $attributeInterfaceName = $attributeName;
1216 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
1217 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
1218 $attributeInterfaceName .= "Name";
1219 } elsif ($attributeName eq "frame") {
1220 # Special case attribute frame to be frameBorders.
1221 $attributeInterfaceName .= "Borders";
1222 } elsif ($attributeName eq "operator") {
1223 # Avoid clash with C++ keyword.
1224 $attributeInterfaceName = "_operator";
1227 $attributeNames{$attributeInterfaceName} = 1;
1230 my $getterSig = "- ($attributeType)$attributeInterfaceName\n";
1232 my $getterExpressionPrefix = $codeGenerator->GetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
1234 # FIXME: Special case attribute ownerDocument to call document. This makes it return the
1235 # document when called on the document itself. Legacy behavior, see <https://bugs.webkit.org/show_bug.cgi?id=10889>.
1236 $getterExpressionPrefix =~ s/\bownerDocument\b/document/;
1238 my $hasGetterException = @{$attribute->getterExceptions};
1239 my $getterContentHead = "IMPL->$getterExpressionPrefix";
1240 my $getterContentTail = ")";
1242 if ($svgPropertyType) {
1243 $getterContentHead = "$getterExpressionPrefix";
1245 # TODO: Handle special case for DOMSVGLength. We do need Custom code support for this.
1246 if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
1247 $getterContentHead = "value(IMPL->contextElement(), ";
1251 my $attributeTypeSansPtr = $attributeType;
1252 $attributeTypeSansPtr =~ s/ \*$//; # Remove trailing " *" from pointer types.
1254 # special case for EventTarget protocol
1255 $attributeTypeSansPtr = "DOMNode" if $idlType eq "EventTarget";
1258 my @customGetterContent = ();
1259 if ($attributeTypeSansPtr eq "DOMImplementation") {
1260 # FIXME: We have to special case DOMImplementation until DOMImplementationFront is removed
1261 $getterContentHead = "kit(implementationFront(IMPL";
1262 $getterContentTail .= ")";
1263 } elsif ($attributeName =~ /(\w+)DisplayString$/) {
1264 my $attributeToDisplay = $1;
1265 $getterContentHead = "WebCore::displayString(IMPL->$attributeToDisplay(), core(self)";
1266 $implIncludes{"HitTestResult.h"} = 1;
1267 } elsif ($attributeName =~ /^absolute(\w+)URL$/) {
1269 $getterContentHead = "[self _getURLAttribute:";
1270 if ($typeOfURL eq "Link") {
1271 $getterContentTail = "\@\"href\"]";
1272 } elsif ($typeOfURL eq "Image") {
1273 if ($interfaceName eq "HTMLObjectElement") {
1274 $getterContentTail = "\@\"data\"]";
1276 $getterContentTail = "\@\"src\"]";
1278 unless ($interfaceName eq "HTMLImageElement") {
1279 push(@customGetterContent, " if (!IMPL->renderer() || !IMPL->renderer()->isImage())\n");
1280 push(@customGetterContent, " return nil;\n");
1281 $implIncludes{"RenderObject.h"} = 1;
1284 $implIncludes{"DOMPrivate.h"} = 1;
1285 } elsif ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
1286 $getterContentHead = "WTF::String::number(" . $getterContentHead;
1287 $getterContentTail .= ")";
1288 } elsif ($codeGenerator->IsPodType($idlType) or $idlType eq "Date") {
1289 $getterContentHead = "kit($getterContentHead";
1290 $getterContentTail .= ")";
1291 } elsif ($svgPropertyType) {
1292 # Special case for DOMSVGNumber
1293 if ($svgPropertyType eq "float") {
1294 # Intentional leave out closing brace, it's already contained in getterContentTail
1295 $getterContentHead = "IMPL->propertyReference(";
1297 $getterContentHead = "IMPL->propertyReference().$getterContentHead";
1299 } elsif ($codeGenerator->IsSVGNewStyleAnimatedType($implClassName) and $codeGenerator->IsSVGTypeNeedingTearOff($idlType)) {
1300 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
1301 $getterContentHead = "kit(static_cast<$idlTypeWithNamespace*>($getterContentHead)";
1302 $getterContentTail .= ")";
1303 } elsif (IsProtocolType($idlType) and $idlType ne "EventTarget") {
1304 $getterContentHead = "kit($getterContentHead";
1305 $getterContentTail .= ")";
1306 } elsif ($idlType eq "Color") {
1307 $getterContentHead = "WebCore::nsColor($getterContentHead";
1308 $getterContentTail .= ")";
1309 } elsif ($attribute->signature->type eq "SerializedScriptValue") {
1310 $getterContentHead = "$getterContentHead";
1311 $getterContentTail .= "->toString()";
1312 } elsif (ConversionNeeded($attribute->signature->type)) {
1313 my $type = $attribute->signature->type;
1314 if ($codeGenerator->IsSVGTypeNeedingTearOff($type) and not $implClassName =~ /List$/) {
1315 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($type);
1316 if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($type) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
1317 $idlTypeWithNamespace =~ s/SVGPropertyTearOff</SVGStaticPropertyTearOff<$implClassNameWithNamespace, /;
1318 $implIncludes{"SVGStaticPropertyTearOff.h"} = 1;
1320 my $getter = $getterContentHead;
1321 $getter =~ s/IMPL->//;
1323 my $updater = "update" . $codeGenerator->WK_ucfirst($getter);
1324 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead$getterContentTail, &${implClassNameWithNamespace}::$updater";
1325 $getterContentTail .= "))";
1326 } elsif ($idlTypeWithNamespace =~ /SVGStaticListPropertyTearOff/) {
1327 my $extraImp = "WebCore::GetOwnerElementForType<$implClassNameWithNamespace, WebCore::IsDerivedFromSVGElement<$implClassNameWithNamespace>::value>::ownerElement(IMPL), ";
1328 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($extraImp$getterContentHead";
1329 $getterContentTail .= ")))";
1330 } elsif ($idlTypeWithNamespace =~ /SVGPointList/) {
1331 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1332 $getterContentTail .= "))";
1334 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($getterContentHead";
1335 $getterContentTail .= ")))";
1338 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1339 $getterContentTail .= "))";
1344 if ($hasGetterException) {
1345 $getterContent = $getterContentHead . "ec" . $getterContentTail;
1347 $getterContent = $getterContentHead . $getterContentTail;
1350 my $attributeConditionalString = GenerateConditionalString($attribute->signature);
1351 push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString;
1352 push(@implContent, $getterSig);
1353 push(@implContent, "{\n");
1354 push(@implContent, " $jsContextSetter\n");
1355 push(@implContent, @customGetterContent);
1356 if ($hasGetterException) {
1357 # Differentiated between when the return type is a pointer and
1358 # not for white space issue (ie. Foo *result vs. int result).
1359 if ($attributeType =~ /\*$/) {
1360 $getterContent = $attributeType . "result = " . $getterContent;
1362 $getterContent = $attributeType . " result = " . $getterContent;
1365 push(@implContent, " $exceptionInit\n");
1366 push(@implContent, " $getterContent;\n");
1367 push(@implContent, " $exceptionRaiseOnError\n");
1368 push(@implContent, " return result;\n");
1370 push(@implContent, " return $getterContent;\n");
1372 push(@implContent, "}\n");
1375 if (!$attributeIsReadonly) {
1376 # Exception handling
1377 my $hasSetterException = @{$attribute->setterExceptions};
1379 my $coreSetterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
1380 my $setterName = "set" . ucfirst($attributeInterfaceName);
1381 my $argName = "new" . ucfirst($attributeInterfaceName);
1382 my $arg = GetObjCTypeGetter($argName, $idlType);
1384 # The definition of ConvertToString is flipped for the setter
1385 if ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
1386 $arg = "WTF::String($arg).toInt()";
1389 my $setterSig = "- (void)$setterName:($attributeType)$argName\n";
1391 push(@implContent, "\n");
1392 push(@implContent, $setterSig);
1393 push(@implContent, "{\n");
1394 push(@implContent, " $jsContextSetter\n");
1396 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1397 push(@implContent, " ASSERT($argName);\n\n");
1400 if ($idlType eq "Date") {
1401 $arg = "core(" . $arg . ")";
1404 if ($svgPropertyType) {
1405 $getterContentHead = "$getterExpressionPrefix";
1406 push(@implContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1407 my $ec = $hasSetterException ? ", ec" : "";
1408 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1410 # Special case for DOMSVGNumber
1411 if ($svgPropertyType eq "float") {
1412 push(@implContent, " podImpl = $arg;\n");
1414 # FIXME: Special case for DOMSVGLength. We do need Custom code support for this.
1415 if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
1416 push(@implContent, " podImpl.$coreSetterName($arg, IMPL->contextElement()$ec);\n");
1418 push(@implContent, " podImpl.$coreSetterName($arg$ec);\n");
1422 if ($hasSetterException) {
1423 push(@implContent, " if (!ec)\n");
1424 push(@implContent, " IMPL->commitChange();\n");
1425 push(@implContent, " $exceptionRaiseOnError\n");
1427 push(@implContent, " IMPL->commitChange();\n");
1429 } elsif ($svgListPropertyType) {
1430 $getterContentHead = "$getterExpressionPrefix";
1431 push(@implContent, " IMPL->$coreSetterName($arg);\n");
1432 } elsif ($podType) {
1433 push(@implContent, " IMPL->$coreSetterName($arg);\n");
1435 my $setterExpressionPrefix = $codeGenerator->SetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
1436 my $ec = $hasSetterException ? ", ec" : "";
1437 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1438 push(@implContent, " IMPL->$setterExpressionPrefix$arg$ec);\n");
1439 push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException;
1442 push(@implContent, "}\n");
1445 push(@implContent, "#endif\n") if $attributeConditionalString;
1446 push(@implContent, "\n");
1451 if ($numFunctions > 0) {
1452 foreach my $function (@{$dataNode->functions}) {
1453 AddIncludesForType($function->signature->type);
1455 my $functionName = $function->signature->name;
1456 my $returnType = GetObjCType($function->signature->type);
1457 my $hasParameters = @{$function->parameters};
1458 my $raisesExceptions = @{$function->raisesExceptions};
1460 my @parameterNames = ();
1461 my @needsAssert = ();
1462 my %needsCustom = ();
1464 my $parameterIndex = 0;
1465 my $functionSig = "- ($returnType)$functionName";
1466 foreach my $param (@{$function->parameters}) {
1467 my $paramName = $param->name;
1468 my $paramType = GetObjCType($param->type);
1470 # make a new parameter name if the original conflicts with a property name
1471 $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
1473 AddIncludesForType($param->type);
1475 my $idlType = $codeGenerator->StripModule($param->type);
1476 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1478 push(@parameterNames, $implGetter);
1479 $needsCustom{"XPathNSResolver"} = $paramName if $idlType eq "XPathNSResolver";
1480 $needsCustom{"NodeFilter"} = $paramName if $idlType eq "NodeFilter";
1481 $needsCustom{"EventListener"} = $paramName if $idlType eq "EventListener";
1482 $needsCustom{"EventTarget"} = $paramName if $idlType eq "EventTarget";
1483 $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"Return"};
1485 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1486 push(@needsAssert, " ASSERT($paramName);\n");
1489 if ($parameterIndex >= 1) {
1490 my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
1491 $paramPrefix = $param->name unless defined($paramPrefix);
1492 $functionSig .= " $paramPrefix";
1495 $functionSig .= ":($paramType)$paramName";
1500 my @functionContent = ();
1501 my $caller = "IMPL";
1503 # special case the XPathNSResolver
1504 if (defined $needsCustom{"XPathNSResolver"}) {
1505 my $paramName = $needsCustom{"XPathNSResolver"};
1506 push(@functionContent, " WebCore::XPathNSResolver* nativeResolver = 0;\n");
1507 push(@functionContent, " RefPtr<WebCore::XPathNSResolver> customResolver;\n");
1508 push(@functionContent, " if ($paramName) {\n");
1509 push(@functionContent, " if ([$paramName isMemberOfClass:[DOMNativeXPathNSResolver class]])\n");
1510 push(@functionContent, " nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>($paramName));\n");
1511 push(@functionContent, " else {\n");
1512 push(@functionContent, " customResolver = WebCore::DOMCustomXPathNSResolver::create($paramName);\n");
1513 push(@functionContent, " nativeResolver = WTF::getPtr(customResolver);\n");
1514 push(@functionContent, " }\n");
1515 push(@functionContent, " }\n");
1518 # special case the EventTarget
1519 if (defined $needsCustom{"EventTarget"}) {
1520 my $paramName = $needsCustom{"EventTarget"};
1521 push(@functionContent, " DOMNode* ${paramName}ObjC = $paramName;\n");
1522 push(@functionContent, " WebCore::Node* ${paramName}Node = core(${paramName}ObjC);\n");
1523 $implIncludes{"DOMNode.h"} = 1;
1524 $implIncludes{"Node.h"} = 1;
1527 if ($function->signature->extendedAttributes->{"UsesView"}) {
1528 push(@functionContent, " WebCore::DOMWindow* dv = $caller->defaultView();\n");
1529 push(@functionContent, " if (!dv)\n");
1530 push(@functionContent, " return nil;\n");
1531 $implIncludes{"DOMWindow.h"} = 1;
1535 # special case the EventListener
1536 if (defined $needsCustom{"EventListener"}) {
1537 my $paramName = $needsCustom{"EventListener"};
1538 push(@functionContent, " RefPtr<WebCore::EventListener> nativeEventListener = WebCore::ObjCEventListener::wrap($paramName);\n");
1541 # special case the NodeFilter
1542 if (defined $needsCustom{"NodeFilter"}) {
1543 my $paramName = $needsCustom{"NodeFilter"};
1544 push(@functionContent, " RefPtr<WebCore::NodeFilter> nativeNodeFilter;\n");
1545 push(@functionContent, " if ($paramName)\n");
1546 push(@functionContent, " nativeNodeFilter = WebCore::NodeFilter::create(WebCore::ObjCNodeFilterCondition::create($paramName));\n");
1549 # FIXME! We need [Custom] support for ObjC, to move these hacks into DOMSVGLength/MatrixCustom.mm
1550 my $svgMatrixRotateFromVector = ($podType and $podType eq "AffineTransform" and $functionName eq "rotateFromVector");
1551 my $svgMatrixInverse = ($podType and $podType eq "AffineTransform" and $functionName eq "inverse");
1552 my $svgLengthConvertToSpecifiedUnits = ($svgPropertyType and $svgPropertyType eq "WebCore::SVGLength" and $functionName eq "convertToSpecifiedUnits");
1554 push(@parameterNames, "IMPL->contextElement()") if $svgLengthConvertToSpecifiedUnits;
1555 push(@parameterNames, "ec") if $raisesExceptions and !($svgMatrixRotateFromVector || $svgMatrixInverse);
1557 # Handle arguments that are 'SVGProperty' based (SVGAngle/SVGLength). We need to convert from SVGPropertyTearOff<Type>* to Type,
1558 # to be able to call the desired WebCore function. If the conversion fails, we can't extract Type and need to raise an exception.
1559 my $currentParameter = -1;
1560 foreach my $param (@{$function->parameters}) {
1561 $currentParameter++;
1563 my $paramName = $param->name;
1564 my $idlType = $codeGenerator->StripModule($param->type);
1565 next if not $codeGenerator->IsSVGTypeNeedingTearOff($idlType) or $implClassName =~ /List$/;
1567 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1568 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
1570 push(@functionContent, " $idlTypeWithNamespace* ${paramName}Core = $implGetter;\n");
1571 push(@functionContent, " if (!${paramName}Core) {\n");
1572 push(@functionContent, " WebCore::ExceptionCode ec = WebCore::TYPE_MISMATCH_ERR;\n");
1573 push(@functionContent, " $exceptionRaiseOnError\n");
1574 if ($returnType eq "void") {
1575 push(@functionContent, " return;\n");
1577 push(@functionContent, " return nil;\n");
1579 push(@functionContent, " }\n");
1581 # Replace the paramter core() getter, by the cached variable.
1582 splice(@parameterNames, $currentParameter, 1, "${paramName}Core->propertyReference()");
1585 my $content = $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
1587 if ($svgPropertyType) {
1588 push(@functionContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1589 $content = "podImpl.$content";
1591 $content = $caller . "->$content";
1594 if ($svgMatrixRotateFromVector) {
1595 # Special case with rotateFromVector & SVGMatrix
1596 push(@functionContent, " $exceptionInit\n");
1597 push(@functionContent, " if (x == 0.0 || y == 0.0)\n");
1598 push(@functionContent, " ec = WebCore::SVGException::SVG_INVALID_VALUE_ERR;\n");
1599 push(@functionContent, " $exceptionRaiseOnError\n");
1600 push(@functionContent, " return kit($content);\n");
1601 } elsif ($svgMatrixInverse) {
1602 # Special case with inverse & SVGMatrix
1603 push(@functionContent, " $exceptionInit\n");
1604 push(@functionContent, " if (!$caller->isInvertible())\n");
1605 push(@functionContent, " ec = WebCore::SVGException::SVG_MATRIX_NOT_INVERTABLE;\n");
1606 push(@functionContent, " $exceptionRaiseOnError\n");
1607 push(@functionContent, " return kit($content);\n");
1608 } elsif ($returnType eq "void") {
1609 # Special case 'void' return type.
1610 if ($raisesExceptions) {
1611 push(@functionContent, " $exceptionInit\n");
1612 push(@functionContent, " $content;\n");
1613 if ($svgPropertyType) {
1614 push(@functionContent, " if (!ec)\n");
1615 push(@functionContent, " IMPL->commitChange();\n");
1617 push(@functionContent, " $exceptionRaiseOnError\n");
1619 push(@functionContent, " $content;\n");
1620 push(@functionContent, " IMPL->commitChange()\n") if $svgPropertyType;
1622 } elsif (defined $needsCustom{"NodeToReturn"}) {
1623 # Special case the insertBefore, replaceChild, removeChild
1624 # and appendChild functions from DOMNode
1625 my $toReturn = $needsCustom{"NodeToReturn"};
1626 if ($raisesExceptions) {
1627 push(@functionContent, " $exceptionInit\n");
1628 push(@functionContent, " if ($content)\n");
1629 push(@functionContent, " return $toReturn;\n");
1630 push(@functionContent, " $exceptionRaiseOnError\n");
1631 push(@functionContent, " return nil;\n");
1633 push(@functionContent, " if ($content)\n");
1634 push(@functionContent, " return $toReturn;\n");
1635 push(@functionContent, " return nil;\n");
1637 } elsif ($returnType eq "SerializedScriptValue") {
1640 if (ConversionNeeded($function->signature->type)) {
1641 if ($codeGenerator->IsSVGTypeNeedingTearOff($function->signature->type) and not $implClassName =~ /List$/) {
1642 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($function->signature->type);
1643 $content = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($content)))";
1644 } elsif ($codeGenerator->IsPodType($function->signature->type)) {
1645 $content = "kit($content)";
1647 $content = "kit(WTF::getPtr($content))";
1651 if ($raisesExceptions) {
1652 # Differentiated between when the return type is a pointer and
1653 # not for white space issue (ie. Foo *result vs. int result).
1654 if ($returnType =~ /\*$/) {
1655 $content = $returnType . "result = " . $content;
1657 $content = $returnType . " result = " . $content;
1660 push(@functionContent, " $exceptionInit\n");
1661 push(@functionContent, " $content;\n");
1662 push(@functionContent, " $exceptionRaiseOnError\n");
1663 push(@functionContent, " return result;\n");
1665 push(@functionContent, " return $content;\n");
1669 push(@implContent, "$functionSig\n");
1670 push(@implContent, "{\n");
1671 push(@implContent, " $jsContextSetter\n");
1672 push(@implContent, @functionContent);
1673 push(@implContent, "}\n\n");
1675 # generate the old style method names with un-named parameters, these methods are deprecated
1676 if (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"}) {
1677 my $deprecatedFunctionSig = $functionSig;
1678 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
1680 push(@implContent, "$deprecatedFunctionSig\n");
1681 push(@implContent, "{\n");
1682 push(@implContent, " $jsContextSetter\n");
1683 push(@implContent, @functionContent);
1684 push(@implContent, "}\n\n");
1692 # END implementation
1693 push(@implContent, "\@end\n");
1695 # Generate internal interfaces
1697 push(@implContent, "\n$podTypeWithNamespace core($className *wrapper)\n");
1698 push(@implContent, "{\n");
1699 push(@implContent, " return wrapper ? *reinterpret_cast<$podTypeWithNamespace*>(wrapper->_internal) : $podTypeWithNamespace();\n");
1700 push(@implContent, "}\n\n");
1702 push(@implContent, "\n$implType* core($className *wrapper)\n");
1703 push(@implContent, "{\n");
1704 push(@implContent, " return wrapper ? reinterpret_cast<$implType*>(wrapper->_internal) : 0;\n");
1705 push(@implContent, "}\n\n");
1709 # FIXME: Implement caching.
1710 push(@implContent, "$className *kit($podTypeWithNamespace value)\n");
1711 push(@implContent, "{\n");
1712 push(@implContent, " $assertMainThread;\n");
1713 push(@implContent, " $className *wrapper = [[$className alloc] _init];\n");
1714 push(@implContent, " wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(new $podTypeWithNamespace(value));\n");
1715 push(@implContent, " return [wrapper autorelease];\n");
1716 push(@implContent, "}\n");
1717 } elsif ($parentImplClassName eq "Object") {
1718 push(@implContent, "$className *kit($implType* value)\n");
1719 push(@implContent, "{\n");
1720 push(@implContent, " $assertMainThread;\n");
1721 push(@implContent, " if (!value)\n");
1722 push(@implContent, " return nil;\n");
1723 push(@implContent, " if ($className *wrapper = getDOMWrapper(value))\n");
1724 push(@implContent, " return [[wrapper retain] autorelease];\n");
1725 if ($dataNode->extendedAttributes->{Polymorphic}) {
1726 push(@implContent, " $className *wrapper = [[kitClass(value) alloc] _init];\n");
1727 push(@implContent, " if (!wrapper)\n");
1728 push(@implContent, " return nil;\n");
1730 push(@implContent, " $className *wrapper = [[$className alloc] _init];\n");
1732 push(@implContent, " wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(value);\n");
1733 push(@implContent, " value->ref();\n");
1734 push(@implContent, " addDOMWrapper(wrapper, value);\n");
1735 push(@implContent, " return [wrapper autorelease];\n");
1736 push(@implContent, "}\n");
1738 push(@implContent, "$className *kit($implType* value)\n");
1739 push(@implContent, "{\n");
1740 push(@implContent, " $assertMainThread;\n");
1741 push(@implContent, " return static_cast<$className*>(kit(static_cast<WebCore::$baseClass*>(value)));\n");
1742 push(@implContent, "}\n");
1745 # - End the ifdef conditional if necessary
1746 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
1748 # - Generate dependencies.
1749 if ($writeDependencies && @ancestorInterfaceNames) {
1750 push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n");
1751 push(@depsContent, map { "$_.idl :\n" } @ancestorInterfaceNames);
1761 # Open files for writing...
1762 my $headerFileName = "$outputDir/" . $name . ".h";
1763 my $privateHeaderFileName = "$outputDir/" . $name . "Private.h";
1764 my $implFileName = "$outputDir/" . $name . ".mm";
1765 my $internalHeaderFileName = "$outputDir/" . $name . "Internal.h";
1766 my $depsFileName = "$outputDir/" . $name . ".dep";
1769 unlink($headerFileName);
1770 unlink($privateHeaderFileName);
1771 unlink($implFileName);
1772 unlink($internalHeaderFileName);
1773 unlink($depsFileName);
1775 # Write public header.
1776 open(HEADER, ">$headerFileName") or die "Couldn't open file $headerFileName";
1778 print HEADER @headerContentHeader;
1779 print HEADER map { "\@class $_;\n" } sort keys(%headerForwardDeclarations);
1780 print HEADER map { "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
1782 my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols);
1783 print HEADER "\n" if $hasForwardDeclarations;
1784 print HEADER @headerContent;
1788 @headerContentHeader = ();
1789 @headerContent = ();
1790 %headerForwardDeclarations = ();
1791 %headerForwardDeclarationsForProtocols = ();
1793 if (@privateHeaderContent > 0) {
1794 open(PRIVATE_HEADER, ">$privateHeaderFileName") or die "Couldn't open file $privateHeaderFileName";
1796 print PRIVATE_HEADER @privateHeaderContentHeader;
1797 print PRIVATE_HEADER map { "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
1798 print PRIVATE_HEADER map { "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
1800 $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols);
1801 print PRIVATE_HEADER "\n" if $hasForwardDeclarations;
1802 print PRIVATE_HEADER @privateHeaderContent;
1804 close(PRIVATE_HEADER);
1806 @privateHeaderContentHeader = ();
1807 @privateHeaderContent = ();
1808 %privateHeaderForwardDeclarations = ();
1809 %privateHeaderForwardDeclarationsForProtocols = ();
1812 # Write implementation file.
1814 open(IMPL, ">$implFileName") or die "Couldn't open file $implFileName";
1816 print IMPL @implContentHeader;
1817 print IMPL map { "#import \"$_\"\n" } sort keys(%implIncludes);
1818 print IMPL @implContent;
1822 @implContentHeader = ();
1827 if (@internalHeaderContent > 0) {
1828 open(INTERNAL_HEADER, ">$internalHeaderFileName") or die "Couldn't open file $internalHeaderFileName";
1830 print INTERNAL_HEADER @internalHeaderContent;
1832 close(INTERNAL_HEADER);
1834 @internalHeaderContent = ();
1837 # Write dependency file.
1839 open(DEPS, ">$depsFileName") or die "Couldn't open file $depsFileName";
1840 print DEPS @depsContent;