Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Unified Diff: Source/bindings/scripts/InterfaceMerger.pm

Issue 15979013: Refactor partial interface resolving and merging into InterfaceMerger.pm (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Handle empties Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/derived_sources.gyp ('k') | Source/bindings/scripts/generate-bindings.pl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/InterfaceMerger.pm
diff --git a/Source/bindings/scripts/InterfaceMerger.pm b/Source/bindings/scripts/InterfaceMerger.pm
new file mode 100755
index 0000000000000000000000000000000000000000..a39fb27a548bb0f65c88fa595a2ea240227ccacd
--- /dev/null
+++ b/Source/bindings/scripts/InterfaceMerger.pm
@@ -0,0 +1,141 @@
+# Copyright (C) 2013 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+package InterfaceMerger;
+
+use strict;
+use warnings;
+
+use File::Basename;
+use Text::ParseWords;
+
+use IDLParser;
+
+require Exporter;
+use vars qw(@ISA @EXPORT_OK);
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(computeIdlDependencies mergePartialInterfaces);
+
+sub computeIdlDependencies
+{
+ my $targetIdlFileBasename = shift;
+ my $dependenciesFile = shift;
+ my $additionalIdlFilesString = shift;
+
+ my $idlDependencies;
+
+ # The format of the dependencies file:
+ #
+ # DOMWindow.idl P.idl Q.idl R.idl
+ # Document.idl S.idl
+ # Event.idl
+ # ...
+ #
+ # The above indicates that DOMWindow.idl depends on P.idl, Q.idl and R.idl,
+ # Document.idl depends on S.idl, and Event.idl depends no IDLs.
+ # Dependencies themselves (e.g. P.idl) do not have their own line.
+ open FH, "< $dependenciesFile" or die "Cannot open $dependenciesFile\n";
+ while (my $line = <FH>) {
+ my ($idlFile, @dependencies) = split(/\s+/, $line);
+ if ($idlFile and basename($idlFile) eq $targetIdlFileBasename) {
+ close FH;
+ return \@dependencies;
+ }
+ }
+ close FH;
+
+ # $additionalIdlFilesString is a list of IDL files which should not be
+ # included in DerivedSources*.cpp (i.e. they are not described in the
+ # dependencies file) but should generate .h and .cpp files.
+ if ($additionalIdlFilesString) {
+ my @additionalIdlFiles = shellwords($additionalIdlFilesString);
+ if (grep { $_ and basename($_) eq $targetIdlFileBasename } @additionalIdlFiles) {
+ return [];
+ }
+ }
+}
+
+sub mergePartialInterfaces
+{
+ my $targetDocument = shift;
+ my $targetInterfaceName = shift;
+ my $targetIdlFile = shift;
+ my $dependencies = shift;
+ my $defines = shift;
+ my $preprocessor = shift;
+ my $verbose = shift;
+
+ foreach my $idlFile (@$dependencies) {
+ # FIXME: circular dependency, should never happen
+ next if $idlFile eq $targetIdlFile;
+ my $interfaceName = fileparse(basename($idlFile), ".idl");
+ my $parser = IDLParser->new(!$verbose);
+ my $document = $parser->Parse($idlFile, $defines, $preprocessor);
+
+ foreach my $interface (@{$document->interfaces}) {
+ die "$idlFile is not a dependency of $targetIdlFile. There maybe a bug in the dependency generator (preprocess_idls.py).\n" unless ($interface->isPartial and $interface->name eq $targetInterfaceName);
+ my $targetDataNode;
+ foreach my $interface (@{$targetDocument->interfaces}) {
+ if ($interface->name eq $targetInterfaceName) {
+ $targetDataNode = $interface;
+ last;
+ }
+ }
+ die "Did not find interface ${targetInterfaceName} in ${targetInterfaceName}.idl." unless defined $targetDataNode;
+
+ foreach my $attribute (@{$interface->attributes}) {
+ $attribute->signature->extendedAttributes->{"ImplementedBy"} = $interfaceName;
+ # Add interface-wide extended attributes to each attribute.
+ foreach my $extendedAttributeName (keys %{$interface->extendedAttributes}) {
+ $attribute->signature->extendedAttributes->{$extendedAttributeName} = $interface->extendedAttributes->{$extendedAttributeName};
+ }
+ push(@{$targetDataNode->attributes}, $attribute);
+ }
+
+ foreach my $function (@{$interface->functions}) {
+ $function->signature->extendedAttributes->{"ImplementedBy"} = $interfaceName;
+ # Add interface-wide extended attributes to each method.
+ foreach my $extendedAttributeName (keys %{$interface->extendedAttributes}) {
+ $function->signature->extendedAttributes->{$extendedAttributeName} = $interface->extendedAttributes->{$extendedAttributeName};
+ }
+ push(@{$targetDataNode->functions}, $function);
+ }
+
+ foreach my $constant (@{$interface->constants}) {
+ $constant->extendedAttributes->{"ImplementedBy"} = $interfaceName;
+ # Add interface-wide extended attributes to each constant.
+ foreach my $extendedAttributeName (keys %{$interface->extendedAttributes}) {
+ $constant->extendedAttributes->{$extendedAttributeName} = $interface->extendedAttributes->{$extendedAttributeName};
+ }
+ push(@{$targetDataNode->constants}, $constant);
+ }
+ }
+ }
+}
+
+1;
« no previous file with comments | « Source/bindings/derived_sources.gyp ('k') | Source/bindings/scripts/generate-bindings.pl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698