RedPanda-CPP/RedPandaIDE/gdbmiresultparser.h

116 lines
3.5 KiB
C
Raw Normal View History

2021-12-26 23:18:28 +08:00
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2021-11-12 10:51:00 +08:00
#ifndef GDBMIRESULTPARSER_H
#define GDBMIRESULTPARSER_H
#include <QByteArray>
2021-11-13 11:16:05 +08:00
#include <QHash>
#include <QList>
2021-11-13 11:16:05 +08:00
#include <memory>
2021-11-12 10:51:00 +08:00
enum class GDBMIResultType {
Breakpoint,
BreakpointTable,
FrameStack,
LocalVariables,
Locals,
Frame,
Disassembly,
Evaluation,
RegisterNames,
RegisterValues,
2021-11-25 11:24:38 +08:00
Memory,
2021-11-25 20:26:43 +08:00
CreateVar,
ListVarChildren,
UpdateVarValue
2021-11-12 10:51:00 +08:00
};
class GDBMIResultParser
{
2021-11-13 11:16:05 +08:00
public:
2021-11-12 22:42:51 +08:00
enum class ParseValueType {
Value,
Object,
Array,
NotAssigned
};
2021-11-13 11:16:05 +08:00
class ParseValue;
class ParseObject {
public:
2021-11-24 17:53:25 +08:00
explicit ParseObject();
ParseObject(const ParseObject& object);
ParseValue operator[](const QByteArray& name) const;
2021-11-13 11:16:05 +08:00
ParseValue& operator[](const QByteArray& name);
ParseObject& operator=(const ParseObject& object);
private:
QHash<QByteArray, ParseValue> mProps;
};
2021-11-12 22:42:51 +08:00
class ParseValue {
public:
explicit ParseValue();
2021-11-21 08:38:03 +08:00
explicit ParseValue(const QByteArray& value);
2021-11-12 22:42:51 +08:00
explicit ParseValue(const ParseObject &object);
2021-11-23 21:08:33 +08:00
explicit ParseValue(const QList<ParseValue>& array);
2021-11-24 17:53:25 +08:00
ParseValue(const ParseValue& value);
2021-11-21 08:38:03 +08:00
const QByteArray &value() const;
2021-11-23 21:08:33 +08:00
const QList<ParseValue> &array() const;
const ParseObject &object() const;
qlonglong intValue(int defaultValue=-1) const;
qulonglong hexValue(bool &ok) const;
2021-11-24 17:53:25 +08:00
2021-11-23 21:08:33 +08:00
QString pathValue() const;
QString utf8PathValue() const;
2021-11-12 22:42:51 +08:00
ParseValueType type() const;
2021-11-24 17:53:25 +08:00
bool isValid() const;
2021-11-21 08:38:03 +08:00
ParseValue& operator=(const QByteArray& value);
2021-11-12 22:42:51 +08:00
ParseValue& operator=(const ParseObject& object);
2021-11-23 21:08:33 +08:00
ParseValue& operator=(const QList<ParseValue>& array);
2021-11-12 22:42:51 +08:00
ParseValue& operator=(const ParseValue& value);
2021-11-12 10:51:00 +08:00
private:
2021-11-21 08:38:03 +08:00
QByteArray mValue;
2021-11-23 21:08:33 +08:00
QList<ParseValue> mArray;
2021-11-12 22:42:51 +08:00
ParseObject mObject;
ParseValueType mType;
2021-11-12 10:51:00 +08:00
};
2021-11-12 22:42:51 +08:00
using PParseValue = std::shared_ptr<ParseValue>;
2021-11-12 10:51:00 +08:00
public:
GDBMIResultParser();
bool parse(const QByteArray& record, const QString& command, GDBMIResultType& type, ParseObject& multiValues);
2021-11-21 10:36:50 +08:00
bool parseAsyncResult(const QByteArray& record, QByteArray& result, ParseObject& multiValue);
2021-11-12 22:42:51 +08:00
private:
2021-11-21 10:36:50 +08:00
bool parseMultiValues(const char*p, ParseObject& multiValue);
2021-11-13 11:16:05 +08:00
bool parseNameAndValue(const char *&p,QByteArray& name, ParseValue& value);
bool parseValue(const char* &p, ParseValue& value);
bool parseStringValue(const char*&p, QByteArray& stringValue);
bool parseObject(const char*&p, ParseObject& obj);
2021-11-23 21:08:33 +08:00
bool parseArray(const char*&p, QList<ParseValue>& array);
2021-11-13 11:16:05 +08:00
void skipSpaces(const char* &p);
2021-11-12 22:42:51 +08:00
bool isNameChar(char ch);
bool isSpaceChar(char ch);
private:
QHash<QString, GDBMIResultType> mResultTypes;
2021-11-12 10:51:00 +08:00
};
#endif // GDBMIRESULTPARSER_H