]> git.saurik.com Git - apple/javascriptcore.git/blob - inspector/scripts/CodeGeneratorInspectorStrings.py
2763744160b84ffd2c37759a43dbd33df0145a44
[apple/javascriptcore.git] / inspector / scripts / CodeGeneratorInspectorStrings.py
1 # Copyright (c) 2013 Google Inc. All rights reserved.
2 # Copyright (c) 2013 Apple 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 # This file contains string resources for CodeGeneratorInspector.
31 # Its syntax is a Python syntax subset, suitable for manual parsing.
32
33 frontend_domain_class = (
34 """class ${exportMacro} ${domainClassName} {
35 public:
36 ${domainClassName}(InspectorFrontendChannel* inspectorFrontendChannel) : m_inspectorFrontendChannel(inspectorFrontendChannel) { }
37 ${frontendDomainMethodDeclarations}private:
38 InspectorFrontendChannel* m_inspectorFrontendChannel;
39 };
40
41 """)
42
43 backend_dispatcher_constructor = (
44 """PassRefPtr<${dispatcherName}> ${dispatcherName}::create(InspectorBackendDispatcher* backendDispatcher, ${agentName}* agent)
45 {
46 return adoptRef(new ${dispatcherName}(backendDispatcher, agent));
47 }
48
49 ${dispatcherName}::${dispatcherName}(InspectorBackendDispatcher* backendDispatcher, ${agentName}* agent)
50 : InspectorSupplementalBackendDispatcher(backendDispatcher)
51 , m_agent(agent)
52 {
53 m_backendDispatcher->registerDispatcherForDomain(ASCIILiteral("${domainName}"), this);
54 }
55 """)
56
57 backend_dispatcher_dispatch_method_simple = (
58 """void ${dispatcherName}::dispatch(long callId, const String& method, PassRefPtr<InspectorObject> message)
59 {
60 Ref<${dispatcherName}> protect(*this);
61
62 ${ifChain}
63 else
64 m_backendDispatcher->reportProtocolError(&callId, InspectorBackendDispatcher::MethodNotFound, String("'") + "${domainName}" + '.' + method + "' was not found");
65 }
66 """)
67
68 backend_dispatcher_dispatch_method = (
69 """void ${dispatcherName}::dispatch(long callId, const String& method, PassRefPtr<InspectorObject> message)
70 {
71 Ref<${dispatcherName}> protect(*this);
72
73 typedef void (${dispatcherName}::*CallHandler)(long callId, const Inspector::InspectorObject& message);
74 typedef HashMap<String, CallHandler> DispatchMap;
75 DEPRECATED_DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ());
76 if (dispatchMap.isEmpty()) {
77 static const struct MethodTable {
78 const char* name;
79 CallHandler handler;
80 } commands[] = {
81 ${dispatcherCommands}
82 };
83 size_t length = WTF_ARRAY_LENGTH(commands);
84 for (size_t i = 0; i < length; ++i)
85 dispatchMap.add(commands[i].name, commands[i].handler);
86 }
87
88 HashMap<String, CallHandler>::iterator it = dispatchMap.find(method);
89 if (it == dispatchMap.end()) {
90 m_backendDispatcher->reportProtocolError(&callId, InspectorBackendDispatcher::MethodNotFound, String("'") + "${domainName}" + '.' + method + "' was not found");
91 return;
92 }
93
94 ((*this).*it->value)(callId, *message.get());
95 }
96 """)
97
98 backend_method = (
99 """void ${dispatcherName}::${methodName}(long callId, const InspectorObject&${requestMessageObject})
100 {
101 ${methodInParametersHandling}${methodDispatchHandling}${methodOutParametersHandling}${methodEndingHandling}
102 }
103 """)
104
105 frontend_method = ("""void Inspector${domainName}FrontendDispatcher::${eventName}(${parameters})
106 {
107 RefPtr<InspectorObject> jsonMessage = InspectorObject::create();
108 jsonMessage->setString(ASCIILiteral("method"), ASCIILiteral("${domainName}.${eventName}"));
109 ${code}
110 m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage->toJSONString());
111 }
112 """)
113
114 callback_method = (
115 """${handlerName}::${callbackName}::${callbackName}(PassRefPtr<InspectorBackendDispatcher> backendDispatcher, int id) : Inspector::InspectorBackendDispatcher::CallbackBase(backendDispatcher, id) { }
116
117 void ${handlerName}::${callbackName}::sendSuccess(${parameters})
118 {
119 RefPtr<InspectorObject> jsonMessage = InspectorObject::create();
120 ${code} sendIfActive(jsonMessage, ErrorString());
121 }
122 """)
123
124 frontend_h = (
125 """#ifndef Inspector${outputFileNamePrefix}FrontendDispatchers_h
126 #define Inspector${outputFileNamePrefix}FrontendDispatchers_h
127
128 #include "Inspector${outputFileNamePrefix}TypeBuilders.h"
129 #include <inspector/InspectorFrontendChannel.h>
130 #include <inspector/InspectorValues.h>
131 #include <wtf/PassRefPtr.h>
132 #include <wtf/text/WTFString.h>
133
134 namespace Inspector {
135
136 #if ENABLE(INSPECTOR)
137
138 ${domainClassList}
139
140 #endif // ENABLE(INSPECTOR)
141
142 } // namespace Inspector
143
144 #endif // !defined(Inspector${outputFileNamePrefix}FrontendDispatchers_h)
145 """)
146
147 backend_h = (
148 """#ifndef Inspector${outputFileNamePrefix}BackendDispatchers_h
149 #define Inspector${outputFileNamePrefix}BackendDispatchers_h
150
151 #if ENABLE(INSPECTOR)
152
153 #include "Inspector${outputFileNamePrefix}TypeBuilders.h"
154 #include <inspector/InspectorBackendDispatcher.h>
155 #include <wtf/PassRefPtr.h>
156 #include <wtf/text/WTFString.h>
157
158 namespace Inspector {
159
160 typedef String ErrorString;
161
162 ${handlerInterfaces}
163
164 ${dispatcherInterfaces}
165 } // namespace Inspector
166
167 #endif // ENABLE(INSPECTOR)
168
169 #endif // !defined(Inspector${outputFileNamePrefix}BackendDispatchers_h)
170 """)
171
172 backend_cpp = (
173 """
174 #include "config.h"
175
176 #if ENABLE(INSPECTOR)
177
178 #include "Inspector${outputFileNamePrefix}BackendDispatchers.h"
179
180 #include <inspector/InspectorFrontendChannel.h>
181 #include <inspector/InspectorValues.h>
182 #include <wtf/text/CString.h>
183 #include <wtf/text/WTFString.h>
184
185 namespace Inspector {
186
187 ${handlerImplementations}
188
189 ${methods}
190 } // namespace Inspector
191
192 #endif // ENABLE(INSPECTOR)
193 """)
194
195 frontend_cpp = (
196 """
197
198 #include "config.h"
199
200 #if ENABLE(INSPECTOR)
201
202 #include "Inspector${outputFileNamePrefix}FrontendDispatchers.h"
203
204 #include <wtf/text/CString.h>
205 #include <wtf/text/WTFString.h>
206
207 namespace Inspector {
208
209 ${methods}
210
211 } // namespace Inspector
212
213 #endif // ENABLE(INSPECTOR)
214 """)
215
216 typebuilder_h = (
217 """
218 #ifndef Inspector${outputFileNamePrefix}TypeBuilders_h
219 #define Inspector${outputFileNamePrefix}TypeBuilders_h
220
221 #if ENABLE(INSPECTOR)
222
223 #include <inspector/InspectorTypeBuilder.h>
224 ${typeBuilderDependencies}
225 #include <wtf/Assertions.h>
226 #include <wtf/PassRefPtr.h>
227
228 namespace Inspector {
229
230 namespace TypeBuilder {
231
232 ${forwards}
233
234 ${exportMacro} String get${outputFileNamePrefix}EnumConstantValue(int code);
235
236 ${typeBuilders}
237 } // namespace TypeBuilder
238
239 } // namespace Inspector
240
241 #endif // ENABLE(INSPECTOR)
242
243 #endif // !defined(Inspector${outputFileNamePrefix}TypeBuilders_h)
244
245 """)
246
247 typebuilder_cpp = (
248 """
249
250 #include "config.h"
251 #include "Inspector${outputFileNamePrefix}TypeBuilders.h"
252
253 #if ENABLE(INSPECTOR)
254
255 #include <wtf/text/CString.h>
256
257 namespace Inspector {
258
259 namespace TypeBuilder {
260
261 static const char* const enum_constant_values[] = {
262 ${enumConstantValues}};
263
264 String get${outputFileNamePrefix}EnumConstantValue(int code) {
265 return enum_constant_values[code];
266 }
267
268 } // namespace TypeBuilder
269
270 ${implCode}
271
272 #if ${validatorIfdefName}
273
274 ${validatorCode}
275
276 #endif // ${validatorIfdefName}
277
278 } // namespace Inspector
279
280 #endif // ENABLE(INSPECTOR)
281 """)
282
283 backend_js = (
284 """
285
286 ${domainInitializers}
287 """)
288
289 param_container_access_code = """
290 RefPtr<InspectorObject> paramsContainer = message.getObject("params");
291 InspectorObject* paramsContainerPtr = paramsContainer.get();
292 InspectorArray* protocolErrorsPtr = protocolErrors.get();
293 """
294
295 class_binding_builder_part_1 = (
296 """ AllFieldsSet = %s
297 };
298
299 template<int STATE>
300 class Builder {
301 private:
302 RefPtr<Inspector::InspectorObject> m_result;
303
304 template<int STEP> Builder<STATE | STEP>& castState()
305 {
306 return *reinterpret_cast<Builder<STATE | STEP>*>(this);
307 }
308
309 Builder(PassRefPtr</*%s*/Inspector::InspectorObject> ptr)
310 {
311 COMPILE_ASSERT(STATE == NoFieldsSet, builder_created_in_non_init_state);
312 m_result = ptr;
313 }
314 friend class %s;
315 public:
316 """)
317
318 class_binding_builder_part_2 = ("""
319 Builder<STATE | %s>& set%s(%s value)
320 {
321 COMPILE_ASSERT(!(STATE & %s), property_%s_already_set);
322 m_result->set%s(ASCIILiteral("%s"), %s);
323 return castState<%s>();
324 }
325 """)
326
327 class_binding_builder_part_3 = ("""
328 operator RefPtr<%s>& ()
329 {
330 COMPILE_ASSERT(STATE == AllFieldsSet, result_is_not_ready);
331 COMPILE_ASSERT(sizeof(%s) == sizeof(Inspector::InspectorObject), cannot_cast);
332 return *reinterpret_cast<RefPtr<%s>*>(&m_result);
333 }
334
335 PassRefPtr<%s> release()
336 {
337 return RefPtr<%s>(*this).release();
338 }
339 };
340
341 """)
342
343 class_binding_builder_part_4 = (
344 """ static Builder<NoFieldsSet> create()
345 {
346 return Builder<NoFieldsSet>(Inspector::InspectorObject::create());
347 }
348 """)