• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   bool ReadDump(const std::string &dump_file) override;
46 
47 
48  private:
49   void ReadFunctions(const abi_dump::TranslationUnit &tu);
50 
51   void ReadGlobalVariables(const abi_dump::TranslationUnit &tu);
52 
53   void ReadEnumTypes(const abi_dump::TranslationUnit &tu);
54 
55   void ReadRecordTypes(const abi_dump::TranslationUnit &tu);
56 
57   void ReadFunctionTypes(const abi_dump::TranslationUnit &tu);
58 
59   void ReadPointerTypes(const abi_dump::TranslationUnit &tu);
60 
61   void ReadBuiltinTypes(const abi_dump::TranslationUnit &tu);
62 
63   void ReadQualifiedTypes(const abi_dump::TranslationUnit &tu);
64 
65   void ReadArrayTypes(const abi_dump::TranslationUnit &tu);
66 
67   void ReadLvalueReferenceTypes(const abi_dump::TranslationUnit &tu);
68 
69   void ReadRvalueReferenceTypes(const abi_dump::TranslationUnit &tu);
70 
71   void ReadElfFunctions(const abi_dump::TranslationUnit &tu);
72 
73   void ReadElfObjects(const abi_dump::TranslationUnit &tu);
74 
75   void ReadTypeInfo(const abi_dump::BasicNamedAndTypedDecl &type_info,
76                     TypeIR *typep);
77 
78   FunctionIR FunctionProtobufToIR(const abi_dump::FunctionDecl &);
79 
80   FunctionTypeIR FunctionTypeProtobufToIR(
81       const abi_dump::FunctionType &function_type_protobuf);
82 
83   RecordTypeIR RecordTypeProtobufToIR(
84       const abi_dump::RecordType &record_type_protobuf);
85 
86   std::vector<RecordFieldIR> RecordFieldsProtobufToIR(
87       const RepeatedPtrField<abi_dump::RecordFieldDecl> &rfp);
88 
89   std::vector<CXXBaseSpecifierIR> RecordCXXBaseSpecifiersProtobufToIR(
90       const RepeatedPtrField<abi_dump::CXXBaseSpecifier> &rbs);
91 
92   std::vector<EnumFieldIR> EnumFieldsProtobufToIR(
93       const RepeatedPtrField<abi_dump::EnumFieldDecl> &efp);
94 
95   EnumTypeIR EnumTypeProtobufToIR(
96       const abi_dump::EnumType &enum_type_protobuf);
97 
98   VTableLayoutIR VTableLayoutProtobufToIR(
99       const abi_dump::VTableLayout &vtable_layout_protobuf);
100 
101   TemplateInfoIR TemplateInfoProtobufToIR(
102       const abi_dump::TemplateInfo &template_info_protobuf);
103 };
104 
105 
106 }  // namespace repr
107 }  // namespace header_checker
108 
109 
110 #endif  // HEADER_CHECKER_REPR_PROTOBUF_IR_READER_H_
111