Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: core/scripts/make_dom_exceptions.py

Issue 22498002: Roll IDL to multivm@1329 (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « core/scripts/make_css_value_keywords.py ('k') | core/scripts/make_event_factory.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 import os.path
31 import sys
32 import shutil
33
34 from in_file import InFile
35 import name_macros
36 import license
37
38
39 HEADER_TEMPLATE = """%(license)s
40
41 #ifndef %(class_name)s_h
42 #define %(class_name)s_h
43
44 namespace WebCore {
45
46 typedef int ExceptionCode;
47
48 enum ExceptionType {
49 %(exception_types)s
50 };
51
52 struct ExceptionCodeDescription {
53 explicit ExceptionCodeDescription(ExceptionCode);
54
55 // |name| is the exception name, also intended for use in exception
56 // description strings; 0 if name not known; maximum length is 27
57 // characters.
58 const char* name;
59
60 // |description| is the exception description, intended for use in
61 // exception strings. It is a more readable explanation of error.
62 const char* description;
63
64 // |code| is the numeric value of the exception within a particular type.
65 int code;
66
67 ExceptionType type;
68 };
69
70 } // namespace WebCore
71
72 #endif // %(class_name)s_h
73 """
74
75
76 IMPLEMENTATION_TEMPLATE = """%(license)s
77
78 #include "config.h"
79 #include "%(class_name)s.h"
80
81 #include "ExceptionCode.h"
82
83 %(includes)s
84
85 #include "modules/indexeddb/IDBDatabaseException.h"
86
87 namespace WebCore {
88
89 ExceptionCodeDescription::ExceptionCodeDescription(ExceptionCode ec)
90 {
91 ASSERT(ec);
92
93 %(description_initalizations)s
94
95 // FIXME: This special case for IDB is undesirable. It is the first usage
96 // of "new style" DOMExceptions where there is no IDL type, but there are
97 // API-specific exception names and/or messages. Consider refactoring back
98 // into the code generator when a common pattern emerges.
99 if (IDBDatabaseException::initializeDescription(ec, this))
100 return;
101
102 if (DOMCoreException::initializeDescription(ec, this))
103 return;
104
105 ASSERT_NOT_REACHED();
106 }
107
108 } // namespace WebCore
109 """
110
111
112 class ExceptionCodeDescriptionWriter(name_macros.Writer):
113 defaults = {
114 'implementedAs': None,
115 'conditional': None,
116 }
117 default_parameters = {
118 'namespace': '',
119 }
120
121 def __init__(self, in_file_path, enabled_conditions):
122 super(ExceptionCodeDescriptionWriter, self).__init__(in_file_path, enabl ed_conditions)
123 self._outputs[(self.class_name + ".cpp")] = self.generate_implementation
124 self._outputs[(self.class_name + ".h")] = self.generate_header
125
126 def _exceptions(self):
127 return self.in_file.name_dictionaries
128
129 def _exception_type(self, exception):
130 return self.wrap_with_condition(' ' + self._class_name_for_entry(exce ption) + 'Type,', exception['conditional'])
131
132 def generate_header(self):
133 return HEADER_TEMPLATE % {
134 'license': license.license_for_generated_cpp(),
135 'class_name': self.class_name,
136 'exception_types': '\n'.join(map(self._exception_type, self._excepti ons())),
137 }
138
139 def _include(self, exception):
140 include = '#include "' + self._headers_header_include_path(exception) + '"'
141 return self.wrap_with_condition(include, exception['conditional'])
142
143 def _description_initalization(self, exception):
144 name = os.path.basename(exception['name'])
145 if name == 'DOMException':
146 return '' # DOMException needs to be last because it's a catch-all.
147 description_initalization = """ if (%(name)s::initializeDescription(e c, this))
148 return;""" % {'name': name}
149 return self.wrap_with_condition(description_initalization, exception['co nditional'])
150
151 def generate_implementation(self):
152 return IMPLEMENTATION_TEMPLATE % {
153 'license': license.license_for_generated_cpp(),
154 'class_name': self.class_name,
155 'includes': '\n'.join(map(self._include, self._exceptions())),
156 'description_initalizations': '\n'.join(map(self._description_inital ization, self._exceptions())),
157 }
158
159
160 if __name__ == "__main__":
161 name_macros.Maker(ExceptionCodeDescriptionWriter).main(sys.argv)
OLDNEW
« no previous file with comments | « core/scripts/make_css_value_keywords.py ('k') | core/scripts/make_event_factory.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698