]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | #!/usr/bin/env python |
2 | # Copyright (c) 2011 Google Inc. All rights reserved. | |
3 | # Copyright (c) 2012 Intel Corporation. All rights reserved. | |
4 | # Copyright (c) 2013, 2014 Apple Inc. All rights reserved. | |
5 | # | |
6 | # Redistribution and use in source and binary forms, with or without | |
7 | # modification, are permitted provided that the following conditions are | |
8 | # met: | |
9 | # | |
10 | # * Redistributions of source code must retain the above copyright | |
11 | # notice, this list of conditions and the following disclaimer. | |
12 | # * Redistributions in binary form must reproduce the above | |
13 | # copyright notice, this list of conditions and the following disclaimer | |
14 | # in the documentation and/or other materials provided with the | |
15 | # distribution. | |
16 | # * Neither the name of Google Inc. nor the names of its | |
17 | # contributors may be used to endorse or promote products derived from | |
18 | # this software without specific prior written permission. | |
19 | # | |
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 | ||
32 | ||
33 | # Generator templates, which can be filled with string.Template. | |
34 | # Following are classes that fill the templates from the typechecked model. | |
35 | ||
36 | class Templates: | |
37 | CopyrightBlock = ( | |
38 | """/* | |
39 | * Copyright (C) 2014 Apple Inc. All rights reserved. | |
40 | * | |
41 | * Redistribution and use in source and binary forms, with or without | |
42 | * modification, are permitted provided that the following conditions | |
43 | * are met: | |
44 | * | |
45 | * 1. Redistributions of source code must retain the above copyright | |
46 | * notice, this list of conditions and the following disclaimer. | |
47 | * 2. Redistributions in binary form must reproduce the above copyright | |
48 | * notice, this list of conditions and the following disclaimer in the | |
49 | * documentation and/or other materials provided with the distribution. | |
50 | * | |
51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
52 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
53 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
54 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
55 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
56 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
57 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
58 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
59 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
60 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
61 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
62 | */ | |
63 | ||
64 | // DO NOT EDIT THIS FILE. It is automatically generated from ${inputFilename} | |
65 | // by the script: JavaScriptCore/replay/scripts/CodeGeneratorReplayInputs.py""") | |
66 | ||
67 | HeaderSkeleton = ( | |
68 | """${licenseBlock} | |
69 | ||
70 | #ifndef ${headerGuard} | |
71 | #define ${headerGuard} | |
72 | ||
73 | #if ${guardCondition} | |
74 | ${includes} | |
75 | ||
76 | ${typeForwardDeclarations} | |
77 | ||
78 | namespace ${inputsNamespace} { | |
79 | ${inputForwardDeclarations} | |
80 | } // namespace ${inputsNamespace} | |
81 | ||
82 | namespace ${traitsNamespace} { | |
83 | ${inputTraitDeclarations} | |
84 | ${enumTraitDeclarations} | |
85 | } // namespace ${traitsNamespace} | |
86 | ||
87 | namespace ${inputsNamespace} { | |
88 | ${inputClassDeclarations} | |
89 | } // namespace ${inputsNamespace} | |
90 | ||
91 | ${forEachMacro} | |
92 | ||
93 | #endif // ${guardCondition} | |
94 | ||
95 | #endif // ${filename}_h | |
96 | """) | |
97 | ||
98 | InputTraitsDeclaration = ( | |
99 | """template<> ${structOrClass} InputTraits<${qualifiedInputName}> { | |
100 | static InputQueue queue() { return InputQueue::${queueType}; } | |
101 | static const AtomicString& type(); | |
102 | ||
103 | static void encode(JSC::EncodedValue&, const ${qualifiedInputName}&); | |
104 | static bool decode(JSC::EncodedValue&, std::unique_ptr<${qualifiedInputName}>&); | |
105 | };""") | |
106 | ||
107 | EnumTraitDeclaration = ( | |
108 | """template<> struct EncodingTraits<${enumName}> { | |
109 | typedef ${enumName} DecodedType; | |
110 | ||
111 | static EncodedValue encodeValue(const ${enumName}& value); | |
112 | static bool decodeValue(EncodedValue&, ${enumName}& value); | |
113 | };""") | |
114 | ||
115 | EnumClassTraitDeclaration = ( | |
116 | """template<> struct EncodingTraits<${enumName}> { | |
117 | typedef ${enumName} DecodedType; | |
118 | ||
119 | static EncodedValue encodeValue(const ${enumName}& value); | |
120 | static bool decodeValue(EncodedValue&, ${enumName}& value); | |
121 | };""") | |
122 | ||
123 | InputClassDeclaration = ( | |
124 | """class ${inputName} : public ${baseClass} { | |
125 | public: | |
126 | ${inputConstructor} | |
127 | ${inputDestructor} | |
128 | ${extraDeclarations} | |
129 | ${memberGetters} | |
130 | ${memberDeclarations} | |
131 | };""") | |
132 | ||
133 | ImplementationSkeleton = ( | |
134 | """${licenseBlock} | |
135 | ||
136 | #include "config.h" | |
137 | #include "${filename}.h" | |
138 | ||
139 | #if ${guardCondition} | |
140 | ${includes} | |
141 | ||
142 | namespace ${inputsNamespace} { | |
143 | ${inputClassImplementations} | |
144 | } // namespace ${inputsNamespace} | |
145 | ||
146 | namespace ${traitsNamespace} { | |
147 | ${inputTraitImplementations} | |
148 | ${enumTraitImplementations} | |
149 | } // namespace ${traitsNamespace} | |
150 | ||
151 | #endif // ${guardCondition} | |
152 | """) | |
153 | ||
154 | InputTraitsImplementation = ( | |
155 | """const AtomicString& InputTraits<${qualifiedInputName}>::type() | |
156 | { | |
157 | $inputTypeImplementation | |
158 | } | |
159 | ||
160 | void InputTraits<${qualifiedInputName}>::encode(EncodedValue& encodedValue, const ${qualifiedInputName}& input) | |
161 | { | |
162 | ${encodeSteps} | |
163 | } | |
164 | ||
165 | bool InputTraits<${qualifiedInputName}>::decode(EncodedValue& encodedValue, std::unique_ptr<${qualifiedInputName}>& input) | |
166 | { | |
167 | ${decodeSteps} | |
168 | input = std::make_unique<${qualifiedInputName}>(${constructorArguments}); | |
169 | return true; | |
170 | }""") | |
171 | ||
172 | EnumClassTraitImplementation = ( | |
173 | """EncodedValue EncodingTraits<${enumName}>::encodeValue(const ${enumName}& enumValue) | |
174 | { | |
175 | switch (enumValue) { | |
176 | ${encodeCases} | |
177 | default: ASSERT_NOT_REACHED(); return EncodedValue::createString("Error!"); | |
178 | } | |
179 | } | |
180 | ||
181 | bool EncodingTraits<${enumName}>::decodeValue(EncodedValue& encodedValue, ${enumName}& enumValue) | |
182 | { | |
183 | String enumString = encodedValue.convertTo<String>(); | |
184 | ${decodeCases} | |
185 | return false; | |
186 | }""") | |
187 | ||
188 | EnumClassEncodeCase = ( | |
189 | """ case ${qualifiedEnumValue}: return EncodedValue::createString("${enumStringValue}");""") | |
190 | ||
191 | EnumClassDecodeCase = ( | |
192 | """ if (enumString == "${enumStringValue}") { | |
193 | enumValue = ${qualifiedEnumValue}; | |
194 | return true; | |
195 | }""") | |
196 | ||
197 | EnumTraitImplementation = ( | |
198 | """EncodedValue EncodingTraits<${enumName}>::encodeValue(const ${enumName}& enumValue) | |
199 | { | |
200 | EncodedValue encodedValue = EncodedValue::createArray(); | |
201 | ${encodeCases} | |
202 | return encodedValue; | |
203 | } | |
204 | ||
205 | bool EncodingTraits<${enumName}>::decodeValue(EncodedValue& encodedValue, ${enumName}& enumValue) | |
206 | { | |
207 | Vector<String> enumStrings; | |
208 | if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings)) | |
209 | return false; | |
210 | ||
211 | for (String enumString : enumStrings) { | |
212 | ${decodeCases} | |
213 | } | |
214 | ||
215 | return true; | |
216 | }""") | |
217 | ||
218 | EnumEncodeCase = ( | |
219 | """ if (enumValue & ${qualifiedEnumValue}) { | |
220 | encodedValue.append<String>(ASCIILiteral("${enumStringValue}")); | |
221 | if (enumValue == ${qualifiedEnumValue}) | |
222 | return encodedValue; | |
223 | }""") | |
224 | ||
225 | EnumDecodeCase = ( | |
226 | """ if (enumString == "${enumStringValue}") | |
227 | enumValue = static_cast<${qualifiedEnumName}>(enumValue | ${qualifiedEnumValue});""") | |
228 | ||
229 | InputTypeFromStaticLocal = ( | |
230 | """ static NeverDestroyed<const AtomicString> type("${inputName}", AtomicString::ConstructFromLiteral); | |
231 | return type;""") | |
232 | ||
233 | InputTypeFromThreadLocal = " return WebCore::inputTypes().${inputName};" | |
234 | ||
235 | InputClassImplementation = ( | |
236 | """${inputName}::${inputName}(${constructorFormalsList}) | |
237 | ${initializerList} | |
238 | { | |
239 | } | |
240 | ||
241 | ${inputName}::~${inputName}() | |
242 | { | |
243 | }""") |