[PATCH] D44765: PR36643 Make clang-format support more generic TMarcos

Teodor Petrov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 29 11:35:27 PDT 2018


obfuscated added inline comments.


================
Comment at: lib/Format/FormatTokenLexer.cpp:386
   String->HasUnescapedNewline = Macro->HasUnescapedNewline;
+  String->TMacroStringLiteral = true;
 
----------------
krasimir wrote:
> In the original code, TMacro detection was done as:
> ```
> (Text.startswith(Prefix = "_T(\"") && Text.endswith(Postfix = "\")"))
> ```
> In the new code the left part is saved in TMacroStringLiteral, and the right part is checked in ContinuationIndenter. Could you keep them together in `FormatTokenLexer`.
> @alexfh, why are we checking for the right check at all? What would be an example where this is needed to disambiguate?
> 
Are you talking about the code in ContinuationIndenter::createBreakableToken?

I don't think I understand how the hole thing works.
Using the debugger I can see that this function is executed first and then createBreakableToken.
So we first detect the tmacro in FormatTokenLexer::tryMerge_TMacro and then use this information in the createBreakableToken to do something with it.

So when I get a TMacroStringLiteral==true in createBreakableToken I know that the token starts with a TMacro and there is no need to use some king of startswith calls. Probably the endswith call is redundant and I can do just a string search backwards...


https://reviews.llvm.org/D44765





More information about the cfe-commits mailing list