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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 #endif // %(namespace)sInterfaces_h | 62 #endif // %(namespace)sInterfaces_h |
63 """ | 63 """ |
64 | 64 |
65 | 65 |
66 class Writer(in_generator.Writer): | 66 class Writer(in_generator.Writer): |
67 def __init__(self, in_file_path): | 67 def __init__(self, in_file_path): |
68 super(Writer, self).__init__(in_file_path) | 68 super(Writer, self).__init__(in_file_path) |
69 self.namespace = self.in_file.parameters['namespace'].strip('"') | 69 self.namespace = self.in_file.parameters['namespace'].strip('"') |
70 self._entries_by_conditional = {} | 70 self._entries_by_conditional = {} |
71 self._unconditional_entries = [] | 71 self._unconditional_entries = [] |
| 72 self._validate_entries() |
72 self._sort_entries_by_conditional() | 73 self._sort_entries_by_conditional() |
73 self._outputs = {(self.namespace + "Headers.h"): self.generate_headers_h
eader, | 74 self._outputs = {(self.namespace + "Headers.h"): self.generate_headers_h
eader, |
74 (self.namespace + "Interfaces.h"): self.generate_interf
aces_header, | 75 (self.namespace + "Interfaces.h"): self.generate_interf
aces_header, |
75 } | 76 } |
76 | 77 |
| 78 def _validate_entries(self): |
| 79 # If there is more than one entry with the same script name, only the fi
rst one will ever |
| 80 # be hit in practice, and so we'll silently ignore any properties reques
ted for the second |
| 81 # (like RuntimeEnabled - see crbug.com/332588). |
| 82 entries_by_script_name = dict() |
| 83 for entry in self.in_file.name_dictionaries: |
| 84 script_name = name_utilities.script_name(entry) |
| 85 if script_name in entries_by_script_name: |
| 86 self._fatal('Multiple entries with script_name=%(script_name)s:
%(name1)s %(name2)s' % { |
| 87 'script_name': script_name, |
| 88 'name1': entry['name'], |
| 89 'name2': entries_by_script_name[script_name]['name']}) |
| 90 entries_by_script_name[script_name] = entry |
| 91 |
| 92 def _fatal(self, message): |
| 93 print 'FATAL ERROR: ' + message |
| 94 exit(1) |
| 95 |
77 def _sort_entries_by_conditional(self): | 96 def _sort_entries_by_conditional(self): |
78 unconditional_names = set() | 97 unconditional_names = set() |
79 for entry in self.in_file.name_dictionaries: | 98 for entry in self.in_file.name_dictionaries: |
80 conditional = entry['Conditional'] | 99 conditional = entry['Conditional'] |
81 if not conditional: | 100 if not conditional: |
82 cpp_name = name_utilities.cpp_name(entry) | 101 cpp_name = name_utilities.cpp_name(entry) |
83 if cpp_name in unconditional_names: | 102 if cpp_name in unconditional_names: |
84 continue | 103 continue |
85 unconditional_names.add(cpp_name) | 104 unconditional_names.add(cpp_name) |
86 self._unconditional_entries.append(entry) | 105 self._unconditional_entries.append(entry) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 176 |
158 def generate_interfaces_header(self): | 177 def generate_interfaces_header(self): |
159 return INTERFACES_HEADER_TEMPLATE % { | 178 return INTERFACES_HEADER_TEMPLATE % { |
160 'license': license.license_for_generated_cpp(), | 179 'license': license.license_for_generated_cpp(), |
161 'namespace': self.namespace, | 180 'namespace': self.namespace, |
162 'macro_style_name': name_utilities.to_macro_style(self.namespace), | 181 'macro_style_name': name_utilities.to_macro_style(self.namespace), |
163 'declare_conditional_macros': self._declare_conditional_macros(), | 182 'declare_conditional_macros': self._declare_conditional_macros(), |
164 'unconditional_macros': '\n'.join(sorted(set(map(self._unconditional
_macro, self._unconditional_entries)))), | 183 'unconditional_macros': '\n'.join(sorted(set(map(self._unconditional
_macro, self._unconditional_entries)))), |
165 'conditional_macros': '\n'.join(map(self._conditional_macros, self._
entries_by_conditional.keys())), | 184 'conditional_macros': '\n'.join(map(self._conditional_macros, self._
entries_by_conditional.keys())), |
166 } | 185 } |
OLD | NEW |