OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 def read_idl_file(self, idl_filename): | 64 def read_idl_file(self, idl_filename): |
65 """Returns an IdlDefinitions object for an IDL file, without any depende
ncies. | 65 """Returns an IdlDefinitions object for an IDL file, without any depende
ncies. |
66 | 66 |
67 The IdlDefinitions object is guaranteed to contain a single | 67 The IdlDefinitions object is guaranteed to contain a single |
68 IdlInterface; it may also contain other definitions, such as | 68 IdlInterface; it may also contain other definitions, such as |
69 callback functions and enumerations.""" | 69 callback functions and enumerations.""" |
70 ast = blink_idl_parser.parse_file(self.parser, idl_filename) | 70 ast = blink_idl_parser.parse_file(self.parser, idl_filename) |
71 if not ast: | 71 if not ast: |
72 raise Exception('Failed to parse %s' % idl_filename) | 72 raise Exception('Failed to parse %s' % idl_filename) |
73 definitions = IdlDefinitions(ast) | 73 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename)) |
| 74 definitions = IdlDefinitions(idl_file_basename, ast) |
74 | 75 |
75 if not self.multi_interface: | 76 if not self.multi_interface: |
76 # Validate file contents with filename convention | 77 # Validate file contents with filename convention |
77 # The Blink IDL filenaming convention is that the file | 78 # The Blink IDL filenaming convention is that the file |
78 # <interface_name>.idl MUST contain exactly 1 interface (or exceptio
n), | 79 # <definition_name>.idl MUST contain exactly 1 definition |
79 # and the interface name must agree with the file's basename, | 80 # (interface, dictionary or exception), and the definition name must |
80 # unless it is a partial interface. | 81 # agree with the file's basename, unless it is a partial definition. |
81 # (e.g., 'partial interface Foo' can be in FooBar.idl). | 82 # (e.g., 'partial interface Foo' can be in FooBar.idl). |
82 number_of_interfaces = len(definitions.interfaces) | 83 targets = (definitions.interfaces.values() + |
83 if number_of_interfaces != 1: | 84 definitions.dictionaries.values()) |
| 85 number_of_targets = len(targets) |
| 86 if number_of_targets != 1: |
84 raise Exception( | 87 raise Exception( |
85 'Expected exactly 1 interface in file {0}, but found {1}' | 88 'Expected exactly 1 definition in file {0}, but found {1}' |
86 .format(idl_filename, number_of_interfaces)) | 89 .format(idl_filename, number_of_targets)) |
87 interface = next(definitions.interfaces.itervalues()) | 90 target = targets[0] |
88 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filenam
e)) | 91 if not target.is_partial and target.name != idl_file_basename: |
89 if not interface.is_partial and interface.name != idl_file_basename: | |
90 raise Exception( | 92 raise Exception( |
91 'Interface name "{0}" disagrees with IDL file basename "{1}"
.' | 93 'Definition name "{0}" disagrees with IDL file basename "{1}
".' |
92 .format(interface.name, idl_file_basename)) | 94 .format(target.name, idl_file_basename)) |
93 else: | 95 else: |
94 if len(definitions.interfaces) > 1: | 96 if len(definitions.interfaces) > 1: |
95 print '----- Supplemental interfaces %s' % len(definitions.inter
faces) | 97 print '----- Supplemental interfaces %s' % len(definitions.inter
faces) |
96 | 98 |
97 # Validate extended attributes | 99 # Validate extended attributes |
98 if not self.extended_attribute_validator: | 100 if not self.extended_attribute_validator: |
99 return definitions | 101 return definitions |
100 | 102 |
101 try: | 103 try: |
102 self.extended_attribute_validator.validate_extended_attributes(defin
itions) | 104 self.extended_attribute_validator.validate_extended_attributes(defin
itions) |
103 except IDLInvalidExtendedAttributeError as error: | 105 except IDLInvalidExtendedAttributeError as error: |
104 raise IDLInvalidExtendedAttributeError(""" | 106 raise IDLInvalidExtendedAttributeError(""" |
105 IDL ATTRIBUTE ERROR in file: | 107 IDL ATTRIBUTE ERROR in file: |
106 %s: | 108 %s: |
107 %s | 109 %s |
108 If you want to add a new IDL extended attribute, please add it to: | 110 If you want to add a new IDL extended attribute, please add it to: |
109 %s | 111 %s |
110 and add an explanation to the Blink IDL documentation at: | 112 and add an explanation to the Blink IDL documentation at: |
111 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes | 113 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes |
112 """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH)) | 114 """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH)) |
113 | 115 |
114 return definitions | 116 return definitions |
OLD | NEW |