summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.74.0/src/newlines.h
blob: cd5d61dbcbf5e3b0b0ece35b8ce2d01d03aed171 (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
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
/**
 * @file newlines.h
 * prototypes for newlines.c
 *
 * @author  Ben Gardner
 * @license GPL v2+
 */

#ifndef NEWLINES_H_INCLUDED
#define NEWLINES_H_INCLUDED

#include "chunk_list.h"

/**
 * Double the newline, if allowed.
 */
void double_newline(chunk_t *nl);

/**
 * Remove all extra newlines.
 * Modify line breaks as needed.
 */
void newlines_remove_newlines(void);


/**
 * Remove all newlines that fail the checks performed by the can_increase_nl() function
 */
void newlines_remove_disallowed();


/** Step through all chunks, altering newlines inside parens of if/for/while/do as needed.
 * Handles the style options: nl_multi_line_sparen_open, nl_multi_line_sparen_close, nl_before_if_closing_paren
 */
void newlines_sparens();

//! Step through all chunks.
void newlines_cleanup_braces(bool first);


void newlines_cleanup_angles();


//! Handle insertion/removal of blank lines before if/for/while/do and functions
void newlines_insert_blank_lines(void);


/**
 * Handle removal of extra blank lines in functions
 * x <= 0: do nothing, x > 0: allow max x-1 blank lines
 */
void newlines_functions_remove_extra_blank_lines(void);


void newlines_squeeze_ifdef(void);

/**
 * In case of consecutive closing parens, which follow a newline,
 * the closing paren are altered to different lines, as per the respective opening parens.
 * In the given example, first 2 opening paren are in same line, hence the respective closing paren are put in the same line.
 * input:
 * func1(func2(
 *    func3(
 *       func4(
 *       )
 *    )
 * )
 * );
 * output:
 * func1(func2(
 *    func3(
 *       func4(
 *       )
 *    )
 * ));
 */
void newlines_squeeze_paren_close(void);


//! removes unnecessary newlines at start and end of a file
void newlines_eat_start_end(void);


/**
 * Searches for a chunk of type chunk_type and moves them, if needed.
 * Will not move tokens that are on their own line or have other than
 * exactly 1 newline before (UO_pos_comma == TRAIL) or after (UO_pos_comma == LEAD).
 * We can't remove a newline if it is right before a preprocessor.
 */
void newlines_chunk_pos(c_token_t chunk_type, uncrustify::token_pos_e mode);


/**
 * Searches for CT_CLASS_COLON and moves them, if needed.
 * Also breaks up the args
 */
void newlines_class_colon_pos(c_token_t tok);


void newlines_cleanup_dup(void);


void annotations_newlines(void);


void newline_after_multiline_comment(void);


//! Handle insertion of blank lines after label colons
void newline_after_label_colon(void);


/**
 * Scans for newline tokens and changes the nl_count.
 * A newline token has a minimum nl_count of 1.
 * Note that a blank line is actually 2 newlines, unless the newline is the
 * first chunk.
 * So, most comparisons have +1 below.
 */
void do_blank_lines(void);


/**
 * Clears the PCF_ONE_LINER flag on the current line.
 * Done right before inserting a newline.
 */
void undo_one_liner(chunk_t *pc);


/**
 * Does a simple Ignore, Add, Remove, or Force after the given chunk
 *
 * @param pc  The chunk
 * @param av  The IARF value
 */
void newline_iarf(chunk_t *pc, uncrustify::iarf_e av);


/**
 * Add a newline before the chunk if there isn't already a newline present.
 * Virtual braces are skipped, as they do not contribute to the output.
 */
chunk_t *newline_add_before(chunk_t *pc);


/**
 * Add a newline after the chunk if there isn't already a newline present.
 * Virtual braces are skipped, as they do not contribute to the output.
 */
chunk_t *newline_force_before(chunk_t *pc);


chunk_t *newline_add_after(chunk_t *pc);


chunk_t *newline_force_after(chunk_t *pc);


/**
 * Removes any CT_NEWLINE or CT_NL_CONT between start and end.
 * Start must be before end on the chunk list.
 * If the 'PCF_IN_PREPROC' status differs between two tags, we can't remove
 * the newline.
 *
 * @param start  The starting chunk (if it is a newline, it will be removed!)
 * @param end    The ending chunk (will not be removed, even if it is a newline)
 *
 * @return true/false - removed something
 */
void newline_del_between(chunk_t *start, chunk_t *end);


/**
 * Add a newline between two tokens.
 * If there is already a newline between then, nothing is done.
 * Otherwise a newline is inserted.
 *
 * If end is CT_BRACE_OPEN and a comment and newline follow, then
 * the brace open is moved instead of inserting a newline.
 *
 * In this situation:
 *    if (...) { //comment
 *
 * you get:
 *    if (...)   //comment
 *    {
 */
chunk_t *newline_add_between(chunk_t *start, chunk_t *end);


/**
 * Counts newlines between two chunk elements
 *
 * @param  pc_start  chunk from which the counting of newlines will start
 * @param  pc_end    chunk at which the counting of newlines will end
 * @param  newlines  reference in which the amount of newlines will be written to
 *                   (will be initialized with 0)
 * @param  scope     specifies region chunks should/should not be considered.
 *
 * @return false  if pc_start or pc_end are nullptr or if pc_end is not reached
 * @return true   if above cases are not met
 */
bool newlines_between(chunk_t *pc_start, chunk_t *pc_end, size_t &newlines, scope_e scope = scope_e::ALL);


#endif /* NEWLINES_H_INCLUDED */