Formatter: Detect ObjC message expressions after 'in' in loop
Before:
for (id foo in[self getStuffFor : bla]) {
}
Now:
for (id foo in [self getStuffFor:bla]) {
}
"in" is treated as loop keyword if the line starts with "for", and as a
regular identifier else. To check for "in", its IdentifierInfo is handed
through a few layers.
llvm-svn: 174889
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 6dc84a1..347e314 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -842,6 +842,8 @@
return FormatTok;
}
+ IdentifierTable &getIdentTable() { return IdentTable; }
+
private:
FormatToken FormatTok;
bool GreaterStashed;
@@ -909,7 +911,8 @@
UnwrappedLineParser Parser(Diag, Style, Tokens, *this);
StructuralError = Parser.parse();
unsigned PreviousEndOfLineColumn = 0;
- TokenAnnotator Annotator(Style, SourceMgr, Lex);
+ TokenAnnotator Annotator(Style, SourceMgr, Lex,
+ Tokens.getIdentTable().get("in"));
for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
Annotator.annotate(AnnotatedLines[i]);
}