[PATCH] D50410: Removing -debug-info-macros from option suggestions test
acoomans created this revision. acoomans added reviewers: cfe-commits, modocache. Herald added subscribers: dexonsmith, JDevlieghere, mehdi_amini. https://reviews.llvm.org/D46776 added support for "did you mean ...?" command line option suggestions. One of the tests was checking against the `-debug-info-macro` option, which was failing on the PS4 build bot. The same test would succeed again the `--help` and `--version` options. >From https://llvm.org/devmtg/2013-11/slides/Robinson-PS4Toolchain.pdf, it >looks like the PS4 SDK forces optimizations and could be disabling the >`-debug-info-macro` altogether. This diff removes `-debug-info-macro` altogether. Note: untested since we do not have access to a PS4 with the SDK. Repository: rC Clang https://reviews.llvm.org/D50410 Files: test/Driver/unknown-arg.c Index: test/Driver/unknown-arg.c === --- test/Driver/unknown-arg.c +++ test/Driver/unknown-arg.c @@ -14,7 +14,7 @@ // RUN: FileCheck %s --check-prefix=CL-ERROR-DID-YOU-MEAN // RUN: %clang_cl -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Wno-unknown-argument -### -- %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=SILENT -// RUN: not %clang -cc1as -hell --version -debug-info-macros 2>&1 | \ +// RUN: not %clang -cc1as -hell --version 2>&1 | \ // RUN: FileCheck %s --check-prefix=CC1AS-DID-YOU-MEAN // RUN: not %clang -cc1asphalt -help 2>&1 | \ // RUN: FileCheck %s --check-prefix=UNKNOWN-INTEGRATED Index: test/Driver/unknown-arg.c === --- test/Driver/unknown-arg.c +++ test/Driver/unknown-arg.c @@ -14,7 +14,7 @@ // RUN: FileCheck %s --check-prefix=CL-ERROR-DID-YOU-MEAN // RUN: %clang_cl -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Wno-unknown-argument -### -- %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=SILENT -// RUN: not %clang -cc1as -hell --version -debug-info-macros 2>&1 | \ +// RUN: not %clang -cc1as -hell --version 2>&1 | \ // RUN: FileCheck %s --check-prefix=CC1AS-DID-YOU-MEAN // RUN: not %clang -cc1asphalt -help 2>&1 | \ // RUN: FileCheck %s --check-prefix=UNKNOWN-INTEGRATED ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50410: Removing -debug-info-macros from option suggestions test
acoomans added a subscriber: probinson. acoomans added a comment. @probinson does this sound a plausible explanation? Do you have access to a PS4 SDK to confirm the `-debug-info-macro` isn't available at all? Repository: rC Clang https://reviews.llvm.org/D50410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49549: Change 'clang-test' to 'check-clang' on the hacking webpage
acoomans added a comment. Ping Repository: rC Clang https://reviews.llvm.org/D49549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49549: Change 'clang-test' to 'check-clang' on the hacking webpage
acoomans added a comment. @JDevlieghere Thanks! subscribers -> makes sense, will do Repository: rC Clang https://reviews.llvm.org/D49549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50515: Re-push "[Option] Fix PR37006 prefix choice in findNearest"
acoomans created this revision. acoomans added a reviewer: cfe-commits. Original changeset (https://reviews.llvm.org/D46776) by @modocache. It was reverted after the PS4 bot failed. The issue has been determined to be with the way the PS4 SDK handles this particular option. https://reviews.llvm.org/D50410 removes this test, so we can push this again. Repository: rC Clang https://reviews.llvm.org/D50515 Files: lib/Option/OptTable.cpp unittests/Option/OptionParsingTest.cpp unittests/Option/Opts.td Index: unittests/Option/Opts.td === --- unittests/Option/Opts.td +++ unittests/Option/Opts.td @@ -30,6 +30,7 @@ def SlurpJoined : Option<["-"], "slurpjoined", KIND_REMAINING_ARGS_JOINED>; def Blorp : Flag<["-", "--"], "blorp">, HelpText<"The blorp option">, Flags<[OptFlag1]>; +def Blarn : Flag<["--", "-"], "blarn">, HelpText<"The blarn option">, Flags<[OptFlag1]>; def Cramb : Joined<["/"], "cramb:">, HelpText<"The cramb option">, MetaVarName<"CRAMB">, Flags<[OptFlag1]>; def Doopf1 : Flag<["-"], "doopf1">, HelpText<"The doopf1 option">, Flags<[OptFlag1]>; def Doopf2 : Flag<["-"], "doopf2">, HelpText<"The doopf2 option">, Flags<[OptFlag2]>; Index: unittests/Option/OptionParsingTest.cpp === --- unittests/Option/OptionParsingTest.cpp +++ unittests/Option/OptionParsingTest.cpp @@ -283,6 +283,10 @@ EXPECT_EQ(Nearest, "-blorp"); EXPECT_EQ(1U, T.findNearest("--blorm", Nearest)); EXPECT_EQ(Nearest, "--blorp"); + EXPECT_EQ(1U, T.findNearest("-blarg", Nearest)); + EXPECT_EQ(Nearest, "-blarn"); + EXPECT_EQ(1U, T.findNearest("--blarm", Nearest)); + EXPECT_EQ(Nearest, "--blarn"); EXPECT_EQ(1U, T.findNearest("-fjormp", Nearest)); EXPECT_EQ(Nearest, "--fjormp"); Index: lib/Option/OptTable.cpp === --- lib/Option/OptTable.cpp +++ lib/Option/OptTable.cpp @@ -252,38 +252,33 @@ unsigned MinimumLength) const { assert(!Option.empty()); - // Consider each option as a candidate, finding the closest match. + // Consider each [option prefix + option name] pair as a candidate, finding + // the closest match. unsigned BestDistance = UINT_MAX; for (const Info &CandidateInfo : ArrayRef(OptionInfos).drop_front(FirstSearchableIndex)) { StringRef CandidateName = CandidateInfo.Name; -// Ignore option candidates with empty names, such as "--", or names -// that do not meet the minimum length. +// We can eliminate some option prefix/name pairs as candidates right away: +// * Ignore option candidates with empty names, such as "--", or names +// that do not meet the minimum length. if (CandidateName.empty() || CandidateName.size() < MinimumLength) continue; -// If FlagsToInclude were specified, ignore options that don't include -// those flags. +// * If FlagsToInclude were specified, ignore options that don't include +// those flags. if (FlagsToInclude && !(CandidateInfo.Flags & FlagsToInclude)) continue; -// Ignore options that contain the FlagsToExclude. +// * Ignore options that contain the FlagsToExclude. if (CandidateInfo.Flags & FlagsToExclude) continue; -// Ignore positional argument option candidates (which do not -// have prefixes). +// * Ignore positional argument option candidates (which do not +// have prefixes). if (!CandidateInfo.Prefixes) continue; -// Find the most appropriate prefix. For example, if a user asks for -// "--helm", suggest "--help" over "-help". -StringRef Prefix = CandidateInfo.Prefixes[0]; -for (int P = 1; CandidateInfo.Prefixes[P]; P++) { - if (Option.startswith(CandidateInfo.Prefixes[P])) -Prefix = CandidateInfo.Prefixes[P]; -} -// Check if the candidate ends with a character commonly used when +// Now check if the candidate ends with a character commonly used when // delimiting an option from its value, such as '=' or ':'. If it does, // attempt to split the given option based on that delimiter. std::string Delimiter = ""; @@ -297,14 +292,19 @@ else std::tie(LHS, RHS) = Option.split(Last); -std::string NormalizedName = -(LHS.drop_front(Prefix.size()) + Delimiter).str(); -unsigned Distance = -CandidateName.edit_distance(NormalizedName, /*AllowReplacements=*/true, -/*MaxEditDistance=*/BestDistance); -if (Distance < BestDistance) { - BestDistance = Distance; - NearestString = (Prefix + CandidateName + RHS).str(); +// Consider each possible prefix for each candidate to find the most +// appropriate one. For example, if a user asks for "--helm", suggest +// "--help" over "-help". +for (int P = 0; const char *const CandidatePrefix = CandidateInfo.Prefixes[
[PATCH] D50535: Fix selective formatting of ObjC scope
acoomans created this revision. acoomans added a reviewer: cfe-commits. ObjC scopes gets formatted beyond the `@end` directive, when formatting specific lines (`clang-format -lines=x:x`). This changeset fixes formatting of `@end` the same way that `r_braces` are. Repository: rC Clang https://reviews.llvm.org/D50535 Files: lib/Format/UnwrappedLineFormatter.cpp test/Format/adjust-indent-objc.m unittests/Format/FormatTestSelective.cpp Index: unittests/Format/FormatTestSelective.cpp === --- unittests/Format/FormatTestSelective.cpp +++ unittests/Format/FormatTestSelective.cpp @@ -584,6 +584,20 @@ 15, 0)); } +TEST_F(FormatTestSelective, StopFormattingWhenLeavingObjCScope) { +EXPECT_EQ("@protocol A\n" + " - (void)f;\n" + " - (void)g;\n" + "@end\n" + "MACRO", + format("@protocol A\n" + " - (void)f;\n" + "- (void)g;\n" // Format here. + "@end\n" + "MACRO", + 25, 0)); +} + TEST_F(FormatTestSelective, SelectivelyRequoteJavaScript) { Style = getGoogleStyle(FormatStyle::LK_JavaScript); EXPECT_EQ( Index: test/Format/adjust-indent-objc.m === --- /dev/null +++ test/Format/adjust-indent-objc.m @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -lines=4:4 \ +// RUN: | FileCheck -strict-whitespace %s + +@protocol A +// CHECK: @protocol A + @optional +// CHECK: {{^ @optional}} +- (void)f; +// CHECK: {{^ - \(void\)f;}} +@end +// CHECK: {{^@end}} +MACRO +// CHECK: {{^MACRO}} \ No newline at end of file Index: lib/Format/UnwrappedLineFormatter.cpp === --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -1042,6 +1042,10 @@ (TheLine.Level == RangeMinLevel && !PreviousRBrace && !TheLine.startsWith(tok::r_brace)); +if (TheLine.First->Next && TheLine.First->Next->Tok.isObjCAtKeyword(tok::objc_end)) { + ContinueFormatting = false; +} + bool FixIndentation = (FixBadIndentation || ContinueFormatting) && Indent != TheLine.First->OriginalColumn; bool ShouldFormat = TheLine.Affected || FixIndentation; Index: unittests/Format/FormatTestSelective.cpp === --- unittests/Format/FormatTestSelective.cpp +++ unittests/Format/FormatTestSelective.cpp @@ -584,6 +584,20 @@ 15, 0)); } +TEST_F(FormatTestSelective, StopFormattingWhenLeavingObjCScope) { +EXPECT_EQ("@protocol A\n" + " - (void)f;\n" + " - (void)g;\n" + "@end\n" + "MACRO", + format("@protocol A\n" + " - (void)f;\n" + "- (void)g;\n" // Format here. + "@end\n" + "MACRO", + 25, 0)); +} + TEST_F(FormatTestSelective, SelectivelyRequoteJavaScript) { Style = getGoogleStyle(FormatStyle::LK_JavaScript); EXPECT_EQ( Index: test/Format/adjust-indent-objc.m === --- /dev/null +++ test/Format/adjust-indent-objc.m @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -lines=4:4 \ +// RUN: | FileCheck -strict-whitespace %s + +@protocol A +// CHECK: @protocol A + @optional +// CHECK: {{^ @optional}} +- (void)f; +// CHECK: {{^ - \(void\)f;}} +@end +// CHECK: {{^@end}} +MACRO +// CHECK: {{^MACRO}} \ No newline at end of file Index: lib/Format/UnwrappedLineFormatter.cpp === --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -1042,6 +1042,10 @@ (TheLine.Level == RangeMinLevel && !PreviousRBrace && !TheLine.startsWith(tok::r_brace)); +if (TheLine.First->Next && TheLine.First->Next->Tok.isObjCAtKeyword(tok::objc_end)) { + ContinueFormatting = false; +} + bool FixIndentation = (FixBadIndentation || ContinueFormatting) && Indent != TheLine.First->OriginalColumn; bool ShouldFormat = TheLine.Affected || FixIndentation; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49580: [clang-format] Adding style option for absolute formatting
acoomans abandoned this revision. acoomans added a comment. Changed approach based on feedback. New changeset: https://reviews.llvm.org/D50535 https://reviews.llvm.org/D49580 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50535: Fix selective formatting of ObjC scope
acoomans added a comment. I probably don't need a unit test AND a lit test, but I'm unsure which one is best here. Any suggestion? Comment at: lib/Format/UnwrappedLineFormatter.cpp:1045-1047 +if (TheLine.First->Next && TheLine.First->Next->Tok.isObjCAtKeyword(tok::objc_end)) { + ContinueFormatting = false; +} Note to self: change the style to match `PreviousRBrace` Repository: rC Clang https://reviews.llvm.org/D50535 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50467: [SEMA] add more -Wfloat-conversion to compound assigment analysis
acoomans accepted this revision. acoomans added a comment. This revision is now accepted and ready to land. LGTM Repository: rC Clang https://reviews.llvm.org/D50467 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50410: Removing -debug-info-macros from option suggestions test
acoomans added a comment. Can anyone confirm the `-debug-info-macro` command line option is unavailable with the PS4 SDK? Repository: rC Clang https://reviews.llvm.org/D50410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50535: Fix selective formatting of ObjC scope
acoomans added a comment. @jolesiak let me know what you think Repository: rC Clang https://reviews.llvm.org/D50535 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50410: Removing -debug-info-macros from option suggestions test
acoomans added subscribers: mattd, Sunil_Srivastava. acoomans added a comment. @mattd @Sunil_Srivastava if you have access to the PS4 SDK, could you tell if the `-debug-info-macro` command line clang option is available? Thank you Repository: rC Clang https://reviews.llvm.org/D50410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50410: Removing -debug-info-macros from option suggestions test
acoomans added a comment. @mattd thanks for confirming. I tried `clang -cc1as -target x86_64-scei-ps4 -debug-info-macros` and got suggestions. @modocache @mattd Should we try to first land https://reviews.llvm.org/D50515 to see if it fails again? Repository: rC Clang https://reviews.llvm.org/D50410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49549: Change 'clang-test' to 'check-clang' on the hacking webpage
acoomans created this revision. acoomans added reviewers: chandlerc, cfe-commits. The command to run tests was previously changed from 'clang-test' to 'check-clang'; with 'clang-test' remaining available as a legacy alias (see git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159483 91177308-0d34-0410-b5e6-96231b3b80d8). This commit changes the www documentation accordingly. Repository: rC Clang https://reviews.llvm.org/D49549 Files: www/hacking.html Index: www/hacking.html === --- www/hacking.html +++ www/hacking.html @@ -124,7 +124,7 @@ about what is being run. If you built LLVM and Clang using CMake, the test suite can be run - with make clang-test from the top-level LLVM directory. + with make check-clang from the top-level LLVM directory. The tests primarily consist of a test runner script running the compiler under test on individual test files grouped in the directories under the @@ -191,8 +191,8 @@ to CMake explicitly. The cmake build tool is set up to create Visual Studio project files - for running the tests, "clang-test" being the root. Therefore, to - run the test from Visual Studio, right-click the clang-test project + for running the tests, "check-clang" being the root. Therefore, to + run the test from Visual Studio, right-click the check-clang project and select "Build". Index: www/hacking.html === --- www/hacking.html +++ www/hacking.html @@ -124,7 +124,7 @@ about what is being run. If you built LLVM and Clang using CMake, the test suite can be run - with make clang-test from the top-level LLVM directory. + with make check-clang from the top-level LLVM directory. The tests primarily consist of a test runner script running the compiler under test on individual test files grouped in the directories under the @@ -191,8 +191,8 @@ to CMake explicitly. The cmake build tool is set up to create Visual Studio project files - for running the tests, "clang-test" being the root. Therefore, to - run the test from Visual Studio, right-click the clang-test project + for running the tests, "check-clang" being the root. Therefore, to + run the test from Visual Studio, right-click the check-clang project and select "Build". ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49580: [WIP] Change clang-format to absolute indentation
acoomans created this revision. Herald added a subscriber: cfe-commits. When running clang-format on specific lines, two types of indentation could be expectedi: - absolute indentation: the indentation one would get if the whole file were formatted; or - relative indentation: keep the indentation relative to the previous lines, even if those are not indented correctly (i.e. would be indented differently if the whole file was formatted) and are not in the range of lines to format clang-format does relative indentation. This diff is a proposal to change to absolute indentation -- WIP existing tests would need to be fixed if we're ok with this diff Repository: rC Clang https://reviews.llvm.org/D49580 Files: lib/Format/UnwrappedLineFormatter.cpp test/Format/line-ranges-indent.cpp Index: test/Format/line-ranges-indent.cpp === --- /dev/null +++ test/Format/line-ranges-indent.cpp @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s \ +// RUN: | clang-format -style=LLVM -lines=3:3 \ +// RUN: | FileCheck -strict-whitespace %s +// CHECK: {{^\@protocol\ A$}} +@protocol A +// CHECK: {{^\ \@optional$}} + @optional +// CHECK: {{^//\ comment$}} +// comment +// CHECK: {{^-\ \(void\)f;$}} +- (void)f; +// CHECK: {{^\@end$}} +@end Index: lib/Format/UnwrappedLineFormatter.cpp === --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -1092,7 +1092,7 @@ // unless the current \c AnnotatedLine is not at the beginning of a line. bool StartsNewLine = TheLine.First->NewlinesBefore > 0 || TheLine.First->IsFirst; - if (StartsNewLine) + if (TheLine.Affected && StartsNewLine) IndentTracker.adjustToUnmodifiedLine(TheLine); if (!DryRun) { bool ReformatLeadingWhitespace = Index: test/Format/line-ranges-indent.cpp === --- /dev/null +++ test/Format/line-ranges-indent.cpp @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s \ +// RUN: | clang-format -style=LLVM -lines=3:3 \ +// RUN: | FileCheck -strict-whitespace %s +// CHECK: {{^\@protocol\ A$}} +@protocol A +// CHECK: {{^\ \@optional$}} + @optional +// CHECK: {{^//\ comment$}} +// comment +// CHECK: {{^-\ \(void\)f;$}} +- (void)f; +// CHECK: {{^\@end$}} +@end Index: lib/Format/UnwrappedLineFormatter.cpp === --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -1092,7 +1092,7 @@ // unless the current \c AnnotatedLine is not at the beginning of a line. bool StartsNewLine = TheLine.First->NewlinesBefore > 0 || TheLine.First->IsFirst; - if (StartsNewLine) + if (TheLine.Affected && StartsNewLine) IndentTracker.adjustToUnmodifiedLine(TheLine); if (!DryRun) { bool ReformatLeadingWhitespace = ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49580: [WIP] Change clang-format to absolute indentation
acoomans added a comment. An alternative to changing the whole behavior would be to make it a parameter / configuration option. Repository: rC Clang https://reviews.llvm.org/D49580 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49580: [clang-format] Adding style option for absolute formatting
acoomans updated this revision to Diff 156571. acoomans retitled this revision from "[WIP] Change clang-format to absolute indentation" to "[clang-format] Adding style option for absolute formatting". acoomans edited the summary of this revision. https://reviews.llvm.org/D49580 Files: docs/ClangFormatStyleOptions.rst include/clang/Format/Format.h lib/Format/Format.cpp lib/Format/UnwrappedLineFormatter.cpp test/Format/line-ranges-indent-abs.c test/Format/line-ranges-indent-abs.m test/Format/line-ranges-indent-rel.c Index: test/Format/line-ranges-indent-rel.c === --- /dev/null +++ test/Format/line-ranges-indent-rel.c @@ -0,0 +1,10 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s \ +// RUN: | clang-format -style=LLVM -lines=2:2 \ +// RUN: | FileCheck -strict-whitespace %s +// CHECK: {{^\ int f\(void\) \{$}} + int f(void) { +// CHECK: {{^\ \ \ int i = 0;$}} + int i = 0; +// CHECK: {{^\ \ \ return i;$}} + return i; +} Index: test/Format/line-ranges-indent-abs.m === --- /dev/null +++ test/Format/line-ranges-indent-abs.m @@ -0,0 +1,9 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s \ +// RUN: | clang-format -style="{BasedOnStyle: LLVM, IndentReference: Absolute}" -lines=2:2 \ +// RUN: | FileCheck -strict-whitespace %s +// CHECK: {{^\ \@protocol\ A$}} + @protocol A +// CHECK: {{^-\ \(void\)f;$}} +- (void)f; +// CHECK: {{^\@end$}} +@end Index: test/Format/line-ranges-indent-abs.c === --- /dev/null +++ test/Format/line-ranges-indent-abs.c @@ -0,0 +1,10 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s \ +// RUN: | clang-format -style="{BasedOnStyle: LLVM, IndentReference: Absolute}" -lines=2:2 \ +// RUN: | FileCheck -strict-whitespace %s +// CHECK: {{^\ int f\(void\) \{$}} + int f(void) { +// CHECK: {{^\ \ int i = 0;$}} + int i = 0; +// CHECK: {{^\ \ return i;$}} + return i; +} Index: lib/Format/UnwrappedLineFormatter.cpp === --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -1089,10 +1089,13 @@ format(Tok->Children, DryRun); // Adapt following lines on the current indent level to the same level - // unless the current \c AnnotatedLine is not at the beginning of a line. + // if indentation should be relative and unless the + // current \c AnnotatedLine is not at the beginning of a line. + bool RelativeIndentation = + Style.IndentReference != FormatStyle::IRS_Absolute; bool StartsNewLine = TheLine.First->NewlinesBefore > 0 || TheLine.First->IsFirst; - if (StartsNewLine) + if (RelativeIndentation && StartsNewLine) IndentTracker.adjustToUnmodifiedLine(TheLine); if (!DryRun) { bool ReformatLeadingWhitespace = Index: lib/Format/Format.cpp === --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -241,6 +241,13 @@ } }; +template <> struct ScalarEnumerationTraits { + static void enumeration(IO &IO, FormatStyle::IndentReferenceStyle &Value) { +IO.enumCase(Value, "Relative", FormatStyle::IRS_Relative); +IO.enumCase(Value, "Absolute", FormatStyle::IRS_Absolute); + } +}; + template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, FormatStyle::PointerAlignmentStyle &Value) { IO.enumCase(Value, "Middle", FormatStyle::PAS_Middle); @@ -411,6 +418,7 @@ IO.mapOptional("IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex); IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels); IO.mapOptional("IndentPPDirectives", Style.IndentPPDirectives); +IO.mapOptional("IndentReference", Style.IndentReference); IO.mapOptional("IndentWidth", Style.IndentWidth); IO.mapOptional("IndentWrappedFunctionNames", Style.IndentWrappedFunctionNames); @@ -670,6 +678,7 @@ LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve; LLVMStyle.IndentCaseLabels = false; LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None; + LLVMStyle.IndentReference = FormatStyle::IRS_Relative; LLVMStyle.IndentWrappedFunctionNames = false; LLVMStyle.IndentWidth = 2; LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave; Index: include/clang/Format/Format.h === --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -1094,6 +1094,30 @@ /// The preprocessor directive indenting style to use. PPDirectiveIndentStyle IndentPPDirectives; + /// Different styles for indenting, used for partial formatting. + enum IndentReferenceStyle { +/// Indent relative to previous line, e.g.: +/// \code +/// int a = 0; +///int f(void) { // mis-indented by one space +/// int i = 0; <- those l
[PATCH] D49580: [clang-format] Adding style option for absolute formatting
acoomans added a comment. @djasper I updated the description of the diff. This fixes the issue of `clang-format -lines=x:x` not returning the same results as `clang-format`, while keeping the current behavior as default. https://reviews.llvm.org/D49580 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49580: [clang-format] Adding style option for absolute formatting
acoomans added a comment. Also ping @jolesiak since he initially filed the report https://reviews.llvm.org/D49580 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49580: [clang-format] Adding style option for absolute formatting
acoomans added a comment. I don't know; I just picked a random bug from the Bugzilla to get myself familiarized with the LLVM codebase :) @jolesiak? https://reviews.llvm.org/D49580 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50147: clang-format: support external styles
acoomans added a comment. Doesn’t clang-format support project-based //.clang-format// or //_clang-format//? How do they play with this diff? Repository: rC Clang https://reviews.llvm.org/D50147 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits