From 324f918438715b4a0d024af5930628c1674f4fcd Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 19 Jan 2019 08:50:56 +0000 Subject: Update the file headers across all of the LLVM projects in the monorepo to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/WhitespaceManager.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/Format/WhitespaceManager.cpp') diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 032b133332..7b649c95fd 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -1,9 +1,8 @@ //===--- WhitespaceManager.cpp - Format C++ code --------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// -- cgit v1.2.3 From 62964850c878e71ca8497b17336232d870afae2f Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Fri, 15 Feb 2019 23:07:43 +0000 Subject: clang-format with UseTab: Always sometimes doesn't insert the right amount of tabs. Trailing comments are not always aligned properly when UseTab is set to Always. Consider: int a; // x int bbbbbbbb; // x With .clang-format: --- Language: Cpp BasedOnStyle: LLVM UseTab: Always ... The trailing comments of this code block should be aligned, but aren't To align the first trailing comment it needs to insert 8 spaces. This should be one tab plus six spaces. It skips the logic of the first partial tab in FirstTabWidth (=2) + Style.TabWidth (=8) <= Spaces (=8) and only inserts one tab. Proposed fix and test is attached. Patch by Hylke Kleve. Differential revision: https://reviews.llvm.org/D57655 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354183 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/WhitespaceManager.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/Format/WhitespaceManager.cpp') diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 7b649c95fd..44aa46f1f6 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -679,11 +679,15 @@ void WhitespaceManager::appendIndentText(std::string &Text, case FormatStyle::UT_Always: { unsigned FirstTabWidth = Style.TabWidth - WhitespaceStartColumn % Style.TabWidth; - // Indent with tabs only when there's at least one full tab. - if (FirstTabWidth + Style.TabWidth <= Spaces) { - Spaces -= FirstTabWidth; - Text.append("\t"); + // Insert only spaces when we want to end up before the next tab. + if (Spaces < FirstTabWidth || Spaces == 1) { + Text.append(Spaces, ' '); + break; } + // Align to the next tab. + Spaces -= FirstTabWidth; + Text.append("\t"); + Text.append(Spaces / Style.TabWidth, '\t'); Text.append(Spaces % Style.TabWidth, ' '); break; -- cgit v1.2.3 From 70f886033a4637e1fb6e4b8ab1fad09a3dcca5a7 Mon Sep 17 00:00:00 2001 From: Paul Hoad Date: Fri, 1 Mar 2019 09:09:54 +0000 Subject: [clang-format] [NFC] clang-format the Format library Previously revisions commited non-clang-formatted changes to the Format library, this means submitting any revision e.g. {D55170} can cause additional whitespace changes to potentially be included in a revision. Commit a non functional change using latest build Windows clang-format r351376 with no other changes, to remove these differences All FormatTests pass [==========] 652 tests from 20 test cases ran. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355182 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/WhitespaceManager.cpp | 55 ++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'lib/Format/WhitespaceManager.cpp') diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 44aa46f1f6..9f1ea7022f 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -432,19 +432,20 @@ void WhitespaceManager::alignConsecutiveAssignments() { if (!Style.AlignConsecutiveAssignments) return; - AlignTokens(Style, - [&](const Change &C) { - // Do not align on equal signs that are first on a line. - if (C.NewlinesBefore > 0) - return false; - - // Do not align on equal signs that are last on a line. - if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0) - return false; - - return C.Tok->is(tok::equal); - }, - Changes, /*StartAt=*/0); + AlignTokens( + Style, + [&](const Change &C) { + // Do not align on equal signs that are first on a line. + if (C.NewlinesBefore > 0) + return false; + + // Do not align on equal signs that are last on a line. + if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0) + return false; + + return C.Tok->is(tok::equal); + }, + Changes, /*StartAt=*/0); } void WhitespaceManager::alignConsecutiveDeclarations() { @@ -457,15 +458,16 @@ void WhitespaceManager::alignConsecutiveDeclarations() { // const char* const* v1; // float const* v2; // SomeVeryLongType const& v3; - AlignTokens(Style, - [](Change const &C) { - // tok::kw_operator is necessary for aligning operator overload - // definitions. - return C.Tok->is(TT_StartOfName) || - C.Tok->is(TT_FunctionDeclarationName) || - C.Tok->is(tok::kw_operator); - }, - Changes, /*StartAt=*/0); + AlignTokens( + Style, + [](Change const &C) { + // tok::kw_operator is necessary for aligning operator overload + // definitions. + return C.Tok->is(TT_StartOfName) || + C.Tok->is(TT_FunctionDeclarationName) || + C.Tok->is(tok::kw_operator); + }, + Changes, /*StartAt=*/0); } void WhitespaceManager::alignTrailingComments() { @@ -541,11 +543,10 @@ void WhitespaceManager::alignTrailingComments() { MinColumn = std::max(MinColumn, ChangeMinColumn); MaxColumn = std::min(MaxColumn, ChangeMaxColumn); } - BreakBeforeNext = - (i == 0) || (Changes[i].NewlinesBefore > 1) || - // Never start a sequence with a comment at the beginning of - // the line. - (Changes[i].NewlinesBefore == 1 && StartOfSequence == i); + BreakBeforeNext = (i == 0) || (Changes[i].NewlinesBefore > 1) || + // Never start a sequence with a comment at the beginning + // of the line. + (Changes[i].NewlinesBefore == 1 && StartOfSequence == i); Newlines = 0; } alignTrailingComments(StartOfSequence, Changes.size(), MinColumn); -- cgit v1.2.3 From c93a7477d59bf70daf83a5d8c32c65dcc9590388 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Wed, 1 May 2019 18:23:44 +0000 Subject: [clang-format] Fix a bug in AlignConsecutiveDeclarations. Fixes PR37175 Differential Revision: https://reviews.llvm.org/D61222 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359711 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/WhitespaceManager.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib/Format/WhitespaceManager.cpp') diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 9f1ea7022f..5383addd7e 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -463,9 +463,21 @@ void WhitespaceManager::alignConsecutiveDeclarations() { [](Change const &C) { // tok::kw_operator is necessary for aligning operator overload // definitions. - return C.Tok->is(TT_StartOfName) || - C.Tok->is(TT_FunctionDeclarationName) || - C.Tok->is(tok::kw_operator); + if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + return true; + if (C.Tok->isNot(TT_StartOfName)) + return false; + // Check if there is a subsequent name that starts the same declaration. + for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) { + if (Next->is(tok::comment)) + continue; + if (!Next->Tok.getIdentifierInfo()) + break; + if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName, + tok::kw_operator)) + return false; + } + return true; }, Changes, /*StartAt=*/0); } -- cgit v1.2.3