OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [go/] [printer/] [testdata/] [statements.input] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package statements
6
 
7
var expr bool
8
 
9
func use(x interface{}) {}
10
 
11
// Formatting of if-statement headers.
12
func _() {
13
        if true {}
14
        if; true {}  // no semicolon printed
15
        if expr{}
16
        if;expr{}  // no semicolon printed
17
        if (expr){}  // no parens printed
18
        if;((expr)){}  // no semicolon and parens printed
19
        if x:=expr;true{
20
        use(x)}
21
        if x:=expr; expr {use(x)}
22
}
23
 
24
 
25
// Formatting of switch-statement headers.
26
func _() {
27
        switch {}
28
        switch;{}  // no semicolon printed
29
        switch expr {}
30
        switch;expr{}  // no semicolon printed
31
        switch (expr) {}  // no parens printed
32
        switch;((expr)){}  // no semicolon and parens printed
33
        switch x := expr; { default:use(
34
x)
35
        }
36
        switch x := expr; expr {default:use(x)}
37
}
38
 
39
 
40
// Formatting of switch statement bodies.
41
func _() {
42
        switch {
43
        }
44
 
45
        switch x := 0; x {
46
        case 1:
47
                use(x)
48
                use(x)  // followed by an empty line
49
 
50
        case 2:  // followed by an empty line
51
 
52
                use(x)  // followed by an empty line
53
 
54
        case 3:  // no empty lines
55
                use(x)
56
                use(x)
57
        }
58
 
59
        switch x {
60
        case 0:
61
                use(x)
62
        case 1:  // this comment should have no effect on the previous or next line
63
                use(x)
64
        }
65
 
66
        switch x := 0; x {
67
        case 1:
68
                x = 0
69
                // this comment should be indented
70
        case 2:
71
                x = 0
72
        // this comment should not be indented, it is aligned with the next case
73
        case 3:
74
                x = 0
75
                /* indented comment
76
                   aligned
77
                   aligned
78
                */
79
                // bla
80
                /* and more */
81
        case 4:
82
                x = 0
83
        /* not indented comment
84
           aligned
85
           aligned
86
        */
87
        // bla
88
        /* and more */
89
        case 5:
90
        }
91
}
92
 
93
 
94
// Formatting of selected select statements.
95
func _() {
96
        select {
97
        }
98
        select { /* this comment should not be tab-aligned because the closing } is on the same line */ }
99
        select { /* this comment should be tab-aligned */
100
        }
101
        select { // this comment should be tab-aligned
102
        }
103
        select { case <-c: }
104
}
105
 
106
 
107
// Formatting of for-statement headers.
108
func _() {
109
        for{}
110
        for expr {}
111
        for (expr) {}  // no parens printed
112
        for;;{}  // no semicolons printed
113
        for x :=expr;; {use( x)}
114
        for; expr;{}  // no semicolons printed
115
        for; ((expr));{}  // no semicolons and parens printed
116
        for; ; expr = false {}
117
        for x :=expr; expr; {use(x)}
118
        for x := expr;; expr=false {use(x)}
119
        for;expr;expr =false {
120
        }
121
        for x := expr;expr;expr = false { use(x) }
122
        for x := range []int{} { use(x) }
123
        for x := range (([]int{})) { use(x) }  // no parens printed
124
}
125
 
126
 
127
// Don't remove mandatory parentheses around composite literals in control clauses.
128
func _() {
129
        // strip parentheses - no composite literals or composite literals don't start with a type name
130
        if (x) {}
131
        if (((x))) {}
132
        if ([]T{}) {}
133
        if (([]T{})) {}
134
        if ; (((([]T{})))) {}
135
 
136
        for (x) {}
137
        for (((x))) {}
138
        for ([]T{}) {}
139
        for (([]T{})) {}
140
        for ; (((([]T{})))) ; {}
141
 
142
        switch (x) {}
143
        switch (((x))) {}
144
        switch ([]T{}) {}
145
        switch ; (((([]T{})))) {}
146
 
147
        for _ = range ((([]T{T{42}}))) {}
148
 
149
        // leave parentheses - composite literals start with a type name
150
        if (T{}) {}
151
        if ((T{})) {}
152
        if ; ((((T{})))) {}
153
 
154
        for (T{}) {}
155
        for ((T{})) {}
156
        for ; ((((T{})))) ; {}
157
 
158
        switch (T{}) {}
159
        switch ; ((((T{})))) {}
160
 
161
        for _ = range (((T1{T{42}}))) {}
162
 
163
        if x == (T{42}[0]) {}
164
        if (x == T{42}[0]) {}
165
        if (x == (T{42}[0])) {}
166
        if (x == (((T{42}[0])))) {}
167
        if (((x == (T{42}[0])))) {}
168
        if x == a + b*(T{42}[0]) {}
169
        if (x == a + b*T{42}[0]) {}
170
        if (x == a + b*(T{42}[0])) {}
171
        if (x == a + ((b * (T{42}[0])))) {}
172
        if (((x == a + b * (T{42}[0])))) {}
173
        if (((a + b * (T{42}[0])) == x)) {}
174
        if (((a + b * (T{42}[0])))) == x {}
175
 
176
        if (struct{x bool}{false}.x) {}
177
        if (struct{x bool}{false}.x) == false {}
178
        if (struct{x bool}{false}.x == false) {}
179
}
180
 
