1 // Copyright (C) 2019 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef HEADER_CHECKER_REPR_PROTOBUF_IR_DIFF_DUMPER_H_
16 #define HEADER_CHECKER_REPR_PROTOBUF_IR_DIFF_DUMPER_H_
17 
18 #include "repr/ir_diff_dumper.h"
19 #include "repr/ir_diff_representation.h"
20 #include "repr/ir_representation.h"
21 #include "repr/protobuf/abi_diff.h"
22 
23 #include <string>
24 
25 
26 namespace header_checker {
27 namespace repr {
28 
29 
30 class ProtobufIRDiffDumper : public IRDiffDumper {
31  public:
ProtobufIRDiffDumper(const std::string & dump_path)32   ProtobufIRDiffDumper(const std::string &dump_path)
33       : IRDiffDumper(dump_path),
34         diff_tu_(new abi_diff::TranslationUnitDiff()) {}
35 
~ProtobufIRDiffDumper()36   ~ProtobufIRDiffDumper() override {}
37 
38   bool AddDiffMessageIR(const DiffMessageIR *, const std::string &type_stack,
39                         DiffKind diff_kind) override;
40 
41   bool AddLinkableMessageIR(const LinkableMessageIR *,
42                             DiffKind diff_kind) override;
43 
44   bool AddElfSymbolMessageIR(const ElfSymbolIR *, DiffKind diff_kind) override;
45 
46   void AddLibNameIR(const std::string &name) override;
47 
48   void AddArchIR(const std::string &arch) override;
49 
50   void AddCompatibilityStatusIR(CompatibilityStatusIR status) override;
51 
52   bool Dump() override;
53 
54   CompatibilityStatusIR GetCompatibilityStatusIR() override;
55 
56 
57  private:
58   bool AddRecordTypeDiffIR(const RecordTypeDiffIR *,
59                            const std::string &type_stack, DiffKind diff_kind);
60 
61   bool AddEnumTypeDiffIR(const EnumTypeDiffIR *,
62                          const std::string &type_stack, DiffKind diff_kind);
63 
64   bool AddFunctionDiffIR(const FunctionDiffIR *,
65                          const std::string &type_stack, DiffKind diff_kind);
66 
67   bool AddGlobalVarDiffIR(const GlobalVarDiffIR *,
68                           const std::string &type_stack, DiffKind diff_kind);
69 
70 
71   bool AddLoneRecordTypeDiffIR(const RecordTypeIR *, DiffKind diff_kind);
72 
73   bool AddLoneEnumTypeDiffIR(const EnumTypeIR *, DiffKind diff_kind);
74 
75   bool AddLoneFunctionDiffIR(const FunctionIR *, DiffKind diff_kind);
76 
77   bool AddLoneGlobalVarDiffIR(const GlobalVarIR *, DiffKind diff_kind);
78 
79 
80   bool AddElfObjectIR(const ElfObjectIR *elf_object_ir, DiffKind diff_kind);
81 
82   bool AddElfFunctionIR(const ElfFunctionIR *elf_function_ir,
83                         DiffKind diff_kind);
84 
85 
86  protected:
87   std::unique_ptr<abi_diff::TranslationUnitDiff> diff_tu_;
88 };
89 
90 
91 }  // namespace repr
92 }  // namespace header_checker
93 
94 
95 #endif  // HEADER_CHECKER_REPR_PROTOBUF_PROTOBUF_IR_DIFF_DUMPER_H_
96