| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2018 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtSCriptTools module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qscriptdebuggerconsolecommandmanager_p.h"cxx . . $ `<file>/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager_p.h`/ |
| 41 | #include "qscriptdebuggerconsolecommand_p.h"cxx . . $ `<file>/src/scripttools/debugging/qscriptdebuggerconsolecommand_p.h`/ |
| 42 | #include "qscriptdebuggerconsolecommandgroupdata_p.h"cxx . . $ `<file>/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h`/ |
| 43 | |
| 44 | #include <QtCore/qlist.h> |
| 45 | #include <QtCore/qstringlist.h> |
| 46 | |
| 47 | #include <algorithm> |
| 48 | |
| 49 | QT_BEGIN_NAMESPACEcxx . . $ `<external>/15045578679651060896/qglobal.h:148:10`! |
| 50 | |
| 51 | /*! |
| 52 | \since 4.5 |
| 53 | \class QScriptDebuggerConsoleCommandManager |
| 54 | \internal |
| 55 | |
| 56 | \brief The QScriptDebuggerConsoleCommandManager manages a collection of console commands. |
| 57 | |
| 58 | */ |
| 59 | |
| 60 | class QScriptDebuggerConsoleCommandManagerPrivatecxx . . $ QScriptDebuggerConsoleCommandManagerPrivate# |
| 61 | { |
| 62 | Q_DECLARE_PUBLICcxx . . $ `<external>/15045578679651060896/qglobal.h:1172:9`!(QScriptDebuggerConsoleCommandManager) |
| 63 | public: |
| 64 | QScriptDebuggerConsoleCommandManagerPrivatecxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#QScriptDebuggerConsoleCommandManagerPrivate(49f6e7a06ebc5aa8).(); |
| 65 | ~cxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#`~QScriptDebuggerConsoleCommandManagerPrivate`(ced63f7c635d850d).QScriptDebuggerConsoleCommandManagerPrivatecxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#(); |
| 66 | |
| 67 | QListcxx . . $ QList#<QScriptDebuggerConsoleCommandcxx . . $ QScriptDebuggerConsoleCommand#*> commandscxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#commands.; |
| 68 | QMapcxx . . $ QMap#<QStringcxx . . $ QString#, QScriptDebuggerConsoleCommandGroupDatacxx . . $ QScriptDebuggerConsoleCommandGroupData#> groupscxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#groups.; |
| 69 | |
| 70 | QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager# *q_ptrcxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#q_ptr.; |
| 71 | }; |
| 72 | |
| 73 | QScriptDebuggerConsoleCommandManagerPrivatecxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#::QScriptDebuggerConsoleCommandManagerPrivatecxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#QScriptDebuggerConsoleCommandManagerPrivate(49f6e7a06ebc5aa8).() |
| 74 | { |
| 75 | groups[QLatin1String("breakpoints")] = |
| 76 | QScriptDebuggerConsoleCommandGroupData(QLatin1String("Making program stop at certain points"), |
| 77 | QLatin1String("")); |
| 78 | groups[QLatin1String("files")] = |
| 79 | QScriptDebuggerConsoleCommandGroupData(QLatin1String("Examining files"), |
| 80 | QLatin1String("")); |
| 81 | groups[QLatin1String("stack")] = |
| 82 | QScriptDebuggerConsoleCommandGroupData(QLatin1String("Examining the stack"), |
| 83 | QLatin1String("")); |
| 84 | groups[QLatin1String("running")] = |
| 85 | QScriptDebuggerConsoleCommandGroupData(QLatin1String("Running the program"), |
| 86 | QLatin1String("")); |
| 87 | groups[QLatin1String("status")] = |
| 88 | QScriptDebuggerConsoleCommandGroupData(QLatin1String("Status inquiries"), |
| 89 | QLatin1String("")); |
| 90 | groups[QLatin1String("void")] = |
| 91 | QScriptDebuggerConsoleCommandGroupData(QLatin1String("No such group"), |
| 92 | QLatin1String("It's a secret to everyone")); |
| 93 | } |
| 94 | |
| 95 | QScriptDebuggerConsoleCommandManagerPrivatecxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#::~cxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#`~QScriptDebuggerConsoleCommandManagerPrivate`(ced63f7c635d850d).QScriptDebuggerConsoleCommandManagerPrivatecxx . . $ QScriptDebuggerConsoleCommandManagerPrivate#() |
| 96 | { |
| 97 | qDeleteAllcxx . . $ qDeleteAll(77d9f17553126ecb).(commands); |
| 98 | } |
| 99 | |
| 100 | QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#QScriptDebuggerConsoleCommandManager(49f6e7a06ebc5aa8).() |
| 101 | : d_ptr(new QScriptDebuggerConsoleCommandManagerPrivate) |
| 102 | { |
| 103 | d_ptr->q_ptr = this; |
| 104 | } |
| 105 | |
| 106 | QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::~cxx . . $ QScriptDebuggerConsoleCommandManager#`~QScriptDebuggerConsoleCommandManager`(ced63f7c635d850d).QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#() |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | /*! |
| 111 | Adds the given \a command. |
| 112 | The manager takes ownership of the command. |
| 113 | */ |
| 114 | void QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::addCommandcxx . . $ QScriptDebuggerConsoleCommandManager#addCommand(e8159275eaa531a2).(QScriptDebuggerConsoleCommandcxx . . $ QScriptDebuggerConsoleCommand# *command) |
| 115 | { |
| 116 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(QScriptDebuggerConsoleCommandManager); |
| 117 | Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:859:13`!(command != 0); |
| 118 | if (command->namecxx . . $ QScriptDebuggerConsoleCommand#name(6ef7b6c27b00b43d).().isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) { |
| 119 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!("addCommand(): nameless command ignored"); |
| 120 | return; |
| 121 | } |
| 122 | if (command->groupcxx . . $ QScriptDebuggerConsoleCommand#group(6ef7b6c27b00b43d).().isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) { |
| 123 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!("addCommand(): groupless command '%s' ignored", |
| 124 | qPrintablecxx . . $ `<external>/15045578679651060896/qglobal.h:831:11`!(command->name())); |
| 125 | return; |
| 126 | } |
| 127 | if (findCommandcxx . . $ QScriptDebuggerConsoleCommandManager#findCommand(c5e30f28890cffb).(command->namecxx . . $ QScriptDebuggerConsoleCommand#name(6ef7b6c27b00b43d).()) != 0) { |
| 128 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!("addCommand(): duplicate command '%s' (group '%s') ignored", |
| 129 | qPrintablecxx . . $ `<external>/15045578679651060896/qglobal.h:831:11`!(command->name()), qPrintablecxx . . $ `<external>/15045578679651060896/qglobal.h:831:11`!(command->group())); |
| 130 | return; |
| 131 | } |
| 132 | if (!d->groups.contains(command->groupcxx . . $ QScriptDebuggerConsoleCommand#group(6ef7b6c27b00b43d).())) { |
| 133 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!("addCommand(): group '%s' for command '%s' is unknown!", |
| 134 | qPrintablecxx . . $ `<external>/15045578679651060896/qglobal.h:831:11`!(command->group()), qPrintablecxx . . $ `<external>/15045578679651060896/qglobal.h:831:11`!(command->name())); |
| 135 | } |
| 136 | d->commands.append(command); |
| 137 | } |
| 138 | |
| 139 | /*! |
| 140 | Registers a command group with the given \a name and \a data. |
| 141 | */ |
| 142 | void QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::addCommandGroupcxx . . $ QScriptDebuggerConsoleCommandManager#addCommandGroup(2fc6275b82d2809a).( |
| 143 | const QStringcxx . . $ QString# &name, const QScriptDebuggerConsoleCommandGroupDatacxx . . $ QScriptDebuggerConsoleCommandGroupData# &data) |
| 144 | { |
| 145 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(QScriptDebuggerConsoleCommandManager); |
| 146 | if (name.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) { |
| 147 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!("addCommandGroup(): nameless group ignored"); |
| 148 | return; |
| 149 | } |
| 150 | if (d->groups.contains(name)) { |
| 151 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!("addCommandGroup(): group '%s' already defined", |
| 152 | qPrintablecxx . . $ `<external>/15045578679651060896/qglobal.h:831:11`!(name)); |
| 153 | return; |
| 154 | } |
| 155 | d->groups[name] = data; |
| 156 | } |
| 157 | |
| 158 | /*! |
| 159 | Returns the command with the given \a name if one exists, otherwise |
| 160 | returns 0. |
| 161 | */ |
| 162 | QScriptDebuggerConsoleCommandcxx . . $ QScriptDebuggerConsoleCommand# *QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::findCommandcxx . . $ QScriptDebuggerConsoleCommandManager#findCommand(c5e30f28890cffb).(const QStringcxx . . $ QString# &name) const |
| 163 | { |
| 164 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const QScriptDebuggerConsoleCommandManager); |
| 165 | for (int i = 0; i <cxx . . $ `operator<`(afd0585ae69deac). d->commands.size(); ++i) { |
| 166 | QScriptDebuggerConsoleCommandcxx . . $ QScriptDebuggerConsoleCommand# *cmd = d->commands.at(i); |
| 167 | if (cmd->namecxx . . $ QScriptDebuggerConsoleCommand#name(6ef7b6c27b00b43d).() ==cxx . . $ `operator==`(5bc2975d2d751687). name) |
| 168 | return cmd; |
| 169 | else if (cmd->aliasescxx . . $ QScriptDebuggerConsoleCommand#aliases(e1dbd5c4feadc8f5).().containscxx . . $ QStringList#contains(8cce4688c16f48f3).(name)) |
| 170 | return cmd; |
| 171 | } |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | /*! |
| 176 | Returns the commands organized into groups. |
| 177 | */ |
| 178 | QMapcxx . . $ QMap#<QStringcxx . . $ QString#, QListcxx . . $ QList#<QScriptDebuggerConsoleCommandcxx . . $ QScriptDebuggerConsoleCommand#*> > QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::commandscxx . . $ QScriptDebuggerConsoleCommandManager#commands(f0f129b32eb9f934).() const |
| 179 | { |
| 180 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const QScriptDebuggerConsoleCommandManager); |
| 181 | QMapcxx . . $ QMap#<QStringcxx . . $ QString#, QListcxx . . $ QList#<QScriptDebuggerConsoleCommandcxx . . $ QScriptDebuggerConsoleCommand#*> > result; |
| 182 | for (int i = 0; i <cxx . . $ `operator<`(afd0585ae69deac). d->commands.size(); ++i) { |
| 183 | QScriptDebuggerConsoleCommandcxx . . $ QScriptDebuggerConsoleCommand# *cmd = d->commands.at(i); |
| 184 | result[cmd->groupcxx . . $ QScriptDebuggerConsoleCommand#group(6ef7b6c27b00b43d).()].append(cmd); |
| 185 | } |
| 186 | return result; |
| 187 | } |
| 188 | |
| 189 | /*! |
| 190 | Returns commands in the group of the given \a name. |
| 191 | */ |
| 192 | QScriptDebuggerConsoleCommandListcxx . . $ QScriptDebuggerConsoleCommandList# QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::commandsInGroupcxx . . $ QScriptDebuggerConsoleCommandManager#commandsInGroup(bb8ae4bb006e0772).(const QStringcxx . . $ QString# &name) const |
| 193 | { |
| 194 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const QScriptDebuggerConsoleCommandManager); |
| 195 | QScriptDebuggerConsoleCommandListcxx . . $ QScriptDebuggerConsoleCommandList# result; |
| 196 | for (int i = 0; i <cxx . . $ `operator<`(afd0585ae69deac). d->commands.size(); ++i) { |
| 197 | QScriptDebuggerConsoleCommandcxx . . $ QScriptDebuggerConsoleCommand# *cmd = d->commands.at(i); |
| 198 | if (cmd->groupcxx . . $ QScriptDebuggerConsoleCommand#group(6ef7b6c27b00b43d).() ==cxx . . $ `operator==`(5bc2975d2d751687). name) |
| 199 | result.append(cmd); |
| 200 | } |
| 201 | return result; |
| 202 | } |
| 203 | |
| 204 | /*! |
| 205 | Returns data associated with the group of the given \a name. |
| 206 | */ |
| 207 | QScriptDebuggerConsoleCommandGroupDatacxx . . $ QScriptDebuggerConsoleCommandGroupData# QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::commandGroupDatacxx . . $ QScriptDebuggerConsoleCommandManager#commandGroupData(e9ebe4710362e1e1).(const QStringcxx . . $ QString# &name) const |
| 208 | { |
| 209 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const QScriptDebuggerConsoleCommandManager); |
| 210 | return d->groups.value(name); |
| 211 | } |
| 212 | |
| 213 | /*! |
| 214 | Returns all command groups. |
| 215 | */ |
| 216 | QMapcxx . . $ QMap#<QStringcxx . . $ QString#, QScriptDebuggerConsoleCommandGroupDatacxx . . $ QScriptDebuggerConsoleCommandGroupData#> QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::commandGroupscxx . . $ QScriptDebuggerConsoleCommandManager#commandGroups(b5c15cf08127f0f8).() const |
| 217 | { |
| 218 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const QScriptDebuggerConsoleCommandManager); |
| 219 | return d->groups; |
| 220 | } |
| 221 | |
| 222 | /*! |
| 223 | Returns the possible completions for the given \a prefix. |
| 224 | */ |
| 225 | QStringListcxx . . $ QStringList# QScriptDebuggerConsoleCommandManagercxx . . $ QScriptDebuggerConsoleCommandManager#::completionscxx . . $ QScriptDebuggerConsoleCommandManager#completions(50afb52245723b61).(const QStringcxx . . $ QString# &prefix) const |
| 226 | { |
| 227 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const QScriptDebuggerConsoleCommandManager); |
| 228 | QStringListcxx . . $ QStringList# resultcxx . . $ QStringList#QStringList(ced63f7c635d850d).; |
| 229 | for (int i = 0; i <cxx . . $ `operator<`(afd0585ae69deac). d->commands.size(); ++i) { |
| 230 | QScriptDebuggerConsoleCommandcxx . . $ QScriptDebuggerConsoleCommand# *cmd = d->commands.at(i); |
| 231 | QStringListcxx . . $ QStringList# namescxx . . $ QStringList#QStringList(ced63f7c635d850d).; |
| 232 | names.append(cmd->namecxx . . $ QScriptDebuggerConsoleCommand#name(6ef7b6c27b00b43d).()); |
| 233 | // names += cmd->aliases(); |
| 234 | for (int j = 0; j <cxx . . $ `operator<`(afd0585ae69deac). names.size(); ++j) { |
| 235 | const QStringcxx . . $ QString# &name = names.at(j); |
| 236 | if ((name.lengthcxx . . $ QString#length(455f465bc33b4cdf).() > prefix.lengthcxx . . $ QString#length(455f465bc33b4cdf).()) && name.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).(prefix)) |
| 237 | result.append(name); |
| 238 | } |
| 239 | } |
| 240 | stdcxx . . $ std/::stable_sortcxx . . $ std/stable_sort(249673c20e2b8d5).(result.begin(), result.end()); |
| 241 | return result; |
| 242 | } |
| 243 | |
| 244 | QT_END_NAMESPACEcxx . . $ `<external>/15045578679651060896/qglobal.h:149:10`! |