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.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
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
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.
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.
33 # Generator templates, which can be filled with string.Template.
34 # Following are classes that fill the templates from the typechecked model.
39 * Copyright (C) 2014 Apple Inc. All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
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.
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.
64 // DO NOT EDIT THIS FILE. It is automatically generated from ${inputFilename}
65 // by the script: JavaScriptCore/replay/scripts/CodeGeneratorReplayInputs.py""")
70 #ifndef ${headerGuard}
71 #define ${headerGuard}
76 ${typeForwardDeclarations}
78 namespace ${inputsNamespace} {
79 ${inputForwardDeclarations}
80 } // namespace ${inputsNamespace}
82 namespace ${traitsNamespace} {
83 ${inputTraitDeclarations}
84 ${enumTraitDeclarations}
85 } // namespace ${traitsNamespace}
87 namespace ${inputsNamespace} {
88 ${inputClassDeclarations}
89 } // namespace ${inputsNamespace}
93 #endif // ${guardCondition}
95 #endif // ${filename}_h
98 InputTraitsDeclaration
= (
99 """template<> ${structOrClass} InputTraits<${qualifiedInputName}> {
100 static InputQueue queue() { return InputQueue::${queueType}; }
101 static const AtomicString& type();
103 static void encode(JSC::EncodedValue&, const ${qualifiedInputName}&);
104 static bool decode(JSC::EncodedValue&, std::unique_ptr<${qualifiedInputName}>&);
107 EnumTraitDeclaration
= (
108 """template<> struct EncodingTraits<${enumName}> {
109 typedef ${enumName} DecodedType;
111 static EncodedValue encodeValue(const ${enumName}& value);
112 static bool decodeValue(EncodedValue&, ${enumName}& value);
115 EnumClassTraitDeclaration
= (
116 """template<> struct EncodingTraits<${enumName}> {
117 typedef ${enumName} DecodedType;
119 static EncodedValue encodeValue(const ${enumName}& value);
120 static bool decodeValue(EncodedValue&, ${enumName}& value);
123 InputClassDeclaration
= (
124 """class ${inputName} : public ${baseClass} {
130 ${memberDeclarations}
133 ImplementationSkeleton
= (
137 #include "${filename}.h"
139 #if ${guardCondition}
142 namespace ${inputsNamespace} {
143 ${inputClassImplementations}
144 } // namespace ${inputsNamespace}
146 namespace ${traitsNamespace} {
147 ${inputTraitImplementations}
148 ${enumTraitImplementations}
149 } // namespace ${traitsNamespace}
151 #endif // ${guardCondition}
154 InputTraitsImplementation
= (
155 """const AtomicString& InputTraits<${qualifiedInputName}>::type()
157 $inputTypeImplementation
160 void InputTraits<${qualifiedInputName}>::encode(EncodedValue& encodedValue, const ${qualifiedInputName}& input)
165 bool InputTraits<${qualifiedInputName}>::decode(EncodedValue& encodedValue, std::unique_ptr<${qualifiedInputName}>& input)
168 input = std::make_unique<${qualifiedInputName}>(${constructorArguments});
172 EnumClassTraitImplementation
= (
173 """EncodedValue EncodingTraits<${enumName}>::encodeValue(const ${enumName}& enumValue)
177 default: ASSERT_NOT_REACHED(); return EncodedValue::createString("Error!");
181 bool EncodingTraits<${enumName}>::decodeValue(EncodedValue& encodedValue, ${enumName}& enumValue)
183 String enumString = encodedValue.convertTo<String>();
188 EnumClassEncodeCase
= (
189 """ case ${qualifiedEnumValue}: return EncodedValue::createString("${enumStringValue}");""")
191 EnumClassDecodeCase
= (
192 """ if (enumString == "${enumStringValue}") {
193 enumValue = ${qualifiedEnumValue};
197 EnumTraitImplementation
= (
198 """EncodedValue EncodingTraits<${enumName}>::encodeValue(const ${enumName}& enumValue)
200 EncodedValue encodedValue = EncodedValue::createArray();
205 bool EncodingTraits<${enumName}>::decodeValue(EncodedValue& encodedValue, ${enumName}& enumValue)
207 Vector<String> enumStrings;
208 if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings))
211 for (String enumString : enumStrings) {
219 """ if (enumValue & ${qualifiedEnumValue}) {
220 encodedValue.append<String>(ASCIILiteral("${enumStringValue}"));
221 if (enumValue == ${qualifiedEnumValue})
226 """ if (enumString == "${enumStringValue}")
227 enumValue = static_cast<${qualifiedEnumName}>(enumValue | ${qualifiedEnumValue});""")
229 InputTypeFromStaticLocal
= (
230 """ static NeverDestroyed<const AtomicString> type("${inputName}", AtomicString::ConstructFromLiteral);
233 InputTypeFromThreadLocal
= " return WebCore::inputTypes().${inputName};"
235 InputClassImplementation
= (
236 """${inputName}::${inputName}(${constructorFormalsList})
241 ${inputName}::~${inputName}()