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 EXPORTED_SYMBOL_SET_ 16 #define EXPORTED_SYMBOL_SET_ 17 18 #include "repr/ir_representation.h" 19 #include <utils/string_utils.h> 20 21 #include <functional> 22 #include <map> 23 #include <set> 24 #include <string> 25 26 27 namespace header_checker { 28 namespace repr { 29 30 31 class ExportedSymbolSet { 32 public: 33 using FunctionMap = std::map<std::string, ElfFunctionIR, std::less<>>; 34 using VarMap = std::map<std::string, ElfObjectIR, std::less<>>; 35 using NameSet = utils::StringSet; 36 using GlobPatternSet = utils::StringSet; 37 38 39 public: ExportedSymbolSet()40 ExportedSymbolSet() {} 41 GetFunctions()42 const FunctionMap &GetFunctions() const { 43 return funcs_; 44 } 45 GetVars()46 const VarMap &GetVars() const { 47 return vars_; 48 } 49 GetGlobPatterns()50 const GlobPatternSet &GetGlobPatterns() const { 51 return glob_patterns_; 52 } 53 GetDemangledCppGlobPatterns()54 const GlobPatternSet &GetDemangledCppGlobPatterns() const { 55 return demangled_cpp_glob_patterns_; 56 } 57 GetDemangledCppSymbols()58 const NameSet &GetDemangledCppSymbols() const { 59 return demangled_cpp_symbols_; 60 } 61 62 bool HasSymbol(const std::string &symbol_name) const; 63 64 void AddFunction(const std::string &name, 65 ElfSymbolIR::ElfSymbolBinding binding); 66 67 void AddVar(const std::string &name, ElfSymbolIR::ElfSymbolBinding binding); 68 AddGlobPattern(const std::string & pattern)69 void AddGlobPattern(const std::string &pattern) { 70 glob_patterns_.insert(pattern); 71 } 72 AddDemangledCppGlobPattern(const std::string & pattern)73 void AddDemangledCppGlobPattern(const std::string &pattern) { 74 demangled_cpp_glob_patterns_.insert(pattern); 75 } 76 AddDemangledCppSymbol(const std::string & pattern)77 void AddDemangledCppSymbol(const std::string &pattern) { 78 demangled_cpp_symbols_.insert(pattern); 79 } 80 81 82 private: HasDemangledCppSymbolsOrPatterns()83 bool HasDemangledCppSymbolsOrPatterns() const { 84 return (!demangled_cpp_glob_patterns_.empty() || 85 !demangled_cpp_symbols_.empty()); 86 } 87 88 89 private: 90 FunctionMap funcs_; 91 VarMap vars_; 92 93 GlobPatternSet glob_patterns_; 94 GlobPatternSet demangled_cpp_glob_patterns_; 95 NameSet demangled_cpp_symbols_; 96 }; 97 98 99 } // namespace repr 100 } // namespace header_checker 101 102 103 #endif // EXPORTED_SYMBOL_SET_ 104