| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 typedef int ExceptionCode; | 46 typedef int ExceptionCode; |
| 47 | 47 |
| 48 enum ExceptionType { | 48 enum ExceptionType { |
| 49 %(exception_types)s | 49 %(exception_types)s |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 struct ExceptionCodeDescription { | 52 struct ExceptionCodeDescription { |
| 53 explicit ExceptionCodeDescription(ExceptionCode); | 53 explicit ExceptionCodeDescription(ExceptionCode); |
| 54 | 54 |
| 55 // |typeName| has spaces and is suitable for use in exception | |
| 56 // description strings; maximum length is 10 characters. | |
| 57 const char* typeName; | |
| 58 | |
| 59 // |name| is the exception name, also intended for use in exception | 55 // |name| is the exception name, also intended for use in exception |
| 60 // description strings; 0 if name not known; maximum length is 27 | 56 // description strings; 0 if name not known; maximum length is 27 |
| 61 // characters. | 57 // characters. |
| 62 const char* name; | 58 const char* name; |
| 63 | 59 |
| 64 // |description| is the exception description, intended for use in | 60 // |description| is the exception description, intended for use in |
| 65 // exception strings. It is a more readable explanation of error. | 61 // exception strings. It is a more readable explanation of error. |
| 66 const char* description; | 62 const char* description; |
| 67 | 63 |
| 68 // |code| is the numeric value of the exception within a particular type. | 64 // |code| is the numeric value of the exception within a particular type. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 104 |
| 109 ASSERT_NOT_REACHED(); | 105 ASSERT_NOT_REACHED(); |
| 110 } | 106 } |
| 111 | 107 |
| 112 } // namespace WebCore | 108 } // namespace WebCore |
| 113 """ | 109 """ |
| 114 | 110 |
| 115 | 111 |
| 116 class ExceptionCodeDescriptionWriter(name_macros.Writer): | 112 class ExceptionCodeDescriptionWriter(name_macros.Writer): |
| 117 defaults = { | 113 defaults = { |
| 118 'interfaceName': None, | 114 'implementedAs': None, |
| 119 'conditional': None, | 115 'conditional': None, |
| 120 } | 116 } |
| 121 default_parameters = { | 117 default_parameters = { |
| 122 'namespace': '', | 118 'namespace': '', |
| 123 } | 119 } |
| 124 | 120 |
| 125 def __init__(self, in_file_path, enabled_conditions): | 121 def __init__(self, in_file_path, enabled_conditions): |
| 126 super(ExceptionCodeDescriptionWriter, self).__init__(in_file_path, enabl
ed_conditions) | 122 super(ExceptionCodeDescriptionWriter, self).__init__(in_file_path, enabl
ed_conditions) |
| 127 self._outputs[(self.class_name + ".cpp")] = self.generate_implementation | 123 self._outputs[(self.class_name + ".cpp")] = self.generate_implementation |
| 128 self._outputs[(self.class_name + ".h")] = self.generate_header | 124 self._outputs[(self.class_name + ".h")] = self.generate_header |
| 129 | 125 |
| 130 def _exceptions(self): | 126 def _exceptions(self): |
| 131 return self.in_file.name_dictionaries | 127 return self.in_file.name_dictionaries |
| 132 | 128 |
| 133 def _exception_type(self, exception): | 129 def _exception_type(self, exception): |
| 134 name = os.path.basename(exception['name']) | 130 return self.wrap_with_condition(' ' + self._class_name_for_entry(exce
ption) + 'Type,', exception['conditional']) |
| 135 return self.wrap_with_condition(' ' + name + 'Type,', exception['cond
itional']) | |
| 136 | 131 |
| 137 def generate_header(self): | 132 def generate_header(self): |
| 138 return HEADER_TEMPLATE % { | 133 return HEADER_TEMPLATE % { |
| 139 'license': license.license_for_generated_cpp(), | 134 'license': license.license_for_generated_cpp(), |
| 140 'class_name': self.class_name, | 135 'class_name': self.class_name, |
| 141 'exception_types': '\n'.join(map(self._exception_type, self._excepti
ons())), | 136 'exception_types': '\n'.join(map(self._exception_type, self._excepti
ons())), |
| 142 } | 137 } |
| 143 | 138 |
| 144 def _include(self, exception): | 139 def _include(self, exception): |
| 145 include = '#include "' + exception['name'] + '.h"' | 140 include = '#include "' + self._headers_header_include_path(exception) +
'"' |
| 146 return self.wrap_with_condition(include, exception['conditional']) | 141 return self.wrap_with_condition(include, exception['conditional']) |
| 147 | 142 |
| 148 def _description_initalization(self, exception): | 143 def _description_initalization(self, exception): |
| 149 name = os.path.basename(exception['name']) | 144 name = os.path.basename(exception['name']) |
| 150 if name == 'DOMCoreException': | 145 if name == 'DOMException': |
| 151 return '' # DOMCoreException needs to be last because it's a catch-
all. | 146 return '' # DOMException needs to be last because it's a catch-all. |
| 152 description_initalization = """ if (%(name)s::initializeDescription(e
c, this)) | 147 description_initalization = """ if (%(name)s::initializeDescription(e
c, this)) |
| 153 return;""" % {'name': name} | 148 return;""" % {'name': name} |
| 154 return self.wrap_with_condition(description_initalization, exception['co
nditional']) | 149 return self.wrap_with_condition(description_initalization, exception['co
nditional']) |
| 155 | 150 |
| 156 def generate_implementation(self): | 151 def generate_implementation(self): |
| 157 return IMPLEMENTATION_TEMPLATE % { | 152 return IMPLEMENTATION_TEMPLATE % { |
| 158 'license': license.license_for_generated_cpp(), | 153 'license': license.license_for_generated_cpp(), |
| 159 'class_name': self.class_name, | 154 'class_name': self.class_name, |
| 160 'includes': '\n'.join(map(self._include, self._exceptions())), | 155 'includes': '\n'.join(map(self._include, self._exceptions())), |
| 161 'description_initalizations': '\n'.join(map(self._description_inital
ization, self._exceptions())), | 156 'description_initalizations': '\n'.join(map(self._description_inital
ization, self._exceptions())), |
| 162 } | 157 } |
| 163 | 158 |
| 164 | 159 |
| 165 if __name__ == "__main__": | 160 if __name__ == "__main__": |
| 166 name_macros.Maker(ExceptionCodeDescriptionWriter).main(sys.argv) | 161 name_macros.Maker(ExceptionCodeDescriptionWriter).main(sys.argv) |
| OLD | NEW |