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

Side by Side 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, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/derived_sources.gyp ('k') | Source/bindings/scripts/generate-bindings.pl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 package InterfaceMerger;
30
31 use strict;
32 use warnings;
33
34 use File::Basename;
35 use Text::ParseWords;
36
37 use IDLParser;
38
39 require Exporter;
40 use vars qw(@ISA @EXPORT_OK);
41 @ISA = qw(Exporter);
42 @EXPORT_OK = qw(computeIdlDependencies mergePartialInterfaces);
43
44 sub computeIdlDependencies
45 {
46 my $targetIdlFileBasename = shift;
47 my $dependenciesFile = shift;
48 my $additionalIdlFilesString = shift;
49
50 my $idlDependencies;
51
52 # The format of the dependencies file:
53 #
54 # DOMWindow.idl P.idl Q.idl R.idl
55 # Document.idl S.idl
56 # Event.idl
57 # ...
58 #
59 # The above indicates that DOMWindow.idl depends on P.idl, Q.idl and R.idl,
60 # Document.idl depends on S.idl, and Event.idl depends no IDLs.
61 # Dependencies themselves (e.g. P.idl) do not have their own line.
62 open FH, "< $dependenciesFile" or die "Cannot open $dependenciesFile\n";
63 while (my $line = <FH>) {
64 my ($idlFile, @dependencies) = split(/\s+/, $line);
65 if ($idlFile and basename($idlFile) eq $targetIdlFileBasename) {
66 close FH;
67 return \@dependencies;
68 }
69 }
70 close FH;
71
72 # $additionalIdlFilesString is a list of IDL files which should not be
73 # included in DerivedSources*.cpp (i.e. they are not described in the
74 # dependencies file) but should generate .h and .cpp files.
75 if ($additionalIdlFilesString) {
76 my @additionalIdlFiles = shellwords($additionalIdlFilesString);
77 if (grep { $_ and basename($_) eq $targetIdlFileBasename } @additionalId lFiles) {
78 return [];
79 }
80 }
81 }
82
83 sub mergePartialInterfaces
84 {
85 my $targetDocument = shift;
86 my $targetInterfaceName = shift;
87 my $targetIdlFile = shift;
88 my $dependencies = shift;
89 my $defines = shift;
90 my $preprocessor = shift;
91 my $verbose = shift;
92
93 foreach my $idlFile (@$dependencies) {
94 # FIXME: circular dependency, should never happen
95 next if $idlFile eq $targetIdlFile;
96 my $interfaceName = fileparse(basename($idlFile), ".idl");
97 my $parser = IDLParser->new(!$verbose);
98 my $document = $parser->Parse($idlFile, $defines, $preprocessor);
99
100 foreach my $interface (@{$document->interfaces}) {
101 die "$idlFile is not a dependency of $targetIdlFile. There maybe a b ug in the dependency generator (preprocess_idls.py).\n" unless ($interface->isPa rtial and $interface->name eq $targetInterfaceName);
102 my $targetDataNode;
103 foreach my $interface (@{$targetDocument->interfaces}) {
104 if ($interface->name eq $targetInterfaceName) {
105 $targetDataNode = $interface;
106 last;
107 }
108 }
109 die "Did not find interface ${targetInterfaceName} in ${targetInterf aceName}.idl." unless defined $targetDataNode;
110
111 foreach my $attribute (@{$interface->attributes}) {
112 $attribute->signature->extendedAttributes->{"ImplementedBy"} = $ interfaceName;
113 # Add interface-wide extended attributes to each attribute.
114 foreach my $extendedAttributeName (keys %{$interface->extendedAt tributes}) {
115 $attribute->signature->extendedAttributes->{$extendedAttribu teName} = $interface->extendedAttributes->{$extendedAttributeName};
116 }
117 push(@{$targetDataNode->attributes}, $attribute);
118 }
119
120 foreach my $function (@{$interface->functions}) {
121 $function->signature->extendedAttributes->{"ImplementedBy"} = $i nterfaceName;
122 # Add interface-wide extended attributes to each method.
123 foreach my $extendedAttributeName (keys %{$interface->extendedAt tributes}) {
124 $function->signature->extendedAttributes->{$extendedAttribut eName} = $interface->extendedAttributes->{$extendedAttributeName};
125 }
126 push(@{$targetDataNode->functions}, $function);
127 }
128
129 foreach my $constant (@{$interface->constants}) {
130 $constant->extendedAttributes->{"ImplementedBy"} = $interfaceNam e;
131 # Add interface-wide extended attributes to each constant.
132 foreach my $extendedAttributeName (keys %{$interface->extendedAt tributes}) {
133 $constant->extendedAttributes->{$extendedAttributeName} = $i nterface->extendedAttributes->{$extendedAttributeName};
134 }
135 push(@{$targetDataNode->constants}, $constant);
136 }
137 }
138 }
139 }
140
141 1;
OLDNEW
« 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