Chromium Code Reviews| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 ################################################################################ | 54 ################################################################################ |
| 55 | 55 |
| 56 def get_partial_interface_name_from_idl(file_contents): | 56 def get_partial_interface_name_from_idl(file_contents): |
| 57 match = re.search(r'partial\s+interface\s+(\w+)\s*{', file_contents) | 57 match = re.search(r'partial\s+interface\s+(\w+)\s*{', file_contents) |
| 58 return match and match.group(1) | 58 return match and match.group(1) |
| 59 | 59 |
| 60 | 60 |
| 61 def get_implemented_interfaces_from_idl(file_contents, interface_name): | 61 def get_implemented_interfaces_from_idl(file_contents, interface_name): |
| 62 # Rule is: identifier-A implements identifier-B; | 62 # Rule is: identifier-A implements identifier-B; |
| 63 # http://www.w3.org/TR/WebIDL/#idl-implements-statements | 63 # http://www.w3.org/TR/WebIDL/#idl-implements-statements |
| 64 def get_implemented(left_identifier, right_identifier): | |
| 65 # identifier-A must be the current interface | |
| 66 if left_identifier != interface_name: | |
| 67 raise IdlBadFilenameError("Identifier on the left of the 'implements ' statement should be %s in %s.idl, but found %s" % (interface_name, interface_n ame, left_identifier)) | |
| 68 return right_identifier | |
| 69 | |
| 70 implements_re = (r'^\s*' | 64 implements_re = (r'^\s*' |
| 71 r'(\w+)\s+' | 65 r'(\w+)\s+' |
| 72 r'implements\s+' | 66 r'implements\s+' |
| 67 r'(\w+)\s*' | |
| 68 r';') | |
| 69 implements_matches = re.finditer(implements_re, file_contents, re.MULTILINE) | |
| 70 implements_pairs = [(match.group(1), match.group(2)) | |
| 71 for match in implements_matches] | |
| 72 implemented_interfaces = [] | |
| 73 for left, right in implements_pairs: | |
| 74 if left == interface_name: | |
| 75 implemented_interfaces.append(right) | |
| 76 return implemented_interfaces | |
| 77 | |
| 78 | |
| 79 def get_source_interfaces_from_idl(file_contents, interface_name): | |
| 80 # Rule is: identifier-A implements identifier-B; | |
| 81 # http://www.w3.org/TR/WebIDL/#idl-implements-statements | |
| 82 implements_re = (r'^\s*' | |
|
Inactive
2014/05/07 20:00:27
The code duplication with get_implemented_interfac
| |
| 83 r'(\w+)\s+' | |
| 84 r'implements\s+' | |
| 73 r'(\w+)\s*' | 85 r'(\w+)\s*' |
| 74 r';') | 86 r';') |
| 75 implements_matches = re.finditer(implements_re, file_contents, re.MULTILINE) | 87 implements_matches = re.finditer(implements_re, file_contents, re.MULTILINE) |
| 76 implements_pairs = [(match.group(1), match.group(2)) | 88 implements_pairs = [(match.group(1), match.group(2)) |
| 77 for match in implements_matches] | 89 for match in implements_matches] |
| 78 return [get_implemented(left, right) for left, right in implements_pairs] | 90 source_interfaces = [] |
| 91 for left, right in implements_pairs: | |
| 92 if right == interface_name: | |
| 93 source_interfaces.append(left) | |
| 94 return source_interfaces | |
| 79 | 95 |
| 80 | 96 |
| 81 def is_callback_interface_from_idl(file_contents): | 97 def is_callback_interface_from_idl(file_contents): |
| 82 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) | 98 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) |
| 83 return bool(match) | 99 return bool(match) |
| 84 | 100 |
| 85 | 101 |
| 86 def get_parent_interface(file_contents): | 102 def get_parent_interface(file_contents): |
| 87 match = re.search(r'interface\s+' | 103 match = re.search(r'interface\s+' |
| 88 r'\w+\s*' | 104 r'\w+\s*' |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 139 |
| 124 def get_put_forward_interfaces_from_idl(file_contents): | 140 def get_put_forward_interfaces_from_idl(file_contents): |
| 125 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' | 141 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' |
| 126 r'readonly\s+' | 142 r'readonly\s+' |
| 127 r'attribute\s+' | 143 r'attribute\s+' |
| 128 r'(\w+)') | 144 r'(\w+)') |
| 129 return sorted(set(match.group(1) | 145 return sorted(set(match.group(1) |
| 130 for match in re.finditer(put_forwards_pattern, | 146 for match in re.finditer(put_forwards_pattern, |
| 131 file_contents, | 147 file_contents, |
| 132 flags=re.DOTALL))) | 148 flags=re.DOTALL))) |
| OLD | NEW |