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