Changeset 162872 in webkit


Ignore:
Timestamp:
Jan 27, 2014 3:15:17 PM (10 years ago)
Author:
aestes@apple.com
Message:

Stop the code generator from adding ENABLE() macros to Objective-C DOM headers
https://bugs.webkit.org/show_bug.cgi?id=127706

Reviewed by David Kilzer.

Instead of adding ENABLE() macros to generated Objective-C DOM
headers, which might become Public or Private headers, elide generated
code for disabled features.

  • bindings/scripts/CodeGeneratorObjC.pm:

(GenerateInterface): Passed $defines to GenerateHeader.
(ConditionalIsEnabled): Checked if the given conditional is found in
$defines. Handled conditionals with '&' and '|'.
(GenerateHeader): Rather than calling GenerateConditionalString to
generate an "#if ENABLE(...)", called ConditionalIsEnabled() to see
whether we should generate code for the given constant, attribute, or
function.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r162871 r162872  
     12014-01-27  Andy Estes  <aestes@apple.com>
     2
     3        Stop the code generator from adding ENABLE() macros to Objective-C DOM headers
     4        https://bugs.webkit.org/show_bug.cgi?id=127706
     5
     6        Reviewed by David Kilzer.
     7
     8        Instead of adding ENABLE() macros to generated Objective-C DOM
     9        headers, which might become Public or Private headers, elide generated
     10        code for disabled features.
     11
     12        * bindings/scripts/CodeGeneratorObjC.pm:
     13        (GenerateInterface): Passed $defines to GenerateHeader.
     14        (ConditionalIsEnabled): Checked if the given conditional is found in
     15        $defines. Handled conditionals with '&' and '|'.
     16        (GenerateHeader): Rather than calling GenerateConditionalString to
     17        generate an "#if ENABLE(...)", called ConditionalIsEnabled() to see
     18        whether we should generate code for the given constant, attribute, or
     19        function.
     20
    1212014-01-27  Zoltan Horvath  <zoltan@webkit.org>
    222
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm

    r161878 r162872  
    2828
    2929use constant FileNamePrefix => "DOM";
     30
     31sub ConditionalIsEnabled(\%$);
    3032
    3133# Global Variables
     
    377379
    378380    # Start actual generation..
    379     $object->GenerateHeader($interface);
     381    $object->GenerateHeader($interface, $defines);
    380382    $object->GenerateImplementation($interface) unless $noImpl;
    381383
     
    791793}
    792794
     795sub ConditionalIsEnabled(\%$)
     796{
     797    my $defines = shift;
     798    my $conditional = shift;
     799
     800    return 1 if !$conditional;
     801
     802    my $operator = ($conditional =~ /&/ ? '&' : ($conditional =~ /\|/ ? '|' : ''));
     803    if (!$operator) {
     804        return exists($defines->{"ENABLE_" . $conditional});
     805    }
     806
     807    my @conditions = split(/\Q$operator\E/, $conditional);
     808    foreach (@conditions) {
     809        my $enable = "ENABLE_" . $_;
     810        return 0 if ($operator eq '&') and !exists($defines->{$enable});
     811        return 1 if ($operator eq '|') and exists($defines->{$enable});
     812    }
     813
     814    return $operator eq '&';
     815}
     816
    793817sub GenerateHeader
    794818{
    795819    my $object = shift;
    796820    my $interface = shift;
     821    my $defines = shift;
     822
     823    my %definesRef = map { $_ => 1 } split(/\s+/, $defines);
    797824
    798825    my $interfaceName = $interface->name;
     
    852879            my $constantName = $constant->name;
    853880            my $constantValue = $constant->value;
    854             my $conditional = $constant->extendedAttributes->{"Conditional"};
    855881            my $notLast = $constant ne $constants[-1];
    856 
    857             if ($conditional) {
    858                 my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional);
    859                 $combinedConstants .= "#if ${conditionalString}\n";
    860             }
    861             $combinedConstants .= "    DOM_$constantName = $constantValue";
    862             $combinedConstants .= "," if $notLast;
    863             if ($conditional) {
    864                 $combinedConstants .= "\n#endif\n";
    865             } elsif ($notLast) {
    866                 $combinedConstants .= "\n";
     882           
     883            if (ConditionalIsEnabled(%definesRef, $constant->extendedAttributes->{"Conditional"})) {
     884                $combinedConstants .= "    DOM_$constantName = $constantValue";
     885                $combinedConstants .= "," if $notLast;
     886                if ($notLast) {
     887                    $combinedConstants .= "\n";
     888                }
    867889            }
    868890        }
     
    944966                push(@headerAttributes, $property) if $public;
    945967                push(@privateHeaderAttributes, $property) unless $public;
    946             } else {
    947                 my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature);
    948                 if ($attributeConditionalString) {
    949                     push(@headerAttributes, "#if ${attributeConditionalString}\n") if $public;
    950                     push(@privateHeaderAttributes, "#if ${attributeConditionalString}\n") unless $public;
    951                 }
    952  
     968            } elsif (ConditionalIsEnabled(%definesRef, $attribute->signature->extendedAttributes->{"Conditional"})) {
    953969                # - GETTER
    954970                my $getter = "- (" . $attributeType . ")" . $attributeName . $declarationSuffix;
     
    962978                    push(@privateHeaderAttributes, $setter) unless $public;
    963979                }
    964  
    965                 if ($attributeConditionalString) {
    966                     push(@headerAttributes, "#endif\n") if $public;
    967                     push(@privateHeaderAttributes, "#endif\n") unless $public;
    968                 }
    969980            }
    970981        }
     
    10531064                $inAppleCopyright{$public ? "public" : "private"} = 0;
    10541065            }
    1055 
    1056             my $functionConditionalString = $codeGenerator->GenerateConditionalString($function->signature);
    1057             if ($functionConditionalString) {
    1058                 push(@headerFunctions, "#if ${functionConditionalString}\n") if $public;
    1059                 push(@privateHeaderFunctions, "#if ${functionConditionalString}\n") unless $public;
    1060                 push(@deprecatedHeaderFunctions, "#if ${functionConditionalString}\n") if $needsDeprecatedVersion;
    1061             }
    1062 
    1063             push(@headerFunctions, $functionDeclaration) if $public;
    1064             push(@privateHeaderFunctions, $functionDeclaration) unless $public;
    1065 
    1066             # generate the old style method names with un-named parameters, these methods are deprecated
    1067             if ($needsDeprecatedVersion) {
    1068                 my $deprecatedFunctionSig = $functionSig;
    1069                 $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
    1070 
    1071                 $publicInterfaceKey = $deprecatedFunctionSig . ";";
    1072 
    1073                 my $availabilityMacro = "WEBKIT_DEPRECATED_MAC(10_4, 10_5)";
    1074                 if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
    1075                     $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
    1076                 }
    1077 
    1078                 $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
    1079 
    1080                 push(@deprecatedHeaderFunctions, $functionDeclaration);
    1081 
    1082                 unless (defined $publicInterfaces{$publicInterfaceKey}) {
    1083                     warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the ObjCLegacyUnnamedParameters IDL attribute removed";
    1084                     $fatalError = 1;
    1085                 }
    1086 
    1087                 delete $publicInterfaces{$publicInterfaceKey};
    1088             }
    1089 
    1090             if ($functionConditionalString) {
    1091                 push(@headerFunctions, "#endif\n") if $public;
    1092                 push(@privateHeaderFunctions, "#endif\n") unless $public;
    1093                 push(@deprecatedHeaderFunctions, "#endif\n") if $needsDeprecatedVersion;
     1066           
     1067            if (ConditionalIsEnabled(%definesRef, $function->signature->extendedAttributes->{"Conditional"})) {
     1068                push(@headerFunctions, $functionDeclaration) if $public;
     1069                push(@privateHeaderFunctions, $functionDeclaration) unless $public;
     1070
     1071                # generate the old style method names with un-named parameters, these methods are deprecated
     1072                if ($needsDeprecatedVersion) {
     1073                    my $deprecatedFunctionSig = $functionSig;
     1074                    $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
     1075
     1076                    $publicInterfaceKey = $deprecatedFunctionSig . ";";
     1077
     1078                    my $availabilityMacro = "WEBKIT_DEPRECATED_MAC(10_4, 10_5)";
     1079                    if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) {
     1080                        $availabilityMacro = $publicInterfaces{$publicInterfaceKey};
     1081                    }
     1082
     1083                    $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n";
     1084
     1085                    push(@deprecatedHeaderFunctions, $functionDeclaration);
     1086
     1087                    unless (defined $publicInterfaces{$publicInterfaceKey}) {
     1088                        warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the ObjCLegacyUnnamedParameters IDL attribute removed";
     1089                        $fatalError = 1;
     1090                    }
     1091
     1092                    delete $publicInterfaces{$publicInterfaceKey};
     1093                }
    10941094            }
    10951095        }
Note: See TracChangeset for help on using the changeset viewer.