Home | History | Annotate | Download | only in json
      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 AddTagTypeInfo(JsonObject &type_decl,
     46                              const TagTypeIR *tag_type_ir);
     47 
     48   static void AddEnumFields(JsonObject &enum_type, const EnumTypeIR *enum_ir);
     49 
     50  public:
     51   static JsonObject ConvertEnumTypeIR(const EnumTypeIR *enump);
     52 
     53   static JsonObject ConvertRecordTypeIR(const RecordTypeIR *recordp);
     54 
     55   static JsonObject ConvertFunctionTypeIR(const FunctionTypeIR *function_typep);
     56 
     57   static void AddFunctionParametersAndSetReturnType(
     58       JsonObject &function, const CFunctionLikeIR *cfunction_like_ir);
     59 
     60   static void AddFunctionParameters(JsonObject &function,
     61                                     const CFunctionLikeIR *cfunction_like_ir);
     62 
     63   static JsonObject ConvertFunctionIR(const FunctionIR *functionp);
     64 
     65   static JsonObject ConvertGlobalVarIR(const GlobalVarIR *global_varp);
     66 
     67   static JsonObject ConvertPointerTypeIR(const PointerTypeIR *pointerp);
     68 
     69   static JsonObject ConvertQualifiedTypeIR(const QualifiedTypeIR *qualtypep);
     70 
     71   static JsonObject ConvertBuiltinTypeIR(const BuiltinTypeIR *builtin_typep);
     72 
     73   static JsonObject ConvertArrayTypeIR(const ArrayTypeIR *array_typep);
     74 
     75   static JsonObject ConvertLvalueReferenceTypeIR(
     76       const LvalueReferenceTypeIR *lvalue_reference_typep);
     77 
     78   static JsonObject ConvertRvalueReferenceTypeIR(
     79       const RvalueReferenceTypeIR *rvalue_reference_typep);
     80 };
     81 
     82 class JsonIRDumper : public IRDumper, public IRToJsonConverter {
     83  public:
     84   JsonIRDumper(const std::string &dump_path);
     85 
     86   ~JsonIRDumper() override {}
     87 
     88   bool Dump(const ModuleIR &module) override;
     89 
     90  private:
     91   bool AddLinkableMessageIR(const LinkableMessageIR *) override;
     92 
     93   bool AddElfSymbolMessageIR(const ElfSymbolIR *) override;
     94 
     95  private:
     96   JsonObject translation_unit_;
     97 };
     98 
     99 
    100 }  // namespace repr
    101 }  // namespace header_checker
    102 
    103 
    104 #endif  // HEADER_CHECKER_REPR_JSON_IR_DUMPER_H_
    105