summaryrefslogtreecommitdiffstats
path: root/indenters/example.cpp
blob: 44e6a80c5453c44cc0767e79fe05c2c1b310ad96 (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#include <a.h>
#include <a.h>
#include <a.h>

using namespace a.b.c a;

PREPROCESSOR()

BEGIN_MESSAGE_MAP()
    ON_COMMAND()
END_MESSAGE_MAP()

extern struct x y;

static const class Example :
    Int1, Int2, Int3
{
public:
    Example::~Example() :
        S1(),
        S2(),
        S3() {
        // if statements with empty braces
        if( x ) { }
        else if( x ) { }
        else { }

        // if statements with exactly one braced statement
        if( x ) {
            statement;
        }
        else if( x ) {
            statement;
        }
        else {
            statement;
        }

        // special 'if' cases
        if( x ) {
            statement;
        }
        else {
            statement;
        }

        if( x ) {
            statement;

            statement;
        }
        else {
            statement;

            statement;
        }

        // if statements with a single implicit substatement
        if( x )
            statement;

        else if( x )
            statement;

        else
            statement;

        // if statements with multiple statements
        if( x ) {
            statement;

            statement;
        }
        else if( x ) {
            statement;

            statement;
        }
        else {
            statement;

            statement;
        }

        // while statements with a single implicit substatement
        while( x )
            statement;

        // while statements with a single implicit 'if' substatement
        while( x )
            if( x )
                statement;

        // while with multiple statements
        while( x ) {
            statement;

            statement;
        }

        // labeled statement
        label:
        statement;

        // for statements with a single braced statement
        for ( x; x; x ) {
            statement;
        }

        // do statements with a single braced substatement
        do {
            statement;
        } while ( false );

        // do statement with an empty block
        do { } while ( x );

        // local blocks
        {
        statement;
        }

        /* Switch blocks:
         *
         * You can have case substatements be aligned by giving an example like:
         *
         * case 1: statement;
         * 
         *         statement;
         * 
         *         statement;
         * 
         *         etc...
         */
        switch( c ) {
            case 1:
            case 2:
            case 3:
                statement;

                statement;

                statement;

            case 4:
                break; // case with exactly one substatement

            default:
                break;
        }
    }

    void method( const myClass<item> &x, int [][][] c, ... ) {
        // try-catch-finally with empty bodies
        try { }
        catch(Throwable e) { }
        finally { }

        // try-catch-finally with exactly one statement
        try {
            statement;
        }
        catch( Throwable t ) {
            statement;
        }
        finally {
            statement;
        }

        // try-catch-finally with multiple statements 
        try {
            statement;

            statement;
        }
        catch( Throwable e ) {
            statement;

            statement;
        }
        finally {
            statement;

            statement;

            statement;
        }
    }
};

// enum statement
static typedef enum x
{
x,
y,
z,
};

// simple typedef
typedef interface static short int x;

namespace x
{
// template header
template <class T>
x y z v() const;

// pure virtual function, using c-style formal parameters with double parens
void v(()) = 0;

// function with one single line statement and c-style formal parameters
void v(( int i )) {
    statement;
};

// function with no statements
myClass<myType>::method() { }
};

template <T> class x
{
public:

    // operator declarations
    int operator +();

    int operator []();

    // template method
    static void A<x>::method() [][][] {
        asm
            {
            - Assembler statements -
            
            The outside braces are formatted but the asm code is passed through
            unchanged.
            }

        asm Single line assembler statements are also just passed through
    }

    extern void oldStyleFunction()
        int a;
        int b;
        int c; {
        // various simple statements
        long int a, b, c;

        long double [] i;

        goto x;

        delete [] x;

        delete [][][] x;

        return x;

        continue label;

        throw e;

        // c-style function calls with double parens
        b((a, b, c));

        a(());

        // expressions 
        new Object()->field.method();

        s = "string"
                "split across lines";

        method(a, B::C, 'd');

        z = j[0][0][0] || k * 3 >> ++i + "0" > i++ & (i) == !j;

        int *v;

        int &v;

        x = x * *x;

        (int *)x;

        int (*functionPointer)( x, y, z );

        h[0] += a ? b : ((int)c).d;

        new Handler();
    }
} a, b, c; // struct instances

class Class2
{
/* Array creation with multiple non-array elements.
 * 
 * If you give this example with the elements on the same line, then 
 * Polystyle will automatically vertically align them into a grid when it 
 * fits your code to the page. An alternate style is to have each
 * element on its own line, like this:
 * {
 * x,
 * y
 * z
 * }
 */
boolean *bools1 =
    {
    x, y, z
    };

// array creation with a single element
boolean bools2 = { x };

// array creation with no elements
boolean bools3 = { };

// multidimensional array creation 
const int *** array =
    {
    { 1, 2, 3 },
    { 1, 2, 3 },
    { 1, 2, 3 },
    };
};

#if x

#define x

#elif a

#define x

#else

#define x

#define x

#define x

#endif

// see if multi line macros are safely handled:
#define multilinemacro do { x= x+5; } while (0); \
printf("a multilinemacro"); \
printf("a multilinemacro2");