Lines Matching refs:s
38 void StructDef::GenSpecialize(std::ostream& s) const { in GenSpecialize()
42 s << "static " << name_ << "* Specialize(" << parent_->name_ << "* parent) {"; in GenSpecialize()
43 s << "ASSERT(" << name_ << "::IsInstance(*parent));"; in GenSpecialize()
44 s << "return static_cast<" << name_ << "*>(parent);"; in GenSpecialize()
45 s << "}"; in GenSpecialize()
48 void StructDef::GenToString(std::ostream& s) const { in GenToString()
49 s << "std::string ToString() {"; in GenToString()
50 s << "std::stringstream ss;"; in GenToString()
51 s << "ss << std::hex << std::showbase << \"" << name_ << " { \";"; in GenToString()
54 s << "ss"; in GenToString()
63 s << (firstfield ? " << \"" : " << \", ") << field->GetName() << " = \" << "; in GenToString()
65 field->GenStringRepresentation(s, field->GetName() + "_"); in GenToString()
71 s << ";"; in GenToString()
74 s << "ss << \" }\";"; in GenToString()
75 s << "return ss.str();"; in GenToString()
76 s << "}\n"; in GenToString()
79 void StructDef::GenParse(std::ostream& s) const { in GenParse()
83 s << "static std::optional<" << iterator << ">"; in GenParse()
85 s << "static " << iterator; in GenParse()
88 s << " Parse(" << name_ << "* to_fill, " << iterator << " struct_begin_it "; in GenParse()
91 s << ", bool fill_parent = true) {"; in GenParse()
93 s << ") {"; in GenParse()
95 s << "auto to_bound = struct_begin_it;"; in GenParse()
98 s << "if (fill_parent) {"; in GenParse()
101 …s << "auto parent_optional_it = " << parent_->name_ << "::Parse(to_fill, to_bound" << parent_param… in GenParse()
103 s << "if (!parent_optional_it) { return {}; }"; in GenParse()
105 s << "ASSERT(parent_optional_it);"; in GenParse()
108 s << parent_->name_ << "::Parse(to_fill, to_bound" << parent_param << ");"; in GenParse()
110 s << "}"; in GenParse()
114 s << "size_t end_index = struct_begin_it.NumBytesRemaining();"; in GenParse()
115 s << "if (end_index < " << GetSize().bytes() << ")"; in GenParse()
116 s << "{ return struct_begin_it.Subrange(0,0);}"; in GenParse()
128 s << "{"; in GenParse()
129 s << "if (to_bound.NumBytesRemaining() < " << total_bits.bytes() << ")"; in GenParse()
131 s << "{ return to_bound.Subrange(to_bound.NumBytesRemaining(),0);}"; in GenParse()
133 s << "{ return {};}"; in GenParse()
135 s << "}"; in GenParse()
141 s << "{"; in GenParse()
143 … field->GenBounds(s, GetStructOffsetForField(field->GetName()), Size(), field->GetStructSize()); in GenParse()
144 s << "auto " << field->GetName() << "_ptr = &to_fill->" << field->GetName() << "_;"; in GenParse()
145 field->GenExtractor(s, num_leading_bits, true); in GenParse()
146 s << "}"; in GenParse()
149 s << "{"; in GenParse()
151 … field->GenBounds(s, GetStructOffsetForField(field->GetName()), Size(), field->GetStructSize()); in GenParse()
152 s << "auto " << field->GetName() << "_ptr = &to_fill->" << field->GetName() << "_extracted_;"; in GenParse()
153 field->GenExtractor(s, num_leading_bits, true); in GenParse()
154 s << "}"; in GenParse()
157 s << "return struct_begin_it + to_fill->size();"; in GenParse()
158 s << "}"; in GenParse()
161 void StructDef::GenParseFunctionPrototype(std::ostream& s) const { in GenParseFunctionPrototype()
162 s << "std::unique_ptr<" << name_ << "> Parse" << name_ << "("; in GenParseFunctionPrototype()
164 s << "Iterator<kLittleEndian>"; in GenParseFunctionPrototype()
166 s << "Iterator<!kLittleEndian>"; in GenParseFunctionPrototype()
168 s << "it);"; in GenParseFunctionPrototype()
171 void StructDef::GenDefinition(std::ostream& s) const { in GenDefinition()
172 s << "class " << name_; in GenDefinition()
174 s << " : public " << parent_->name_; in GenDefinition()
177 s << " : public PacketStruct<kLittleEndian>"; in GenDefinition()
179 s << " : public PacketStruct<!kLittleEndian>"; in GenDefinition()
182 s << " {"; in GenDefinition()
183 s << " public:"; in GenDefinition()
185 GenConstructor(s); in GenDefinition()
187 s << " public:\n"; in GenDefinition()
188 s << " virtual ~" << name_ << "() override = default;\n"; in GenDefinition()
190 GenSerialize(s); in GenDefinition()
191 s << "\n"; in GenDefinition()
193 GenParse(s); in GenDefinition()
194 s << "\n"; in GenDefinition()
196 GenSize(s); in GenDefinition()
197 s << "\n"; in GenDefinition()
199 GenInstanceOf(s); in GenDefinition()
200 s << "\n"; in GenDefinition()
202 GenSpecialize(s); in GenDefinition()
203 s << "\n"; in GenDefinition()
205 GenToString(s); in GenDefinition()
206 s << "\n"; in GenDefinition()
208 GenMembers(s); in GenDefinition()
211 s << "\n private:\n"; in GenDefinition()
212 s << " mutable " << field->GetDataType() << " " << field->GetName() << "_extracted_{0};"; in GenDefinition()
215 s << "};\n"; in GenDefinition()
218 GenParseFunctionPrototype(s); in GenDefinition()
220 s << "\n"; in GenDefinition()
223 void StructDef::GenDefinitionPybind11(std::ostream& s) const { in GenDefinitionPybind11()
224 s << "py::class_<" << name_; in GenDefinitionPybind11()
226 s << ", " << parent_->name_; in GenDefinitionPybind11()
229 s << ", PacketStruct<kLittleEndian>"; in GenDefinitionPybind11()
231 s << ", PacketStruct<!kLittleEndian>"; in GenDefinitionPybind11()
234 s << ", std::shared_ptr<" << name_ << ">"; in GenDefinitionPybind11()
235 s << ">(m, \"" << name_ << "\")"; in GenDefinitionPybind11()
236 s << ".def(py::init<>())"; in GenDefinitionPybind11()
237 s << ".def(\"Serialize\", [](" << GetTypeName() << "& obj){"; in GenDefinitionPybind11()
238 s << "std::vector<uint8_t> bytes;"; in GenDefinitionPybind11()
239 s << "BitInserter bi(bytes);"; in GenDefinitionPybind11()
240 s << "obj.Serialize(bi);"; in GenDefinitionPybind11()
241 s << "return bytes;})"; in GenDefinitionPybind11()
242 s << ".def(\"Parse\", &" << name_ << "::Parse)"; in GenDefinitionPybind11()
243 s << ".def(\"size\", &" << name_ << "::size)"; in GenDefinitionPybind11()
248 …s << ".def_readwrite(\"" << field->GetName() << "\", &" << name_ << "::" << field->GetName() << "_… in GenDefinitionPybind11()
250 s << ";\n"; in GenDefinitionPybind11()
253 void StructDef::GenConstructor(std::ostream& s) const { in GenConstructor()
255 s << name_ << "(const " << parent_->name_ << "& parent) : " << parent_->name_ << "(parent) {}"; in GenConstructor()
256 s << name_ << "() : " << parent_->name_ << "() {"; in GenConstructor()
258 s << name_ << "() {"; in GenConstructor()
274 s << parent_->name_ << "::" << field->GetName() << "_ = "; in GenConstructor()
276 s << std::get<int64_t>(constraint->second) << ";"; in GenConstructor()
278 s << std::get<std::string>(constraint->second) << ";"; in GenConstructor()
286 s << "}\n"; in GenConstructor()