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";
34 my $writeDependencies = 0;
35 my %publicInterfaces = ();
36 my $newPublicClass = 0;
37 my $interfaceAvailabilityVersion = "";
41 my @headerContentHeader = ();
42 my @headerContent = ();
43 my %headerForwardDeclarations = ();
44 my %headerForwardDeclarationsForProtocols = ();
46 my @privateHeaderContentHeader = ();
47 my @privateHeaderContent = ();
48 my %privateHeaderForwardDeclarations = ();
49 my %privateHeaderForwardDeclarationsForProtocols = ();
51 my @internalHeaderContent = ();
53 my @implContentHeader = ();
55 my %implIncludes = ();
59 my %protocolTypeHash = ("XPathNSResolver" => 1, "EventListener" => 1, "EventTarget" => 1, "NodeFilter" => 1,
60 "SVGLocatable" => 1, "SVGTransformable" => 1, "SVGStylable" => 1, "SVGFilterPrimitiveStandardAttributes" => 1,
61 "SVGTests" => 1, "SVGLangSpace" => 1, "SVGExternalResourcesRequired" => 1, "SVGURIReference" => 1,
62 "SVGZoomAndPan" => 1, "SVGFitToViewBox" => 1, "SVGAnimatedPathData" => 1, "ElementTimeControl" => 1);
63 my %nativeObjCTypeHash = ("URL" => 1, "Color" => 1);
65 # FIXME: this should be replaced with a function that recurses up the tree
66 # to find the actual base type.
67 my %baseTypeHash = ("Object" => 1, "Node" => 1, "NodeList" => 1, "NamedNodeMap" => 1, "DOMImplementation" => 1,
68 "Event" => 1, "CSSRule" => 1, "CSSValue" => 1, "StyleSheet" => 1, "MediaList" => 1,
69 "Counter" => 1, "Rect" => 1, "RGBColor" => 1, "XPathExpression" => 1, "XPathResult" => 1,
70 "NodeIterator" => 1, "TreeWalker" => 1, "AbstractView" => 1, "Blob" => 1,
71 "SVGAngle" => 1, "SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1, "SVGAnimatedEnumeration" => 1,
72 "SVGAnimatedInteger" => 1, "SVGAnimatedLength" => 1, "SVGAnimatedLengthList" => 1,
73 "SVGAnimatedNumber" => 1, "SVGAnimatedNumberList" => 1,
74 "SVGAnimatedPreserveAspectRatio" => 1, "SVGAnimatedRect" => 1, "SVGAnimatedString" => 1,
75 "SVGAnimatedTransformList" => 1, "SVGLength" => 1, "SVGLengthList" => 1, "SVGMatrix" => 1,
76 "SVGNumber" => 1, "SVGNumberList" => 1, "SVGPathSeg" => 1, "SVGPathSegList" => 1, "SVGPoint" => 1,
77 "SVGPointList" => 1, "SVGPreserveAspectRatio" => 1, "SVGRect" => 1, "SVGRenderingIntent" => 1,
78 "SVGStringList" => 1, "SVGTransform" => 1, "SVGTransformList" => 1, "SVGUnitTypes" => 1);
81 my $buildingForTigerOrEarlier = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} <= 10.4;
82 my $buildingForLeopardOrLater = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} >= 10.5;
83 my $exceptionInit = "WebCore::ExceptionCode ec = 0;";
84 my $jsContextSetter = "WebCore::JSMainThreadNullState state;";
85 my $exceptionRaiseOnError = "WebCore::raiseOnDOMError(ec);";
86 my $assertMainThread = "{ DOM_ASSERT_MAIN_THREAD(); WebCoreThreadViolationCheckRoundOne(); }";
88 my %conflictMethod = (
89 # FIXME: Add C language keywords?
90 # FIXME: Add other predefined types like "id"?
92 "callWebScriptMethod:withArguments:" => "WebScriptObject",
93 "evaluateWebScript:" => "WebScriptObject",
94 "removeWebScriptKey:" => "WebScriptObject",
95 "setException:" => "WebScriptObject",
96 "setWebScriptValueAtIndex:value:" => "WebScriptObject",
97 "stringRepresentation" => "WebScriptObject",
98 "webScriptValueAtIndex:" => "WebScriptObject",
100 "autorelease" => "NSObject",
101 "awakeAfterUsingCoder:" => "NSObject",
102 "class" => "NSObject",
103 "classForCoder" => "NSObject",
104 "conformsToProtocol:" => "NSObject",
105 "copy" => "NSObject",
106 "copyWithZone:" => "NSObject",
107 "dealloc" => "NSObject",
108 "description" => "NSObject",
109 "doesNotRecognizeSelector:" => "NSObject",
110 "encodeWithCoder:" => "NSObject",
111 "finalize" => "NSObject",
112 "forwardInvocation:" => "NSObject",
113 "hash" => "NSObject",
114 "init" => "NSObject",
115 "initWithCoder:" => "NSObject",
116 "isEqual:" => "NSObject",
117 "isKindOfClass:" => "NSObject",
118 "isMemberOfClass:" => "NSObject",
119 "isProxy" => "NSObject",
120 "methodForSelector:" => "NSObject",
121 "methodSignatureForSelector:" => "NSObject",
122 "mutableCopy" => "NSObject",
123 "mutableCopyWithZone:" => "NSObject",
124 "performSelector:" => "NSObject",
125 "release" => "NSObject",
126 "replacementObjectForCoder:" => "NSObject",
127 "respondsToSelector:" => "NSObject",
128 "retain" => "NSObject",
129 "retainCount" => "NSObject",
130 "self" => "NSObject",
131 "superclass" => "NSObject",
132 "zone" => "NSObject",
137 # Default License Templates
138 my $headerLicenseTemplate = << "EOF";
140 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
141 * Copyright (C) 2006 Samuel Weinig <sam.weinig\@gmail.com>
143 * Redistribution and use in source and binary forms, with or without
144 * modification, are permitted provided that the following conditions
146 * 1. Redistributions of source code must retain the above copyright
147 * notice, this list of conditions and the following disclaimer.
148 * 2. Redistributions in binary form must reproduce the above copyright
149 * notice, this list of conditions and the following disclaimer in the
150 * documentation and/or other materials provided with the distribution.
152 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
153 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
154 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
155 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
156 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
157 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
158 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
159 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
160 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
161 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
162 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
166 my $implementationLicenseTemplate = << "EOF";
168 * This file is part of the WebKit open source project.
169 * This file has been generated by generate-bindings.pl. DO NOT MODIFY!
171 * Redistribution and use in source and binary forms, with or without
172 * modification, are permitted provided that the following conditions
174 * 1. Redistributions of source code must retain the above copyright
175 * notice, this list of conditions and the following disclaimer.
176 * 2. Redistributions in binary form must reproduce the above copyright
177 * notice, this list of conditions and the following disclaimer in the
178 * documentation and/or other materials provided with the distribution.
180 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
181 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
183 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
184 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
185 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
186 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
187 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
188 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
189 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
190 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
194 # Default constructor
200 $codeGenerator = shift;
202 shift; # $outputHeadersDir
203 shift; # $useLayerOnTop
204 shift; # $preprocessor
205 $writeDependencies = shift;
207 bless($reference, $object);
211 sub ReadPublicInterfaces
214 my $superClass = shift;
216 my $isProtocol = shift;
219 my $actualSuperClass;
220 %publicInterfaces = ();
222 my $fileName = "WebCore/bindings/objc/PublicDOMInterfaces.h";
223 my $gccLocation = "";
225 $gccLocation = $ENV{CC};
226 } elsif (($Config::Config{'osname'}) =~ /solaris/i) {
227 $gccLocation = "/usr/sfw/bin/gcc";
229 $gccLocation = "/usr/bin/gcc";
231 open FILE, "-|", $gccLocation, "-E", "-P", "-x", "objective-c",
232 (map { "-D$_" } split(/ +/, $defines)), "-DOBJC_CODE_GENERATION", $fileName or die "Could not open $fileName";
233 my @documentContent = <FILE>;
236 foreach $line (@documentContent) {
237 if (!$isProtocol && $line =~ /^\s*\@interface\s*$class\s*:\s*(\w+)\s*([A-Z0-9_]*)/) {
238 if ($superClass ne $1) {
239 warn "Public API change. Superclass for \"$class\" differs ($1 != $superClass)";
243 $interfaceAvailabilityVersion = $2 if defined $2;
246 } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*<[^>]+>\s*([A-Z0-9_]*)/) {
247 $interfaceAvailabilityVersion = $1 if defined $1;
252 last if $found and $line =~ /^\s?\@end\s?$/;
259 my $availabilityMacro = "";
260 $line =~ s/\s([A-Z0-9_]+)\s*;$/;/;
261 $availabilityMacro = $1 if defined $1;
263 $publicInterfaces{$line} = $availabilityMacro if length $line;
267 # If this class was not found in PublicDOMInterfaces.h then it should be considered as an entirely new public class.
268 $newPublicClass = !$found;
269 $interfaceAvailabilityVersion = "WEBKIT_VERSION_LATEST" if $newPublicClass;
272 # Params: 'domClass' struct
273 sub GenerateInterface
276 my $dataNode = shift;
281 my $name = $dataNode->name;
282 my $className = GetClassName($name);
283 my $parentClassName = "DOM" . GetParentImplClassName($dataNode);
284 $isProtocol = $dataNode->extendedAttributes->{ObjCProtocol};
285 $noImpl = $dataNode->extendedAttributes->{ObjCCustomImplementation} || $isProtocol;
287 ReadPublicInterfaces($className, $parentClassName, $defines, $isProtocol);
289 # Start actual generation..
290 $object->GenerateHeader($dataNode);
291 $object->GenerateImplementation($dataNode) unless $noImpl;
294 $object->WriteData(FileNamePrefix . $name);
296 # Check for missing public API
297 if (keys %publicInterfaces > 0) {
298 my $missing = join("\n", keys %publicInterfaces);
299 warn "Public API change. There are missing public properties and/or methods from the \"$className\" class.\n$missing\n";
306 # Params: 'idlDocument' struct
310 my $dataNode = shift;
312 $module = $dataNode->module;
317 my $name = $codeGenerator->StripModule(shift);
320 return "NSString" if $codeGenerator->IsStringType($name) or $name eq "SerializedScriptValue";
321 return "NS$name" if IsNativeObjCType($name);
322 return "BOOL" if $name eq "boolean";
323 return "unsigned" if $name eq "unsigned long";
324 return "int" if $name eq "long";
325 return "NSTimeInterval" if $name eq "Date";
326 return "DOMAbstractView" if $name eq "DOMWindow";
327 return $name if $codeGenerator->IsPrimitiveType($name) or $name eq "DOMImplementation" or $name eq "DOMTimeStamp";
329 # Default, assume Objective-C type has the same type name as
330 # idl type prefixed with "DOM".
334 sub GetClassHeaderName
338 return "DOMDOMImplementation" if $name eq "DOMImplementation";
344 my $name = $codeGenerator->StripModule(shift);
346 return "DOMImplementationFront" if $name eq "DOMImplementation";
347 return "DOMWindow" if $name eq "AbstractView";
351 sub GetParentImplClassName
353 my $dataNode = shift;
355 return "Object" if @{$dataNode->parents} eq 0;
357 my $parent = $codeGenerator->StripModule($dataNode->parents(0));
360 return "Object" if $parent eq "HTMLCollection";
365 sub GetParentAndProtocols
367 my $dataNode = shift;
368 my $numParents = @{$dataNode->parents};
372 if ($numParents eq 0) {
374 push(@protocols, "NSObject");
375 push(@protocols, "NSCopying") if $dataNode->name eq "EventTarget";
377 $parent = "DOMObject";
379 } elsif ($numParents eq 1) {
380 my $parentName = $codeGenerator->StripModule($dataNode->parents(0));
382 die "Parents of protocols must also be protocols." unless IsProtocolType($parentName);
383 push(@protocols, "DOM" . $parentName);
385 if (IsProtocolType($parentName)) {
386 push(@protocols, "DOM" . $parentName);
387 } elsif ($parentName eq "HTMLCollection") {
388 $parent = "DOMObject";
390 $parent = "DOM" . $parentName;
394 my @parents = @{$dataNode->parents};
395 my $firstParent = $codeGenerator->StripModule(shift(@parents));
396 if (IsProtocolType($firstParent)) {
397 push(@protocols, "DOM" . $firstParent);
399 $parent = "DOMObject";
402 $parent = "DOM" . $firstParent;
405 foreach my $parentName (@parents) {
406 $parentName = $codeGenerator->StripModule($parentName);
407 die "Everything past the first class should be a protocol!" unless IsProtocolType($parentName);
409 push(@protocols, "DOM" . $parentName);
413 return ($parent, @protocols);
420 return $parent if $parent eq "Object" or IsBaseType($parent);
421 return "Event" if $parent eq "UIEvent" or $parent eq "MouseEvent";
422 return "CSSValue" if $parent eq "SVGColor" or $parent eq "CSSValueList";
430 return 1 if $baseTypeHash{$type};
438 return 1 if $protocolTypeHash{$type};
446 return 1 if $nativeObjCTypeHash{$type};
452 my $function = shift;
454 return 1 if $codeGenerator->GetSequenceType($function->signature->type);
455 return 1 if $codeGenerator->GetArrayType($function->signature->type);
457 foreach my $param (@{$function->parameters}) {
458 return 1 if $codeGenerator->GetSequenceType($param->type);
459 return 1 if $codeGenerator->GetArrayType($param->type);
460 return 1 if $param->extendedAttributes->{"Clamp"};
468 my $attribute = shift;
470 $codeGenerator->AssertNotSequenceType($attribute->signature->type);
471 return 1 if $codeGenerator->GetArrayType($attribute->signature->type);
472 return 1 if $codeGenerator->IsTypedArrayType($attribute->signature->type);
474 # This is for DynamicsCompressorNode.idl
475 if ($attribute->signature->name eq "release") {
486 my $name = GetClassName($type);
488 return "id <$name>" if IsProtocolType($type);
489 return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
490 return "unsigned short" if $type eq "CompareHow";
494 sub GetPropertyAttributes
496 my $type = $codeGenerator->StripModule(shift);
497 my $readOnly = shift;
501 push(@attributes, "readonly") if $readOnly;
503 # FIXME: <rdar://problem/5049934> Consider using 'nonatomic' on the DOM @property declarations.
504 if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) {
505 push(@attributes, "copy");
506 } elsif ($codeGenerator->IsSVGAnimatedType($type)) {
507 push(@attributes, "retain");
508 } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow") {
509 push(@attributes, "retain");
512 return "" unless @attributes > 0;
513 return "(" . join(", ", @attributes) . ")";
518 my $type = $codeGenerator->StripModule(shift);
520 return !$codeGenerator->IsNonPointerType($type) && !$codeGenerator->IsStringType($type) && !IsNativeObjCType($type);
523 sub GetObjCTypeGetter
526 my $type = $codeGenerator->StripModule(shift);
528 return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
529 return $argName . "Node" if $type eq "EventTarget";
530 return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow";
531 return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener";
532 return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter";
533 return "WTF::getPtr(nativeResolver)" if $type eq "XPathNSResolver";
535 if ($type eq "SerializedScriptValue") {
536 $implIncludes{"SerializedScriptValue.h"} = 1;
537 return "WebCore::SerializedScriptValue::create(WTF::String($argName))";
539 return "core($argName)";
542 sub AddForwardDeclarationsForType
544 my $type = $codeGenerator->StripModule(shift);
547 return if $codeGenerator->IsNonPointerType($type);
548 return if $codeGenerator->GetSequenceType($type);
549 return if $codeGenerator->GetArrayType($type);
551 my $class = GetClassName($type);
553 if (IsProtocolType($type)) {
554 $headerForwardDeclarationsForProtocols{$class} = 1 if $public;
555 $privateHeaderForwardDeclarationsForProtocols{$class} = 1 if !$public and !$headerForwardDeclarationsForProtocols{$class};
559 $headerForwardDeclarations{$class} = 1 if $public;
561 # Private headers include the public header, so only add a forward declaration to the private header
562 # if the public header does not already have the same forward declaration.
563 $privateHeaderForwardDeclarations{$class} = 1 if !$public and !$headerForwardDeclarations{$class};
566 sub AddIncludesForType
568 my $type = $codeGenerator->StripModule(shift);
570 return if $codeGenerator->IsNonPointerType($type);
571 return if $codeGenerator->GetSequenceType($type);
572 return if $codeGenerator->GetArrayType($type);
574 if (IsNativeObjCType($type)) {
575 if ($type eq "Color") {
576 $implIncludes{"ColorMac.h"} = 1;
581 if ($codeGenerator->IsStringType($type)) {
582 $implIncludes{"KURL.h"} = 1;
586 if ($type eq "DOMWindow") {
587 $implIncludes{"DOMAbstractViewInternal.h"} = 1;
588 $implIncludes{"DOMWindow.h"} = 1;
592 if ($type eq "DOMImplementation") {
593 $implIncludes{"DOMDOMImplementationInternal.h"} = 1;
594 $implIncludes{"DOMImplementationFront.h"} = 1;
598 if ($type eq "EventTarget") {
599 $implIncludes{"Node.h"} = 1;
600 $implIncludes{"DOMEventTarget.h"} = 1;
604 if ($codeGenerator->IsSVGAnimatedType($type)) {
605 $implIncludes{"${type}.h"} = 1;
606 $implIncludes{"DOM${type}Internal.h"} = 1;
610 if ($type =~ /(\w+)(Abs|Rel)$/) {
611 $implIncludes{"$1.h"} = 1;
612 $implIncludes{"DOM${type}Internal.h"} = 1;
616 if ($type eq "NodeFilter") {
617 $implIncludes{"NodeFilter.h"} = 1;
618 $implIncludes{"ObjCNodeFilterCondition.h"} = 1;
622 if ($type eq "EventListener") {
623 $implIncludes{"EventListener.h"} = 1;
624 $implIncludes{"ObjCEventListener.h"} = 1;
628 if ($type eq "XPathNSResolver") {
629 $implIncludes{"DOMCustomXPathNSResolver.h"} = 1;
630 $implIncludes{"XPathNSResolver.h"} = 1;
634 if ($type eq "SerializedScriptValue") {
635 $implIncludes{"SerializedScriptValue.h"} = 1;
639 # FIXME: won't compile without these
640 $implIncludes{"StylePropertySet.h"} = 1 if $type eq "CSSStyleDeclaration";
641 $implIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList";
643 # Default, include the same named file (the implementation) and the same name prefixed with "DOM".
644 $implIncludes{"$type.h"} = 1 if not $codeGenerator->SkipIncludeHeader($type);
645 $implIncludes{"DOM${type}Internal.h"} = 1;
648 sub GetSVGTypeWithNamespace
651 my $typeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($type);
653 # Special case for DOMSVGNumber
654 $typeWithNamespace =~ s/</\<WebCore::/ unless $type eq "SVGNumber";
655 return $typeWithNamespace;
658 sub GetSVGPropertyTypes
660 my $implType = shift;
663 my $svgListPropertyType;
666 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $implType =~ /SVG/;
668 $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($implType);
669 return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType;
671 # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType>
672 $svgNativeType = "WebCore::$svgNativeType ";
673 $svgNativeType =~ s/</\<WebCore::/ if not $svgNativeType =~ /float/;
675 my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implType);
676 if ($svgNativeType =~ /SVGPropertyTearOff/) {
677 if ($svgWrappedNativeType eq "float") {
678 # Special case for DOMSVGNumber
679 $svgPropertyType = $svgWrappedNativeType;
681 $svgPropertyType = "WebCore::$svgWrappedNativeType";
682 $svgPropertyType =~ s/</\<WebCore::/;
684 } elsif ($svgNativeType =~ /SVGListPropertyTearOff/ or $svgNativeType =~ /SVGStaticListPropertyTearOff/) {
685 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
686 $svgListPropertyType =~ s/</\<WebCore::/;
687 } elsif ($svgNativeType =~ /SVGTransformListPropertyTearOff/) {
688 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
689 $svgListPropertyType =~ s/</\<WebCore::/;
690 } elsif ($svgNativeType =~ /SVGPathSegListPropertyTearOff/) {
691 $svgListPropertyType = "WebCore::$svgWrappedNativeType";
692 $svgListPropertyType =~ s/</\<WebCore::/;
695 return ($svgPropertyType, $svgListPropertyType, $svgNativeType);
701 my $dataNode = shift;
703 my $interfaceName = $dataNode->name;
704 my $className = GetClassName($interfaceName);
707 my @protocolsToImplement = ();
708 ($parentName, @protocolsToImplement) = GetParentAndProtocols($dataNode);
710 my $numConstants = @{$dataNode->constants};
711 my $numAttributes = @{$dataNode->attributes};
712 my $numFunctions = @{$dataNode->functions};
714 # - Add default header template
715 @headerContentHeader = split("\r", $headerLicenseTemplate);
716 push(@headerContentHeader, "\n");
719 my $includedWebKitAvailabilityHeader = 0;
720 unless ($isProtocol) {
721 my $parentHeaderName = GetClassHeaderName($parentName);
722 push(@headerContentHeader, "#import <WebCore/$parentHeaderName.h>\n");
723 $includedWebKitAvailabilityHeader = 1;
726 foreach my $parentProtocol (@protocolsToImplement) {
727 next if $parentProtocol =~ /^NS/;
728 $parentProtocol = GetClassHeaderName($parentProtocol);
729 push(@headerContentHeader, "#import <WebCore/$parentProtocol.h>\n");
730 $includedWebKitAvailabilityHeader = 1;
733 # Special case needed for legacy support of DOMRange
734 if ($interfaceName eq "Range") {
735 push(@headerContentHeader, "#import <WebCore/DOMCore.h>\n");
736 push(@headerContentHeader, "#import <WebCore/DOMDocument.h>\n");
737 push(@headerContentHeader, "#import <WebCore/DOMRangeException.h>\n");
738 $includedWebKitAvailabilityHeader = 1;
741 push(@headerContentHeader, "#import <JavaScriptCore/WebKitAvailability.h>\n") unless $includedWebKitAvailabilityHeader;
743 my $interfaceAvailabilityVersionCheck = "#if WEBKIT_VERSION_MAX_ALLOWED >= $interfaceAvailabilityVersion\n\n";
745 push(@headerContentHeader, "\n");
746 push(@headerContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
749 if ($numConstants > 0) {
750 my @headerConstants = ();
751 my @constants = @{$dataNode->constants};
752 my $combinedConstants = "";
754 # FIXME: we need a way to include multiple enums.
755 foreach my $constant (@constants) {
756 my $constantName = $constant->name;
757 my $constantValue = $constant->value;
758 my $conditional = $constant->extendedAttributes->{"Conditional"};
759 my $notLast = $constant ne $constants[-1];
762 my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional);
763 $combinedConstants .= "#if ${conditionalString}\n";
765 $combinedConstants .= " DOM_$constantName = $constantValue";
766 $combinedConstants .= "," if $notLast;
768 $combinedConstants .= "\n#endif\n";
770 $combinedConstants .= "\n";
774 # FIXME: the formatting of the enums should line up the equal signs.
775 # FIXME: enums are unconditionally placed in the public header.
776 push(@headerContent, "enum {\n");
777 push(@headerContent, $combinedConstants);
778 push(@headerContent, "\n};\n\n");
781 # - Begin @interface or @protocol
782 my $interfaceDeclaration = ($isProtocol ? "\@protocol $className" : "\@interface $className : $parentName");
783 $interfaceDeclaration .= " <" . join(", ", @protocolsToImplement) . ">" if @protocolsToImplement > 0;
784 $interfaceDeclaration .= "\n";
786 push(@headerContent, $interfaceDeclaration);
788 my @headerAttributes = ();
789 my @privateHeaderAttributes = ();
791 # - Add attribute getters/setters.
792 if ($numAttributes > 0) {
793 foreach my $attribute (@{$dataNode->attributes}) {
794 next if SkipAttribute($attribute);
795 my $attributeName = $attribute->signature->name;
797 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
798 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
799 $attributeName .= "Name";
800 } elsif ($attributeName eq "frame") {
801 # Special case attribute frame to be frameBorders.
802 $attributeName .= "Borders";
805 my $attributeType = GetObjCType($attribute->signature->type);
806 my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
808 my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attributeIsReadonly);
809 # Some SVGFE*Element.idl use 'operator' as attribute name, rewrite as '_operator' to avoid clashes with C/C++
810 $attributeName =~ s/operator/_operator/ if ($attributeName =~ /operator/);
811 $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName;
813 my $publicInterfaceKey = $property . ";";
815 my $availabilityMacro = "";
816 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
817 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
820 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
822 my $declarationSuffix = ";\n";
823 $declarationSuffix = " $availabilityMacro;\n" if length $availabilityMacro;
825 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
826 delete $publicInterfaces{$publicInterfaceKey};
828 AddForwardDeclarationsForType($attribute->signature->type, $public);
830 my $setterName = "set" . ucfirst($attributeName) . ":";
832 my $conflict = $conflictMethod{$attributeName};
834 warn "$className conflicts with $conflict method $attributeName\n";
838 $conflict = $conflictMethod{$setterName};
840 warn "$className conflicts with $conflict method $setterName\n";
844 if ($buildingForLeopardOrLater) {
845 $property .= $declarationSuffix;
846 push(@headerAttributes, $property) if $public;
847 push(@privateHeaderAttributes, $property) unless $public;
849 my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature);
850 if ($attributeConditionalString) {
851 push(@headerAttributes, "#if ${attributeConditionalString}\n") if $public;
852 push(@privateHeaderAttributes, "#if ${attributeConditionalString}\n") unless $public;
856 my $getter = "- (" . $attributeType . ")" . $attributeName . $declarationSuffix;
857 push(@headerAttributes, $getter) if $public;
858 push(@privateHeaderAttributes, $getter) unless $public;
861 if (!$attributeIsReadonly) {
862 my $setter = "- (void)$setterName(" . $attributeType . ")new" . ucfirst($attributeName) . $declarationSuffix;
863 push(@headerAttributes, $setter) if $public;
864 push(@privateHeaderAttributes, $setter) unless $public;
867 if ($attributeConditionalString) {
868 push(@headerAttributes, "#endif\n") if $public;
869 push(@privateHeaderAttributes, "#endif\n") unless $public;
874 push(@headerContent, @headerAttributes) if @headerAttributes > 0;
877 my @headerFunctions = ();
878 my @privateHeaderFunctions = ();
879 my @deprecatedHeaderFunctions = ();
882 if ($numFunctions > 0) {
883 foreach my $function (@{$dataNode->functions}) {
884 next if SkipFunction($function);
885 my $functionName = $function->signature->name;
887 my $returnType = GetObjCType($function->signature->type);
888 my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"ObjCLegacyUnnamedParameters"});
889 my $numberOfParameters = @{$function->parameters};
890 my %typesToForwardDeclare = ($function->signature->type => 1);
892 my $parameterIndex = 0;
893 my $functionSig = "- ($returnType)$functionName";
894 my $methodName = $functionName;
895 foreach my $param (@{$function->parameters}) {
896 my $paramName = $param->name;
897 my $paramType = GetObjCType($param->type);
899 $typesToForwardDeclare{$param->type} = 1;
901 if ($parameterIndex >= 1) {
902 $functionSig .= " $paramName";
903 $methodName .= $paramName;
906 $functionSig .= ":($paramType)$paramName";
912 my $publicInterfaceKey = $functionSig . ";";
914 my $conflict = $conflictMethod{$methodName};
916 warn "$className conflicts with $conflict method $methodName\n";
920 if ($isProtocol && !$newPublicClass && !defined $publicInterfaces{$publicInterfaceKey}) {
921 warn "Protocol method $publicInterfaceKey is not in PublicDOMInterfaces.h. Protocols require all methods to be public";
925 my $availabilityMacro = "";
926 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
927 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
930 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
932 my $functionDeclaration = $functionSig;
933 $functionDeclaration .= " " . $availabilityMacro if length $availabilityMacro;
934 $functionDeclaration .= ";\n";
936 my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
937 delete $publicInterfaces{$publicInterfaceKey};
939 foreach my $type (keys %typesToForwardDeclare) {
940 # add any forward declarations to the public header if a deprecated version will be generated
941 AddForwardDeclarationsForType($type, 1) if $needsDeprecatedVersion;
942 AddForwardDeclarationsForType($type, $public) unless $public and $needsDeprecatedVersion;
945 my $functionConditionalString = $codeGenerator->GenerateConditionalString($function->signature);
946 if ($functionConditionalString) {
947 push(@headerFunctions, "#if ${functionConditionalString}\n") if $public;
948 push(@privateHeaderFunctions, "#if ${functionConditionalString}\n") unless $public;
949 push(@deprecatedHeaderFunctions, "#if ${functionConditionalString}\n") if $needsDeprecatedVersion;
952 push(@headerFunctions, $functionDeclaration) if $public;
953 push(@privateHeaderFunctions, $functionDeclaration) unless $public;
955 # generate the old style method names with un-named parameters, these methods are deprecated
956 if ($needsDeprecatedVersion) {
957 my $deprecatedFunctionSig = $functionSig;
958 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
960 $publicInterfaceKey = $deprecatedFunctionSig . ";";
962 my $availabilityMacro = "AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0";
963 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
964 $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
967 $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if $buildingForTigerOrEarlier;
969 $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
971 push(@deprecatedHeaderFunctions, $functionDeclaration);
973 unless (defined $publicInterfaces{$publicInterfaceKey}) {
974 warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the ObjCLegacyUnnamedParameters IDL attribute removed";
978 delete $publicInterfaces{$publicInterfaceKey};
981 if ($functionConditionalString) {
982 push(@headerFunctions, "#endif\n") if $public;
983 push(@privateHeaderFunctions, "#endif\n") unless $public;
984 push(@deprecatedHeaderFunctions, "#endif\n") if $needsDeprecatedVersion;
988 if (@headerFunctions > 0) {
989 push(@headerContent, "\n") if $buildingForLeopardOrLater and @headerAttributes > 0;
990 push(@headerContent, @headerFunctions);
994 if (@deprecatedHeaderFunctions > 0 && $isProtocol) {
995 push(@headerContent, @deprecatedHeaderFunctions);
998 # - End @interface or @protocol
999 push(@headerContent, "\@end\n");
1001 if (@deprecatedHeaderFunctions > 0 && !$isProtocol) {
1002 # - Deprecated category @interface
1003 push(@headerContent, "\n\@interface $className (" . $className . "Deprecated)\n");
1004 push(@headerContent, @deprecatedHeaderFunctions);
1005 push(@headerContent, "\@end\n");
1008 push(@headerContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
1010 my %alwaysGenerateForNoSVGBuild = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement);
1012 if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0 or exists $alwaysGenerateForNoSVGBuild{$className}) {
1013 # - Private category @interface
1014 @privateHeaderContentHeader = split("\r", $headerLicenseTemplate);
1015 push(@privateHeaderContentHeader, "\n");
1017 my $classHeaderName = GetClassHeaderName($className);
1018 push(@privateHeaderContentHeader, "#import <WebCore/$classHeaderName.h>\n\n");
1019 push(@privateHeaderContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
1021 @privateHeaderContent = ();
1022 push(@privateHeaderContent, "\@interface $className (" . $className . "Private)\n");
1023 push(@privateHeaderContent, @privateHeaderAttributes) if @privateHeaderAttributes > 0;
1024 push(@privateHeaderContent, "\n") if $buildingForLeopardOrLater and @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0;
1025 push(@privateHeaderContent, @privateHeaderFunctions) if @privateHeaderFunctions > 0;
1026 push(@privateHeaderContent, "\@end\n");
1028 push(@privateHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
1031 unless ($isProtocol) {
1032 # Generate internal interfaces
1033 my $implClassName = GetImplClassName($interfaceName);
1034 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
1036 my $implType = $implClassNameWithNamespace;
1037 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
1038 $implType = $svgNativeType if $svgNativeType;
1040 # Generate interface definitions.
1041 @internalHeaderContent = split("\r", $implementationLicenseTemplate);
1043 push(@internalHeaderContent, "\n#import <WebCore/$className.h>\n\n");
1044 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedPropertyTearOff.h>\n\n") if $svgPropertyType;
1045 if ($svgListPropertyType) {
1046 push(@internalHeaderContent, "#import <WebCore/SVGAnimatedListPropertyTearOff.h>\n\n");
1047 push(@internalHeaderContent, "#import <WebCore/SVGTransformListPropertyTearOff.h>\n\n") if $svgListPropertyType =~ /SVGTransformList/;
1048 push(@internalHeaderContent, "#import <WebCore/SVGPathSegListPropertyTearOff.h>\n\n") if $svgListPropertyType =~ /SVGPathSegList/;
1050 push(@internalHeaderContent, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
1052 if ($interfaceName eq "Node") {
1053 push(@internalHeaderContent, "\@protocol DOMEventTarget;\n\n");
1056 my $startedNamespace = 0;
1058 if ($codeGenerator->IsSVGAnimatedType($interfaceName)) {
1059 push(@internalHeaderContent, "#import <WebCore/$implClassName.h>\n\n");
1061 push(@internalHeaderContent, "namespace WebCore {\n");
1062 $startedNamespace = 1;
1063 if ($interfaceName eq "Node") {
1064 push(@internalHeaderContent, " class EventTarget;\n class Node;\n");
1066 push(@internalHeaderContent, " class $implClassName;\n");
1068 push(@internalHeaderContent, "}\n\n");
1071 push(@internalHeaderContent, "$implType* core($className *);\n");
1072 push(@internalHeaderContent, "$className *kit($implType*);\n");
1074 if ($dataNode->extendedAttributes->{"ObjCPolymorphic"}) {
1075 push(@internalHeaderContent, "Class kitClass($implType*);\n");
1078 if ($interfaceName eq "Node") {
1079 push(@internalHeaderContent, "id <DOMEventTarget> kit(WebCore::EventTarget*);\n");
1082 push(@internalHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
1086 sub GenerateImplementation
1089 my $dataNode = shift;
1091 my @ancestorInterfaceNames = ();
1093 if (@{$dataNode->parents} > 1) {
1094 $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@ancestorInterfaceNames);
1097 my $interfaceName = $dataNode->name;
1098 my $className = GetClassName($interfaceName);
1099 my $implClassName = GetImplClassName($interfaceName);
1100 my $parentImplClassName = GetParentImplClassName($dataNode);
1101 my $implClassNameWithNamespace = "WebCore::" . $implClassName;
1102 my $baseClass = GetBaseClass($parentImplClassName);
1103 my $classHeaderName = GetClassHeaderName($className);
1105 my $numAttributes = @{$dataNode->attributes};
1106 my $numFunctions = @{$dataNode->functions};
1107 my $implType = $implClassNameWithNamespace;
1109 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
1110 $implType = $svgNativeType if $svgNativeType;
1112 # - Add default header template.
1113 @implContentHeader = split("\r", $implementationLicenseTemplate);
1116 push(@implContentHeader, "\n#import \"config.h\"\n");
1118 my $conditionalString = $codeGenerator->GenerateConditionalString($dataNode);
1119 push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString;
1121 push(@implContentHeader, "#import \"DOMInternal.h\"\n\n");
1122 push(@implContentHeader, "#import \"$classHeaderName.h\"\n\n");
1124 $implIncludes{"ExceptionHandlers.h"} = 1;
1125 $implIncludes{"ThreadCheck.h"} = 1;
1126 $implIncludes{"JSMainThreadExecState.h"} = 1;
1127 $implIncludes{"WebScriptObjectPrivate.h"} = 1;
1128 $implIncludes{$classHeaderName . "Internal.h"} = 1;
1130 # FIXME: These includes are only needed when the class is a subclass of one of these polymorphic classes.
1131 $implIncludes{"DOMBlobInternal.h"} = 1;
1132 $implIncludes{"DOMCSSRuleInternal.h"} = 1;
1133 $implIncludes{"DOMCSSValueInternal.h"} = 1;
1134 $implIncludes{"DOMEventInternal.h"} = 1;
1135 $implIncludes{"DOMNodeInternal.h"} = 1;
1136 $implIncludes{"DOMStyleSheetInternal.h"} = 1;
1138 $implIncludes{"DOMSVGPathSegInternal.h"} = 1 if $interfaceName =~ /^SVGPathSeg.+/;
1140 if ($interfaceName =~ /(\w+)(Abs|Rel)$/) {
1141 $implIncludes{"$1.h"} = 1;
1143 if (!$codeGenerator->SkipIncludeHeader($implClassName)) {
1144 $implIncludes{"$implClassName.h"} = 1 ;
1145 } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($implClassName)) {
1146 my $includeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implClassName);
1147 $implIncludes{"${includeType}.h"} = 1;
1153 push(@implContent, "#import <wtf/GetPtr.h>\n\n");
1155 # add implementation accessor
1156 if ($parentImplClassName eq "Object") {
1157 push(@implContent, "#define IMPL reinterpret_cast<$implType*>(_internal)\n\n");
1159 my $baseClassWithNamespace = "WebCore::$baseClass";
1160 push(@implContent, "#define IMPL static_cast<$implClassNameWithNamespace*>(reinterpret_cast<$baseClassWithNamespace*>(_internal))\n\n");
1163 # START implementation
1164 push(@implContent, "\@implementation $className\n\n");
1166 # Only generate 'dealloc' and 'finalize' methods for direct subclasses of DOMObject.
1167 if ($parentImplClassName eq "Object") {
1168 $implIncludes{"WebCoreObjCExtras.h"} = 1;
1169 push(@implContent, "- (void)dealloc\n");
1170 push(@implContent, "{\n");
1171 push(@implContent, " if (WebCoreObjCScheduleDeallocateOnMainThread([$className class], self))\n");
1172 push(@implContent, " return;\n");
1173 push(@implContent, "\n");
1174 if ($interfaceName eq "NodeIterator") {
1175 push(@implContent, " if (_internal) {\n");
1176 push(@implContent, " [self detach];\n");
1177 push(@implContent, " IMPL->deref();\n");
1178 push(@implContent, " };\n");
1180 push(@implContent, " if (_internal)\n");
1181 push(@implContent, " IMPL->deref();\n");
1183 push(@implContent, " [super dealloc];\n");
1184 push(@implContent, "}\n\n");
1186 push(@implContent, "- (void)finalize\n");
1187 push(@implContent, "{\n");
1188 if ($interfaceName eq "NodeIterator") {
1189 push(@implContent, " if (_internal) {\n");
1190 push(@implContent, " [self detach];\n");
1191 push(@implContent, " IMPL->deref();\n");
1192 push(@implContent, " };\n");
1194 push(@implContent, " if (_internal)\n");
1195 push(@implContent, " IMPL->deref();\n");
1197 push(@implContent, " [super finalize];\n");
1198 push(@implContent, "}\n\n");
1202 %attributeNames = ();
1205 if ($numAttributes > 0) {
1206 foreach my $attribute (@{$dataNode->attributes}) {
1207 next if SkipAttribute($attribute);
1208 AddIncludesForType($attribute->signature->type);
1210 my $idlType = $codeGenerator->StripModule($attribute->signature->type);
1212 my $attributeName = $attribute->signature->name;
1213 my $attributeType = GetObjCType($attribute->signature->type);
1214 my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
1215 my $attributeClassName = GetClassName($attribute->signature->type);
1217 my $attributeInterfaceName = $attributeName;
1218 if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
1219 # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
1220 $attributeInterfaceName .= "Name";
1221 } elsif ($attributeName eq "frame") {
1222 # Special case attribute frame to be frameBorders.
1223 $attributeInterfaceName .= "Borders";
1224 } elsif ($attributeName eq "operator") {
1225 # Avoid clash with C++ keyword.
1226 $attributeInterfaceName = "_operator";
1229 $attributeNames{$attributeInterfaceName} = 1;
1232 my $getterSig = "- ($attributeType)$attributeInterfaceName\n";
1234 my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute);
1235 my $getterExpressionPrefix = "$functionName(" . join(", ", @arguments);
1237 # FIXME: Special case attribute ownerDocument to call document. This makes it return the
1238 # document when called on the document itself. Legacy behavior, see <https://bugs.webkit.org/show_bug.cgi?id=10889>.
1239 $getterExpressionPrefix =~ s/\bownerDocument\b/document/;
1241 my $hasGetterException = @{$attribute->getterExceptions};
1242 my $getterContentHead;
1243 if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {
1244 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};
1245 $implIncludes{"${implementedBy}.h"} = 1;
1246 $getterContentHead = "${implementedBy}::${getterExpressionPrefix}IMPL";
1248 $getterContentHead = "IMPL->$getterExpressionPrefix";
1251 my $getterContentTail = ")";
1253 if ($svgPropertyType) {
1254 $getterContentHead = "$getterExpressionPrefix";
1256 # TODO: Handle special case for DOMSVGLength. We do need Custom code support for this.
1257 if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
1258 $getterContentHead = "value(WebCore::SVGLengthContext(IMPL->contextElement()), ";
1262 my $attributeTypeSansPtr = $attributeType;
1263 $attributeTypeSansPtr =~ s/ \*$//; # Remove trailing " *" from pointer types.
1265 # special case for EventTarget protocol
1266 $attributeTypeSansPtr = "DOMNode" if $idlType eq "EventTarget";
1269 my @customGetterContent = ();
1270 if ($attributeTypeSansPtr eq "DOMImplementation") {
1271 # FIXME: We have to special case DOMImplementation until DOMImplementationFront is removed
1272 $getterContentHead = "kit(implementationFront(IMPL";
1273 $getterContentTail .= ")";
1274 } elsif ($attributeName =~ /(\w+)DisplayString$/) {
1275 my $attributeToDisplay = $1;
1276 $getterContentHead = "WebCore::displayString(IMPL->$attributeToDisplay(), core(self)";
1277 $implIncludes{"HitTestResult.h"} = 1;
1278 } elsif ($attributeName =~ /^absolute(\w+)URL$/) {
1280 $getterContentHead = "[self _getURLAttribute:";
1281 if ($typeOfURL eq "Link") {
1282 $getterContentTail = "\@\"href\"]";
1283 } elsif ($typeOfURL eq "Image") {
1284 if ($interfaceName eq "HTMLObjectElement") {
1285 $getterContentTail = "\@\"data\"]";
1287 $getterContentTail = "\@\"src\"]";
1289 unless ($interfaceName eq "HTMLImageElement") {
1290 push(@customGetterContent, " if (!IMPL->renderer() || !IMPL->renderer()->isImage())\n");
1291 push(@customGetterContent, " return nil;\n");
1292 $implIncludes{"RenderObject.h"} = 1;
1295 $implIncludes{"DOMPrivate.h"} = 1;
1296 } elsif ($attribute->signature->extendedAttributes->{"ObjCImplementedAsUnsignedLong"}) {
1297 $getterContentHead = "WTF::String::number(" . $getterContentHead;
1298 $getterContentTail .= ")";
1299 } elsif ($idlType eq "Date") {
1300 $getterContentHead = "kit($getterContentHead";
1301 $getterContentTail .= ")";
1302 } elsif ($svgPropertyType) {
1303 # Special case for DOMSVGNumber
1304 if ($svgPropertyType eq "float") {
1305 # Intentional leave out closing brace, it's already contained in getterContentTail
1306 $getterContentHead = "IMPL->propertyReference(";
1308 $getterContentHead = "IMPL->propertyReference().$getterContentHead";
1311 if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($idlType) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
1312 my $getter = $getterContentHead;
1313 $getter =~ s/\(\)//;
1315 my $tearOffType = GetSVGTypeWithNamespace($idlType);
1316 my $selfIsTearOffType = $codeGenerator->IsSVGTypeNeedingTearOff($implClassName);
1317 if ($selfIsTearOffType) {
1318 $implIncludes{"SVGStaticPropertyWithParentTearOff.h"} = 1;
1319 $tearOffType =~ s/SVGPropertyTearOff</SVGStaticPropertyWithParentTearOff<$implClassNameWithNamespace, /;
1321 my $getter = $getterExpressionPrefix;
1322 $getter =~ s/IMPL->//;
1324 my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter);
1326 if ($getterContentHead =~ /matrix/ and $implClassName eq "SVGTransform") {
1327 # SVGTransform offers a matrix() method for internal usage that returns an AffineTransform
1328 # and a svgMatrix() method returning a SVGMatrix, used for the bindings.
1329 $getterContentHead =~ s/matrix/svgMatrix/;
1332 $getterContentHead = "${tearOffType}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod)";
1334 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1335 $getterContentTail = "))";
1338 } elsif (($codeGenerator->IsSVGAnimatedType($implClassName) or $implClassName eq "SVGViewSpec") and $codeGenerator->IsSVGTypeNeedingTearOff($idlType)) {
1339 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
1340 $getterContentHead = "kit(static_cast<$idlTypeWithNamespace*>($getterContentHead)";
1341 $getterContentTail .= ")";
1342 } elsif (IsProtocolType($idlType) and $idlType ne "EventTarget") {
1343 $getterContentHead = "kit($getterContentHead";
1344 $getterContentTail .= ")";
1345 } elsif ($idlType eq "Color") {
1346 $getterContentHead = "WebCore::nsColor($getterContentHead";
1347 $getterContentTail .= ")";
1348 } elsif ($attribute->signature->type eq "SerializedScriptValue") {
1349 $getterContentHead = "$getterContentHead";
1350 $getterContentTail .= "->toString()";
1351 } elsif (ConversionNeeded($attribute->signature->type)) {
1352 my $type = $attribute->signature->type;
1353 if ($codeGenerator->IsSVGTypeNeedingTearOff($type) and not $implClassName =~ /List$/) {
1354 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($type);
1355 $implIncludes{"$type.h"} = 1 if not $codeGenerator->SkipIncludeHeader($type);
1356 if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($type) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
1357 $idlTypeWithNamespace =~ s/SVGPropertyTearOff</SVGStaticPropertyTearOff<$implClassNameWithNamespace, /;
1358 $implIncludes{"SVGStaticPropertyTearOff.h"} = 1;
1360 my $getter = $getterContentHead;
1361 $getter =~ s/IMPL->//;
1363 my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter);
1364 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod";
1365 $getterContentTail .= "))";
1366 } elsif ($idlTypeWithNamespace =~ /SVG(Point|PathSeg)List/) {
1367 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1368 $getterContentTail .= "))";
1369 } elsif ($idlTypeWithNamespace =~ /SVGStaticListPropertyTearOff/) {
1370 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead";
1371 $getterContentTail .= ")))";
1373 $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($getterContentHead";
1374 $getterContentTail .= ")))";
1377 $getterContentHead = "kit(WTF::getPtr($getterContentHead";
1378 $getterContentTail .= "))";
1383 if ($hasGetterException) {
1384 $getterContent = $getterContentHead . ($getterContentHead =~ /\($|, $/ ? "ec" : ", ec") . $getterContentTail;
1386 $getterContent = $getterContentHead . $getterContentTail;
1389 my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature);
1390 push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString;
1391 push(@implContent, $getterSig);
1392 push(@implContent, "{\n");
1393 push(@implContent, " $jsContextSetter\n");
1394 push(@implContent, @customGetterContent);
1395 if ($hasGetterException) {
1396 # Differentiated between when the return type is a pointer and
1397 # not for white space issue (ie. Foo *result vs. int result).
1398 if ($attributeType =~ /\*$/) {
1399 $getterContent = $attributeType . "result = " . $getterContent;
1401 $getterContent = $attributeType . " result = " . $getterContent;
1404 push(@implContent, " $exceptionInit\n");
1405 push(@implContent, " $getterContent;\n");
1406 push(@implContent, " $exceptionRaiseOnError\n");
1407 push(@implContent, " return result;\n");
1409 push(@implContent, " return $getterContent;\n");
1411 push(@implContent, "}\n");
1414 if (!$attributeIsReadonly) {
1415 # Exception handling
1416 my $hasSetterException = @{$attribute->setterExceptions};
1418 my $coreSetterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
1419 my $setterName = "set" . ucfirst($attributeInterfaceName);
1420 my $argName = "new" . ucfirst($attributeInterfaceName);
1421 my $arg = GetObjCTypeGetter($argName, $idlType);
1423 # The definition of ObjCImplementedAsUnsignedLong is flipped for the setter
1424 if ($attribute->signature->extendedAttributes->{"ObjCImplementedAsUnsignedLong"}) {
1425 $arg = "WTF::String($arg).toInt()";
1428 my $setterSig = "- (void)$setterName:($attributeType)$argName\n";
1430 push(@implContent, "\n");
1431 push(@implContent, $setterSig);
1432 push(@implContent, "{\n");
1433 push(@implContent, " $jsContextSetter\n");
1435 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1436 push(@implContent, " ASSERT($argName);\n\n");
1439 if ($idlType eq "Date") {
1440 $arg = "core(" . $arg . ")";
1443 if ($svgPropertyType) {
1444 $implIncludes{"ExceptionCode.h"} = 1;
1445 $getterContentHead = "$getterExpressionPrefix";
1446 push(@implContent, " if (IMPL->isReadOnly()) {\n");
1447 push(@implContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n");
1448 push(@implContent, " return;\n");
1449 push(@implContent, " }\n");
1450 push(@implContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1451 my $ec = $hasSetterException ? ", ec" : "";
1452 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1454 # Special case for DOMSVGNumber
1455 if ($svgPropertyType eq "float") {
1456 push(@implContent, " podImpl = $arg;\n");
1458 # FIXME: Special case for DOMSVGLength. We do need Custom code support for this.
1459 if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
1460 push(@implContent, " podImpl.$coreSetterName($arg, WebCore::SVGLengthContext(IMPL->contextElement())$ec);\n");
1462 push(@implContent, " podImpl.$coreSetterName($arg$ec);\n");
1466 if ($hasSetterException) {
1467 push(@implContent, " if (!ec)\n");
1468 push(@implContent, " IMPL->commitChange();\n");
1469 push(@implContent, " $exceptionRaiseOnError\n");
1471 push(@implContent, " IMPL->commitChange();\n");
1473 } elsif ($svgListPropertyType) {
1474 $getterContentHead = "$getterExpressionPrefix";
1475 push(@implContent, " IMPL->$coreSetterName($arg);\n");
1477 my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute);
1478 push(@arguments, $arg);
1479 push(@arguments, "ec") if $hasSetterException;
1480 push(@implContent, " $exceptionInit\n") if $hasSetterException;
1481 if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {
1482 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};
1483 $implIncludes{"${implementedBy}.h"} = 1;
1484 unshift(@arguments, "IMPL");
1485 $functionName = "${implementedBy}::${functionName}";
1487 $functionName = "IMPL->${functionName}";
1489 push(@implContent, " ${functionName}(" . join(", ", @arguments) . ");\n");
1490 push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException;
1493 push(@implContent, "}\n");
1496 push(@implContent, "#endif\n") if $attributeConditionalString;
1497 push(@implContent, "\n");
1502 if ($numFunctions > 0) {
1503 foreach my $function (@{$dataNode->functions}) {
1504 next if SkipFunction($function);
1505 AddIncludesForType($function->signature->type);
1507 my $functionName = $function->signature->name;
1508 my $returnType = GetObjCType($function->signature->type);
1509 my $hasParameters = @{$function->parameters};
1510 my $raisesExceptions = @{$function->raisesExceptions};
1512 my @parameterNames = ();
1513 my @needsAssert = ();
1514 my %needsCustom = ();
1516 my $parameterIndex = 0;
1517 my $functionSig = "- ($returnType)$functionName";
1518 foreach my $param (@{$function->parameters}) {
1519 my $paramName = $param->name;
1520 my $paramType = GetObjCType($param->type);
1522 # make a new parameter name if the original conflicts with a property name
1523 $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
1525 AddIncludesForType($param->type);
1527 my $idlType = $codeGenerator->StripModule($param->type);
1528 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1530 push(@parameterNames, $implGetter);
1531 $needsCustom{"XPathNSResolver"} = $paramName if $idlType eq "XPathNSResolver";
1532 $needsCustom{"NodeFilter"} = $paramName if $idlType eq "NodeFilter";
1533 $needsCustom{"EventListener"} = $paramName if $idlType eq "EventListener";
1534 $needsCustom{"EventTarget"} = $paramName if $idlType eq "EventTarget";
1535 $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"CustomReturn"};
1537 unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
1538 push(@needsAssert, " ASSERT($paramName);\n");
1541 if ($parameterIndex >= 1) {
1542 $functionSig .= " " . $param->name;
1545 $functionSig .= ":($paramType)$paramName";
1550 my @functionContent = ();
1551 my $caller = "IMPL";
1553 # special case the XPathNSResolver
1554 if (defined $needsCustom{"XPathNSResolver"}) {
1555 my $paramName = $needsCustom{"XPathNSResolver"};
1556 push(@functionContent, " WebCore::XPathNSResolver* nativeResolver = 0;\n");
1557 push(@functionContent, " RefPtr<WebCore::XPathNSResolver> customResolver;\n");
1558 push(@functionContent, " if ($paramName) {\n");
1559 push(@functionContent, " if ([$paramName isMemberOfClass:[DOMNativeXPathNSResolver class]])\n");
1560 push(@functionContent, " nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>($paramName));\n");
1561 push(@functionContent, " else {\n");
1562 push(@functionContent, " customResolver = WebCore::DOMCustomXPathNSResolver::create($paramName);\n");
1563 push(@functionContent, " nativeResolver = WTF::getPtr(customResolver);\n");
1564 push(@functionContent, " }\n");
1565 push(@functionContent, " }\n");
1568 # special case the EventTarget
1569 if (defined $needsCustom{"EventTarget"}) {
1570 my $paramName = $needsCustom{"EventTarget"};
1571 push(@functionContent, " DOMNode* ${paramName}ObjC = $paramName;\n");
1572 push(@functionContent, " WebCore::Node* ${paramName}Node = core(${paramName}ObjC);\n");
1573 $implIncludes{"DOMNode.h"} = 1;
1574 $implIncludes{"Node.h"} = 1;
1577 if ($function->signature->extendedAttributes->{"ObjCUseDefaultView"}) {
1578 push(@functionContent, " WebCore::DOMWindow* dv = $caller->defaultView();\n");
1579 push(@functionContent, " if (!dv)\n");
1580 push(@functionContent, " return nil;\n");
1581 $implIncludes{"DOMWindow.h"} = 1;
1585 # special case the EventListener
1586 if (defined $needsCustom{"EventListener"}) {
1587 my $paramName = $needsCustom{"EventListener"};
1588 push(@functionContent, " RefPtr<WebCore::EventListener> nativeEventListener = WebCore::ObjCEventListener::wrap($paramName);\n");
1591 # special case the NodeFilter
1592 if (defined $needsCustom{"NodeFilter"}) {
1593 my $paramName = $needsCustom{"NodeFilter"};
1594 push(@functionContent, " RefPtr<WebCore::NodeFilter> nativeNodeFilter;\n");
1595 push(@functionContent, " if ($paramName)\n");
1596 push(@functionContent, " nativeNodeFilter = WebCore::NodeFilter::create(WebCore::ObjCNodeFilterCondition::create($paramName));\n");
1599 # FIXME! We need [Custom] support for ObjC, to move these hacks into DOMSVGLength/MatrixCustom.mm
1600 my $svgLengthConvertToSpecifiedUnits = ($svgPropertyType and $svgPropertyType eq "WebCore::SVGLength" and $functionName eq "convertToSpecifiedUnits");
1602 push(@parameterNames, "WebCore::SVGLengthContext(IMPL->contextElement())") if $svgLengthConvertToSpecifiedUnits;
1603 push(@parameterNames, "ec") if $raisesExceptions;
1605 # Handle arguments that are 'SVGProperty' based (SVGAngle/SVGLength). We need to convert from SVGPropertyTearOff<Type>* to Type,
1606 # to be able to call the desired WebCore function. If the conversion fails, we can't extract Type and need to raise an exception.
1607 my $currentParameter = -1;
1608 foreach my $param (@{$function->parameters}) {
1609 $currentParameter++;
1611 my $paramName = $param->name;
1613 # make a new parameter name if the original conflicts with a property name
1614 $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
1616 my $idlType = $codeGenerator->StripModule($param->type);
1617 next if not $codeGenerator->IsSVGTypeNeedingTearOff($idlType) or $implClassName =~ /List$/;
1619 my $implGetter = GetObjCTypeGetter($paramName, $idlType);
1620 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
1622 $implIncludes{"ExceptionCode.h"} = 1;
1623 push(@functionContent, " $idlTypeWithNamespace* ${paramName}Core = $implGetter;\n");
1624 push(@functionContent, " if (!${paramName}Core) {\n");
1625 push(@functionContent, " WebCore::ExceptionCode ec = WebCore::TYPE_MISMATCH_ERR;\n");
1626 push(@functionContent, " $exceptionRaiseOnError\n");
1627 if ($returnType eq "void") {
1628 push(@functionContent, " return;\n");
1630 push(@functionContent, " return nil;\n");
1632 push(@functionContent, " }\n");
1634 # Replace the paramter core() getter, by the cached variable.
1635 splice(@parameterNames, $currentParameter, 1, "${paramName}Core->propertyReference()");
1639 if ($function->signature->extendedAttributes->{"ImplementedBy"}) {
1640 my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"};
1641 $implIncludes{"${implementedBy}.h"} = 1;
1642 unshift(@parameterNames, $caller);
1643 $content = "${implementedBy}::" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
1644 } elsif ($svgPropertyType) {
1645 $implIncludes{"ExceptionCode.h"} = 1;
1646 push(@functionContent, " if (IMPL->isReadOnly()) {\n");
1647 push(@functionContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n");
1648 if ($returnType eq "void") {
1649 push(@functionContent, " return;\n");
1651 push(@functionContent, " return nil;\n");
1653 push(@functionContent, " }\n");
1654 push(@functionContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
1655 $content = "podImpl." . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
1657 $content = "$caller->" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
1660 if ($returnType eq "void") {
1661 # Special case 'void' return type.
1662 if ($raisesExceptions) {
1663 push(@functionContent, " $exceptionInit\n");
1664 push(@functionContent, " $content;\n");
1665 if ($svgPropertyType) {
1666 push(@functionContent, " if (!ec)\n");
1667 push(@functionContent, " IMPL->commitChange();\n");
1669 push(@functionContent, " $exceptionRaiseOnError\n");
1671 push(@functionContent, " $content;\n");
1672 push(@functionContent, " IMPL->commitChange();\n") if $svgPropertyType;
1674 } elsif (defined $needsCustom{"NodeToReturn"}) {
1675 # Special case the insertBefore, replaceChild, removeChild
1676 # and appendChild functions from DOMNode
1677 my $toReturn = $needsCustom{"NodeToReturn"};
1678 if ($raisesExceptions) {
1679 push(@functionContent, " $exceptionInit\n");
1680 push(@functionContent, " if ($content)\n");
1681 push(@functionContent, " return $toReturn;\n");
1682 push(@functionContent, " $exceptionRaiseOnError\n");
1683 push(@functionContent, " return nil;\n");
1685 push(@functionContent, " if ($content)\n");
1686 push(@functionContent, " return $toReturn;\n");
1687 push(@functionContent, " return nil;\n");
1689 } elsif ($returnType eq "SerializedScriptValue") {
1692 if (ConversionNeeded($function->signature->type)) {
1693 if ($codeGenerator->IsSVGTypeNeedingTearOff($function->signature->type) and not $implClassName =~ /List$/) {
1694 my $idlTypeWithNamespace = GetSVGTypeWithNamespace($function->signature->type);
1695 $content = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($content)))";
1697 $content = "kit(WTF::getPtr($content))";
1701 if ($raisesExceptions) {
1702 # Differentiated between when the return type is a pointer and
1703 # not for white space issue (ie. Foo *result vs. int result).
1704 if ($returnType =~ /\*$/) {
1705 $content = $returnType . "result = " . $content;
1707 $content = $returnType . " result = " . $content;
1710 push(@functionContent, " $exceptionInit\n");
1711 push(@functionContent, " $content;\n");
1712 push(@functionContent, " $exceptionRaiseOnError\n");
1713 push(@functionContent, " return result;\n");
1715 push(@functionContent, " return $content;\n");
1719 my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature);
1720 push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
1722 push(@implContent, "$functionSig\n");
1723 push(@implContent, "{\n");
1724 push(@implContent, " $jsContextSetter\n");
1725 push(@implContent, @functionContent);
1726 push(@implContent, "}\n\n");
1728 push(@implContent, "#endif\n\n") if $conditionalString;
1730 # generate the old style method names with un-named parameters, these methods are deprecated
1731 if (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"ObjCLegacyUnnamedParameters"}) {
1732 my $deprecatedFunctionSig = $functionSig;
1733 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
1735 push(@implContent, "$deprecatedFunctionSig\n");
1736 push(@implContent, "{\n");
1737 push(@implContent, " $jsContextSetter\n");
1738 push(@implContent, @functionContent);
1739 push(@implContent, "}\n\n");
1747 # END implementation
1748 push(@implContent, "\@end\n");
1750 # Generate internal interfaces
1751 push(@implContent, "\n$implType* core($className *wrapper)\n");
1752 push(@implContent, "{\n");
1753 push(@implContent, " return wrapper ? reinterpret_cast<$implType*>(wrapper->_internal) : 0;\n");
1754 push(@implContent, "}\n\n");
1756 if ($parentImplClassName eq "Object") {
1757 push(@implContent, "$className *kit($implType* value)\n");
1758 push(@implContent, "{\n");
1759 push(@implContent, " $assertMainThread;\n");
1760 push(@implContent, " if (!value)\n");
1761 push(@implContent, " return nil;\n");
1762 push(@implContent, " if ($className *wrapper = getDOMWrapper(value))\n");
1763 push(@implContent, " return [[wrapper retain] autorelease];\n");
1764 if ($dataNode->extendedAttributes->{"ObjCPolymorphic"}) {
1765 push(@implContent, " $className *wrapper = [[kitClass(value) alloc] _init];\n");
1766 push(@implContent, " if (!wrapper)\n");
1767 push(@implContent, " return nil;\n");
1769 push(@implContent, " $className *wrapper = [[$className alloc] _init];\n");
1771 push(@implContent, " wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(value);\n");
1772 push(@implContent, " value->ref();\n");
1773 push(@implContent, " addDOMWrapper(wrapper, value);\n");
1774 push(@implContent, " return [wrapper autorelease];\n");
1775 push(@implContent, "}\n");
1777 push(@implContent, "$className *kit($implType* value)\n");
1778 push(@implContent, "{\n");
1779 push(@implContent, " $assertMainThread;\n");
1780 push(@implContent, " return static_cast<$className*>(kit(static_cast<WebCore::$baseClass*>(value)));\n");
1781 push(@implContent, "}\n");
1784 # - End the ifdef conditional if necessary
1785 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
1787 # - Generate dependencies.
1788 if ($writeDependencies && @ancestorInterfaceNames) {
1789 push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n");
1790 push(@depsContent, map { "$_.idl :\n" } @ancestorInterfaceNames);
1800 # Open files for writing...
1801 my $headerFileName = "$outputDir/" . $name . ".h";
1802 my $privateHeaderFileName = "$outputDir/" . $name . "Private.h";
1803 my $implFileName = "$outputDir/" . $name . ".mm";
1804 my $internalHeaderFileName = "$outputDir/" . $name . "Internal.h";
1805 my $depsFileName = "$outputDir/" . $name . ".dep";
1807 # Write public header.
1808 my $contents = join "", @headerContentHeader;
1809 map { $contents .= "\@class $_;\n" } sort keys(%headerForwardDeclarations);
1810 map { $contents .= "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
1812 my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols);
1813 $contents .= "\n" if $hasForwardDeclarations;
1814 $contents .= join "", @headerContent;
1815 $codeGenerator->UpdateFile($headerFileName, $contents);
1817 @headerContentHeader = ();
1818 @headerContent = ();
1819 %headerForwardDeclarations = ();
1820 %headerForwardDeclarationsForProtocols = ();
1822 if (@privateHeaderContent > 0) {
1823 $contents = join "", @privateHeaderContentHeader;
1824 map { $contents .= "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
1825 map { $contents .= "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
1827 $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols);
1828 $contents .= "\n" if $hasForwardDeclarations;
1829 $contents .= join "", @privateHeaderContent;
1830 $codeGenerator->UpdateFile($privateHeaderFileName, $contents);
1832 @privateHeaderContentHeader = ();
1833 @privateHeaderContent = ();
1834 %privateHeaderForwardDeclarations = ();
1835 %privateHeaderForwardDeclarationsForProtocols = ();
1838 # Write implementation file.
1840 $contents = join "", @implContentHeader;
1841 map { $contents .= "#import \"$_\"\n" } sort keys(%implIncludes);
1842 $contents .= join "", @implContent;
1843 $codeGenerator->UpdateFile($implFileName, $contents);
1845 @implContentHeader = ();
1850 if (@internalHeaderContent > 0) {
1851 $contents = join "", @internalHeaderContent;
1852 $codeGenerator->UpdateFile($internalHeaderFileName, $contents);
1854 @internalHeaderContent = ();
1857 # Write dependency file.
1859 $contents = join "", @depsContent;
1860 $codeGenerator->UpdateFile($depsFileName, $contents);