File indexing completed on 2024-05-19 05:44:24

0001 /*
0002     SPDX-FileCopyrightText: 2016-2017 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef LOCATIONDATA_H
0008 #define LOCATIONDATA_H
0009 
0010 #include <QHashFunctions>
0011 #include <QMetaType>
0012 
0013 #include <util/indices.h>
0014 
0015 #include <boost/functional/hash.hpp>
0016 
0017 Q_DECLARE_METATYPE(ModuleIndex)
0018 Q_DECLARE_METATYPE(FunctionIndex)
0019 Q_DECLARE_METATYPE(FileIndex)
0020 
0021 struct Symbol
0022 {
0023     // function name
0024     FunctionIndex functionId;
0025     // path to dso / executable
0026     ModuleIndex moduleId;
0027 
0028     bool operator==(const Symbol& rhs) const
0029     {
0030         return functionId == rhs.functionId && moduleId == rhs.moduleId;
0031     }
0032 
0033     bool operator!=(const Symbol& rhs) const
0034     {
0035         return !operator==(rhs);
0036     }
0037 
0038     bool operator<(const Symbol& rhs) const
0039     {
0040         return std::tie(functionId, moduleId) < std::tie(rhs.functionId, rhs.moduleId);
0041     }
0042 
0043     bool isValid() const
0044     {
0045         return *this != Symbol {};
0046     }
0047 };
0048 
0049 Q_DECLARE_TYPEINFO(Symbol, Q_MOVABLE_TYPE);
0050 Q_DECLARE_METATYPE(Symbol)
0051 
0052 struct FileLine
0053 {
0054     FileIndex fileId;
0055     int line;
0056 
0057     bool operator==(const FileLine& rhs) const
0058     {
0059         return fileId == rhs.fileId && line == rhs.line;
0060     }
0061 };
0062 Q_DECLARE_TYPEINFO(FileLine, Q_MOVABLE_TYPE);
0063 Q_DECLARE_METATYPE(FileLine)
0064 
0065 const QString& unresolvedFunctionName();
0066 
0067 namespace std {
0068 template <>
0069 struct hash<Symbol>
0070 {
0071     std::size_t operator()(const Symbol symbol) const
0072     {
0073         return boost::hash_value(std::tie(symbol.functionId.index, symbol.moduleId.index));
0074     }
0075 };
0076 }
0077 
0078 inline uint qHash(const Symbol& symbol, uint seed = 0)
0079 {
0080     QtPrivate::QHashCombine hash;
0081     seed = hash(seed, symbol.functionId);
0082     seed = hash(seed, symbol.moduleId);
0083     return seed;
0084 }
0085 
0086 inline uint qHash(const FileLine& location, uint seed = 0)
0087 {
0088     QtPrivate::QHashCombine hash;
0089     seed = hash(seed, location.fileId);
0090     seed = hash(seed, location.line);
0091     return seed;
0092 }
0093 
0094 #endif // LOCATIONDATA_H