⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codegeneratorobjc.pm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 PM
📖 第 1 页 / 共 5 页
字号:
    if ($type eq "SVGRect") {        $implIncludes{"FloatRect.h"} = 1;        $implIncludes{"DOM$type.h"} = 1;        return;    }    if ($type eq "SVGPoint") {        $implIncludes{"FloatPoint.h"} = 1;        $implIncludes{"DOM$type.h"} = 1;        return;    }    if ($type eq "SVGMatrix") {        $implIncludes{"TransformationMatrix.h"} = 1;        $implIncludes{"DOM$type.h"} = 1;        $implIncludes{"SVGException.h"} = 1;        return;    }    if ($type eq "SVGNumber") {        $implIncludes{"DOM$type.h"} = 1;        return;    }    if ($type =~ /(\w+)(Abs|Rel)$/) {        $implIncludes{"$1.h"} = 1;        $implIncludes{"DOM$type.h"} = 1;        return;    }    $implIncludes{"ObjCEventListener.h"} = 1 if $type eq "EventListener";    $implIncludes{"ObjCNodeFilterCondition.h"} = 1 if $type eq "NodeFilter";    $implIncludes{"DOMCustomXPathNSResolver.h"} = 1 if $type eq "XPathNSResolver";    # FIXME: won't compile without these    $implIncludes{"CSSMutableStyleDeclaration.h"} = 1 if $type eq "CSSStyleDeclaration";    $implIncludes{"NamedAttrMap.h"} = 1 if $type eq "NamedNodeMap";    $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;    $implIncludes{"DOM$type.h"} = 1;}sub GenerateHeader{    my $object = shift;    my $dataNode = shift;    my $interfaceName = $dataNode->name;    my $className = GetClassName($interfaceName);    my $parentName = "";    my @protocolsToImplement = ();    ($parentName, @protocolsToImplement) = GetParentAndProtocols($dataNode);    my $numConstants = @{$dataNode->constants};    my $numAttributes = @{$dataNode->attributes};    my $numFunctions = @{$dataNode->functions};    # - Add default header template    @headerContentHeader = split("\r", $headerLicenceTemplate);    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 = ();        # FIXME: we need a way to include multiple enums.        foreach my $constant (@{$dataNode->constants}) {            my $constantName = $constant->name;            my $constantValue = $constant->value;            my $output = "    DOM_" . $constantName . " = " . $constantValue;            push(@headerConstants, $output);        }        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");            }    # - 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) {        # Add ivars, if any, first        @ivars = ();        foreach my $attribute (@{$dataNode->attributes}) {            push(@ivars, $attribute) if $attribute->signature->extendedAttributes->{"ObjCIvar"};        }        if (@ivars > 0) {            push(@headerContent, "{\n");            foreach my $attribute (@ivars) {                my $type = GetObjCType($attribute->signature->type);                my $name = "m_" . $attribute->signature->name;                my $ivarDeclaration = "$type $name";                push(@headerContent, "    $ivarDeclaration;\n");            }            push(@headerContent, "}\n");        }        foreach my $attribute (@{$dataNode->attributes}) {            my $attributeName = $attribute->signature->name;            if ($attributeName eq "id" or $attributeName eq "hash") {                # Special case attributes id and hash to be idName and hashName to avoid ObjC naming conflict.                $attributeName .= "Name";            } elsif ($attributeName eq "frame") {                # Special case attribute frame to be frameBorders.                $attributeName .= "Borders";            }            my $attributeType = GetObjCType($attribute->signature->type);            my $attributeIsReadonly = ($attribute->type =~ /^readonly/);            my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attributeIsReadonly);            $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName;            my $publicInterfaceKey = $property . ";";            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;            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;            }            if ($buildingForLeopardOrLater) {                $property .= $declarationSuffix;                push(@headerAttributes, $property) if $public;                push(@privateHeaderAttributes, $property) unless $public;            } else {                # - GETTER                my $getter = "- (" . $attributeType . ")" . $attributeName . $declarationSuffix;                push(@headerAttributes, $getter) if $public;                push(@privateHeaderAttributes, $getter) unless $public;                # - SETTER                if (!$attributeIsReadonly) {                    my $setter = "- (void)$setterName(" . $attributeType . ")new" . ucfirst($attributeName) . $declarationSuffix;                    push(@headerAttributes, $setter) if $public;                    push(@privateHeaderAttributes, $setter) unless $public;                }            }        }        push(@headerContent, @headerAttributes) if @headerAttributes > 0;    }    my @headerFunctions = ();    my @privateHeaderFunctions = ();    my @deprecatedHeaderFunctions = ();    # - Add functions.    if ($numFunctions > 0) {        foreach my $function (@{$dataNode->functions}) {            my $functionName = $function->signature->name;            my $returnType = GetObjCType($function->signature->type);            my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"});            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) {                    my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};                    $paramPrefix = $paramName unless defined($paramPrefix);                    $functionSig .= " $paramPrefix";                    $methodName .= $paramPrefix;                }                $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};            }            $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if length $availabilityMacro and $buildingForTigerOrEarlier;            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;            }            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};                }                $availabilityMacro = "WEBKIT_OBJC_METHOD_ANNOTATION($availabilityMacro)" if $buildingForTigerOrEarlier;                $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 OldStyleObjC IDL attribute removed";                    $fatalError = 1;                }                delete $publicInterfaces{$publicInterfaceKey};            }        }        if (@headerFunctions > 0) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -