Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/perl -w | 1 #!/usr/bin/perl -w |
| 2 # | 2 # |
| 3 # Copyright (C) 2011 Google Inc. All rights reserved. | 3 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 # | 4 # |
| 5 # This library is free software; you can redistribute it and/or | 5 # This library is free software; you can redistribute it and/or |
| 6 # modify it under the terms of the GNU Library General Public | 6 # modify it under the terms of the GNU Library General Public |
| 7 # License as published by the Free Software Foundation; either | 7 # License as published by the Free Software Foundation; either |
| 8 # version 2 of the License, or (at your option) any later version. | 8 # version 2 of the License, or (at your option) any later version. |
| 9 # | 9 # |
| 10 # This library is distributed in the hope that it will be useful, | 10 # This library is distributed in the hope that it will be useful, |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 # Library General Public License for more details. | 13 # Library General Public License for more details. |
| 14 # | 14 # |
| 15 # You should have received a copy of the GNU Library General Public License | 15 # You should have received a copy of the GNU Library General Public License |
| 16 # along with this library; see the file COPYING.LIB. If not, write to | 16 # along with this library; see the file COPYING.LIB. If not, write to |
| 17 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 # Boston, MA 02110-1301, USA. | 18 # Boston, MA 02110-1301, USA. |
| 19 # | 19 # |
| 20 | 20 |
| 21 use strict; | 21 use strict; |
| 22 | 22 |
| 23 use File::Basename; | 23 use File::Basename; |
| 24 use Getopt::Long; | 24 use Getopt::Long; |
| 25 use Cwd; | 25 use Cwd; |
| 26 use IDLParser; | |
| 26 | 27 |
| 27 my $defines; | 28 my $defines; |
| 28 my $preprocessor; | 29 my $preprocessor; |
| 29 my $idlFilesList; | 30 my $idlFilesList; |
| 30 my $supplementalDependencyFile; | 31 my $supplementalDependencyFile; |
| 32 my $windowConstructorsSupplementalFile; | |
| 31 my $supplementalMakefileDeps; | 33 my $supplementalMakefileDeps; |
| 32 | 34 |
| 33 GetOptions('defines=s' => \$defines, | 35 GetOptions('defines=s' => \$defines, |
| 34 'preprocessor=s' => \$preprocessor, | 36 'preprocessor=s' => \$preprocessor, |
| 35 'idlFilesList=s' => \$idlFilesList, | 37 'idlFilesList=s' => \$idlFilesList, |
| 36 'supplementalDependencyFile=s' => \$supplementalDependencyFile, | 38 'supplementalDependencyFile=s' => \$supplementalDependencyFile, |
| 39 'windowConstructorsSupplementalFile=s' => \$windowConstructorsSupplem entalFile, | |
| 37 'supplementalMakefileDeps=s' => \$supplementalMakefileDeps); | 40 'supplementalMakefileDeps=s' => \$supplementalMakefileDeps); |
| 38 | 41 |
| 39 die('Must specify an output file using --supplementalDependencyFile.') unless de fined($supplementalDependencyFile); | 42 die('Must specify an output file using --supplementalDependencyFile.') unless de fined($supplementalDependencyFile); |
| 43 die('Must specify an output file using --windowConstructorsSupplementalFile.') u nless defined($windowConstructorsSupplementalFile); | |
| 40 die('Must specify the file listing all IDLs using --idlFilesList.') unless defin ed($idlFilesList); | 44 die('Must specify the file listing all IDLs using --idlFilesList.') unless defin ed($idlFilesList); |
| 41 | 45 |
| 42 open FH, "< $idlFilesList" or die "Cannot open $idlFilesList\n"; | 46 open FH, "< $idlFilesList" or die "Cannot open $idlFilesList\n"; |
| 43 my @idlFiles = <FH>; | 47 my @idlFiles = <FH>; |
| 44 chomp(@idlFiles); | 48 chomp(@idlFiles); |
| 45 close FH; | 49 close FH; |
| 46 | 50 |
| 47 # Parse all IDL files. | 51 # Parse all IDL files. |
| 48 my %interfaceNameToIdlFile; | 52 my %interfaceNameToIdlFile; |
| 49 my %idlFileToInterfaceName; | 53 my %idlFileToInterfaceName; |
| 50 my %supplementalDependencies; | 54 my %supplementalDependencies; |
| 51 my %supplementals; | 55 my %supplementals; |
| 56 my $constructorAttributesCode = ""; | |
| 52 foreach my $idlFile (@idlFiles) { | 57 foreach my $idlFile (@idlFiles) { |
| 53 my $fullPath = Cwd::realpath($idlFile); | 58 my $fullPath = Cwd::realpath($idlFile); |
| 54 my $partialInterfaceName = getPartialInterfaceNameFromIDLFile($fullPath); | 59 my $parser = IDLParser->new(1); |
| 55 if ($partialInterfaceName) { | 60 my $document = $parser->Parse($fullPath, $defines, $preprocessor); |
|
abarth-chromium
2013/05/06 18:06:48
How does this effect compile time? Previously, we
| |
| 56 $supplementalDependencies{$fullPath} = $partialInterfaceName; | 61 my $isPartialInterface = 0; |
| 62 foreach my $interface (@{$document->interfaces}) { | |
| 63 if ($interface->isPartial) { | |
| 64 $supplementalDependencies{$fullPath} = $interface->name; | |
| 65 $isPartialInterface = 1; | |
| 66 last; | |
| 67 } | |
| 68 unless ($interface->isCallback || $interface->extendedAttributes->{"NoIn terfaceObject"}) { | |
| 69 $constructorAttributesCode .= GenerateConstructorAttribute($interfac e); | |
| 70 } | |
| 57 } | 71 } |
| 72 next if $isPartialInterface; | |
| 58 my $interfaceName = fileparse(basename($idlFile), ".idl"); | 73 my $interfaceName = fileparse(basename($idlFile), ".idl"); |
| 59 $interfaceNameToIdlFile{$interfaceName} = $fullPath; | 74 $interfaceNameToIdlFile{$interfaceName} = $fullPath; |
| 60 $idlFileToInterfaceName{$fullPath} = $interfaceName; | 75 $idlFileToInterfaceName{$fullPath} = $interfaceName; |
| 61 $supplementals{$fullPath} = []; | 76 $supplementals{$fullPath} = []; |
| 62 } | 77 } |
| 63 | 78 |
| 79 # Generate DOMWindow Constructors partial interface. | |
| 80 open PARTIAL_WINDOW_FH, "> $windowConstructorsSupplementalFile" or die "Cannot o pen $windowConstructorsSupplementalFile\n"; | |
| 81 print PARTIAL_WINDOW_FH "partial interface DOMWindow {\n"; | |
| 82 print PARTIAL_WINDOW_FH $constructorAttributesCode; | |
| 83 print PARTIAL_WINDOW_FH "};\n"; | |
| 84 close PARTIAL_WINDOW_FH; | |
| 85 $supplementalDependencies{$windowConstructorsSupplementalFile} = "DOMWindow"; | |
| 86 | |
| 64 # Resolves partial interfaces dependencies. | 87 # Resolves partial interfaces dependencies. |
| 65 foreach my $idlFile (keys %supplementalDependencies) { | 88 foreach my $idlFile (keys %supplementalDependencies) { |
| 66 my $baseFile = $supplementalDependencies{$idlFile}; | 89 my $baseFile = $supplementalDependencies{$idlFile}; |
| 67 my $targetIdlFile = $interfaceNameToIdlFile{$baseFile}; | 90 my $targetIdlFile = $interfaceNameToIdlFile{$baseFile}; |
| 68 push(@{$supplementals{$targetIdlFile}}, $idlFile); | 91 push(@{$supplementals{$targetIdlFile}}, $idlFile); |
| 69 delete $supplementals{$idlFile}; | 92 delete $supplementals{$idlFile}; |
| 70 } | 93 } |
| 71 | 94 |
| 72 # Outputs the dependency. | 95 # Outputs the dependency. |
| 73 # The format of a supplemental dependency file: | 96 # The format of a supplemental dependency file: |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 101 print MAKE_FH "DOM${basename}.h: @{dependencies}\n"; | 124 print MAKE_FH "DOM${basename}.h: @{dependencies}\n"; |
| 102 print MAKE_FH "WebDOM${basename}.h: @{dependencies}\n"; | 125 print MAKE_FH "WebDOM${basename}.h: @{dependencies}\n"; |
| 103 foreach my $dependency (@dependencies) { | 126 foreach my $dependency (@dependencies) { |
| 104 print MAKE_FH "${dependency}:\n"; | 127 print MAKE_FH "${dependency}:\n"; |
| 105 } | 128 } |
| 106 } | 129 } |
| 107 | 130 |
| 108 close MAKE_FH; | 131 close MAKE_FH; |
| 109 } | 132 } |
| 110 | 133 |
| 134 sub GenerateConstructorAttribute | |
| 135 { | |
| 136 my $interface = shift; | |
| 137 my $code = " "; | |
| 138 my @extendedAttributesList; | |
| 139 foreach my $attributeName (keys $interface->extendedAttributes) { | |
| 140 next unless ($attributeName eq "Conditional" || $attributeName eq "Enabled AtRuntime" || $attributeName eq "EnabledPerContext"); | |
| 141 my $extendedAttribute = $attributeName; | |
| 142 $extendedAttribute .= "=" . $interface->extendedAttributes->{$attributeNam e} unless $interface->extendedAttributes->{$attributeName} eq "VALUE_IS_MISSING" ; | |
| 143 push(@extendedAttributesList, $extendedAttribute); | |
| 144 } | |
| 145 $code .= "[" . join(', ', @extendedAttributesList) . "] " if @extendedAttrib utesList; | |
| 146 my $interfaceName = $interface->name; | |
| 147 $interfaceName = $interface->extendedAttributes->{"InterfaceName"} if $inter face->extendedAttributes->{"InterfaceName"}; | |
| 148 $interfaceName = $interface->extendedAttributes->{"ConstructorPrefix"} . $in terfaceName if $interface->extendedAttributes->{"ConstructorPrefix"}; | |
| 149 $code .= "attribute " . $interface->name . "Constructor $interfaceName;\n"; | |
| 111 | 150 |
| 112 sub getPartialInterfaceNameFromIDLFile | 151 # In addition to the regular property, for every [NamedConstructor] extended attribute on an interface, |
| 113 { | 152 # a corresponding property MUST exist on the ECMAScript global object. |
| 114 my $idlFile = shift; | 153 if ($interface->extendedAttributes->{"NamedConstructor"}) { |
| 115 | 154 my $constructorName = $interface->extendedAttributes->{"NamedConstructor "}; |
| 116 open FILE, "<", $idlFile; | 155 $code .= " "; |
| 117 my @lines = <FILE>; | 156 $code .= "[" . join(', ', @extendedAttributesList) . "] " if @extendedAt tributesList; |
| 118 close FILE; | 157 $code .= "attribute " . $interface->name . "ConstructorConstructor $cons tructorName;\n"; |
| 119 | |
| 120 my $fileContents = join('', @lines); | |
| 121 if ($fileContents =~ /partial\s+interface\s+(\w+)/gs) { | |
| 122 return $1; | |
| 123 } | 158 } |
| 159 return $code; | |
| 124 } | 160 } |
| OLD | NEW |