blob: e8acdc306ab807b22ddff146b5f0dacdf60f30bd [file] [log] [blame]
Ajay Panicker4d6b7602019-02-06 14:02:36 -08001/*
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 "enum_def.h"
23#include "field_list.h"
24#include "fields/packet_field.h"
Myles Watsonea6331b2019-07-09 14:09:42 -070025#include "parent_def.h"
Ajay Panicker4d6b7602019-02-06 14:02:36 -080026
Myles Watsonea6331b2019-07-09 14:09:42 -070027class PacketDef : public ParentDef {
Ajay Panicker4d6b7602019-02-06 14:02:36 -080028 public:
29 PacketDef(std::string name, FieldList fields);
30 PacketDef(std::string name, FieldList fields, PacketDef* parent);
31
Myles Watsonea6331b2019-07-09 14:09:42 -070032 PacketField* GetNewField(const std::string& name, ParseLocation loc) const;
Ajay Panicker4d6b7602019-02-06 14:02:36 -080033
34 void GenParserDefinition(std::ostream& s) const;
35
Jack He9be1dcd2019-11-18 19:20:41 -080036 void GenParserDefinitionPybind11(std::ostream& s) const;
37
Ajay Panicker4d6b7602019-02-06 14:02:36 -080038 void GenParserFieldGetter(std::ostream& s, const PacketField* field) const;
39
Ajay Panicker4d6b7602019-02-06 14:02:36 -080040 void GenValidator(std::ostream& s) const;
41
Myles Watsonea6331b2019-07-09 14:09:42 -070042 TypeDef::Type GetDefinitionType() const;
Ajay Panicker4d6b7602019-02-06 14:02:36 -080043
Myles Watsonea6331b2019-07-09 14:09:42 -070044 void GenBuilderDefinition(std::ostream& s) const;
Ajay Panicker4d6b7602019-02-06 14:02:36 -080045
Jack He9be1dcd2019-11-18 19:20:41 -080046 void GenBuilderDefinitionPybind11(std::ostream& s) const;
47
Myles Watsonfc57a962019-08-22 16:11:01 -070048 void GenTestDefine(std::ostream& s) const;
49
Jack He8af1b622019-10-18 16:11:17 -070050 void GenFuzzTestDefine(std::ostream& s) const;
51
Ajay Panicker4d6b7602019-02-06 14:02:36 -080052 FieldList GetParametersToValidate() const;
53
54 void GenBuilderCreate(std::ostream& s) const;
55
Jack He9be1dcd2019-11-18 19:20:41 -080056 void GenBuilderCreatePybind11(std::ostream& s) const;
57
Ajay Panicker4d6b7602019-02-06 14:02:36 -080058 void GenBuilderParameterChecker(std::ostream& s) const;
59
60 void GenBuilderConstructor(std::ostream& s) const;
Ajay Panicker4d6b7602019-02-06 14:02:36 -080061};