diff --git a/clang/lib/Format/.clang-format b/clang/lib/Format/.clang-format new file mode 100644 --- /dev/null +++ b/clang/lib/Format/.clang-format @@ -0,0 +1,3 @@ +BasedOnStyle: LLVM +InsertBraces: true +RemoveBracesLLVM: true diff --git a/clang/lib/Format/MacroCallReconstructor.cpp b/clang/lib/Format/MacroCallReconstructor.cpp --- a/clang/lib/Format/MacroCallReconstructor.cpp +++ b/clang/lib/Format/MacroCallReconstructor.cpp @@ -35,9 +35,8 @@ for (const auto &N : Line.Tokens) { Call(N.Tok, Parent, First); First = false; - for (const auto &Child : N.Children) { + for (const auto &Child : N.Children) forEachToken(Child, Call, N.Tok); - } } } @@ -61,7 +60,8 @@ UnwrappedLine MacroCallReconstructor::takeResult() && { finalize(); - assert(Result.Tokens.size() == 1 && Result.Tokens.front()->Children.size() == 1); + assert(Result.Tokens.size() == 1 && + Result.Tokens.front()->Children.size() == 1); UnwrappedLine Final = createUnwrappedLine(*Result.Tokens.front()->Children.front(), Level); assert(!Final.Tokens.empty()); @@ -194,9 +194,8 @@ FormatToken *Mapped = SpelledParentToReconstructedParent.lookup(Parent); if (!Mapped) return Parent; - for (; Mapped; Mapped = SpelledParentToReconstructedParent.lookup(Parent)) { + for (; Mapped; Mapped = SpelledParentToReconstructedParent.lookup(Parent)) Parent = Mapped; - } // If we use a different token than the parent in the expanded token stream // as parent, mark it as a special parent, so the formatting code knows it // needs to have its children formatted. @@ -216,9 +215,8 @@ // If the order of tokens in the expanded token stream is not the // same as the order of tokens in the reconstructed stream, we need // to reconstruct tokens that arrive later in the stream. - if (Token->MacroCtx->Role != MR_Hidden) { + if (Token->MacroCtx->Role != MR_Hidden) reconstructActiveCallUntil(Token); - } } assert(!ActiveExpansions.empty()); if (ActiveExpansions.back().SpelledI != ActiveExpansions.back().SpelledE) { @@ -334,9 +332,8 @@ bool PreviousLevel = Token->MacroCtx && (ActiveExpansions.size() < Token->MacroCtx->ExpandedFrom.size()); - if (!ClosingParen && !TrailingComment && !PreviousLevel) { + if (!ClosingParen && !TrailingComment && !PreviousLevel) llvm::dbgs() << "At token: " << Token->TokenText << "\n"; - } // In addition to the following cases, we can also run into this // when a macro call had more arguments than expected; in that case, // the comma and the remaining tokens in the macro call will potentially @@ -392,9 +389,8 @@ ++ActiveExpansions.back().SpelledI; if (Token->MacroCtx) { // Skip tokens that are not part of the macro call. - if (Token->MacroCtx->Role == MR_Hidden) { + if (Token->MacroCtx->Role == MR_Hidden) return false; - } // Skip tokens we already expanded during an inner reconstruction. // For example, given: #define ID(x) {x} // And the call: ID(ID(f)) @@ -403,9 +399,8 @@ // ID({f}) -> {{f}} // We reconstruct f during the first reconstruction, and skip it during the // second reconstruction. - if (ActiveExpansions.size() < Token->MacroCtx->ExpandedFrom.size()) { + if (ActiveExpansions.size() < Token->MacroCtx->ExpandedFrom.size()) return false; - } } // Tokens that do not have a macro context are tokens in that are part of the // macro call that have not taken part in expansion. diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2069,8 +2069,9 @@ // type[] a in Java if (Style.Language == FormatStyle::LK_Java && - PreviousNotConst->is(tok::r_square)) + PreviousNotConst->is(tok::r_square)) { return true; + } // const a = in JavaScript. return Style.isJavaScript() && PreviousNotConst->is(tok::kw_const); @@ -2369,8 +2370,9 @@ // case, the matching `{` is on the same unwrapped line, so check for the // presence of the matching brace to distinguish between those. if (PrevToken->is(tok::r_brace) && Tok.is(tok::star) && - !PrevToken->MatchingParen) + !PrevToken->MatchingParen) { return TT_PointerOrReference; + } if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete)) return TT_UnaryOperator;