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

📄 make_names.pl

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 PL
📖 第 1 页 / 共 2 页
字号:
    if (keys %attrs) {        print F "\n// Attributes\n";        for my $name (sort keys %attrs) {            print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Attr, nullAtom, \"$name\", ${lowerNamespace}NamespaceURI);\n";        }        print F "\n\nWebCore::QualifiedName** get$parameters{'namespace'}Attrs(size_t* size)\n";        print F "{\n    static WebCore::QualifiedName* $parameters{'namespace'}Attr[] = {\n";        for my $name (sort keys %attrs) {            print F "        (WebCore::QualifiedName*)&${name}Attr,\n";        }        print F "    };\n";        print F "    *size = ", scalar(keys %attrs), ";\n";        print F "    return $parameters{'namespace'}Attr;\n";        print F "}\n";    }    if (keys %tags) {        printDefinitionStrings($F, \%tags, "tags");    }    if (keys %attrs) {        printDefinitionStrings($F, \%attrs, "attributes");    }print F "\nvoid init(){    static bool initialized = false;    if (initialized)        return;    initialized = true;        // Use placement new to initialize the globals.        AtomicString::init();";        print(F "    AtomicString ${lowerNamespace}NS(\"$parameters{'namespaceURI'}\");\n\n");    print(F "    // Namespace\n");    print(F "    new ((void*)&${lowerNamespace}NamespaceURI) AtomicString(${lowerNamespace}NS);\n\n");    if (keys %tags) {        my $tagsNamespace = $parameters{'tagsNullNamespace'} ? "nullAtom" : "${lowerNamespace}NS";        printDefinitions($F, \%tags, "tags", $tagsNamespace);    }    if (keys %attrs) {        my $attrsNamespace = $parameters{'attrsNullNamespace'} ? "nullAtom" : "${lowerNamespace}NS";        printDefinitions($F, \%attrs, "attributes", $attrsNamespace);    }    print F "}\n\n} }\n\n";    close F;}sub printJSElementIncludes{    my $F = shift;    my %tagsSeen;    for my $tagName (sort keys %tags) {        my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"};        next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName);        $tagsSeen{$JSInterfaceName} = 1;        print F "#include \"JS${JSInterfaceName}.h\"\n";    }}sub printElementIncludes{    my $F = shift;    my %tagsSeen;    for my $tagName (sort keys %tags) {        my $interfaceName = $tags{$tagName}{"interfaceName"};        next if defined($tagsSeen{$interfaceName});        $tagsSeen{$interfaceName} = 1;        print F "#include \"${interfaceName}.h\"\n";    }}sub printDefinitionStrings{    my ($F, $namesRef, $type) = @_;    my $singularType = substr($type, 0, -1);    my $shortType = substr($singularType, 0, 4);    my $shortCamelType = ucfirst($shortType);    print F "\n// " . ucfirst($type) . " as strings\n";    my %names = %$namesRef;    for my $name (sort keys %$namesRef) {        next if (!$parameters{'exportStrings'} and !$names{$name}{"exportString"});        my $realName = $name;        $realName =~ s/_/-/g;        print F "char $name","${shortCamelType}String[] = \"$realName\";\n";    }} sub printDefinitions{    my ($F, $namesRef, $type, $namespaceURI) = @_;    my $singularType = substr($type, 0, -1);    my $shortType = substr($singularType, 0, 4);    my $shortCamelType = ucfirst($shortType);    my $shortUpperType = uc($shortType);        print F "    // " . ucfirst($type) . "\n";    my %names = %$namesRef;    for my $name (sort keys %$namesRef) {        next if ($parameters{'exportStrings'} or $names{$name}{"exportString"});        my $realName = $name;        $realName =~ s/_/-/g;        print F "    const char *$name","${shortCamelType}String = \"$realName\";\n";    }    print "\n";    for my $name (sort keys %$namesRef) {        print F "    new ((void*)&$name","${shortCamelType}) QualifiedName(nullAtom, $name","${shortCamelType}String, $namespaceURI);\n";    }}## ElementFactory routinessub printFactoryCppFile{    my $cppPath = shift;    my $F;    open F, ">$cppPath";printLicenseHeader($F);print F <<END#include "config.h"#include "$parameters{'namespace'}ElementFactory.h"#include "$parameters{'namespace'}Names.h"#if ENABLE(DASHBOARD_SUPPORT)#include "Document.h"#include "Settings.h"#endifEND;if ($parameters{'namespace'} eq "HTML") {    print F "#include \"HTMLFormElement.h\"\n";}printElementIncludes($F);print F <<END#include <wtf/HashMap.h>namespace WebCore {using namespace $parameters{'namespace'}Names;END;print F "typedef PassRefPtr<$parameters{'namespace'}Element> (*ConstructorFunction)(const QualifiedName&, Document*";if ($parameters{'namespace'} eq "HTML") {    print F ", HTMLFormElement*";}print F ", bool createdByParser);\n";print F <<ENDtypedef HashMap<AtomicStringImpl*, ConstructorFunction> FunctionMap;static FunctionMap* gFunctionMap = 0;END;my %tagConstructorMap = buildConstructorMap();printConstructors($F, \%tagConstructorMap);print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'};print F <<ENDstatic void addTag(const QualifiedName& tag, ConstructorFunction func){    gFunctionMap->set(tag.localName().impl(), func);}static inline void createFunctionMapIfNecessary(){    if (gFunctionMap)        return;    // Create the table.    gFunctionMap = new FunctionMap;        // Populate it with constructor functions.END;printFunctionInits($F, \%tagConstructorMap);print F "}\n";print F "#endif\n" if $parameters{'guardFactoryWith'};print F "\nPassRefPtr<$parameters{'namespace'}Element> $parameters{'namespace'}ElementFactory::create$parameters{'namespace'}Element(const QualifiedName& qName, Document* doc";if ($parameters{"namespace"} eq "HTML") {    print F ", HTMLFormElement* formElement";}print F ", bool createdByParser)\n{\n";print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'};print F <<END    // Don't make elements without a document    if (!doc)        return 0;END;if ($parameters{'namespace'} ne "HTML") {print F <<END#if ENABLE(DASHBOARD_SUPPORT)    Settings* settings = doc->settings();    if (settings && settings->usesDashboardBackwardCompatibilityMode())        return 0;#endifEND;}print F <<END    createFunctionMapIfNecessary();    ConstructorFunction func = gFunctionMap->get(qName.localName().impl());    if (func)END;if ($parameters{"namespace"} eq "HTML") {    print F "        return func(qName, doc, formElement, createdByParser);\n";} else {    print F "        return func(qName, doc, createdByParser);\n";}print F "    return new $parameters{'namespace'}Element(qName, doc);\n";if ($parameters{'guardFactoryWith'}) {print F <<END#else    return 0;#endifEND;}print F <<END}} // namespace WebCoreEND;    close F;}sub printFactoryHeaderFile{    my $headerPath = shift;    my $F;    open F, ">$headerPath";    printLicenseHeader($F);    print F<<END#ifndef $parameters{'namespace'}ElementFactory_h#define $parameters{'namespace'}ElementFactory_h#include <wtf/PassRefPtr.h>namespace WebCore {    class Element;    class Document;    class QualifiedName;    class AtomicString;}namespace WebCore {    class $parameters{'namespace'}Element;END;if ($parameters{'namespace'} eq "HTML") {    print F "     class HTMLFormElement;\n";}print F<<END    // The idea behind this class is that there will eventually be a mapping from namespace URIs to ElementFactories that can dispense    // elements. In a compound document world, the generic createElement function (will end up being virtual) will be called.    class $parameters{'namespace'}ElementFactory {    public:        PassRefPtr<Element> createElement(const WebCore::QualifiedName&, WebCore::Document*, bool createdByParser = true);END;print F "        static PassRefPtr<$parameters{'namespace'}Element> create$parameters{'namespace'}Element(const WebCore::QualifiedName&, WebCore::Document*";if ($parameters{'namespace'} eq "HTML") {    print F ", HTMLFormElement* = 0";}print F ", bool /*createdByParser*/ = true);\n";printf F<<END    };}#endif // $parameters{'namespace'}ElementFactory_hEND;    close F;}## Wrapper Factory routinessub usesDefaultJSWrapper{    my $name = shift;    # A tag reuses the default wrapper if its JSInterfaceName matches the default namespace Element.    return $tags{$name}{'JSInterfaceName'} eq $parameters{"namespace"} . "Element";}sub printWrapperFunctions{    my $F = shift;    my %tagsSeen;    for my $tagName (sort keys %tags) {        # Avoid defining the same wrapper method twice.        my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"};        next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName);        $tagsSeen{$JSInterfaceName} = 1;        # Hack for the media tags        if ($tags{$tagName}{"wrapperOnlyIfMediaIsAvailable"}) {            print F <<ENDstatic JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element){    if (!MediaPlayer::isAvailable())        return CREATE_DOM_NODE_WRAPPER(exec, $parameters{'namespace'}Element, element.get());    return CREATE_DOM_NODE_WRAPPER(exec, ${JSInterfaceName}, element.get());}END;        } else {            print F <<ENDstatic JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element){    return CREATE_DOM_NODE_WRAPPER(exec, ${JSInterfaceName}, element.get());}END;        }    }}sub printWrapperFactoryCppFile{    my $cppPath = shift;    my $F;    open F, ">$cppPath";    printLicenseHeader($F);    print F "#include \"config.h\"\n\n";    print F "#if $parameters{'guardFactoryWith'}\n\n" if $parameters{'guardFactoryWith'};    print F "#include \"JS$parameters{'namespace'}ElementWrapperFactory.h\"\n";    printJSElementIncludes($F);    print F "\n#include \"$parameters{'namespace'}Names.h\"\n\n";    printElementIncludes($F);    print F "\n#include <wtf/StdLibExtras.h>\n\n";        print F <<ENDusing namespace JSC;namespace WebCore {using namespace $parameters{'namespace'}Names;typedef JSNode* (*Create$parameters{'namespace'}ElementWrapperFunction)(ExecState*, PassRefPtr<$parameters{'namespace'}Element>);END;    printWrapperFunctions($F);    print F <<ENDJSNode* createJS$parameters{'namespace'}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element){       typedef HashMap<WebCore::AtomicStringImpl*, Create$parameters{'namespace'}ElementWrapperFunction> FunctionMap;    DEFINE_STATIC_LOCAL(FunctionMap, map, ());    if (map.isEmpty()) {END;    for my $tag (sort keys %tags) {        # Do not add the name to the map if it does not have a JS wrapper constructor or uses the default wrapper.        next if usesDefaultJSWrapper($tag, \%tags);        my $ucTag = $tags{$tag}{"JSInterfaceName"};        print F "       map.set(${tag}Tag.localName().impl(), create${ucTag}Wrapper);\n";    }    print F <<END    }    Create$parameters{'namespace'}ElementWrapperFunction createWrapperFunction = map.get(element->localName().impl());    if (createWrapperFunction)        return createWrapperFunction(exec, element);    return CREATE_DOM_NODE_WRAPPER(exec, $parameters{'namespace'}Element, element.get());}}END;    print F "#endif\n" if $parameters{'guardFactoryWith'};    close F;}sub printWrapperFactoryHeaderFile{    my $headerPath = shift;    my $F;    open F, ">$headerPath";    printLicenseHeader($F);    print F "#ifndef JS$parameters{'namespace'}ElementWrapperFactory_h\n";    print F "#define JS$parameters{'namespace'}ElementWrapperFactory_h\n\n";    print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'};    print F <<END#include <wtf/Forward.h>namespace JSC {    class ExecState;}                                                                                         namespace WebCore {    class JSNode;    class $parameters{'namespace'}Element;    JSNode* createJS$parameters{'namespace'}Wrapper(JSC::ExecState*, PassRefPtr<$parameters{'namespace'}Element>);} END;    print F "#endif // $parameters{'guardFactoryWith'}\n\n" if $parameters{'guardFactoryWith'};    print F "#endif // JS$parameters{'namespace'}ElementWrapperFactory_h\n";    close F;}

⌨️ 快捷键说明

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