]> git.saurik.com Git - apple/javascriptcore.git/blob - replay/scripts/CodeGeneratorReplayInputsTemplates.py
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / replay / scripts / CodeGeneratorReplayInputsTemplates.py
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 ${inputTypeTraitDeclarations}
92
93 ${forEachMacro}
94
95 #endif // ${guardCondition}
96
97 #endif // ${filename}_h
98 """)
99
100 InputTraitsDeclaration = (
101 """template<> ${structOrClass} InputTraits<${qualifiedInputName}> {
102 static InputQueue queue() { return InputQueue::${queueType}; }
103 static const String& type();
104
105 static void encode(JSC::EncodedValue&, const ${qualifiedInputName}&);
106 static bool decode(JSC::EncodedValue&, std::unique_ptr<${qualifiedInputName}>&);
107 };""")
108
109 InputTypeTraitsDeclaration = (
110 """SPECIALIZE_TYPE_TRAITS_BEGIN(${qualifiedInputName})
111 static bool isType(const NondeterministicInputBase& input) { return input.type() == InputTraits<${qualifiedInputName}>::type(); }
112 SPECIALIZE_TYPE_TRAITS_END()""")
113
114 EnumTraitDeclaration = (
115 """template<> ${structOrClass} EncodingTraits<${encodingTypeArgument}> {
116 typedef ${enumType} DecodedType;
117
118 static EncodedValue encodeValue(const ${enumType}& value);
119 static bool decodeValue(EncodedValue&, ${enumType}& value);
120 };""")
121
122 EnumClassTraitDeclaration = (
123 """template<> ${structOrClass} EncodingTraits<${encodingTypeArgument}> {
124 typedef ${enumType} DecodedType;
125
126 static EncodedValue encodeValue(const ${enumType}& value);
127 static bool decodeValue(EncodedValue&, ${enumType}& value);
128 };""")
129
130 InputClassDeclaration = (
131 """class ${inputName} : public ${baseClass} {
132 public:
133 ${inputConstructor}
134 ${inputDestructor}
135 ${extraDeclarations}
136 ${memberGetters}
137 ${memberDeclarations}
138 };""")
139
140 ImplementationSkeleton = (
141 """${licenseBlock}
142
143 #include "config.h"
144 #include "${filename}.h"
145
146 #if ${guardCondition}
147 ${includes}
148
149 namespace ${inputsNamespace} {
150 ${inputClassImplementations}
151 } // namespace ${inputsNamespace}
152
153 namespace ${traitsNamespace} {
154 ${inputTraitImplementations}
155 ${enumTraitImplementations}
156 } // namespace ${traitsNamespace}
157
158 #endif // ${guardCondition}
159 """)
160
161 InputTraitsImplementation = (
162 """const String& InputTraits<${qualifiedInputName}>::type()
163 {
164 static NeverDestroyed<const String> type(ASCIILiteral(${inputNameStringLiteral}));
165 return type;
166 }
167
168 void InputTraits<${qualifiedInputName}>::encode(EncodedValue& encodedValue, const ${qualifiedInputName}& input)
169 {
170 ${encodeSteps}
171 }
172
173 bool InputTraits<${qualifiedInputName}>::decode(EncodedValue& encodedValue, std::unique_ptr<${qualifiedInputName}>& input)
174 {
175 ${decodeSteps}
176 input = std::make_unique<${qualifiedInputName}>(${constructorArguments});
177 return true;
178 }""")
179
180 EnumClassTraitImplementation = (
181 """EncodedValue EncodingTraits<${encodingTypeArgument}>::encodeValue(const ${enumType}& enumValue)
182 {
183 switch (enumValue) {
184 ${encodeCases}
185 default: ASSERT_NOT_REACHED(); return EncodedValue::createString("Error!");
186 }
187 }
188
189 bool EncodingTraits<${encodingTypeArgument}>::decodeValue(EncodedValue& encodedValue, ${enumType}& enumValue)
190 {
191 String enumString = encodedValue.convertTo<String>();
192 ${decodeCases}
193 return false;
194 }""")
195
196 EnumClassEncodeCase = (
197 """ case ${qualifiedEnumValue}: return EncodedValue::createString("${enumStringValue}");""")
198
199 EnumClassDecodeCase = (
200 """ if (enumString == "${enumStringValue}") {
201 enumValue = ${qualifiedEnumValue};
202 return true;
203 }""")
204
205 EnumTraitImplementation = (
206 """EncodedValue EncodingTraits<${encodingTypeArgument}>::encodeValue(const ${enumType}& enumValue)
207 {
208 EncodedValue encodedValue = EncodedValue::createArray();
209 ${encodeCases}
210 return encodedValue;
211 }
212
213 bool EncodingTraits<${encodingTypeArgument}>::decodeValue(EncodedValue& encodedValue, ${enumType}& enumValue)
214 {
215 Vector<String> enumStrings;
216 if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings))
217 return false;
218
219 for (const String& enumString : enumStrings) {
220 ${decodeCases}
221 }
222
223 return true;
224 }""")
225
226 EnumEncodeCase = (
227 """ if (enumValue & ${qualifiedEnumValue}) {
228 encodedValue.append<String>(ASCIILiteral("${enumStringValue}"));
229 if (enumValue == ${qualifiedEnumValue})
230 return encodedValue;
231 }""")
232
233 EnumDecodeCase = (
234 """ ${branchKeyword} (enumString == "${enumStringValue}")
235 enumValue = static_cast<${qualifiedEnumName}>(enumValue | ${qualifiedEnumValue});""")
236
237 InputClassImplementation = (
238 """${inputName}::${inputName}(${constructorFormalsList})
239 ${initializerList}
240 {
241 }
242
243 ${inputName}::~${inputName}()
244 {
245 }""")