12QRegularExpression
Parameters::s_varComment(R"(^/\*\s*([a-zA-Z_0-9]+)\s*\*/$)");
15
16
17
18
19
20
21
22
25
26
27
28
29
32
33
34
35
39 if (!p.isEmpty() && !p.endsWith(QChar(
'*')) && !p.endsWith(QChar(
'&')) &&
40 !p.endsWith(QChar(
' ')) && !m_name.isEmpty()) {
41 p += QLatin1Char(
' ');
44 if (includeValue && !m_defaultValue.isEmpty())
45 p +=
" = " + m_defaultValue;
50
51
52
53
54
55
56
57
58
59
60
61
69 : m_valid(
true), m_privateSignal(
false), m_tok(0), m_tokenizer(
nullptr)
71 if (!signature.isEmpty()) {
72 if (!parse(signature)) {
80
81
82
89
90
93 return m_tokenizer->lexeme();
97
98
101 return m_tokenizer->previousLexeme();
105
106
107
108
111 if (m_tok == target) {
119
120
121
122
123void Parameters::matchTemplateAngles(CodeChunk &type)
126 int leftAngleDepth = 0;
127 int parenAndBraceDepth = 0;
134 ++parenAndBraceDepth;
136 if (--parenAndBraceDepth < 0)
139 type.append(lexeme());
141 }
while (leftAngleDepth > 0 && m_tok !=
Tok_Eoi);
146
147
148
149bool Parameters::matchTypeAndName(CodeChunk &type, QString &name)
152
153
154
160
161
162
163
168
169
170
171 while (match(Tok_const) || match(Tok_volatile))
172 type.append(previousLexeme());
180 type.append(pending);
182 type.append(lexeme());
187 if (!pending.isEmpty()) {
188 type.append(pending);
191 while (match(Tok_const) || match(Tok_volatile))
192 type.append(previousLexeme());
194 if (match(Tok_Tilde))
195 type.append(previousLexeme());
201
202
203
204
206 && ((previousLexeme() ==
"QT_PREPEND_NAMESPACE")
207 || (previousLexeme() ==
"NS"))) {
210 type.append(previousLexeme());
213 type.append(previousLexeme());
216 type.append(previousLexeme());
221 type.append(previousLexeme());
224 matchTemplateAngles(type);
226 while (match(Tok_const) || match(Tok_volatile))
227 type.append(previousLexeme());
230 type.append(previousLexeme());
235 while (match(Tok_Ampersand) || match(Tok_Aster) || match(Tok_const) || match(Tok_Caret)
236 || match(Tok_Ellipsis))
237 type.append(previousLexeme());
241
242
243
244
245
247 type.append(previousLexeme());
248 type.appendHotspot();
249 if (match(Tok_Ident))
250 name = previousLexeme();
253 type.append(previousLexeme());
256 type.append(previousLexeme());
261 if (!matchTypeAndName(type, dummy))
263 if (match(Tok_Comma))
264 type.append(previousLexeme());
268 type.append(previousLexeme());
271
272
273
274 type.appendHotspot();
277 name = previousLexeme();
280
281
282
283
284
285
286
287 auto match = s_varComment.match(previousLexeme());
288 if (match.hasMatch())
289 name = match.captured(1);
293 name.append(lexeme());
301 name.append(lexeme());
313 type.append(lexeme());
322
323
324
325
329 m_privateSignal =
true;
335 if (!matchTypeAndName(chunk, name))
337 QString type = chunk.toString();
338 QString defaultValue;
346 chunk.append(lexeme());
349 defaultValue = chunk.toString();
351 append(type, name, defaultValue);
356
357
358
359
360
361bool Parameters::parse(
const QString &signature)
364 int outerTok = m_tok;
366 QByteArray latin1 = signature.toLatin1();
369 m_tokenizer = &stringTokenizer;
373 if (!matchParameter()) {
374 m_parameters.clear();
380 m_tokenizer = outerTokenizer;
386
387
388
391 m_parameters.append(
Parameter(type, name, value));
395
396
397
401 if (!m_parameters.empty()) {
402 for (
int i = 0; i < m_parameters.size(); i++) {
405 result += m_parameters.at(i).signature(includeValues);
412
413
414
415
416
417
418
422 const auto params = m_parameters;
423 for (
const auto ¶meter : params) {
424 raw += parameter.type();
426 raw += parameter.name();
428 raw += parameter.defaultValue();
434
435
436
437
438
439
443 if (!signature.isEmpty()) {
444 QStringList commaSplit = signature.split(
',');
445 m_parameters.resize(commaSplit.size());
447 for (
const auto &item : std::as_const(commaSplit)) {
448 QStringList blankSplit = item.split(
' ', Qt::SkipEmptyParts);
450 qsizetype defaultIdx = blankSplit.indexOf(QStringLiteral(
"="));
451 if (defaultIdx != -1) {
452 if (++defaultIdx < blankSplit.size())
453 pDefault = blankSplit.mid(defaultIdx).join(
' ');
454 blankSplit = blankSplit.mid(0, defaultIdx - 1);
456 QString pName = blankSplit.takeLast();
457 QString pType = blankSplit.join(
' ');
458 if (pType.isEmpty() && pName == QLatin1String(
"..."))
462 while (j < pName.size() && !pName.at(j).isLetter())
465 pType += QChar(
' ') + pName.left(j);
466 pName = pName.mid(j);
469 m_parameters[i++].set(pType, pName, pDefault);
475
476
480 const auto params = m_parameters;
481 for (
const auto ¶meter : params) {
482 if (!parameter.name().isEmpty())
483 names.insert(parameter.name());
489
490
495 for (
int i = 0; i <
count(); ++i) {
498 out += m_parameters.at(i).type();
505
506
507
512 for (
int i = 0; i <
count(); ++i) {
517 if (out[out.size() - 1].isLetterOrNumber())
518 out += QLatin1Char(
' ');
526
527
528
535 for (
int i = 0; i <
count(); i++) {
536 if (parameters
.at(i
).type() != m_parameters.at(i).type())
The Location class provides a way to mark a location in a file.
Location()
Constructs an empty location.
The Parameter class describes one function parameter.
QString signature(bool includeValue=false) const
Reconstructs the text signature for the parameter and returns it.
A class for parsing and managing a function parameter list.
QSet< QString > getNames() const
Insert all the parameter names into names.
bool match(const Parameters ¶meters) const
Returns true if parameters contains the same parameter signature as this.
Parameters(const QString &signature)
QString rawSignature(bool names=false, bool values=false) const
Returns the signature of all the parameters with all the spaces and commas removed.
QString generateTypeList() const
Construct a list of the parameter types and return it.
const Parameter & at(int i) const
QString signature(bool includeValues=false) const
Returns the list of reconstructed parameters.
QString generateTypeAndNameList() const
Construct a list of the parameter type/name pairs and return it.
void append(const QString &type, const QString &name, const QString &value)
Append a Parameter constructed from type, name, and value to the parameter vector.
void set(const QString &signature)
Parse the parameter signature by splitting the string, and store the individual parameters in the par...
void setParsingFnOrMacro(bool macro)
Combined button and popup list for selecting options.