package CodeGeneratorObjC;
+use constant FileNamePrefix => "DOM";
+use File::Basename;
+use FindBin;
+
+sub ConditionalIsEnabled(\%$);
+
# Global Variables
-my $module = "";
-my $outputDir = "";
my $writeDependencies = 0;
my %publicInterfaces = ();
my $newPublicClass = 0;
my @internalHeaderContent = ();
+my @implConditionalIncludes = ();
my @implContentHeader = ();
my @implContent = ();
my %implIncludes = ();
my @depsContent = ();
+my $beginAppleCopyrightForHeaderFiles = <<END;
+// ------- Begin Apple Copyright -------
+/*
+ * Copyright (C) 2008, Apple Inc. All rights reserved.
+ *
+ * Permission is granted by Apple to use this file to the extent
+ * necessary to relink with LGPL WebKit files.
+ *
+ * No license or rights are granted by Apple expressly or by
+ * implication, estoppel, or otherwise, to Apple patents and
+ * trademarks. For the sake of clarity, no license or rights are
+ * granted by Apple expressly or by implication, estoppel, or otherwise,
+ * under any Apple patents, copyrights and trademarks to underlying
+ * implementations of any application programming interfaces (APIs)
+ * or to any functionality that is invoked by calling any API.
+ */
+
+END
+my $beginAppleCopyrightForSourceFiles = <<END;
+// ------- Begin Apple Copyright -------
+/*
+ * Copyright (C) 2008, Apple Inc. All rights reserved.
+ *
+ * No license or rights are granted by Apple expressly or by implication,
+ * estoppel, or otherwise, to Apple copyrights, patents, trademarks, trade
+ * secrets or other rights.
+ */
+
+END
+my $endAppleCopyright = <<END;
+// ------- End Apple Copyright -------
+
+END
+
# Hashes
-my %protocolTypeHash = ("XPathNSResolver" => 1, "EventListener" => 1, "EventTarget" => 1, "NodeFilter" => 1,
- "SVGLocatable" => 1, "SVGTransformable" => 1, "SVGStylable" => 1, "SVGFilterPrimitiveStandardAttributes" => 1,
- "SVGTests" => 1, "SVGLangSpace" => 1, "SVGExternalResourcesRequired" => 1, "SVGURIReference" => 1,
- "SVGZoomAndPan" => 1, "SVGFitToViewBox" => 1, "SVGAnimatedPathData" => 1, "ElementTimeControl" => 1);
+my %protocolTypeHash = ("XPathNSResolver" => 1, "EventListener" => 1, "EventTarget" => 1, "NodeFilter" => 1);
my %nativeObjCTypeHash = ("URL" => 1, "Color" => 1);
# FIXME: this should be replaced with a function that recurses up the tree
my %baseTypeHash = ("Object" => 1, "Node" => 1, "NodeList" => 1, "NamedNodeMap" => 1, "DOMImplementation" => 1,
"Event" => 1, "CSSRule" => 1, "CSSValue" => 1, "StyleSheet" => 1, "MediaList" => 1,
"Counter" => 1, "Rect" => 1, "RGBColor" => 1, "XPathExpression" => 1, "XPathResult" => 1,
- "NodeIterator" => 1, "TreeWalker" => 1, "AbstractView" => 1, "Blob" => 1,
- "SVGAngle" => 1, "SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1, "SVGAnimatedEnumeration" => 1,
- "SVGAnimatedInteger" => 1, "SVGAnimatedLength" => 1, "SVGAnimatedLengthList" => 1,
- "SVGAnimatedNumber" => 1, "SVGAnimatedNumberList" => 1,
- "SVGAnimatedPreserveAspectRatio" => 1, "SVGAnimatedRect" => 1, "SVGAnimatedString" => 1,
- "SVGAnimatedTransformList" => 1, "SVGLength" => 1, "SVGLengthList" => 1, "SVGMatrix" => 1,
- "SVGNumber" => 1, "SVGNumberList" => 1, "SVGPathSeg" => 1, "SVGPathSegList" => 1, "SVGPoint" => 1,
- "SVGPointList" => 1, "SVGPreserveAspectRatio" => 1, "SVGRect" => 1, "SVGRenderingIntent" => 1,
- "SVGStringList" => 1, "SVGTransform" => 1, "SVGTransformList" => 1, "SVGUnitTypes" => 1);
+ "NodeIterator" => 1, "TreeWalker" => 1, "AbstractView" => 1, "Blob" => 1);
# Constants
-my $buildingForTigerOrEarlier = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} <= 10.4;
-my $buildingForLeopardOrLater = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} >= 10.5;
+my $buildingForIPhone = defined $ENV{PLATFORM_NAME} && ($ENV{PLATFORM_NAME} eq "iphoneos" or $ENV{PLATFORM_NAME} eq "iphonesimulator");
+my $nullableInit = "bool isNull = false;";
my $exceptionInit = "WebCore::ExceptionCode ec = 0;";
my $jsContextSetter = "WebCore::JSMainThreadNullState state;";
my $exceptionRaiseOnError = "WebCore::raiseOnDOMError(ec);";
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
my $reference = { };
$codeGenerator = shift;
- $outputDir = shift;
- shift; # $outputHeadersDir
shift; # $useLayerOnTop
shift; # $preprocessor
$writeDependencies = shift;
return $reference;
}
-sub finish
-{
- my $object = shift;
-}
-
sub ReadPublicInterfaces
{
my $class = shift;
my $actualSuperClass;
%publicInterfaces = ();
- my $fileName = "WebCore/bindings/objc/PublicDOMInterfaces.h";
+ my @args = qw(-E -P -x objective-c);
+
+ push(@args, "-I" . $ENV{BUILT_PRODUCTS_DIR} . "/usr/local/include") if $ENV{BUILT_PRODUCTS_DIR};
+ push(@args, "-isysroot", $ENV{SDKROOT}) if $ENV{SDKROOT};
+
+ my $bindingsDir = dirname($FindBin::Bin);
+ my $fileName = "$bindingsDir/objc/PublicDOMInterfaces.h";
my $gccLocation = "";
if ($ENV{CC}) {
$gccLocation = $ENV{CC};
} elsif (($Config::Config{'osname'}) =~ /solaris/i) {
$gccLocation = "/usr/sfw/bin/gcc";
+ } elsif (-x "/usr/bin/clang") {
+ $gccLocation = "/usr/bin/clang";
} else {
$gccLocation = "/usr/bin/gcc";
}
- open FILE, "-|", $gccLocation, "-E", "-P", "-x", "objective-c",
+
+ open FILE, "-|", $gccLocation, @args,
(map { "-D$_" } split(/ +/, $defines)), "-DOBJC_CODE_GENERATION", $fileName or die "Could not open $fileName";
my @documentContent = <FILE>;
close FILE;
$interfaceAvailabilityVersion = $2 if defined $2;
$found = 1;
next;
- } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*<[^>]+>\s*([A-Z0-9_]*)/) {
+ } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*<[^>]+>\s*([A-Z0-9_()]*)/) {
$interfaceAvailabilityVersion = $1 if defined $1;
$found = 1;
next;
$line =~ s/\s+$//;
my $availabilityMacro = "";
- $line =~ s/\s([A-Z0-9_]+)\s*;$/;/;
+ $line =~ s/\s([A-Z0-9_(), ]+)\s*;$/;/;
$availabilityMacro = $1 if defined $1;
$publicInterfaces{$line} = $availabilityMacro if length $line;
# If this class was not found in PublicDOMInterfaces.h then it should be considered as an entirely new public class.
$newPublicClass = !$found;
- $interfaceAvailabilityVersion = "WEBKIT_VERSION_LATEST" if $newPublicClass;
+ $interfaceAvailabilityVersion = "TBD" if $newPublicClass;
}
-sub GenerateConditionalString
+sub AddMethodsConstantsAndAttributesFromParentInterfaces
{
- my $node = shift;
- my $conditional = $node->extendedAttributes->{"Conditional"};
- if ($conditional) {
- if ($conditional =~ /&/) {
- return "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
- } elsif ($conditional =~ /\|/) {
- return "ENABLE(" . join(") || ENABLE(", split(/\|/, $conditional)) . ")";
- } else {
- return "ENABLE(" . $conditional . ")";
+ # Add to $interface all of its inherited interface members, except for those
+ # inherited through $interface's first listed parent. If an array reference
+ # is passed in as $parents, the names of all ancestor interfaces visited
+ # will be appended to the array. If $collectDirectParents is true, then
+ # even the names of $interface's first listed parent and its ancestors will
+ # be appended to $parents.
+
+ my $interface = shift;
+ my $parents = shift;
+ my $collectDirectParents = shift;
+
+ my $first = 1;
+
+ $codeGenerator->ForAllParents($interface, sub {
+ my $currentInterface = shift;
+
+ if ($first) {
+ # Ignore first parent class, already handled by the generation itself.
+ $first = 0;
+
+ if ($collectDirectParents) {
+ # Just collect the names of the direct ancestor interfaces,
+ # if necessary.
+ push(@$parents, $currentInterface->name);
+ $codeGenerator->ForAllParents($currentInterface, sub {
+ my $currentInterface = shift;
+ push(@$parents, $currentInterface->name);
+ }, undef);
+ }
+
+ # Prune the recursion here.
+ return 'prune';
}
- } else {
- return "";
- }
+
+ # Collect the name of this additional parent.
+ push(@$parents, $currentInterface->name) if $parents;
+
+ print " | |> -> Inheriting "
+ . @{$currentInterface->constants} . " constants, "
+ . @{$currentInterface->functions} . " functions, "
+ . @{$currentInterface->attributes} . " attributes...\n | |>\n" if $verbose;
+
+ # Add this parent's members to $interface.
+ push(@{$interface->constants}, @{$currentInterface->constants});
+ push(@{$interface->functions}, @{$currentInterface->functions});
+ push(@{$interface->attributes}, @{$currentInterface->attributes});
+ });
}
-# Params: 'domClass' struct
sub GenerateInterface
{
my $object = shift;
- my $dataNode = shift;
+ my $interface = shift;
my $defines = shift;
$fatalError = 0;
- my $name = $dataNode->name;
+ my $name = $interface->name;
my $className = GetClassName($name);
- my $parentClassName = "DOM" . GetParentImplClassName($dataNode);
- $isProtocol = $dataNode->extendedAttributes->{ObjCProtocol};
- $noImpl = $dataNode->extendedAttributes->{ObjCCustomImplementation} || $isProtocol;
+ my $parentClassName = "DOM" . GetParentImplClassName($interface);
+ $isProtocol = $interface->extendedAttributes->{ObjCProtocol};
+ $noImpl = $interface->extendedAttributes->{ObjCCustomImplementation} || $isProtocol;
ReadPublicInterfaces($className, $parentClassName, $defines, $isProtocol);
# Start actual generation..
- $object->GenerateHeader($dataNode);
- $object->GenerateImplementation($dataNode) unless $noImpl;
-
- # Write changes.
- $object->WriteData("DOM" . $name);
+ $object->GenerateHeader($interface, $defines);
+ $object->GenerateImplementation($interface) unless $noImpl;
# Check for missing public API
if (keys %publicInterfaces > 0) {
$fatalError = 1;
}
- die if $fatalError;
-}
-
-# Params: 'idlDocument' struct
-sub GenerateModule
-{
- my $object = shift;
- my $dataNode = shift;
-
- $module = $dataNode->module;
+ # FIXME: This should not need to be an exception.
+ # ObjCCustomImplementation doesn't work with CMake right now.
+ # https://bugs.webkit.org/show_bug.cgi?id=135860
+ die if $fatalError && $className ne "DOMAbstractView";
}
sub GetClassName
{
- my $name = $codeGenerator->StripModule(shift);
+ my $name = shift;
# special cases
return "NSString" if $codeGenerator->IsStringType($name) or $name eq "SerializedScriptValue";
+ return "CGColorRef" if $name eq "Color" and $buildingForIPhone;
return "NS$name" if IsNativeObjCType($name);
return "BOOL" if $name eq "boolean";
+ return "unsigned char" if $name eq "octet";
+ return "char" if $name eq "byte";
return "unsigned" if $name eq "unsigned long";
return "int" if $name eq "long";
return "NSTimeInterval" if $name eq "Date";
sub GetImplClassName
{
- my $name = $codeGenerator->StripModule(shift);
+ my $name = shift;
return "DOMImplementationFront" if $name eq "DOMImplementation";
return "DOMWindow" if $name eq "AbstractView";
sub GetParentImplClassName
{
- my $dataNode = shift;
+ my $interface = shift;
- return "Object" if @{$dataNode->parents} eq 0;
+ return "Object" if @{$interface->parents} eq 0;
- my $parent = $codeGenerator->StripModule($dataNode->parents(0));
+ my $parent = $interface->parents(0);
# special cases
return "Object" if $parent eq "HTMLCollection";
sub GetParentAndProtocols
{
- my $dataNode = shift;
- my $numParents = @{$dataNode->parents};
+ my $interface = shift;
+ my $numParents = @{$interface->parents};
my $parent = "";
my @protocols = ();
if ($numParents eq 0) {
if ($isProtocol) {
push(@protocols, "NSObject");
- push(@protocols, "NSCopying") if $dataNode->name eq "EventTarget";
+ push(@protocols, "NSCopying") if $interface->name eq "EventTarget";
} else {
$parent = "DOMObject";
}
} elsif ($numParents eq 1) {
- my $parentName = $codeGenerator->StripModule($dataNode->parents(0));
+ my $parentName = $interface->parents(0);
if ($isProtocol) {
die "Parents of protocols must also be protocols." unless IsProtocolType($parentName);
push(@protocols, "DOM" . $parentName);
}
}
} else {
- my @parents = @{$dataNode->parents};
- my $firstParent = $codeGenerator->StripModule(shift(@parents));
+ my @parents = @{$interface->parents};
+ my $firstParent = shift(@parents);
if (IsProtocolType($firstParent)) {
push(@protocols, "DOM" . $firstParent);
if (!$isProtocol) {
}
foreach my $parentName (@parents) {
- $parentName = $codeGenerator->StripModule($parentName);
die "Everything past the first class should be a protocol!" unless IsProtocolType($parentName);
push(@protocols, "DOM" . $parentName);
$parent = shift;
return $parent if $parent eq "Object" or IsBaseType($parent);
- return "Event" if $parent eq "UIEvent";
- return "CSSValue" if $parent eq "SVGColor" or $parent eq "CSSValueList";
+ return "Event" if $parent eq "UIEvent" or $parent eq "MouseEvent";
+ return "CSSValue" if $parent eq "CSSValueList";
return "Node";
}
return 0;
}
+sub IsCoreFoundationType
+{
+ my $type = shift;
+
+ return 1 if $type =~ /^(CF|CG)[A-Za-z]+Ref$/;
+ return 0;
+}
+
+sub SkipFunction
+{
+ my $function = shift;
+
+ return 1 if $codeGenerator->GetSequenceType($function->signature->type);
+ return 1 if $codeGenerator->GetArrayType($function->signature->type);
+
+ foreach my $param (@{$function->parameters}) {
+ return 1 if $codeGenerator->GetSequenceType($param->type);
+ return 1 if $codeGenerator->GetArrayType($param->type);
+ return 1 if $param->extendedAttributes->{"Clamp"};
+ }
+
+ return 0;
+}
+
+sub SkipAttribute
+{
+ my $attribute = shift;
+ my $type = $attribute->signature->type;
+
+ $codeGenerator->AssertNotSequenceType($type);
+ return 1 if $codeGenerator->GetArrayType($type);
+ return 1 if $codeGenerator->IsTypedArrayType($type);
+ return 1 if $codeGenerator->IsEnumType($type);
+ return 1 if $attribute->isStatic;
+
+ # This is for DynamicsCompressorNode.idl
+ if ($attribute->signature->name eq "release") {
+ return 1;
+ }
+
+ return 0;
+}
+
sub GetObjCType
{
my $type = shift;
my $name = GetClassName($type);
+ return "double" if $type eq "unrestricted double";
+ return "float" if $type eq "unrestricted float";
return "id <$name>" if IsProtocolType($type);
return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
return "unsigned short" if $type eq "CompareHow";
+ return $name if IsCoreFoundationType($name);
return "$name *";
}
sub GetPropertyAttributes
{
- my $type = $codeGenerator->StripModule(shift);
+ my $type = shift;
my $readOnly = shift;
my @attributes = ();
# FIXME: <rdar://problem/5049934> Consider using 'nonatomic' on the DOM @property declarations.
if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) {
push(@attributes, "copy");
- } elsif ($codeGenerator->IsSVGAnimatedType($type)) {
- push(@attributes, "retain");
} elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow") {
- push(@attributes, "retain");
+ push(@attributes, "strong");
}
return "" unless @attributes > 0;
- return "(" . join(", ", @attributes) . ")";
+ return " (" . join(", ", @attributes) . ")";
}
sub ConversionNeeded
{
- my $type = $codeGenerator->StripModule(shift);
+ my $type = shift;
return !$codeGenerator->IsNonPointerType($type) && !$codeGenerator->IsStringType($type) && !IsNativeObjCType($type);
}
sub GetObjCTypeGetter
{
my $argName = shift;
- my $type = $codeGenerator->StripModule(shift);
+ my $type = shift;
return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
return $argName . "Node" if $type eq "EventTarget";
sub AddForwardDeclarationsForType
{
- my $type = $codeGenerator->StripModule(shift);
+ my $type = shift;
my $public = shift;
- return if $codeGenerator->IsNonPointerType($type) ;
+ return if $codeGenerator->IsNonPointerType($type);
+ return if $codeGenerator->GetSequenceType($type);
+ return if $codeGenerator->GetArrayType($type);
my $class = GetClassName($type);
sub AddIncludesForType
{
- my $type = $codeGenerator->StripModule(shift);
+ my $type = shift;
return if $codeGenerator->IsNonPointerType($type);
+ return if $codeGenerator->GetSequenceType($type);
+ return if $codeGenerator->GetArrayType($type);
if (IsNativeObjCType($type)) {
if ($type eq "Color") {
- $implIncludes{"ColorMac.h"} = 1;
+ if ($buildingForIPhone) {
+ $implIncludes{"ColorSpace.h"} = 1;
+ } else {
+ $implIncludes{"ColorMac.h"} = 1;
+ }
}
return;
}
if ($codeGenerator->IsStringType($type)) {
- $implIncludes{"KURL.h"} = 1;
+ $implIncludes{"URL.h"} = 1;
return;
}
return;
}
- if ($codeGenerator->IsSVGAnimatedType($type)) {
- $implIncludes{"${type}.h"} = 1;
- $implIncludes{"DOM${type}Internal.h"} = 1;
- return;
- }
-
if ($type =~ /(\w+)(Abs|Rel)$/) {
$implIncludes{"$1.h"} = 1;
$implIncludes{"DOM${type}Internal.h"} = 1;
}
# FIXME: won't compile without these
- $implIncludes{"CSSMutableStyleDeclaration.h"} = 1 if $type eq "CSSStyleDeclaration";
+ $implIncludes{"CSSImportRule.h"} = 1 if $type eq "CSSRule";
+ $implIncludes{"StyleProperties.h"} = 1 if $type eq "CSSStyleDeclaration";
$implIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList";
# Default, include the same named file (the implementation) and the same name prefixed with "DOM".
- $implIncludes{"$type.h"} = 1 if not $codeGenerator->AvoidInclusionOfType($type);
+ $implIncludes{"$type.h"} = 1 if not $codeGenerator->SkipIncludeHeader($type);
$implIncludes{"DOM${type}Internal.h"} = 1;
}
-sub GetSVGTypeWithNamespace
-{
- my $type = shift;
- my $typeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($type);
-
- # Special case for DOMSVGNumber
- $typeWithNamespace =~ s/</\<WebCore::/ unless $type eq "SVGNumber";
- return $typeWithNamespace;
-}
-
-sub GetSVGPropertyTypes
+sub ConditionalIsEnabled(\%$)
{
- my $implType = shift;
-
- my $svgPropertyType;
- my $svgListPropertyType;
- my $svgNativeType;
-
- return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $implType =~ /SVG/;
+ my $defines = shift;
+ my $conditional = shift;
- $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($implType);
- return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType;
+ return 1 if !$conditional;
- # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType>
- $svgNativeType = "WebCore::$svgNativeType ";
- $svgNativeType =~ s/</\<WebCore::/ if not $svgNativeType =~ /float/;
+ my $operator = ($conditional =~ /&/ ? '&' : ($conditional =~ /\|/ ? '|' : ''));
+ if (!$operator) {
+ return exists($defines->{"ENABLE_" . $conditional});
+ }
- my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implType);
- if ($svgNativeType =~ /SVGPropertyTearOff/) {
- if ($svgWrappedNativeType eq "float") {
- # Special case for DOMSVGNumber
- $svgPropertyType = $svgWrappedNativeType;
- } else {
- $svgPropertyType = "WebCore::$svgWrappedNativeType";
- $svgPropertyType =~ s/</\<WebCore::/;
- }
- } elsif ($svgNativeType =~ /SVGListPropertyTearOff/ or $svgNativeType =~ /SVGStaticListPropertyTearOff/) {
- $svgListPropertyType = "WebCore::$svgWrappedNativeType";
- $svgListPropertyType =~ s/</\<WebCore::/;
- } elsif ($svgNativeType =~ /SVGTransformListPropertyTearOff/) {
- $svgListPropertyType = "WebCore::$svgWrappedNativeType";
- $svgListPropertyType =~ s/</\<WebCore::/;
- } elsif ($svgNativeType =~ /SVGPathSegListPropertyTearOff/) {
- $svgListPropertyType = "WebCore::$svgWrappedNativeType";
- $svgListPropertyType =~ s/</\<WebCore::/;
+ my @conditions = split(/\Q$operator\E/, $conditional);
+ foreach (@conditions) {
+ my $enable = "ENABLE_" . $_;
+ return 0 if ($operator eq '&') and !exists($defines->{$enable});
+ return 1 if ($operator eq '|') and exists($defines->{$enable});
}
- return ($svgPropertyType, $svgListPropertyType, $svgNativeType);
+ return $operator eq '&';
}
sub GenerateHeader
{
my $object = shift;
- my $dataNode = shift;
+ my $interface = shift;
+ my $defines = shift;
+
+ my %definesRef = map { $_ => 1 } split(/\s+/, $defines);
- my $interfaceName = $dataNode->name;
+ my $interfaceName = $interface->name;
my $className = GetClassName($interfaceName);
my $parentName = "";
my @protocolsToImplement = ();
- ($parentName, @protocolsToImplement) = GetParentAndProtocols($dataNode);
+ ($parentName, @protocolsToImplement) = GetParentAndProtocols($interface);
- my $numConstants = @{$dataNode->constants};
- my $numAttributes = @{$dataNode->attributes};
- my $numFunctions = @{$dataNode->functions};
+ my $numConstants = @{$interface->constants};
+ my $numAttributes = @{$interface->attributes};
+ my $numFunctions = @{$interface->functions};
# - Add default header template
- @headerContentHeader = split("\r", $headerLicenseTemplate);
+ if ($interface->extendedAttributes->{"AppleCopyright"}) {
+ @headerContentHeader = split("\r", $beginAppleCopyrightForHeaderFiles);
+ } else {
+ @headerContentHeader = split("\r", $headerLicenseTemplate);
+ }
push(@headerContentHeader, "\n");
# - INCLUDES -
$includedWebKitAvailabilityHeader = 1;
}
- push(@headerContentHeader, "#import <JavaScriptCore/WebKitAvailability.h>\n") unless $includedWebKitAvailabilityHeader;
-
- my $interfaceAvailabilityVersionCheck = "#if WEBKIT_VERSION_MAX_ALLOWED >= $interfaceAvailabilityVersion\n\n";
+ push(@headerContentHeader, "#import <WebCore/WebKitAvailability.h>\n") unless $includedWebKitAvailabilityHeader;
push(@headerContentHeader, "\n");
- push(@headerContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
# - Add constants.
if ($numConstants > 0) {
my @headerConstants = ();
+ my @constants = @{$interface->constants};
+ my $combinedConstants = "";
# FIXME: we need a way to include multiple enums.
- foreach my $constant (@{$dataNode->constants}) {
+ foreach my $constant (@constants) {
my $constantName = $constant->name;
my $constantValue = $constant->value;
-
- my $output = " DOM_" . $constantName . " = " . $constantValue;
- push(@headerConstants, $output);
+ my $notLast = $constant ne $constants[-1];
+
+ if (ConditionalIsEnabled(%definesRef, $constant->extendedAttributes->{"Conditional"})) {
+ $combinedConstants .= " DOM_$constantName = $constantValue";
+ $combinedConstants .= "," if $notLast;
+ if ($notLast) {
+ $combinedConstants .= "\n";
+ }
+ }
}
- my $combinedConstants = join(",\n", @headerConstants);
-
# FIXME: the formatting of the enums should line up the equal signs.
# FIXME: enums are unconditionally placed in the public header.
push(@headerContent, "enum {\n");
push(@headerContent, $combinedConstants);
- push(@headerContent, "\n};\n\n");
+ push(@headerContent, "\n}");
+ push(@headerContent, " WEBKIT_ENUM_AVAILABLE_MAC($interfaceAvailabilityVersion)") if length $interfaceAvailabilityVersion;
+ push(@headerContent, ";\n\n");
}
# - Begin @interface or @protocol
$interfaceDeclaration .= " <" . join(", ", @protocolsToImplement) . ">" if @protocolsToImplement > 0;
$interfaceDeclaration .= "\n";
+ push(@headerContent, "WEBKIT_CLASS_AVAILABLE_MAC($interfaceAvailabilityVersion)\n") if length $interfaceAvailabilityVersion;
push(@headerContent, $interfaceDeclaration);
my @headerAttributes = ();
# - Add attribute getters/setters.
if ($numAttributes > 0) {
- foreach my $attribute (@{$dataNode->attributes}) {
+ foreach my $attribute (@{$interface->attributes}) {
+ next if SkipAttribute($attribute);
my $attributeName = $attribute->signature->name;
if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
}
my $attributeType = GetObjCType($attribute->signature->type);
- my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
+ my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attribute->isReadOnly);
- my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attributeIsReadonly);
- # Some SVGFE*Element.idl use 'operator' as attribute name, rewrite as '_operator' to avoid clashes with C/C++
- $attributeName =~ s/operator/_operator/ if ($attributeName =~ /operator/);
$property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName;
my $publicInterfaceKey = $property . ";";
+ # FIXME: This only works for the getter, but not the setter. Need to refactor this code.
+ if ($buildingForTigerOrEarlier && !$buildingForIPhone || IsCoreFoundationType($attributeType)) {
+ $publicInterfaceKey = "- (" . $attributeType . ")" . $attributeName . ";";
+ }
+
my $availabilityMacro = "";
if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
$availabilityMacro = $publicInterfaces{$publicInterfaceKey};
}
- $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
-
my $declarationSuffix = ";\n";
$declarationSuffix = " $availabilityMacro;\n" if length $availabilityMacro;
$fatalError = 1;
}
- if ($buildingForLeopardOrLater) {
+ if (!IsCoreFoundationType($attributeType)) {
$property .= $declarationSuffix;
push(@headerAttributes, $property) if $public;
push(@privateHeaderAttributes, $property) unless $public;
- } else {
- my $attributeConditionalString = GenerateConditionalString($attribute->signature);
- if ($attributeConditionalString) {
- push(@headerAttributes, "#if ${attributeConditionalString}\n") if $public;
- push(@privateHeaderAttributes, "#if ${attributeConditionalString}\n") unless $public;
- }
-
+ } elsif (ConditionalIsEnabled(%definesRef, $attribute->signature->extendedAttributes->{"Conditional"})) {
# - GETTER
my $getter = "- (" . $attributeType . ")" . $attributeName . $declarationSuffix;
push(@headerAttributes, $getter) if $public;
push(@privateHeaderAttributes, $getter) unless $public;
-
+
# - SETTER
- if (!$attributeIsReadonly) {
+ if (!$attribute->isReadOnly) {
my $setter = "- (void)$setterName(" . $attributeType . ")new" . ucfirst($attributeName) . $declarationSuffix;
push(@headerAttributes, $setter) if $public;
push(@privateHeaderAttributes, $setter) unless $public;
}
-
- if ($attributeConditionalString) {
- push(@headerAttributes, "#endif\n") if $public;
- push(@privateHeaderAttributes, "#endif\n") unless $public;
- }
}
}
# - Add functions.
if ($numFunctions > 0) {
- foreach my $function (@{$dataNode->functions}) {
+ my %inAppleCopyright = (public => 0, private => 0);
+ foreach my $function (@{$interface->functions}) {
+ next if SkipFunction($function);
+ next if ($function->signature->name eq "set" and $interface->extendedAttributes->{"TypedArray"});
my $functionName = $function->signature->name;
my $returnType = GetObjCType($function->signature->type);
- my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"});
+ my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"ObjCLegacyUnnamedParameters"});
+ my $needsAppleCopyright = $function->signature->extendedAttributes->{"AppleCopyright"};
my $numberOfParameters = @{$function->parameters};
my %typesToForwardDeclare = ($function->signature->type => 1);
$typesToForwardDeclare{$param->type} = 1;
if ($parameterIndex >= 1) {
- my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
- $paramPrefix = $paramName unless defined($paramPrefix);
- $functionSig .= " $paramPrefix";
- $methodName .= $paramPrefix;
+ $functionSig .= " $paramName";
+ $methodName .= $paramName;
}
$functionSig .= ":($paramType)$paramName";
$availabilityMacro = $publicInterfaces{$publicInterfaceKey};
}
- $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;
-
my $functionDeclaration = $functionSig;
$functionDeclaration .= " " . $availabilityMacro if length $availabilityMacro;
$functionDeclaration .= ";\n";
AddForwardDeclarationsForType($type, $public) unless $public and $needsDeprecatedVersion;
}
- push(@headerFunctions, $functionDeclaration) if $public;
- push(@privateHeaderFunctions, $functionDeclaration) unless $public;
+ if ($needsAppleCopyright) {
+ if (!$inAppleCopyright{$public ? "public" : "private"}) {
+ push(@headerFunctions, $beginAppleCopyrightForHeaderFiles) if $public;
+ push(@privateHeaderFunctions, $beginAppleCopyrightForHeaderFiles) unless $public;
+ $inAppleCopyright{$public ? "public" : "private"} = 1;
+ }
+ } elsif ($inAppleCopyright{$public ? "public" : "private"}) {
+ push(@headerFunctions, $endAppleCopyright) if $public;
+ push(@privateHeaderFunctions, $endAppleCopyright) unless $public;
+ $inAppleCopyright{$public ? "public" : "private"} = 0;
+ }
+
+ if (ConditionalIsEnabled(%definesRef, $function->signature->extendedAttributes->{"Conditional"})) {
+ push(@headerFunctions, $functionDeclaration) if $public;
+ push(@privateHeaderFunctions, $functionDeclaration) unless $public;
- # generate the old style method names with un-named parameters, these methods are deprecated
- if ($needsDeprecatedVersion) {
- my $deprecatedFunctionSig = $functionSig;
- $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
+ # generate the old style method names with un-named parameters, these methods are deprecated
+ if ($needsDeprecatedVersion) {
+ my $deprecatedFunctionSig = $functionSig;
+ $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
- $publicInterfaceKey = $deprecatedFunctionSig . ";";
+ $publicInterfaceKey = $deprecatedFunctionSig . ";";
- my $availabilityMacro = "AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0";
- if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
- $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
- }
+ my $availabilityMacro = "WEBKIT_DEPRECATED_MAC(10_4, 10_5)";
+ if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
+ $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
+ }
- $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if $buildingForTigerOrEarlier;
+ $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
- $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
+ push(@deprecatedHeaderFunctions, $functionDeclaration);
- push(@deprecatedHeaderFunctions, $functionDeclaration);
+ unless (defined $publicInterfaces{$publicInterfaceKey}) {
+ warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the ObjCLegacyUnnamedParameters IDL attribute removed";
+ $fatalError = 1;
+ }
- unless (defined $publicInterfaces{$publicInterfaceKey}) {
- warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the OldStyleObjC IDL attribute removed";
- $fatalError = 1;
+ delete $publicInterfaces{$publicInterfaceKey};
}
-
- delete $publicInterfaces{$publicInterfaceKey};
}
}
+ push(@headerFunctions, $endAppleCopyright) if $inAppleCopyright{"public"};
+ push(@privateHeaderFunctions, $endAppleCopyright) if $inAppleCopyright{"private"};
+
if (@headerFunctions > 0) {
- push(@headerContent, "\n") if $buildingForLeopardOrLater and @headerAttributes > 0;
+ push(@headerContent, "\n") if @headerAttributes > 0;
push(@headerContent, @headerFunctions);
}
}
push(@headerContent, "\@end\n");
}
- push(@headerContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
+ if ($interface->extendedAttributes->{"AppleCopyright"}) {
+ push(@headerContent, split("\r", $endAppleCopyright));
+ }
- my %alwaysGenerateForNoSVGBuild = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement);
+ my %alwaysGenerate = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement);
- if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0 or exists $alwaysGenerateForNoSVGBuild{$className}) {
+ if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0 or exists $alwaysGenerate{$className}) {
# - Private category @interface
- @privateHeaderContentHeader = split("\r", $headerLicenseTemplate);
+ if ($interface->extendedAttributes->{"AppleCopyright"}) {
+ @privateHeaderContentHeader = split("\r", $beginAppleCopyrightForHeaderFiles);
+ } else {
+ @privateHeaderContentHeader = split("\r", $headerLicenseTemplate);
+ }
push(@privateHeaderContentHeader, "\n");
my $classHeaderName = GetClassHeaderName($className);
push(@privateHeaderContentHeader, "#import <WebCore/$classHeaderName.h>\n\n");
- push(@privateHeaderContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
@privateHeaderContent = ();
push(@privateHeaderContent, "\@interface $className (" . $className . "Private)\n");
push(@privateHeaderContent, @privateHeaderAttributes) if @privateHeaderAttributes > 0;
- push(@privateHeaderContent, "\n") if $buildingForLeopardOrLater and @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0;
+ push(@privateHeaderContent, "\n") if @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0;
push(@privateHeaderContent, @privateHeaderFunctions) if @privateHeaderFunctions > 0;
push(@privateHeaderContent, "\@end\n");
- push(@privateHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
+ if ($interface->extendedAttributes->{"AppleCopyright"}) {
+ push(@privateHeaderContent, split("\r", $endAppleCopyright));
+ }
}
unless ($isProtocol) {
my $implClassNameWithNamespace = "WebCore::" . $implClassName;
my $implType = $implClassNameWithNamespace;
- my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
- $implType = $svgNativeType if $svgNativeType;
# Generate interface definitions.
- @internalHeaderContent = split("\r", $implementationLicenseTemplate);
+ if ($interface->extendedAttributes->{"AppleCopyright"}) {
+ @internalHeaderContent = split("\r", $beginAppleCopyrightForHeaderFiles);
+ } else {
+ @internalHeaderContent = split("\r", $implementationLicenseTemplate);
+ }
push(@internalHeaderContent, "\n#import <WebCore/$className.h>\n\n");
- push(@internalHeaderContent, "#import <WebCore/SVGAnimatedPropertyTearOff.h>\n\n") if $svgPropertyType;
- if ($svgListPropertyType) {
- push(@internalHeaderContent, "#import <WebCore/SVGAnimatedListPropertyTearOff.h>\n\n");
- push(@internalHeaderContent, "#import <WebCore/SVGTransformListPropertyTearOff.h>\n\n") if $svgListPropertyType =~ /SVGTransformList/;
- push(@internalHeaderContent, "#import <WebCore/SVGPathSegListPropertyTearOff.h>\n\n") if $svgListPropertyType =~ /SVGPathSegList/;
- }
- push(@internalHeaderContent, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion;
if ($interfaceName eq "Node") {
push(@internalHeaderContent, "\@protocol DOMEventTarget;\n\n");
my $startedNamespace = 0;
- if ($codeGenerator->IsSVGAnimatedType($interfaceName)) {
- push(@internalHeaderContent, "#import <WebCore/$implClassName.h>\n\n");
+ push(@internalHeaderContent, "namespace WebCore {\n");
+ $startedNamespace = 1;
+ if ($interfaceName eq "Node") {
+ push(@internalHeaderContent, "class EventTarget;\n class Node;\n");
} else {
- push(@internalHeaderContent, "namespace WebCore {\n");
- $startedNamespace = 1;
- if ($interfaceName eq "Node") {
- push(@internalHeaderContent, " class EventTarget;\n class Node;\n");
- } else {
- push(@internalHeaderContent, " class $implClassName;\n");
- }
- push(@internalHeaderContent, "}\n\n");
+ push(@internalHeaderContent, "class $implClassName;\n");
}
+ push(@internalHeaderContent, "}\n\n");
push(@internalHeaderContent, "$implType* core($className *);\n");
push(@internalHeaderContent, "$className *kit($implType*);\n");
- if ($dataNode->extendedAttributes->{Polymorphic}) {
+ if ($interface->extendedAttributes->{"ObjCPolymorphic"}) {
push(@internalHeaderContent, "Class kitClass($implType*);\n");
}
if ($interfaceName eq "Node") {
push(@internalHeaderContent, "id <DOMEventTarget> kit(WebCore::EventTarget*);\n");
}
-
- push(@internalHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
}
}
sub GenerateImplementation
{
my $object = shift;
- my $dataNode = shift;
+ my $interface = shift;
my @ancestorInterfaceNames = ();
- if (@{$dataNode->parents} > 1) {
- $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@ancestorInterfaceNames);
+ if (@{$interface->parents} > 1) {
+ AddMethodsConstantsAndAttributesFromParentInterfaces($interface, \@ancestorInterfaceNames);
}
- my $interfaceName = $dataNode->name;
+ my $interfaceName = $interface->name;
my $className = GetClassName($interfaceName);
my $implClassName = GetImplClassName($interfaceName);
- my $parentImplClassName = GetParentImplClassName($dataNode);
+ my $parentImplClassName = GetParentImplClassName($interface);
my $implClassNameWithNamespace = "WebCore::" . $implClassName;
my $baseClass = GetBaseClass($parentImplClassName);
my $classHeaderName = GetClassHeaderName($className);
- my $numAttributes = @{$dataNode->attributes};
- my $numFunctions = @{$dataNode->functions};
+ my $numAttributes = @{$interface->attributes};
+ my $numFunctions = @{$interface->functions};
my $implType = $implClassNameWithNamespace;
- my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
- $implType = $svgNativeType if $svgNativeType;
-
# - Add default header template.
- @implContentHeader = split("\r", $implementationLicenseTemplate);
+ if ($interface->extendedAttributes->{"AppleCopyright"}) {
+ @implContentHeader = split("\r", $beginAppleCopyrightForSourceFiles);
+ } else {
+ @implContentHeader = split("\r", $implementationLicenseTemplate);
+ }
# - INCLUDES -
push(@implContentHeader, "\n#import \"config.h\"\n");
- my $conditionalString = GenerateConditionalString($dataNode);
+ my $conditionalString = $codeGenerator->GenerateConditionalString($interface);
push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString;
push(@implContentHeader, "#import \"DOMInternal.h\"\n\n");
$implIncludes{"JSMainThreadExecState.h"} = 1;
$implIncludes{"WebScriptObjectPrivate.h"} = 1;
$implIncludes{$classHeaderName . "Internal.h"} = 1;
-
- # FIXME: These includes are only needed when the class is a subclass of one of these polymorphic classes.
- $implIncludes{"DOMBlobInternal.h"} = 1;
- $implIncludes{"DOMCSSRuleInternal.h"} = 1;
- $implIncludes{"DOMCSSValueInternal.h"} = 1;
- $implIncludes{"DOMEventInternal.h"} = 1;
$implIncludes{"DOMNodeInternal.h"} = 1;
- $implIncludes{"DOMStyleSheetInternal.h"} = 1;
- $implIncludes{"DOMSVGPathSegInternal.h"} = 1 if $interfaceName =~ /^SVGPathSeg.+/;
+ $implIncludes{"DOMBlobInternal.h"} = 1 if $interfaceName eq "File";
+ $implIncludes{"DOMCSSRuleInternal.h"} = 1 if $interfaceName =~ /.*CSS.*Rule/;
+ $implIncludes{"DOMCSSValueInternal.h"} = 1 if $interfaceName =~ /.*CSS.*Value/;
+ $implIncludes{"DOMEventInternal.h"} = 1 if $interfaceName =~ /.*Event/;
+ $implIncludes{"DOMStyleSheetInternal.h"} = 1 if $interfaceName eq "CSSStyleSheet";
if ($interfaceName =~ /(\w+)(Abs|Rel)$/) {
$implIncludes{"$1.h"} = 1;
} else {
- if (!$codeGenerator->AvoidInclusionOfType($implClassName)) {
+ if (!$codeGenerator->SkipIncludeHeader($implClassName)) {
$implIncludes{"$implClassName.h"} = 1 ;
- } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($implClassName)) {
- my $includeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implClassName);
- $implIncludes{"${includeType}.h"} = 1;
}
}
# - Attributes
if ($numAttributes > 0) {
- foreach my $attribute (@{$dataNode->attributes}) {
+ foreach my $attribute (@{$interface->attributes}) {
+ next if SkipAttribute($attribute);
AddIncludesForType($attribute->signature->type);
- my $idlType = $codeGenerator->StripModule($attribute->signature->type);
+ my $idlType = $attribute->signature->type;
my $attributeName = $attribute->signature->name;
my $attributeType = GetObjCType($attribute->signature->type);
- my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
my $attributeClassName = GetClassName($attribute->signature->type);
my $attributeInterfaceName = $attributeName;
} elsif ($attributeName eq "frame") {
# Special case attribute frame to be frameBorders.
$attributeInterfaceName .= "Borders";
- } elsif ($attributeName eq "operator") {
- # Avoid clash with C++ keyword.
- $attributeInterfaceName = "_operator";
}
$attributeNames{$attributeInterfaceName} = 1;
# - GETTER
my $getterSig = "- ($attributeType)$attributeInterfaceName\n";
- my $getterExpressionPrefix = $codeGenerator->GetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
+ my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute);
+
+ # To avoid bloating Obj-C bindings, we use getAttribute() instead of fastGetAttribute().
+ if ($functionName eq "fastGetAttribute") {
+ $functionName = "getAttribute";
+ }
+
+ my $getterExpressionPrefix = "$functionName(" . join(", ", @arguments);
# FIXME: Special case attribute ownerDocument to call document. This makes it return the
# document when called on the document itself. Legacy behavior, see <https://bugs.webkit.org/show_bug.cgi?id=10889>.
$getterExpressionPrefix =~ s/\bownerDocument\b/document/;
- my $hasGetterException = @{$attribute->getterExceptions};
- my $getterContentHead = "IMPL->$getterExpressionPrefix";
- my $getterContentTail = ")";
-
- if ($svgPropertyType) {
- $getterContentHead = "$getterExpressionPrefix";
-
- # TODO: Handle special case for DOMSVGLength. We do need Custom code support for this.
- if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
- $getterContentHead = "value(IMPL->contextElement(), ";
- }
+ my $hasGetterException = $attribute->signature->extendedAttributes->{"GetterRaisesException"};
+ my $getterContentHead;
+ if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {
+ my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};
+ $implIncludes{"${implementedBy}.h"} = 1;
+ $getterContentHead = "${implementedBy}::${getterExpressionPrefix}IMPL";
+ } else {
+ $getterContentHead = "IMPL->$getterExpressionPrefix";
}
+ my $getterContentTail = ")";
+
my $attributeTypeSansPtr = $attributeType;
$attributeTypeSansPtr =~ s/ \*$//; # Remove trailing " *" from pointer types.
unless ($interfaceName eq "HTMLImageElement") {
push(@customGetterContent, " if (!IMPL->renderer() || !IMPL->renderer()->isImage())\n");
push(@customGetterContent, " return nil;\n");
- $implIncludes{"RenderObject.h"} = 1;
+ $implIncludes{"RenderElement.h"} = 1;
}
}
$implIncludes{"DOMPrivate.h"} = 1;
- } elsif ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
+ } elsif ($attribute->signature->extendedAttributes->{"ObjCImplementedAsUnsignedLong"}) {
$getterContentHead = "WTF::String::number(" . $getterContentHead;
$getterContentTail .= ")";
} elsif ($idlType eq "Date") {
$getterContentHead = "kit($getterContentHead";
$getterContentTail .= ")";
- } elsif ($svgPropertyType) {
- # Special case for DOMSVGNumber
- if ($svgPropertyType eq "float") {
- # Intentional leave out closing brace, it's already contained in getterContentTail
- $getterContentHead = "IMPL->propertyReference(";
- } else {
- $getterContentHead = "IMPL->propertyReference().$getterContentHead";
- }
-
- if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($idlType) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
- my $getter = $getterContentHead;
- $getter =~ s/\(\)//;
-
- my $tearOffType = GetSVGTypeWithNamespace($idlType);
- my $selfIsTearOffType = $codeGenerator->IsSVGTypeNeedingTearOff($implClassName);
- if ($selfIsTearOffType) {
- $implIncludes{"SVGStaticPropertyWithParentTearOff.h"} = 1;
- $tearOffType =~ s/SVGPropertyTearOff</SVGStaticPropertyWithParentTearOff<$implClassNameWithNamespace, /;
-
- my $getter = $getterExpressionPrefix;
- $getter =~ s/IMPL->//;
- $getter =~ s/\(//;
- my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter);
-
- if ($getterContentHead =~ /matrix/ and $implClassName eq "SVGTransform") {
- # SVGTransform offers a matrix() method for internal usage that returns an AffineTransform
- # and a svgMatrix() method returning a SVGMatrix, used for the bindings.
- $getterContentHead =~ s/matrix/svgMatrix/;
- }
-
- $getterContentHead = "${tearOffType}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod)";
-
- $getterContentHead = "kit(WTF::getPtr($getterContentHead";
- $getterContentTail = "))";
- }
- }
- } elsif ($codeGenerator->IsSVGAnimatedType($implClassName) and $codeGenerator->IsSVGTypeNeedingTearOff($idlType)) {
- my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
- $getterContentHead = "kit(static_cast<$idlTypeWithNamespace*>($getterContentHead)";
- $getterContentTail .= ")";
} elsif (IsProtocolType($idlType) and $idlType ne "EventTarget") {
$getterContentHead = "kit($getterContentHead";
$getterContentTail .= ")";
} elsif ($idlType eq "Color") {
- $getterContentHead = "WebCore::nsColor($getterContentHead";
- $getterContentTail .= ")";
+ if ($buildingForIPhone) {
+ $getterContentHead = "WebCore::cachedCGColor($getterContentHead";
+ $getterContentTail .= ", WebCore::ColorSpaceDeviceRGB)";
+ } else {
+ $getterContentHead = "WebCore::nsColor($getterContentHead";
+ $getterContentTail .= ")";
+ }
} elsif ($attribute->signature->type eq "SerializedScriptValue") {
$getterContentHead = "$getterContentHead";
$getterContentTail .= "->toString()";
} elsif (ConversionNeeded($attribute->signature->type)) {
- my $type = $attribute->signature->type;
- if ($codeGenerator->IsSVGTypeNeedingTearOff($type) and not $implClassName =~ /List$/) {
- my $idlTypeWithNamespace = GetSVGTypeWithNamespace($type);
- $implIncludes{"$type.h"} = 1 if not $codeGenerator->AvoidInclusionOfType($type);
- if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($type) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
- $idlTypeWithNamespace =~ s/SVGPropertyTearOff</SVGStaticPropertyTearOff<$implClassNameWithNamespace, /;
- $implIncludes{"SVGStaticPropertyTearOff.h"} = 1;
-
- my $getter = $getterContentHead;
- $getter =~ s/IMPL->//;
- $getter =~ s/\(//;
- my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter);
- $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod";
- $getterContentTail .= "))";
- } elsif ($idlTypeWithNamespace =~ /SVG(Point|PathSeg)List/) {
- $getterContentHead = "kit(WTF::getPtr($getterContentHead";
- $getterContentTail .= "))";
- } elsif ($idlTypeWithNamespace =~ /SVGStaticListPropertyTearOff/) {
- $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead";
- $getterContentTail .= ")))";
- } else {
- $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($getterContentHead";
- $getterContentTail .= ")))";
- }
- } else {
- $getterContentHead = "kit(WTF::getPtr($getterContentHead";
- $getterContentTail .= "))";
- }
+ $getterContentHead = "kit(WTF::getPtr($getterContentHead";
+ $getterContentTail .= "))";
}
my $getterContent;
- if ($hasGetterException) {
- $getterContent = $getterContentHead . "ec" . $getterContentTail;
+ if ($hasGetterException || $attribute->signature->isNullable) {
+ $getterContent = $getterContentHead;
+ my $getterWithoutAttributes = $getterContentHead =~ /\($|, $/ ? "ec" : ", ec";
+ if ($attribute->signature->isNullable) {
+ $getterContent .= $getterWithoutAttributes ? "isNull" : ", isNull";
+ $getterWithoutAttributes = 0;
+ }
+ if ($hasGetterException) {
+ $getterContent .= $getterWithoutAttributes ? "ec" : ", ec";
+ }
+ $getterContent .= $getterContentTail;
} else {
$getterContent = $getterContentHead . $getterContentTail;
}
- my $attributeConditionalString = GenerateConditionalString($attribute->signature);
+ my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature);
push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString;
push(@implContent, $getterSig);
push(@implContent, "{\n");
push(@implContent, " $jsContextSetter\n");
push(@implContent, @customGetterContent);
+
+ # FIXME: Should we return a default value when isNull == true?
+ if ($attribute->signature->isNullable) {
+ push(@implContents, " $nullableInit\n");
+ }
+
if ($hasGetterException) {
# Differentiated between when the return type is a pointer and
# not for white space issue (ie. Foo *result vs. int result).
push(@implContent, "}\n");
# - SETTER
- if (!$attributeIsReadonly) {
+ if (!$attribute->isReadOnly) {
# Exception handling
- my $hasSetterException = @{$attribute->setterExceptions};
+ my $hasSetterException = $attribute->signature->extendedAttributes->{"SetterRaisesException"};
my $coreSetterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
my $setterName = "set" . ucfirst($attributeInterfaceName);
my $argName = "new" . ucfirst($attributeInterfaceName);
my $arg = GetObjCTypeGetter($argName, $idlType);
- # The definition of ConvertToString is flipped for the setter
- if ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
+ # The definition of ObjCImplementedAsUnsignedLong is flipped for the setter
+ if ($attribute->signature->extendedAttributes->{"ObjCImplementedAsUnsignedLong"}) {
$arg = "WTF::String($arg).toInt()";
}
$arg = "core(" . $arg . ")";
}
- if ($svgPropertyType) {
- $implIncludes{"ExceptionCode.h"} = 1;
- $getterContentHead = "$getterExpressionPrefix";
- push(@implContent, " if (IMPL->role() == WebCore::AnimValRole) {\n");
- push(@implContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n");
- push(@implContent, " return;\n");
- push(@implContent, " }\n");
- push(@implContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
- my $ec = $hasSetterException ? ", ec" : "";
- push(@implContent, " $exceptionInit\n") if $hasSetterException;
-
- # Special case for DOMSVGNumber
- if ($svgPropertyType eq "float") {
- push(@implContent, " podImpl = $arg;\n");
- } else {
- # FIXME: Special case for DOMSVGLength. We do need Custom code support for this.
- if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
- push(@implContent, " podImpl.$coreSetterName($arg, IMPL->contextElement()$ec);\n");
- } else {
- push(@implContent, " podImpl.$coreSetterName($arg$ec);\n");
- }
- }
-
- if ($hasSetterException) {
- push(@implContent, " if (!ec)\n");
- push(@implContent, " IMPL->commitChange();\n");
- push(@implContent, " $exceptionRaiseOnError\n");
- } else {
- push(@implContent, " IMPL->commitChange();\n");
- }
- } elsif ($svgListPropertyType) {
- $getterContentHead = "$getterExpressionPrefix";
- push(@implContent, " IMPL->$coreSetterName($arg);\n");
+ my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute);
+ push(@arguments, $arg);
+ push(@arguments, "ec") if $hasSetterException;
+ push(@implContent, " $exceptionInit\n") if $hasSetterException;
+ if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {
+ my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};
+ $implIncludes{"${implementedBy}.h"} = 1;
+ unshift(@arguments, "IMPL");
+ $functionName = "${implementedBy}::${functionName}";
} else {
- my $setterExpressionPrefix = $codeGenerator->SetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
- my $ec = $hasSetterException ? ", ec" : "";
- push(@implContent, " $exceptionInit\n") if $hasSetterException;
- push(@implContent, " IMPL->$setterExpressionPrefix$arg$ec);\n");
- push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException;
+ $functionName = "IMPL->${functionName}";
}
+ push(@implContent, " ${functionName}(" . join(", ", @arguments) . ");\n");
+ push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException;
push(@implContent, "}\n");
}
# - Functions
if ($numFunctions > 0) {
- foreach my $function (@{$dataNode->functions}) {
+ my $inAppleCopyright = 0;
+ foreach my $function (@{$interface->functions}) {
+ next if SkipFunction($function);
+ next if ($function->signature->name eq "set" and $interface->extendedAttributes->{"TypedArray"});
AddIncludesForType($function->signature->type);
my $functionName = $function->signature->name;
my $returnType = GetObjCType($function->signature->type);
+ my $needsAppleCopyright = $function->signature->extendedAttributes->{"AppleCopyright"};
my $hasParameters = @{$function->parameters};
- my $raisesExceptions = @{$function->raisesExceptions};
+ my $raisesExceptions = $function->signature->extendedAttributes->{"RaisesException"};
my @parameterNames = ();
my @needsAssert = ();
AddIncludesForType($param->type);
- my $idlType = $codeGenerator->StripModule($param->type);
- my $implGetter = GetObjCTypeGetter($paramName, $idlType);
+ my $idlType = $param->type;
+ my $implGetter;
+ if ($param->extendedAttributes->{"ObjCExplicitAtomicString"}) {
+ $implGetter = "AtomicString($paramName)"
+ } else {
+ $implGetter = GetObjCTypeGetter($paramName, $idlType);
+ }
push(@parameterNames, $implGetter);
$needsCustom{"XPathNSResolver"} = $paramName if $idlType eq "XPathNSResolver";
$needsCustom{"NodeFilter"} = $paramName if $idlType eq "NodeFilter";
$needsCustom{"EventListener"} = $paramName if $idlType eq "EventListener";
$needsCustom{"EventTarget"} = $paramName if $idlType eq "EventTarget";
- $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"Return"};
+ $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"CustomReturn"};
unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
push(@needsAssert, " ASSERT($paramName);\n");
}
if ($parameterIndex >= 1) {
- my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
- $paramPrefix = $param->name unless defined($paramPrefix);
- $functionSig .= " $paramPrefix";
+ $functionSig .= " " . $param->name;
}
$functionSig .= ":($paramType)$paramName";
$implIncludes{"Node.h"} = 1;
}
- if ($function->signature->extendedAttributes->{"UsesView"}) {
+ if ($function->signature->extendedAttributes->{"ObjCUseDefaultView"}) {
push(@functionContent, " WebCore::DOMWindow* dv = $caller->defaultView();\n");
push(@functionContent, " if (!dv)\n");
push(@functionContent, " return nil;\n");
push(@functionContent, " nativeNodeFilter = WebCore::NodeFilter::create(WebCore::ObjCNodeFilterCondition::create($paramName));\n");
}
- # FIXME! We need [Custom] support for ObjC, to move these hacks into DOMSVGLength/MatrixCustom.mm
- my $svgLengthConvertToSpecifiedUnits = ($svgPropertyType and $svgPropertyType eq "WebCore::SVGLength" and $functionName eq "convertToSpecifiedUnits");
-
- push(@parameterNames, "IMPL->contextElement()") if $svgLengthConvertToSpecifiedUnits;
push(@parameterNames, "ec") if $raisesExceptions;
- # Handle arguments that are 'SVGProperty' based (SVGAngle/SVGLength). We need to convert from SVGPropertyTearOff<Type>* to Type,
- # to be able to call the desired WebCore function. If the conversion fails, we can't extract Type and need to raise an exception.
- my $currentParameter = -1;
- foreach my $param (@{$function->parameters}) {
- $currentParameter++;
-
- my $paramName = $param->name;
-
- # make a new parameter name if the original conflicts with a property name
- $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
-
- my $idlType = $codeGenerator->StripModule($param->type);
- next if not $codeGenerator->IsSVGTypeNeedingTearOff($idlType) or $implClassName =~ /List$/;
-
- my $implGetter = GetObjCTypeGetter($paramName, $idlType);
- my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType);
-
- $implIncludes{"ExceptionCode.h"} = 1;
- push(@functionContent, " $idlTypeWithNamespace* ${paramName}Core = $implGetter;\n");
- push(@functionContent, " if (!${paramName}Core) {\n");
- push(@functionContent, " WebCore::ExceptionCode ec = WebCore::TYPE_MISMATCH_ERR;\n");
- push(@functionContent, " $exceptionRaiseOnError\n");
- if ($returnType eq "void") {
- push(@functionContent, " return;\n");
- } else {
- push(@functionContent, " return nil;\n");
- }
- push(@functionContent, " }\n");
-
- # Replace the paramter core() getter, by the cached variable.
- splice(@parameterNames, $currentParameter, 1, "${paramName}Core->propertyReference()");
- }
-
- my $content = $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
-
- if ($svgPropertyType) {
- $implIncludes{"ExceptionCode.h"} = 1;
- push(@functionContent, " if (IMPL->role() == WebCore::AnimValRole) {\n");
- push(@functionContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n");
- if ($returnType eq "void") {
- push(@functionContent, " return;\n");
- } else {
- push(@functionContent, " return nil;\n");
- }
- push(@functionContent, " }\n");
- push(@functionContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n");
- $content = "podImpl.$content";
+ my $content;
+ if ($function->signature->extendedAttributes->{"ImplementedBy"}) {
+ my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"};
+ $implIncludes{"${implementedBy}.h"} = 1;
+ unshift(@parameterNames, $caller);
+ $content = "${implementedBy}::" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
} else {
- $content = $caller . "->$content";
+ my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementedAs"} || $codeGenerator->WK_lcfirst($functionName);
+ $content = "$caller->" . $functionImplementationName . "(" . join(", ", @parameterNames) . ")";
}
if ($returnType eq "void") {
if ($raisesExceptions) {
push(@functionContent, " $exceptionInit\n");
push(@functionContent, " $content;\n");
- if ($svgPropertyType) {
- push(@functionContent, " if (!ec)\n");
- push(@functionContent, " IMPL->commitChange();\n");
- }
push(@functionContent, " $exceptionRaiseOnError\n");
} else {
push(@functionContent, " $content;\n");
- push(@functionContent, " IMPL->commitChange();\n") if $svgPropertyType;
}
} elsif (defined $needsCustom{"NodeToReturn"}) {
# Special case the insertBefore, replaceChild, removeChild
$content = "foo";
} else {
if (ConversionNeeded($function->signature->type)) {
- if ($codeGenerator->IsSVGTypeNeedingTearOff($function->signature->type) and not $implClassName =~ /List$/) {
- my $idlTypeWithNamespace = GetSVGTypeWithNamespace($function->signature->type);
- $content = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($content)))";
- } else {
- $content = "kit(WTF::getPtr($content))";
- }
+ $content = "kit(WTF::getPtr($content))";
}
if ($raisesExceptions) {
}
}
- my $conditionalString = GenerateConditionalString($function->signature);
+ if ($needsAppleCopyright) {
+ if (!$inAppleCopyright) {
+ push(@implContent, $beginAppleCopyrightForSourceFiles);
+ $inAppleCopyright = 1;
+ }
+ } elsif ($inAppleCopyright) {
+ push(@implContent, $endAppleCopyright);
+ $inAppleCopyright = 0;
+ }
+
+ my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature);
push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
push(@implContent, "$functionSig\n");
push(@implContent, "#endif\n\n") if $conditionalString;
# generate the old style method names with un-named parameters, these methods are deprecated
- if (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"}) {
+ if (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"ObjCLegacyUnnamedParameters"}) {
my $deprecatedFunctionSig = $functionSig;
$deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
# Clear the hash
%needsCustom = ();
}
+ push(@implContent, $endAppleCopyright) if $inAppleCopyright;
}
# END implementation
push(@implContent, "\@end\n");
+ if ($interface->extendedAttributes->{"AppleCopyright"}) {
+ push(@implContent, split("\r", $endAppleCopyright));
+ }
+
# Generate internal interfaces
push(@implContent, "\n$implType* core($className *wrapper)\n");
push(@implContent, "{\n");
push(@implContent, " return nil;\n");
push(@implContent, " if ($className *wrapper = getDOMWrapper(value))\n");
push(@implContent, " return [[wrapper retain] autorelease];\n");
- if ($dataNode->extendedAttributes->{Polymorphic}) {
+ if ($interface->extendedAttributes->{"ObjCPolymorphic"}) {
push(@implContent, " $className *wrapper = [[kitClass(value) alloc] _init];\n");
push(@implContent, " if (!wrapper)\n");
push(@implContent, " return nil;\n");
# - End the ifdef conditional if necessary
push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
+ if ($interface->extendedAttributes->{"AppleCopyright"}) {
+ push(@implContent, split("\r", $endAppleCopyright));
+ }
+
# - Generate dependencies.
if ($writeDependencies && @ancestorInterfaceNames) {
push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n");
sub WriteData
{
my $object = shift;
- my $name = shift;
+ my $interface = shift;
+ my $outputDir = shift;
# Open files for writing...
- my $headerFileName = "$outputDir/" . $name . ".h";
- my $privateHeaderFileName = "$outputDir/" . $name . "Private.h";
- my $implFileName = "$outputDir/" . $name . ".mm";
- my $internalHeaderFileName = "$outputDir/" . $name . "Internal.h";
- my $depsFileName = "$outputDir/" . $name . ".dep";
-
- # Remove old files.
- unlink($headerFileName);
- unlink($privateHeaderFileName);
- unlink($implFileName);
- unlink($internalHeaderFileName);
- unlink($depsFileName);
+ my $name = $interface->name;
+ my $prefix = FileNamePrefix;
+ my $headerFileName = "$outputDir/$prefix$name.h";
+ my $privateHeaderFileName = "$outputDir/$prefix${name}Private.h";
+ my $implFileName = "$outputDir/$prefix$name.mm";
+ my $internalHeaderFileName = "$outputDir/$prefix${name}Internal.h";
+ my $depsFileName = "$outputDir/$prefix$name.dep";
# Write public header.
- open(HEADER, ">$headerFileName") or die "Couldn't open file $headerFileName";
-
- print HEADER @headerContentHeader;
- print HEADER map { "\@class $_;\n" } sort keys(%headerForwardDeclarations);
- print HEADER map { "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
+ my $contents = join "", @headerContentHeader;
+ map { $contents .= (IsCoreFoundationType($_) ? "typedef struct " . substr($_, 0, -3) . "* $_;\n" : "\@class $_;\n") } sort keys(%headerForwardDeclarations);
+ map { $contents .= "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols);
- print HEADER "\n" if $hasForwardDeclarations;
- print HEADER @headerContent;
-
- close(HEADER);
+ $contents .= "\n" if $hasForwardDeclarations;
+ $contents .= join "", @headerContent;
+ $codeGenerator->UpdateFile($headerFileName, $contents);
@headerContentHeader = ();
@headerContent = ();
%headerForwardDeclarationsForProtocols = ();
if (@privateHeaderContent > 0) {
- open(PRIVATE_HEADER, ">$privateHeaderFileName") or die "Couldn't open file $privateHeaderFileName";
-
- print PRIVATE_HEADER @privateHeaderContentHeader;
- print PRIVATE_HEADER map { "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
- print PRIVATE_HEADER map { "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
+ $contents = join "", @privateHeaderContentHeader;
+ map { $contents .= "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
+ map { $contents .= "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
$hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols);
- print PRIVATE_HEADER "\n" if $hasForwardDeclarations;
- print PRIVATE_HEADER @privateHeaderContent;
-
- close(PRIVATE_HEADER);
+ $contents .= "\n" if $hasForwardDeclarations;
+ $contents .= join "", @privateHeaderContent;
+ $codeGenerator->UpdateFile($privateHeaderFileName, $contents);
@privateHeaderContentHeader = ();
@privateHeaderContent = ();
# Write implementation file.
unless ($noImpl) {
- open(IMPL, ">$implFileName") or die "Couldn't open file $implFileName";
-
- print IMPL @implContentHeader;
- print IMPL map { "#import \"$_\"\n" } sort keys(%implIncludes);
- print IMPL @implContent;
-
- close(IMPL);
+ $contents = join "", @implContentHeader;
+ map { $contents .= "#import \"$_\"\n" } sort keys(%implIncludes);
+ $contents .= join "", @implContent;
+ $codeGenerator->UpdateFile($implFileName, $contents);
@implContentHeader = ();
@implContent = ();
%implIncludes = ();
}
-
- if (@internalHeaderContent > 0) {
- open(INTERNAL_HEADER, ">$internalHeaderFileName") or die "Couldn't open file $internalHeaderFileName";
- print INTERNAL_HEADER @internalHeaderContent;
-
- close(INTERNAL_HEADER);
+ if (@internalHeaderContent > 0) {
+ $contents = join "", @internalHeaderContent;
+ $codeGenerator->UpdateFile($internalHeaderFileName, $contents);
- @internalHeaderContent = ();
+ @internalHeaderContent = ();
}
# Write dependency file.
if (@depsContent) {
- open(DEPS, ">$depsFileName") or die "Couldn't open file $depsFileName";
- print DEPS @depsContent;
- close(DEPS);
+ $contents = join "", @depsContent;
+ $codeGenerator->UpdateFile($depsFileName, $contents);
+
@depsContent = ();
}
}