diff options
Diffstat (limited to 'Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm')
-rw-r--r-- | Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm | 322 |
1 files changed, 197 insertions, 125 deletions
diff --git a/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm b/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm index 47677a8c3..04898db17 100644 --- a/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm +++ b/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm @@ -114,6 +114,21 @@ sub FixUpDecamelizedName { return $classname; } +sub HumanReadableConditional { + my @conditional = split('_', shift); + my @upperCaseExceptions = ("SQL", "API"); + my @humanReadable; + + for $part (@conditional) { + if (!grep {$_ eq $part} @upperCaseExceptions) { + $part = camelize(lc($part)); + } + push(@humanReadable, $part); + } + + return join(' ', @humanReadable); +} + sub ClassNameToGObjectType { my $className = shift; my $CLASS_NAME = uc(decamelize($className)); @@ -164,6 +179,10 @@ sub SkipAttribute { return 1; } + if ($codeGenerator->GetArrayType($propType)) { + return 1; + } + # This is for DOMWindow.idl location attribute if ($attribute->signature->name eq "location") { return 1; @@ -188,6 +207,7 @@ sub SkipFunction { my $prefix = shift; my $functionName = "webkit_dom_" . $decamelize . "_" . $prefix . decamelize($function->signature->name); + my $functionReturnType = $prefix eq "set_" ? "void" : $function->signature->type; my $isCustomFunction = $function->signature->extendedAttributes->{"Custom"}; my $callWith = $function->signature->extendedAttributes->{"CallWith"}; my $isUnsupportedCallWith = $codeGenerator->ExtendedAttributeContains($callWith, "ScriptArguments") || $codeGenerator->ExtendedAttributeContains($callWith, "CallStack"); @@ -210,13 +230,18 @@ sub SkipFunction { return 1; } + if ($codeGenerator->GetArrayType($functionReturnType)) { + return 1; + } + # Skip functions that have ["Callback"] parameters, because this # code generator doesn't know how to auto-generate callbacks. - # Skip functions that have "MediaQueryListListener" parameters, because this - # code generator doesn't know how to auto-generate MediaQueryListListener. + # Skip functions that have "MediaQueryListListener" or sequence<T> parameters, because this + # code generator doesn't know how to auto-generate MediaQueryListListener or sequence<T>. foreach my $param (@{$function->parameters}) { if ($param->extendedAttributes->{"Callback"} || - $param->type eq "MediaQueryListListener") { + $param->type eq "MediaQueryListListener" || + $codeGenerator->GetArrayType($param->type)) { return 1; } } @@ -318,29 +343,47 @@ sub GetWriteableProperties { return @result; } -sub GenerateConditionalString +sub GenerateConditionalWarning { my $node = shift; + my $indentSize = shift; + if (!$indentSize) { + $indentSize = 4; + } + my $conditional = $node->extendedAttributes->{"Conditional"}; + my @warn; + if ($conditional) { if ($conditional =~ /&/) { - return "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")"; + my @splitConditionals = split(/&/, $conditional); + foreach $condition (@splitConditionals) { + push(@warn, "#if !ENABLE($condition)\n"); + push(@warn, ' ' x $indentSize . "WEBKIT_WARN_FEATURE_NOT_PRESENT(\"" . HumanReadableConditional($condition) . "\")\n"); + push(@warn, "#endif\n"); + } } elsif ($conditional =~ /\|/) { - return "ENABLE(" . join(") || ENABLE(", split(/\|/, $conditional)) . ")"; + foreach $condition (split(/\|/, $conditional)) { + push(@warn, ' ' x $indentSize . "WEBKIT_WARN_FEATURE_NOT_PRESENT(\"" . HumanReadableConditional($condition) . "\")\n"); + } } else { - return "ENABLE(" . $conditional . ")"; + push(@warn, ' ' x $indentSize . "WEBKIT_WARN_FEATURE_NOT_PRESENT(\"" . HumanReadableConditional($conditional) . "\")\n"); } - } else { - return ""; } + + return @warn; } sub GenerateProperty { my $attribute = shift; my $interfaceName = shift; my @writeableProperties = @{shift @_}; + my $parentNode = shift; - my $conditionalString = GenerateConditionalString($attribute->signature); + my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + my @conditionalWarn = GenerateConditionalWarning($attribute->signature, 8); + my $parentConditionalString = $codeGenerator->GenerateConditionalString($parentNode); + my @parentConditionalWarn = GenerateConditionalWarning($parentNode, 8); my $camelPropName = $attribute->signature->name; my $setPropNameFunction = $codeGenerator->WK_ucfirst($camelPropName); my $getPropNameFunction = $codeGenerator->WK_lcfirst($camelPropName); @@ -349,9 +392,7 @@ sub GenerateProperty { my $propNameCaps = uc($propName); $propName =~ s/_/-/g; my ${propEnum} = "PROP_${propNameCaps}"; - push(@cBodyPriv, "#if ${conditionalString}\n") if $conditionalString; - push(@cBodyPriv, " ${propEnum},\n"); - push(@cBodyPriv, "#endif /* ${conditionalString} */\n") if $conditionalString; + push(@cBodyProperties, " ${propEnum},\n"); my $propType = $attribute->signature->type; my ${propGType} = decamelize($propType); @@ -400,16 +441,23 @@ sub GenerateProperty { push(@setterArguments, "ec") if @{$attribute->setterExceptions}; if (grep {$_ eq $attribute} @writeableProperties) { + push(@txtSetProps, " case ${propEnum}: {\n"); + push(@txtSetProps, "#if ${parentConditionalString}\n") if $parentConditionalString; push(@txtSetProps, "#if ${conditionalString}\n") if $conditionalString; - push(@txtSetProps, " case ${propEnum}:\n {\n"); push(@txtSetProps, " WebCore::ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions}; push(@txtSetProps, " ${setterFunctionName}(" . join(", ", @setterArguments) . ");\n"); - push(@txtSetProps, " break;\n }\n"); + push(@txtSetProps, "#else\n") if $conditionalString; + push(@txtSetProps, @conditionalWarn) if scalar(@conditionalWarn); push(@txtSetProps, "#endif /* ${conditionalString} */\n") if $conditionalString; + push(@txtSetProps, "#else\n") if $parentConditionalString; + push(@txtSetProps, @parentConditionalWarn) if scalar(@parentConditionalWarn); + push(@txtSetProps, "#endif /* ${parentConditionalString} */\n") if $parentConditionalString; + push(@txtSetProps, " break;\n }\n"); } + push(@txtGetProps, " case ${propEnum}: {\n"); + push(@txtGetProps, "#if ${parentConditionalString}\n") if $parentConditionalString; push(@txtGetProps, "#if ${conditionalString}\n") if $conditionalString; - push(@txtGetProps, " case ${propEnum}:\n {\n"); push(@txtGetProps, " WebCore::ExceptionCode ec = 0;\n") if @{$attribute->getterExceptions}; my $postConvertFunction = ""; @@ -439,8 +487,13 @@ sub GenerateProperty { } } - push(@txtGetProps, " break;\n }\n"); + push(@txtGetProps, "#else\n") if $conditionalString; + push(@txtGetProps, @conditionalWarn) if scalar(@conditionalWarn); push(@txtGetProps, "#endif /* ${conditionalString} */\n") if $conditionalString; + push(@txtGetProps, "#else\n") if $parentConditionalString; + push(@txtGetProps, @parentConditionalWarn) if scalar(@parentConditionalWarn); + push(@txtGetProps, "#endif /* ${parentConditionalString} */\n") if $parentConditionalString; + push(@txtGetProps, " break;\n }\n"); my %param_spec_options = ("int", "G_MININT, /* min */\nG_MAXINT, /* max */\n0, /* default */", "boolean", "FALSE, /* default */", @@ -466,9 +519,7 @@ sub GenerateProperty { $param_spec_options{$gtype} ${gparamflag})); EOF - push(@txtInstallProps, "#if ${conditionalString}\n") if $conditionalString; push(@txtInstallProps, $txtInstallProp); - push(@txtInstallProps, "#endif /* ${conditionalString} */\n") if $conditionalString; } sub GenerateProperties { @@ -477,6 +528,14 @@ sub GenerateProperties { my $clsCaps = substr(ClassNameToGObjectType($className), 12); my $lowerCaseIfaceName = "webkit_dom_" . (FixUpDecamelizedName(decamelize($interfaceName))); + my $conditionGuardStart = ""; + my $conditionGuardEnd = ""; + my $conditionalString = $codeGenerator->GenerateConditionalString($dataNode); + if ($conditionalString) { + $conditionGuardStart = "#if ${conditionalString}"; + $conditionGuardEnd = "#endif // ${conditionalString}"; + } + # Properties my $implContent = ""; @@ -485,14 +544,14 @@ sub GenerateProperties { enum { PROP_0, EOF - push(@cBodyPriv, $implContent); + push(@cBodyProperties, $implContent); my @readableProperties = GetReadableProperties($dataNode->attributes); my $privFunction = GetCoreObject($interfaceName, "coreSelf", "self"); my $txtGetProp = << "EOF"; -static void ${lowerCaseIfaceName}_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) +static void ${lowerCaseIfaceName}_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) { WebCore::JSMainThreadNullState state; EOF @@ -502,18 +561,18 @@ EOF ${className}* self = WEBKIT_DOM_${clsCaps}(object); $privFunction EOF - push(@txtGetProps, $txtGetProp); + push(@txtGetProps, $txtGetProp); } $txtGetProp = << "EOF"; - switch (prop_id) { + switch (propertyId) { EOF push(@txtGetProps, $txtGetProp); my @writeableProperties = GetWriteableProperties(\@readableProperties); my $txtSetProps = << "EOF"; -static void ${lowerCaseIfaceName}_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) +static void ${lowerCaseIfaceName}_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) { WebCore::JSMainThreadNullState state; EOF @@ -528,22 +587,22 @@ EOF } $txtSetProps = << "EOF"; - switch (prop_id) { + switch (propertyId) { EOF push(@txtSetProps, $txtSetProps); foreach my $attribute (@readableProperties) { if ($attribute->signature->type ne "EventListener" && $attribute->signature->type ne "MediaQueryListListener") { - GenerateProperty($attribute, $interfaceName, \@writeableProperties); + GenerateProperty($attribute, $interfaceName, \@writeableProperties, $dataNode); } } - push(@cBodyPriv, "};\n\n"); + push(@cBodyProperties, "};\n\n"); $txtGetProp = << "EOF"; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); break; } } @@ -552,7 +611,7 @@ EOF $txtSetProps = << "EOF"; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); break; } } @@ -563,19 +622,20 @@ EOF $" = ""; $implContent = << "EOF"; - static void ${lowerCaseIfaceName}_finalize(GObject* object) { - WebKitDOMObject* dom_object = WEBKIT_DOM_OBJECT(object); +$conditionGuardStart + WebKitDOMObject* domObject = WEBKIT_DOM_OBJECT(object); - if (dom_object->coreObject) { - WebCore::${interfaceName}* coreObject = static_cast<WebCore::${interfaceName} *>(dom_object->coreObject); + if (domObject->coreObject) { + WebCore::${interfaceName}* coreObject = static_cast<WebCore::${interfaceName}*>(domObject->coreObject); WebKit::DOMObjectCache::forget(coreObject); coreObject->deref(); - dom_object->coreObject = NULL; + domObject->coreObject = 0; } +$conditionGuardEnd G_OBJECT_CLASS(${lowerCaseIfaceName}_parent_class)->finalize(object); } @@ -587,7 +647,7 @@ static void ${lowerCaseIfaceName}_finalize(GObject* object) static void ${lowerCaseIfaceName}_constructed(GObject* object) { EOF - push(@cBodyPriv, $implContent); + push(@cBodyProperties, $implContent); $implContent = << "EOF"; @txtInstallEventListeners @@ -597,7 +657,7 @@ EOF static void ${lowerCaseIfaceName}_class_init(${className}Class* requestClass) { - GObjectClass *gobjectClass = G_OBJECT_CLASS(requestClass); + GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); gobjectClass->finalize = ${lowerCaseIfaceName}_finalize; gobjectClass->set_property = ${lowerCaseIfaceName}_set_property; gobjectClass->get_property = ${lowerCaseIfaceName}_get_property; @@ -612,7 +672,7 @@ static void ${lowerCaseIfaceName}_init(${className}* request) } EOF - push(@cBodyPriv, $implContent); + push(@cBodyProperties, $implContent); } sub GenerateHeader { @@ -716,7 +776,7 @@ sub addIncludeInBody { } sub GenerateFunction { - my ($object, $interfaceName, $function, $prefix) = @_; + my ($object, $interfaceName, $function, $prefix, $parentNode) = @_; my $decamelize = FixUpDecamelizedName(decamelize($interfaceName)); @@ -733,7 +793,11 @@ sub GenerateFunction { my $functionName = "webkit_dom_" . $decamelize . "_" . $prefix . decamelize($functionSigName); my $returnType = GetGlibTypeName($functionSigType); my $returnValueIsGDOMType = IsGDOMClassType($functionSigType); - my $conditionalString = GenerateConditionalString($function->signature); + + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + my $parentConditionalString = $codeGenerator->GenerateConditionalString($parentNode); + my @conditionalWarn = GenerateConditionalWarning($function->signature); + my @parentConditionalWarn = GenerateConditionalWarning($parentNode); my $functionSig = "${className}* self"; @@ -748,7 +812,7 @@ sub GenerateFunction { addIncludeInBody($paramIDLType); my $paramType = GetGlibTypeName($paramIDLType); my $const = $paramType eq "gchar*" ? "const " : ""; - my $paramName = decamelize($param->name); + my $paramName = $param->name; $functionSig .= ", ${const}$paramType $paramName"; @@ -759,7 +823,7 @@ sub GenerateFunction { } } if ($paramIsGDOMType || ($paramIDLType eq "DOMString") || ($paramIDLType eq "CompareHow")) { - $paramName = "converted_" . $paramName; + $paramName = "converted" . $codeGenerator->WK_ucfirst($paramName); } push(@callImplParams, $paramName); } @@ -775,8 +839,8 @@ sub GenerateFunction { $implIncludes{"${functionSigType}.h"} = 1; } - if(@{$function->raisesExceptions}) { - $functionSig .= ", GError **error"; + if (@{$function->raisesExceptions}) { + $functionSig .= ", GError** error"; } # Insert introspection annotations @@ -788,7 +852,7 @@ sub GenerateFunction { my $paramType = GetGlibTypeName($param->type); # $paramType can have a trailing * in some cases $paramType =~ s/\*$//; - my $paramName = decamelize($param->name); + my $paramName = $param->name; push(@hBody, " * \@${paramName}: A #${paramType}\n"); } if(@{$function->raisesExceptions}) { @@ -807,6 +871,7 @@ sub GenerateFunction { push(@hBody, "\n"); push(@cBody, "$returnType\n$functionName($functionSig)\n{\n"); + push(@cBody, "#if ${parentConditionalString}\n") if $parentConditionalString; push(@cBody, "#if ${conditionalString}\n") if $conditionalString; if ($returnType ne "void") { @@ -818,12 +883,11 @@ sub GenerateFunction { push(@cBody, " WebCore::JSMainThreadNullState state;\n"); - # The WebKit::core implementations check for NULL already; no need to - # duplicate effort. - push(@cBody, " WebCore::${interfaceName} * item = WebKit::core(self);\n"); + # The WebKit::core implementations check for null already; no need to duplicate effort. + push(@cBody, " WebCore::${interfaceName}* item = WebKit::core(self);\n"); foreach my $param (@{$function->parameters}) { - my $paramName = decamelize($param->name); + my $paramName = $param->name; my $paramIDLType = $param->type; my $paramTypeIsPrimitive = $codeGenerator->IsPrimitiveType($paramIDLType); my $paramIsGDOMType = IsGDOMClassType($paramIDLType); @@ -844,28 +908,29 @@ sub GenerateFunction { $returnParamName = ""; foreach my $param (@{$function->parameters}) { my $paramIDLType = $param->type; - my $paramName = decamelize($param->name); + my $paramName = $param->name; my $paramIsGDOMType = IsGDOMClassType($paramIDLType); + $convertedParamName = "converted" . $codeGenerator->WK_ucfirst($paramName); if ($paramIDLType eq "DOMString") { - push(@cBody, " WTF::String converted_${paramName} = WTF::String::fromUTF8($paramName);\n"); + push(@cBody, " WTF::String ${convertedParamName} = WTF::String::fromUTF8($paramName);\n"); } elsif ($paramIDLType eq "CompareHow") { - push(@cBody, " WebCore::Range::CompareHow converted_${paramName} = static_cast<WebCore::Range::CompareHow>($paramName);\n"); + push(@cBody, " WebCore::Range::CompareHow ${convertedParamName} = static_cast<WebCore::Range::CompareHow>($paramName);\n"); } elsif ($paramIsGDOMType) { - push(@cBody, " WebCore::${paramIDLType} * converted_${paramName} = NULL;\n"); - push(@cBody, " if (${paramName} != NULL) {\n"); - push(@cBody, " converted_${paramName} = WebKit::core($paramName);\n"); + push(@cBody, " WebCore::${paramIDLType}* ${convertedParamName} = 0;\n"); + push(@cBody, " if (${paramName}) {\n"); + push(@cBody, " ${convertedParamName} = WebKit::core($paramName);\n"); if ($returnType ne "void") { # TODO: return proper default result - push(@cBody, " g_return_val_if_fail(converted_${paramName}, 0);\n"); + push(@cBody, " g_return_val_if_fail(${convertedParamName}, 0);\n"); } else { - push(@cBody, " g_return_if_fail(converted_${paramName});\n"); + push(@cBody, " g_return_if_fail(${convertedParamName});\n"); } push(@cBody, " }\n"); } - $returnParamName = "converted_".$paramName if $param->extendedAttributes->{"CustomReturn"}; + $returnParamName = $convertedParamName if $param->extendedAttributes->{"CustomReturn"}; } my $assign = ""; @@ -879,14 +944,14 @@ sub GenerateFunction { $functionName eq "webkit_dom_node_insert_before" || $functionName eq "webkit_dom_node_replace_child" || $functionName eq "webkit_dom_node_remove_child"; - + if ($returnType ne "void" && !$functionHasCustomReturn) { if ($returnValueIsGDOMType) { - $assign = "PassRefPtr<WebCore::${functionSigType}> g_res = "; + $assign = "RefPtr<WebCore::${functionSigType}> gobjectResult = "; $assignPre = "WTF::getPtr("; $assignPost = ")"; } else { - $assign = "${returnType} res = "; + $assign = "${returnType} result = "; } } @@ -900,8 +965,8 @@ sub GenerateFunction { my $customNodeAppendChild = << "EOF"; if (ok) { - ${returnType} res = WebKit::kit($returnParamName); - return res; + ${returnType} result = WebKit::kit($returnParamName); + return result; } EOF push(@cBody, $customNodeAppendChild); @@ -914,7 +979,7 @@ EOF EOF push(@cBody, $exceptionHandling); } - push(@cBody, "return NULL;"); + push(@cBody, "return 0;"); push(@cBody, "}\n\n"); return; } elsif ($functionSigType eq "DOMString") { @@ -997,26 +1062,40 @@ EOF if ($returnType ne "void" && !$functionHasCustomReturn) { if ($functionSigType ne "DOMObject") { if ($returnValueIsGDOMType) { - push(@cBody, " ${returnType} res = WebKit::kit(g_res.get());\n"); + push(@cBody, " ${returnType} result = WebKit::kit(gobjectResult.get());\n"); } } if ($functionSigType eq "DOMObject") { - push(@cBody, " return NULL; /* TODO: return canvas object */\n"); + push(@cBody, " return 0; // TODO: return canvas object\n"); } else { - push(@cBody, " return res;\n"); + push(@cBody, " return result;\n"); } } if ($conditionalString) { + push(@cBody, "#else\n"); + push(@cBody, @conditionalWarn) if scalar(@conditionalWarn); if ($returnType ne "void") { - push(@cBody, "#else\n"); if ($codeGenerator->IsNonPointerType($functionSigType)) { push(@cBody, " return static_cast<${returnType}>(0);\n"); } else { - push(@cBody, " return NULL;\n"); + push(@cBody, " return 0;\n"); } } - push(@cBody, "#endif /* ${conditionalString} */\n") if $conditionalString; + push(@cBody, "#endif /* ${conditionalString} */\n"); + } + + if ($parentConditionalString) { + push(@cBody, "#else\n"); + push(@cBody, @parentConditionalWarn) if scalar(@parentConditionalWarn); + if ($returnType ne "void") { + if ($codeGenerator->IsNonPointerType($functionSigType)) { + push(@cBody, " return static_cast<${returnType}>(0);\n"); + } else { + push(@cBody, " return 0;\n"); + } + } + push(@cBody, "#endif /* ${parentConditionalString} */\n"); } push(@cBody, "}\n\n"); @@ -1038,7 +1117,7 @@ sub GenerateFunctions { my ($object, $interfaceName, $dataNode) = @_; foreach my $function (@{$dataNode->functions}) { - $object->GenerateFunction($interfaceName, $function, ""); + $object->GenerateFunction($interfaceName, $function, "", $dataNode); } TOP: @@ -1071,7 +1150,7 @@ sub GenerateFunctions { my $function = new domFunction(); $function->signature($attribute->signature); $function->raisesExceptions($attribute->getterExceptions); - $object->GenerateFunction($interfaceName, $function, "get_"); + $object->GenerateFunction($interfaceName, $function, "get_", $dataNode); # FIXME: We are not generating setters for 'Replaceable' # attributes now, but we should somehow. @@ -1093,13 +1172,13 @@ sub GenerateFunctions { $param->name("value"); $param->type($attribute->signature->type); my %attributes = (); - $param->extendedAttributes("attributes"); + $param->extendedAttributes(\%attributes); my $arrayRef = $function->parameters; push(@$arrayRef, $param); $function->raisesExceptions($attribute->setterExceptions); - $object->GenerateFunction($interfaceName, $function, "set_"); + $object->GenerateFunction($interfaceName, $function, "set_", $dataNode); } } @@ -1118,8 +1197,10 @@ sub GenerateCFile { $implContent = << "EOF"; ${defineTypeMacro}(${className}, ${lowerCaseIfaceName}, ${parentGObjType}${defineTypeInterfaceImplementation} -namespace WebKit { +EOF + push(@cBodyProperties, $implContent); + $implContent = << "EOF"; WebCore::${interfaceName}* core(${className}* request) { g_return_val_if_fail(request, 0); @@ -1130,29 +1211,24 @@ WebCore::${interfaceName}* core(${className}* request) return coreObject; } -} // namespace WebKit EOF - push(@cBodyPriv, $implContent); + $object->GenerateProperties($interfaceName, $dataNode); $object->GenerateFunctions($interfaceName, $dataNode); my $wrapMethod = << "EOF"; -namespace WebKit { ${className}* wrap${interfaceName}(WebCore::${interfaceName}* coreObject) { g_return_val_if_fail(coreObject, 0); - /* We call ref() rather than using a C++ smart pointer because we can't store a C++ object - * in a C-allocated GObject structure. See the finalize() code for the - * matching deref(). - */ + // We call ref() rather than using a C++ smart pointer because we can't store a C++ object + // in a C-allocated GObject structure. See the finalize() code for the matching deref(). coreObject->ref(); - return WEBKIT_DOM_${clsCaps}(g_object_new(WEBKIT_TYPE_DOM_${clsCaps}, - "core-object", coreObject, NULL)); + return WEBKIT_DOM_${clsCaps}(g_object_new(WEBKIT_TYPE_DOM_${clsCaps}, "core-object", coreObject, NULL)); } -} // namespace WebKit + EOF push(@cBodyPriv, $wrapMethod); } @@ -1220,7 +1296,7 @@ static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface) EOF - push(@cBody, $impl); + push(@cBodyProperties, $impl); $defineTypeMacro = "G_DEFINE_TYPE_WITH_CODE"; $defineTypeInterfaceImplementation = ", G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_DOM_EVENT_TARGET, webkit_dom_event_target_init))"; @@ -1233,11 +1309,6 @@ sub Generate { my $parentGObjType = GetParentGObjType($dataNode); my $interfaceName = $dataNode->name; - # Add the guard if the 'Conditional' extended attribute exists - my $conditionalString = GenerateConditionalString($dataNode); - push(@conditionGuardStart, "#if ${conditionalString}\n\n") if $conditionalString; - push(@conditionGuardEnd, "#endif /* ${conditionalString} */\n") if $conditionalString; - # Add the default impl header template @cPrefix = split("\r", $licenceTemplate); push(@cPrefix, "\n"); @@ -1258,8 +1329,6 @@ sub Generate { if (!UsesManualKitImplementation($interfaceName)) { my $converter = << "EOF"; -namespace WebKit { - ${className}* kit(WebCore::$interfaceName* obj) { g_return_val_if_fail(obj, 0); @@ -1269,11 +1338,9 @@ ${className}* kit(WebCore::$interfaceName* obj) return static_cast<${className}*>(DOMObjectCache::put(obj, WebKit::wrap${interfaceName}(obj))); } - -} // namespace WebKit // EOF - push(@cBody, $converter); + push(@cBodyPriv, $converter); } $object->GenerateHeader($interfaceName, $parentClassName); @@ -1289,9 +1356,12 @@ sub WriteData { # Write a private header. my $interfaceName = $dataNode->name; my $filename = "$outputDir/" . $className . "Private.h"; - my $guard = uc(decamelize($className)) . "_PRIVATE_H"; + my $guard = "${className}Private_h"; my $parentClassName = GetParentClassName($dataNode); + # Add the guard if the 'Conditional' extended attribute exists + my $conditionalString = $codeGenerator->GenerateConditionalString($dataNode); + open(PRIVHEADER, ">$filename") or die "Couldn't open file $filename for writing"; print PRIVHEADER split("\r", $licenceTemplate); @@ -1301,41 +1371,35 @@ sub WriteData { #ifndef $guard #define $guard +#include "${interfaceName}.h" #include <glib-object.h> #include <webkit/${parentClassName}.h> -#include "${interfaceName}.h" EOF print PRIVHEADER $text; + print PRIVHEADER "#if ${conditionalString}\n" if $conditionalString; print PRIVHEADER map { "#include \"$_\"\n" } sort keys(%hdrPropIncludes); - print PRIVHEADER "\n" if keys(%hdrPropIncludes); + print PRIVHEADER "\n"; $text = << "EOF"; namespace WebKit { - ${className} * - wrap${interfaceName}(WebCore::${interfaceName} *coreObject); - - WebCore::${interfaceName} * - core(${className} *request); - +${className}* wrap${interfaceName}(WebCore::${interfaceName}*); +WebCore::${interfaceName}* core(${className}* request); EOF print PRIVHEADER $text; if ($className ne "WebKitDOMNode") { - $text = << "EOF"; - ${className}* - kit(WebCore::${interfaceName}* node); - -EOF - print PRIVHEADER $text; + print PRIVHEADER "${className}* kit(WebCore::${interfaceName}* node);\n" } $text = << "EOF"; } // namespace WebKit -#endif /* ${guard} */ EOF + print PRIVHEADER $text; + print PRIVHEADER "#endif /* ${conditionalString} */\n\n" if $conditionalString; + print PRIVHEADER "#endif /* ${guard} */\n"; close(PRIVHEADER); @@ -1343,17 +1407,16 @@ EOF $basename =~ s/_//g; # Write public header. - my $hdrFName = "$outputDir/" . $basename . ".h"; - open(HEADER, ">$hdrFName") or die "Couldn't open file $hdrFName"; + my $fullHeaderFilename = "$outputDir/" . $basename . ".h"; + my $installedHeaderFilename = "${basename}.h"; + open(HEADER, ">$fullHeaderFilename") or die "Couldn't open file $fullHeaderFilename"; print HEADER @hPrefix; print HEADER @hPrefixGuard; - print HEADER "#include \"webkit/webkitdomdefines.h\"\n"; print HEADER "#include <glib-object.h>\n"; + print HEADER map { "#include <$_>\n" } sort keys(%hdrIncludes); print HEADER "#include <webkit/webkitdefines.h>\n"; - print HEADER map { "#include \"$_\"\n" } sort keys(%hdrIncludes); - print HEADER "\n" if keys(%hdrIncludes); - print HEADER "\n"; + print HEADER "#include <webkit/webkitdomdefines.h>\n\n"; print HEADER @hBodyPre; print HEADER @hBody; print HEADER @hPrefixGuardEnd; @@ -1365,18 +1428,26 @@ EOF open(IMPL, ">$implFileName") or die "Couldn't open file $implFileName"; print IMPL @cPrefix; + print IMPL "#include \"config.h\"\n"; + print IMPL "#include \"$installedHeaderFilename\"\n\n"; + + # Remove the implementation header from the list of included files. + %includesCopy = %implIncludes; + delete ($includesCopy{"webkit/$installedHeaderFilename"}); + print IMPL map { "#include \"$_\"\n" } sort keys(%includesCopy); + print IMPL "#include <glib-object.h>\n"; - print IMPL "#include \"config.h\"\n\n"; - print IMPL @conditionGuardStart; print IMPL "#include <wtf/GetPtr.h>\n"; - print IMPL "#include <wtf/RefPtr.h>\n"; - print IMPL map { "#include \"$_\"\n" } sort keys(%implIncludes); - print IMPL "\n" if keys(%implIncludes); - print IMPL @cBody; + print IMPL "#include <wtf/RefPtr.h>\n\n"; + print IMPL "#if ${conditionalString}\n\n" if $conditionalString; - print IMPL "\n"; + print IMPL "namespace WebKit {\n\n"; print IMPL @cBodyPriv; - print IMPL @conditionGuardEnd; + print IMPL "} // namespace WebKit\n\n"; + print IMPL "#endif // ${conditionalString}\n\n" if $conditionalString; + + print IMPL @cBodyProperties; + print IMPL @cBody; close(IMPL); @@ -1388,6 +1459,7 @@ EOF @cPrefix = (); @cBody = (); @cBodyPriv = (); + @cBodyProperties = (); } sub GenerateInterface { |