16
17
18
19
20
21
22
23
24
25
26
27
35 : m_valid(
true), m_privateSignal(
false), m_tok(0), m_tokenizer(
nullptr)
37 if (!signature.isEmpty()) {
38 if (!parse(signature)) {
46
47
48
55
56
59 return m_tokenizer->lexeme();
63
64
67 return m_tokenizer->previousLexeme();
71
72
73
74
77 if (m_tok == target) {
85
86
87
88
89
90
91
92
93
94
95
96
97void Parameters::matchTemplateAngles(CodeChunk &type)
100 int leftAngleDepth = 0;
101 int parenAndBraceDepth = 0;
108 ++parenAndBraceDepth;
110 if (--parenAndBraceDepth < 0)
113 type.append(lexeme());
115 }
while (leftAngleDepth > 0 && m_tok !=
Tok_Eoi);
120
121
122
123bool Parameters::matchTypeAndName(CodeChunk &type, QString &name)
126
127
128
134
135
136
137
142
143
144
146 type.append(previousLexeme());
154 type.append(pending);
156 type.append(lexeme());
161 if (!pending.isEmpty()) {
162 type.append(pending);
166 type.append(previousLexeme());
169 type.append(previousLexeme());
175
176
177
178
180 && ((previousLexeme() ==
"QT_PREPEND_NAMESPACE")
181 || (previousLexeme() ==
"NS"))) {
184 type.append(previousLexeme());
187 type.append(previousLexeme());
190 type.append(previousLexeme());
195 type.append(previousLexeme());
198 matchTemplateAngles(type);
201 type.append(previousLexeme());
204 type.append(previousLexeme());
211 type.append(previousLexeme());
215
216
217
218
219
221 type.append(previousLexeme());
222 type.appendHotspot();
223 if (match(Tok_Ident))
224 name = previousLexeme();
227 type.append(previousLexeme());
230 type.append(previousLexeme());
235 if (!matchTypeAndName(type, dummy))
238 type.append(previousLexeme());
242 type.append(previousLexeme());
245
246
247
248 type.appendHotspot();
251 name = previousLexeme();
254 auto match = s_varComment.match(previousLexeme());
255 if (match.hasMatch())
256 name = match.captured(1);
260 name.append(lexeme());
268 name.append(lexeme());
280 type.append(lexeme());
289
290
291
292
296 m_privateSignal =
true;
302 if (!matchTypeAndName(chunk, name))
304 QString type = chunk.toString();
305 QString defaultValue;
313 chunk.append(lexeme());
316 defaultValue = chunk.toString();
318 append(type, name, defaultValue);
323
324
325
326
327
328bool Parameters::parse(
const QString &signature)
331 int outerTok = m_tok;
333 const QByteArray &latin1 = signature.toLatin1();
336 m_tokenizer = &stringTokenizer;
340 if (!matchParameter()) {
341 m_parameters.clear();
347 m_tokenizer = outerTokenizer;
353
354
355
358 m_parameters.append(
Parameter(type, name, value));
362
363
364
368 if (!m_parameters.empty()) {
369 for (
int i = 0; i < m_parameters.size(); i++) {
372 result += m_parameters.at(i).signature(includeValues);
379
380
381
382
383
384
385
389 const auto params = m_parameters;
390 for (
const auto ¶meter : params) {
391 raw += parameter.type();
393 raw += parameter.name();
395 raw += parameter.defaultValue();
401
402
403
404
405
406
410 if (!signature.isEmpty()) {
411 QStringList commaSplit = signature.split(
',');
412 m_parameters.resize(commaSplit.size());
414 for (
const auto &item : std::as_const(commaSplit)) {
415 QStringList blankSplit = item.split(
' ', Qt::SkipEmptyParts);
417 qsizetype defaultIdx = blankSplit.indexOf(QStringLiteral(
"="));
418 if (defaultIdx != -1) {
419 if (++defaultIdx < blankSplit.size())
420 pDefault = blankSplit.mid(defaultIdx).join(
' ');
421 blankSplit = blankSplit.mid(0, defaultIdx - 1);
423 QString pName = blankSplit.takeLast();
424 QString pType = blankSplit.join(
' ');
425 if (pType.isEmpty() && pName == QLatin1String(
"..."))
429 while (j < pName.size() && !pName.at(j).isLetter())
432 pType += QChar(
' ') + pName.left(j);
433 pName = pName.mid(j);
436 m_parameters[i++].set(pType, pName, pDefault);
442
443
447 const auto params = m_parameters;
448 for (
const auto ¶meter : params) {
449 if (!parameter.name().isEmpty())
450 names.insert(parameter.name());
456
457
462 for (
int i = 0; i <
count(); ++i) {
465 out += m_parameters.at(i).type();
472
473
474
479 for (
int i = 0; i <
count(); ++i) {
484 if (out[out.size() - 1].isLetterOrNumber())
485 out += QLatin1Char(
' ');
493
494
495
496
497
506 for (
int i = 0; i < n; ++i) {
509 const QString &name = m_parameters.at(i).name();
511 out += QString(
"arg%1").arg(i + 1);
519
520
521
524 return std::equal(m_parameters.cbegin(), m_parameters.cend(), parameters.m_parameters.cbegin(),
525 parameters.m_parameters.cend(),
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...