Commit e220825
committed
[clang-format] Continue aligned lines better
after with config `{AlignConsecutiveAssignments: true}`
```C++
auto aaaaaaaaaaaaaaaaaaaaa = {};
auto b = [] {
x = {.one_foooooooooooooooo = 2, //
.two_fooooooooooooo = 3, //
.three_fooooooooooooo = 4};
};
A B = {"Hello "
"World"};
BYTE payload = 2;
float i2 = 0;
auto v = type{i2 = 1, //
i = 3};
```
before
```C++
auto aaaaaaaaaaaaaaaaaaaaa = {};
auto b = [] {
x = {.one_foooooooooooooooo = 2, //
.two_fooooooooooooo = 3, //
.three_fooooooooooooo = 4};
};
A B = {"Hello "
"World"};
BYTE payload = 2;
float i2 = 0;
auto v = type{i2 = 1, //
i = 3};
```
When a line gets aligned, the following lines may need to move with it.
This patch replaces the old algorithm with a simpler one. It uses the
`IsAligned` attribute. It makes most of the scope stack irrelevant.
Now the stack only needs to keep track of 2 levels.
The old algorithm had problems like these.
- Whether lines inside a braced list moved depended on whether there was
a type at the start. It should depend on whether the inside was
aligned to the brace. The first case that came up with a type name at
the start happened to have a comma at the end of the list so the
inside was not aligned to the brace.
- Excluding lines inside closures did not always work.
- A continued string could move twice as much as it should.
The following problems are not fixed yet.
A token that opens a scope is needed. Operator precedence is not
enough.
```C++
auto aaaaaaaaaaaaaaaaaaaaa = {};
auto b = 0 + //
0;
```
The algorithm has trouble when things that should not move and things
that should move are nested. This is related to the `IsAligned`
attribute being a boolean. It also affects how spaces and tabs are
selected.
```C++
auto aaaaaaaaaaaaaaaaaaaaa = {};
auto b = {.a = {
.a = 0,
}};
```1 parent 36dc2a9 commit e220825
File tree
2 files changed
+74
-102
lines changed- clang
- lib/Format
- unittests/Format
2 files changed
+74
-102
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | | - | |
293 | | - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
294 | 295 | | |
295 | 296 | | |
296 | | - | |
297 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
298 | 300 | | |
299 | 301 | | |
300 | 302 | | |
301 | 303 | | |
302 | | - | |
| 304 | + | |
| 305 | + | |
303 | 306 | | |
304 | 307 | | |
305 | 308 | | |
| |||
309 | 312 | | |
310 | 313 | | |
311 | 314 | | |
312 | | - | |
| 315 | + | |
313 | 316 | | |
314 | 317 | | |
315 | 318 | | |
316 | 319 | | |
317 | 320 | | |
318 | 321 | | |
319 | | - | |
320 | | - | |
321 | | - | |
| 322 | + | |
| 323 | + | |
322 | 324 | | |
323 | 325 | | |
324 | 326 | | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
335 | 332 | | |
336 | 333 | | |
337 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
338 | 337 | | |
339 | 338 | | |
340 | 339 | | |
| |||
349 | 348 | | |
350 | 349 | | |
351 | 350 | | |
| 351 | + | |
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
362 | 362 | | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
| 363 | + | |
433 | 364 | | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
| 365 | + | |
438 | 366 | | |
439 | | - | |
440 | 367 | | |
441 | 368 | | |
442 | 369 | | |
443 | 370 | | |
444 | 371 | | |
445 | 372 | | |
446 | 373 | | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | 374 | | |
451 | 375 | | |
452 | 376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19575 | 19575 | | |
19576 | 19576 | | |
19577 | 19577 | | |
| 19578 | + | |
| 19579 | + | |
| 19580 | + | |
| 19581 | + | |
| 19582 | + | |
| 19583 | + | |
19578 | 19584 | | |
19579 | 19585 | | |
19580 | 19586 | | |
| |||
20192 | 20198 | | |
20193 | 20199 | | |
20194 | 20200 | | |
| 20201 | + | |
| 20202 | + | |
| 20203 | + | |
| 20204 | + | |
| 20205 | + | |
20195 | 20206 | | |
20196 | 20207 | | |
20197 | 20208 | | |
| |||
20681 | 20692 | | |
20682 | 20693 | | |
20683 | 20694 | | |
| 20695 | + | |
| 20696 | + | |
| 20697 | + | |
| 20698 | + | |
| 20699 | + | |
| 20700 | + | |
| 20701 | + | |
| 20702 | + | |
| 20703 | + | |
| 20704 | + | |
| 20705 | + | |
| 20706 | + | |
| 20707 | + | |
| 20708 | + | |
| 20709 | + | |
20684 | 20710 | | |
20685 | 20711 | | |
20686 | 20712 | | |
| |||
20763 | 20789 | | |
20764 | 20790 | | |
20765 | 20791 | | |
| 20792 | + | |
| 20793 | + | |
| 20794 | + | |
| 20795 | + | |
| 20796 | + | |
| 20797 | + | |
| 20798 | + | |
| 20799 | + | |
| 20800 | + | |
| 20801 | + | |
| 20802 | + | |
| 20803 | + | |
| 20804 | + | |
| 20805 | + | |
| 20806 | + | |
| 20807 | + | |
| 20808 | + | |
| 20809 | + | |
| 20810 | + | |
| 20811 | + | |
| 20812 | + | |
| 20813 | + | |
20766 | 20814 | | |
20767 | 20815 | | |
20768 | 20816 | | |
| |||
0 commit comments