diff options
author | Owen Pan <owenpiano@gmail.com> | 2023-07-14 01:25:34 -0700 |
---|---|---|
committer | Owen Pan <owenpiano@gmail.com> | 2023-07-18 14:18:40 -0700 |
commit | 5c106f7b947e514852402ad5678c0ebf70ce91b1 (patch) | |
tree | 173900800b3bf31e5486809a6761a82793443cab /clang/lib/Format/FormatTokenLexer.cpp | |
parent | a060102b3cb09d0710a58f783e18679858b3fdfc (diff) | |
download | llvm-5c106f7b947e514852402ad5678c0ebf70ce91b1.zip llvm-5c106f7b947e514852402ad5678c0ebf70ce91b1.tar.gz llvm-5c106f7b947e514852402ad5678c0ebf70ce91b1.tar.bz2 |
[clang-format] Add TypeNames option to disambiguate types/objects
If a non-keyword identifier is found in TypeNames, then a *, &, or && that
follows it is annotated as TT_PointerOrReference.
Differential Revision: https://reviews.llvm.org/D155273
Diffstat (limited to 'clang/lib/Format/FormatTokenLexer.cpp')
-rw-r--r-- | clang/lib/Format/FormatTokenLexer.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index ae54de9..4d43796 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -71,6 +71,9 @@ FormatTokenLexer::FormatTokenLexer( auto Identifier = &IdentTable.get(StatementAttributeLikeMacro); Macros.insert({Identifier, TT_StatementAttributeLikeMacro}); } + + for (const auto &TypeName : Style.TypeNames) + TypeNames.insert(&IdentTable.get(TypeName)); } ArrayRef<FormatToken *> FormatTokenLexer::lex() { @@ -1222,7 +1225,8 @@ FormatToken *FormatTokenLexer::getNextToken() { } if (Style.isCpp()) { - auto it = Macros.find(FormatTok->Tok.getIdentifierInfo()); + auto *Identifier = FormatTok->Tok.getIdentifierInfo(); + auto it = Macros.find(Identifier); if (!(Tokens.size() > 0 && Tokens.back()->Tok.getIdentifierInfo() && Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() == tok::pp_define) && @@ -1240,6 +1244,8 @@ FormatToken *FormatTokenLexer::getNextToken() { FormatTok->setType(TT_MacroBlockBegin); else if (MacroBlockEndRegex.match(Text)) FormatTok->setType(TT_MacroBlockEnd); + else if (TypeNames.contains(Identifier)) + FormatTok->setFinalizedType(TT_TypeName); } } |