123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842 |
- #
- # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
- # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
- # Copyright (C) 2006, 2007 Samuel Weinig <sam@webkit.org>
- # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
- # Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
- # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
- # Copyright (C) 2010 Google Inc.
- # Copyright (C) Research In Motion Limited 2010. All rights reserved.
- #
- # This library is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Library General Public
- # License as published by the Free Software Foundation; either
- # version 2 of the License, or (at your option) any later version.
- #
- # This library is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # Library General Public License for more details.
- #
- # You should have received a copy of the GNU Library General Public License
- # along with this library; see the file COPYING.LIB. If not, write to
- # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- # Boston, MA 02110-1301, USA.
- #
- package CodeGeneratorObjC;
- use constant FileNamePrefix => "DOM";
- # Global Variables
- my $writeDependencies = 0;
- my %publicInterfaces = ();
- my $newPublicClass = 0;
- my $interfaceAvailabilityVersion = "";
- my $isProtocol = 0;
- my $noImpl = 0;
- my @headerContentHeader = ();
- my @headerContent = ();
- my %headerForwardDeclarations = ();
- my %headerForwardDeclarationsForProtocols = ();
- my @privateHeaderContentHeader = ();
- my @privateHeaderContent = ();
- my %privateHeaderForwardDeclarations = ();
- my %privateHeaderForwardDeclarationsForProtocols = ();
- my @internalHeaderContent = ();
- my @implContentHeader = ();
- my @implContent = ();
- my %implIncludes = ();
- my @depsContent = ();
- # Hashes
- my %protocolTypeHash = ("XPathNSResolver" => 1, "EventListener" => 1, "EventTarget" => 1, "NodeFilter" => 1,
- "SVGLocatable" => 1, "SVGTransformable" => 1, "SVGFilterPrimitiveStandardAttributes" => 1,
- "SVGTests" => 1, "SVGLangSpace" => 1, "SVGExternalResourcesRequired" => 1, "SVGURIReference" => 1,
- "SVGZoomAndPan" => 1, "SVGFitToViewBox" => 1, "SVGAnimatedPathData" => 1, "ElementTimeControl" => 1);
- my %nativeObjCTypeHash = ("URL" => 1, "Color" => 1);
- # FIXME: this should be replaced with a function that recurses up the tree
- # to find the actual base type.
- 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);
- # Constants
- my $nullableInit = "bool isNull = false;";
- my $exceptionInit = "WebCore::ExceptionCode ec = 0;";
- my $jsContextSetter = "WebCore::JSMainThreadNullState state;";
- my $exceptionRaiseOnError = "WebCore::raiseOnDOMError(ec);";
- my $assertMainThread = "{ DOM_ASSERT_MAIN_THREAD(); WebCoreThreadViolationCheckRoundOne(); }";
- my %conflictMethod = (
- # FIXME: Add C language keywords?
- # FIXME: Add other predefined types like "id"?
- "callWebScriptMethod:withArguments:" => "WebScriptObject",
- "evaluateWebScript:" => "WebScriptObject",
- "removeWebScriptKey:" => "WebScriptObject",
- "setException:" => "WebScriptObject",
- "setWebScriptValueAtIndex:value:" => "WebScriptObject",
- "stringRepresentation" => "WebScriptObject",
- "webScriptValueAtIndex:" => "WebScriptObject",
- "autorelease" => "NSObject",
- "awakeAfterUsingCoder:" => "NSObject",
- "class" => "NSObject",
- "classForCoder" => "NSObject",
- "conformsToProtocol:" => "NSObject",
- "copy" => "NSObject",
- "copyWithZone:" => "NSObject",
- "dealloc" => "NSObject",
- "description" => "NSObject",
- "doesNotRecognizeSelector:" => "NSObject",
- "encodeWithCoder:" => "NSObject",
- "finalize" => "NSObject",
- "forwardInvocation:" => "NSObject",
- "hash" => "NSObject",
- "init" => "NSObject",
- "initWithCoder:" => "NSObject",
- "isEqual:" => "NSObject",
- "isKindOfClass:" => "NSObject",
- "isMemberOfClass:" => "NSObject",
- "isProxy" => "NSObject",
- "methodForSelector:" => "NSObject",
- "methodSignatureForSelector:" => "NSObject",
- "mutableCopy" => "NSObject",
- "mutableCopyWithZone:" => "NSObject",
- "performSelector:" => "NSObject",
- "release" => "NSObject",
- "replacementObjectForCoder:" => "NSObject",
- "respondsToSelector:" => "NSObject",
- "retain" => "NSObject",
- "retainCount" => "NSObject",
- "self" => "NSObject",
- "superclass" => "NSObject",
- "zone" => "NSObject",
- );
- my $fatalError = 0;
- # Default License Templates
- my $headerLicenseTemplate = << "EOF";
- /*
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
- * Copyright (C) 2006 Samuel Weinig <sam.weinig\@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * 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
- * 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
- * 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
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- EOF
- my $implementationLicenseTemplate = << "EOF";
- /*
- * This file is part of the WebKit open source project.
- * This file has been generated by generate-bindings.pl. DO NOT MODIFY!
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * 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
- * 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
- * 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
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- EOF
- # Default constructor
- sub new
- {
- my $object = shift;
- my $reference = { };
- $codeGenerator = shift;
- shift; # $useLayerOnTop
- shift; # $preprocessor
- $writeDependencies = shift;
- bless($reference, $object);
- return $reference;
- }
- sub ReadPublicInterfaces
- {
- my $class = shift;
- my $superClass = shift;
- my $defines = shift;
- my $isProtocol = shift;
- my $found = 0;
- my $actualSuperClass;
- %publicInterfaces = ();
- my $fileName = "WebCore/bindings/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",
- (map { "-D$_" } split(/ +/, $defines)), "-DOBJC_CODE_GENERATION", $fileName or die "Could not open $fileName";
- my @documentContent = <FILE>;
- close FILE;
- foreach $line (@documentContent) {
- if (!$isProtocol && $line =~ /^\s*\@interface\s*$class\s*:\s*(\w+)\s*([A-Z0-9_]*)/) {
- if ($superClass ne $1) {
- warn "Public API change. Superclass for \"$class\" differs ($1 != $superClass)";
- $fatalError = 1;
- }
- $interfaceAvailabilityVersion = $2 if defined $2;
- $found = 1;
- next;
- } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*<[^>]+>\s*([A-Z0-9_]*)/) {
- $interfaceAvailabilityVersion = $1 if defined $1;
- $found = 1;
- next;
- }
- last if $found and $line =~ /^\s?\@end\s?$/;
- if ($found) {
- # trim whitspace
- $line =~ s/^\s+//;
- $line =~ s/\s+$//;
- my $availabilityMacro = "";
- $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;
- }
- sub GenerateInterface
- {
- my $object = shift;
- my $interface = shift;
- my $defines = shift;
- $fatalError = 0;
- my $name = $interface->name;
- my $className = GetClassName($name);
- my $parentClassName = "DOM" . GetParentImplClassName($interface);
- $isProtocol = $interface->extendedAttributes->{ObjCProtocol};
- $noImpl = $interface->extendedAttributes->{ObjCCustomImplementation} || $isProtocol;
- ReadPublicInterfaces($className, $parentClassName, $defines, $isProtocol);
- # Start actual generation..
- $object->GenerateHeader($interface);
- $object->GenerateImplementation($interface) unless $noImpl;
- # Check for missing public API
- if (keys %publicInterfaces > 0) {
- my $missing = join("\n", keys %publicInterfaces);
- warn "Public API change. There are missing public properties and/or methods from the \"$className\" class.\n$missing\n";
- $fatalError = 1;
- }
- die if $fatalError;
- }
- sub GetClassName
- {
- my $name = shift;
- # special cases
- return "NSString" if $codeGenerator->IsStringType($name) or $name eq "SerializedScriptValue";
- 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";
- return "DOMAbstractView" if $name eq "DOMWindow";
- return $name if $codeGenerator->IsPrimitiveType($name) or $name eq "DOMImplementation" or $name eq "DOMTimeStamp";
- # Default, assume Objective-C type has the same type name as
- # idl type prefixed with "DOM".
- return "DOM$name";
- }
- sub GetClassHeaderName
- {
- my $name = shift;
- return "DOMDOMImplementation" if $name eq "DOMImplementation";
- return $name;
- }
- sub GetImplClassName
- {
- my $name = shift;
- return "DOMImplementationFront" if $name eq "DOMImplementation";
- return "DOMWindow" if $name eq "AbstractView";
- return $name;
- }
- sub GetParentImplClassName
- {
- my $interface = shift;
- return "Object" if @{$interface->parents} eq 0;
- my $parent = $interface->parents(0);
- # special cases
- return "Object" if $parent eq "HTMLCollection";
- return $parent;
- }
- sub GetParentAndProtocols
- {
- my $interface = shift;
- my $numParents = @{$interface->parents};
- my $parent = "";
- my @protocols = ();
- if ($numParents eq 0) {
- if ($isProtocol) {
- push(@protocols, "NSObject");
- push(@protocols, "NSCopying") if $interface->name eq "EventTarget";
- } else {
- $parent = "DOMObject";
- }
- } elsif ($numParents eq 1) {
- my $parentName = $interface->parents(0);
- if ($isProtocol) {
- die "Parents of protocols must also be protocols." unless IsProtocolType($parentName);
- push(@protocols, "DOM" . $parentName);
- } else {
- if (IsProtocolType($parentName)) {
- push(@protocols, "DOM" . $parentName);
- } elsif ($parentName eq "HTMLCollection") {
- $parent = "DOMObject";
- } else {
- $parent = "DOM" . $parentName;
- }
- }
- } else {
- my @parents = @{$interface->parents};
- my $firstParent = shift(@parents);
- if (IsProtocolType($firstParent)) {
- push(@protocols, "DOM" . $firstParent);
- if (!$isProtocol) {
- $parent = "DOMObject";
- }
- } else {
- $parent = "DOM" . $firstParent;
- }
- foreach my $parentName (@parents) {
- die "Everything past the first class should be a protocol!" unless IsProtocolType($parentName);
- push(@protocols, "DOM" . $parentName);
- }
- }
- return ($parent, @protocols);
- }
- sub GetBaseClass
- {
- $parent = shift;
- return $parent if $parent eq "Object" or IsBaseType($parent);
- return "Event" if $parent eq "UIEvent" or $parent eq "MouseEvent";
- return "CSSValue" if $parent eq "SVGColor" or $parent eq "CSSValueList";
- return "Node";
- }
- sub IsBaseType
- {
- my $type = shift;
- return 1 if $baseTypeHash{$type};
- return 0;
- }
- sub IsProtocolType
- {
- my $type = shift;
- return 1 if $protocolTypeHash{$type};
- return 0;
- }
- sub IsNativeObjCType
- {
- my $type = shift;
- return 1 if $nativeObjCTypeHash{$type};
- 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 "id <$name>" if IsProtocolType($type);
- return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
- return "unsigned short" if $type eq "CompareHow";
- return "$name *";
- }
- sub GetPropertyAttributes
- {
- my $type = shift;
- my $readOnly = shift;
- my @attributes = ();
- push(@attributes, "readonly") if $readOnly;
- # 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");
- }
- return "" unless @attributes > 0;
- return "(" . join(", ", @attributes) . ")";
- }
- sub ConversionNeeded
- {
- my $type = shift;
- return !$codeGenerator->IsNonPointerType($type) && !$codeGenerator->IsStringType($type) && !IsNativeObjCType($type);
- }
- sub GetObjCTypeGetter
- {
- my $argName = shift;
- my $type = shift;
- return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
- return $argName . "Node" if $type eq "EventTarget";
- return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow";
- return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener";
- return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter";
- return "WTF::getPtr(nativeResolver)" if $type eq "XPathNSResolver";
-
- if ($type eq "SerializedScriptValue") {
- $implIncludes{"SerializedScriptValue.h"} = 1;
- return "WebCore::SerializedScriptValue::create(WTF::String($argName))";
- }
- return "core($argName)";
- }
- sub AddForwardDeclarationsForType
- {
- my $type = shift;
- my $public = shift;
- return if $codeGenerator->IsNonPointerType($type);
- return if $codeGenerator->GetSequenceType($type);
- return if $codeGenerator->GetArrayType($type);
- my $class = GetClassName($type);
- if (IsProtocolType($type)) {
- $headerForwardDeclarationsForProtocols{$class} = 1 if $public;
- $privateHeaderForwardDeclarationsForProtocols{$class} = 1 if !$public and !$headerForwardDeclarationsForProtocols{$class};
- return;
- }
- $headerForwardDeclarations{$class} = 1 if $public;
- # Private headers include the public header, so only add a forward declaration to the private header
- # if the public header does not already have the same forward declaration.
- $privateHeaderForwardDeclarations{$class} = 1 if !$public and !$headerForwardDeclarations{$class};
- }
- sub AddIncludesForType
- {
- 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;
- }
- return;
- }
- if ($codeGenerator->IsStringType($type)) {
- $implIncludes{"KURL.h"} = 1;
- return;
- }
- if ($type eq "DOMWindow") {
- $implIncludes{"DOMAbstractViewInternal.h"} = 1;
- $implIncludes{"DOMWindow.h"} = 1;
- return;
- }
- if ($type eq "DOMImplementation") {
- $implIncludes{"DOMDOMImplementationInternal.h"} = 1;
- $implIncludes{"DOMImplementationFront.h"} = 1;
- return;
- }
- if ($type eq "EventTarget") {
- $implIncludes{"Node.h"} = 1;
- $implIncludes{"DOMEventTarget.h"} = 1;
- 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;
- return;
- }
- if ($type eq "NodeFilter") {
- $implIncludes{"NodeFilter.h"} = 1;
- $implIncludes{"ObjCNodeFilterCondition.h"} = 1;
- return;
- }
- if ($type eq "EventListener") {
- $implIncludes{"EventListener.h"} = 1;
- $implIncludes{"ObjCEventListener.h"} = 1;
- return;
- }
- if ($type eq "XPathNSResolver") {
- $implIncludes{"DOMCustomXPathNSResolver.h"} = 1;
- $implIncludes{"XPathNSResolver.h"} = 1;
- return;
- }
- if ($type eq "SerializedScriptValue") {
- $implIncludes{"SerializedScriptValue.h"} = 1;
- return;
- }
- # FIXME: won't compile without these
- $implIncludes{"CSSImportRule.h"} = 1 if $type eq "CSSRule";
- $implIncludes{"StylePropertySet.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->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
- {
- my $implType = shift;
- my $svgPropertyType;
- my $svgListPropertyType;
- my $svgNativeType;
- return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $implType =~ /SVG/;
- $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($implType);
- return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType;
- # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType>
- $svgNativeType = "WebCore::$svgNativeType ";
- $svgNativeType =~ s/</\<WebCore::/ if not $svgNativeType =~ /float/;
- 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::/;
- }
- return ($svgPropertyType, $svgListPropertyType, $svgNativeType);
- }
- sub GenerateHeader
- {
- my $object = shift;
- my $interface = shift;
- my $interfaceName = $interface->name;
- my $className = GetClassName($interfaceName);
- my $parentName = "";
- my @protocolsToImplement = ();
- ($parentName, @protocolsToImplement) = GetParentAndProtocols($interface);
- my $numConstants = @{$interface->constants};
- my $numAttributes = @{$interface->attributes};
- my $numFunctions = @{$interface->functions};
- # - Add default header template
- @headerContentHeader = split("\r", $headerLicenseTemplate);
- push(@headerContentHeader, "\n");
- # - INCLUDES -
- my $includedWebKitAvailabilityHeader = 0;
- unless ($isProtocol) {
- my $parentHeaderName = GetClassHeaderName($parentName);
- push(@headerContentHeader, "#import <WebCore/$parentHeaderName.h>\n");
- $includedWebKitAvailabilityHeader = 1;
- }
- foreach my $parentProtocol (@protocolsToImplement) {
- next if $parentProtocol =~ /^NS/;
- $parentProtocol = GetClassHeaderName($parentProtocol);
- push(@headerContentHeader, "#import <WebCore/$parentProtocol.h>\n");
- $includedWebKitAvailabilityHeader = 1;
- }
- # Special case needed for legacy support of DOMRange
- if ($interfaceName eq "Range") {
- push(@headerContentHeader, "#import <WebCore/DOMCore.h>\n");
- push(@headerContentHeader, "#import <WebCore/DOMDocument.h>\n");
- push(@headerContentHeader, "#import <WebCore/DOMRangeException.h>\n");
- $includedWebKitAvailabilityHeader = 1;
- }
- push(@headerContentHeader, "#import <JavaScriptCore/WebKitAvailability.h>\n") unless $includedWebKitAvailabilityHeader;
- my $interfaceAvailabilityVersionCheck = "#if WEBKIT_VERSION_MAX_ALLOWED >= $interfaceAvailabilityVersion\n\n";
- 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 (@constants) {
- my $constantName = $constant->name;
- my $constantValue = $constant->value;
- my $conditional = $constant->extendedAttributes->{"Conditional"};
- my $notLast = $constant ne $constants[-1];
- if ($conditional) {
- my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional);
- $combinedConstants .= "#if ${conditionalString}\n";
- }
- $combinedConstants .= " DOM_$constantName = $constantValue";
- $combinedConstants .= "," if $notLast;
- if ($conditional) {
- $combinedConstants .= "\n#endif\n";
- } elsif ($notLast) {
- $combinedConstants .= "\n";
- }
- }
- # 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");
- }
- # - Begin @interface or @protocol
- my $interfaceDeclaration = ($isProtocol ? "\@protocol $className" : "\@interface $className : $parentName");
- $interfaceDeclaration .= " <" . join(", ", @protocolsToImplement) . ">" if @protocolsToImplement > 0;
- $interfaceDeclaration .= "\n";
- push(@headerContent, $interfaceDeclaration);
- my @headerAttributes = ();
- my @privateHeaderAttributes = ();
- # - Add attribute getters/setters.
- if ($numAttributes > 0) {
- 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") {
- # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
- $attributeName .= "Name";
- } elsif ($attributeName eq "frame") {
- # Special case attribute frame to be frameBorders.
- $attributeName .= "Borders";
- }
- my $attributeType = GetObjCType($attribute->signature->type);
- my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attribute->isReadOnly);
- # 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 . ";";
- my $availabilityMacro = "";
- if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
- $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
- }
- my $declarationSuffix = ";\n";
- $declarationSuffix = " $availabilityMacro;\n" if length $availabilityMacro;
- my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
- delete $publicInterfaces{$publicInterfaceKey};
- AddForwardDeclarationsForType($attribute->signature->type, $public);
- my $setterName = "set" . ucfirst($attributeName) . ":";
- my $conflict = $conflictMethod{$attributeName};
- if ($conflict) {
- warn "$className conflicts with $conflict method $attributeName\n";
- $fatalError = 1;
- }
- $conflict = $conflictMethod{$setterName};
- if ($conflict) {
- warn "$className conflicts with $conflict method $setterName\n";
- $fatalError = 1;
- }
- $property .= $declarationSuffix;
- push(@headerAttributes, $property) if $public;
- push(@privateHeaderAttributes, $property) unless $public;
- }
- push(@headerContent, @headerAttributes) if @headerAttributes > 0;
- }
- my @headerFunctions = ();
- my @privateHeaderFunctions = ();
- my @deprecatedHeaderFunctions = ();
- # - Add functions.
- if ($numFunctions > 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->{"ObjCLegacyUnnamedParameters"});
- my $numberOfParameters = @{$function->parameters};
- my %typesToForwardDeclare = ($function->signature->type => 1);
- my $parameterIndex = 0;
- my $functionSig = "- ($returnType)$functionName";
- my $methodName = $functionName;
- foreach my $param (@{$function->parameters}) {
- my $paramName = $param->name;
- my $paramType = GetObjCType($param->type);
- $typesToForwardDeclare{$param->type} = 1;
- if ($parameterIndex >= 1) {
- $functionSig .= " $paramName";
- $methodName .= $paramName;
- }
- $functionSig .= ":($paramType)$paramName";
- $methodName .= ":";
- $parameterIndex++;
- }
- my $publicInterfaceKey = $functionSig . ";";
- my $conflict = $conflictMethod{$methodName};
- if ($conflict) {
- warn "$className conflicts with $conflict method $methodName\n";
- $fatalError = 1;
- }
- if ($isProtocol && !$newPublicClass && !defined $publicInterfaces{$publicInterfaceKey}) {
- warn "Protocol method $publicInterfaceKey is not in PublicDOMInterfaces.h. Protocols require all methods to be public";
- $fatalError = 1;
- }
- my $availabilityMacro = "";
- if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
- $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
- }
- my $functionDeclaration = $functionSig;
- $functionDeclaration .= " " . $availabilityMacro if length $availabilityMacro;
- $functionDeclaration .= ";\n";
- my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass);
- delete $publicInterfaces{$publicInterfaceKey};
- foreach my $type (keys %typesToForwardDeclare) {
- # add any forward declarations to the public header if a deprecated version will be generated
- AddForwardDeclarationsForType($type, 1) if $needsDeprecatedVersion;
- AddForwardDeclarationsForType($type, $public) unless $public and $needsDeprecatedVersion;
- }
- my $functionConditionalString = $codeGenerator->GenerateConditionalString($function->signature);
- if ($functionConditionalString) {
- push(@headerFunctions, "#if ${functionConditionalString}\n") if $public;
- push(@privateHeaderFunctions, "#if ${functionConditionalString}\n") unless $public;
- push(@deprecatedHeaderFunctions, "#if ${functionConditionalString}\n") if $needsDeprecatedVersion;
- }
- 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
- $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};
- }
- $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
- 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;
- }
- delete $publicInterfaces{$publicInterfaceKey};
- }
- if ($functionConditionalString) {
- push(@headerFunctions, "#endif\n") if $public;
- push(@privateHeaderFunctions, "#endif\n") unless $public;
- push(@deprecatedHeaderFunctions, "#endif\n") if $needsDeprecatedVersion;
- }
- }
- if (@headerFunctions > 0) {
- push(@headerContent, "\n") if @headerAttributes > 0;
- push(@headerContent, @headerFunctions);
- }
- }
- if (@deprecatedHeaderFunctions > 0 && $isProtocol) {
- push(@headerContent, @deprecatedHeaderFunctions);
- }
- # - End @interface or @protocol
- push(@headerContent, "\@end\n");
- if (@deprecatedHeaderFunctions > 0 && !$isProtocol) {
- # - Deprecated category @interface
- push(@headerContent, "\n\@interface $className (" . $className . "Deprecated)\n");
- push(@headerContent, @deprecatedHeaderFunctions);
- push(@headerContent, "\@end\n");
- }
- push(@headerContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
- my %alwaysGenerateForNoSVGBuild = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement);
- if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0 or exists $alwaysGenerateForNoSVGBuild{$className}) {
- # - Private category @interface
- @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 @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0;
- push(@privateHeaderContent, @privateHeaderFunctions) if @privateHeaderFunctions > 0;
- push(@privateHeaderContent, "\@end\n");
- push(@privateHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion;
- }
- unless ($isProtocol) {
- # Generate internal interfaces
- my $implClassName = GetImplClassName($interfaceName);
- my $implClassNameWithNamespace = "WebCore::" . $implClassName;
- my $implType = $implClassNameWithNamespace;
- my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName);
- $implType = $svgNativeType if $svgNativeType;
- # Generate interface definitions.
- @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");
- } 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, "$implType* core($className *);\n");
- push(@internalHeaderContent, "$className *kit($implType*);\n");
- 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 $interface = shift;
- my @ancestorInterfaceNames = ();
- if (@{$interface->parents} > 1) {
- $codeGenerator->AddMethodsConstantsAndAttributesFromParentInterfaces($interface, \@ancestorInterfaceNames);
- }
- my $interfaceName = $interface->name;
- my $className = GetClassName($interfaceName);
- my $implClassName = GetImplClassName($interfaceName);
- my $parentImplClassName = GetParentImplClassName($interface);
- my $implClassNameWithNamespace = "WebCore::" . $implClassName;
- my $baseClass = GetBaseClass($parentImplClassName);
- my $classHeaderName = GetClassHeaderName($className);
- 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);
- # - INCLUDES -
- push(@implContentHeader, "\n#import \"config.h\"\n");
- my $conditionalString = $codeGenerator->GenerateConditionalString($interface);
- push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString;
- push(@implContentHeader, "#import \"DOMInternal.h\"\n\n");
- push(@implContentHeader, "#import \"$classHeaderName.h\"\n\n");
- $implIncludes{"ExceptionHandlers.h"} = 1;
- $implIncludes{"ThreadCheck.h"} = 1;
- $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.+/;
- if ($interfaceName =~ /(\w+)(Abs|Rel)$/) {
- $implIncludes{"$1.h"} = 1;
- } else {
- if (!$codeGenerator->SkipIncludeHeader($implClassName)) {
- $implIncludes{"$implClassName.h"} = 1 ;
- } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($implClassName)) {
- my $includeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implClassName);
- $implIncludes{"${includeType}.h"} = 1;
- }
- }
- @implContent = ();
- push(@implContent, "#import <wtf/GetPtr.h>\n\n");
- # add implementation accessor
- if ($parentImplClassName eq "Object") {
- push(@implContent, "#define IMPL reinterpret_cast<$implType*>(_internal)\n\n");
- } else {
- my $baseClassWithNamespace = "WebCore::$baseClass";
- push(@implContent, "#define IMPL static_cast<$implClassNameWithNamespace*>(reinterpret_cast<$baseClassWithNamespace*>(_internal))\n\n");
- }
- # START implementation
- push(@implContent, "\@implementation $className\n\n");
- # Only generate 'dealloc' and 'finalize' methods for direct subclasses of DOMObject.
- if ($parentImplClassName eq "Object") {
- $implIncludes{"WebCoreObjCExtras.h"} = 1;
- push(@implContent, "- (void)dealloc\n");
- push(@implContent, "{\n");
- push(@implContent, " if (WebCoreObjCScheduleDeallocateOnMainThread([$className class], self))\n");
- push(@implContent, " return;\n");
- push(@implContent, "\n");
- if ($interfaceName eq "NodeIterator") {
- push(@implContent, " if (_internal) {\n");
- push(@implContent, " [self detach];\n");
- push(@implContent, " IMPL->deref();\n");
- push(@implContent, " };\n");
- } else {
- push(@implContent, " if (_internal)\n");
- push(@implContent, " IMPL->deref();\n");
- }
- push(@implContent, " [super dealloc];\n");
- push(@implContent, "}\n\n");
- push(@implContent, "- (void)finalize\n");
- push(@implContent, "{\n");
- if ($interfaceName eq "NodeIterator") {
- push(@implContent, " if (_internal) {\n");
- push(@implContent, " [self detach];\n");
- push(@implContent, " IMPL->deref();\n");
- push(@implContent, " };\n");
- } else {
- push(@implContent, " if (_internal)\n");
- push(@implContent, " IMPL->deref();\n");
- }
- push(@implContent, " [super finalize];\n");
- push(@implContent, "}\n\n");
-
- }
- %attributeNames = ();
- # - Attributes
- if ($numAttributes > 0) {
- foreach my $attribute (@{$interface->attributes}) {
- next if SkipAttribute($attribute);
- AddIncludesForType($attribute->signature->type);
- my $idlType = $attribute->signature->type;
- my $attributeName = $attribute->signature->name;
- my $attributeType = GetObjCType($attribute->signature->type);
- my $attributeClassName = GetClassName($attribute->signature->type);
- my $attributeInterfaceName = $attributeName;
- if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") {
- # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts.
- $attributeInterfaceName .= "Name";
- } 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 ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute);
- 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->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 = ")";
- 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(WebCore::SVGLengthContext(IMPL->contextElement()), ";
- }
- }
- my $attributeTypeSansPtr = $attributeType;
- $attributeTypeSansPtr =~ s/ \*$//; # Remove trailing " *" from pointer types.
- # special case for EventTarget protocol
- $attributeTypeSansPtr = "DOMNode" if $idlType eq "EventTarget";
- # Special cases
- my @customGetterContent = ();
- if ($attributeTypeSansPtr eq "DOMImplementation") {
- # FIXME: We have to special case DOMImplementation until DOMImplementationFront is removed
- $getterContentHead = "kit(implementationFront(IMPL";
- $getterContentTail .= ")";
- } elsif ($attributeName =~ /(\w+)DisplayString$/) {
- my $attributeToDisplay = $1;
- $getterContentHead = "WebCore::displayString(IMPL->$attributeToDisplay(), core(self)";
- $implIncludes{"HitTestResult.h"} = 1;
- } elsif ($attributeName =~ /^absolute(\w+)URL$/) {
- my $typeOfURL = $1;
- $getterContentHead = "[self _getURLAttribute:";
- if ($typeOfURL eq "Link") {
- $getterContentTail = "\@\"href\"]";
- } elsif ($typeOfURL eq "Image") {
- if ($interfaceName eq "HTMLObjectElement") {
- $getterContentTail = "\@\"data\"]";
- } else {
- $getterContentTail = "\@\"src\"]";
- }
- unless ($interfaceName eq "HTMLImageElement") {
- push(@customGetterContent, " if (!IMPL->renderer() || !IMPL->renderer()->isImage())\n");
- push(@customGetterContent, " return nil;\n");
- $implIncludes{"RenderObject.h"} = 1;
- }
- }
- $implIncludes{"DOMPrivate.h"} = 1;
- } 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) or $implClassName eq "SVGViewSpec") 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 .= ")";
- } 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->SkipIncludeHeader($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 .= "))";
- }
- }
- my $getterContent;
- 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 = $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).
- if ($attributeType =~ /\*$/) {
- $getterContent = $attributeType . "result = " . $getterContent;
- } else {
- $getterContent = $attributeType . " result = " . $getterContent;
- }
- push(@implContent, " $exceptionInit\n");
- push(@implContent, " $getterContent;\n");
- push(@implContent, " $exceptionRaiseOnError\n");
- push(@implContent, " return result;\n");
- } else {
- push(@implContent, " return $getterContent;\n");
- }
- push(@implContent, "}\n");
- # - SETTER
- if (!$attribute->isReadOnly) {
- # Exception handling
- 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 ObjCImplementedAsUnsignedLong is flipped for the setter
- if ($attribute->signature->extendedAttributes->{"ObjCImplementedAsUnsignedLong"}) {
- $arg = "WTF::String($arg).toInt()";
- }
- my $setterSig = "- (void)$setterName:($attributeType)$argName\n";
- push(@implContent, "\n");
- push(@implContent, $setterSig);
- push(@implContent, "{\n");
- push(@implContent, " $jsContextSetter\n");
- unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
- push(@implContent, " ASSERT($argName);\n\n");
- }
- if ($idlType eq "Date") {
- $arg = "core(" . $arg . ")";
- }
- if ($svgPropertyType) {
- $implIncludes{"ExceptionCode.h"} = 1;
- $getterContentHead = "$getterExpressionPrefix";
- push(@implContent, " if (IMPL->isReadOnly()) {\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, WebCore::SVGLengthContext(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");
- } else {
- 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 {
- $functionName = "IMPL->${functionName}";
- }
- push(@implContent, " ${functionName}(" . join(", ", @arguments) . ");\n");
- push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException;
- }
- push(@implContent, "}\n");
- }
- push(@implContent, "#endif\n") if $attributeConditionalString;
- push(@implContent, "\n");
- }
- }
- # - Functions
- if ($numFunctions > 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 $hasParameters = @{$function->parameters};
- my $raisesExceptions = $function->signature->extendedAttributes->{"RaisesException"};
- my @parameterNames = ();
- my @needsAssert = ();
- my %needsCustom = ();
- my $parameterIndex = 0;
- my $functionSig = "- ($returnType)$functionName";
- foreach my $param (@{$function->parameters}) {
- my $paramName = $param->name;
- my $paramType = GetObjCType($param->type);
- # make a new parameter name if the original conflicts with a property name
- $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
- AddIncludesForType($param->type);
- my $idlType = $param->type;
- my $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->{"CustomReturn"};
- unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
- push(@needsAssert, " ASSERT($paramName);\n");
- }
- if ($parameterIndex >= 1) {
- $functionSig .= " " . $param->name;
- }
- $functionSig .= ":($paramType)$paramName";
- $parameterIndex++;
- }
- my @functionContent = ();
- my $caller = "IMPL";
- # special case the XPathNSResolver
- if (defined $needsCustom{"XPathNSResolver"}) {
- my $paramName = $needsCustom{"XPathNSResolver"};
- push(@functionContent, " WebCore::XPathNSResolver* nativeResolver = 0;\n");
- push(@functionContent, " RefPtr<WebCore::XPathNSResolver> customResolver;\n");
- push(@functionContent, " if ($paramName) {\n");
- push(@functionContent, " if ([$paramName isMemberOfClass:[DOMNativeXPathNSResolver class]])\n");
- push(@functionContent, " nativeResolver = core(static_cast<DOMNativeXPathNSResolver *>($paramName));\n");
- push(@functionContent, " else {\n");
- push(@functionContent, " customResolver = WebCore::DOMCustomXPathNSResolver::create($paramName);\n");
- push(@functionContent, " nativeResolver = WTF::getPtr(customResolver);\n");
- push(@functionContent, " }\n");
- push(@functionContent, " }\n");
- }
- # special case the EventTarget
- if (defined $needsCustom{"EventTarget"}) {
- my $paramName = $needsCustom{"EventTarget"};
- push(@functionContent, " DOMNode* ${paramName}ObjC = $paramName;\n");
- push(@functionContent, " WebCore::Node* ${paramName}Node = core(${paramName}ObjC);\n");
- $implIncludes{"DOMNode.h"} = 1;
- $implIncludes{"Node.h"} = 1;
- }
- if ($function->signature->extendedAttributes->{"ObjCUseDefaultView"}) {
- push(@functionContent, " WebCore::DOMWindow* dv = $caller->defaultView();\n");
- push(@functionContent, " if (!dv)\n");
- push(@functionContent, " return nil;\n");
- $implIncludes{"DOMWindow.h"} = 1;
- $caller = "dv";
- }
- # special case the EventListener
- if (defined $needsCustom{"EventListener"}) {
- my $paramName = $needsCustom{"EventListener"};
- push(@functionContent, " RefPtr<WebCore::EventListener> nativeEventListener = WebCore::ObjCEventListener::wrap($paramName);\n");
- }
- # special case the NodeFilter
- if (defined $needsCustom{"NodeFilter"}) {
- my $paramName = $needsCustom{"NodeFilter"};
- push(@functionContent, " RefPtr<WebCore::NodeFilter> nativeNodeFilter;\n");
- push(@functionContent, " if ($paramName)\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, "WebCore::SVGLengthContext(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 = $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;
- 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) . ")";
- } elsif ($svgPropertyType) {
- $implIncludes{"ExceptionCode.h"} = 1;
- push(@functionContent, " if (IMPL->isReadOnly()) {\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." . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
- } else {
- $content = "$caller->" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
- }
- if ($returnType eq "void") {
- # Special case 'void' return type.
- 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
- # and appendChild functions from DOMNode
- my $toReturn = $needsCustom{"NodeToReturn"};
- if ($raisesExceptions) {
- push(@functionContent, " $exceptionInit\n");
- push(@functionContent, " if ($content)\n");
- push(@functionContent, " return $toReturn;\n");
- push(@functionContent, " $exceptionRaiseOnError\n");
- push(@functionContent, " return nil;\n");
- } else {
- push(@functionContent, " if ($content)\n");
- push(@functionContent, " return $toReturn;\n");
- push(@functionContent, " return nil;\n");
- }
- } elsif ($returnType eq "SerializedScriptValue") {
- $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))";
- }
- }
- if ($raisesExceptions) {
- # Differentiated between when the return type is a pointer and
- # not for white space issue (ie. Foo *result vs. int result).
- if ($returnType =~ /\*$/) {
- $content = $returnType . "result = " . $content;
- } else {
- $content = $returnType . " result = " . $content;
- }
- push(@functionContent, " $exceptionInit\n");
- push(@functionContent, " $content;\n");
- push(@functionContent, " $exceptionRaiseOnError\n");
- push(@functionContent, " return result;\n");
- } else {
- push(@functionContent, " return $content;\n");
- }
- }
- my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature);
- push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
- push(@implContent, "$functionSig\n");
- push(@implContent, "{\n");
- push(@implContent, " $jsContextSetter\n");
- push(@implContent, @functionContent);
- push(@implContent, "}\n\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->{"ObjCLegacyUnnamedParameters"}) {
- my $deprecatedFunctionSig = $functionSig;
- $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
- push(@implContent, "$deprecatedFunctionSig\n");
- push(@implContent, "{\n");
- push(@implContent, " $jsContextSetter\n");
- push(@implContent, @functionContent);
- push(@implContent, "}\n\n");
- }
- # Clear the hash
- %needsCustom = ();
- }
- }
- # END implementation
- push(@implContent, "\@end\n");
- # Generate internal interfaces
- push(@implContent, "\n$implType* core($className *wrapper)\n");
- push(@implContent, "{\n");
- push(@implContent, " return wrapper ? reinterpret_cast<$implType*>(wrapper->_internal) : 0;\n");
- push(@implContent, "}\n\n");
- if ($parentImplClassName eq "Object") {
- push(@implContent, "$className *kit($implType* value)\n");
- push(@implContent, "{\n");
- push(@implContent, " $assertMainThread;\n");
- push(@implContent, " if (!value)\n");
- push(@implContent, " return nil;\n");
- push(@implContent, " if ($className *wrapper = getDOMWrapper(value))\n");
- push(@implContent, " return [[wrapper retain] autorelease];\n");
- if ($interface->extendedAttributes->{"ObjCPolymorphic"}) {
- push(@implContent, " $className *wrapper = [[kitClass(value) alloc] _init];\n");
- push(@implContent, " if (!wrapper)\n");
- push(@implContent, " return nil;\n");
- } else {
- push(@implContent, " $className *wrapper = [[$className alloc] _init];\n");
- }
- push(@implContent, " wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(value);\n");
- push(@implContent, " value->ref();\n");
- push(@implContent, " addDOMWrapper(wrapper, value);\n");
- push(@implContent, " return [wrapper autorelease];\n");
- push(@implContent, "}\n");
- } else {
- push(@implContent, "$className *kit($implType* value)\n");
- push(@implContent, "{\n");
- push(@implContent, " $assertMainThread;\n");
- push(@implContent, " return static_cast<$className*>(kit(static_cast<WebCore::$baseClass*>(value)));\n");
- push(@implContent, "}\n");
- }
- # - End the ifdef conditional if necessary
- push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
- # - Generate dependencies.
- if ($writeDependencies && @ancestorInterfaceNames) {
- push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n");
- push(@depsContent, map { "$_.idl :\n" } @ancestorInterfaceNames);
- }
- }
- # Internal helper
- sub WriteData
- {
- my $object = shift;
- my $dataNode = shift;
- my $outputDir = shift;
- # Open files for writing...
- my $name = $dataNode->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.
- my $contents = join "", @headerContentHeader;
- map { $contents .= "\@class $_;\n" } sort keys(%headerForwardDeclarations);
- map { $contents .= "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
- my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols);
- $contents .= "\n" if $hasForwardDeclarations;
- $contents .= join "", @headerContent;
- $codeGenerator->UpdateFile($headerFileName, $contents);
- @headerContentHeader = ();
- @headerContent = ();
- %headerForwardDeclarations = ();
- %headerForwardDeclarationsForProtocols = ();
- if (@privateHeaderContent > 0) {
- $contents = join "", @privateHeaderContentHeader;
- map { $contents .= "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
- map { $contents .= "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
- $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols);
- $contents .= "\n" if $hasForwardDeclarations;
- $contents .= join "", @privateHeaderContent;
- $codeGenerator->UpdateFile($privateHeaderFileName, $contents);
- @privateHeaderContentHeader = ();
- @privateHeaderContent = ();
- %privateHeaderForwardDeclarations = ();
- %privateHeaderForwardDeclarationsForProtocols = ();
- }
- # Write implementation file.
- unless ($noImpl) {
- $contents = join "", @implContentHeader;
- map { $contents .= "#import \"$_\"\n" } sort keys(%implIncludes);
- $contents .= join "", @implContent;
- $codeGenerator->UpdateFile($implFileName, $contents);
- @implContentHeader = ();
- @implContent = ();
- %implIncludes = ();
- }
- if (@internalHeaderContent > 0) {
- $contents = join "", @internalHeaderContent;
- $codeGenerator->UpdateFile($internalHeaderFileName, $contents);
- @internalHeaderContent = ();
- }
- # Write dependency file.
- if (@depsContent) {
- $contents = join "", @depsContent;
- $codeGenerator->UpdateFile($depsFileName, $contents);
- @depsContent = ();
- }
- }
- 1;
|