[PATCH] D47095: [clang-format/ObjC] Correctly parse Objective-C methods with 'class' in name

Jacek Olesiak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 23 04:42:56 PDT 2018


jolesiak added inline comments.


================
Comment at: lib/Format/UnwrappedLineParser.cpp:2137
+  do {
+    if (FormatTok->Tok.isOneOf(tok::semi, tok::r_brace)) {
+      nextToken();
----------------
`tok::r_brace` could be skiped - see comment to line 2143.


================
Comment at: lib/Format/UnwrappedLineParser.cpp:2143
+      parseBlock(/*MustBeDeclaration=*/false);
+      addUnwrappedLine();
+    } else {
----------------
We have to add `return` after `addUnwrappedLine` as `parseBlock` does consume `tok::r_brace`. Without `return` we will consume tokens after `}`. This problem will rarely occur as most lines end with `tok::semi` or `tok::r_brace` and it will be terminated properly (however maybe not handled properly as we just skip every token in `else`) by `if` branch.

Test like:
```
@implementation Foo
- (foo)foo {
}
@end
@implementation Bar
- (bar)bar {
}
@end
```
will distinguish version with `return` from one without. Therefore, I think we should add it.


Repository:
  rC Clang

https://reviews.llvm.org/D47095





More information about the cfe-commits mailing list