blob: d096a9a78f85d74c920106db14c1afcd138aa144 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/**
* @file align_eigen_comma_init.cpp
*
* @author Matthew Woehlke
* copied/adapted from align_left_shift.cpp
* @author Guy Maurel
* @author Ben Gardner
* @license GPL v2+
*/
#include "align_eigen_comma_init.h"
#include "align_stack.h"
#include "indent.h"
#include "log_rules.h"
constexpr static auto LCURRENT = LALIGN;
using namespace uncrustify;
void align_eigen_comma_init()
{
LOG_FUNC_ENTRY();
Chunk *start = Chunk::NullChunkPtr;
AlignStack as;
as.Start(255);
Chunk *pc = Chunk::GetHead();
while (pc->IsNotNullChunk())
{
LOG_CHUNK(LTOK, pc);
if ( start->IsNotNullChunk()
&& ((pc->GetFlags() & PCF_IN_PREPROC) != (start->GetFlags() & PCF_IN_PREPROC)))
{
// a change in preproc status restarts the aligning
as.Flush();
start = Chunk::NullChunkPtr;
}
else if (pc->IsNewline())
{
as.NewLines(pc->GetNlCount());
}
else if ( start->IsNotNullChunk()
&& pc->GetLevel() < start->GetLevel())
{
// A drop in level restarts the aligning
as.Flush();
start = Chunk::NullChunkPtr;
}
else if ( start->IsNotNullChunk()
&& pc->GetLevel() > start->GetLevel())
{
// Ignore any deeper levels when aligning
}
else if (pc->Is(CT_SEMICOLON))
{
// A semicolon at the same level flushes
as.Flush();
start = Chunk::NullChunkPtr;
}
else if ( !pc->TestFlags(PCF_IN_ENUM)
&& !pc->TestFlags(PCF_IN_TYPEDEF)
&& pc->IsString("<<"))
{
if (pc->GetParentType() == CT_OPERATOR)
{
// Ignore operator<<
}
else
{
/*
* check if the first one is actually on a blank line and then
* indent it. Eg:
*
* cout
* << "something";
*/
Chunk *prev = pc->GetPrev();
if ( prev->IsNotNullChunk()
&& prev->IsNewline())
{
log_rule_B("indent_columns");
indent_to_column(pc, pc->GetColumnIndent() + options::indent_columns());
pc->SetColumnIndent(pc->GetColumn());
pc->SetFlagBits(PCF_DONT_INDENT);
}
// Restart alignment
as.Flush();
as.Add(pc->GetNext());
start = pc;
}
}
else if (!as.m_aligned.Empty())
{
Chunk *prev = pc->GetPrev();
if ( prev->IsNewline()
&& pc->GetPrevNcNnl()->Is(CT_COMMA))
{
log_rule_B("align_eigen_comma_init");
as.Add(pc);
}
}
pc = pc->GetNext();
}
as.End();
} // align_left_shift
|