📄 codegeneratorobjc.pm
字号:
# 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 = $codeGenerator->StripModule(shift); return "DOMImplementationFront" if $name eq "DOMImplementation"; return "DOMWindow" if $name eq "AbstractView"; return $name;}sub GetParentImplClassName{ my $dataNode = shift; return "Object" if @{$dataNode->parents} eq 0; my $parent = $codeGenerator->StripModule($dataNode->parents(0)); # special cases return "Object" if $parent eq "HTMLCollection"; return $parent;}sub GetParentAndProtocols{ my $dataNode = shift; my $numParents = @{$dataNode->parents}; my $parent = ""; my @protocols = (); if ($numParents eq 0) { if ($isProtocol) { push(@protocols, "NSObject"); push(@protocols, "NSCopying") if $dataNode->name eq "EventTarget"; } else { $parent = "DOMObject"; } } elsif ($numParents eq 1) { my $parentName = $codeGenerator->StripModule($dataNode->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 = @{$dataNode->parents}; my $firstParent = $codeGenerator->StripModule(shift(@parents)); if (IsProtocolType($firstParent)) { push(@protocols, "DOM" . $firstParent); if (!$isProtocol) { $parent = "DOMObject"; } } else { $parent = "DOM" . $firstParent; } 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); } } return ($parent, @protocols);}sub GetBaseClass{ $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 "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 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" or $type eq "SVGPaintType"; return "$name *";}sub GetPropertyAttributes{ my $type = $codeGenerator->StripModule(shift); my $readOnly = shift; my @attributes = (); push(@attributes, "readonly") if $readOnly;# FIXME: uncomment these lines once <rdar://problem/4996504> is fixed.# unless ($readOnly) { if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) { push(@attributes, "copy"); } elsif ($codeGenerator->IsPodType($type) || $codeGenerator->IsSVGAnimatedType($type)) { push(@attributes, "retain"); } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow" && $type ne "SVGPaintType") { push(@attributes, "retain"); }# } return "" unless @attributes > 0; return "(" . join(", ", @attributes) . ")";}sub GetObjCTypeMaker{ my $type = $codeGenerator->StripModule(shift); return "" if $codeGenerator->IsNonPointerType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type); return "_wrapAbstractView" if $type eq "DOMWindow"; return "_wrap$type";}sub GetObjCTypeGetterName{ my $type = $codeGenerator->StripModule(shift); my $typeGetter = ""; if ($type =~ /^(HTML|CSS|SVG)/ or $type eq "DOMImplementation" or $type eq "CDATASection" or $type eq "RGBColor") { $typeGetter = $type; } elsif ($type =~ /^XPath(.+)/) { $typeGetter = "xpath" . $1; } elsif ($type eq "DOMWindow") { $typeGetter = "abstractView"; } else { $typeGetter = lcfirst($type); } # put into the form "_fooBar" for type FooBar. return "_" . $typeGetter;}sub GetObjCTypeGetter{ my $argName = shift; my $type = $codeGenerator->StripModule(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 "static_cast<WebCore::SVGPaint::SVGPaintType>($argName)" if $type eq "SVGPaintType"; my $typeGetterMethodName = GetObjCTypeGetterName($type); return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener"; return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter"; return "WTF::getPtr(nativeResolver)" if $type eq "XPathNSResolver"; return "[$argName $typeGetterMethodName]";}sub GetInternalTypeGetterSignature{ my ($interfaceName, $podType) = @_; my $implClassNameWithNamespace = "WebCore::" . GetImplClassName($interfaceName); my $podTypeWithNamespace; if ($podType) { $podTypeWithNamespace = ($podType eq "float") ? "$podType" : "WebCore::$podType"; } # - Type-Getter # - (WebCore::FooBar *)_fooBar for implementation class FooBar my $typeGetterName = GetObjCTypeGetterName($interfaceName); return "- " . ($podType ? "($podTypeWithNamespace)" : "($implClassNameWithNamespace *)") . $typeGetterName;}sub GetInternalTypeMakerSignature{ my ($interfaceName, $podType) = @_; my $className = GetClassName($interfaceName); my $implClassNameWithNamespace = "WebCore::" . GetImplClassName($interfaceName); my $podTypeWithNamespace; if ($podType) { $podTypeWithNamespace = ($podType eq "float") ? "$podType" : "WebCore::$podType"; } my @ivarsToRetain = (); my $ivarsToInit = ""; my $typeMakerSigAddition = ""; if (@ivars > 0) { my @ivarsInitSig = (); my @ivarsInitCall = (); foreach $attribute (@ivars) { my $name = $attribute->signature->name; my $memberName = "m_" . $name; my $varName = "in" . $name; my $type = GetObjCType($attribute->signature->type); push(@ivarsInitSig, "$name:($type)$varName"); push(@ivarsInitCall, "$name:$varName"); push(@ivarsToRetain, " $memberName = [$varName retain];\n"); } $ivarsToInit = " " . join(" ", @ivarsInitCall); $typeMakerSigAddition = " " . join(" ", @ivarsInitSig); } my $typeMakerName = GetObjCTypeMaker($interfaceName); return ("+ ($className *)$typeMakerName:(" . ($podType ? "$podTypeWithNamespace" : "$implClassNameWithNamespace *") . ")impl" . $typeMakerSigAddition, $typeMakerSigAddition, $ivarsToInit);}sub AddForwardDeclarationsForType{ my $type = $codeGenerator->StripModule(shift); my $public = shift; return if $codeGenerator->IsNonPointerType($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 = $codeGenerator->StripModule(shift); return if $codeGenerator->IsNonPointerType($type) or IsNativeObjCType($type); if ($codeGenerator->IsStringType($type)) { $implIncludes{"KURL.h"} = 1; return; } if ($type eq "RGBColor") { $implIncludes{"Color.h"} = 1; $implIncludes{"DOM$type.h"} = 1; return; } if ($type eq "DOMWindow") { $implIncludes{"DOMAbstractView.h"} = 1; $implIncludes{"$type.h"} = 1; return; } if ($type eq "DOMImplementation") { $implIncludes{"DOMImplementationFront.h"} = 1; $implIncludes{"DOM$type.h"} = 1; return; } if ($type eq "EventTarget") { $implIncludes{"Node.h"} = 1; $implIncludes{"DOM$type.h"} = 1; return; } if ($codeGenerator->IsSVGAnimatedType($type)) { $implIncludes{"SVGAnimatedTemplate.h"} = 1; $implIncludes{"DOM$type.h"} = 1; return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -