1 // Copyright (C) 2016 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 ABI_WRAPPERS_H_ 16 #define ABI_WRAPPERS_H_ 17 18 #pragma clang diagnostic push 19 #pragma clang diagnostic ignored "-Wunused-parameter" 20 #pragma clang diagnostic ignored "-Wnested-anon-types" 21 #include "proto/abi_dump.pb.h" 22 #pragma clang diagnostic pop 23 24 #include <clang/AST/AST.h> 25 #include <clang/AST/ASTConsumer.h> 26 #include <clang/AST/Mangle.h> 27 #include <clang/AST/VTableBuilder.h> 28 #include <clang/Frontend/CompilerInstance.h> 29 30 namespace abi_wrapper { 31 class ABIWrapper { 32 public: 33 ABIWrapper(clang::MangleContext *mangle_contextp, 34 clang::ASTContext *ast_contextp, 35 const clang::CompilerInstance *cip); 36 37 static std::string GetDeclSourceFile(const clang::Decl *decl, 38 const clang::CompilerInstance *cip); 39 40 protected: 41 abi_dump::AccessSpecifier AccessClangToDump( 42 const clang::AccessSpecifier sp) const; 43 44 std::string GetMangledNameDecl(const clang::NamedDecl *decl) const; 45 46 bool SetupTemplateParamNames(abi_dump::TemplateInfo *tinfo, 47 clang::TemplateParameterList *pl) const; 48 49 bool SetupTemplateArguments(abi_dump::TemplateInfo *tinfo, 50 const clang::TemplateArgumentList *tl) const; 51 52 std::string QualTypeToString(const clang::QualType &sweet_qt) const; 53 54 std::string GetTagDeclQualifiedName(const clang::TagDecl *decl) const; 55 56 bool SetupBasicTypeAbi(abi_dump::BasicTypeAbi *type_abi, 57 const clang::QualType type) const; 58 59 bool SetupBasicNamedAndTypedDecl( 60 abi_dump::BasicNamedAndTypedDecl *basic_named_and_typed_decl, 61 const clang::QualType type, const std::string &name, 62 const clang::AccessSpecifier &access, std::string key) const; 63 64 protected: 65 const clang::CompilerInstance *cip_; 66 clang::MangleContext *mangle_contextp_; 67 clang::ASTContext *ast_contextp_; 68 }; 69 70 class RecordDeclWrapper : public ABIWrapper { 71 public: 72 RecordDeclWrapper(clang::MangleContext *mangle_contextp, 73 clang::ASTContext *ast_contextp, 74 const clang::CompilerInstance *compiler_instance_p, 75 const clang::RecordDecl *decl); 76 77 std::unique_ptr<abi_dump::RecordDecl> GetRecordDecl() const; 78 79 private: 80 const clang::RecordDecl *record_decl_; 81 82 private: 83 bool SetupRecordInfo(abi_dump::RecordDecl *record_declp, 84 const std::string &source_file) const; 85 86 bool SetupRecordFields(abi_dump::RecordDecl *record_declp) const; 87 88 bool SetupCXXBases(abi_dump::RecordDecl *cxxp, 89 const clang::CXXRecordDecl *cxx_record_decl) const; 90 91 bool SetupTemplateInfo(abi_dump::RecordDecl *record_declp, 92 const clang::CXXRecordDecl *cxx_record_decl) const; 93 94 bool SetupRecordVTable(abi_dump::RecordDecl *record_declp, 95 const clang::CXXRecordDecl *cxx_record_decl) const; 96 bool SetupRecordVTableComponent( 97 abi_dump::VTableComponent *added_vtable_component, 98 const clang::VTableComponent &vtable_component) const; 99 100 bool SetupCXXRecordInfo(abi_dump::RecordDecl *record_declp) const; 101 }; 102 103 class FunctionDeclWrapper : public ABIWrapper { 104 public: 105 FunctionDeclWrapper(clang::MangleContext *mangle_contextp, 106 clang::ASTContext *ast_contextp, 107 const clang::CompilerInstance *compiler_instance_p, 108 const clang::FunctionDecl *decl); 109 110 std::unique_ptr<abi_dump::FunctionDecl> GetFunctionDecl() const; 111 112 private: 113 const clang::FunctionDecl *function_decl_; 114 115 private: 116 bool SetupFunction(abi_dump::FunctionDecl *methodp, 117 const std::string &source_file) const; 118 119 bool SetupTemplateInfo(abi_dump::FunctionDecl *functionp) const; 120 121 bool SetupFunctionParameters(abi_dump::FunctionDecl *functionp) const; 122 }; 123 124 class EnumDeclWrapper : public ABIWrapper { 125 public: 126 EnumDeclWrapper(clang::MangleContext *mangle_contextp, 127 clang::ASTContext *ast_contextp, 128 const clang::CompilerInstance *compiler_instance_p, 129 const clang::EnumDecl *decl); 130 131 std::unique_ptr<abi_dump::EnumDecl> GetEnumDecl() const; 132 133 private: 134 const clang::EnumDecl *enum_decl_; 135 136 private: 137 bool SetupEnum(abi_dump::EnumDecl *enump, 138 const std::string &source_file) const; 139 bool SetupEnumFields(abi_dump::EnumDecl *enump) const; 140 }; 141 142 class GlobalVarDeclWrapper : public ABIWrapper { 143 public: 144 GlobalVarDeclWrapper(clang::MangleContext *mangle_contextp, 145 clang::ASTContext *ast_contextp, 146 const clang::CompilerInstance *compiler_instance_p, 147 const clang::VarDecl *decl); 148 149 std::unique_ptr<abi_dump::GlobalVarDecl> GetGlobalVarDecl() const; 150 151 private: 152 const clang::VarDecl *global_var_decl_; 153 private: 154 bool SetupGlobalVar(abi_dump::GlobalVarDecl *global_varp, 155 const std::string &source_file) const; 156 }; 157 158 } //end namespace abi_wrapper 159 160 #endif // ABI_WRAPPERS_H_ 161