File indexing completed on 2024-05-12 05:43:26

0001 /*
0002     Copyright (C) 2013-2014 Volker Krause <vkrause@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <https://www.gnu.org/licenses/>.
0016 */
0017 
0018 #ifndef DEMANGLER_H
0019 #define DEMANGLER_H
0020 
0021 #include <QByteArray>
0022 #include <QHash>
0023 #include <QMetaType>
0024 #include <QVector>
0025 
0026 struct demangle_component;
0027 
0028 /** C++ name demangler. */
0029 class Demangler
0030 {
0031 public:
0032     Demangler() = default;
0033     Demangler(const Demangler &other) = delete;
0034     Demangler& operator=(const Demangler &other) = delete;
0035 
0036     /** Demangle the given name and return the name split in namespace(s)/class/method. */
0037     QVector<QByteArray> demangle(const char* name);
0038 
0039     /** Demangle the given name into a single string. */
0040     static QByteArray demangleFull(const char* name);
0041 
0042     enum class SymbolType {
0043         Normal,
0044         VTable,
0045         TypeInfo,
0046         TypeInfoName,
0047         VTT,
0048         ConstructionVTable
0049     };
0050     /** Determine type of C++ symbols. */
0051     static SymbolType symbolType(const char* name);
0052 
0053 private:
0054     void reset();
0055     void handleNameComponent(demangle_component *component, QVector<QByteArray> &nameParts);
0056     void handleOptionalNameComponent(demangle_component *component, QVector<QByteArray> &nameParts);
0057     void handleOperatorComponent(demangle_component *component, QVector<QByteArray> &nameParts);
0058 
0059     const char *m_mangledName = nullptr;
0060     int m_templateParamIndex = 0;
0061     QHash<int, QByteArray> m_templateParams;
0062     QByteArray m_modifiers;
0063     QByteArray m_ptrmemType;
0064     bool m_inArgList = false;
0065     bool m_pendingPointer = false;
0066     bool m_pendingReference = false;
0067     bool m_indexTemplateArgs = false;
0068 
0069     // TODO shared value caching
0070 };
0071 
0072 Q_DECLARE_METATYPE(Demangler::SymbolType)
0073 
0074 #endif // DEMANGLER_H