xref: /aosp_15_r20/development/vndk/tools/header-checker/src/repr/protobuf/ir_reader.h (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
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_READER_H_
16 #define HEADER_CHECKER_REPR_PROTOBUF_IR_READER_H_
17 
18 #include "repr/ir_reader.h"
19 #include "repr/protobuf/abi_diff.h"
20 #include "repr/protobuf/abi_dump.h"
21 
22 #include <string>
23 #include <vector>
24 
25 #include <google/protobuf/text_format.h>
26 #include <google/protobuf/io/zero_copy_stream_impl.h>
27 
28 
29 namespace header_checker {
30 namespace repr {
31 
32 
33 class ProtobufIRReader : public IRReader {
34  private:
35   template <typename T>
36   using RepeatedPtrField = google::protobuf::RepeatedPtrField<T>;
37 
38 
39  public:
ProtobufIRReader(std::unique_ptr<ModuleIR> module_ir)40   ProtobufIRReader(std::unique_ptr<ModuleIR> module_ir)
41       : IRReader(std::move(module_ir)) {}
42 
43  private:
44   bool ReadDumpImpl(const std::string &dump_file) override;
45 
46   void ReadFunctions(const abi_dump::TranslationUnit &tu);
47 
48   void ReadGlobalVariables(const abi_dump::TranslationUnit &tu);
49 
50   void ReadEnumTypes(const abi_dump::TranslationUnit &tu);
51 
52   void ReadRecordTypes(const abi_dump::TranslationUnit &tu);
53 
54   void ReadFunctionTypes(const abi_dump::TranslationUnit &tu);
55 
56   void ReadPointerTypes(const abi_dump::TranslationUnit &tu);
57 
58   void ReadBuiltinTypes(const abi_dump::TranslationUnit &tu);
59 
60   void ReadQualifiedTypes(const abi_dump::TranslationUnit &tu);
61 
62   void ReadArrayTypes(const abi_dump::TranslationUnit &tu);
63 
64   void ReadLvalueReferenceTypes(const abi_dump::TranslationUnit &tu);
65 
66   void ReadRvalueReferenceTypes(const abi_dump::TranslationUnit &tu);
67 
68   void ReadElfFunctions(const abi_dump::TranslationUnit &tu);
69 
70   void ReadElfObjects(const abi_dump::TranslationUnit &tu);
71 
72   void ReadTypeInfo(const abi_dump::BasicNamedAndTypedDecl &type_info,
73                     TypeIR *typep);
74 
75   FunctionIR FunctionProtobufToIR(const abi_dump::FunctionDecl &);
76 
77   FunctionTypeIR FunctionTypeProtobufToIR(
78       const abi_dump::FunctionType &function_type_protobuf);
79 
80   RecordTypeIR RecordTypeProtobufToIR(
81       const abi_dump::RecordType &record_type_protobuf);
82 
83   std::vector<RecordFieldIR> RecordFieldsProtobufToIR(
84       const RepeatedPtrField<abi_dump::RecordFieldDecl> &rfp);
85 
86   std::vector<CXXBaseSpecifierIR> RecordCXXBaseSpecifiersProtobufToIR(
87       const RepeatedPtrField<abi_dump::CXXBaseSpecifier> &rbs);
88 
89   std::vector<EnumFieldIR> EnumFieldsProtobufToIR(
90       const RepeatedPtrField<abi_dump::EnumFieldDecl> &efp);
91 
92   EnumTypeIR EnumTypeProtobufToIR(
93       const abi_dump::EnumType &enum_type_protobuf);
94 
95   VTableLayoutIR VTableLayoutProtobufToIR(
96       const abi_dump::VTableLayout &vtable_layout_protobuf);
97 
98   TemplateInfoIR TemplateInfoProtobufToIR(
99       const abi_dump::TemplateInfo &template_info_protobuf);
100 };
101 
102 
103 }  // namespace repr
104 }  // namespace header_checker
105 
106 
107 #endif  // HEADER_CHECKER_REPR_PROTOBUF_IR_READER_H_
108