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, "SVGAnimatedPoints" => 1,
63 "ElementTimeControl" => 1);
64 my %nativeObjCTypeHash = ("URL" => 1, "Color" => 1);
66 # FIXME: this should be replaced with a function that recurses up the tree
67 # to find the actual base type.
68 my %baseTypeHash = ("Object" => 1, "Node" => 1, "NodeList" => 1, "NamedNodeMap" => 1, "DOMImplementation" => 1,
69 "Event" => 1, "CSSRule" => 1, "CSSValue" => 1, "StyleSheet" => 1, "MediaList" => 1,
70 "Counter" => 1, "Rect" => 1, "RGBColor" => 1, "XPathExpression" => 1, "XPathResult" => 1,
71 "NodeIterator" => 1, "TreeWalker" => 1, "AbstractView" => 1, "Blob" => 1,
72 "SVGAngle" => 1, "SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1, "SVGAnimatedEnumeration" => 1,
73 "SVGAnimatedInteger" => 1, "SVGAnimatedLength" => 1, "SVGAnimatedLengthList" => 1,
74 "SVGAnimatedNumber" => 1, "SVGAnimatedNumberList" => 1, "SVGAnimatedPoints" => 1,
75 "SVGAnimatedPreserveAspectRatio" => 1, "SVGAnimatedRect" => 1, "SVGAnimatedString" => 1,
76 "SVGAnimatedTransformList" => 1, "SVGLength" => 1, "SVGLengthList" => 1, "SVGMatrix" => 1,
77 "SVGNumber" => 1, "SVGNumberList" => 1, "SVGPathSeg" => 1, "SVGPathSegList" => 1, "SVGPoint" => 1,
78 "SVGPointList" => 1, "SVGPreserveAspectRatio" => 1, "SVGRect" => 1, "SVGRenderingIntent" => 1,
79 "SVGStringList" => 1, "SVGTransform" => 1, "SVGTransformList" => 1, "SVGUnitTypes" => 1);
82 my $buildingForTigerOrEarlier = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} <= 10.4;
83 my $buildingForLeopardOrLater = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} >= 10.5;
84 my $exceptionInit = "WebCore::ExceptionCode ec = 0;";
85 my $jsContextSetter = "WebCore::JSMainThreadNullState state;";
86 my $exceptionRaiseOnError = "WebCore::raiseOnDOMError(ec);";
87 my $assertMainThread = "{ DOM_ASSERT_MAIN_THREAD(); WebCoreThreadViolationCheckRoundOne(); }";
89 my %conflictMethod = (
90 # FIXME: Add C language keywords?
91 # FIXME: Add other predefined types like "id"?
93 "callWebScriptMethod:withArguments:" => "WebScriptObject",
94 "evaluateWebScript:" => "WebScriptObject",
95 "removeWebScriptKey:" => "WebScriptObject",
96 "setException:" => "WebScriptObject",
97 "setWebScriptValueAtIndex:value:" => "WebScriptObject",
98 "stringRepresentation" => "WebScriptObject",
99 "webScriptValueAtIndex:" => "WebScriptObject",
101 "autorelease" => "NSObject",
102 "awakeAfterUsingCoder:" => "NSObject",
103 "class" => "NSObject",
104 "classForCoder" => "NSObject",
105 "conformsToProtocol:" => "NSObject",
106 "copy" => "NSObject",
107 "copyWithZone:" => "NSObject",
108 "dealloc" => "NSObject",
109 "description" => "NSObject",
110 "doesNotRecognizeSelector:" => "NSObject",
111 "encodeWithCoder:" => "NSObject",
112 "finalize" => "NSObject",
113 "forwardInvocation:" => "NSObject",
114 "hash" => "NSObject",
115 "init" => "NSObject",
116 "initWithCoder:" => "NSObject",
117 "isEqual:" => "NSObject",
118 "isKindOfClass:" => "NSObject",
119 "isMemberOfClass:" => "NSObject",
120 "isProxy" => "NSObject",
121 "methodForSelector:" => "NSObject",
122 "methodSignatureForSelector:" => "NSObject",
123 "mutableCopy" => "NSObject",
124 "mutableCopyWithZone:" => "NSObject",
125 "performSelector:" => "NSObject",
126 "release" => "NSObject",
127 "replacementObjectForCoder:" => "NSObject",
128 "respondsToSelector:" => "NSObject",
129 "retain" => "NSObject",
130 "retainCount" => "NSObject",
131 "self" => "NSObject",
132 "superclass" => "NSObject",
133 "zone" => "NSObject",
138 # Default License Templates
139 my $headerLicenseTemplate = << "EOF";
141 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
142 * Copyright (C) 2006 Samuel Weinig <sam.weinig\@gmail.com>
144 * Redistribution and use in source and binary forms, with or without
145 * modification, are permitted provided that the following conditions
147 * 1. Redistributions of source code must retain the above copyright
148 * notice, this list of conditions and the following disclaimer.
149 * 2. Redistributions in binary form must reproduce the above copyright
150 * notice, this list of conditions and the following disclaimer in the
151 * documentation and/or other materials provided with the distribution.
153 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
154 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
155 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
156 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
157 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
158 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
159 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
160 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
161 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
162 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
163 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
167 my $implementationLicenseTemplate = << "EOF";
169 * This file is part of the WebKit open source project.
170 * This file has been generated by generate-bindings.pl. DO NOT MODIFY!
172 * Redistribution and use in source and binary forms, with or without
173 * modification, are permitted provided that the following conditions
175 * 1. Redistributions of source code must retain the above copyright
176 * notice, this list of conditions and the following disclaimer.
177 * 2. Redistributions in binary form must reproduce the above copyright
178 * notice, this list of conditions and the following disclaimer in the
179 * documentation and/or other materials provided with the distribution.
181 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
182 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
183 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
184 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
185 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
186 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
187 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
188 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
189 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
190 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
191 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
195 # Default constructor
201 $codeGenerator = shift;
203 shift; # $outputHeadersDir
204 shift; # $useLayerOnTop
205 shift; # $preprocessor
206 $writeDependencies = shift;
208 bless($reference, $object);
217 sub ReadPublicInterfaces
220 my $superClass = shift;
222 my $isProtocol = shift;
225 my $actualSuperClass;
226 %publicInterfaces = ();
228 my $fileName = "WebCore/bindings/objc/PublicDOMInterfaces.h";
229 my $gccLocation = "";
231 $gccLocation = $ENV{CC};
232 } elsif (($Config::Config{'osname'}) =~ /solaris/i) {
233 $gccLocation = "/usr/sfw/bin/gcc";
235 $gccLocation = "/usr/bin/gcc";
237 open FILE, "-|", $gccLocation, "-E", "-P", "-x", "objective-c",
238 (map { "-D$_" } split(/ +/, $defines)), "-DOBJC_CODE_GENERATION", $fileName or die "Could not open $fileName";
239 my @documentContent = <FILE>;
242 foreach $line (@documentContent) {
243 if (!$isProtocol && $line =~ /^\s*\@interface\s*$class\s*:\s*(\w+)\s*([A-Z0-9_]*)/) {
244 if ($superClass ne $1) {
245 warn "Public API change. Superclass for \"$class\" differs ($1 != $superClass)";
249 $interfaceAvailabilityVersion = $2 if defined $2;
252 } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*<[^>]+>\s*([A-Z0-9_]*)/) {
253 $interfaceAvailabilityVersion = $1 if defined $1;
258 last if $found and $line =~ /^\s?\@end\s?$/;
265 my $availabilityMacro = "";
266 $line =~ s/\s([A-Z0-9_]+)\s*;$/;/;
267 $availabilityMacro = $1 if defined $1;
269 $publicInterfaces{$line} = $availabilityMacro if length $line;
273 # If this class was not found in PublicDOMInterfaces.h then it should be considered as an entirely new public class.
274 $newPublicClass = !$found;
275 $interfaceAvailabilityVersion = "WEBKIT_VERSION_LATEST" if $newPublicClass;
278 sub GenerateConditionalString
281 my $conditional = $node->extendedAttributes->{"Conditional"};
283 if ($conditional =~ /&/) {
284 return "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
285 } elsif ($conditional =~ /\|/) {
286 return "ENABLE(" . join(") || ENABLE(", split(/\|/, $conditional)) . ")";
288 return "ENABLE(" . $conditional . ")";
295 # Params: 'domClass' struct
296 sub GenerateInterface
299 my $dataNode = shift;
304 my $name = $dataNode->name;
305 my $className = GetClassName($name);
306 my $parentClassName = "DOM" . GetParentImplClassName($dataNode);
307 $isProtocol = $dataNode->extendedAttributes->{ObjCProtocol};
308 $noImpl = $dataNode->extendedAttributes->{ObjCCustomImplementation} || $isProtocol;
310 ReadPublicInterfaces($className, $parentClassName, $defines, $isProtocol);
312 # Start actual generation..
313 $object->GenerateHeader($dataNode);
314 $object->GenerateImplementation($dataNode) unless $noImpl;
317 $object->WriteData("DOM" . $name);
319 # Check for missing public API
320 if (keys %publicInterfaces > 0) {
321 my $missing = join("\n", keys %publicInterfaces);
322 warn "Public API change. There are missing public properties and/or methods from the \"$className\" class.\n$missing\n";
329 # Params: 'idlDocument' struct
333 my $dataNode = shift;
335 $module = $dataNode->module;
340 my $name = $codeGenerator->StripModule(shift);
343 return "NSString" if $codeGenerator->IsStringType($name) or $name eq "SerializedScriptValue";
344 return "NS$name" if IsNativeObjCType($name);
345 return "BOOL" if $name eq "boolean";
346 return "unsigned" if $name eq "unsigned long";
347 return "int" if $name eq "long";
348 return "NSTimeInterval" if $name eq "Date";
349 return "DOMAbstractView" if $name eq "DOMWindow";
350 return $name if $codeGenerator->IsPrimitiveType($name) or $name eq "DOMImplementation" or $name eq "DOMTimeStamp";
352 # Default, assume Objective-C type has the same type name as
353 # idl type prefixed with "DOM".
357 sub GetClassHeaderName
361 return "DOMDOMImplementation" if $name eq "DOMImplementation";
367 my $name = $codeGenerator->StripModule(shift);
369 return "DOMImplementationFront" if $name eq "DOMImplementation";
370 return "DOMWindow" if $name eq "AbstractView";
374 sub GetParentImplClassName
376 my $dataNode = shift;
378 return "Object" if @{$dataNode->parents} eq 0;
380 my $parent = $codeGenerator->StripModule($dataNode->parents(0));
383 return "Object" if $parent eq "HTMLCollection";
388 sub GetParentAndProtocols
390 my $dataNode = shift;
391 my $numParents = @{$dataNode->parents};
395 if ($numParents eq 0) {
397 push(@protocols, "NSObject");
398 push(@protocols, "NSCopying") if $dataNode->name eq "EventTarget";
400 $parent = "DOMObject";
402 } elsif ($numParents eq 1) {
403 my $parentName = $codeGenerator->StripModule($dataNode->parents(0));
405 die "Parents of protocols must also be protocols." unless IsProtocolType($parentName);
406 push(@protocols, "DOM" . $parentName);
408 if (IsProtocolType($parentName)) {
409 push(@protocols, "DOM" . $parentName);
410 } elsif ($parentName eq "HTMLCollection") {
411 $parent = "DOMObject";
413 $parent = "DOM" . $parentName;
417 my @parents = @{$dataNode->parents};
418 my $firstParent = $codeGenerator->StripModule(shift(@parents));
419 if (IsProtocolType($firstParent)) {
420 push(@protocols, "DOM" . $firstParent);
422 $parent = "DOMObject";
425 $parent = "DOM" . $firstParent;
428 foreach my $parentName (@parents) {
429 $parentName = $codeGenerator->StripModule($parentName);
430 die "Everything past the first class should be a protocol!" unless IsProtocolType($parentName);
432 push(@protocols, "DOM" . $parentName);
436 return ($parent, @protocols);
443 return $parent if $parent eq "Object" or IsBaseType($parent);
444 return "Event" if $parent eq "UIEvent";
445 return "CSSValue" if $parent eq "SVGColor" or $parent eq "CSSValueList";
453 return 1 if $baseTypeHash{$type};
461 return 1 if $protocolTypeHash{$type};
469 return 1 if $nativeObjCTypeHash{$type};
476 my $name = GetClassName($type);
478 return "id <$name>" if IsProtocolType($type);
479 return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
480 return "unsigned short" if $type eq "CompareHow" or $type eq "SVGPaintType";
484 sub GetPropertyAttributes
486 my $type = $codeGenerator->StripModule(shift);
487 my $readOnly = shift;
491 push(@attributes, "readonly") if $readOnly;
493 # FIXME: <rdar://problem/5049934> Consider using 'nonatomic' on the DOM @property declarations.
494 if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) {
495 push(@attributes, "copy");
496 } elsif ($codeGenerator->IsPodType($type) || $codeGenerator->IsSVGAnimatedType($type)) {
497 push(@attributes, "retain");
498 } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow" && $type ne "SVGPaintType") {
499 push(@attributes, "retain");
502 return "" unless @attributes > 0;
503 return "(" . join(", ", @attributes) . ")";
508 my $type = $codeGenerator->StripModule(shift);
510 return !$codeGenerator->IsNonPointerType($type) && !$codeGenerator->IsStringType($type) && !IsNativeObjCType($type);
513 sub GetObjCTypeGetter
516 my $type = $codeGenerator->StripModule(shift);
518 return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
519 return $argName . "Node" if $type eq "EventTarget";
520 return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow";
521 return "static_cast<WebCore::SVGPaint::SVGPaintType>($argName)" if $type eq "SVGPaintType";
522 return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener";
523 return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter";
524 return "WTF::getPtr(nativeResolver)" if $type eq "XPathNSResolver";
526 if ($type eq "SerializedScriptValue") {
527 $implIncludes{"SerializedScriptValue.h"} = 1;
528 return "WebCore::SerializedScriptValue::create(WTF::String($argName))";
530 return "core($argName)";
533 sub AddForwardDeclarationsForType
535 my $type = $codeGenerator->StripModule(shift);
538 return if $codeGenerator->IsNonPointerType($type) ;
540 my $class = GetClassName($type);
542 if (IsProtocolType($type)) {
543 $headerForwardDeclarationsForProtocols{$class} = 1 if $public;
544 $privateHeaderForwardDeclarationsForProtocols{$class} = 1 if !$public and !$headerForwardDeclarationsForProtocols{$class};
548 $headerForwardDeclarations{$class} = 1 if $public;
550 # Private headers include the public header, so only add a forward declaration to the private header
551 # if the public header does not already have the same forward declaration.
552 $privateHeaderForwardDeclarations{$class} = 1 if !$public and !$headerForwardDeclarations{$class};
555 sub AddIncludesForType
557 my $type = $codeGenerator->StripModule(shift);
559 return if $codeGenerator->IsNonPointerType($type);
561 if (IsNativeObjCType($type)) {
562 if ($type eq "Color") {
563 $implIncludes{"ColorMac.h"} = 1;
568 if ($codeGenerator->IsStringType($type)) {
569 $implIncludes{"KURL.h"} = 1;
573 if ($type eq "DOMWindow") {
574 $implIncludes{"DOMAbstractViewInternal.h"} = 1;
575 $implIncludes{"DOMWindow.h"} = 1;
579 if ($type eq "DOMImplementation") {
580 $implIncludes{"DOMDOMImplementationInternal.h"} = 1;
581 $implIncludes{"DOMImplementationFront.h"} = 1;
585 if ($type eq "EventTarget") {
586 $implIncludes{"Node.h"} = 1;
587 $implIncludes{"DOMEventTarget.h"} = 1;
591 if ($codeGenerator->IsSVGNewStyleAnimatedType($type)) {
592 $implIncludes{"${type}.h"} = 1;
593 $implIncludes{"DOM${type}Internal.h"} = 1;
597 if ($codeGenerator->IsSVGAnimatedType($type)) {
598 $implIncludes{"DeprecatedSVGAnimatedTemplate.h"} = 1;
599 $implIncludes{"DOM${type}Internal.h"} = 1;
603 if ($type eq "SVGPoint") {
604 $implIncludes{"FloatPoint.h"} = 1;
605 $implIncludes{"DOMSVGPointInternal.h"} = 1;
609 if ($type eq "SVGMatrix") {
610 $implIncludes{"AffineTransform.h"} = 1;
611 $implIncludes{"DOMSVGMatrixInternal.h"} = 1;
612 $implIncludes{"SVGException.h"} = 1;
616 if ($type eq "SVGNumber") {
617 $implIncludes{"DOMSVGNumberInternal.h"} = 1;
621 if ($type =~ /(\w+)(Abs|Rel)$/) {
622 $implIncludes{"$1.h"} = 1;
623 $implIncludes{"DOM${type}Internal.h"} = 1;
627 if ($type eq "NodeFilter") {
628 $implIncludes{"NodeFilter.h"} = 1;
629 $implIncludes{"ObjCNodeFilterCondition.h"} = 1;
633 if ($type eq "EventListener") {
634 $implIncludes{"EventListener.h"} = 1;
635 $implIncludes{"ObjCEventListener.h"} = 1;
639 if ($type eq "XPathNSResolver") {
640 $implIncludes{"DOMCustomXPathNSResolver.h"} = 1;
641 $implIncludes{"XPathNSResolver.h"} = 1;
645 if ($type eq "SerializedScriptValue") {
646 $implIncludes{"SerializedScriptValue.h"} = 1;
650 # FIXME: won't compile without these
651 $implIncludes{"CSSMutableStyleDeclaration.h"} = 1 if $type eq "CSSStyleDeclaration";
652 $implIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList";
654 # Default, include the same named file (the implementation) and the same name prefixed with "DOM".
655 $implIncludes{"$type.h"} = 1 if not $codeGenerator->AvoidInclusionOfType($type);
656 $implIncludes{"DOM${type}Internal.h"} = 1;
659 sub GetSVGPropertyTypes
661 my $implType = shift;
664 my $svgListPropertyType;
667 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $implType =~ /SVG/;
669 $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($implType);
670 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType;
672 # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType>
673 $svgNativeType = "WebCore::$svgNativeType ";
674 $svgNativeType =~ s/</\<WebCore::/;
676 my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implType);
677 if ($svgNativeType =~ /SVGPropertyTearOff/) {
678 $svgPropertyType = "WebCore::$svgWrappedNativeType";
679 $svgPropertyType =~ s/</\<WebCore::/;
680 } elsif ($svgNativeType =~ /SVGListPropertyTearOff/) {
681 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
682 $svgListPropertyType =~ s/</\<WebCore::/;
685 return ($svgPropertyType, $svgListPropertyType, $svgNativeType);
691 my $dataNode = shift;
693 my $interfaceName = $dataNode->name;
694 my $className = GetClassName($interfaceName);
697 my @protocolsToImplement = ();
698 ($parentName, @protocolsToImplement) = GetParentAndProtocols($dataNode);
700 my $numConstants = @{$dataNode->constants};
701 my $numAttributes = @{$dataNode->attributes};
702 my $numFunctions = @{$dataNode->functions};
704 # - Add default header template
705 @headerContentHeader = split("\r", $headerLicenseTemplate);
706 push(@headerContentHeader, "\n");
709 my $includedWebKitAvailabilityHeader = 0;
710 unless ($isProtocol) {
711 my $parentHeaderName = GetClassHeaderName($parentName);
712 push(@headerContentHeader, "#import <WebCore/$parentHeaderName.h>\n");
713 $includedWebKitAvailabilityHeader = 1;
716 foreach my $parentProtocol (@protocolsToImplement) {
717 next if $parentProtocol =~ /^NS/;
718 $parentProtocol = GetClassHeaderName($parentProtocol);
719 push(@headerContentHeader, "#import <WebCore/$parentProtocol.h>\n");
720 $includedWebKitAvailabilityHeader = 1;
723 # Special case needed for legacy support of DOMRange
724 if ($interfaceName eq "Range") {
725 push(@headerContentHeader, "#import <WebCore/DOMCore.h>\n");
726 push(@headerContentHeader, "#import <WebCore/DOMDocument.h>\n");
727 push(@headerContentHeader, "#import <WebCore/DOMRangeException.h>\n");
728 $includedWebKitAvailabilityHeader = 1;
731 push(@headerContentHeader, "#import <JavaScriptCore/WebKitAvailability.h>\n") unless $includedWebKitAvailabilityHeader;
733 my $interfaceAvailabilityVersionCheck = "#if WEBKIT_VERSION_MAX_ALLOWED >= $interfaceAvailabilityVersion\n\n";
735 push(@headerContentHeader, "\n");
736 push(@headerContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
739 if ($numConstants > 0) {
740 my @headerConstants = ();
742 # FIXME: we need a way to include multiple enums.
743 foreach my $constant (@{$dataNode->constants}) {
744 my $constantName = $constant->name;
745 my $constantValue = $constant->value;
747 my $output = " DOM_" . $constantName . " = " . $constantValue;
748 push(@headerConstants, $output);
751 my $combinedConstants = join(",\n", @headerConstants);
753 # FIXME: the formatting of the enums should line up the equal signs.
754 # FIXME: enums are unconditionally placed in the public header.
755 push(@headerContent, "enum {\n");
756 push(@headerContent, $combinedConstants);
757 push(@headerContent, "\n};\n\n");
760 # - Begin @interface or @protocol
761 my $interfaceDeclaration = ($isProtocol ? "\@protocol $className" : "\@interface $className : $parentName");
762 $interfaceDeclaration .= " <" . join(", ", @protocolsToImplement) . ">" if @protocolsToImplement > 0;
763 $interfaceDeclaration .= "\n";
765 push(@headerContent, $interfaceDeclaration);
767 my @headerAttributes = ();
768 my @privateHeaderAttributes = ();
770 # - Add attribute getters/setters.
771 if ($numAttributes > 0) {
772 foreach my $attribute (@{$dataNode->attributes}) {
773 my $attributeName = $attribute->signature->name;
775 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
776 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
777 $attributeName .= "Name";
778 } elsif ($attributeName eq "frame") {
779 # Special case attribute frame to be frameBorders.
780 $attributeName .= "Borders";
783 my $attributeType = GetObjCType($attribute->signature->type);
784 my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
786 my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attributeIsReadonly);
787 # Some SVGFE*Element.idl use 'operator' as attribute name, rewrite as '_operator' to avoid clashes with C/C++
788 $attributeName =~ s/operator/_operator/ if ($attributeName =~ /operator/);
789 $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName;
791 my $publicInterfaceKey = $property . ";";
793 my $availabilityMacro = "";
794 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
795 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
798 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
800 my $declarationSuffix = ";\n";
801 $declarationSuffix = " $availabilityMacro;\n" if length $availabilityMacro;
803 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
804 delete $publicInterfaces{$publicInterfaceKey};
806 AddForwardDeclarationsForType($attribute->signature->type, $public);
808 my $setterName = "set" . ucfirst($attributeName) . ":";
810 my $conflict = $conflictMethod{$attributeName};
812 warn "$className conflicts with $conflict method $attributeName\n";
816 $conflict = $conflictMethod{$setterName};
818 warn "$className conflicts with $conflict method $setterName\n";
822 if ($buildingForLeopardOrLater) {
823 $property .= $declarationSuffix;
824 push(@headerAttributes, $property) if $public;
825 push(@privateHeaderAttributes, $property) unless $public;
827 my $attributeConditionalString = GenerateConditionalString($attribute->signature);
828 if ($attributeConditionalString) {
829 push(@headerAttributes, "#if ${attributeConditionalString}\n") if $public;
830 push(@privateHeaderAttributes, "#if ${attributeConditionalString}\n") unless $public;
834 my $getter = "- (" . $attributeType . ")" . $attributeName . $declarationSuffix;
835 push(@headerAttributes, $getter) if $public;
836 push(@privateHeaderAttributes, $getter) unless $public;
839 if (!$attributeIsReadonly) {
840 my $setter = "- (void)$setterName(" . $attributeType . ")new" . ucfirst($attributeName) . $declarationSuffix;
841 push(@headerAttributes, $setter) if $public;
842 push(@privateHeaderAttributes, $setter) unless $public;
845 if ($attributeConditionalString) {
846 push(@headerAttributes, "#endif\n") if $public;
847 push(@privateHeaderAttributes, "#endif\n") unless $public;
852 push(@headerContent, @headerAttributes) if @headerAttributes > 0;
855 my @headerFunctions = ();
856 my @privateHeaderFunctions = ();
857 my @deprecatedHeaderFunctions = ();
860 if ($numFunctions > 0) {
861 foreach my $function (@{$dataNode->functions}) {
862 my $functionName = $function->signature->name;
864 my $returnType = GetObjCType($function->signature->type);
865 my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"});
866 my $numberOfParameters = @{$function->parameters};
867 my %typesToForwardDeclare = ($function->signature->type => 1);
869 my $parameterIndex = 0;
870 my $functionSig = "- ($returnType)$functionName";
871 my $methodName = $functionName;
872 foreach my $param (@{$function->parameters}) {
873 my $paramName = $param->name;
874 my $paramType = GetObjCType($param->type);
876 $typesToForwardDeclare{$param->type} = 1;
878 if ($parameterIndex >= 1) {
879 my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
880 $paramPrefix = $paramName unless defined($paramPrefix);
881 $functionSig .= " $paramPrefix";
882 $methodName .= $paramPrefix;
885 $functionSig .= ":($paramType)$paramName";
891 my $publicInterfaceKey = $functionSig . ";";
893 my $conflict = $conflictMethod{$methodName};
895 warn "$className conflicts with $conflict method $methodName\n";
899 if ($isProtocol && !$newPublicClass && !defined $publicInterfaces{$publicInterfaceKey}) {
900 warn "Protocol method $publicInterfaceKey is not in PublicDOMInterfaces.h. Protocols require all methods to be public";
904 my $availabilityMacro = "";
905 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
906 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
909 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
911 my $functionDeclaration = $functionSig;
912 $functionDeclaration .= " " . $availabilityMacro if length $availabilityMacro;
913 $functionDeclaration .= ";\n";
915 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
916 delete $publicInterfaces{$publicInterfaceKey};
918 foreach my $type (keys %typesToForwardDeclare) {
919 # add any forward declarations to the public header if a deprecated version will be generated
920 AddForwardDeclarationsForType($type, 1) if $needsDeprecatedVersion;
921 AddForwardDeclarationsForType($type, $public) unless $public and $needsDeprecatedVersion;
924 push(@headerFunctions, $functionDeclaration) if $public;
925 push(@privateHeaderFunctions, $functionDeclaration) unless $public;
927 # generate the old style method names with un-named parameters, these methods are deprecated
928 if ($needsDeprecatedVersion) {
929 my $deprecatedFunctionSig = $functionSig;
930 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
932 $publicInterfaceKey = $deprecatedFunctionSig . ";";
934 my $availabilityMacro = "AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0";
935 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
936 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
939 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if $buildingForTigerOrEarlier;
941 $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
943 push(@deprecatedHeaderFunctions, $functionDeclaration);
945 unless (defined $publicInterfaces{$publicInterfaceKey}) {
946 warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the OldStyleObjC IDL attribute removed";
950 delete $publicInterfaces{$publicInterfaceKey};
954 if (@headerFunctions > 0) {
955 push(@headerContent, "\n") if $buildingForLeopardOrLater and @headerAttributes > 0;
956 push(@headerContent, @headerFunctions);
960 if (@deprecatedHeaderFunctions > 0 && $isProtocol) {
961 push(@headerContent, @deprecatedHeaderFunctions);
964 # - End @interface or @protocol
965 push(@headerContent, "\@end\n");
967 if (@deprecatedHeaderFunctions > 0 && !$isProtocol) {
968 # - Deprecated category @interface
969 push(@headerContent, "\n\@interface $className (" . $className . "Deprecated)\n");
970 push(@headerContent, @deprecatedHeaderFunctions);
971 push(@headerContent, "\@end\n");
974 push(@headerContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
976 my %alwaysGenerateForNoSVGBuild = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement);
978 if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0 or exists $alwaysGenerateForNoSVGBuild{$className}) {
979 # - Private category @interface
980 @privateHeaderContentHeader = split("\r", $headerLicenseTemplate);
981 push(@privateHeaderContentHeader, "\n");
983 my $classHeaderName = GetClassHeaderName($className);
984 push(@privateHeaderContentHeader, "#import <WebCore/$classHeaderName.h>\n\n");
985 push(@privateHeaderContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
987 @privateHeaderContent = ();
988 push(@privateHeaderContent, "\@interface $className (" . $className . "Private)\n");
989 push(@privateHeaderContent, @privateHeaderAttributes) if @privateHeaderAttributes > 0;
990 push(@privateHeaderContent, "\n") if $buildingForLeopardOrLater and @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0;
991 push(@privateHeaderContent, @privateHeaderFunctions) if @privateHeaderFunctions > 0;
992 push(@privateHeaderContent, "\@end\n");
994 push(@privateHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
997 unless ($isProtocol) {
998 # Generate internal interfaces
999 my $podType = $dataNode->extendedAttributes->{"PODType"};
1000 my $podTypeWithNamespace;
1001 my $implClassName = GetImplClassName($interfaceName);
1002 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
1004 my $implType = $implClassNameWithNamespace;
1005 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
1006 $implType = $svgNativeType if $svgNativeType;
1009 $podTypeWithNamespace = ($podType eq "float") ? "$podType" : "WebCore::$podType";
1012 # Generate interface definitions.
1013 @internalHeaderContent = split("\r", $implementationLicenseTemplate);
1015 push(@internalHeaderContent, "\n#import <WebCore/$className.h>\n\n");
1016 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedPropertyTearOff.h>\n\n") if $svgPropertyType;
1017 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedListPropertyTearOff.h>\n\n") if $svgListPropertyType;
1018 push(@internalHeaderContent, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
1020 if ($interfaceName eq "Node") {
1021 push(@internalHeaderContent, "\@protocol DOMEventTarget;\n\n");
1024 my $startedNamespace = 0;
1026 if ($codeGenerator->IsSVGNewStyleAnimatedType($interfaceName)) {
1027 push(@internalHeaderContent, "#import <WebCore/$implClassName.h>\n\n");
1028 } elsif ($codeGenerator->IsSVGAnimatedType($interfaceName)) {
1029 push(@internalHeaderContent, "#import <WebCore/DeprecatedSVGAnimatedTemplate.h>\n\n");
1031 push(@internalHeaderContent, "namespace WebCore {\n");
1032 $startedNamespace = 1;
1033 if ($podType and $podType ne "float") {
1034 push(@internalHeaderContent, " class $podType;\n");
1035 } elsif ($interfaceName eq "Node") {
1036 push(@internalHeaderContent, " class EventTarget;\n class Node;\n");
1038 push(@internalHeaderContent, " class $implClassName;\n");
1040 push(@internalHeaderContent, "}\n\n");
1044 push(@internalHeaderContent, "$podTypeWithNamespace core($className *);\n");
1045 push(@internalHeaderContent, "$className *kit($podTypeWithNamespace);\n");
1047 push(@internalHeaderContent, "$implType* core($className *);\n");
1048 push(@internalHeaderContent, "$className *kit($implType*);\n");
1051 if ($dataNode->extendedAttributes->{Polymorphic}) {
1052 push(@internalHeaderContent, "Class kitClass($implType*);\n");
1055 if ($interfaceName eq "Node") {
1056 push(@internalHeaderContent, "id <DOMEventTarget> kit(WebCore::EventTarget*);\n");
1059 push(@internalHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
1063 sub GenerateImplementation
1066 my $dataNode = shift;
1068 my @ancestorInterfaceNames = ();
1070 if (@{$dataNode->parents} > 1) {
1071 $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@ancestorInterfaceNames);
1074 my $interfaceName = $dataNode->name;
1075 my $className = GetClassName($interfaceName);
1076 my $implClassName = GetImplClassName($interfaceName);
1077 my $parentImplClassName = GetParentImplClassName($dataNode);
1078 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
1079 my $baseClass = GetBaseClass($parentImplClassName);
1080 my $classHeaderName = GetClassHeaderName($className);
1082 my $numAttributes = @{$dataNode->attributes};
1083 my $numFunctions = @{$dataNode->functions};
1085 my $podType = $dataNode->extendedAttributes->{"PODType"};
1086 my $podTypeWithNamespace;
1087 my $implType = $implClassNameWithNamespace;
1089 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
1090 $implType = $svgNativeType if $svgNativeType;
1093 $podTypeWithNamespace = ($podType eq "float") ? "$podType" : "WebCore::$podType";
1096 # - Add default header template.
1097 @implContentHeader = split("\r", $implementationLicenseTemplate);
1100 push(@implContentHeader, "\n#import \"config.h\"\n");
1102 my $conditionalString = GenerateConditionalString($dataNode);
1103 push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString;
1105 push(@implContentHeader, "#import \"DOMInternal.h\"\n\n");
1106 push(@implContentHeader, "#import \"$classHeaderName.h\"\n\n");
1108 $implIncludes{"ExceptionHandlers.h"} = 1;
1109 $implIncludes{"ThreadCheck.h"} = 1;
1110 $implIncludes{"JSMainThreadExecState.h"} = 1;
1111 $implIncludes{"WebScriptObjectPrivate.h"} = 1;
1112 $implIncludes{$classHeaderName . "Internal.h"} = 1;
1114 # FIXME: These includes are only needed when the class is a subclass of one of these polymorphic classes.
1115 $implIncludes{"DOMBlobInternal.h"} = 1;
1116 $implIncludes{"DOMCSSRuleInternal.h"} = 1;
1117 $implIncludes{"DOMCSSValueInternal.h"} = 1;
1118 $implIncludes{"DOMEventInternal.h"} = 1;
1119 $implIncludes{"DOMNodeInternal.h"} = 1;
1120 $implIncludes{"DOMStyleSheetInternal.h"} = 1;
1122 $implIncludes{"DOMSVGPathSegInternal.h"} = 1 if $interfaceName =~ /^SVGPathSeg.+/;
1124 if ($codeGenerator->IsSVGAnimatedType($interfaceName) and !$codeGenerator->IsSVGNewStyleAnimatedType($interfaceName)) {
1125 $implIncludes{"DeprecatedSVGAnimatedTemplate.h"} = 1;
1126 } elsif ($interfaceName =~ /(\w+)(Abs|Rel)$/) {
1127 $implIncludes{"$1.h"} = 1;
1130 $implIncludes{"$implClassName.h"} = 1 if not $codeGenerator->AvoidInclusionOfType($implClassName);
1132 $implIncludes{"$podType.h"} = 1 unless $podType eq "float";
1138 push(@implContent, "#import <wtf/GetPtr.h>\n\n");
1140 # add implementation accessor
1142 push(@implContent, "#define IMPL reinterpret_cast<$podTypeWithNamespace*>(_internal)\n\n");
1143 } elsif ($parentImplClassName eq "Object") {
1144 push(@implContent, "#define IMPL reinterpret_cast<$implType*>(_internal)\n\n");
1146 my $baseClassWithNamespace = "WebCore::$baseClass";
1147 push(@implContent, "#define IMPL static_cast<$implClassNameWithNamespace*>(reinterpret_cast<$baseClassWithNamespace*>(_internal))\n\n");
1150 # START implementation
1151 push(@implContent, "\@implementation $className\n\n");
1153 # Only generate 'dealloc' and 'finalize' methods for direct subclasses of DOMObject.
1154 if ($parentImplClassName eq "Object") {
1155 $implIncludes{"WebCoreObjCExtras.h"} = 1;
1156 push(@implContent, "- (void)dealloc\n");
1157 push(@implContent, "{\n");
1158 push(@implContent, " if (WebCoreObjCScheduleDeallocateOnMainThread([$className class], self))\n");
1159 push(@implContent, " return;\n");
1160 push(@implContent, "\n");
1161 if ($interfaceName eq "NodeIterator") {
1162 push(@implContent, " if (_internal) {\n");
1163 push(@implContent, " [self detach];\n");
1164 push(@implContent, " IMPL->deref();\n");
1165 push(@implContent, " };\n");
1166 } elsif ($podType) {
1167 push(@implContent, " delete IMPL;\n");
1169 push(@implContent, " if (_internal)\n");
1170 push(@implContent, " IMPL->deref();\n");
1172 push(@implContent, " [super dealloc];\n");
1173 push(@implContent, "}\n\n");
1175 push(@implContent, "- (void)finalize\n");
1176 push(@implContent, "{\n");
1177 if ($interfaceName eq "NodeIterator") {
1178 push(@implContent, " if (_internal) {\n");
1179 push(@implContent, " [self detach];\n");
1180 push(@implContent, " IMPL->deref();\n");
1181 push(@implContent, " };\n");
1182 } elsif ($podType) {
1183 push(@implContent, " delete IMPL;\n");
1185 push(@implContent, " if (_internal)\n");
1186 push(@implContent, " IMPL->deref();\n");
1188 push(@implContent, " [super finalize];\n");
1189 push(@implContent, "}\n\n");
1193 %attributeNames = ();
1196 if ($numAttributes > 0) {
1197 foreach my $attribute (@{$dataNode->attributes}) {
1198 AddIncludesForType($attribute->signature->type);
1200 my $idlType = $codeGenerator->StripModule($attribute->signature->type);
1202 my $attributeName = $attribute->signature->name;
1203 my $attributeType = GetObjCType($attribute->signature->type);
1204 my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
1205 my $attributeClassName = GetClassName($attribute->signature->type);
1207 my $attributeInterfaceName = $attributeName;
1208 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
1209 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
1210 $attributeInterfaceName .= "Name";
1211 } elsif ($attributeName eq "frame") {
1212 # Special case attribute frame to be frameBorders.
1213 $attributeInterfaceName .= "Borders";
1214 } elsif ($attributeName eq "operator") {
1215 # Avoid clash with C++ keyword.
1216 $attributeInterfaceName = "_operator";
1219 $attributeNames{$attributeInterfaceName} = 1;
1222 my $getterSig = "- ($attributeType)$attributeInterfaceName\n";
1224 my $getterExpressionPrefix = $codeGenerator->GetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
1226 # FIXME: Special case attribute ownerDocument to call document. This makes it return the
1227 # document when called on the document itself. Legacy behavior, see <https://bugs.webkit.org/show_bug.cgi?id=10889>.
1228 $getterExpressionPrefix =~ s/\bownerDocument\b/document/;
1230 my $hasGetterException = @{$attribute->getterExceptions};
1231 my $getterContentHead = "IMPL->$getterExpressionPrefix";
1232 my $getterContentTail = ")";
1234 if ($svgPropertyType) {
1235 $getterContentHead = "$getterExpressionPrefix";
1237 # TODO: Handle special case for DOMSVGLength. We do need Custom code support for this.
1238 if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
1239 $getterContentHead = "value(0 /* FIXME */";
1242 # Special case for DOMSVGNumber
1243 if ($podType and $podType eq "float") {
1244 $getterContentHead = "*IMPL";
1245 $getterContentTail = "";
1249 my $attributeTypeSansPtr = $attributeType;
1250 $attributeTypeSansPtr =~ s/ \*$//; # Remove trailing " *" from pointer types.
1252 # special case for EventTarget protocol
1253 $attributeTypeSansPtr = "DOMNode" if $idlType eq "EventTarget";
1256 my @customGetterContent = ();
1257 if ($attributeTypeSansPtr eq "DOMImplementation") {
1258 # FIXME: We have to special case DOMImplementation until DOMImplementationFront is removed
1259 $getterContentHead = "kit(implementationFront(IMPL";
1260 $getterContentTail .= ")";
1261 } elsif ($attributeName =~ /(\w+)DisplayString$/) {
1262 my $attributeToDisplay = $1;
1263 $getterContentHead = "WebCore::displayString(IMPL->$attributeToDisplay(), core(self)";
1264 $implIncludes{"HitTestResult.h"} = 1;
1265 } elsif ($attributeName =~ /^absolute(\w+)URL$/) {
1267 $getterContentHead = "[self _getURLAttribute:";
1268 if ($typeOfURL eq "Link") {
1269 $getterContentTail = "\@\"href\"]";
1270 } elsif ($typeOfURL eq "Image") {
1271 if ($interfaceName eq "HTMLObjectElement") {
1272 $getterContentTail = "\@\"data\"]";
1274 $getterContentTail = "\@\"src\"]";
1276 unless ($interfaceName eq "HTMLImageElement") {
1277 push(@customGetterContent, " if (!IMPL->renderer() || !IMPL->renderer()->isImage())\n");
1278 push(@customGetterContent, " return nil;\n");
1279 $implIncludes{"RenderObject.h"} = 1;
1282 $implIncludes{"DOMPrivate.h"} = 1;
1283 } elsif ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
1284 $getterContentHead = "WTF::String::number(" . $getterContentHead;
1285 $getterContentTail .= ")";
1286 } elsif ($codeGenerator->IsPodType($idlType) or $idlType eq "Date") {
1287 $getterContentHead = "kit($getterContentHead";
1288 $getterContentTail .= ")";
1289 } elsif ($svgPropertyType) {
1290 $getterContentHead = "IMPL->propertyReference().$getterContentHead";
1291 } elsif ($codeGenerator->IsSVGNewStyleAnimatedType($implClassName) and $codeGenerator->IsSVGTypeNeedingTearOff($idlType)) {
1292 my $idlTypeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($idlType);
1293 $idlTypeWithNamespace =~ s/</\<WebCore::/;
1294 $getterContentHead = "kit(static_cast<$idlTypeWithNamespace*>($getterContentHead)";
1295 $getterContentTail .= ")";
1296 } elsif (IsProtocolType($idlType) and $idlType ne "EventTarget") {
1297 $getterContentHead = "kit($getterContentHead";
1298 $getterContentTail .= ")";
1299 } elsif ($idlType eq "Color") {
1300 $getterContentHead = "WebCore::nsColor($getterContentHead";
1301 $getterContentTail .= ")";
1302 } elsif ($attribute->signature->type eq "SerializedScriptValue") {
1303 $getterContentHead = "$getterContentHead";
1304 $getterContentTail .= "->toString()";
1305 } elsif (ConversionNeeded($attribute->signature->type)) {
1306 if ($codeGenerator->IsSVGTypeNeedingTearOff($attribute->signature->type) and not $implClassName =~ /List$/) {
1307 my $idlType = $attribute->signature->type;
1308 my $idlTypeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($idlType);
1309 $idlTypeWithNamespace =~ s/</\<WebCore::/;
1310 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($getterContentHead";
1311 $getterContentTail .= ")))";
1313 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1314 $getterContentTail .= "))";
1319 if ($hasGetterException) {
1320 $getterContent = $getterContentHead . "ec" . $getterContentTail;
1322 $getterContent = $getterContentHead . $getterContentTail;
1325 my $attributeConditionalString = GenerateConditionalString($attribute->signature);
1326 push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString;
1327 push(@implContent, $getterSig);
1328 push(@implContent, "{\n");
1329 push(@implContent, " $jsContextSetter\n");
1330 push(@implContent, @customGetterContent);
1331 if ($hasGetterException) {
1332 # Differentiated between when the return type is a pointer and
1333 # not for white space issue (ie. Foo *result vs. int result).
1334 if ($attributeType =~ /\*$/) {
1335 $getterContent = $attributeType . "result = " . $getterContent;
1337 $getterContent = $attributeType . " result = " . $getterContent;
1340 push(@implContent, " $exceptionInit\n");
1341 push(@implContent, " $getterContent;\n");
1342 push(@implContent, " $exceptionRaiseOnError\n");
1343 push(@implContent, " return result;\n");
1345 push(@implContent, " return $getterContent;\n");
1347 push(@implContent, "}\n");
1350 if (!$attributeIsReadonly) {
1351 # Exception handling
1352 my $hasSetterException = @{$attribute->setterExceptions};
1354 my $coreSetterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
1355 my $setterName = "set" . ucfirst($attributeInterfaceName);
1356 my $argName = "new" . ucfirst($attributeInterfaceName);
1357 my $arg = GetObjCTypeGetter($argName, $idlType);
1359 # The definition of ConvertToString is flipped for the setter
1360 if ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
1361 $arg = "WTF::String($arg).toInt()";
1364 my $setterSig = "- (void)$setterName:($attributeType)$argName\n";
1366 push(@implContent, "\n");
1367 push(@implContent, $setterSig);
1368 push(@implContent, "{\n");
1369 push(@implContent, " $jsContextSetter\n");
1371 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1372 push(@implContent, " ASSERT($argName);\n\n");
1375 if ($idlType eq "Date") {
1376 $arg = "core(" . $arg . ")";
1379 if ($svgPropertyType) {
1380 $getterContentHead = "$getterExpressionPrefix";
1381 push(@implContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1382 my $ec = $hasSetterException ? ", ec" : "";
1383 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1384 push(@implContent, " podImpl.$coreSetterName($arg$ec);\n");
1385 if ($hasSetterException) {
1386 push(@implContent, " if (!ec)\n");
1387 push(@implContent, " IMPL->commitChange();\n");
1388 push(@implContent, " $exceptionRaiseOnError\n");
1390 push(@implContent, " IMPL->commitChange();\n");
1392 } elsif ($svgListPropertyType) {
1393 $getterContentHead = "$getterExpressionPrefix";
1394 push(@implContent, " IMPL->$coreSetterName($arg);\n");
1395 } elsif ($podType) {
1396 # Special case for DOMSVGNumber
1397 if ($podType eq "float") {
1398 push(@implContent, " *IMPL = $arg;\n");
1400 push(@implContent, " IMPL->$coreSetterName($arg);\n");
1403 my $setterExpressionPrefix = $codeGenerator->SetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
1404 my $ec = $hasSetterException ? ", ec" : "";
1405 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1406 push(@implContent, " IMPL->$setterExpressionPrefix$arg$ec);\n");
1407 push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException;
1410 push(@implContent, "}\n");
1413 push(@implContent, "#endif\n") if $attributeConditionalString;
1414 push(@implContent, "\n");
1419 if ($numFunctions > 0) {
1420 foreach my $function (@{$dataNode->functions}) {
1421 AddIncludesForType($function->signature->type);
1423 my $functionName = $function->signature->name;
1424 my $returnType = GetObjCType($function->signature->type);
1425 my $hasParameters = @{$function->parameters};
1426 my $raisesExceptions = @{$function->raisesExceptions};
1428 my @parameterNames = ();
1429 my @needsAssert = ();
1430 my %needsCustom = ();
1432 my $parameterIndex = 0;
1433 my $functionSig = "- ($returnType)$functionName";
1434 foreach my $param (@{$function->parameters}) {
1435 my $paramName = $param->name;
1436 my $paramType = GetObjCType($param->type);
1438 # make a new parameter name if the original conflicts with a property name
1439 $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
1441 AddIncludesForType($param->type);
1443 my $idlType = $codeGenerator->StripModule($param->type);
1444 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1446 push(@parameterNames, $implGetter);
1447 $needsCustom{"XPathNSResolver"} = $paramName if $idlType eq "XPathNSResolver";
1448 $needsCustom{"NodeFilter"} = $paramName if $idlType eq "NodeFilter";
1449 $needsCustom{"EventListener"} = $paramName if $idlType eq "EventListener";
1450 $needsCustom{"EventTarget"} = $paramName if $idlType eq "EventTarget";
1451 $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"Return"};
1453 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1454 push(@needsAssert, " ASSERT($paramName);\n");
1457 if ($parameterIndex >= 1) {
1458 my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
1459 $paramPrefix = $param->name unless defined($paramPrefix);
1460 $functionSig .= " $paramPrefix";
1463 $functionSig .= ":($paramType)$paramName";
1468 my @functionContent = ();
1469 my $caller = "IMPL";
1471 # special case the XPathNSResolver
1472 if (defined $needsCustom{"XPathNSResolver"}) {
1473 my $paramName = $needsCustom{"XPathNSResolver"};
1474 push(@functionContent, " WebCore::XPathNSResolver* nativeResolver = 0;\n");
1475 push(@functionContent, " RefPtr<WebCore::XPathNSResolver> customResolver;\n");
1476 push(@functionContent, " if ($paramName) {\n");
1477 push(@functionContent, " if ([$paramName isMemberOfClass:[DOMNativeXPathNSResolver class]])\n");
1478 push(@functionContent, " nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>($paramName));\n");
1479 push(@functionContent, " else {\n");
1480 push(@functionContent, " customResolver = WebCore::DOMCustomXPathNSResolver::create($paramName);\n");
1481 push(@functionContent, " nativeResolver = WTF::getPtr(customResolver);\n");
1482 push(@functionContent, " }\n");
1483 push(@functionContent, " }\n");
1486 # special case the EventTarget
1487 if (defined $needsCustom{"EventTarget"}) {
1488 my $paramName = $needsCustom{"EventTarget"};
1489 push(@functionContent, " DOMNode* ${paramName}ObjC = $paramName;\n");
1490 push(@functionContent, " WebCore::Node* ${paramName}Node = core(${paramName}ObjC);\n");
1491 $implIncludes{"DOMNode.h"} = 1;
1492 $implIncludes{"Node.h"} = 1;
1495 if ($function->signature->extendedAttributes->{"UsesView"}) {
1496 push(@functionContent, " WebCore::DOMWindow* dv = $caller->defaultView();\n");
1497 push(@functionContent, " if (!dv)\n");
1498 push(@functionContent, " return nil;\n");
1499 $implIncludes{"DOMWindow.h"} = 1;
1503 # special case the EventListener
1504 if (defined $needsCustom{"EventListener"}) {
1505 my $paramName = $needsCustom{"EventListener"};
1506 push(@functionContent, " RefPtr<WebCore::EventListener> nativeEventListener = WebCore::ObjCEventListener::wrap($paramName);\n");
1509 # special case the NodeFilter
1510 if (defined $needsCustom{"NodeFilter"}) {
1511 my $paramName = $needsCustom{"NodeFilter"};
1512 push(@functionContent, " RefPtr<WebCore::NodeFilter> nativeNodeFilter;\n");
1513 push(@functionContent, " if ($paramName)\n");
1514 push(@functionContent, " nativeNodeFilter = WebCore::NodeFilter::create(WebCore::ObjCNodeFilterCondition::create($paramName));\n");
1517 # FIXME! We need [Custom] support for ObjC, to move these hacks into DOMSVGLength/MatrixCustom.mm
1518 my $svgMatrixRotateFromVector = ($podType and $podType eq "AffineTransform" and $functionName eq "rotateFromVector");
1519 my $svgMatrixInverse = ($podType and $podType eq "AffineTransform" and $functionName eq "inverse");
1520 my $svgLengthConvertToSpecifiedUnits = ($svgPropertyType and $svgPropertyType eq "WebCore::SVGLength" and $functionName eq "convertToSpecifiedUnits");
1522 push(@parameterNames, "ec") if $raisesExceptions and !($svgMatrixRotateFromVector || $svgMatrixInverse);
1523 push(@parameterNames, "0 /* FIXME */") if $svgLengthConvertToSpecifiedUnits;
1525 # Handle arguments that are 'SVGProperty' based (SVGAngle/SVGLength). We need to convert from SVGPropertyTearOff<Type>* to Type,
1526 # to be able to call the desired WebCore function. If the conversion fails, we can't extract Type and need to raise an exception.
1527 my $currentParameter = -1;
1528 foreach my $param (@{$function->parameters}) {
1529 $currentParameter++;
1531 my $paramName = $param->name;
1532 my $idlType = $codeGenerator->StripModule($param->type);
1533 next if not $codeGenerator->IsSVGTypeNeedingTearOff($idlType) or $implClassName =~ /List$/;
1535 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1536 my $idlTypeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($idlType);
1537 $idlTypeWithNamespace =~ s/</\<WebCore::/;
1539 push(@functionContent, " $idlTypeWithNamespace* ${paramName}Core = $implGetter;\n");
1540 push(@functionContent, " if (!${paramName}Core) {\n");
1541 push(@functionContent, " WebCore::ExceptionCode ec = WebCore::TYPE_MISMATCH_ERR;\n");
1542 push(@functionContent, " $exceptionRaiseOnError\n");
1543 if ($returnType eq "void") {
1544 push(@functionContent, " return;\n");
1546 push(@functionContent, " return nil;\n");
1548 push(@functionContent, " }\n");
1550 # Replace the paramter core() getter, by the cached variable.
1551 splice(@parameterNames, $currentParameter, 1, "${paramName}Core->propertyReference()");
1554 my $content = $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
1556 if ($svgPropertyType) {
1557 push(@functionContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1558 $content = "podImpl.$content;\n IMPL->commitChange()";
1560 $content = $caller . "->$content";
1563 if ($svgMatrixRotateFromVector) {
1564 # Special case with rotateFromVector & SVGMatrix
1565 push(@functionContent, " $exceptionInit\n");
1566 push(@functionContent, " if (x == 0.0 || y == 0.0)\n");
1567 push(@functionContent, " ec = WebCore::SVGException::SVG_INVALID_VALUE_ERR;\n");
1568 push(@functionContent, " $exceptionRaiseOnError\n");
1569 push(@functionContent, " return kit($content);\n");
1570 } elsif ($svgMatrixInverse) {
1571 # Special case with inverse & SVGMatrix
1572 push(@functionContent, " $exceptionInit\n");
1573 push(@functionContent, " if (!$caller->isInvertible())\n");
1574 push(@functionContent, " ec = WebCore::SVGException::SVG_MATRIX_NOT_INVERTABLE;\n");
1575 push(@functionContent, " $exceptionRaiseOnError\n");
1576 push(@functionContent, " return kit($content);\n");
1577 } elsif ($returnType eq "void") {
1578 # Special case 'void' return type.
1579 if ($raisesExceptions) {
1580 push(@functionContent, " $exceptionInit\n");
1581 push(@functionContent, " $content;\n");
1582 push(@functionContent, " $exceptionRaiseOnError\n");
1584 push(@functionContent, " $content;\n");
1586 } elsif (defined $needsCustom{"NodeToReturn"}) {
1587 # Special case the insertBefore, replaceChild, removeChild
1588 # and appendChild functions from DOMNode
1589 my $toReturn = $needsCustom{"NodeToReturn"};
1590 if ($raisesExceptions) {
1591 push(@functionContent, " $exceptionInit\n");
1592 push(@functionContent, " if ($content)\n");
1593 push(@functionContent, " return $toReturn;\n");
1594 push(@functionContent, " $exceptionRaiseOnError\n");
1595 push(@functionContent, " return nil;\n");
1597 push(@functionContent, " if ($content)\n");
1598 push(@functionContent, " return $toReturn;\n");
1599 push(@functionContent, " return nil;\n");
1601 } elsif ($returnType eq "SerializedScriptValue") {
1604 if (ConversionNeeded($function->signature->type)) {
1605 if ($codeGenerator->IsSVGTypeNeedingTearOff($function->signature->type) and not $implClassName =~ /List$/) {
1606 my $idlType = $function->signature->type;
1607 my $idlTypeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($idlType);
1608 $idlTypeWithNamespace =~ s/</\<WebCore::/;
1609 $content = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($content)))";
1610 } elsif ($codeGenerator->IsPodType($function->signature->type)) {
1611 $content = "kit($content)";
1613 $content = "kit(WTF::getPtr($content))";
1617 if ($raisesExceptions) {
1618 # Differentiated between when the return type is a pointer and
1619 # not for white space issue (ie. Foo *result vs. int result).
1620 if ($returnType =~ /\*$/) {
1621 $content = $returnType . "result = " . $content;
1623 $content = $returnType . " result = " . $content;
1626 push(@functionContent, " $exceptionInit\n");
1627 push(@functionContent, " $content;\n");
1628 push(@functionContent, " $exceptionRaiseOnError\n");
1629 push(@functionContent, " return result;\n");
1631 push(@functionContent, " return $content;\n");
1635 push(@implContent, "$functionSig\n");
1636 push(@implContent, "{\n");
1637 push(@implContent, " $jsContextSetter\n");
1638 push(@implContent, @functionContent);
1639 push(@implContent, "}\n\n");
1641 # generate the old style method names with un-named parameters, these methods are deprecated
1642 if (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"}) {
1643 my $deprecatedFunctionSig = $functionSig;
1644 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
1646 push(@implContent, "$deprecatedFunctionSig\n");
1647 push(@implContent, "{\n");
1648 push(@implContent, " $jsContextSetter\n");
1649 push(@implContent, @functionContent);
1650 push(@implContent, "}\n\n");
1658 # END implementation
1659 push(@implContent, "\@end\n");
1661 # Generate internal interfaces
1663 push(@implContent, "\n$podTypeWithNamespace core($className *wrapper)\n");
1664 push(@implContent, "{\n");
1665 push(@implContent, " return wrapper ? *reinterpret_cast<$podTypeWithNamespace*>(wrapper->_internal) : $podTypeWithNamespace();\n");
1666 push(@implContent, "}\n\n");
1668 push(@implContent, "\n$implType* core($className *wrapper)\n");
1669 push(@implContent, "{\n");
1670 push(@implContent, " return wrapper ? reinterpret_cast<$implType*>(wrapper->_internal) : 0;\n");
1671 push(@implContent, "}\n\n");
1675 # FIXME: Implement caching.
1676 push(@implContent, "$className *kit($podTypeWithNamespace value)\n");
1677 push(@implContent, "{\n");
1678 push(@implContent, " $assertMainThread;\n");
1679 push(@implContent, " $className *wrapper = [[$className alloc] _init];\n");
1680 push(@implContent, " wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(new $podTypeWithNamespace(value));\n");
1681 push(@implContent, " return [wrapper autorelease];\n");
1682 push(@implContent, "}\n");
1683 } elsif ($parentImplClassName eq "Object") {
1684 push(@implContent, "$className *kit($implType* value)\n");
1685 push(@implContent, "{\n");
1686 push(@implContent, " $assertMainThread;\n");
1687 push(@implContent, " if (!value)\n");
1688 push(@implContent, " return nil;\n");
1689 push(@implContent, " if ($className *wrapper = getDOMWrapper(value))\n");
1690 push(@implContent, " return [[wrapper retain] autorelease];\n");
1691 if ($dataNode->extendedAttributes->{Polymorphic}) {
1692 push(@implContent, " $className *wrapper = [[kitClass(value) alloc] _init];\n");
1693 push(@implContent, " if (!wrapper)\n");
1694 push(@implContent, " return nil;\n");
1696 push(@implContent, " $className *wrapper = [[$className alloc] _init];\n");
1698 push(@implContent, " wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(value);\n");
1699 push(@implContent, " value->ref();\n");
1700 push(@implContent, " addDOMWrapper(wrapper, value);\n");
1701 push(@implContent, " return [wrapper autorelease];\n");
1702 push(@implContent, "}\n");
1704 push(@implContent, "$className *kit($implType* value)\n");
1705 push(@implContent, "{\n");
1706 push(@implContent, " $assertMainThread;\n");
1707 push(@implContent, " return static_cast<$className*>(kit(static_cast<WebCore::$baseClass*>(value)));\n");
1708 push(@implContent, "}\n");
1711 # - End the ifdef conditional if necessary
1712 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
1714 # - Generate dependencies.
1715 if ($writeDependencies && @ancestorInterfaceNames) {
1716 push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n");
1717 push(@depsContent, map { "$_.idl :\n" } @ancestorInterfaceNames);
1727 # Open files for writing...
1728 my $headerFileName = "$outputDir/" . $name . ".h";
1729 my $privateHeaderFileName = "$outputDir/" . $name . "Private.h";
1730 my $implFileName = "$outputDir/" . $name . ".mm";
1731 my $internalHeaderFileName = "$outputDir/" . $name . "Internal.h";
1732 my $depsFileName = "$outputDir/" . $name . ".dep";
1735 unlink($headerFileName);
1736 unlink($privateHeaderFileName);
1737 unlink($implFileName);
1738 unlink($internalHeaderFileName);
1739 unlink($depsFileName);
1741 # Write public header.
1742 open(HEADER, ">$headerFileName") or die "Couldn't open file $headerFileName";
1744 print HEADER @headerContentHeader;
1745 print HEADER map { "\@class $_;\n" } sort keys(%headerForwardDeclarations);
1746 print HEADER map { "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
1748 my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols);
1749 print HEADER "\n" if $hasForwardDeclarations;
1750 print HEADER @headerContent;
1754 @headerContentHeader = ();
1755 @headerContent = ();
1756 %headerForwardDeclarations = ();
1757 %headerForwardDeclarationsForProtocols = ();
1759 if (@privateHeaderContent > 0) {
1760 open(PRIVATE_HEADER, ">$privateHeaderFileName") or die "Couldn't open file $privateHeaderFileName";
1762 print PRIVATE_HEADER @privateHeaderContentHeader;
1763 print PRIVATE_HEADER map { "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
1764 print PRIVATE_HEADER map { "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
1766 $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols);
1767 print PRIVATE_HEADER "\n" if $hasForwardDeclarations;
1768 print PRIVATE_HEADER @privateHeaderContent;
1770 close(PRIVATE_HEADER);
1772 @privateHeaderContentHeader = ();
1773 @privateHeaderContent = ();
1774 %privateHeaderForwardDeclarations = ();
1775 %privateHeaderForwardDeclarationsForProtocols = ();
1778 # Write implementation file.
1780 open(IMPL, ">$implFileName") or die "Couldn't open file $implFileName";
1782 print IMPL @implContentHeader;
1783 print IMPL map { "#import \"$_\"\n" } sort keys(%implIncludes);
1784 print IMPL @implContent;
1788 @implContentHeader = ();
1793 if (@internalHeaderContent > 0) {
1794 open(INTERNAL_HEADER, ">$internalHeaderFileName") or die "Couldn't open file $internalHeaderFileName";
1796 print INTERNAL_HEADER @internalHeaderContent;
1798 close(INTERNAL_HEADER);
1800 @internalHeaderContent = ();
1803 # Write dependency file.
1805 open(DEPS, ">$depsFileName") or die "Couldn't open file $depsFileName";
1806 print DEPS @depsContent;