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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
/**
* @file align_func_proto.cpp
*
* @author Guy Maurel
* split from align.cpp
* @author Ben Gardner
* @license GPL v2+
*/
#include "align_func_proto.h"
#include "align_stack.h"
#include "align_tools.h"
#include "log_rules.h"
#include <algorithm> // to get max
constexpr static auto LCURRENT = LALPROTO;
using namespace uncrustify;
void align_func_proto(size_t span)
{
LOG_FUNC_ENTRY();
size_t myspan = span;
size_t mythresh = 0;
log_rule_B("align_func_proto_gap");
size_t mygap = options::align_func_proto_gap();
log_rule_B("align_func_proto_thresh");
mythresh = options::align_func_proto_thresh();
// Issue #2771
// we align token-1 and token-2 if:
// token-1->level == token-2->level
// and
// token-1->brace_level == token-2->brace_level
// we don't check if token-1 and token-2 are in the same block
log_rule_B("align_func_proto_star_style");
size_t mystar_style = options::align_func_proto_star_style();
log_rule_B("align_func_proto_amp_style");
size_t myamp_style = options::align_func_proto_amp_style();
size_t num_of_column = 1;
size_t num_of_row = 1;
AlignStack *stack_init_value = nullptr;
// Issue #2984
vector<vector<AlignStack *> > many_as;
// Issue #2771
vector<vector<AlignStack *> > many_as_brace;
// init the vector ...
many_as.resize(num_of_column, vector<AlignStack *>(num_of_row, stack_init_value));
many_as_brace.resize(num_of_column, vector<AlignStack *>(num_of_row, stack_init_value));
log_rule_B("align_single_line_brace_gap");
size_t mybr_gap = options::align_single_line_brace_gap();
bool look_bro = false;
chunk_t *toadd;
for (chunk_t *pc = chunk_get_head(); pc != nullptr; pc = chunk_get_next(pc))
{
char copy[1000];
LOG_FMT(LAS, "%s(%d): orig_line is %zu, orig_col is %zu, text() is '%s', type is %s, level is %zu, brace_level is %zu\n",
__func__, __LINE__, pc->orig_line, pc->orig_col, pc->elided_text(copy),
get_token_name(pc->type), pc->level, pc->brace_level);
// make the vector larger if necessary
if ( pc->level >= num_of_column // Issue #2960
|| pc->brace_level >= num_of_row)
{
num_of_column = pc->level + 1;
num_of_row = pc->brace_level + 1;
many_as.resize(num_of_column);
many_as_brace.resize(num_of_column);
for (size_t i = 0; i < num_of_column; ++i)
{
many_as[i].resize(num_of_row);
many_as_brace[i].resize(num_of_row);
}
}
if ( chunk_is_newline(pc)
&& !pc->flags.test(PCF_IN_FCN_CALL)) // Issue #2831
{
look_bro = false;
AlignStack *stack_at_l_bl = many_as.at(pc->level).at(pc->brace_level);
if (stack_at_l_bl == nullptr)
{
// get a Stack
stack_at_l_bl = new AlignStack();
// start it
stack_at_l_bl->Start(myspan, mythresh);
stack_at_l_bl->m_gap = mygap;
stack_at_l_bl->m_star_style = static_cast<AlignStack::StarStyle>(mystar_style);
stack_at_l_bl->m_amp_style = static_cast<AlignStack::StarStyle>(myamp_style);
// store
many_as.at(pc->level).at(pc->brace_level) = stack_at_l_bl;
}
stack_at_l_bl->Debug();
for (size_t idx = 0; idx < num_of_column; idx++)
{
for (size_t idx_brace = 0; idx_brace < num_of_row; idx_brace++)
{
stack_at_l_bl = many_as.at(idx).at(idx_brace);
if (stack_at_l_bl != nullptr)
{
stack_at_l_bl->NewLines(pc->nl_count);
}
}
}
AlignStack *stack_at_l_bl_brace = many_as_brace.at(pc->level).at(pc->brace_level);
if (stack_at_l_bl_brace == nullptr)
{
// get a Stack
stack_at_l_bl_brace = new AlignStack();
// start it
stack_at_l_bl_brace->Start(myspan, mythresh);
stack_at_l_bl_brace->m_gap = mybr_gap;
// store
many_as_brace.at(pc->level).at(pc->brace_level) = stack_at_l_bl_brace;
}
stack_at_l_bl_brace->Debug();
stack_at_l_bl_brace->NewLines(pc->nl_count);
}
else if ( chunk_is_token(pc, CT_FUNC_PROTO)
|| ( chunk_is_token(pc, CT_FUNC_DEF)
&& options::align_single_line_func()))
{
log_rule_B("align_single_line_func");
log_rule_B("align_on_operator");
if ( get_chunk_parent_type(pc) == CT_OPERATOR
&& options::align_on_operator())
{
toadd = chunk_get_prev_ncnnl(pc);
}
else
{
toadd = pc;
}
chunk_t *tmp = step_back_over_member(toadd);
LOG_FMT(LAS, "%s(%d): tmp->text() is '%s', orig_line is %zu, orig_col is %zu, level is %zu, brace_level is %zu\n",
__func__, __LINE__, tmp->text(), tmp->orig_line, tmp->orig_col,
tmp->level, tmp->brace_level);
// test the Stack
AlignStack *stack_at_l_bl = many_as.at(pc->level).at(pc->brace_level);
if (stack_at_l_bl == nullptr)
{
// get a Stack
stack_at_l_bl = new AlignStack();
// start it
stack_at_l_bl->Start(myspan, mythresh);
stack_at_l_bl->m_gap = mygap;
stack_at_l_bl->m_star_style = static_cast<AlignStack::StarStyle>(mystar_style);
stack_at_l_bl->m_amp_style = static_cast<AlignStack::StarStyle>(myamp_style);
// store
many_as.at(pc->level).at(pc->brace_level) = stack_at_l_bl;
}
stack_at_l_bl->Add(tmp);
log_rule_B("align_single_line_brace");
look_bro = (chunk_is_token(pc, CT_FUNC_DEF))
&& options::align_single_line_brace();
}
else if ( look_bro
&& chunk_is_token(pc, CT_BRACE_OPEN)
&& pc->flags.test(PCF_ONE_LINER))
{
AlignStack *stack_at_l_bl_brace = many_as_brace.at(pc->level).at(pc->brace_level);
stack_at_l_bl_brace->Add(pc);
look_bro = false;
}
}
LOG_FMT(LAS, "%s(%d): as\n", __func__, __LINE__);
// purge
for (size_t idx = 0; idx < num_of_column; idx++)
{
for (size_t idx_brace = 0; idx_brace < num_of_row; idx_brace++)
{
AlignStack *stack_at_l_bl = many_as.at(idx).at(idx_brace);
if (stack_at_l_bl != nullptr)
{
stack_at_l_bl->End();
delete stack_at_l_bl;
stack_at_l_bl = nullptr;
}
AlignStack *stack_at_l_bl_brace = many_as_brace.at(idx).at(idx_brace);
if (stack_at_l_bl_brace != nullptr)
{
stack_at_l_bl_brace->End();
delete stack_at_l_bl_brace;
stack_at_l_bl_brace = nullptr;
}
}
}
} // align_func_proto
|