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
123
124
125
126
127
128
129
130
131void Parameters::matchTemplateAngles(CodeChunk &type)
134 int leftAngleDepth = 0;
135 int parenAndBraceDepth = 0;
142 ++parenAndBraceDepth;
144 if (--parenAndBraceDepth < 0)
147 type.append(lexeme());
149 }
while (leftAngleDepth > 0 && m_tok !=
Tok_Eoi);
154
155
156
157bool Parameters::matchTypeAndName(CodeChunk &type, QString &name)
160
161
162
168
169
170
171
176
177
178
179 while (match(Tok_const) || match(Tok_volatile))
180 type.append(previousLexeme());
188 type.append(pending);
190 type.append(lexeme());
195 if (!pending.isEmpty()) {
196 type.append(pending);
199 while (match(Tok_const) || match(Tok_volatile))
200 type.append(previousLexeme());
202 if (match(Tok_Tilde))
203 type.append(previousLexeme());
209
210
211
212
214 && ((previousLexeme() ==
"QT_PREPEND_NAMESPACE")
215 || (previousLexeme() ==
"NS"))) {
218 type.append(previousLexeme());
221 type.append(previousLexeme());
224 type.append(previousLexeme());
229 type.append(previousLexeme());
232 matchTemplateAngles(type);
234 while (match(Tok_const) || match(Tok_volatile))
235 type.append(previousLexeme());
238 type.append(previousLexeme());
243 while (match(Tok_Ampersand) || match(Tok_Aster) || match(Tok_const) || match(Tok_Caret)
244 || match(Tok_Ellipsis))
245 type.append(previousLexeme());
249
250
251
252
253
255 type.append(previousLexeme());
256 type.appendHotspot();
257 if (match(Tok_Ident))
258 name = previousLexeme();
261 type.append(previousLexeme());
264 type.append(previousLexeme());
269 if (!matchTypeAndName(type, dummy))
271 if (match(Tok_Comma))
272 type.append(previousLexeme());
276 type.append(previousLexeme());
279
280
281
282 type.appendHotspot();
285 name = previousLexeme();
288 auto match = s_varComment.match(previousLexeme());
289 if (match.hasMatch())
290 name = match.captured(1);
294 name.append(lexeme());
302 name.append(lexeme());
314 type.append(lexeme());
323
324
325
326
330 m_privateSignal =
true;
336 if (!matchTypeAndName(chunk, name))
338 QString type = chunk.toString();
339 QString defaultValue;
347 chunk.append(lexeme());
350 defaultValue = chunk.toString();
352 append(type, name, defaultValue);
357
358
359
360
361
362bool Parameters::parse(
const QString &signature)
365 int outerTok = m_tok;
367 const QByteArray &latin1 = signature.toLatin1();
370 m_tokenizer = &stringTokenizer;
374 if (!matchParameter()) {
375 m_parameters.clear();
381 m_tokenizer = outerTokenizer;
387
388
389
392 m_parameters.append(
Parameter(type, name, value));
396
397
398
402 if (!m_parameters.empty()) {
403 for (
int i = 0; i < m_parameters.size(); i++) {
406 result += m_parameters.at(i).signature(includeValues);
413
414
415
416
417
418
419
423 const auto params = m_parameters;
424 for (
const auto ¶meter : params) {
425 raw += parameter.type();
427 raw += parameter.name();
429 raw += parameter.defaultValue();
435
436
437
438
439
440
444 if (!signature.isEmpty()) {
445 QStringList commaSplit = signature.split(
',');
446 m_parameters.resize(commaSplit.size());
448 for (
const auto &item : std::as_const(commaSplit)) {
449 QStringList blankSplit = item.split(
' ', Qt::SkipEmptyParts);
451 qsizetype defaultIdx = blankSplit.indexOf(QStringLiteral(
"="));
452 if (defaultIdx != -1) {
453 if (++defaultIdx < blankSplit.size())
454 pDefault = blankSplit.mid(defaultIdx).join(
' ');
455 blankSplit = blankSplit.mid(0, defaultIdx - 1);
457 QString pName = blankSplit.takeLast();
458 QString pType = blankSplit.join(
' ');
459 if (pType.isEmpty() && pName == QLatin1String(
"..."))
463 while (j < pName.size() && !pName.at(j).isLetter())
466 pType += QChar(
' ') + pName.left(j);
467 pName = pName.mid(j);
470 m_parameters[i++].set(pType, pName, pDefault);
476
477
481 const auto params = m_parameters;
482 for (
const auto ¶meter : params) {
483 if (!parameter.name().isEmpty())
484 names.insert(parameter.name());
490
491
496 for (
int i = 0; i <
count(); ++i) {
499 out += m_parameters.at(i).type();
506
507
508
513 for (
int i = 0; i <
count(); ++i) {
518 if (out[out.size() - 1].isLetterOrNumber())
519 out += QLatin1Char(
' ');
527
528
529
536 for (
int i = 0; i <
count(); i++) {
537 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.
void setParsingFnOrMacro(bool macro)
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...