• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <map>
20 #include <variant>
21 
22 #include "field_list.h"
23 #include "fields/packet_field.h"
24 #include "parent_def.h"
25 #include "parse_location.h"
26 #include "type_def.h"
27 
28 class StructDef : public ParentDef {
29  public:
30   StructDef(std::string name, FieldList fields);
31   StructDef(std::string name, FieldList fields, StructDef* parent);
32 
33   PacketField* GetNewField(const std::string& name, ParseLocation loc) const;
34 
35   TypeDef::Type GetDefinitionType() const;
36 
37   void GenSpecialize(std::ostream& s) const;
38 
39   void GenToString(std::ostream& s) const;
40 
41   void GenParse(std::ostream& s) const;
42 
43   void GenParseFunctionPrototype(std::ostream& s) const;
44 
45   void GenDefinition(std::ostream& s) const;
46 
47   void GenDefinitionPybind11(std::ostream& s) const;
48 
49   void GenConstructor(std::ostream& s) const;
50 
51   Size GetStructOffsetForField(std::string field_name) const;
52 
53   void GenRustDeclarations(std::ostream& s) const;
54 
55   void GenRustImpls(std::ostream& s) const;
56 
57   void GenRustFieldNameAndType(std::ostream& s, bool include_fixed) const;
58 
59   void GenRustFieldNames(std::ostream& s) const;
60 
61   void GenRustDef(std::ostream& s) const;
62 
63  private:
64   Size total_size_;
65 };
66