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

📄 codegeneratorjs.pm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 PM
📖 第 1 页 / 共 5 页
字号:
    push(@headerContent, "    virtual void defineGetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction);\n") if $dataNode->extendedAttributes->{"CustomDefineGetter"};    # Custom defineSetter function    push(@headerContent, "    virtual void defineSetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction);\n") if $dataNode->extendedAttributes->{"CustomDefineSetter"};    # Custom lookupGetter function    push(@headerContent, "    virtual JSC::JSValuePtr lookupGetter(JSC::ExecState*, const JSC::Identifier& propertyName);\n") if $dataNode->extendedAttributes->{"CustomLookupGetter"};    # Custom lookupSetter function    push(@headerContent, "    virtual JSC::JSValuePtr lookupSetter(JSC::ExecState*, const JSC::Identifier& propertyName);\n") if $dataNode->extendedAttributes->{"CustomLookupSetter"};    # Constructor object getter    push(@headerContent, "    static JSC::JSValuePtr getConstructor(JSC::ExecState*);\n") if $dataNode->extendedAttributes->{"GenerateConstructor"};    my $numCustomFunctions = 0;    my $numCustomAttributes = 0;    # Attribute and function enums    if ($numAttributes > 0) {        foreach (@{$dataNode->attributes}) {            my $attribute = $_;            $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCCustom"};            $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"CustomGetter"};            $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"CustomSetter"};        }    }    if ($numCustomAttributes > 0) {        push(@headerContent, "\n    // Custom attributes\n");        foreach my $attribute (@{$dataNode->attributes}) {            if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCCustom"}) {                push(@headerContent, "    JSC::JSValuePtr " . $codeGenerator->WK_lcfirst($attribute->signature->name) . "(JSC::ExecState*) const;\n");                if ($attribute->type !~ /^readonly/) {                    push(@headerContent, "    void set" . $codeGenerator->WK_ucfirst($attribute->signature->name) . "(JSC::ExecState*, JSC::JSValuePtr);\n");                }            } elsif ($attribute->signature->extendedAttributes->{"CustomGetter"}) {                push(@headerContent, "    JSC::JSValuePtr " . $codeGenerator->WK_lcfirst($attribute->signature->name) . "(JSC::ExecState*) const;\n");            } elsif ($attribute->signature->extendedAttributes->{"CustomSetter"}) {                if ($attribute->type !~ /^readonly/) {                    push(@headerContent, "    void set" . $codeGenerator->WK_ucfirst($attribute->signature->name) . "(JSC::ExecState*, JSC::JSValuePtr);\n");                }            }        }    }    foreach my $function (@{$dataNode->functions}) {        $numCustomFunctions++ if $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"};    }    if ($numCustomFunctions > 0) {        push(@headerContent, "\n    // Custom functions\n");        foreach my $function (@{$dataNode->functions}) {            if ($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"}) {                my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementationFunction"} || $codeGenerator->WK_lcfirst($function->signature->name);                push(@headerContent, "    JSC::JSValuePtr " . $functionImplementationName . "(JSC::ExecState*, const JSC::ArgList&);\n");            }        }    }    if (!$hasParent) {        if ($podType) {            push(@headerContent, "    JSSVGPODTypeWrapper<$podType>* impl() const { return m_impl.get(); }\n");            push(@headerContent, "    SVGElement* context() const { return m_context.get(); }\n\n");            push(@headerContent, "private:\n");            push(@headerContent, "    RefPtr<SVGElement> m_context;\n");            push(@headerContent, "    RefPtr<JSSVGPODTypeWrapper<$podType> > m_impl;\n");        } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {            push(@headerContent, "    $implClassName* impl() const { return m_impl.get(); }\n");            push(@headerContent, "    SVGElement* context() const { return m_context.get(); }\n\n");            push(@headerContent, "private:\n");            push(@headerContent, "    RefPtr<SVGElement> m_context;\n");            push(@headerContent, "    RefPtr<$implClassName > m_impl;\n");        } else {            push(@headerContent, "    $implClassName* impl() const { return m_impl.get(); }\n\n");            push(@headerContent, "private:\n");            push(@headerContent, "    RefPtr<$implClassName> m_impl;\n");        }    } elsif ($dataNode->extendedAttributes->{"GenerateNativeConverter"}) {        push(@headerContent, "    $implClassName* impl() const\n");        push(@headerContent, "    {\n");        push(@headerContent, "        return static_cast<$implClassName*>(Base::impl());\n");        push(@headerContent, "    }\n");    }    # Index getter    if ($dataNode->extendedAttributes->{"HasIndexGetter"}) {        push(@headerContent, "    static JSC::JSValuePtr indexGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);\n");    }    if ($dataNode->extendedAttributes->{"HasCustomIndexGetter"}) {        push(@headerContent, "    JSC::JSValuePtr getByIndex(JSC::ExecState*, unsigned index);\n");    }        # Index setter    if ($dataNode->extendedAttributes->{"HasCustomIndexSetter"}) {        push(@headerContent, "    void indexSetter(JSC::ExecState*, unsigned index, JSC::JSValuePtr);\n");    }    # Name getter    if ($dataNode->extendedAttributes->{"HasNameGetter"} || $dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {        push(@headerContent, "private:\n");        push(@headerContent, "    static bool canGetItemsForName(JSC::ExecState*, $implClassName*, const JSC::Identifier&);\n");        push(@headerContent, "    static JSC::JSValuePtr nameGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);\n");    }    push(@headerContent, "};\n\n");    if ($dataNode->extendedAttributes->{"InlineGetOwnPropertySlot"}) {        push(@headerContent, "ALWAYS_INLINE bool ${className}::getOwnPropertySlot(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertySlot& slot)\n");        push(@headerContent, "{\n");        push(@headerContent, GenerateGetOwnPropertySlotBody($dataNode, $interfaceName, $className, $implClassName, $numAttributes > 0, 1));        push(@headerContent, "}\n\n");    }    if (!$hasParent || $dataNode->extendedAttributes->{"GenerateToJS"}) {        if ($podType) {            push(@headerContent, "JSC::JSValuePtr toJS(JSC::ExecState*, JSSVGPODTypeWrapper<$podType>*, SVGElement* context);\n");        } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {            push(@headerContent, "JSC::JSValuePtr toJS(JSC::ExecState*, $implType*, SVGElement* context);\n");        } else {            push(@headerContent, "JSC::JSValuePtr toJS(JSC::ExecState*, $implType*);\n");        }    }    if (!$hasParent || $dataNode->extendedAttributes->{"GenerateNativeConverter"}) {        if ($podType) {            push(@headerContent, "$podType to${interfaceName}(JSC::JSValuePtr);\n");        } elsif ($interfaceName eq "NodeFilter") {            push(@headerContent, "PassRefPtr<NodeFilter> toNodeFilter(JSC::JSValuePtr);\n");        } else {            push(@headerContent, "$implClassName* to${interfaceName}(JSC::JSValuePtr);\n");        }    }    if ($interfaceName eq "Node" or $interfaceName eq "Element" or $interfaceName eq "Text" or $interfaceName eq "CDATASection") {        push(@headerContent, "JSC::JSValuePtr toJSNewlyCreated(JSC::ExecState*, $interfaceName*);\n");    }        push(@headerContent, "\n");    # Add prototype declaration.    push(@headerContent, "class ${className}Prototype : public JSC::JSObject {\n");    push(@headerContent, "public:\n");    if ($interfaceName eq "DOMWindow") {        push(@headerContent, "    void* operator new(size_t);\n");    } elsif ($interfaceName eq "WorkerContext") {        push(@headerContent, "    void* operator new(size_t, JSC::JSGlobalData*);\n");    } else {        push(@headerContent, "    static JSC::JSObject* self(JSC::ExecState*);\n");    }    push(@headerContent, "    virtual const JSC::ClassInfo* classInfo() const { return &s_info; }\n");    push(@headerContent, "    static const JSC::ClassInfo s_info;\n");    if ($numFunctions > 0 || $numConstants > 0) {        push(@headerContent, "    virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);\n");        push(@headerContent,            "    static PassRefPtr<JSC::Structure> createStructure(JSC::JSValuePtr prototype)\n" .            "    {\n" .            "        return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType));\n" .            "    }\n");    }    push(@headerContent, "    ${className}Prototype(PassRefPtr<JSC::Structure> structure) : JSC::JSObject(structure) { }\n");    push(@headerContent, "};\n\n");    if ($numFunctions > 0) {        push(@headerContent,"// Functions\n\n");        foreach my $function (@{$dataNode->functions}) {            my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);            push(@headerContent, "JSC::JSValuePtr ${functionName}(JSC::ExecState*, JSC::JSObject*, JSC::JSValuePtr, const JSC::ArgList&);\n");        }    }    if ($numAttributes > 0 || $dataNode->extendedAttributes->{"GenerateConstructor"}) {        push(@headerContent,"// Attributes\n\n");        foreach my $attribute (@{$dataNode->attributes}) {            my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");            push(@headerContent, "JSC::JSValuePtr ${getter}(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);\n");            unless ($attribute->type =~ /readonly/) {                my $setter = "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");                push(@headerContent, "void ${setter}(JSC::ExecState*, JSC::JSObject*, JSC::JSValuePtr);\n");            }        }                if ($dataNode->extendedAttributes->{"GenerateConstructor"}) {            my $getter = "js" . $interfaceName . "Constructor";            push(@headerContent, "JSC::JSValuePtr ${getter}(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);\n");        }    }    if ($numConstants > 0) {        push(@headerContent,"// Constants\n\n");        foreach my $constant (@{$dataNode->constants}) {            my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($constant->name);            push(@headerContent, "JSC::JSValuePtr ${getter}(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);\n");        }    }    push(@headerContent, "\n} // namespace WebCore\n\n");    push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditional;    push(@headerContent, "#endif\n");}sub GenerateImplementation{    my ($object, $dataNode) = @_;    my $interfaceName = $dataNode->name;    my $className = "JS$interfaceName";    my $implClassName = $interfaceName;    my $hasLegacyParent = $dataNode->extendedAttributes->{"LegacyParent"};    my $hasRealParent = @{$dataNode->parents} > 0;    my $hasParent = $hasLegacyParent || $hasRealParent;    my $parentClassName = GetParentClassName($dataNode);    my $conditional = $dataNode->extendedAttributes->{"Conditional"};    my $visibleClassName = GetVisibleClassName($interfaceName);    # - Add default header template    @implContentHeader = split("\r", $headerTemplate);    push(@implContentHeader, "\n#include \"config.h\"\n\n");    my $conditionalString;    if ($conditional) {        $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";        push(@implContentHeader, "\n#if ${conditionalString}\n\n");    }    if ($className =~ /^JSSVG/) {        push(@implContentHeader, "#include \"SVGElement.h\"\n");        if ($className =~ /^JSSVGAnimated/) {            AddIncludesForSVGAnimatedType($interfaceName);        }    }    push(@implContentHeader, "#include \"$className.h\"\n\n");    push(@implContentHeader, "#include <wtf/GetPtr.h>\n\n");    push(@implContentHeader, "#include <runtime/PropertyNameArray.h>\n") if $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"};    AddIncludesForType($interfaceName);    @implContent = ();    push(@implContent, "\nusing namespace JSC;\n\n");    push(@implContent, "namespace WebCore {\n\n");    push(@implContent, "ASSERT_CLASS_FITS_IN_CELL($className)\n\n");    # - Add all attributes in a hashtable definition    my $numAttributes = @{$dataNode->attributes};    $numAttributes++ if $dataNode->extendedAttributes->{"GenerateConstructor"};    if ($numAttributes > 0) {        my $hashSize = $numAttributes;        my $hashName = $className . "Table";        my @hashKeys = ();        my @hashSpecials = ();        my @hashValue1 = ();        my @hashValue2 = ();

⌨️ 快捷键说明

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