[PATCH] D120034: [clang-format] PROPOSAL - WIP: Added ability to parse template arguments
Björn Schäpers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 17 03:13:53 PST 2022
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, curdeius, MyDeveloperDay.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Obviously not implemented yet.
For https://github.com/llvm/llvm-project/issues/53864 I need to get the end of the requires clause at the end of the nested template. But `parseBracedList()` just ends on the first `>` it finds.
Simply extending it the be recursive on `<` wouldn't work, since we have to determine if `<` is a `less` or a template opener. Analogous for `>`. Currently we have `TokenAnnotator::parseAngle` to deal with this stuff. Including `// FIXME: This is getting out of hand, write a decent parser.`
So my proposal is to add this parsing in `UnwrappedLineParser` and set `TT_TemplateOpener` and `TT_TempalteCloser` already there.
This is going to be a huge change, so I ask for your opinion before I put a lot of effort into that.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D120034
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
Index: clang/lib/Format/UnwrappedLineParser.h
===================================================================
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -118,6 +118,7 @@
tok::TokenKind ClosingBraceKind = tok::r_brace);
void parseParens(TokenType AmpAmpTokenType = TT_Unknown);
void parseSquare(bool LambdaIntroducer = false);
+ void parseTemplateArguments();
void keepAncestorBraces();
FormatToken *parseIfThenElse(IfStmtKind *IfKind, bool KeepBraces = false);
void parseTryCatch();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2289,6 +2289,21 @@
} while (!eof());
}
+/// \brief Parses a template arguments, that is from the opening < to the
+/// closing >. Returns when it succesfully read the template arguments or
+/// detected that it's not a template argument list.
+void clang::format::UnwrappedLineParser::parseTemplateArguments() {
+ assert(FormatTok->is(tok::less) && "'<' expected.");
+ assert(FormatTok->is(TT_Unknown) && "Type already set on '<'");
+ auto OpeningAngle = FormatTok;
+ nextToken();
+
+
+ do {
+ //Do stuff
+ } while (!eof());
+}
+
void UnwrappedLineParser::keepAncestorBraces() {
if (!Style.RemoveBracesLLVM)
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120034.409563.patch
Type: text/x-patch
Size: 1423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220217/5943fafc/attachment.bin>
More information about the cfe-commits
mailing list