diff options
author | Paul Wicking <paul.wicking@qt.io> | 2023-03-05 14:09:10 +0100 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2023-03-08 16:42:35 +0100 |
commit | 4b92acd101766af02257319a94598f49b0a55bf9 (patch) | |
tree | 0599c86de52128eb68a966e835f6f30cf9a633a8 | |
parent | 58b7aef1d443e338b8aa638233a47635df14a5f9 (diff) | |
download | qttools-4b92acd101766af02257319a94598f49b0a55bf9.tar.gz |
QDoc: flatten loop in PureDocParser::processQdocComments
TLDR; Inverse the conditional to continue the while early, in order
to flatten the rest of the method.
PureDocParser::processQdocComments consists of a while loop over
a token. For any token that isn't Tok_Doc, get the next token and
continue. Tok_Doc tokens are processed, and this processing
constitutes the bulk of the method.
Inverse the logic of the conditional to allow an early continue. This
allows for dropping the else branch entirely, and makes it clear early
on that the method is only interested in Toc_Doc. Another advantage is
that the bulk of the method can be dedented to the main scope of the
while loop, reducing the cognitive load for readers of this code.
Change-Id: I01c9d3f547cd7610aa5adc19ffac456096f0a427
Reviewed-by: Luca Di Sera <luca.disera@qt.io>
-rw-r--r-- | src/qdoc/puredocparser.cpp | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/qdoc/puredocparser.cpp b/src/qdoc/puredocparser.cpp index 09f9fe30f..7bbc17b73 100644 --- a/src/qdoc/puredocparser.cpp +++ b/src/qdoc/puredocparser.cpp @@ -60,36 +60,36 @@ void PureDocParser::processQdocComments(QFile& input_file) int token = tokenizer.getToken(); while (token != Tok_Eoi) { - if (token == Tok_Doc) { - QString comment = tokenizer.lexeme(); // returns an entire qdoc comment. - Location start_loc(tokenizer.location()); - token = tokenizer.getToken(); - - Doc::trimCStyleComment(start_loc, comment); - Location end_loc(tokenizer.location()); - - // Doc constructor parses the comment. - Doc doc(start_loc, end_loc, comment, commands, topicCommands()); - const TopicList &topics = doc.topicsUsed(); - if (topics.isEmpty()) { - doc.location().warning(QStringLiteral("This qdoc comment contains no topic command " - "(e.g., '\\%1', '\\%2').") - .arg(COMMAND_MODULE, COMMAND_PAGE)); - continue; - } - - if (hasTooManyTopics(doc)) - continue; - - DocList docs; - NodeList nodes; - QString topic = topics[0].m_topic; - - processTopicArgs(doc, topic, nodes, docs); - processMetaCommands(nodes, docs); - } else { + if (token != Tok_Doc) { token = tokenizer.getToken(); + continue; + } + QString comment = tokenizer.lexeme(); // returns an entire qdoc comment. + Location start_loc(tokenizer.location()); + token = tokenizer.getToken(); + + Doc::trimCStyleComment(start_loc, comment); + Location end_loc(tokenizer.location()); + + // Doc constructor parses the comment. + Doc doc(start_loc, end_loc, comment, commands, topicCommands()); + const TopicList &topics = doc.topicsUsed(); + if (topics.isEmpty()) { + doc.location().warning(QStringLiteral("This qdoc comment contains no topic command " + "(e.g., '\\%1', '\\%2').") + .arg(COMMAND_MODULE, COMMAND_PAGE)); + continue; } + + if (hasTooManyTopics(doc)) + continue; + + DocList docs; + NodeList nodes; + QString topic = topics[0].m_topic; + + processTopicArgs(doc, topic, nodes, docs); + processMetaCommands(nodes, docs); } } |