📄 codegeneratorcom.pm
字号:
## 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 Apple Inc. 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# aint with this library; see the file COPYING.LIB. If not, write to# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,# Boston, MA 02111-1307, USA.package CodeGeneratorCOM;use File::stat;# Global Variablesmy $module = "";my $outputDir = "";my @IDLHeader = ();my @IDLContent = ();my %IDLIncludes = ();my %IDLForwardDeclarations = ();my %IDLDontForwardDeclare = ();my %IDLImports = ();my %IDLDontImport = ();my @CPPInterfaceHeader = ();my @CPPHeaderHeader = ();my @CPPHeaderContent = ();my %CPPHeaderIncludes = ();my %CPPHeaderIncludesAngle = ();my %CPPHeaderForwardDeclarations = ();my %CPPHeaderDontForwardDeclarations = ();my @CPPImplementationHeader = ();my @CPPImplementationContent = ();my %CPPImplementationIncludes = ();my %CPPImplementationWebCoreIncludes = ();my %CPPImplementationIncludesAngle = ();my %CPPImplementationDontIncludes = ();my @additionalInterfaceDefinitions = ();my $DASHES = "----------------------------------------";my $TEMP_PREFIX = "GEN_";# Hashesmy %includeCorrector = map {($_, 1)} qw{UIEvent KeyboardEvent MouseEvent MutationEvent OverflowEvent WheelEvent};my %conflictMethod = ( # FIXME: Add C language keywords?);# Default License Templatesmy @licenseTemplate = split(/\r/, << "EOF");/* * Copyright (C) 2007 Apple Inc. All rights reserved. * * 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. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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 constructorsub new{ my $object = shift; my $reference = { }; $codeGenerator = shift; $outputDir = shift; bless($reference, $object); return $reference;}sub finish{ my $object = shift;}# Params: 'domClass' structsub GenerateInterface{ my $object = shift; my $dataNode = shift; my $defines = shift; my $name = $dataNode->name; my $pureInterface = $dataNode->extendedAttributes->{"PureInterface"}; # Start actual generation.. $object->GenerateIDL($dataNode, $pureInterface); if ($pureInterface) { $object->GenerateInterfaceHeader($dataNode); } else { $object->GenerateCPPHeader($dataNode); $object->GenerateCPPImplementation($dataNode); } # Write changes. $object->WriteData($name, $pureInterface);}# Params: 'idlDocument' structsub GenerateModule{ my $object = shift; my $dataNode = shift; $module = $dataNode->module;}sub GetInterfaceName{ my $name = $codeGenerator->StripModule(shift); die "GetInterfaceName should only be used on interfaces." if ($codeGenerator->IsStringType($name) or $codeGenerator->IsPrimitiveType($name)); # special cases return "I" . $TEMP_PREFIX . "DOMAbstractView" if $name eq "DOMWindow"; return "I" . $TEMP_PREFIX . $name if $name eq "DOMImplementation" or $name eq "DOMTimeStamp"; # Default, assume COM type has the same type name as # idl type prefixed with "IDOM". return "I" . $TEMP_PREFIX . "DOM" . $name;}sub GetClassName{ my $name = $codeGenerator->StripModule(shift); # special cases return "BSTR" if $codeGenerator->IsStringType($name); return "BOOL" if $name eq "boolean"; return "unsigned" if $name eq "unsigned long"; return "int" if $name eq "long"; return $name if $codeGenerator->IsPrimitiveType($name); return $TEMP_PREFIX . "DOMAbstractView" if $name eq "DOMWindow"; return $TEMP_PREFIX . $name if $name eq "DOMImplementation" or $name eq "DOMTimeStamp"; # Default, assume COM type has the same type name as # idl type prefixed with "DOM". return $TEMP_PREFIX . "DOM" . $name;}sub GetCOMType{ my ($type) = @_; die "Don't use GetCOMType for string types, use one of In/Out variants instead." if $codeGenerator->IsStringType($type); return "BOOL" if $type eq "boolean"; return "UINT" if $type eq "unsigned long"; return "INT" if $type eq "long"; return $type if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp"; # return "unsigned short" if $type eq "CompareHow" or $type eq "SVGPaintType"; return GetInterfaceName($type) . "*";}sub GetCOMTypeIn{ my ($type) = @_; return "LPCTSTR" if $codeGenerator->IsStringType($type); return GetCOMType($type);}sub GetCOMTypeOut{ my ($type) = @_; return "BSTR" if $codeGenerator->IsStringType($type); return GetCOMType($type);}sub IDLTypeToImplementationType{ my $type = $codeGenerator->StripModule(shift); return "bool" if $type eq "boolean"; return "unsigned" if $type eq "unsigned long"; return "int" if $type eq "long"; return $type if $codeGenerator->IsPrimitiveType($type); return "WebCore::String" if $codeGenerator->IsStringType($type); return "WebCore::${type}";}sub StripNamespace{ my ($type) = @_; $type =~ s/^WebCore:://; return $type;}sub GetParentInterface{ my ($dataNode) = @_; return "I" . $TEMP_PREFIX . "DOMObject" if (@{$dataNode->parents} == 0); return GetInterfaceName($codeGenerator->StripModule($dataNode->parents(0)));}sub GetParentClass{ my ($dataNode) = @_; return $TEMP_PREFIX . "DOMObject" if (@{$dataNode->parents} == 0); return GetClassName($codeGenerator->StripModule($dataNode->parents(0)));}sub AddForwardDeclarationsForTypeInIDL{ my $type = $codeGenerator->StripModule(shift); return if $codeGenerator->IsNonPointerType($type) or $codeGenerator->IsStringType($type); my $interface = GetInterfaceName($type); $IDLForwardDeclarations{$interface} = 1; $IDLImports{$interface} = 1;}sub AddIncludesForTypeInCPPHeader{ my $type = $codeGenerator->StripModule(shift); my $useAngleBrackets = shift; return if $codeGenerator->IsNonPointerType($type); # Add special Cases HERE if ($type =~ m/^I/) { $type = "WebKit"; } if ($useAngleBrackets) { $CPPHeaderIncludesAngle{"$type.h"} = 1; return; } if ($type eq "GEN_DOMImplementation") { $CPPHeaderIncludes{"GEN_DOMDOMImplementation.h"} = 1; return; } if ($type eq "IGEN_DOMImplementation") { $CPPHeaderIncludes{"IGEN_DOMDOMImplementation.h"} = 1; return; } $CPPHeaderIncludes{"$type.h"} = 1;}sub AddForwardDeclarationsForTypeInCPPHeader{ my $type = $codeGenerator->StripModule(shift); return if $codeGenerator->IsNonPointerType($type) or $codeGenerator->IsStringType($type); my $interface = GetInterfaceName($type); $CPPHeaderForwardDeclarations{$interface} = 1;}sub AddIncludesForTypeInCPPImplementation{ my $type = $codeGenerator->StripModule(shift); die "Include type not supported!" if $includeCorrector{$type}; return if $codeGenerator->IsNonPointerType($type); if ($codeGenerator->IsStringType($type)) { $CPPImplementationWebCoreIncludes{"AtomicString.h"} = 1; $CPPImplementationWebCoreIncludes{"BString.h"} = 1; $CPPImplementationWebCoreIncludes{"KURL.h"} = 1; return; } # Special casing $CPPImplementationWebCoreIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList"; $CPPImplementationWebCoreIncludes{"CSSMutableStyleDeclaration.h"} = 1 if $type eq "CSSStyleDeclaration"; # Add implementation type $CPPImplementationWebCoreIncludes{StripNamespace(IDLTypeToImplementationType($type)) . ".h"} = 1; my $COMClassName = GetClassName($type); $CPPImplementationIncludes{"${COMClassName}.h"} = 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -