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}
91 ${inputTypeTraitDeclarations}
95 #endif // ${guardCondition}
97 #endif // ${filename}_h
100 InputTraitsDeclaration
= (
101 """template<> ${structOrClass} InputTraits<${qualifiedInputName}> {
102 static InputQueue queue() { return InputQueue::${queueType}; }
103 static const String& type();
105 static void encode(JSC::EncodedValue&, const ${qualifiedInputName}&);
106 static bool decode(JSC::EncodedValue&, std::unique_ptr<${qualifiedInputName}>&);
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()""")
114 EnumTraitDeclaration
= (
115 """template<> ${structOrClass} EncodingTraits<${encodingTypeArgument}> {
116 typedef ${enumType} DecodedType;
118 static EncodedValue encodeValue(const ${enumType}& value);
119 static bool decodeValue(EncodedValue&, ${enumType}& value);
122 EnumClassTraitDeclaration
= (
123 """template<> ${structOrClass} EncodingTraits<${encodingTypeArgument}> {
124 typedef ${enumType} DecodedType;
126 static EncodedValue encodeValue(const ${enumType}& value);
127 static bool decodeValue(EncodedValue&, ${enumType}& value);
130 InputClassDeclaration
= (
131 """class ${inputName} : public ${baseClass} {
137 ${memberDeclarations}
140 ImplementationSkeleton
= (
144 #include "${filename}.h"
146 #if ${guardCondition}
149 namespace ${inputsNamespace} {
150 ${inputClassImplementations}
151 } // namespace ${inputsNamespace}
153 namespace ${traitsNamespace} {
154 ${inputTraitImplementations}
155 ${enumTraitImplementations}
156 } // namespace ${traitsNamespace}
158 #endif // ${guardCondition}
161 InputTraitsImplementation
= (
162 """const String& InputTraits<${qualifiedInputName}>::type()
164 static NeverDestroyed<const String> type(ASCIILiteral(${inputNameStringLiteral}));
168 void InputTraits<${qualifiedInputName}>::encode(EncodedValue& encodedValue, const ${qualifiedInputName}& input)
173 bool InputTraits<${qualifiedInputName}>::decode(EncodedValue& encodedValue, std::unique_ptr<${qualifiedInputName}>& input)
176 input = std::make_unique<${qualifiedInputName}>(${constructorArguments});
180 EnumClassTraitImplementation
= (
181 """EncodedValue EncodingTraits<${encodingTypeArgument}>::encodeValue(const ${enumType}& enumValue)
185 default: ASSERT_NOT_REACHED(); return EncodedValue::createString("Error!");
189 bool EncodingTraits<${encodingTypeArgument}>::decodeValue(EncodedValue& encodedValue, ${enumType}& enumValue)
191 String enumString = encodedValue.convertTo<String>();
196 EnumClassEncodeCase
= (
197 """ case ${qualifiedEnumValue}: return EncodedValue::createString("${enumStringValue}");""")
199 EnumClassDecodeCase
= (
200 """ if (enumString == "${enumStringValue}") {
201 enumValue = ${qualifiedEnumValue};
205 EnumTraitImplementation
= (
206 """EncodedValue EncodingTraits<${encodingTypeArgument}>::encodeValue(const ${enumType}& enumValue)
208 EncodedValue encodedValue = EncodedValue::createArray();
213 bool EncodingTraits<${encodingTypeArgument}>::decodeValue(EncodedValue& encodedValue, ${enumType}& enumValue)
215 Vector<String> enumStrings;
216 if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings))
219 for (const String& enumString : enumStrings) {
227 """ if (enumValue & ${qualifiedEnumValue}) {
228 encodedValue.append<String>(ASCIILiteral("${enumStringValue}"));
229 if (enumValue == ${qualifiedEnumValue})
234 """ ${branchKeyword} (enumString == "${enumStringValue}")
235 enumValue = static_cast<${qualifiedEnumName}>(enumValue | ${qualifiedEnumValue});""")
237 InputClassImplementation
= (
238 """${inputName}::${inputName}(${constructorFormalsList})
243 ${inputName}::~${inputName}()