[PATCH] D45498: [clang-format] Don't insert space between ObjC class and lightweight generic
This revision was automatically updated to reflect the committed changes. Closed by commit rL329917: [clang-format] Don't insert space between ObjC class and lightweight generic (authored by benhamilton, committed by ). Herald added a subscriber: llvm-commits. Repository: rL LLVM https://reviews.llvm.org/D45498 Files: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTestObjC.cpp Index: cfe/trunk/lib/Format/TokenAnnotator.cpp === --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/lib/Format/TokenAnnotator.cpp @@ -2349,9 +2349,12 @@ : Style.SpacesInParentheses; if (Right.isOneOf(tok::semi, tok::comma)) return false; - if (Right.is(tok::less) && Line.Type == LT_ObjCDecl && - Style.ObjCSpaceBeforeProtocolList) -return true; + if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) { +bool IsLightweightGeneric = +Right.MatchingParen && Right.MatchingParen->Next && +Right.MatchingParen->Next->is(tok::colon); +return !IsLightweightGeneric && Style.ObjCSpaceBeforeProtocolList; + } if (Right.is(tok::less) && Left.is(tok::kw_template)) return Style.SpaceAfterTemplateKeyword; if (Left.isOneOf(tok::exclaim, tok::tilde)) Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp === --- cfe/trunk/unittests/Format/FormatTestObjC.cpp +++ cfe/trunk/unittests/Format/FormatTestObjC.cpp @@ -299,13 +299,13 @@ "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo : Bar {\n" + verifyFormat("@interface Foo : Bar {\n" " int _i;\n" "}\n" "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo > : Xyzzy {\n" + verifyFormat("@interface Foo> : Xyzzy {\n" " int _i;\n" "}\n" "+ (id)init;\n" Index: cfe/trunk/lib/Format/TokenAnnotator.cpp === --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/lib/Format/TokenAnnotator.cpp @@ -2349,9 +2349,12 @@ : Style.SpacesInParentheses; if (Right.isOneOf(tok::semi, tok::comma)) return false; - if (Right.is(tok::less) && Line.Type == LT_ObjCDecl && - Style.ObjCSpaceBeforeProtocolList) -return true; + if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) { +bool IsLightweightGeneric = +Right.MatchingParen && Right.MatchingParen->Next && +Right.MatchingParen->Next->is(tok::colon); +return !IsLightweightGeneric && Style.ObjCSpaceBeforeProtocolList; + } if (Right.is(tok::less) && Left.is(tok::kw_template)) return Style.SpaceAfterTemplateKeyword; if (Left.isOneOf(tok::exclaim, tok::tilde)) Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp === --- cfe/trunk/unittests/Format/FormatTestObjC.cpp +++ cfe/trunk/unittests/Format/FormatTestObjC.cpp @@ -299,13 +299,13 @@ "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo : Bar {\n" + verifyFormat("@interface Foo : Bar {\n" " int _i;\n" "}\n" "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo > : Xyzzy {\n" + verifyFormat("@interface Foo> : Xyzzy {\n" " int _i;\n" "}\n" "+ (id)init;\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45498: [clang-format] Don't insert space between ObjC class and lightweight generic
benhamilton updated this revision to Diff 142186. benhamilton marked an inline comment as done. benhamilton added a comment. Avoid else after return. Clean up logic so it doesn't need a comment. Repository: rC Clang https://reviews.llvm.org/D45498 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTestObjC.cpp Index: unittests/Format/FormatTestObjC.cpp === --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -299,13 +299,13 @@ "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo : Bar {\n" + verifyFormat("@interface Foo : Bar {\n" " int _i;\n" "}\n" "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo > : Xyzzy {\n" + verifyFormat("@interface Foo> : Xyzzy {\n" " int _i;\n" "}\n" "+ (id)init;\n" Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2349,9 +2349,12 @@ : Style.SpacesInParentheses; if (Right.isOneOf(tok::semi, tok::comma)) return false; - if (Right.is(tok::less) && Line.Type == LT_ObjCDecl && - Style.ObjCSpaceBeforeProtocolList) -return true; + if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) { +bool IsLightweightGeneric = +Right.MatchingParen && Right.MatchingParen->Next && +Right.MatchingParen->Next->is(tok::colon); +return !IsLightweightGeneric && Style.ObjCSpaceBeforeProtocolList; + } if (Right.is(tok::less) && Left.is(tok::kw_template)) return Style.SpaceAfterTemplateKeyword; if (Left.isOneOf(tok::exclaim, tok::tilde)) Index: unittests/Format/FormatTestObjC.cpp === --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -299,13 +299,13 @@ "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo : Bar {\n" + verifyFormat("@interface Foo : Bar {\n" " int _i;\n" "}\n" "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo > : Xyzzy {\n" + verifyFormat("@interface Foo> : Xyzzy {\n" " int _i;\n" "}\n" "+ (id)init;\n" Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2349,9 +2349,12 @@ : Style.SpacesInParentheses; if (Right.isOneOf(tok::semi, tok::comma)) return false; - if (Right.is(tok::less) && Line.Type == LT_ObjCDecl && - Style.ObjCSpaceBeforeProtocolList) -return true; + if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) { +bool IsLightweightGeneric = +Right.MatchingParen && Right.MatchingParen->Next && +Right.MatchingParen->Next->is(tok::colon); +return !IsLightweightGeneric && Style.ObjCSpaceBeforeProtocolList; + } if (Right.is(tok::less) && Left.is(tok::kw_template)) return Style.SpaceAfterTemplateKeyword; if (Left.isOneOf(tok::exclaim, tok::tilde)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45498: [clang-format] Don't insert space between ObjC class and lightweight generic
djasper accepted this revision. djasper added a comment. This revision is now accepted and ready to land. Looks good. Comment at: lib/Format/TokenAnnotator.cpp:2357 + return false; +else + // Protocol list -> space if configured. @interface Foo : Bar Don't use else after return. https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return I'd have a slight preference for writing: bool IsLightweightGeneric = Right.MatchingParen && Right.MatchingParen->Next && Right.MatchingParen->Next->is(tok::colon); return !IsLightweightGeneric && Style.ObjCSpaceBeforeProtocolList; Then I think it might not even need a comment (or a shorter one). Repository: rC Clang https://reviews.llvm.org/D45498 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45498: [clang-format] Don't insert space between ObjC class and lightweight generic
benhamilton created this revision. benhamilton added reviewers: djasper, jolesiak. Herald added subscribers: cfe-commits, klimek. In https://reviews.llvm.org/D45185, I added clang-format parser support for Objective-C generics. However, I didn't touch the whitespace logic, so they got the same space logic as Objective-C protocol lists. In every example in the Apple SDK and in the documentation, there is no space between the class name and the opening `<` for the lightweight generic specification, so this diff removes the space and updates the tests. Test Plan: Tests updated. Ran tests with: % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests Repository: rC Clang https://reviews.llvm.org/D45498 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTestObjC.cpp Index: unittests/Format/FormatTestObjC.cpp === --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -299,13 +299,13 @@ "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo : Bar {\n" + verifyFormat("@interface Foo : Bar {\n" " int _i;\n" "}\n" "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo > : Xyzzy {\n" + verifyFormat("@interface Foo> : Xyzzy {\n" " int _i;\n" "}\n" "+ (id)init;\n" Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2349,9 +2349,15 @@ : Style.SpacesInParentheses; if (Right.isOneOf(tok::semi, tok::comma)) return false; - if (Right.is(tok::less) && Line.Type == LT_ObjCDecl && - Style.ObjCSpaceBeforeProtocolList) -return true; + if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) { +if (Right.MatchingParen && Right.MatchingParen->Next && +Right.MatchingParen->Next->is(tok::colon)) + // Lightweight generic -> no space. @interface Foo : Bar + return false; +else + // Protocol list -> space if configured. @interface Foo : Bar + return Style.ObjCSpaceBeforeProtocolList; + } if (Right.is(tok::less) && Left.is(tok::kw_template)) return Style.SpaceAfterTemplateKeyword; if (Left.isOneOf(tok::exclaim, tok::tilde)) Index: unittests/Format/FormatTestObjC.cpp === --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -299,13 +299,13 @@ "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo : Bar {\n" + verifyFormat("@interface Foo : Bar {\n" " int _i;\n" "}\n" "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo > : Xyzzy {\n" + verifyFormat("@interface Foo> : Xyzzy {\n" " int _i;\n" "}\n" "+ (id)init;\n" Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2349,9 +2349,15 @@ : Style.SpacesInParentheses; if (Right.isOneOf(tok::semi, tok::comma)) return false; - if (Right.is(tok::less) && Line.Type == LT_ObjCDecl && - Style.ObjCSpaceBeforeProtocolList) -return true; + if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) { +if (Right.MatchingParen && Right.MatchingParen->Next && +Right.MatchingParen->Next->is(tok::colon)) + // Lightweight generic -> no space. @interface Foo : Bar + return false; +else + // Protocol list -> space if configured. @interface Foo : Bar + return Style.ObjCSpaceBeforeProtocolList; + } if (Right.is(tok::less) && Left.is(tok::kw_template)) return Style.SpaceAfterTemplateKeyword; if (Left.isOneOf(tok::exclaim, tok::tilde)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits