OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build
. | 5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build
. |
6 | 6 |
7 Design doc: http://www.chromium.org/developers/design-documents/idl-build | 7 Design doc: http://www.chromium.org/developers/design-documents/idl-build |
8 """ | 8 """ |
9 | 9 |
10 import os | 10 import os |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return ( | 112 return ( |
113 [left for left, right in implements_pairs if right == interface_name], | 113 [left for left, right in implements_pairs if right == interface_name], |
114 [right for left, right in implements_pairs if left == interface_name]) | 114 [right for left, right in implements_pairs if left == interface_name]) |
115 | 115 |
116 | 116 |
117 def is_callback_interface_from_idl(file_contents): | 117 def is_callback_interface_from_idl(file_contents): |
118 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) | 118 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) |
119 return bool(match) | 119 return bool(match) |
120 | 120 |
121 | 121 |
| 122 def is_dictionary_from_idl(file_contents): |
| 123 match = re.search(r'dictionary\s+\w+\s*{', file_contents) |
| 124 return bool(match) |
| 125 |
| 126 |
122 def get_parent_interface(file_contents): | 127 def get_parent_interface(file_contents): |
123 match = re.search(r'interface\s+' | 128 match = re.search(r'interface\s+' |
124 r'\w+\s*' | 129 r'\w+\s*' |
125 r':\s*(\w+)\s*' | 130 r':\s*(\w+)\s*' |
126 r'{', | 131 r'{', |
127 file_contents) | 132 file_contents) |
128 return match and match.group(1) | 133 return match and match.group(1) |
129 | 134 |
130 | 135 |
131 def get_interface_extended_attributes_from_idl(file_contents): | 136 def get_interface_extended_attributes_from_idl(file_contents): |
132 # Strip comments | 137 # Strip comments |
133 # re.compile needed b/c Python 2.6 doesn't support flags in re.sub | 138 # re.compile needed b/c Python 2.6 doesn't support flags in re.sub |
134 single_line_comment_re = re.compile(r'//.*$', flags=re.MULTILINE) | 139 single_line_comment_re = re.compile(r'//.*$', flags=re.MULTILINE) |
135 block_comment_re = re.compile(r'/\*.*?\*/', flags=re.MULTILINE | re.DOTALL) | 140 block_comment_re = re.compile(r'/\*.*?\*/', flags=re.MULTILINE | re.DOTALL) |
136 file_contents = re.sub(single_line_comment_re, '', file_contents) | 141 file_contents = re.sub(single_line_comment_re, '', file_contents) |
137 file_contents = re.sub(block_comment_re, '', file_contents) | 142 file_contents = re.sub(block_comment_re, '', file_contents) |
138 | 143 |
139 match = re.search(r'\[(.*)\]\s*' | 144 match = re.search(r'\[(.*)\]\s*' |
140 r'((callback|partial)\s+)?' | 145 r'((callback|partial)\s+)?' |
141 r'(interface|exception)\s+' | 146 r'(interface|exception)\s+' |
142 r'\w+\s*' | 147 r'\w+\s*' |
143 r'(:\s*\w+\s*)?' | 148 r'(:\s*\w+\s*)?' |
144 r'{', | 149 r'{', |
145 file_contents, flags=re.DOTALL) | 150 file_contents, flags=re.DOTALL) |
146 if not match: | 151 if not match: |
147 return {} | 152 return {} |
148 | 153 |
149 extended_attributes_string = match.group(1) | 154 extended_attributes_string = match.group(1) |
150 extended_attributes = {} | 155 extended_attributes = {} |
151 # FIXME: this splitting is WRONG: it fails on ExtendedAttributeArgList like | 156 # FIXME: this splitting is WRONG: it fails on extended attributes where list
s of |
152 # 'NamedConstructor=Foo(a, b)' | 157 # multiple values are used, which are seperated by a comma and a space. |
153 parts = [extended_attribute.strip() | 158 parts = [extended_attribute.strip() |
154 for extended_attribute in extended_attributes_string.split(',') | 159 for extended_attribute in re.split(',\s+', extended_attributes_stri
ng) |
155 # Discard empty parts, which may exist due to trailing comma | 160 # Discard empty parts, which may exist due to trailing comma |
156 if extended_attribute.strip()] | 161 if extended_attribute.strip()] |
157 for part in parts: | 162 for part in parts: |
158 name, _, value = map(string.strip, part.partition('=')) | 163 name, _, value = map(string.strip, part.partition('=')) |
159 extended_attributes[name] = value | 164 extended_attributes[name] = value |
160 return extended_attributes | 165 return extended_attributes |
161 | 166 |
162 | 167 |
163 def get_put_forward_interfaces_from_idl(file_contents): | 168 def get_put_forward_interfaces_from_idl(file_contents): |
164 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' | 169 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' |
165 r'readonly\s+' | 170 r'readonly\s+' |
166 r'attribute\s+' | 171 r'attribute\s+' |
167 r'(\w+)') | 172 r'(\w+)') |
168 return sorted(set(match.group(1) | 173 return sorted(set(match.group(1) |
169 for match in re.finditer(put_forwards_pattern, | 174 for match in re.finditer(put_forwards_pattern, |
170 file_contents, | 175 file_contents, |
171 flags=re.DOTALL))) | 176 flags=re.DOTALL))) |
OLD | NEW |