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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 def _to_macro_style(name): | 65 def _to_macro_style(name): |
66 s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) | 66 s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) |
67 return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).upper() | 67 return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).upper() |
68 | 68 |
69 | 69 |
70 def _name_for_entry(entry): | 70 def _name_for_entry(entry): |
71 if entry['interfaceName']: | 71 if entry['interfaceName']: |
72 return entry['interfaceName'] | 72 return entry['interfaceName'] |
73 return os.path.basename(entry['name']) | 73 return os.path.basename(entry['name']) |
74 | 74 |
75 | |
76 class Writer(in_generator.Writer): | 75 class Writer(in_generator.Writer): |
77 def __init__(self, in_file_path): | 76 def __init__(self, in_file_path): |
78 super(Writer, self).__init__(in_file_path) | 77 super(Writer, self).__init__(in_file_path) |
79 self.class_name = self.in_file.parameters['namespace'].strip('"') | 78 self.class_name = self.in_file.parameters['namespace'].strip('"') |
80 self._entries_by_conditional = {} | 79 self._entries_by_conditional = {} |
81 self._unconditional_entries = [] | 80 self._unconditional_entries = [] |
82 self._sort_entries_by_conditional() | 81 self._sort_entries_by_conditional() |
83 | 82 |
84 def _sort_entries_by_conditional(self): | 83 def _sort_entries_by_conditional(self): |
85 unconditional_names = set() | 84 unconditional_names = set() |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 150 |
152 def generate_interfaces_header(self): | 151 def generate_interfaces_header(self): |
153 return INTERFACES_HEADER_TEMPLATE % { | 152 return INTERFACES_HEADER_TEMPLATE % { |
154 'license': license.license_for_generated_cpp(), | 153 'license': license.license_for_generated_cpp(), |
155 'class_name': self.class_name, | 154 'class_name': self.class_name, |
156 'macro_style_name': _to_macro_style(self.class_name), | 155 'macro_style_name': _to_macro_style(self.class_name), |
157 'declare_conditional_macros': self._declare_conditional_macros(), | 156 'declare_conditional_macros': self._declare_conditional_macros(), |
158 'unconditional_macros': '\n'.join(sorted(set(map(self._unconditional
_macro, self._unconditional_entries)))), | 157 'unconditional_macros': '\n'.join(sorted(set(map(self._unconditional
_macro, self._unconditional_entries)))), |
159 'conditional_macros': '\n'.join(map(self._conditional_macros, self._
entries_by_conditional.keys())), | 158 'conditional_macros': '\n'.join(map(self._conditional_macros, self._
entries_by_conditional.keys())), |
160 } | 159 } |
OLD | NEW |