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

Side by Side Diff: Source/bindings/scripts/SemanticAnalyzer.pm

Issue 15984007: Refactor IDL value checking into SemanticAnalyzer.pm (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add dependency 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 SemanticAnalyzer;
30
31 sub new
32 {
33 my $class = shift;
34 my $idlAttributesFile = shift;
35
36 $idlAttributes = {};
37 open FH, "<", $idlAttributesFile or die "Couldn't open $idlAttributesFile: $ !";
38 while (my $line = <FH>) {
39 chomp $line;
40 next if $line =~ /^\s*#/;
41 next if $line =~ /^\s*$/;
42
43 if ($line =~ /^\s*([^=\s]*)\s*=?\s*(.*)/) {
44 my $name = $1;
45 $idlAttributes{$name} = {};
46 if ($2) {
47 foreach my $rightValue (split /\|/, $2) {
48 $rightValue =~ s/^\s*|\s*$//g;
49 $rightValue = "VALUE_IS_MISSING" unless $rightValue;
50 $idlAttributes{$name}{$rightValue} = 1;
51 }
52 } else {
53 $idlAttributes{$name}{"VALUE_IS_MISSING"} = 1;
54 }
55 } else {
56 die "The format of " . basename($idlAttributesFile) . " is wrong: li ne $.\n";
57 }
58 }
59 close FH;
60
61 my $reference = { };
62 bless($reference, $class);
63 return $reference;
64 }
65
66 sub checkIDLAttributes
67 {
68 my $object = shift;
69 my $document = shift;
70 my $idlFile = shift;
71
72 foreach my $interface (@{$document->interfaces}) {
73 $object->checkIfIDLAttributesExists($idlAttributes, $interface->extended Attributes, $idlFile);
74
75 foreach my $attribute (@{$interface->attributes}) {
76 $object->checkIfIDLAttributesExists($idlAttributes, $attribute->sign ature->extendedAttributes, $idlFile);
77 }
78
79 foreach my $function (@{$interface->functions}) {
80 $object->checkIfIDLAttributesExists($idlAttributes, $function->signa ture->extendedAttributes, $idlFile);
81 foreach my $parameter (@{$function->parameters}) {
82 $object->checkIfIDLAttributesExists($idlAttributes, $parameter-> extendedAttributes, $idlFile);
83 }
84 }
85 }
86 }
87
88 sub checkIfIDLAttributesExists
89 {
90 my $object = shift;
91 my $extendedAttributes = shift;
92 my $idlFile = shift;
93
94 my $error;
95 OUTER: for my $name (keys %$extendedAttributes) {
96 if (!exists $object->idlAttributes->{$name}) {
97 # if (!exists $idlAttributes->{$name}) {
98 $error = "Unknown IDL attribute [$name] is found at $idlFile.";
99 last OUTER;
100 }
101 if ($object->idlAttributes->{$name}{"*"}) {
102 next;
103 }
104 for my $rightValue (split /\s*\|\s*/, $extendedAttributes->{$name}) {
105 if (!exists $object->idlAttributes->{$name}{$rightValue}) {
106 $error = "Unknown IDL attribute [$name=" . $extendedAttributes-> {$name} . "] is found at $idlFile.";
107 last OUTER;
108 }
109 }
110 }
111 if ($error) {
112 die "IDL ATTRIBUTE CHECKER ERROR: $error
113 If you want to add a new IDL attribute, you need to add it to bindings/scripts/I DLAttributes.txt and add explanations to the Blink IDL document (http://chromium .org/blink/webidl).
114 ";
115 }
116 }
117
118 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