berenm marked 2 inline comments as done.

================
Comment at: lib/Format/WhitespaceManager.cpp:197
@@ +196,3 @@
+  // Keep track of the nesting level of matching tokens, i.e. the number of
+  // surrounding (), [], or {}. We will only align a sequence of matching
+  // token that share the same scope depth.
----------------
I have added some details in the comments, but couldn't manage to use the 
FormatToken::NestingLevel member. I haven't figured out why exactly, but it 
doesn't increase the nesting level counter in the braced scope of examples like:

```
int l = []() {
  int i = 0;
  int h = 0;
}
```

i.e.: tokens `i` and `h` have `NestingLevel == 0` as it is the case for token 
`l`.

I will try to figure out why exactly but it will require a bit more time.

================
Comment at: lib/Format/WhitespaceManager.cpp:263-274
@@ -321,21 +262,14 @@
 
-    if (Changes[i].Kind == tok::r_brace) {
-      if (!FoundLeftBraceOnLine)
-        AlignSequence();
-      FoundLeftBraceOnLine = false;
-    } else if (Changes[i].Kind == tok::l_brace) {
-      FoundLeftBraceOnLine = true;
-      if (!FoundDeclarationOnLine)
-        AlignSequence();
-    } else if (Changes[i].Kind == tok::r_paren) {
-      if (!FoundLeftParenOnLine)
-        AlignSequence();
-      FoundLeftParenOnLine = false;
-    } else if (Changes[i].Kind == tok::l_paren) {
-      FoundLeftParenOnLine = true;
-      if (!FoundDeclarationOnLine)
-        AlignSequence();
-    } else if (!FoundDeclarationOnLine && !FoundLeftBraceOnLine &&
-               !FoundLeftParenOnLine && Changes[i].IsStartOfDeclName) {
-      FoundDeclarationOnLine = true;
+    if (Matches(Changes[i])) {
+      // If there is more than one matching token per line, or if the number of
+      // preceding commas, or the scope depth, do not match anymore, end the
+      // sequence.
+      if (FoundMatchOnLine || CommasBeforeMatch != CommasBeforeLastMatch ||
+          NestingLevel != NestingLevelOfLastMatch)
+        AlignCurrentSequence();
+
+      CommasBeforeLastMatch = CommasBeforeMatch;
+      NestingLevelOfLastMatch = NestingLevel;
+      FoundMatchOnLine = true;
+
       if (StartOfSequence == 0)
----------------
I did that.

It makes me think that the code actually forbids the generic `AlignToken` 
function to be used with a matcher for aligning commas or braces, paren and 
brackets...


http://reviews.llvm.org/D14325



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to