181
 
182
// Extra empty lines inside functions. Do respect source code line
183
// breaks between statement boundaries but print at most one empty
184
// line at a time.
185
func _() {
186
 
187
        const _ = 0
188
 
189
        const _ = 1
190
        type _ int
191
        type _ float
192
 
193
        var _ = 0
194
        var x = 1
195
 
196
        // Each use(x) call below should have at most one empty line before and after.
197
        // Known bug: The first use call may have more than one empty line before
198
        //            (see go/printer/nodes.go, func linebreak).
199
 
200
 
201
 
202
        use(x)
203
 
204
        if x < x {
205
 
206
                use(x)
207
 
208
        } else {
209
 
210
                use(x)
211
 
212
        }
213
}
214
 
215
 
216
// Formatting around labels.
217
func _() {
218
        L:
219
}
220
 
221
 
222
func _() {
223
        // this comment should be indented
224
        L: ;  // no semicolon needed
225
}
226
 
227
 
228
func _() {
229
        switch 0 {
230
        case 0:
231
                L0: ;  // semicolon required
232
        case 1:
233
                L1: ;  // semicolon required
234
        default:
235
                L2: ;  // no semicolon needed
236
        }
237
}
238
 
239
 
240
func _() {
241
        f()
242
L1:
243
        f()
244
L2:
245
        ;
246
L3:
247
}
248
 
249
 
250
func _() {
251
        // this comment should be indented
252
        L:
253
}
254
 
255
 
256
func _() {
257
        L: _ = 0
258
}
259
 
260
 
261
func _() {
262
        // this comment should be indented
263
        L: _ = 0
264
}
265
 
266
 
267
func _() {
268
        for {
269
        L1: _ = 0
270
        L2:
271
                _ = 0
272
        }
273
}
274
 
275
 
276
func _() {
277
                // this comment should be indented
278
        for {
279
        L1: _ = 0
280
        L2:
281
                _ = 0
282
        }
283
}
284
 
285
 
286
func _() {
287
        if true {
288
                _ = 0
289
        }
290
        _ = 0  // the indentation here should not be affected by the long label name
291
AnOverlongLabel:
292
        _ = 0
293
 
294
        if true {
295
                _ = 0
296
        }
297
        _ = 0
298
 
299
L:      _ = 0
300
}
301
 
302
 
303
func _() {
304
        for {
305
                goto L
306
        }
307
L:
308
 
309
        MoreCode()
310
}
311
 
312
 
313
func _() {
314
        for {
315
                goto L
316
        }
317
L:      // A comment on the same line as the label, followed by a single empty line.
318
        // Known bug: There may be more than one empty line before MoreCode()
319
        //            (see go/printer/nodes.go, func linebreak).
320
 
321
 
322
 
323
 
324
        MoreCode()
325
}
326
 
327
 
328
func _() {
329
        for {
330
                goto L
331
        }
332
L:
333
 
334
 
335
 
336
 
337
        // There should be a single empty line before this comment.
338
        MoreCode()
339
}
340
 
341
 
342
func _() {
343
        for {
344
                goto AVeryLongLabelThatShouldNotAffectFormatting
345
        }
346
AVeryLongLabelThatShouldNotAffectFormatting:
347
        // There should be a single empty line after this comment.
348
 
349
        // There should be a single empty line before this comment.
350
        MoreCode()
351
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.