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