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;
32 my $writeDependencies = 0;
33 my %publicInterfaces = ();
34 my $newPublicClass = 0;
35 my $interfaceAvailabilityVersion = "";
39 my @headerContentHeader = ();
40 my @headerContent = ();
41 my %headerForwardDeclarations = ();
42 my %headerForwardDeclarationsForProtocols = ();
44 my @privateHeaderContentHeader = ();
45 my @privateHeaderContent = ();
46 my %privateHeaderForwardDeclarations = ();
47 my %privateHeaderForwardDeclarationsForProtocols = ();
49 my @internalHeaderContent = ();
51 my @implContentHeader = ();
53 my %implIncludes = ();
57 my %protocolTypeHash = ("XPathNSResolver" => 1, "EventListener" => 1, "EventTarget" => 1, "NodeFilter" => 1,
58 "SVGLocatable" => 1, "SVGTransformable" => 1, "SVGStylable" => 1, "SVGFilterPrimitiveStandardAttributes" => 1,
59 "SVGTests" => 1, "SVGLangSpace" => 1, "SVGExternalResourcesRequired" => 1, "SVGURIReference" => 1,
60 "SVGZoomAndPan" => 1, "SVGFitToViewBox" => 1, "SVGAnimatedPathData" => 1, "ElementTimeControl" => 1);
61 my %nativeObjCTypeHash = ("URL" => 1, "Color" => 1);
63 # FIXME: this should be replaced with a function that recurses up the tree
64 # to find the actual base type.
65 my %baseTypeHash = ("Object" => 1, "Node" => 1, "NodeList" => 1, "NamedNodeMap" => 1, "DOMImplementation" => 1,
66 "Event" => 1, "CSSRule" => 1, "CSSValue" => 1, "StyleSheet" => 1, "MediaList" => 1,
67 "Counter" => 1, "Rect" => 1, "RGBColor" => 1, "XPathExpression" => 1, "XPathResult" => 1,
68 "NodeIterator" => 1, "TreeWalker" => 1, "AbstractView" => 1, "Blob" => 1,
69 "SVGAngle" => 1, "SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1, "SVGAnimatedEnumeration" => 1,
70 "SVGAnimatedInteger" => 1, "SVGAnimatedLength" => 1, "SVGAnimatedLengthList" => 1,
71 "SVGAnimatedNumber" => 1, "SVGAnimatedNumberList" => 1,
72 "SVGAnimatedPreserveAspectRatio" => 1, "SVGAnimatedRect" => 1, "SVGAnimatedString" => 1,
73 "SVGAnimatedTransformList" => 1, "SVGLength" => 1, "SVGLengthList" => 1, "SVGMatrix" => 1,
74 "SVGNumber" => 1, "SVGNumberList" => 1, "SVGPathSeg" => 1, "SVGPathSegList" => 1, "SVGPoint" => 1,
75 "SVGPointList" => 1, "SVGPreserveAspectRatio" => 1, "SVGRect" => 1, "SVGRenderingIntent" => 1,
76 "SVGStringList" => 1, "SVGTransform" => 1, "SVGTransformList" => 1, "SVGUnitTypes" => 1);
79 my $buildingForTigerOrEarlier = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} <= 10.4;
80 my $buildingForLeopardOrLater = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} >= 10.5;
81 my $exceptionInit = "WebCore::ExceptionCode ec = 0;";
82 my $jsContextSetter = "WebCore::JSMainThreadNullState state;";
83 my $exceptionRaiseOnError = "WebCore::raiseOnDOMError(ec);";
84 my $assertMainThread = "{ DOM_ASSERT_MAIN_THREAD(); WebCoreThreadViolationCheckRoundOne(); }";
86 my %conflictMethod = (
87 # FIXME: Add C language keywords?
88 # FIXME: Add other predefined types like "id"?
90 "callWebScriptMethod:withArguments:" => "WebScriptObject",
91 "evaluateWebScript:" => "WebScriptObject",
92 "removeWebScriptKey:" => "WebScriptObject",
93 "setException:" => "WebScriptObject",
94 "setWebScriptValueAtIndex:value:" => "WebScriptObject",
95 "stringRepresentation" => "WebScriptObject",
96 "webScriptValueAtIndex:" => "WebScriptObject",
98 "autorelease" => "NSObject",
99 "awakeAfterUsingCoder:" => "NSObject",
100 "class" => "NSObject",
101 "classForCoder" => "NSObject",
102 "conformsToProtocol:" => "NSObject",
103 "copy" => "NSObject",
104 "copyWithZone:" => "NSObject",
105 "dealloc" => "NSObject",
106 "description" => "NSObject",
107 "doesNotRecognizeSelector:" => "NSObject",
108 "encodeWithCoder:" => "NSObject",
109 "finalize" => "NSObject",
110 "forwardInvocation:" => "NSObject",
111 "hash" => "NSObject",
112 "init" => "NSObject",
113 "initWithCoder:" => "NSObject",
114 "isEqual:" => "NSObject",
115 "isKindOfClass:" => "NSObject",
116 "isMemberOfClass:" => "NSObject",
117 "isProxy" => "NSObject",
118 "methodForSelector:" => "NSObject",
119 "methodSignatureForSelector:" => "NSObject",
120 "mutableCopy" => "NSObject",
121 "mutableCopyWithZone:" => "NSObject",
122 "performSelector:" => "NSObject",
123 "release" => "NSObject",
124 "replacementObjectForCoder:" => "NSObject",
125 "respondsToSelector:" => "NSObject",
126 "retain" => "NSObject",
127 "retainCount" => "NSObject",
128 "self" => "NSObject",
129 "superclass" => "NSObject",
130 "zone" => "NSObject",
135 # Default License Templates
136 my $headerLicenseTemplate = << "EOF";
138 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
139 * Copyright (C) 2006 Samuel Weinig <sam.weinig\@gmail.com>
141 * Redistribution and use in source and binary forms, with or without
142 * modification, are permitted provided that the following conditions
144 * 1. Redistributions of source code must retain the above copyright
145 * notice, this list of conditions and the following disclaimer.
146 * 2. Redistributions in binary form must reproduce the above copyright
147 * notice, this list of conditions and the following disclaimer in the
148 * documentation and/or other materials provided with the distribution.
150 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
151 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
152 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
153 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
154 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
155 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
156 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
157 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
158 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
159 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
160 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
164 my $implementationLicenseTemplate = << "EOF";
166 * This file is part of the WebKit open source project.
167 * This file has been generated by generate-bindings.pl. DO NOT MODIFY!
169 * Redistribution and use in source and binary forms, with or without
170 * modification, are permitted provided that the following conditions
172 * 1. Redistributions of source code must retain the above copyright
173 * notice, this list of conditions and the following disclaimer.
174 * 2. Redistributions in binary form must reproduce the above copyright
175 * notice, this list of conditions and the following disclaimer in the
176 * documentation and/or other materials provided with the distribution.
178 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
179 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
180 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
181 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
182 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
183 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
184 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
185 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
186 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
187 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
188 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
192 # Default constructor
198 $codeGenerator = shift;
200 shift; # $outputHeadersDir
201 shift; # $useLayerOnTop
202 shift; # $preprocessor
203 $writeDependencies = shift;
205 bless($reference, $object);
214 sub ReadPublicInterfaces
217 my $superClass = shift;
219 my $isProtocol = shift;
222 my $actualSuperClass;
223 %publicInterfaces = ();
225 my $fileName = "WebCore/bindings/objc/PublicDOMInterfaces.h";
226 my $gccLocation = "";
228 $gccLocation = $ENV{CC};
229 } elsif (($Config::Config{'osname'}) =~ /solaris/i) {
230 $gccLocation = "/usr/sfw/bin/gcc";
232 $gccLocation = "/usr/bin/gcc";
234 open FILE, "-|", $gccLocation, "-E", "-P", "-x", "objective-c",
235 (map { "-D$_" } split(/ +/, $defines)), "-DOBJC_CODE_GENERATION", $fileName or die "Could not open $fileName";
236 my @documentContent = <FILE>;
239 foreach $line (@documentContent) {
240 if (!$isProtocol && $line =~ /^\s*\@interface\s*$class\s*:\s*(\w+)\s*([A-Z0-9_]*)/) {
241 if ($superClass ne $1) {
242 warn "Public API change. Superclass for \"$class\" differs ($1 != $superClass)";
246 $interfaceAvailabilityVersion = $2 if defined $2;
249 } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*<[^>]+>\s*([A-Z0-9_]*)/) {
250 $interfaceAvailabilityVersion = $1 if defined $1;
255 last if $found and $line =~ /^\s?\@end\s?$/;
262 my $availabilityMacro = "";
263 $line =~ s/\s([A-Z0-9_]+)\s*;$/;/;
264 $availabilityMacro = $1 if defined $1;
266 $publicInterfaces{$line} = $availabilityMacro if length $line;
270 # If this class was not found in PublicDOMInterfaces.h then it should be considered as an entirely new public class.
271 $newPublicClass = !$found;
272 $interfaceAvailabilityVersion = "WEBKIT_VERSION_LATEST" if $newPublicClass;
275 sub GenerateConditionalString
278 my $conditional = $node->extendedAttributes->{"Conditional"};
280 if ($conditional =~ /&/) {
281 return "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
282 } elsif ($conditional =~ /\|/) {
283 return "ENABLE(" . join(") || ENABLE(", split(/\|/, $conditional)) . ")";
285 return "ENABLE(" . $conditional . ")";
292 # Params: 'domClass' struct
293 sub GenerateInterface
296 my $dataNode = shift;
301 my $name = $dataNode->name;
302 my $className = GetClassName($name);
303 my $parentClassName = "DOM" . GetParentImplClassName($dataNode);
304 $isProtocol = $dataNode->extendedAttributes->{ObjCProtocol};
305 $noImpl = $dataNode->extendedAttributes->{ObjCCustomImplementation} || $isProtocol;
307 ReadPublicInterfaces($className, $parentClassName, $defines, $isProtocol);
309 # Start actual generation..
310 $object->GenerateHeader($dataNode);
311 $object->GenerateImplementation($dataNode) unless $noImpl;
314 $object->WriteData("DOM" . $name);
316 # Check for missing public API
317 if (keys %publicInterfaces > 0) {
318 my $missing = join("\n", keys %publicInterfaces);
319 warn "Public API change. There are missing public properties and/or methods from the \"$className\" class.\n$missing\n";
326 # Params: 'idlDocument' struct
330 my $dataNode = shift;
332 $module = $dataNode->module;
337 my $name = $codeGenerator->StripModule(shift);
340 return "NSString" if $codeGenerator->IsStringType($name) or $name eq "SerializedScriptValue";
341 return "NS$name" if IsNativeObjCType($name);
342 return "BOOL" if $name eq "boolean";
343 return "unsigned" if $name eq "unsigned long";
344 return "int" if $name eq "long";
345 return "NSTimeInterval" if $name eq "Date";
346 return "DOMAbstractView" if $name eq "DOMWindow";
347 return $name if $codeGenerator->IsPrimitiveType($name) or $name eq "DOMImplementation" or $name eq "DOMTimeStamp";
349 # Default, assume Objective-C type has the same type name as
350 # idl type prefixed with "DOM".
354 sub GetClassHeaderName
358 return "DOMDOMImplementation" if $name eq "DOMImplementation";
364 my $name = $codeGenerator->StripModule(shift);
366 return "DOMImplementationFront" if $name eq "DOMImplementation";
367 return "DOMWindow" if $name eq "AbstractView";
371 sub GetParentImplClassName
373 my $dataNode = shift;
375 return "Object" if @{$dataNode->parents} eq 0;
377 my $parent = $codeGenerator->StripModule($dataNode->parents(0));
380 return "Object" if $parent eq "HTMLCollection";
385 sub GetParentAndProtocols
387 my $dataNode = shift;
388 my $numParents = @{$dataNode->parents};
392 if ($numParents eq 0) {
394 push(@protocols, "NSObject");
395 push(@protocols, "NSCopying") if $dataNode->name eq "EventTarget";
397 $parent = "DOMObject";
399 } elsif ($numParents eq 1) {
400 my $parentName = $codeGenerator->StripModule($dataNode->parents(0));
402 die "Parents of protocols must also be protocols." unless IsProtocolType($parentName);
403 push(@protocols, "DOM" . $parentName);
405 if (IsProtocolType($parentName)) {
406 push(@protocols, "DOM" . $parentName);
407 } elsif ($parentName eq "HTMLCollection") {
408 $parent = "DOMObject";
410 $parent = "DOM" . $parentName;
414 my @parents = @{$dataNode->parents};
415 my $firstParent = $codeGenerator->StripModule(shift(@parents));
416 if (IsProtocolType($firstParent)) {
417 push(@protocols, "DOM" . $firstParent);
419 $parent = "DOMObject";
422 $parent = "DOM" . $firstParent;
425 foreach my $parentName (@parents) {
426 $parentName = $codeGenerator->StripModule($parentName);
427 die "Everything past the first class should be a protocol!" unless IsProtocolType($parentName);
429 push(@protocols, "DOM" . $parentName);
433 return ($parent, @protocols);
440 return $parent if $parent eq "Object" or IsBaseType($parent);
441 return "Event" if $parent eq "UIEvent";
442 return "CSSValue" if $parent eq "SVGColor" or $parent eq "CSSValueList";
450 return 1 if $baseTypeHash{$type};
458 return 1 if $protocolTypeHash{$type};
466 return 1 if $nativeObjCTypeHash{$type};
473 my $name = GetClassName($type);
475 return "id <$name>" if IsProtocolType($type);
476 return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
477 return "unsigned short" if $type eq "CompareHow";
481 sub GetPropertyAttributes
483 my $type = $codeGenerator->StripModule(shift);
484 my $readOnly = shift;
488 push(@attributes, "readonly") if $readOnly;
490 # FIXME: <rdar://problem/5049934> Consider using 'nonatomic' on the DOM @property declarations.
491 if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) {
492 push(@attributes, "copy");
493 } elsif ($codeGenerator->IsSVGAnimatedType($type)) {
494 push(@attributes, "retain");
495 } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow") {
496 push(@attributes, "retain");
499 return "" unless @attributes > 0;
500 return "(" . join(", ", @attributes) . ")";
505 my $type = $codeGenerator->StripModule(shift);
507 return !$codeGenerator->IsNonPointerType($type) && !$codeGenerator->IsStringType($type) && !IsNativeObjCType($type);
510 sub GetObjCTypeGetter
513 my $type = $codeGenerator->StripModule(shift);
515 return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
516 return $argName . "Node" if $type eq "EventTarget";
517 return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow";
518 return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener";
519 return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter";
520 return "WTF::getPtr(nativeResolver)" if $type eq "XPathNSResolver";
522 if ($type eq "SerializedScriptValue") {
523 $implIncludes{"SerializedScriptValue.h"} = 1;
524 return "WebCore::SerializedScriptValue::create(WTF::String($argName))";
526 return "core($argName)";
529 sub AddForwardDeclarationsForType
531 my $type = $codeGenerator->StripModule(shift);
534 return if $codeGenerator->IsNonPointerType($type) ;
536 my $class = GetClassName($type);
538 if (IsProtocolType($type)) {
539 $headerForwardDeclarationsForProtocols{$class} = 1 if $public;
540 $privateHeaderForwardDeclarationsForProtocols{$class} = 1 if !$public and !$headerForwardDeclarationsForProtocols{$class};
544 $headerForwardDeclarations{$class} = 1 if $public;
546 # Private headers include the public header, so only add a forward declaration to the private header
547 # if the public header does not already have the same forward declaration.
548 $privateHeaderForwardDeclarations{$class} = 1 if !$public and !$headerForwardDeclarations{$class};
551 sub AddIncludesForType
553 my $type = $codeGenerator->StripModule(shift);
555 return if $codeGenerator->IsNonPointerType($type);
557 if (IsNativeObjCType($type)) {
558 if ($type eq "Color") {
559 $implIncludes{"ColorMac.h"} = 1;
564 if ($codeGenerator->IsStringType($type)) {
565 $implIncludes{"KURL.h"} = 1;
569 if ($type eq "DOMWindow") {
570 $implIncludes{"DOMAbstractViewInternal.h"} = 1;
571 $implIncludes{"DOMWindow.h"} = 1;
575 if ($type eq "DOMImplementation") {
576 $implIncludes{"DOMDOMImplementationInternal.h"} = 1;
577 $implIncludes{"DOMImplementationFront.h"} = 1;
581 if ($type eq "EventTarget") {
582 $implIncludes{"Node.h"} = 1;
583 $implIncludes{"DOMEventTarget.h"} = 1;
587 if ($codeGenerator->IsSVGAnimatedType($type)) {
588 $implIncludes{"${type}.h"} = 1;
589 $implIncludes{"DOM${type}Internal.h"} = 1;
593 if ($type =~ /(\w+)(Abs|Rel)$/) {
594 $implIncludes{"$1.h"} = 1;
595 $implIncludes{"DOM${type}Internal.h"} = 1;
599 if ($type eq "NodeFilter") {
600 $implIncludes{"NodeFilter.h"} = 1;
601 $implIncludes{"ObjCNodeFilterCondition.h"} = 1;
605 if ($type eq "EventListener") {
606 $implIncludes{"EventListener.h"} = 1;
607 $implIncludes{"ObjCEventListener.h"} = 1;
611 if ($type eq "XPathNSResolver") {
612 $implIncludes{"DOMCustomXPathNSResolver.h"} = 1;
613 $implIncludes{"XPathNSResolver.h"} = 1;
617 if ($type eq "SerializedScriptValue") {
618 $implIncludes{"SerializedScriptValue.h"} = 1;
622 # FIXME: won't compile without these
623 $implIncludes{"CSSMutableStyleDeclaration.h"} = 1 if $type eq "CSSStyleDeclaration";
624 $implIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList";
626 # Default, include the same named file (the implementation) and the same name prefixed with "DOM".
627 $implIncludes{"$type.h"} = 1 if not $codeGenerator->AvoidInclusionOfType($type);
628 $implIncludes{"DOM${type}Internal.h"} = 1;
631 sub GetSVGTypeWithNamespace
634 my $typeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($type);
636 # Special case for DOMSVGNumber
637 $typeWithNamespace =~ s/</\<WebCore::/ unless $type eq "SVGNumber";
638 return $typeWithNamespace;
641 sub GetSVGPropertyTypes
643 my $implType = shift;
646 my $svgListPropertyType;
649 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $implType =~ /SVG/;
651 $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($implType);
652 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType;
654 # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType>
655 $svgNativeType = "WebCore::$svgNativeType ";
656 $svgNativeType =~ s/</\<WebCore::/ if not $svgNativeType =~ /float/;
658 my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implType);
659 if ($svgNativeType =~ /SVGPropertyTearOff/) {
660 if ($svgWrappedNativeType eq "float") {
661 # Special case for DOMSVGNumber
662 $svgPropertyType = $svgWrappedNativeType;
664 $svgPropertyType = "WebCore::$svgWrappedNativeType";
665 $svgPropertyType =~ s/</\<WebCore::/;
667 } elsif ($svgNativeType =~ /SVGListPropertyTearOff/ or $svgNativeType =~ /SVGStaticListPropertyTearOff/) {
668 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
669 $svgListPropertyType =~ s/</\<WebCore::/;
670 } elsif ($svgNativeType =~ /SVGTransformListPropertyTearOff/) {
671 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
672 $svgListPropertyType =~ s/</\<WebCore::/;
673 } elsif ($svgNativeType =~ /SVGPathSegListPropertyTearOff/) {
674 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
675 $svgListPropertyType =~ s/</\<WebCore::/;
678 return ($svgPropertyType, $svgListPropertyType, $svgNativeType);
684 my $dataNode = shift;
686 my $interfaceName = $dataNode->name;
687 my $className = GetClassName($interfaceName);
690 my @protocolsToImplement = ();
691 ($parentName, @protocolsToImplement) = GetParentAndProtocols($dataNode);
693 my $numConstants = @{$dataNode->constants};
694 my $numAttributes = @{$dataNode->attributes};
695 my $numFunctions = @{$dataNode->functions};
697 # - Add default header template
698 @headerContentHeader = split("\r", $headerLicenseTemplate);
699 push(@headerContentHeader, "\n");
702 my $includedWebKitAvailabilityHeader = 0;
703 unless ($isProtocol) {
704 my $parentHeaderName = GetClassHeaderName($parentName);
705 push(@headerContentHeader, "#import <WebCore/$parentHeaderName.h>\n");
706 $includedWebKitAvailabilityHeader = 1;
709 foreach my $parentProtocol (@protocolsToImplement) {
710 next if $parentProtocol =~ /^NS/;
711 $parentProtocol = GetClassHeaderName($parentProtocol);
712 push(@headerContentHeader, "#import <WebCore/$parentProtocol.h>\n");
713 $includedWebKitAvailabilityHeader = 1;
716 # Special case needed for legacy support of DOMRange
717 if ($interfaceName eq "Range") {
718 push(@headerContentHeader, "#import <WebCore/DOMCore.h>\n");
719 push(@headerContentHeader, "#import <WebCore/DOMDocument.h>\n");
720 push(@headerContentHeader, "#import <WebCore/DOMRangeException.h>\n");
721 $includedWebKitAvailabilityHeader = 1;
724 push(@headerContentHeader, "#import <JavaScriptCore/WebKitAvailability.h>\n") unless $includedWebKitAvailabilityHeader;
726 my $interfaceAvailabilityVersionCheck = "#if WEBKIT_VERSION_MAX_ALLOWED >= $interfaceAvailabilityVersion\n\n";
728 push(@headerContentHeader, "\n");
729 push(@headerContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
732 if ($numConstants > 0) {
733 my @headerConstants = ();
735 # FIXME: we need a way to include multiple enums.
736 foreach my $constant (@{$dataNode->constants}) {
737 my $constantName = $constant->name;
738 my $constantValue = $constant->value;
740 my $output = " DOM_" . $constantName . " = " . $constantValue;
741 push(@headerConstants, $output);
744 my $combinedConstants = join(",\n", @headerConstants);
746 # FIXME: the formatting of the enums should line up the equal signs.
747 # FIXME: enums are unconditionally placed in the public header.
748 push(@headerContent, "enum {\n");
749 push(@headerContent, $combinedConstants);
750 push(@headerContent, "\n};\n\n");
753 # - Begin @interface or @protocol
754 my $interfaceDeclaration = ($isProtocol ? "\@protocol $className" : "\@interface $className : $parentName");
755 $interfaceDeclaration .= " <" . join(", ", @protocolsToImplement) . ">" if @protocolsToImplement > 0;
756 $interfaceDeclaration .= "\n";
758 push(@headerContent, $interfaceDeclaration);
760 my @headerAttributes = ();
761 my @privateHeaderAttributes = ();
763 # - Add attribute getters/setters.
764 if ($numAttributes > 0) {
765 foreach my $attribute (@{$dataNode->attributes}) {
766 my $attributeName = $attribute->signature->name;
768 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
769 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
770 $attributeName .= "Name";
771 } elsif ($attributeName eq "frame") {
772 # Special case attribute frame to be frameBorders.
773 $attributeName .= "Borders";
776 my $attributeType = GetObjCType($attribute->signature->type);
777 my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
779 my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attributeIsReadonly);
780 # Some SVGFE*Element.idl use 'operator' as attribute name, rewrite as '_operator' to avoid clashes with C/C++
781 $attributeName =~ s/operator/_operator/ if ($attributeName =~ /operator/);
782 $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName;
784 my $publicInterfaceKey = $property . ";";
786 my $availabilityMacro = "";
787 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
788 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
791 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
793 my $declarationSuffix = ";\n";
794 $declarationSuffix = " $availabilityMacro;\n" if length $availabilityMacro;
796 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
797 delete $publicInterfaces{$publicInterfaceKey};
799 AddForwardDeclarationsForType($attribute->signature->type, $public);
801 my $setterName = "set" . ucfirst($attributeName) . ":";
803 my $conflict = $conflictMethod{$attributeName};
805 warn "$className conflicts with $conflict method $attributeName\n";
809 $conflict = $conflictMethod{$setterName};
811 warn "$className conflicts with $conflict method $setterName\n";
815 if ($buildingForLeopardOrLater) {
816 $property .= $declarationSuffix;
817 push(@headerAttributes, $property) if $public;
818 push(@privateHeaderAttributes, $property) unless $public;
820 my $attributeConditionalString = GenerateConditionalString($attribute->signature);
821 if ($attributeConditionalString) {
822 push(@headerAttributes, "#if ${attributeConditionalString}\n") if $public;
823 push(@privateHeaderAttributes, "#if ${attributeConditionalString}\n") unless $public;
827 my $getter = "- (" . $attributeType . ")" . $attributeName . $declarationSuffix;
828 push(@headerAttributes, $getter) if $public;
829 push(@privateHeaderAttributes, $getter) unless $public;
832 if (!$attributeIsReadonly) {
833 my $setter = "- (void)$setterName(" . $attributeType . ")new" . ucfirst($attributeName) . $declarationSuffix;
834 push(@headerAttributes, $setter) if $public;
835 push(@privateHeaderAttributes, $setter) unless $public;
838 if ($attributeConditionalString) {
839 push(@headerAttributes, "#endif\n") if $public;
840 push(@privateHeaderAttributes, "#endif\n") unless $public;
845 push(@headerContent, @headerAttributes) if @headerAttributes > 0;
848 my @headerFunctions = ();
849 my @privateHeaderFunctions = ();
850 my @deprecatedHeaderFunctions = ();
853 if ($numFunctions > 0) {
854 foreach my $function (@{$dataNode->functions}) {
855 my $functionName = $function->signature->name;
857 my $returnType = GetObjCType($function->signature->type);
858 my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"});
859 my $numberOfParameters = @{$function->parameters};
860 my %typesToForwardDeclare = ($function->signature->type => 1);
862 my $parameterIndex = 0;
863 my $functionSig = "- ($returnType)$functionName";
864 my $methodName = $functionName;
865 foreach my $param (@{$function->parameters}) {
866 my $paramName = $param->name;
867 my $paramType = GetObjCType($param->type);
869 $typesToForwardDeclare{$param->type} = 1;
871 if ($parameterIndex >= 1) {
872 my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
873 $paramPrefix = $paramName unless defined($paramPrefix);
874 $functionSig .= " $paramPrefix";
875 $methodName .= $paramPrefix;
878 $functionSig .= ":($paramType)$paramName";
884 my $publicInterfaceKey = $functionSig . ";";
886 my $conflict = $conflictMethod{$methodName};
888 warn "$className conflicts with $conflict method $methodName\n";
892 if ($isProtocol && !$newPublicClass && !defined $publicInterfaces{$publicInterfaceKey}) {
893 warn "Protocol method $publicInterfaceKey is not in PublicDOMInterfaces.h. Protocols require all methods to be public";
897 my $availabilityMacro = "";
898 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
899 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
902 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
904 my $functionDeclaration = $functionSig;
905 $functionDeclaration .= " " . $availabilityMacro if length $availabilityMacro;
906 $functionDeclaration .= ";\n";
908 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
909 delete $publicInterfaces{$publicInterfaceKey};
911 foreach my $type (keys %typesToForwardDeclare) {
912 # add any forward declarations to the public header if a deprecated version will be generated
913 AddForwardDeclarationsForType($type, 1) if $needsDeprecatedVersion;
914 AddForwardDeclarationsForType($type, $public) unless $public and $needsDeprecatedVersion;
917 push(@headerFunctions, $functionDeclaration) if $public;
918 push(@privateHeaderFunctions, $functionDeclaration) unless $public;
920 # generate the old style method names with un-named parameters, these methods are deprecated
921 if ($needsDeprecatedVersion) {
922 my $deprecatedFunctionSig = $functionSig;
923 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
925 $publicInterfaceKey = $deprecatedFunctionSig . ";";
927 my $availabilityMacro = "AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0";
928 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
929 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
932 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if $buildingForTigerOrEarlier;
934 $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
936 push(@deprecatedHeaderFunctions, $functionDeclaration);
938 unless (defined $publicInterfaces{$publicInterfaceKey}) {
939 warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the OldStyleObjC IDL attribute removed";
943 delete $publicInterfaces{$publicInterfaceKey};
947 if (@headerFunctions > 0) {
948 push(@headerContent, "\n") if $buildingForLeopardOrLater and @headerAttributes > 0;
949 push(@headerContent, @headerFunctions);
953 if (@deprecatedHeaderFunctions > 0 && $isProtocol) {
954 push(@headerContent, @deprecatedHeaderFunctions);
957 # - End @interface or @protocol
958 push(@headerContent, "\@end\n");
960 if (@deprecatedHeaderFunctions > 0 && !$isProtocol) {
961 # - Deprecated category @interface
962 push(@headerContent, "\n\@interface $className (" . $className . "Deprecated)\n");
963 push(@headerContent, @deprecatedHeaderFunctions);
964 push(@headerContent, "\@end\n");
967 push(@headerContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
969 my %alwaysGenerateForNoSVGBuild = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement);
971 if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0 or exists $alwaysGenerateForNoSVGBuild{$className}) {
972 # - Private category @interface
973 @privateHeaderContentHeader = split("\r", $headerLicenseTemplate);
974 push(@privateHeaderContentHeader, "\n");
976 my $classHeaderName = GetClassHeaderName($className);
977 push(@privateHeaderContentHeader, "#import <WebCore/$classHeaderName.h>\n\n");
978 push(@privateHeaderContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
980 @privateHeaderContent = ();
981 push(@privateHeaderContent, "\@interface $className (" . $className . "Private)\n");
982 push(@privateHeaderContent, @privateHeaderAttributes) if @privateHeaderAttributes > 0;
983 push(@privateHeaderContent, "\n") if $buildingForLeopardOrLater and @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0;
984 push(@privateHeaderContent, @privateHeaderFunctions) if @privateHeaderFunctions > 0;
985 push(@privateHeaderContent, "\@end\n");
987 push(@privateHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
990 unless ($isProtocol) {
991 # Generate internal interfaces
992 my $implClassName = GetImplClassName($interfaceName);
993 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
995 my $implType = $implClassNameWithNamespace;
996 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
997 $implType = $svgNativeType if $svgNativeType;
999 # Generate interface definitions.
1000 @internalHeaderContent = split("\r", $implementationLicenseTemplate);
1002 push(@internalHeaderContent, "\n#import <WebCore/$className.h>\n\n");
1003 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedPropertyTearOff.h>\n\n") if $svgPropertyType;
1004 if ($svgListPropertyType) {
1005 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedListPropertyTearOff.h>\n\n");
1006 push(@internalHeaderContent, "#import <WebCore/SVGTransformListPropertyTearOff.h>\n\n") if $svgListPropertyType =~ /SVGTransformList/;
1007 push(@internalHeaderContent, "#import <WebCore/SVGPathSegListPropertyTearOff.h>\n\n") if $svgListPropertyType =~ /SVGPathSegList/;
1009 push(@internalHeaderContent, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
1011 if ($interfaceName eq "Node") {
1012 push(@internalHeaderContent, "\@protocol DOMEventTarget;\n\n");
1015 my $startedNamespace = 0;
1017 if ($codeGenerator->IsSVGAnimatedType($interfaceName)) {
1018 push(@internalHeaderContent, "#import <WebCore/$implClassName.h>\n\n");
1020 push(@internalHeaderContent, "namespace WebCore {\n");
1021 $startedNamespace = 1;
1022 if ($interfaceName eq "Node") {
1023 push(@internalHeaderContent, " class EventTarget;\n class Node;\n");
1025 push(@internalHeaderContent, " class $implClassName;\n");
1027 push(@internalHeaderContent, "}\n\n");
1030 push(@internalHeaderContent, "$implType* core($className *);\n");
1031 push(@internalHeaderContent, "$className *kit($implType*);\n");
1033 if ($dataNode->extendedAttributes->{Polymorphic}) {
1034 push(@internalHeaderContent, "Class kitClass($implType*);\n");
1037 if ($interfaceName eq "Node") {
1038 push(@internalHeaderContent, "id <DOMEventTarget> kit(WebCore::EventTarget*);\n");
1041 push(@internalHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
1045 sub GenerateImplementation
1048 my $dataNode = shift;
1050 my @ancestorInterfaceNames = ();
1052 if (@{$dataNode->parents} > 1) {
1053 $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@ancestorInterfaceNames);
1056 my $interfaceName = $dataNode->name;
1057 my $className = GetClassName($interfaceName);
1058 my $implClassName = GetImplClassName($interfaceName);
1059 my $parentImplClassName = GetParentImplClassName($dataNode);
1060 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
1061 my $baseClass = GetBaseClass($parentImplClassName);
1062 my $classHeaderName = GetClassHeaderName($className);
1064 my $numAttributes = @{$dataNode->attributes};
1065 my $numFunctions = @{$dataNode->functions};
1066 my $implType = $implClassNameWithNamespace;
1068 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
1069 $implType = $svgNativeType if $svgNativeType;
1071 # - Add default header template.
1072 @implContentHeader = split("\r", $implementationLicenseTemplate);
1075 push(@implContentHeader, "\n#import \"config.h\"\n");
1077 my $conditionalString = GenerateConditionalString($dataNode);
1078 push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString;
1080 push(@implContentHeader, "#import \"DOMInternal.h\"\n\n");
1081 push(@implContentHeader, "#import \"$classHeaderName.h\"\n\n");
1083 $implIncludes{"ExceptionHandlers.h"} = 1;
1084 $implIncludes{"ThreadCheck.h"} = 1;
1085 $implIncludes{"JSMainThreadExecState.h"} = 1;
1086 $implIncludes{"WebScriptObjectPrivate.h"} = 1;
1087 $implIncludes{$classHeaderName . "Internal.h"} = 1;
1089 # FIXME: These includes are only needed when the class is a subclass of one of these polymorphic classes.
1090 $implIncludes{"DOMBlobInternal.h"} = 1;
1091 $implIncludes{"DOMCSSRuleInternal.h"} = 1;
1092 $implIncludes{"DOMCSSValueInternal.h"} = 1;
1093 $implIncludes{"DOMEventInternal.h"} = 1;
1094 $implIncludes{"DOMNodeInternal.h"} = 1;
1095 $implIncludes{"DOMStyleSheetInternal.h"} = 1;
1097 $implIncludes{"DOMSVGPathSegInternal.h"} = 1 if $interfaceName =~ /^SVGPathSeg.+/;
1099 if ($interfaceName =~ /(\w+)(Abs|Rel)$/) {
1100 $implIncludes{"$1.h"} = 1;
1102 if (!$codeGenerator->AvoidInclusionOfType($implClassName)) {
1103 $implIncludes{"$implClassName.h"} = 1 ;
1104 } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($implClassName)) {
1105 my $includeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implClassName);
1106 $implIncludes{"${includeType}.h"} = 1;
1112 push(@implContent, "#import <wtf/GetPtr.h>\n\n");
1114 # add implementation accessor
1115 if ($parentImplClassName eq "Object") {
1116 push(@implContent, "#define IMPL reinterpret_cast<$implType*>(_internal)\n\n");
1118 my $baseClassWithNamespace = "WebCore::$baseClass";
1119 push(@implContent, "#define IMPL static_cast<$implClassNameWithNamespace*>(reinterpret_cast<$baseClassWithNamespace*>(_internal))\n\n");
1122 # START implementation
1123 push(@implContent, "\@implementation $className\n\n");
1125 # Only generate 'dealloc' and 'finalize' methods for direct subclasses of DOMObject.
1126 if ($parentImplClassName eq "Object") {
1127 $implIncludes{"WebCoreObjCExtras.h"} = 1;
1128 push(@implContent, "- (void)dealloc\n");
1129 push(@implContent, "{\n");
1130 push(@implContent, " if (WebCoreObjCScheduleDeallocateOnMainThread([$className class], self))\n");
1131 push(@implContent, " return;\n");
1132 push(@implContent, "\n");
1133 if ($interfaceName eq "NodeIterator") {
1134 push(@implContent, " if (_internal) {\n");
1135 push(@implContent, " [self detach];\n");
1136 push(@implContent, " IMPL->deref();\n");
1137 push(@implContent, " };\n");
1139 push(@implContent, " if (_internal)\n");
1140 push(@implContent, " IMPL->deref();\n");
1142 push(@implContent, " [super dealloc];\n");
1143 push(@implContent, "}\n\n");
1145 push(@implContent, "- (void)finalize\n");
1146 push(@implContent, "{\n");
1147 if ($interfaceName eq "NodeIterator") {
1148 push(@implContent, " if (_internal) {\n");
1149 push(@implContent, " [self detach];\n");
1150 push(@implContent, " IMPL->deref();\n");
1151 push(@implContent, " };\n");
1153 push(@implContent, " if (_internal)\n");
1154 push(@implContent, " IMPL->deref();\n");
1156 push(@implContent, " [super finalize];\n");
1157 push(@implContent, "}\n\n");
1161 %attributeNames = ();
1164 if ($numAttributes > 0) {
1165 foreach my $attribute (@{$dataNode->attributes}) {
1166 AddIncludesForType($attribute->signature->type);
1168 my $idlType = $codeGenerator->StripModule($attribute->signature->type);
1170 my $attributeName = $attribute->signature->name;
1171 my $attributeType = GetObjCType($attribute->signature->type);
1172 my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
1173 my $attributeClassName = GetClassName($attribute->signature->type);
1175 my $attributeInterfaceName = $attributeName;
1176 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
1177 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
1178 $attributeInterfaceName .= "Name";
1179 } elsif ($attributeName eq "frame") {
1180 # Special case attribute frame to be frameBorders.
1181 $attributeInterfaceName .= "Borders";
1182 } elsif ($attributeName eq "operator") {
1183 # Avoid clash with C++ keyword.
1184 $attributeInterfaceName = "_operator";
1187 $attributeNames{$attributeInterfaceName} = 1;
1190 my $getterSig = "- ($attributeType)$attributeInterfaceName\n";
1192 my $getterExpressionPrefix = $codeGenerator->GetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
1194 # FIXME: Special case attribute ownerDocument to call document. This makes it return the
1195 # document when called on the document itself. Legacy behavior, see <https://bugs.webkit.org/show_bug.cgi?id=10889>.
1196 $getterExpressionPrefix =~ s/\bownerDocument\b/document/;
1198 my $hasGetterException = @{$attribute->getterExceptions};
1199 my $getterContentHead = "IMPL->$getterExpressionPrefix";
1200 my $getterContentTail = ")";
1202 if ($svgPropertyType) {
1203 $getterContentHead = "$getterExpressionPrefix";
1205 # TODO: Handle special case for DOMSVGLength. We do need Custom code support for this.
1206 if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
1207 $getterContentHead = "value(IMPL->contextElement(), ";
1211 my $attributeTypeSansPtr = $attributeType;
1212 $attributeTypeSansPtr =~ s/ \*$//; # Remove trailing " *" from pointer types.
1214 # special case for EventTarget protocol
1215 $attributeTypeSansPtr = "DOMNode" if $idlType eq "EventTarget";
1218 my @customGetterContent = ();
1219 if ($attributeTypeSansPtr eq "DOMImplementation") {
1220 # FIXME: We have to special case DOMImplementation until DOMImplementationFront is removed
1221 $getterContentHead = "kit(implementationFront(IMPL";
1222 $getterContentTail .= ")";
1223 } elsif ($attributeName =~ /(\w+)DisplayString$/) {
1224 my $attributeToDisplay = $1;
1225 $getterContentHead = "WebCore::displayString(IMPL->$attributeToDisplay(), core(self)";
1226 $implIncludes{"HitTestResult.h"} = 1;
1227 } elsif ($attributeName =~ /^absolute(\w+)URL$/) {
1229 $getterContentHead = "[self _getURLAttribute:";
1230 if ($typeOfURL eq "Link") {
1231 $getterContentTail = "\@\"href\"]";
1232 } elsif ($typeOfURL eq "Image") {
1233 if ($interfaceName eq "HTMLObjectElement") {
1234 $getterContentTail = "\@\"data\"]";
1236 $getterContentTail = "\@\"src\"]";
1238 unless ($interfaceName eq "HTMLImageElement") {
1239 push(@customGetterContent, " if (!IMPL->renderer() || !IMPL->renderer()->isImage())\n");
1240 push(@customGetterContent, " return nil;\n");
1241 $implIncludes{"RenderObject.h"} = 1;
1244 $implIncludes{"DOMPrivate.h"} = 1;
1245 } elsif ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
1246 $getterContentHead = "WTF::String::number(" . $getterContentHead;
1247 $getterContentTail .= ")";
1248 } elsif ($idlType eq "Date") {
1249 $getterContentHead = "kit($getterContentHead";
1250 $getterContentTail .= ")";
1251 } elsif ($svgPropertyType) {
1252 # Special case for DOMSVGNumber
1253 if ($svgPropertyType eq "float") {
1254 # Intentional leave out closing brace, it's already contained in getterContentTail
1255 $getterContentHead = "IMPL->propertyReference(";
1257 $getterContentHead = "IMPL->propertyReference().$getterContentHead";
1260 if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($idlType) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
1261 my $getter = $getterContentHead;
1262 $getter =~ s/\(\)//;
1264 my $tearOffType = GetSVGTypeWithNamespace($idlType);
1265 my $selfIsTearOffType = $codeGenerator->IsSVGTypeNeedingTearOff($implClassName);
1266 if ($selfIsTearOffType) {
1267 $implIncludes{"SVGStaticPropertyWithParentTearOff.h"} = 1;
1268 $tearOffType =~ s/SVGPropertyTearOff</SVGStaticPropertyWithParentTearOff<$implClassNameWithNamespace, /;
1270 my $getter = $getterExpressionPrefix;
1271 $getter =~ s/IMPL->//;
1273 my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter);
1275 if ($getterContentHead =~ /matrix/ and $implClassName eq "SVGTransform") {
1276 # SVGTransform offers a matrix() method for internal usage that returns an AffineTransform
1277 # and a svgMatrix() method returning a SVGMatrix, used for the bindings.
1278 $getterContentHead =~ s/matrix/svgMatrix/;
1281 $getterContentHead = "${tearOffType}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod)";
1283 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1284 $getterContentTail = "))";
1287 } elsif ($codeGenerator->IsSVGAnimatedType($implClassName) and $codeGenerator->IsSVGTypeNeedingTearOff($idlType)) {
1288 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
1289 $getterContentHead = "kit(static_cast<$idlTypeWithNamespace*>($getterContentHead)";
1290 $getterContentTail .= ")";
1291 } elsif (IsProtocolType($idlType) and $idlType ne "EventTarget") {
1292 $getterContentHead = "kit($getterContentHead";
1293 $getterContentTail .= ")";
1294 } elsif ($idlType eq "Color") {
1295 $getterContentHead = "WebCore::nsColor($getterContentHead";
1296 $getterContentTail .= ")";
1297 } elsif ($attribute->signature->type eq "SerializedScriptValue") {
1298 $getterContentHead = "$getterContentHead";
1299 $getterContentTail .= "->toString()";
1300 } elsif (ConversionNeeded($attribute->signature->type)) {
1301 my $type = $attribute->signature->type;
1302 if ($codeGenerator->IsSVGTypeNeedingTearOff($type) and not $implClassName =~ /List$/) {
1303 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($type);
1304 $implIncludes{"$type.h"} = 1 if not $codeGenerator->AvoidInclusionOfType($type);
1305 if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($type) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
1306 $idlTypeWithNamespace =~ s/SVGPropertyTearOff</SVGStaticPropertyTearOff<$implClassNameWithNamespace, /;
1307 $implIncludes{"SVGStaticPropertyTearOff.h"} = 1;
1309 my $getter = $getterContentHead;
1310 $getter =~ s/IMPL->//;
1312 my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter);
1313 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod";
1314 $getterContentTail .= "))";
1315 } elsif ($idlTypeWithNamespace =~ /SVG(Point|PathSeg)List/) {
1316 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1317 $getterContentTail .= "))";
1318 } elsif ($idlTypeWithNamespace =~ /SVGStaticListPropertyTearOff/) {
1319 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead";
1320 $getterContentTail .= ")))";
1322 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($getterContentHead";
1323 $getterContentTail .= ")))";
1326 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1327 $getterContentTail .= "))";
1332 if ($hasGetterException) {
1333 $getterContent = $getterContentHead . "ec" . $getterContentTail;
1335 $getterContent = $getterContentHead . $getterContentTail;
1338 my $attributeConditionalString = GenerateConditionalString($attribute->signature);
1339 push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString;
1340 push(@implContent, $getterSig);
1341 push(@implContent, "{\n");
1342 push(@implContent, " $jsContextSetter\n");
1343 push(@implContent, @customGetterContent);
1344 if ($hasGetterException) {
1345 # Differentiated between when the return type is a pointer and
1346 # not for white space issue (ie. Foo *result vs. int result).
1347 if ($attributeType =~ /\*$/) {
1348 $getterContent = $attributeType . "result = " . $getterContent;
1350 $getterContent = $attributeType . " result = " . $getterContent;
1353 push(@implContent, " $exceptionInit\n");
1354 push(@implContent, " $getterContent;\n");
1355 push(@implContent, " $exceptionRaiseOnError\n");
1356 push(@implContent, " return result;\n");
1358 push(@implContent, " return $getterContent;\n");
1360 push(@implContent, "}\n");
1363 if (!$attributeIsReadonly) {
1364 # Exception handling
1365 my $hasSetterException = @{$attribute->setterExceptions};
1367 my $coreSetterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
1368 my $setterName = "set" . ucfirst($attributeInterfaceName);
1369 my $argName = "new" . ucfirst($attributeInterfaceName);
1370 my $arg = GetObjCTypeGetter($argName, $idlType);
1372 # The definition of ConvertToString is flipped for the setter
1373 if ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
1374 $arg = "WTF::String($arg).toInt()";
1377 my $setterSig = "- (void)$setterName:($attributeType)$argName\n";
1379 push(@implContent, "\n");
1380 push(@implContent, $setterSig);
1381 push(@implContent, "{\n");
1382 push(@implContent, " $jsContextSetter\n");
1384 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1385 push(@implContent, " ASSERT($argName);\n\n");
1388 if ($idlType eq "Date") {
1389 $arg = "core(" . $arg . ")";
1392 if ($svgPropertyType) {
1393 $getterContentHead = "$getterExpressionPrefix";
1394 push(@implContent, " if (IMPL->role() == WebCore::AnimValRole) {\n");
1395 push(@implContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n");
1396 push(@implContent, " return;\n");
1397 push(@implContent, " }\n");
1398 push(@implContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1399 my $ec = $hasSetterException ? ", ec" : "";
1400 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1402 # Special case for DOMSVGNumber
1403 if ($svgPropertyType eq "float") {
1404 push(@implContent, " podImpl = $arg;\n");
1406 # FIXME: Special case for DOMSVGLength. We do need Custom code support for this.
1407 if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
1408 push(@implContent, " podImpl.$coreSetterName($arg, IMPL->contextElement()$ec);\n");
1410 push(@implContent, " podImpl.$coreSetterName($arg$ec);\n");
1414 if ($hasSetterException) {
1415 push(@implContent, " if (!ec)\n");
1416 push(@implContent, " IMPL->commitChange();\n");
1417 push(@implContent, " $exceptionRaiseOnError\n");
1419 push(@implContent, " IMPL->commitChange();\n");
1421 } elsif ($svgListPropertyType) {
1422 $getterContentHead = "$getterExpressionPrefix";
1423 push(@implContent, " IMPL->$coreSetterName($arg);\n");
1425 my $setterExpressionPrefix = $codeGenerator->SetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
1426 my $ec = $hasSetterException ? ", ec" : "";
1427 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1428 push(@implContent, " IMPL->$setterExpressionPrefix$arg$ec);\n");
1429 push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException;
1432 push(@implContent, "}\n");
1435 push(@implContent, "#endif\n") if $attributeConditionalString;
1436 push(@implContent, "\n");
1441 if ($numFunctions > 0) {
1442 foreach my $function (@{$dataNode->functions}) {
1443 AddIncludesForType($function->signature->type);
1445 my $functionName = $function->signature->name;
1446 my $returnType = GetObjCType($function->signature->type);
1447 my $hasParameters = @{$function->parameters};
1448 my $raisesExceptions = @{$function->raisesExceptions};
1450 my @parameterNames = ();
1451 my @needsAssert = ();
1452 my %needsCustom = ();
1454 my $parameterIndex = 0;
1455 my $functionSig = "- ($returnType)$functionName";
1456 foreach my $param (@{$function->parameters}) {
1457 my $paramName = $param->name;
1458 my $paramType = GetObjCType($param->type);
1460 # make a new parameter name if the original conflicts with a property name
1461 $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
1463 AddIncludesForType($param->type);
1465 my $idlType = $codeGenerator->StripModule($param->type);
1466 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1468 push(@parameterNames, $implGetter);
1469 $needsCustom{"XPathNSResolver"} = $paramName if $idlType eq "XPathNSResolver";
1470 $needsCustom{"NodeFilter"} = $paramName if $idlType eq "NodeFilter";
1471 $needsCustom{"EventListener"} = $paramName if $idlType eq "EventListener";
1472 $needsCustom{"EventTarget"} = $paramName if $idlType eq "EventTarget";
1473 $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"Return"};
1475 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1476 push(@needsAssert, " ASSERT($paramName);\n");
1479 if ($parameterIndex >= 1) {
1480 my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
1481 $paramPrefix = $param->name unless defined($paramPrefix);
1482 $functionSig .= " $paramPrefix";
1485 $functionSig .= ":($paramType)$paramName";
1490 my @functionContent = ();
1491 my $caller = "IMPL";
1493 # special case the XPathNSResolver
1494 if (defined $needsCustom{"XPathNSResolver"}) {
1495 my $paramName = $needsCustom{"XPathNSResolver"};
1496 push(@functionContent, " WebCore::XPathNSResolver* nativeResolver = 0;\n");
1497 push(@functionContent, " RefPtr<WebCore::XPathNSResolver> customResolver;\n");
1498 push(@functionContent, " if ($paramName) {\n");
1499 push(@functionContent, " if ([$paramName isMemberOfClass:[DOMNativeXPathNSResolver class]])\n");
1500 push(@functionContent, " nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>($paramName));\n");
1501 push(@functionContent, " else {\n");
1502 push(@functionContent, " customResolver = WebCore::DOMCustomXPathNSResolver::create($paramName);\n");
1503 push(@functionContent, " nativeResolver = WTF::getPtr(customResolver);\n");
1504 push(@functionContent, " }\n");
1505 push(@functionContent, " }\n");
1508 # special case the EventTarget
1509 if (defined $needsCustom{"EventTarget"}) {
1510 my $paramName = $needsCustom{"EventTarget"};
1511 push(@functionContent, " DOMNode* ${paramName}ObjC = $paramName;\n");
1512 push(@functionContent, " WebCore::Node* ${paramName}Node = core(${paramName}ObjC);\n");
1513 $implIncludes{"DOMNode.h"} = 1;
1514 $implIncludes{"Node.h"} = 1;
1517 if ($function->signature->extendedAttributes->{"UsesView"}) {
1518 push(@functionContent, " WebCore::DOMWindow* dv = $caller->defaultView();\n");
1519 push(@functionContent, " if (!dv)\n");
1520 push(@functionContent, " return nil;\n");
1521 $implIncludes{"DOMWindow.h"} = 1;
1525 # special case the EventListener
1526 if (defined $needsCustom{"EventListener"}) {
1527 my $paramName = $needsCustom{"EventListener"};
1528 push(@functionContent, " RefPtr<WebCore::EventListener> nativeEventListener = WebCore::ObjCEventListener::wrap($paramName);\n");
1531 # special case the NodeFilter
1532 if (defined $needsCustom{"NodeFilter"}) {
1533 my $paramName = $needsCustom{"NodeFilter"};
1534 push(@functionContent, " RefPtr<WebCore::NodeFilter> nativeNodeFilter;\n");
1535 push(@functionContent, " if ($paramName)\n");
1536 push(@functionContent, " nativeNodeFilter = WebCore::NodeFilter::create(WebCore::ObjCNodeFilterCondition::create($paramName));\n");
1539 # FIXME! We need [Custom] support for ObjC, to move these hacks into DOMSVGLength/MatrixCustom.mm
1540 my $svgLengthConvertToSpecifiedUnits = ($svgPropertyType and $svgPropertyType eq "WebCore::SVGLength" and $functionName eq "convertToSpecifiedUnits");
1542 push(@parameterNames, "IMPL->contextElement()") if $svgLengthConvertToSpecifiedUnits;
1543 push(@parameterNames, "ec") if $raisesExceptions;
1545 # Handle arguments that are 'SVGProperty' based (SVGAngle/SVGLength). We need to convert from SVGPropertyTearOff<Type>* to Type,
1546 # to be able to call the desired WebCore function. If the conversion fails, we can't extract Type and need to raise an exception.
1547 my $currentParameter = -1;
1548 foreach my $param (@{$function->parameters}) {
1549 $currentParameter++;
1551 my $paramName = $param->name;
1553 # make a new parameter name if the original conflicts with a property name
1554 $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
1556 my $idlType = $codeGenerator->StripModule($param->type);
1557 next if not $codeGenerator->IsSVGTypeNeedingTearOff($idlType) or $implClassName =~ /List$/;
1559 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1560 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
1562 push(@functionContent, " $idlTypeWithNamespace* ${paramName}Core = $implGetter;\n");
1563 push(@functionContent, " if (!${paramName}Core) {\n");
1564 push(@functionContent, " WebCore::ExceptionCode ec = WebCore::TYPE_MISMATCH_ERR;\n");
1565 push(@functionContent, " $exceptionRaiseOnError\n");
1566 if ($returnType eq "void") {
1567 push(@functionContent, " return;\n");
1569 push(@functionContent, " return nil;\n");
1571 push(@functionContent, " }\n");
1573 # Replace the paramter core() getter, by the cached variable.
1574 splice(@parameterNames, $currentParameter, 1, "${paramName}Core->propertyReference()");
1577 my $content = $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
1579 if ($svgPropertyType) {
1580 push(@functionContent, " if (IMPL->role() == WebCore::AnimValRole) {\n");
1581 push(@functionContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n");
1582 if ($returnType eq "void") {
1583 push(@functionContent, " return;\n");
1585 push(@functionContent, " return nil;\n");
1587 push(@functionContent, " }\n");
1588 push(@functionContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1589 $content = "podImpl.$content";
1591 $content = $caller . "->$content";
1594 if ($returnType eq "void") {
1595 # Special case 'void' return type.
1596 if ($raisesExceptions) {
1597 push(@functionContent, " $exceptionInit\n");
1598 push(@functionContent, " $content;\n");
1599 if ($svgPropertyType) {
1600 push(@functionContent, " if (!ec)\n");
1601 push(@functionContent, " IMPL->commitChange();\n");
1603 push(@functionContent, " $exceptionRaiseOnError\n");
1605 push(@functionContent, " $content;\n");
1606 push(@functionContent, " IMPL->commitChange();\n") if $svgPropertyType;
1608 } elsif (defined $needsCustom{"NodeToReturn"}) {
1609 # Special case the insertBefore, replaceChild, removeChild
1610 # and appendChild functions from DOMNode
1611 my $toReturn = $needsCustom{"NodeToReturn"};
1612 if ($raisesExceptions) {
1613 push(@functionContent, " $exceptionInit\n");
1614 push(@functionContent, " if ($content)\n");
1615 push(@functionContent, " return $toReturn;\n");
1616 push(@functionContent, " $exceptionRaiseOnError\n");
1617 push(@functionContent, " return nil;\n");
1619 push(@functionContent, " if ($content)\n");
1620 push(@functionContent, " return $toReturn;\n");
1621 push(@functionContent, " return nil;\n");
1623 } elsif ($returnType eq "SerializedScriptValue") {
1626 if (ConversionNeeded($function->signature->type)) {
1627 if ($codeGenerator->IsSVGTypeNeedingTearOff($function->signature->type) and not $implClassName =~ /List$/) {
1628 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($function->signature->type);
1629 $content = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($content)))";
1631 $content = "kit(WTF::getPtr($content))";
1635 if ($raisesExceptions) {
1636 # Differentiated between when the return type is a pointer and
1637 # not for white space issue (ie. Foo *result vs. int result).
1638 if ($returnType =~ /\*$/) {
1639 $content = $returnType . "result = " . $content;
1641 $content = $returnType . " result = " . $content;
1644 push(@functionContent, " $exceptionInit\n");
1645 push(@functionContent, " $content;\n");
1646 push(@functionContent, " $exceptionRaiseOnError\n");
1647 push(@functionContent, " return result;\n");
1649 push(@functionContent, " return $content;\n");
1653 my $conditionalString = GenerateConditionalString($function->signature);
1654 push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
1656 push(@implContent, "$functionSig\n");
1657 push(@implContent, "{\n");
1658 push(@implContent, " $jsContextSetter\n");
1659 push(@implContent, @functionContent);
1660 push(@implContent, "}\n\n");
1662 push(@implContent, "#endif\n\n") if $conditionalString;
1664 # generate the old style method names with un-named parameters, these methods are deprecated
1665 if (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"}) {
1666 my $deprecatedFunctionSig = $functionSig;
1667 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
1669 push(@implContent, "$deprecatedFunctionSig\n");
1670 push(@implContent, "{\n");
1671 push(@implContent, " $jsContextSetter\n");
1672 push(@implContent, @functionContent);
1673 push(@implContent, "}\n\n");
1681 # END implementation
1682 push(@implContent, "\@end\n");
1684 # Generate internal interfaces
1685 push(@implContent, "\n$implType* core($className *wrapper)\n");
1686 push(@implContent, "{\n");
1687 push(@implContent, " return wrapper ? reinterpret_cast<$implType*>(wrapper->_internal) : 0;\n");
1688 push(@implContent, "}\n\n");
1690 if ($parentImplClassName eq "Object") {
1691 push(@implContent, "$className *kit($implType* value)\n");
1692 push(@implContent, "{\n");
1693 push(@implContent, " $assertMainThread;\n");
1694 push(@implContent, " if (!value)\n");
1695 push(@implContent, " return nil;\n");
1696 push(@implContent, " if ($className *wrapper = getDOMWrapper(value))\n");
1697 push(@implContent, " return [[wrapper retain] autorelease];\n");
1698 if ($dataNode->extendedAttributes->{Polymorphic}) {
1699 push(@implContent, " $className *wrapper = [[kitClass(value) alloc] _init];\n");
1700 push(@implContent, " if (!wrapper)\n");
1701 push(@implContent, " return nil;\n");
1703 push(@implContent, " $className *wrapper = [[$className alloc] _init];\n");
1705 push(@implContent, " wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(value);\n");
1706 push(@implContent, " value->ref();\n");
1707 push(@implContent, " addDOMWrapper(wrapper, value);\n");
1708 push(@implContent, " return [wrapper autorelease];\n");
1709 push(@implContent, "}\n");
1711 push(@implContent, "$className *kit($implType* value)\n");
1712 push(@implContent, "{\n");
1713 push(@implContent, " $assertMainThread;\n");
1714 push(@implContent, " return static_cast<$className*>(kit(static_cast<WebCore::$baseClass*>(value)));\n");
1715 push(@implContent, "}\n");
1718 # - End the ifdef conditional if necessary
1719 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
1721 # - Generate dependencies.
1722 if ($writeDependencies && @ancestorInterfaceNames) {
1723 push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n");
1724 push(@depsContent, map { "$_.idl :\n" } @ancestorInterfaceNames);
1734 # Open files for writing...
1735 my $headerFileName = "$outputDir/" . $name . ".h";
1736 my $privateHeaderFileName = "$outputDir/" . $name . "Private.h";
1737 my $implFileName = "$outputDir/" . $name . ".mm";
1738 my $internalHeaderFileName = "$outputDir/" . $name . "Internal.h";
1739 my $depsFileName = "$outputDir/" . $name . ".dep";
1742 unlink($headerFileName);
1743 unlink($privateHeaderFileName);
1744 unlink($implFileName);
1745 unlink($internalHeaderFileName);
1746 unlink($depsFileName);
1748 # Write public header.
1749 open(HEADER, ">$headerFileName") or die "Couldn't open file $headerFileName";
1751 print HEADER @headerContentHeader;
1752 print HEADER map { "\@class $_;\n" } sort keys(%headerForwardDeclarations);
1753 print HEADER map { "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
1755 my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols);
1756 print HEADER "\n" if $hasForwardDeclarations;
1757 print HEADER @headerContent;
1761 @headerContentHeader = ();
1762 @headerContent = ();
1763 %headerForwardDeclarations = ();
1764 %headerForwardDeclarationsForProtocols = ();
1766 if (@privateHeaderContent > 0) {
1767 open(PRIVATE_HEADER, ">$privateHeaderFileName") or die "Couldn't open file $privateHeaderFileName";
1769 print PRIVATE_HEADER @privateHeaderContentHeader;
1770 print PRIVATE_HEADER map { "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
1771 print PRIVATE_HEADER map { "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
1773 $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols);
1774 print PRIVATE_HEADER "\n" if $hasForwardDeclarations;
1775 print PRIVATE_HEADER @privateHeaderContent;
1777 close(PRIVATE_HEADER);
1779 @privateHeaderContentHeader = ();
1780 @privateHeaderContent = ();
1781 %privateHeaderForwardDeclarations = ();
1782 %privateHeaderForwardDeclarationsForProtocols = ();
1785 # Write implementation file.
1787 open(IMPL, ">$implFileName") or die "Couldn't open file $implFileName";
1789 print IMPL @implContentHeader;
1790 print IMPL map { "#import \"$_\"\n" } sort keys(%implIncludes);
1791 print IMPL @implContent;
1795 @implContentHeader = ();
1800 if (@internalHeaderContent > 0) {
1801 open(INTERNAL_HEADER, ">$internalHeaderFileName") or die "Couldn't open file $internalHeaderFileName";
1803 print INTERNAL_HEADER @internalHeaderContent;
1805 close(INTERNAL_HEADER);
1807 @internalHeaderContent = ();
1810 # Write dependency file.
1812 open(DEPS, ">$depsFileName") or die "Couldn't open file $depsFileName";
1813 print DEPS @depsContent;