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_JSON_IR_DUMPER_H_ 16 #define HEADER_CHECKER_REPR_JSON_IR_DUMPER_H_ 17 18 #include "repr/ir_dumper.h" 19 #include "repr/ir_reader.h" 20 #include "repr/ir_representation.h" 21 #include "repr/json/converter.h" 22 23 24 namespace header_checker { 25 namespace repr { 26 27 28 class IRToJsonConverter { 29 private: 30 static void AddTemplateInfo(JsonObject &type_decl, 31 const TemplatedArtifactIR *template_ir); 32 33 // BasicNamedAndTypedDecl 34 static void AddTypeInfo(JsonObject &type_decl, const TypeIR *type_ir); 35 36 static void AddRecordFields(JsonObject &record_type, 37 const RecordTypeIR *record_ir); 38 39 static void AddBaseSpecifiers(JsonObject &record_type, 40 const RecordTypeIR *record_ir); 41 42 static void AddVTableLayout(JsonObject &record_type, 43 const RecordTypeIR *record_ir); 44 45 static void AddEnumFields(JsonObject &enum_type, const EnumTypeIR *enum_ir); 46 47 public: 48 static JsonObject ConvertEnumTypeIR(const EnumTypeIR *enump); 49 50 static JsonObject ConvertRecordTypeIR(const RecordTypeIR *recordp); 51 52 static JsonObject ConvertFunctionTypeIR(const FunctionTypeIR *function_typep); 53 54 static void AddFunctionParametersAndSetReturnType( 55 JsonObject &function, const CFunctionLikeIR *cfunction_like_ir); 56 57 static void AddFunctionParameters(JsonObject &function, 58 const CFunctionLikeIR *cfunction_like_ir); 59 60 static JsonObject ConvertFunctionIR(const FunctionIR *functionp); 61 62 static JsonObject ConvertGlobalVarIR(const GlobalVarIR *global_varp); 63 64 static JsonObject ConvertPointerTypeIR(const PointerTypeIR *pointerp); 65 66 static JsonObject ConvertQualifiedTypeIR(const QualifiedTypeIR *qualtypep); 67 68 static JsonObject ConvertBuiltinTypeIR(const BuiltinTypeIR *builtin_typep); 69 70 static JsonObject ConvertArrayTypeIR(const ArrayTypeIR *array_typep); 71 72 static JsonObject ConvertLvalueReferenceTypeIR( 73 const LvalueReferenceTypeIR *lvalue_reference_typep); 74 75 static JsonObject ConvertRvalueReferenceTypeIR( 76 const RvalueReferenceTypeIR *rvalue_reference_typep); 77 }; 78 79 class JsonIRDumper : public IRDumper, public IRToJsonConverter { 80 public: 81 JsonIRDumper(const std::string &dump_path); 82 ~JsonIRDumper()83 ~JsonIRDumper() override {} 84 85 bool Dump(const ModuleIR &module) override; 86 87 private: 88 bool AddLinkableMessageIR(const LinkableMessageIR *) override; 89 90 bool AddElfSymbolMessageIR(const ElfSymbolIR *) override; 91 92 private: 93 JsonObject translation_unit_; 94 }; 95 96 97 } // namespace repr 98 } // namespace header_checker 99 100 101 #endif // HEADER_CHECKER_REPR_JSON_IR_DUMPER_H_ 102