Skip to content

Commit

Permalink
[clang-format] Add MacroUnexpander.
Browse files Browse the repository at this point in the history
MacroUnexpander applies the structural formatting of expanded lines into
UnwrappedLines to the corresponding unexpanded macro calls, resulting in
UnwrappedLines for the macro calls the user typed.

Differential Revision: https://reviews.llvm.org/D88299
  • Loading branch information
r4nt committed Jul 12, 2022
1 parent ad3a078 commit d6d0dc1
Show file tree
Hide file tree
Showing 7 changed files with 1,529 additions and 19 deletions.
1 change: 1 addition & 0 deletions clang/lib/Format/CMakeLists.txt
Expand Up @@ -8,6 +8,7 @@ add_clang_library(clangFormat
Format.cpp
FormatToken.cpp
FormatTokenLexer.cpp
MacroCallReconstructor.cpp
MacroExpander.cpp
NamespaceEndCommentsFixer.cpp
QualifierAlignmentFixer.cpp
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/Format/FormatToken.h
Expand Up @@ -497,6 +497,15 @@ struct FormatToken {
// in a configured macro expansion.
llvm::Optional<MacroExpansion> MacroCtx;

/// When macro expansion introduces nodes with children, those are marked as
/// \c MacroParent.
/// FIXME: The formatting code currently hard-codes the assumption that
/// child nodes are introduced by blocks following an opening brace.
/// This is deeply baked into the code and disentangling this will require
/// signficant refactorings. \c MacroParent allows us to special-case the
/// cases in which we treat parents as block-openers for now.
bool MacroParent = false;

bool is(tok::TokenKind Kind) const { return Tok.is(Kind); }
bool is(TokenType TT) const { return getType() == TT; }
bool is(const IdentifierInfo *II) const {
Expand Down

0 comments on commit d6d0dc1

Please sign in to comment.