Commit 2aaaed16 authored by Igor Kushnir's avatar Igor Kushnir
Browse files

Don't use findClose() before ParamIterator()

ParamIterator::position() returns the position just after the closing
parenthesis. Use this information instead of looking for ')' twice. This
is both more efficient and less verbose.
parent f6f07a4f
Pipeline #251045 canceled with stage
in 55 seconds
......@@ -1116,24 +1116,21 @@ void Visitor::setDeclData(CXCursor cursor, MacroDefinition* decl) const
decl->setFunctionLike(true);
const auto openingParen = posAfterMacroId;
const auto closingParen = findClose(contents, openingParen);
if (closingParen == -1) {
// unlikely: invalid macro definition, insert the complete #define statement
const QString definition = QLatin1String("#define ") + contents;
setDefinition(definition);
return;
}
setDefinition(contents.mid(closingParen + 1));
// extract macro function parameters
const auto parameters = contents.mid(openingParen, closingParen - openingParen + 1); // include both '(' and ')'
ParamIterator paramIt(u"()", parameters, 0);
ParamIterator paramIt(u"()", contents, posAfterMacroId);
while (paramIt) {
decl->addParameter(IndexedString(*paramIt));
++paramIt;
}
const auto paramEndPosition = paramIt.position();
if (paramEndPosition > 0 && contents[paramEndPosition - 1] == QLatin1Char{')'}) {
setDefinition(contents.mid(paramEndPosition));
} else {
// unlikely: invalid macro definition, insert the complete #define statement
const QString definition = QLatin1String("#define ") + contents;
setDefinition(definition);
}
}
template<CXCursorKind CK>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment