11QRegularExpression
Parameters::s_varComment(R"(^/\*\s*([a-zA-Z_0-9]+)\s*\*/$)");
14
15
16
17
18
19
20
21
22
23
24
25
33 : m_valid(
true), m_privateSignal(
false), m_tok(0), m_tokenizer(
nullptr)
35 if (!signature.isEmpty()) {
36 if (!parse(signature)) {
44
45
46
53
54
57 return m_tokenizer->lexeme();
61
62
65 return m_tokenizer->previousLexeme();
69
70
71
72
75 if (m_tok == target) {
83
84
85
86
87
88
89
90
91
92
93
94
95void Parameters::matchTemplateAngles(CodeChunk &type)
98 int leftAngleDepth = 0;
99 int parenAndBraceDepth = 0;
106 ++parenAndBraceDepth;
108 if (--parenAndBraceDepth < 0)
111 type.append(lexeme());
113 }
while (leftAngleDepth > 0 && m_tok !=
Tok_Eoi);
118
119
120
121bool Parameters::matchTypeAndName(CodeChunk &type, QString &name)
124
125
126
132
133
134
135
140
141
142
144 type.append(previousLexeme());
152 type.append(pending);
154 type.append(lexeme());
159 if (!pending.isEmpty()) {
160 type.append(pending);
164 type.append(previousLexeme());
167 type.append(previousLexeme());
173
174
175
176
178 && ((previousLexeme() ==
"QT_PREPEND_NAMESPACE")
179 || (previousLexeme() ==
"NS"))) {
182 type.append(previousLexeme());
185 type.append(previousLexeme());
188 type.append(previousLexeme());
193 type.append(previousLexeme());
196 matchTemplateAngles(type);
199 type.append(previousLexeme());
202 type.append(previousLexeme());
209 type.append(previousLexeme());
213
214
215
216
217
219 type.append(previousLexeme());
220 type.appendHotspot();
221 if (match(Tok_Ident))
222 name = previousLexeme();
225 type.append(previousLexeme());
228 type.append(previousLexeme());
233 if (!matchTypeAndName(type, dummy))
236 type.append(previousLexeme());
240 type.append(previousLexeme());
243
244
245
246 type.appendHotspot();
249 name = previousLexeme();
252 auto match = s_varComment.match(previousLexeme());
253 if (match.hasMatch())
254 name = match.captured(1);
258 name.append(lexeme());
266 name.append(lexeme());
278 type.append(lexeme());
287
288
289
290
294 m_privateSignal =
true;
300 if (!matchTypeAndName(chunk, name))
302 QString type = chunk.toString();
303 QString defaultValue;
311 chunk.append(lexeme());
314 defaultValue = chunk.toString();
316 append(type, name, defaultValue);
321
322
323
324
325
326bool Parameters::parse(
const QString &signature)
329 int outerTok = m_tok;
331 const QByteArray &latin1 = signature.toLatin1();
334 m_tokenizer = &stringTokenizer;
338 if (!matchParameter()) {
339 m_parameters.clear();
345 m_tokenizer = outerTokenizer;
351
352
353
356 m_parameters.append(
Parameter(type, name, value));
360
361
362
366 if (!m_parameters.empty()) {
367 for (
int i = 0; i < m_parameters.size(); i++) {
370 result += m_parameters.at(i).signature(includeValues);
377
378
379
380
381
382
383
387 const auto params = m_parameters;
388 for (
const auto ¶meter : params) {
389 raw += parameter.type();
391 raw += parameter.name();
393 raw += parameter.defaultValue();
399
400
401
402
403
404
408 if (!signature.isEmpty()) {
409 QStringList commaSplit = signature.split(
',');
410 m_parameters.resize(commaSplit.size());
412 for (
const auto &item : std::as_const(commaSplit)) {
413 QStringList blankSplit = item.split(
' ', Qt::SkipEmptyParts);
415 qsizetype defaultIdx = blankSplit.indexOf(QStringLiteral(
"="));
416 if (defaultIdx != -1) {
417 if (++defaultIdx < blankSplit.size())
418 pDefault = blankSplit.mid(defaultIdx).join(
' ');
419 blankSplit = blankSplit.mid(0, defaultIdx - 1);
421 QString pName = blankSplit.takeLast();
422 QString pType = blankSplit.join(
' ');
423 if (pType.isEmpty() && pName == QLatin1String(
"..."))
427 while (j < pName.size() && !pName.at(j).isLetter())
430 pType += QChar(
' ') + pName.left(j);
431 pName = pName.mid(j);
434 m_parameters[i++].set(pType, pName, pDefault);
440
441
445 const auto params = m_parameters;
446 for (
const auto ¶meter : params) {
447 if (!parameter.name().isEmpty())
448 names.insert(parameter.name());
454
455
460 for (
int i = 0; i <
count(); ++i) {
463 out += m_parameters.at(i).type();
470
471
472
477 for (
int i = 0; i <
count(); ++i) {
482 if (out[out.size() - 1].isLetterOrNumber())
483 out += QLatin1Char(
' ');
491
492
493
494
495
504 for (
int i = 0; i < n; ++i) {
507 const QString &name = m_parameters.at(i).name();
509 out += QString(
"arg%1").arg(i + 1);
517
518
519
526 for (
int i = 0; i <
count(); i++) {
527 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.
void setParsingFnOrMacro(bool macro)
Combined button and popup list for selecting options.
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.
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...