[clang-format] Allow to set token types final
authorBjörn Schäpers <bjoern@hazardy.de>
Thu, 24 Feb 2022 07:57:03 +0000 (08:57 +0100)
committerBjörn Schäpers <bjoern@hazardy.de>
Tue, 1 Mar 2022 20:55:31 +0000 (21:55 +0100)
commit1e7cc72ac91d524da80ec6e144dce925a27090fc
tree94e87e8e534b03df9aae420f2da472a43e8e8be9
parentf642436cc213f99a90e3a4258666dd693b29d79d
[clang-format] Allow to set token types final

We have a little problem. TokenAnnotator::resetTokenMetadata() resets
the type, except for a (growing) whitelist. This is because the
TokenAnnotator visits some tokens multiple times. E.g. trying to
identify if a < is an operator less or a template opener. And in some
runs, which are bascially "reverted" the types are reset.

On the other hand, if the parser does already know the type, it should
be able to set it, without it being reset. So we introduce the ability
to set a type and make that final.

Differential Revision: https://reviews.llvm.org/D120511
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp