11using namespace Qt::Literals::StringLiterals;
18
19
20
21
22
23
24
25
26
27
28
29
37 : m_valid(
true), m_privateSignal(
false), m_tok(0), m_tokenizer(
nullptr)
39 if (!signature.isEmpty()) {
40 if (!parse(signature)) {
48
49
50
57
58
61 return m_tokenizer->lexeme();
65
66
69 return m_tokenizer->previousLexeme();
73
74
75
76
79 if (m_tok == target) {
87
88
89
90
91
92
93
94
95
96
97
98
99void Parameters::matchTemplateAngles(CodeChunk &type)
102 int leftAngleDepth = 0;
103 int parenAndBraceDepth = 0;
110 ++parenAndBraceDepth;
112 if (--parenAndBraceDepth < 0)
115 type.append(lexeme());
117 }
while (leftAngleDepth > 0 && m_tok !=
Tok_Eoi);
122
123
124
125bool Parameters::matchTypeAndName(CodeChunk &type, QString &name)
128
129
130
136
137
138
139
144
145
146
148 type.append(previousLexeme());
156 type.append(pending);
158 type.append(lexeme());
163 if (!pending.isEmpty()) {
164 type.append(pending);
168 type.append(previousLexeme());
171 type.append(previousLexeme());
177
178
179
180
182 && ((previousLexeme() ==
"QT_PREPEND_NAMESPACE")
183 || (previousLexeme() ==
"NS"))) {
186 type.append(previousLexeme());
189 type.append(previousLexeme());
192 type.append(previousLexeme());
197 type.append(previousLexeme());
200 matchTemplateAngles(type);
203 type.append(previousLexeme());
206 type.append(previousLexeme());
213 type.append(previousLexeme());
217
218
219
220
221
223 type.append(previousLexeme());
224 type.appendHotspot();
226 name = previousLexeme();
229 type.append(previousLexeme());
232 type.append(previousLexeme());
237 if (!matchTypeAndName(type, dummy))
240 type.append(previousLexeme());
244 type.append(previousLexeme());
247
248
249
250 type.appendHotspot();
253 name = previousLexeme();
256 auto match = s_varComment.match(previousLexeme());
257 if (match.hasMatch())
258 name = match.captured(1);
262 name.append(lexeme());
270 name.append(lexeme());
282 type.append(lexeme());
291
292
293
294
298 m_privateSignal =
true;
304 if (!matchTypeAndName(chunk, name))
306 QString type = chunk.toString();
307 QString defaultValue;
315 chunk.append(lexeme());
318 defaultValue = chunk.toString();
320 append(type, name, defaultValue);
325
326
327
328
329
330bool Parameters::parse(
const QString &signature)
333 int outerTok = m_tok;
335 const QByteArray &latin1 = signature.toLatin1();
338 m_tokenizer = &stringTokenizer;
342 if (!matchParameter()) {
343 m_parameters.clear();
349 m_tokenizer = outerTokenizer;
355
356
357
360 m_parameters.append(
Parameter(type, name, value));
364
365
366
370 if (!m_parameters.empty()) {
371 for (
int i = 0; i < m_parameters.size(); i++) {
374 result += m_parameters.at(i).signature(includeValues);
381
382
383
384
385
386
387
391 const auto params = m_parameters;
392 for (
const auto ¶meter : params) {
393 raw += parameter.type();
395 raw += parameter.name();
397 raw += parameter.defaultValue();
403
404
405
406
407
408
412 if (!signature.isEmpty()) {
413 QStringList commaSplit = signature.split(
',');
414 m_parameters.resize(commaSplit.size());
416 for (
const auto &item : std::as_const(commaSplit)) {
417 QStringList blankSplit = item.split(
' ', Qt::SkipEmptyParts);
419 qsizetype defaultIdx = blankSplit.indexOf(QStringLiteral(
"="));
420 if (defaultIdx != -1) {
421 if (++defaultIdx < blankSplit.size())
422 pDefault = blankSplit.mid(defaultIdx).join(
' ');
423 blankSplit = blankSplit.mid(0, defaultIdx - 1);
425 QString pName = blankSplit.takeLast();
426 QString pType = blankSplit.join(
' ');
427 if (pType.isEmpty() && pName == QLatin1String(
"..."))
431 while (j < pName.size() && !pName.at(j).isLetter())
434 pType += QChar(
' ') + pName.left(j);
435 pName = pName.mid(j);
438 m_parameters[i++].set(pType, pName, pDefault);
444
445
449 const auto params = m_parameters;
450 for (
const auto ¶meter : params) {
451 if (!parameter.name().isEmpty())
452 names.insert(parameter.name());
458
459
464 for (
int i = 0; i <
count(); ++i) {
467 out += m_parameters.at(i).type();
474
475
476
481 for (
int i = 0; i <
count(); ++i) {
486 if (out[out.size() - 1].isLetterOrNumber())
487 out += QLatin1Char(
' ');
495
496
497
498
499
508 for (
int i = 0; i < n; ++i) {
511 const QString &name = m_parameters.at(i).name();
513 out += QString(
"arg%1").arg(i + 1);
521
522
523
526 return std::equal(m_parameters.cbegin(), m_parameters.cend(), parameters.m_parameters.cbegin(),
527 parameters.m_parameters.cend(),
532
533
534
535
536
537
538
539
540
543 if (!signature.endsWith(
')'_L1))
546 qsizetype position = signature.size() - 1;
549 while (position >= 0) {
550 if (signature.at(position) ==
')'_L1)
552 else if (signature.at(position) ==
'('_L1) {
563 for (qsizetype i = 0; i < position; ++i) {
564 if (signature.at(i) ==
'('_L1)
566 else if (signature.at(i) ==
')'_L1) {
575 QString parameters = signature.mid(position + 1, signature.size() - position - 2);
576 signature.truncate(position);
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.
\inmodule QtCore \reentrant
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 generateNameList() const
Construct a list of just the parameter names (without types) and return it.
QString generateTypeList() const
Construct a list of the parameter types and return it.
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...