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

Side by Side Diff: Source/bindings/scripts/semantic_analyzer.py

Issue 15959019: Rewrite generate-bindings.pl in Python (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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/scripts/interface_merger.py ('k') | no next file » | 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 import os.path
30
31
32 class AttributeFileFormatError(Exception):
33 pass
34
35
36 class InvalidIDLAttributeError(Exception):
37 pass
38
39
40 def read_idl_file(idl_attributes_filename):
41 idl_attributes = {}
42 with open(idl_attributes_filename) as idl_attributes_file:
43 for line in idl_attributes_file:
44 line = line.strip()
45 if not line or line.startswith('#'):
46 continue
47 name, _, values_string = map(str.strip, line.partition('='))
48 if not name:
49 raise AttributeFileFormatError('The format of %s is wrong, in li ne "%s"' % os.path.basename(idl_attributes_filename), line)
50 idl_attributes[name] = set()
51 value_list = values_string.split('|')
52 if not value_list:
53 idl_attributes[name].add(None)
54 continue
55 for value in value_list:
56 value = value.strip()
57 if not value:
58 value = None
59 idl_attributes[name].add(value)
60 return idl_attributes
61
62
63 class IDLAttributeChecker():
64 def __init__(self, idl_attributes_filename):
65 self.idl_attributes = read_idl_file(idl_attributes_filename)
66
67 def validate_name_value_string(self, name, values_string):
68 if name not in self.idl_attributes:
69 raise InvalidIDLAttributeError('Unknown IDL attribute [%s]' % name)
70 valid_values = self.idl_attributes[name]
71 if '*' in valid_values: # wildcard, any value ok
72 return
73 value_list = values_string.strip.split('|')
74 for value in value_list:
75 if value not in valid_values:
76 raise InvalidIDLAttributeError('Invalid IDL value {value} found in attribute [{name}={value_string}]'.format(**locals))
77
78 def validate_extended_attributes(self, node):
79 for name, value_string in node['extendedAttributes'].iteritems():
80 self.validate_name_value_string(name, value_string)
81
82 def check_idl_attributes(self, document, idl_filename):
83 # FIXME: this should be done when parsing the tree, rather than after
84 try:
85 for interface in document['interfaces']:
86 self.validate_extended_attributes(interface)
87 for attribute in interface['attributes']:
88 self.validate_extended_attributes(attribute['signature'])
89 for function in interface['functions']:
90 self.validate_extended_attributes(function['signature'])
91 for parameter in function['parameters']:
92 self.validate_extended_attributes(parameter)
93 except InvalidIDLAttributeError, error:
94 raise InvalidIDLAttributeError("""IDL ATTRIBUTE ERROR in file %s:
95 %s
96 If you want to add a new IDL attribute, please add it to bindings/scripts/IDLAtt ributes.txt and add an explanation to the Blink IDL document at http://chromium. org/blink/webidl
97 """ % idl_filename, error.value)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/interface_merger.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698