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;
29 use constant FileNamePrefix => "DOM";
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 "SVGFilterPrimitiveStandardAttributes" => 1,
59 "SVGTests" => 1, "SVGLangSpace" => 1, "SVGExternalResourcesRequired" => 1, "SVGURIReference" => 1,
60 "SVGZoomAndPan" => 1, "SVGFitToViewBox" => 1, "SVGAnimatedPathData" => 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 $nullableInit = "bool isNull = false;";
80 my $exceptionInit = "WebCore::ExceptionCode ec = 0;";
81 my $jsContextSetter = "WebCore::JSMainThreadNullState state;";
82 my $exceptionRaiseOnError = "WebCore::raiseOnDOMError(ec);";
83 my $assertMainThread = "{ DOM_ASSERT_MAIN_THREAD(); WebCoreThreadViolationCheckRoundOne(); }";
85 my %conflictMethod = (
86 # FIXME: Add C language keywords?
87 # FIXME: Add other predefined types like "id"?
89 "callWebScriptMethod:withArguments:" => "WebScriptObject",
90 "evaluateWebScript:" => "WebScriptObject",
91 "removeWebScriptKey:" => "WebScriptObject",
92 "setException:" => "WebScriptObject",
93 "setWebScriptValueAtIndex:value:" => "WebScriptObject",
94 "stringRepresentation" => "WebScriptObject",
95 "webScriptValueAtIndex:" => "WebScriptObject",
97 "autorelease" => "NSObject",
98 "awakeAfterUsingCoder:" => "NSObject",
99 "class" => "NSObject",
100 "classForCoder" => "NSObject",
101 "conformsToProtocol:" => "NSObject",
102 "copy" => "NSObject",
103 "copyWithZone:" => "NSObject",
104 "dealloc" => "NSObject",
105 "description" => "NSObject",
106 "doesNotRecognizeSelector:" => "NSObject",
107 "encodeWithCoder:" => "NSObject",
108 "finalize" => "NSObject",
109 "forwardInvocation:" => "NSObject",
110 "hash" => "NSObject",
111 "init" => "NSObject",
112 "initWithCoder:" => "NSObject",
113 "isEqual:" => "NSObject",
114 "isKindOfClass:" => "NSObject",
115 "isMemberOfClass:" => "NSObject",
116 "isProxy" => "NSObject",
117 "methodForSelector:" => "NSObject",
118 "methodSignatureForSelector:" => "NSObject",
119 "mutableCopy" => "NSObject",
120 "mutableCopyWithZone:" => "NSObject",
121 "performSelector:" => "NSObject",
122 "release" => "NSObject",
123 "replacementObjectForCoder:" => "NSObject",
124 "respondsToSelector:" => "NSObject",
125 "retain" => "NSObject",
126 "retainCount" => "NSObject",
127 "self" => "NSObject",
128 "superclass" => "NSObject",
129 "zone" => "NSObject",
134 # Default License Templates
135 my $headerLicenseTemplate = << "EOF";
137 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
138 * Copyright (C) 2006 Samuel Weinig <sam.weinig\@gmail.com>
140 * Redistribution and use in source and binary forms, with or without
141 * modification, are permitted provided that the following conditions
143 * 1. Redistributions of source code must retain the above copyright
144 * notice, this list of conditions and the following disclaimer.
145 * 2. Redistributions in binary form must reproduce the above copyright
146 * notice, this list of conditions and the following disclaimer in the
147 * documentation and/or other materials provided with the distribution.
149 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
150 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
151 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
152 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
153 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
154 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
155 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
156 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
157 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
158 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
159 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
163 my $implementationLicenseTemplate = << "EOF";
165 * This file is part of the WebKit open source project.
166 * This file has been generated by generate-bindings.pl. DO NOT MODIFY!
168 * Redistribution and use in source and binary forms, with or without
169 * modification, are permitted provided that the following conditions
171 * 1. Redistributions of source code must retain the above copyright
172 * notice, this list of conditions and the following disclaimer.
173 * 2. Redistributions in binary form must reproduce the above copyright
174 * notice, this list of conditions and the following disclaimer in the
175 * documentation and/or other materials provided with the distribution.
177 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
178 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
180 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
181 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
182 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
183 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
184 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
185 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
186 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
187 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
191 # Default constructor
197 $codeGenerator = shift;
198 shift; # $useLayerOnTop
199 shift; # $preprocessor
200 $writeDependencies = shift;
202 bless($reference, $object);
206 sub ReadPublicInterfaces
209 my $superClass = shift;
211 my $isProtocol = shift;
214 my $actualSuperClass;
215 %publicInterfaces = ();
217 my $fileName = "WebCore/bindings/objc/PublicDOMInterfaces.h";
218 my $gccLocation = "";
220 $gccLocation = $ENV{CC};
221 } elsif (($Config::Config{'osname'}) =~ /solaris/i) {
222 $gccLocation = "/usr/sfw/bin/gcc";
223 } elsif (-x "/usr/bin/clang") {
224 $gccLocation = "/usr/bin/clang";
226 $gccLocation = "/usr/bin/gcc";
228 open FILE, "-|", $gccLocation, "-E", "-P", "-x", "objective-c",
229 (map { "-D$_" } split(/ +/, $defines)), "-DOBJC_CODE_GENERATION", $fileName or die "Could not open $fileName";
230 my @documentContent = <FILE>;
233 foreach $line (@documentContent) {
234 if (!$isProtocol && $line =~ /^\s*\@interface\s*$class\s*:\s*(\w+)\s*([A-Z0-9_]*)/) {
235 if ($superClass ne $1) {
236 warn "Public API change. Superclass for \"$class\" differs ($1 != $superClass)";
240 $interfaceAvailabilityVersion = $2 if defined $2;
243 } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*<[^>]+>\s*([A-Z0-9_]*)/) {
244 $interfaceAvailabilityVersion = $1 if defined $1;
249 last if $found and $line =~ /^\s?\@end\s?$/;
256 my $availabilityMacro = "";
257 $line =~ s/\s([A-Z0-9_]+)\s*;$/;/;
258 $availabilityMacro = $1 if defined $1;
260 $publicInterfaces{$line} = $availabilityMacro if length $line;
264 # If this class was not found in PublicDOMInterfaces.h then it should be considered as an entirely new public class.
265 $newPublicClass = !$found;
266 $interfaceAvailabilityVersion = "WEBKIT_VERSION_LATEST" if $newPublicClass;
269 sub GenerateInterface
272 my $interface = shift;
277 my $name = $interface->name;
278 my $className = GetClassName($name);
279 my $parentClassName = "DOM" . GetParentImplClassName($interface);
280 $isProtocol = $interface->extendedAttributes->{ObjCProtocol};
281 $noImpl = $interface->extendedAttributes->{ObjCCustomImplementation} || $isProtocol;
283 ReadPublicInterfaces($className, $parentClassName, $defines, $isProtocol);
285 # Start actual generation..
286 $object->GenerateHeader($interface);
287 $object->GenerateImplementation($interface) unless $noImpl;
289 # Check for missing public API
290 if (keys %publicInterfaces > 0) {
291 my $missing = join("\n", keys %publicInterfaces);
292 warn "Public API change. There are missing public properties and/or methods from the \"$className\" class.\n$missing\n";
304 return "NSString" if $codeGenerator->IsStringType($name) or $name eq "SerializedScriptValue";
305 return "NS$name" if IsNativeObjCType($name);
306 return "BOOL" if $name eq "boolean";
307 return "unsigned char" if $name eq "octet";
308 return "char" if $name eq "byte";
309 return "unsigned" if $name eq "unsigned long";
310 return "int" if $name eq "long";
311 return "NSTimeInterval" if $name eq "Date";
312 return "DOMAbstractView" if $name eq "DOMWindow";
313 return $name if $codeGenerator->IsPrimitiveType($name) or $name eq "DOMImplementation" or $name eq "DOMTimeStamp";
315 # Default, assume Objective-C type has the same type name as
316 # idl type prefixed with "DOM".
320 sub GetClassHeaderName
324 return "DOMDOMImplementation" if $name eq "DOMImplementation";
332 return "DOMImplementationFront" if $name eq "DOMImplementation";
333 return "DOMWindow" if $name eq "AbstractView";
337 sub GetParentImplClassName
339 my $interface = shift;
341 return "Object" if @{$interface->parents} eq 0;
343 my $parent = $interface->parents(0);
346 return "Object" if $parent eq "HTMLCollection";
351 sub GetParentAndProtocols
353 my $interface = shift;
354 my $numParents = @{$interface->parents};
358 if ($numParents eq 0) {
360 push(@protocols, "NSObject");
361 push(@protocols, "NSCopying") if $interface->name eq "EventTarget";
363 $parent = "DOMObject";
365 } elsif ($numParents eq 1) {
366 my $parentName = $interface->parents(0);
368 die "Parents of protocols must also be protocols." unless IsProtocolType($parentName);
369 push(@protocols, "DOM" . $parentName);
371 if (IsProtocolType($parentName)) {
372 push(@protocols, "DOM" . $parentName);
373 } elsif ($parentName eq "HTMLCollection") {
374 $parent = "DOMObject";
376 $parent = "DOM" . $parentName;
380 my @parents = @{$interface->parents};
381 my $firstParent = shift(@parents);
382 if (IsProtocolType($firstParent)) {
383 push(@protocols, "DOM" . $firstParent);
385 $parent = "DOMObject";
388 $parent = "DOM" . $firstParent;
391 foreach my $parentName (@parents) {
392 die "Everything past the first class should be a protocol!" unless IsProtocolType($parentName);
394 push(@protocols, "DOM" . $parentName);
398 return ($parent, @protocols);
405 return $parent if $parent eq "Object" or IsBaseType($parent);
406 return "Event" if $parent eq "UIEvent" or $parent eq "MouseEvent";
407 return "CSSValue" if $parent eq "SVGColor" or $parent eq "CSSValueList";
415 return 1 if $baseTypeHash{$type};
423 return 1 if $protocolTypeHash{$type};
431 return 1 if $nativeObjCTypeHash{$type};
437 my $function = shift;
439 return 1 if $codeGenerator->GetSequenceType($function->signature->type);
440 return 1 if $codeGenerator->GetArrayType($function->signature->type);
442 foreach my $param (@{$function->parameters}) {
443 return 1 if $codeGenerator->GetSequenceType($param->type);
444 return 1 if $codeGenerator->GetArrayType($param->type);
445 return 1 if $param->extendedAttributes->{"Clamp"};
453 my $attribute = shift;
454 my $type = $attribute->signature->type;
456 $codeGenerator->AssertNotSequenceType($type);
457 return 1 if $codeGenerator->GetArrayType($type);
458 return 1 if $codeGenerator->IsTypedArrayType($type);
459 return 1 if $codeGenerator->IsEnumType($type);
460 return 1 if $attribute->isStatic;
462 # This is for DynamicsCompressorNode.idl
463 if ($attribute->signature->name eq "release") {
474 my $name = GetClassName($type);
476 return "id <$name>" if IsProtocolType($type);
477 return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
478 return "unsigned short" if $type eq "CompareHow";
482 sub GetPropertyAttributes
485 my $readOnly = shift;
489 push(@attributes, "readonly") if $readOnly;
491 # FIXME: <rdar://problem/5049934> Consider using 'nonatomic' on the DOM @property declarations.
492 if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) {
493 push(@attributes, "copy");
494 } elsif ($codeGenerator->IsSVGAnimatedType($type)) {
495 push(@attributes, "retain");
496 } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow") {
497 push(@attributes, "retain");
500 return "" unless @attributes > 0;
501 return "(" . join(", ", @attributes) . ")";
508 return !$codeGenerator->IsNonPointerType($type) && !$codeGenerator->IsStringType($type) && !IsNativeObjCType($type);
511 sub GetObjCTypeGetter
516 return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
517 return $argName . "Node" if $type eq "EventTarget";
518 return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow";
519 return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener";
520 return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter";
521 return "WTF::getPtr(nativeResolver)" if $type eq "XPathNSResolver";
523 if ($type eq "SerializedScriptValue") {
524 $implIncludes{"SerializedScriptValue.h"} = 1;
525 return "WebCore::SerializedScriptValue::create(WTF::String($argName))";
527 return "core($argName)";
530 sub AddForwardDeclarationsForType
535 return if $codeGenerator->IsNonPointerType($type);
536 return if $codeGenerator->GetSequenceType($type);
537 return if $codeGenerator->GetArrayType($type);
539 my $class = GetClassName($type);
541 if (IsProtocolType($type)) {
542 $headerForwardDeclarationsForProtocols{$class} = 1 if $public;
543 $privateHeaderForwardDeclarationsForProtocols{$class} = 1 if !$public and !$headerForwardDeclarationsForProtocols{$class};
547 $headerForwardDeclarations{$class} = 1 if $public;
549 # Private headers include the public header, so only add a forward declaration to the private header
550 # if the public header does not already have the same forward declaration.
551 $privateHeaderForwardDeclarations{$class} = 1 if !$public and !$headerForwardDeclarations{$class};
554 sub AddIncludesForType
558 return if $codeGenerator->IsNonPointerType($type);
559 return if $codeGenerator->GetSequenceType($type);
560 return if $codeGenerator->GetArrayType($type);
562 if (IsNativeObjCType($type)) {
563 if ($type eq "Color") {
564 $implIncludes{"ColorMac.h"} = 1;
569 if ($codeGenerator->IsStringType($type)) {
570 $implIncludes{"KURL.h"} = 1;
574 if ($type eq "DOMWindow") {
575 $implIncludes{"DOMAbstractViewInternal.h"} = 1;
576 $implIncludes{"DOMWindow.h"} = 1;
580 if ($type eq "DOMImplementation") {
581 $implIncludes{"DOMDOMImplementationInternal.h"} = 1;
582 $implIncludes{"DOMImplementationFront.h"} = 1;
586 if ($type eq "EventTarget") {
587 $implIncludes{"Node.h"} = 1;
588 $implIncludes{"DOMEventTarget.h"} = 1;
592 if ($codeGenerator->IsSVGAnimatedType($type)) {
593 $implIncludes{"${type}.h"} = 1;
594 $implIncludes{"DOM${type}Internal.h"} = 1;
598 if ($type =~ /(\w+)(Abs|Rel)$/) {
599 $implIncludes{"$1.h"} = 1;
600 $implIncludes{"DOM${type}Internal.h"} = 1;
604 if ($type eq "NodeFilter") {
605 $implIncludes{"NodeFilter.h"} = 1;
606 $implIncludes{"ObjCNodeFilterCondition.h"} = 1;
610 if ($type eq "EventListener") {
611 $implIncludes{"EventListener.h"} = 1;
612 $implIncludes{"ObjCEventListener.h"} = 1;
616 if ($type eq "XPathNSResolver") {
617 $implIncludes{"DOMCustomXPathNSResolver.h"} = 1;
618 $implIncludes{"XPathNSResolver.h"} = 1;
622 if ($type eq "SerializedScriptValue") {
623 $implIncludes{"SerializedScriptValue.h"} = 1;
627 # FIXME: won't compile without these
628 $implIncludes{"CSSImportRule.h"} = 1 if $type eq "CSSRule";
629 $implIncludes{"StylePropertySet.h"} = 1 if $type eq "CSSStyleDeclaration";
630 $implIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList";
632 # Default, include the same named file (the implementation) and the same name prefixed with "DOM".
633 $implIncludes{"$type.h"} = 1 if not $codeGenerator->SkipIncludeHeader($type);
634 $implIncludes{"DOM${type}Internal.h"} = 1;
637 sub GetSVGTypeWithNamespace
640 my $typeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($type);
642 # Special case for DOMSVGNumber
643 $typeWithNamespace =~ s/</\<WebCore::/ unless $type eq "SVGNumber";
644 return $typeWithNamespace;
647 sub GetSVGPropertyTypes
649 my $implType = shift;
652 my $svgListPropertyType;
655 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $implType =~ /SVG/;
657 $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($implType);
658 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType;
660 # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType>
661 $svgNativeType = "WebCore::$svgNativeType ";
662 $svgNativeType =~ s/</\<WebCore::/ if not $svgNativeType =~ /float/;
664 my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implType);
665 if ($svgNativeType =~ /SVGPropertyTearOff/) {
666 if ($svgWrappedNativeType eq "float") {
667 # Special case for DOMSVGNumber
668 $svgPropertyType = $svgWrappedNativeType;
670 $svgPropertyType = "WebCore::$svgWrappedNativeType";
671 $svgPropertyType =~ s/</\<WebCore::/;
673 } elsif ($svgNativeType =~ /SVGListPropertyTearOff/ or $svgNativeType =~ /SVGStaticListPropertyTearOff/) {
674 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
675 $svgListPropertyType =~ s/</\<WebCore::/;
676 } elsif ($svgNativeType =~ /SVGTransformListPropertyTearOff/) {
677 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
678 $svgListPropertyType =~ s/</\<WebCore::/;
679 } elsif ($svgNativeType =~ /SVGPathSegListPropertyTearOff/) {
680 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
681 $svgListPropertyType =~ s/</\<WebCore::/;
684 return ($svgPropertyType, $svgListPropertyType, $svgNativeType);
690 my $interface = shift;
692 my $interfaceName = $interface->name;
693 my $className = GetClassName($interfaceName);
696 my @protocolsToImplement = ();
697 ($parentName, @protocolsToImplement) = GetParentAndProtocols($interface);
699 my $numConstants = @{$interface->constants};
700 my $numAttributes = @{$interface->attributes};
701 my $numFunctions = @{$interface->functions};
703 # - Add default header template
704 @headerContentHeader = split("\r", $headerLicenseTemplate);
705 push(@headerContentHeader, "\n");
708 my $includedWebKitAvailabilityHeader = 0;
709 unless ($isProtocol) {
710 my $parentHeaderName = GetClassHeaderName($parentName);
711 push(@headerContentHeader, "#import <WebCore/$parentHeaderName.h>\n");
712 $includedWebKitAvailabilityHeader = 1;
715 foreach my $parentProtocol (@protocolsToImplement) {
716 next if $parentProtocol =~ /^NS/;
717 $parentProtocol = GetClassHeaderName($parentProtocol);
718 push(@headerContentHeader, "#import <WebCore/$parentProtocol.h>\n");
719 $includedWebKitAvailabilityHeader = 1;
722 # Special case needed for legacy support of DOMRange
723 if ($interfaceName eq "Range") {
724 push(@headerContentHeader, "#import <WebCore/DOMCore.h>\n");
725 push(@headerContentHeader, "#import <WebCore/DOMDocument.h>\n");
726 push(@headerContentHeader, "#import <WebCore/DOMRangeException.h>\n");
727 $includedWebKitAvailabilityHeader = 1;
730 push(@headerContentHeader, "#import <JavaScriptCore/WebKitAvailability.h>\n") unless $includedWebKitAvailabilityHeader;
732 my $interfaceAvailabilityVersionCheck = "#if WEBKIT_VERSION_MAX_ALLOWED >= $interfaceAvailabilityVersion\n\n";
734 push(@headerContentHeader, "\n");
735 push(@headerContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
738 if ($numConstants > 0) {
739 my @headerConstants = ();
740 my @constants = @{$interface->constants};
741 my $combinedConstants = "";
743 # FIXME: we need a way to include multiple enums.
744 foreach my $constant (@constants) {
745 my $constantName = $constant->name;
746 my $constantValue = $constant->value;
747 my $conditional = $constant->extendedAttributes->{"Conditional"};
748 my $notLast = $constant ne $constants[-1];
751 my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional);
752 $combinedConstants .= "#if ${conditionalString}\n";
754 $combinedConstants .= " DOM_$constantName = $constantValue";
755 $combinedConstants .= "," if $notLast;
757 $combinedConstants .= "\n#endif\n";
759 $combinedConstants .= "\n";
763 # FIXME: the formatting of the enums should line up the equal signs.
764 # FIXME: enums are unconditionally placed in the public header.
765 push(@headerContent, "enum {\n");
766 push(@headerContent, $combinedConstants);
767 push(@headerContent, "\n};\n\n");
770 # - Begin @interface or @protocol
771 my $interfaceDeclaration = ($isProtocol ? "\@protocol $className" : "\@interface $className : $parentName");
772 $interfaceDeclaration .= " <" . join(", ", @protocolsToImplement) . ">" if @protocolsToImplement > 0;
773 $interfaceDeclaration .= "\n";
775 push(@headerContent, $interfaceDeclaration);
777 my @headerAttributes = ();
778 my @privateHeaderAttributes = ();
780 # - Add attribute getters/setters.
781 if ($numAttributes > 0) {
782 foreach my $attribute (@{$interface->attributes}) {
783 next if SkipAttribute($attribute);
784 my $attributeName = $attribute->signature->name;
786 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
787 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
788 $attributeName .= "Name";
789 } elsif ($attributeName eq "frame") {
790 # Special case attribute frame to be frameBorders.
791 $attributeName .= "Borders";
794 my $attributeType = GetObjCType($attribute->signature->type);
795 my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attribute->isReadOnly);
796 # Some SVGFE*Element.idl use 'operator' as attribute name, rewrite as '_operator' to avoid clashes with C/C++
797 $attributeName =~ s/operator/_operator/ if ($attributeName =~ /operator/);
798 $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName;
800 my $publicInterfaceKey = $property . ";";
802 my $availabilityMacro = "";
803 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
804 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
807 my $declarationSuffix = ";\n";
808 $declarationSuffix = " $availabilityMacro;\n" if length $availabilityMacro;
810 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
811 delete $publicInterfaces{$publicInterfaceKey};
813 AddForwardDeclarationsForType($attribute->signature->type, $public);
815 my $setterName = "set" . ucfirst($attributeName) . ":";
817 my $conflict = $conflictMethod{$attributeName};
819 warn "$className conflicts with $conflict method $attributeName\n";
823 $conflict = $conflictMethod{$setterName};
825 warn "$className conflicts with $conflict method $setterName\n";
829 $property .= $declarationSuffix;
830 push(@headerAttributes, $property) if $public;
831 push(@privateHeaderAttributes, $property) unless $public;
834 push(@headerContent, @headerAttributes) if @headerAttributes > 0;
837 my @headerFunctions = ();
838 my @privateHeaderFunctions = ();
839 my @deprecatedHeaderFunctions = ();
842 if ($numFunctions > 0) {
843 foreach my $function (@{$interface->functions}) {
844 next if SkipFunction($function);
845 next if ($function->signature->name eq "set" and $interface->extendedAttributes->{"TypedArray"});
846 my $functionName = $function->signature->name;
848 my $returnType = GetObjCType($function->signature->type);
849 my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"ObjCLegacyUnnamedParameters"});
850 my $numberOfParameters = @{$function->parameters};
851 my %typesToForwardDeclare = ($function->signature->type => 1);
853 my $parameterIndex = 0;
854 my $functionSig = "- ($returnType)$functionName";
855 my $methodName = $functionName;
856 foreach my $param (@{$function->parameters}) {
857 my $paramName = $param->name;
858 my $paramType = GetObjCType($param->type);
860 $typesToForwardDeclare{$param->type} = 1;
862 if ($parameterIndex >= 1) {
863 $functionSig .= " $paramName";
864 $methodName .= $paramName;
867 $functionSig .= ":($paramType)$paramName";
873 my $publicInterfaceKey = $functionSig . ";";
875 my $conflict = $conflictMethod{$methodName};
877 warn "$className conflicts with $conflict method $methodName\n";
881 if ($isProtocol && !$newPublicClass && !defined $publicInterfaces{$publicInterfaceKey}) {
882 warn "Protocol method $publicInterfaceKey is not in PublicDOMInterfaces.h. Protocols require all methods to be public";
886 my $availabilityMacro = "";
887 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
888 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
891 my $functionDeclaration = $functionSig;
892 $functionDeclaration .= " " . $availabilityMacro if length $availabilityMacro;
893 $functionDeclaration .= ";\n";
895 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
896 delete $publicInterfaces{$publicInterfaceKey};
898 foreach my $type (keys %typesToForwardDeclare) {
899 # add any forward declarations to the public header if a deprecated version will be generated
900 AddForwardDeclarationsForType($type, 1) if $needsDeprecatedVersion;
901 AddForwardDeclarationsForType($type, $public) unless $public and $needsDeprecatedVersion;
904 my $functionConditionalString = $codeGenerator->GenerateConditionalString($function->signature);
905 if ($functionConditionalString) {
906 push(@headerFunctions, "#if ${functionConditionalString}\n") if $public;
907 push(@privateHeaderFunctions, "#if ${functionConditionalString}\n") unless $public;
908 push(@deprecatedHeaderFunctions, "#if ${functionConditionalString}\n") if $needsDeprecatedVersion;
911 push(@headerFunctions, $functionDeclaration) if $public;
912 push(@privateHeaderFunctions, $functionDeclaration) unless $public;
914 # generate the old style method names with un-named parameters, these methods are deprecated
915 if ($needsDeprecatedVersion) {
916 my $deprecatedFunctionSig = $functionSig;
917 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
919 $publicInterfaceKey = $deprecatedFunctionSig . ";";
921 my $availabilityMacro = "AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0";
922 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
923 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
926 $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
928 push(@deprecatedHeaderFunctions, $functionDeclaration);
930 unless (defined $publicInterfaces{$publicInterfaceKey}) {
931 warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the ObjCLegacyUnnamedParameters IDL attribute removed";
935 delete $publicInterfaces{$publicInterfaceKey};
938 if ($functionConditionalString) {
939 push(@headerFunctions, "#endif\n") if $public;
940 push(@privateHeaderFunctions, "#endif\n") unless $public;
941 push(@deprecatedHeaderFunctions, "#endif\n") if $needsDeprecatedVersion;
945 if (@headerFunctions > 0) {
946 push(@headerContent, "\n") if @headerAttributes > 0;
947 push(@headerContent, @headerFunctions);
951 if (@deprecatedHeaderFunctions > 0 && $isProtocol) {
952 push(@headerContent, @deprecatedHeaderFunctions);
955 # - End @interface or @protocol
956 push(@headerContent, "\@end\n");
958 if (@deprecatedHeaderFunctions > 0 && !$isProtocol) {
959 # - Deprecated category @interface
960 push(@headerContent, "\n\@interface $className (" . $className . "Deprecated)\n");
961 push(@headerContent, @deprecatedHeaderFunctions);
962 push(@headerContent, "\@end\n");
965 push(@headerContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
967 my %alwaysGenerateForNoSVGBuild = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement);
969 if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0 or exists $alwaysGenerateForNoSVGBuild{$className}) {
970 # - Private category @interface
971 @privateHeaderContentHeader = split("\r", $headerLicenseTemplate);
972 push(@privateHeaderContentHeader, "\n");
974 my $classHeaderName = GetClassHeaderName($className);
975 push(@privateHeaderContentHeader, "#import <WebCore/$classHeaderName.h>\n\n");
976 push(@privateHeaderContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
978 @privateHeaderContent = ();
979 push(@privateHeaderContent, "\@interface $className (" . $className . "Private)\n");
980 push(@privateHeaderContent, @privateHeaderAttributes) if @privateHeaderAttributes > 0;
981 push(@privateHeaderContent, "\n") if @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0;
982 push(@privateHeaderContent, @privateHeaderFunctions) if @privateHeaderFunctions > 0;
983 push(@privateHeaderContent, "\@end\n");
985 push(@privateHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
988 unless ($isProtocol) {
989 # Generate internal interfaces
990 my $implClassName = GetImplClassName($interfaceName);
991 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
993 my $implType = $implClassNameWithNamespace;
994 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
995 $implType = $svgNativeType if $svgNativeType;
997 # Generate interface definitions.
998 @internalHeaderContent = split("\r", $implementationLicenseTemplate);
1000 push(@internalHeaderContent, "\n#import <WebCore/$className.h>\n\n");
1001 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedPropertyTearOff.h>\n\n") if $svgPropertyType;
1002 if ($svgListPropertyType) {
1003 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedListPropertyTearOff.h>\n\n");
1004 push(@internalHeaderContent, "#import <WebCore/SVGTransformListPropertyTearOff.h>\n\n") if $svgListPropertyType =~ /SVGTransformList/;
1005 push(@internalHeaderContent, "#import <WebCore/SVGPathSegListPropertyTearOff.h>\n\n") if $svgListPropertyType =~ /SVGPathSegList/;
1007 push(@internalHeaderContent, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
1009 if ($interfaceName eq "Node") {
1010 push(@internalHeaderContent, "\@protocol DOMEventTarget;\n\n");
1013 my $startedNamespace = 0;
1015 if ($codeGenerator->IsSVGAnimatedType($interfaceName)) {
1016 push(@internalHeaderContent, "#import <WebCore/$implClassName.h>\n\n");
1018 push(@internalHeaderContent, "namespace WebCore {\n");
1019 $startedNamespace = 1;
1020 if ($interfaceName eq "Node") {
1021 push(@internalHeaderContent, "class EventTarget;\n class Node;\n");
1023 push(@internalHeaderContent, "class $implClassName;\n");
1025 push(@internalHeaderContent, "}\n\n");
1028 push(@internalHeaderContent, "$implType* core($className *);\n");
1029 push(@internalHeaderContent, "$className *kit($implType*);\n");
1031 if ($interface->extendedAttributes->{"ObjCPolymorphic"}) {
1032 push(@internalHeaderContent, "Class kitClass($implType*);\n");
1035 if ($interfaceName eq "Node") {
1036 push(@internalHeaderContent, "id <DOMEventTarget> kit(WebCore::EventTarget*);\n");
1039 push(@internalHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
1043 sub GenerateImplementation
1046 my $interface = shift;
1048 my @ancestorInterfaceNames = ();
1050 if (@{$interface->parents} > 1) {
1051 $codeGenerator->AddMethodsConstantsAndAttributesFromParentInterfaces($interface, \@ancestorInterfaceNames);
1054 my $interfaceName = $interface->name;
1055 my $className = GetClassName($interfaceName);
1056 my $implClassName = GetImplClassName($interfaceName);
1057 my $parentImplClassName = GetParentImplClassName($interface);
1058 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
1059 my $baseClass = GetBaseClass($parentImplClassName);
1060 my $classHeaderName = GetClassHeaderName($className);
1062 my $numAttributes = @{$interface->attributes};
1063 my $numFunctions = @{$interface->functions};
1064 my $implType = $implClassNameWithNamespace;
1066 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
1067 $implType = $svgNativeType if $svgNativeType;
1069 # - Add default header template.
1070 @implContentHeader = split("\r", $implementationLicenseTemplate);
1073 push(@implContentHeader, "\n#import \"config.h\"\n");
1075 my $conditionalString = $codeGenerator->GenerateConditionalString($interface);
1076 push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString;
1078 push(@implContentHeader, "#import \"DOMInternal.h\"\n\n");
1079 push(@implContentHeader, "#import \"$classHeaderName.h\"\n\n");
1081 $implIncludes{"ExceptionHandlers.h"} = 1;
1082 $implIncludes{"ThreadCheck.h"} = 1;
1083 $implIncludes{"JSMainThreadExecState.h"} = 1;
1084 $implIncludes{"WebScriptObjectPrivate.h"} = 1;
1085 $implIncludes{$classHeaderName . "Internal.h"} = 1;
1087 # FIXME: These includes are only needed when the class is a subclass of one of these polymorphic classes.
1088 $implIncludes{"DOMBlobInternal.h"} = 1;
1089 $implIncludes{"DOMCSSRuleInternal.h"} = 1;
1090 $implIncludes{"DOMCSSValueInternal.h"} = 1;
1091 $implIncludes{"DOMEventInternal.h"} = 1;
1092 $implIncludes{"DOMNodeInternal.h"} = 1;
1093 $implIncludes{"DOMStyleSheetInternal.h"} = 1;
1095 $implIncludes{"DOMSVGPathSegInternal.h"} = 1 if $interfaceName =~ /^SVGPathSeg.+/;
1097 if ($interfaceName =~ /(\w+)(Abs|Rel)$/) {
1098 $implIncludes{"$1.h"} = 1;
1100 if (!$codeGenerator->SkipIncludeHeader($implClassName)) {
1101 $implIncludes{"$implClassName.h"} = 1 ;
1102 } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($implClassName)) {
1103 my $includeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implClassName);
1104 $implIncludes{"${includeType}.h"} = 1;
1110 push(@implContent, "#import <wtf/GetPtr.h>\n\n");
1112 # add implementation accessor
1113 if ($parentImplClassName eq "Object") {
1114 push(@implContent, "#define IMPL reinterpret_cast<$implType*>(_internal)\n\n");
1116 my $baseClassWithNamespace = "WebCore::$baseClass";
1117 push(@implContent, "#define IMPL static_cast<$implClassNameWithNamespace*>(reinterpret_cast<$baseClassWithNamespace*>(_internal))\n\n");
1120 # START implementation
1121 push(@implContent, "\@implementation $className\n\n");
1123 # Only generate 'dealloc' and 'finalize' methods for direct subclasses of DOMObject.
1124 if ($parentImplClassName eq "Object") {
1125 $implIncludes{"WebCoreObjCExtras.h"} = 1;
1126 push(@implContent, "- (void)dealloc\n");
1127 push(@implContent, "{\n");
1128 push(@implContent, " if (WebCoreObjCScheduleDeallocateOnMainThread([$className class], self))\n");
1129 push(@implContent, " return;\n");
1130 push(@implContent, "\n");
1131 if ($interfaceName eq "NodeIterator") {
1132 push(@implContent, " if (_internal) {\n");
1133 push(@implContent, " [self detach];\n");
1134 push(@implContent, " IMPL->deref();\n");
1135 push(@implContent, " };\n");
1137 push(@implContent, " if (_internal)\n");
1138 push(@implContent, " IMPL->deref();\n");
1140 push(@implContent, " [super dealloc];\n");
1141 push(@implContent, "}\n\n");
1143 push(@implContent, "- (void)finalize\n");
1144 push(@implContent, "{\n");
1145 if ($interfaceName eq "NodeIterator") {
1146 push(@implContent, " if (_internal) {\n");
1147 push(@implContent, " [self detach];\n");
1148 push(@implContent, " IMPL->deref();\n");
1149 push(@implContent, " };\n");
1151 push(@implContent, " if (_internal)\n");
1152 push(@implContent, " IMPL->deref();\n");
1154 push(@implContent, " [super finalize];\n");
1155 push(@implContent, "}\n\n");
1159 %attributeNames = ();
1162 if ($numAttributes > 0) {
1163 foreach my $attribute (@{$interface->attributes}) {
1164 next if SkipAttribute($attribute);
1165 AddIncludesForType($attribute->signature->type);
1167 my $idlType = $attribute->signature->type;
1169 my $attributeName = $attribute->signature->name;
1170 my $attributeType = GetObjCType($attribute->signature->type);
1171 my $attributeClassName = GetClassName($attribute->signature->type);
1173 my $attributeInterfaceName = $attributeName;
1174 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
1175 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
1176 $attributeInterfaceName .= "Name";
1177 } elsif ($attributeName eq "frame") {
1178 # Special case attribute frame to be frameBorders.
1179 $attributeInterfaceName .= "Borders";
1180 } elsif ($attributeName eq "operator") {
1181 # Avoid clash with C++ keyword.
1182 $attributeInterfaceName = "_operator";
1185 $attributeNames{$attributeInterfaceName} = 1;
1188 my $getterSig = "- ($attributeType)$attributeInterfaceName\n";
1190 my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute);
1191 my $getterExpressionPrefix = "$functionName(" . join(", ", @arguments);
1193 # FIXME: Special case attribute ownerDocument to call document. This makes it return the
1194 # document when called on the document itself. Legacy behavior, see <https://bugs.webkit.org/show_bug.cgi?id=10889>.
1195 $getterExpressionPrefix =~ s/\bownerDocument\b/document/;
1197 my $hasGetterException = $attribute->signature->extendedAttributes->{"GetterRaisesException"};
1198 my $getterContentHead;
1199 if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {
1200 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};
1201 $implIncludes{"${implementedBy}.h"} = 1;
1202 $getterContentHead = "${implementedBy}::${getterExpressionPrefix}IMPL";
1204 $getterContentHead = "IMPL->$getterExpressionPrefix";
1207 my $getterContentTail = ")";
1209 if ($svgPropertyType) {
1210 $getterContentHead = "$getterExpressionPrefix";
1212 # TODO: Handle special case for DOMSVGLength. We do need Custom code support for this.
1213 if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
1214 $getterContentHead = "value(WebCore::SVGLengthContext(IMPL->contextElement()), ";
1218 my $attributeTypeSansPtr = $attributeType;
1219 $attributeTypeSansPtr =~ s/ \*$//; # Remove trailing " *" from pointer types.
1221 # special case for EventTarget protocol
1222 $attributeTypeSansPtr = "DOMNode" if $idlType eq "EventTarget";
1225 my @customGetterContent = ();
1226 if ($attributeTypeSansPtr eq "DOMImplementation") {
1227 # FIXME: We have to special case DOMImplementation until DOMImplementationFront is removed
1228 $getterContentHead = "kit(implementationFront(IMPL";
1229 $getterContentTail .= ")";
1230 } elsif ($attributeName =~ /(\w+)DisplayString$/) {
1231 my $attributeToDisplay = $1;
1232 $getterContentHead = "WebCore::displayString(IMPL->$attributeToDisplay(), core(self)";
1233 $implIncludes{"HitTestResult.h"} = 1;
1234 } elsif ($attributeName =~ /^absolute(\w+)URL$/) {
1236 $getterContentHead = "[self _getURLAttribute:";
1237 if ($typeOfURL eq "Link") {
1238 $getterContentTail = "\@\"href\"]";
1239 } elsif ($typeOfURL eq "Image") {
1240 if ($interfaceName eq "HTMLObjectElement") {
1241 $getterContentTail = "\@\"data\"]";
1243 $getterContentTail = "\@\"src\"]";
1245 unless ($interfaceName eq "HTMLImageElement") {
1246 push(@customGetterContent, " if (!IMPL->renderer() || !IMPL->renderer()->isImage())\n");
1247 push(@customGetterContent, " return nil;\n");
1248 $implIncludes{"RenderObject.h"} = 1;
1251 $implIncludes{"DOMPrivate.h"} = 1;
1252 } elsif ($attribute->signature->extendedAttributes->{"ObjCImplementedAsUnsignedLong"}) {
1253 $getterContentHead = "WTF::String::number(" . $getterContentHead;
1254 $getterContentTail .= ")";
1255 } elsif ($idlType eq "Date") {
1256 $getterContentHead = "kit($getterContentHead";
1257 $getterContentTail .= ")";
1258 } elsif ($svgPropertyType) {
1259 # Special case for DOMSVGNumber
1260 if ($svgPropertyType eq "float") {
1261 # Intentional leave out closing brace, it's already contained in getterContentTail
1262 $getterContentHead = "IMPL->propertyReference(";
1264 $getterContentHead = "IMPL->propertyReference().$getterContentHead";
1267 if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($idlType) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
1268 my $getter = $getterContentHead;
1269 $getter =~ s/\(\)//;
1271 my $tearOffType = GetSVGTypeWithNamespace($idlType);
1272 my $selfIsTearOffType = $codeGenerator->IsSVGTypeNeedingTearOff($implClassName);
1273 if ($selfIsTearOffType) {
1274 $implIncludes{"SVGStaticPropertyWithParentTearOff.h"} = 1;
1275 $tearOffType =~ s/SVGPropertyTearOff</SVGStaticPropertyWithParentTearOff<$implClassNameWithNamespace, /;
1277 my $getter = $getterExpressionPrefix;
1278 $getter =~ s/IMPL->//;
1280 my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter);
1282 if ($getterContentHead =~ /matrix/ and $implClassName eq "SVGTransform") {
1283 # SVGTransform offers a matrix() method for internal usage that returns an AffineTransform
1284 # and a svgMatrix() method returning a SVGMatrix, used for the bindings.
1285 $getterContentHead =~ s/matrix/svgMatrix/;
1288 $getterContentHead = "${tearOffType}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod)";
1290 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1291 $getterContentTail = "))";
1294 } elsif (($codeGenerator->IsSVGAnimatedType($implClassName) or $implClassName eq "SVGViewSpec") and $codeGenerator->IsSVGTypeNeedingTearOff($idlType)) {
1295 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
1296 $getterContentHead = "kit(static_cast<$idlTypeWithNamespace*>($getterContentHead)";
1297 $getterContentTail .= ")";
1298 } elsif (IsProtocolType($idlType) and $idlType ne "EventTarget") {
1299 $getterContentHead = "kit($getterContentHead";
1300 $getterContentTail .= ")";
1301 } elsif ($idlType eq "Color") {
1302 $getterContentHead = "WebCore::nsColor($getterContentHead";
1303 $getterContentTail .= ")";
1304 } elsif ($attribute->signature->type eq "SerializedScriptValue") {
1305 $getterContentHead = "$getterContentHead";
1306 $getterContentTail .= "->toString()";
1307 } elsif (ConversionNeeded($attribute->signature->type)) {
1308 my $type = $attribute->signature->type;
1309 if ($codeGenerator->IsSVGTypeNeedingTearOff($type) and not $implClassName =~ /List$/) {
1310 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($type);
1311 $implIncludes{"$type.h"} = 1 if not $codeGenerator->SkipIncludeHeader($type);
1312 if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($type) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
1313 $idlTypeWithNamespace =~ s/SVGPropertyTearOff</SVGStaticPropertyTearOff<$implClassNameWithNamespace, /;
1314 $implIncludes{"SVGStaticPropertyTearOff.h"} = 1;
1316 my $getter = $getterContentHead;
1317 $getter =~ s/IMPL->//;
1319 my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter);
1320 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod";
1321 $getterContentTail .= "))";
1322 } elsif ($idlTypeWithNamespace =~ /SVG(Point|PathSeg)List/) {
1323 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1324 $getterContentTail .= "))";
1325 } elsif ($idlTypeWithNamespace =~ /SVGStaticListPropertyTearOff/) {
1326 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead";
1327 $getterContentTail .= ")))";
1329 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($getterContentHead";
1330 $getterContentTail .= ")))";
1333 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1334 $getterContentTail .= "))";
1339 if ($hasGetterException || $attribute->signature->isNullable) {
1340 $getterContent = $getterContentHead;
1341 my $getterWithoutAttributes = $getterContentHead =~ /\($|, $/ ? "ec" : ", ec";
1342 if ($attribute->signature->isNullable) {
1343 $getterContent .= $getterWithoutAttributes ? "isNull" : ", isNull";
1344 $getterWithoutAttributes = 0;
1346 if ($hasGetterException) {
1347 $getterContent .= $getterWithoutAttributes ? "ec" : ", ec";
1349 $getterContent .= $getterContentTail;
1351 $getterContent = $getterContentHead . $getterContentTail;
1354 my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature);
1355 push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString;
1356 push(@implContent, $getterSig);
1357 push(@implContent, "{\n");
1358 push(@implContent, " $jsContextSetter\n");
1359 push(@implContent, @customGetterContent);
1361 # FIXME: Should we return a default value when isNull == true?
1362 if ($attribute->signature->isNullable) {
1363 push(@implContents, " $nullableInit\n");
1366 if ($hasGetterException) {
1367 # Differentiated between when the return type is a pointer and
1368 # not for white space issue (ie. Foo *result vs. int result).
1369 if ($attributeType =~ /\*$/) {
1370 $getterContent = $attributeType . "result = " . $getterContent;
1372 $getterContent = $attributeType . " result = " . $getterContent;
1375 push(@implContent, " $exceptionInit\n");
1376 push(@implContent, " $getterContent;\n");
1377 push(@implContent, " $exceptionRaiseOnError\n");
1378 push(@implContent, " return result;\n");
1380 push(@implContent, " return $getterContent;\n");
1382 push(@implContent, "}\n");
1385 if (!$attribute->isReadOnly) {
1386 # Exception handling
1387 my $hasSetterException = $attribute->signature->extendedAttributes->{"SetterRaisesException"};
1389 my $coreSetterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
1390 my $setterName = "set" . ucfirst($attributeInterfaceName);
1391 my $argName = "new" . ucfirst($attributeInterfaceName);
1392 my $arg = GetObjCTypeGetter($argName, $idlType);
1394 # The definition of ObjCImplementedAsUnsignedLong is flipped for the setter
1395 if ($attribute->signature->extendedAttributes->{"ObjCImplementedAsUnsignedLong"}) {
1396 $arg = "WTF::String($arg).toInt()";
1399 my $setterSig = "- (void)$setterName:($attributeType)$argName\n";
1401 push(@implContent, "\n");
1402 push(@implContent, $setterSig);
1403 push(@implContent, "{\n");
1404 push(@implContent, " $jsContextSetter\n");
1406 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1407 push(@implContent, " ASSERT($argName);\n\n");
1410 if ($idlType eq "Date") {
1411 $arg = "core(" . $arg . ")";
1414 if ($svgPropertyType) {
1415 $implIncludes{"ExceptionCode.h"} = 1;
1416 $getterContentHead = "$getterExpressionPrefix";
1417 push(@implContent, " if (IMPL->isReadOnly()) {\n");
1418 push(@implContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n");
1419 push(@implContent, " return;\n");
1420 push(@implContent, " }\n");
1421 push(@implContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1422 my $ec = $hasSetterException ? ", ec" : "";
1423 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1425 # Special case for DOMSVGNumber
1426 if ($svgPropertyType eq "float") {
1427 push(@implContent, " podImpl = $arg;\n");
1429 # FIXME: Special case for DOMSVGLength. We do need Custom code support for this.
1430 if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
1431 push(@implContent, " podImpl.$coreSetterName($arg, WebCore::SVGLengthContext(IMPL->contextElement())$ec);\n");
1433 push(@implContent, " podImpl.$coreSetterName($arg$ec);\n");
1437 if ($hasSetterException) {
1438 push(@implContent, " if (!ec)\n");
1439 push(@implContent, " IMPL->commitChange();\n");
1440 push(@implContent, " $exceptionRaiseOnError\n");
1442 push(@implContent, " IMPL->commitChange();\n");
1444 } elsif ($svgListPropertyType) {
1445 $getterContentHead = "$getterExpressionPrefix";
1446 push(@implContent, " IMPL->$coreSetterName($arg);\n");
1448 my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute);
1449 push(@arguments, $arg);
1450 push(@arguments, "ec") if $hasSetterException;
1451 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1452 if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {
1453 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};
1454 $implIncludes{"${implementedBy}.h"} = 1;
1455 unshift(@arguments, "IMPL");
1456 $functionName = "${implementedBy}::${functionName}";
1458 $functionName = "IMPL->${functionName}";
1460 push(@implContent, " ${functionName}(" . join(", ", @arguments) . ");\n");
1461 push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException;
1464 push(@implContent, "}\n");
1467 push(@implContent, "#endif\n") if $attributeConditionalString;
1468 push(@implContent, "\n");
1473 if ($numFunctions > 0) {
1474 foreach my $function (@{$interface->functions}) {
1475 next if SkipFunction($function);
1476 next if ($function->signature->name eq "set" and $interface->extendedAttributes->{"TypedArray"});
1477 AddIncludesForType($function->signature->type);
1479 my $functionName = $function->signature->name;
1480 my $returnType = GetObjCType($function->signature->type);
1481 my $hasParameters = @{$function->parameters};
1482 my $raisesExceptions = $function->signature->extendedAttributes->{"RaisesException"};
1484 my @parameterNames = ();
1485 my @needsAssert = ();
1486 my %needsCustom = ();
1488 my $parameterIndex = 0;
1489 my $functionSig = "- ($returnType)$functionName";
1490 foreach my $param (@{$function->parameters}) {
1491 my $paramName = $param->name;
1492 my $paramType = GetObjCType($param->type);
1494 # make a new parameter name if the original conflicts with a property name
1495 $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
1497 AddIncludesForType($param->type);
1499 my $idlType = $param->type;
1500 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1502 push(@parameterNames, $implGetter);
1503 $needsCustom{"XPathNSResolver"} = $paramName if $idlType eq "XPathNSResolver";
1504 $needsCustom{"NodeFilter"} = $paramName if $idlType eq "NodeFilter";
1505 $needsCustom{"EventListener"} = $paramName if $idlType eq "EventListener";
1506 $needsCustom{"EventTarget"} = $paramName if $idlType eq "EventTarget";
1507 $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"CustomReturn"};
1509 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1510 push(@needsAssert, " ASSERT($paramName);\n");
1513 if ($parameterIndex >= 1) {
1514 $functionSig .= " " . $param->name;
1517 $functionSig .= ":($paramType)$paramName";
1522 my @functionContent = ();
1523 my $caller = "IMPL";
1525 # special case the XPathNSResolver
1526 if (defined $needsCustom{"XPathNSResolver"}) {
1527 my $paramName = $needsCustom{"XPathNSResolver"};
1528 push(@functionContent, " WebCore::XPathNSResolver* nativeResolver = 0;\n");
1529 push(@functionContent, " RefPtr<WebCore::XPathNSResolver> customResolver;\n");
1530 push(@functionContent, " if ($paramName) {\n");
1531 push(@functionContent, " if ([$paramName isMemberOfClass:[DOMNativeXPathNSResolver class]])\n");
1532 push(@functionContent, " nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>($paramName));\n");
1533 push(@functionContent, " else {\n");
1534 push(@functionContent, " customResolver = WebCore::DOMCustomXPathNSResolver::create($paramName);\n");
1535 push(@functionContent, " nativeResolver = WTF::getPtr(customResolver);\n");
1536 push(@functionContent, " }\n");
1537 push(@functionContent, " }\n");
1540 # special case the EventTarget
1541 if (defined $needsCustom{"EventTarget"}) {
1542 my $paramName = $needsCustom{"EventTarget"};
1543 push(@functionContent, " DOMNode* ${paramName}ObjC = $paramName;\n");
1544 push(@functionContent, " WebCore::Node* ${paramName}Node = core(${paramName}ObjC);\n");
1545 $implIncludes{"DOMNode.h"} = 1;
1546 $implIncludes{"Node.h"} = 1;
1549 if ($function->signature->extendedAttributes->{"ObjCUseDefaultView"}) {
1550 push(@functionContent, " WebCore::DOMWindow* dv = $caller->defaultView();\n");
1551 push(@functionContent, " if (!dv)\n");
1552 push(@functionContent, " return nil;\n");
1553 $implIncludes{"DOMWindow.h"} = 1;
1557 # special case the EventListener
1558 if (defined $needsCustom{"EventListener"}) {
1559 my $paramName = $needsCustom{"EventListener"};
1560 push(@functionContent, " RefPtr<WebCore::EventListener> nativeEventListener = WebCore::ObjCEventListener::wrap($paramName);\n");
1563 # special case the NodeFilter
1564 if (defined $needsCustom{"NodeFilter"}) {
1565 my $paramName = $needsCustom{"NodeFilter"};
1566 push(@functionContent, " RefPtr<WebCore::NodeFilter> nativeNodeFilter;\n");
1567 push(@functionContent, " if ($paramName)\n");
1568 push(@functionContent, " nativeNodeFilter = WebCore::NodeFilter::create(WebCore::ObjCNodeFilterCondition::create($paramName));\n");
1571 # FIXME! We need [Custom] support for ObjC, to move these hacks into DOMSVGLength/MatrixCustom.mm
1572 my $svgLengthConvertToSpecifiedUnits = ($svgPropertyType and $svgPropertyType eq "WebCore::SVGLength" and $functionName eq "convertToSpecifiedUnits");
1574 push(@parameterNames, "WebCore::SVGLengthContext(IMPL->contextElement())") if $svgLengthConvertToSpecifiedUnits;
1575 push(@parameterNames, "ec") if $raisesExceptions;
1577 # Handle arguments that are 'SVGProperty' based (SVGAngle/SVGLength). We need to convert from SVGPropertyTearOff<Type>* to Type,
1578 # to be able to call the desired WebCore function. If the conversion fails, we can't extract Type and need to raise an exception.
1579 my $currentParameter = -1;
1580 foreach my $param (@{$function->parameters}) {
1581 $currentParameter++;
1583 my $paramName = $param->name;
1585 # make a new parameter name if the original conflicts with a property name
1586 $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
1588 my $idlType = $param->type;
1589 next if not $codeGenerator->IsSVGTypeNeedingTearOff($idlType) or $implClassName =~ /List$/;
1591 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1592 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
1594 $implIncludes{"ExceptionCode.h"} = 1;
1595 push(@functionContent, " $idlTypeWithNamespace* ${paramName}Core = $implGetter;\n");
1596 push(@functionContent, " if (!${paramName}Core) {\n");
1597 push(@functionContent, " WebCore::ExceptionCode ec = WebCore::TYPE_MISMATCH_ERR;\n");
1598 push(@functionContent, " $exceptionRaiseOnError\n");
1599 if ($returnType eq "void") {
1600 push(@functionContent, " return;\n");
1602 push(@functionContent, " return nil;\n");
1604 push(@functionContent, " }\n");
1606 # Replace the paramter core() getter, by the cached variable.
1607 splice(@parameterNames, $currentParameter, 1, "${paramName}Core->propertyReference()");
1611 if ($function->signature->extendedAttributes->{"ImplementedBy"}) {
1612 my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"};
1613 $implIncludes{"${implementedBy}.h"} = 1;
1614 unshift(@parameterNames, $caller);
1615 $content = "${implementedBy}::" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
1616 } elsif ($svgPropertyType) {
1617 $implIncludes{"ExceptionCode.h"} = 1;
1618 push(@functionContent, " if (IMPL->isReadOnly()) {\n");
1619 push(@functionContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n");
1620 if ($returnType eq "void") {
1621 push(@functionContent, " return;\n");
1623 push(@functionContent, " return nil;\n");
1625 push(@functionContent, " }\n");
1626 push(@functionContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1627 $content = "podImpl." . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
1629 $content = "$caller->" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
1632 if ($returnType eq "void") {
1633 # Special case 'void' return type.
1634 if ($raisesExceptions) {
1635 push(@functionContent, " $exceptionInit\n");
1636 push(@functionContent, " $content;\n");
1637 if ($svgPropertyType) {
1638 push(@functionContent, " if (!ec)\n");
1639 push(@functionContent, " IMPL->commitChange();\n");
1641 push(@functionContent, " $exceptionRaiseOnError\n");
1643 push(@functionContent, " $content;\n");
1644 push(@functionContent, " IMPL->commitChange();\n") if $svgPropertyType;
1646 } elsif (defined $needsCustom{"NodeToReturn"}) {
1647 # Special case the insertBefore, replaceChild, removeChild
1648 # and appendChild functions from DOMNode
1649 my $toReturn = $needsCustom{"NodeToReturn"};
1650 if ($raisesExceptions) {
1651 push(@functionContent, " $exceptionInit\n");
1652 push(@functionContent, " if ($content)\n");
1653 push(@functionContent, " return $toReturn;\n");
1654 push(@functionContent, " $exceptionRaiseOnError\n");
1655 push(@functionContent, " return nil;\n");
1657 push(@functionContent, " if ($content)\n");
1658 push(@functionContent, " return $toReturn;\n");
1659 push(@functionContent, " return nil;\n");
1661 } elsif ($returnType eq "SerializedScriptValue") {
1664 if (ConversionNeeded($function->signature->type)) {
1665 if ($codeGenerator->IsSVGTypeNeedingTearOff($function->signature->type) and not $implClassName =~ /List$/) {
1666 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($function->signature->type);
1667 $content = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($content)))";
1669 $content = "kit(WTF::getPtr($content))";
1673 if ($raisesExceptions) {
1674 # Differentiated between when the return type is a pointer and
1675 # not for white space issue (ie. Foo *result vs. int result).
1676 if ($returnType =~ /\*$/) {
1677 $content = $returnType . "result = " . $content;
1679 $content = $returnType . " result = " . $content;
1682 push(@functionContent, " $exceptionInit\n");
1683 push(@functionContent, " $content;\n");
1684 push(@functionContent, " $exceptionRaiseOnError\n");
1685 push(@functionContent, " return result;\n");
1687 push(@functionContent, " return $content;\n");
1691 my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature);
1692 push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
1694 push(@implContent, "$functionSig\n");
1695 push(@implContent, "{\n");
1696 push(@implContent, " $jsContextSetter\n");
1697 push(@implContent, @functionContent);
1698 push(@implContent, "}\n\n");
1700 push(@implContent, "#endif\n\n") if $conditionalString;
1702 # generate the old style method names with un-named parameters, these methods are deprecated
1703 if (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"ObjCLegacyUnnamedParameters"}) {
1704 my $deprecatedFunctionSig = $functionSig;
1705 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
1707 push(@implContent, "$deprecatedFunctionSig\n");
1708 push(@implContent, "{\n");
1709 push(@implContent, " $jsContextSetter\n");
1710 push(@implContent, @functionContent);
1711 push(@implContent, "}\n\n");
1719 # END implementation
1720 push(@implContent, "\@end\n");
1722 # Generate internal interfaces
1723 push(@implContent, "\n$implType* core($className *wrapper)\n");
1724 push(@implContent, "{\n");
1725 push(@implContent, " return wrapper ? reinterpret_cast<$implType*>(wrapper->_internal) : 0;\n");
1726 push(@implContent, "}\n\n");
1728 if ($parentImplClassName eq "Object") {
1729 push(@implContent, "$className *kit($implType* value)\n");
1730 push(@implContent, "{\n");
1731 push(@implContent, " $assertMainThread;\n");
1732 push(@implContent, " if (!value)\n");
1733 push(@implContent, " return nil;\n");
1734 push(@implContent, " if ($className *wrapper = getDOMWrapper(value))\n");
1735 push(@implContent, " return [[wrapper retain] autorelease];\n");
1736 if ($interface->extendedAttributes->{"ObjCPolymorphic"}) {
1737 push(@implContent, " $className *wrapper = [[kitClass(value) alloc] _init];\n");
1738 push(@implContent, " if (!wrapper)\n");
1739 push(@implContent, " return nil;\n");
1741 push(@implContent, " $className *wrapper = [[$className alloc] _init];\n");
1743 push(@implContent, " wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(value);\n");
1744 push(@implContent, " value->ref();\n");
1745 push(@implContent, " addDOMWrapper(wrapper, value);\n");
1746 push(@implContent, " return [wrapper autorelease];\n");
1747 push(@implContent, "}\n");
1749 push(@implContent, "$className *kit($implType* value)\n");
1750 push(@implContent, "{\n");
1751 push(@implContent, " $assertMainThread;\n");
1752 push(@implContent, " return static_cast<$className*>(kit(static_cast<WebCore::$baseClass*>(value)));\n");
1753 push(@implContent, "}\n");
1756 # - End the ifdef conditional if necessary
1757 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
1759 # - Generate dependencies.
1760 if ($writeDependencies && @ancestorInterfaceNames) {
1761 push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n");
1762 push(@depsContent, map { "$_.idl :\n" } @ancestorInterfaceNames);
1770 my $dataNode = shift;
1771 my $outputDir = shift;
1773 # Open files for writing...
1774 my $name = $dataNode->name;
1775 my $prefix = FileNamePrefix;
1776 my $headerFileName = "$outputDir/$prefix$name.h";
1777 my $privateHeaderFileName = "$outputDir/$prefix${name}Private.h";
1778 my $implFileName = "$outputDir/$prefix$name.mm";
1779 my $internalHeaderFileName = "$outputDir/$prefix${name}Internal.h";
1780 my $depsFileName = "$outputDir/$prefix$name.dep";
1782 # Write public header.
1783 my $contents = join "", @headerContentHeader;
1784 map { $contents .= "\@class $_;\n" } sort keys(%headerForwardDeclarations);
1785 map { $contents .= "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
1787 my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols);
1788 $contents .= "\n" if $hasForwardDeclarations;
1789 $contents .= join "", @headerContent;
1790 $codeGenerator->UpdateFile($headerFileName, $contents);
1792 @headerContentHeader = ();
1793 @headerContent = ();
1794 %headerForwardDeclarations = ();
1795 %headerForwardDeclarationsForProtocols = ();
1797 if (@privateHeaderContent > 0) {
1798 $contents = join "", @privateHeaderContentHeader;
1799 map { $contents .= "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
1800 map { $contents .= "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
1802 $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols);
1803 $contents .= "\n" if $hasForwardDeclarations;
1804 $contents .= join "", @privateHeaderContent;
1805 $codeGenerator->UpdateFile($privateHeaderFileName, $contents);
1807 @privateHeaderContentHeader = ();
1808 @privateHeaderContent = ();
1809 %privateHeaderForwardDeclarations = ();
1810 %privateHeaderForwardDeclarationsForProtocols = ();
1813 # Write implementation file.
1815 $contents = join "", @implContentHeader;
1816 map { $contents .= "#import \"$_\"\n" } sort keys(%implIncludes);
1817 $contents .= join "", @implContent;
1818 $codeGenerator->UpdateFile($implFileName, $contents);
1820 @implContentHeader = ();
1825 if (@internalHeaderContent > 0) {
1826 $contents = join "", @internalHeaderContent;
1827 $codeGenerator->UpdateFile($internalHeaderFileName, $contents);
1829 @internalHeaderContent = ();
1832 # Write dependency file.
1834 $contents = join "", @depsContent;
1835 $codeGenerator->UpdateFile($depsFileName, $contents);