OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (C) 2013 Google Inc. All rights reserved. | 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 ASSERT_NOT_REACHED(); | 109 ASSERT_NOT_REACHED(); |
110 } | 110 } |
111 | 111 |
112 } // namespace WebCore | 112 } // namespace WebCore |
113 """ | 113 """ |
114 | 114 |
115 | 115 |
116 class ExceptionCodeDescriptionWriter(name_macros.Writer): | 116 class ExceptionCodeDescriptionWriter(name_macros.Writer): |
117 defaults = { | 117 defaults = { |
118 'JSInterfaceName': None, | 118 'implementedAs': None, |
119 'interfaceName': None, | |
120 'conditional': None, | 119 'conditional': None, |
121 } | 120 } |
122 default_parameters = { | 121 default_parameters = { |
123 'namespace': '', | 122 'namespace': '', |
124 } | 123 } |
125 | 124 |
126 def __init__(self, in_file_path, enabled_conditions): | 125 def __init__(self, in_file_path, enabled_conditions): |
127 super(ExceptionCodeDescriptionWriter, self).__init__(in_file_path, enabl
ed_conditions) | 126 super(ExceptionCodeDescriptionWriter, self).__init__(in_file_path, enabl
ed_conditions) |
128 self._outputs[(self.class_name + ".cpp")] = self.generate_implementation | 127 self._outputs[(self.class_name + ".cpp")] = self.generate_implementation |
129 self._outputs[(self.class_name + ".h")] = self.generate_header | 128 self._outputs[(self.class_name + ".h")] = self.generate_header |
130 | 129 |
131 def _exceptions(self): | 130 def _exceptions(self): |
132 return self.in_file.name_dictionaries | 131 return self.in_file.name_dictionaries |
133 | 132 |
134 def _exception_type(self, exception): | 133 def _exception_type(self, exception): |
135 name = os.path.basename(exception['name']) | 134 return self.wrap_with_condition(' ' + self._class_name_for_entry(exce
ption) + 'Type,', exception['conditional']) |
136 return self.wrap_with_condition(' ' + name + 'Type,', exception['cond
itional']) | |
137 | 135 |
138 def generate_header(self): | 136 def generate_header(self): |
139 return HEADER_TEMPLATE % { | 137 return HEADER_TEMPLATE % { |
140 'license': license.license_for_generated_cpp(), | 138 'license': license.license_for_generated_cpp(), |
141 'class_name': self.class_name, | 139 'class_name': self.class_name, |
142 'exception_types': '\n'.join(map(self._exception_type, self._excepti
ons())), | 140 'exception_types': '\n'.join(map(self._exception_type, self._excepti
ons())), |
143 } | 141 } |
144 | 142 |
145 def _include(self, exception): | 143 def _include(self, exception): |
146 include = '#include "' + exception['name'] + '.h"' | 144 include = '#include "' + self._headers_header_include_path(exception) +
'"' |
147 return self.wrap_with_condition(include, exception['conditional']) | 145 return self.wrap_with_condition(include, exception['conditional']) |
148 | 146 |
149 def _description_initalization(self, exception): | 147 def _description_initalization(self, exception): |
150 name = os.path.basename(exception['name']) | 148 name = os.path.basename(exception['name']) |
151 if name == 'DOMCoreException': | 149 if name == 'DOMException': |
152 return '' # DOMCoreException needs to be last because it's a catch-
all. | 150 return '' # DOMException needs to be last because it's a catch-all. |
153 description_initalization = """ if (%(name)s::initializeDescription(e
c, this)) | 151 description_initalization = """ if (%(name)s::initializeDescription(e
c, this)) |
154 return;""" % {'name': name} | 152 return;""" % {'name': name} |
155 return self.wrap_with_condition(description_initalization, exception['co
nditional']) | 153 return self.wrap_with_condition(description_initalization, exception['co
nditional']) |
156 | 154 |
157 def generate_implementation(self): | 155 def generate_implementation(self): |
158 return IMPLEMENTATION_TEMPLATE % { | 156 return IMPLEMENTATION_TEMPLATE % { |
159 'license': license.license_for_generated_cpp(), | 157 'license': license.license_for_generated_cpp(), |
160 'class_name': self.class_name, | 158 'class_name': self.class_name, |
161 'includes': '\n'.join(map(self._include, self._exceptions())), | 159 'includes': '\n'.join(map(self._include, self._exceptions())), |
162 'description_initalizations': '\n'.join(map(self._description_inital
ization, self._exceptions())), | 160 'description_initalizations': '\n'.join(map(self._description_inital
ization, self._exceptions())), |
163 } | 161 } |
164 | 162 |
165 | 163 |
166 if __name__ == "__main__": | 164 if __name__ == "__main__": |
167 name_macros.Maker(ExceptionCodeDescriptionWriter).main(sys.argv) | 165 name_macros.Maker(ExceptionCodeDescriptionWriter).main(sys.argv) |
OLD | NEW |