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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [go/] [printer/] [testdata/] [comments.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
// This is a package for testing comment placement by go/printer.
6
//
7
package main
8
 
9
import "fmt"  // fmt
10
 
11
const c0 = 0  // zero
12
const (
13
        c1 = iota  // c1
14
        c2  // c2
15
)
16
 
17
// Alignment of comments in declarations>
18
const (
19
        _ T = iota  // comment
20
        _  // comment
21
        _  // comment
22
        _ = iota+10
23
        _  // comments
24
 
25
        _ = 10  // comment
26
        _ T = 20  // comment
27
)
28
 
29
const (
30
        _____ = iota // foo
31
        _ // bar
32
        _  = 0    // bal
33
        _ // bat
34
)
35
 
36
const (
37
        _ T = iota // comment
38
        _ // comment
39
        _ // comment
40
        _ = iota + 10
41
        _ // comment
42
        _ = 10
43
        _ = 20 // comment
44
        _ T = 0 // comment
45
)
46
 
47
// The SZ struct; it is empty.
48
type SZ struct {}
49
 
50
// The S0 struct; no field is exported.
51
type S0 struct {
52
        int
53
        x, y, z int  // 3 unexported fields
54
}
55
 
56
// The S1 struct; some fields are not exported.
57
type S1 struct {
58
        S0
59
        A, B, C float  // 3 exported fields
60
        D, b, c int  // 2 unexported fields
61
}
62
 
63
// The S2 struct; all fields are exported.
64
type S2 struct {
65
        S1
66
        A, B, C float  // 3 exported fields
67
}
68
 
69
// The IZ interface; it is empty.
70
type SZ interface {}
71
 
72
// The I0 interface; no method is exported.
73
type I0 interface {
74
        f(x int) int  // unexported method
75
}
76
 
77
// The I1 interface; some methods are not exported.
78
type I1 interface {
79
        I0
80
        F(x float) float  // exported methods
81
        g(x int) int  // unexported method
82
}
83
 
84
// The I2 interface; all methods are exported.
85
type I2 interface {
86
        I0
87
        F(x float) float  // exported method
88
        G(x float) float  // exported method
89
}
90
 
91
// The S3 struct; all comments except for the last one must appear in the export.
92
type S3 struct {
93
        // lead comment for F1
94
        F1 int // line comment for F1
95
        // lead comment for F2
96
        F2 int // line comment for F2
97
        f3 int // f3 is not exported
98
}
99
 
100
// This comment group should be separated
101
// with a newline from the next comment
102
// group.
103
 
104
// This comment should NOT be associated with the next declaration.
105
 
106
var x int  // x
107
var ()
108
 
109
 
110
// This comment SHOULD be associated with f0.
111
func f0() {
112
        const pi = 3.14  // pi
113
        var s1 struct {}  /* an empty struct */ /* foo */
114
        // a struct constructor
115
        // --------------------
116
        var s2 struct {} = struct {}{}
117
        x := pi
118
}
119
//
120
// This comment should be associated with f1, with one blank line before the comment.
121
//
122
func f1() {
123
        f0()
124
        /* 1 */
125
        // 2
126
        /* 3 */
127
        /* 4 */
128
        f0()
129
}
130
 
131
 
132
func _() {
133
// this comment should be properly indented
134
}
135
 
136
 
137
func _(x int) int {
138
        if x < 0 {  // the tab printed before this comment's // must not affect the remaining lines
139
                return -x  // this statement should be properly indented
140
        }
141
        if x < 0 {  /* the tab printed before this comment's /* must not affect the remaining lines */
142
                return -x  // this statement should be properly indented
143
        }
144
        return x
145
}
146
 
147
 
148
func typeswitch(x interface{}) {
149
        switch v := x.(type) {
150
        case bool, int, float:
151
        case string:
152
        default:
153
        }
154
 
155
        switch x.(type) {
156
        }
157
 
158
        switch v0, ok := x.(int); v := x.(type) {
159
        }
160
 
161
        switch v0, ok := x.(int); x.(type) {
162
        case byte:  // this comment should be on the same line as the keyword
163
                // this comment should be normally indented
164
                _ = 0
165
        case bool, int, float:
166
                // this comment should be indented
167
        case string:
168
        default:
169
                // this comment should be indented
170
        }
171
        // this comment should not be indented
172
}
173
 
174
func _() {
175
        /* freestanding comment
176
           aligned              line
177
           aligned line
178
        */
179
}
180
 
181
func _() {
182
        /* freestanding comment
183
           aligned              line
184
           aligned line
185
           */
186
}
187
 
188
func _() {
189
        /* freestanding comment
190
           aligned              line
191
           aligned line */
192
}
193
 
194
func _() {
195
        /*      freestanding comment
196
                aligned         line
197
                aligned line
198
        */
199
}
200
 
201
func _() {
202
        /*      freestanding comment
203
                aligned         line
204
                aligned line
205
                */
206
}
207
 
208
func _() {
209
        /*      freestanding comment
210
                aligned         line
211
                aligned line */
212
}
213
 
214
 
215
func _() {
216
        /*
217
           freestanding comment
218
           aligned              line
219
           aligned line
220
        */
221
}
222
 
223
func _() {
224
        /*
225
           freestanding comment
226
           aligned              line
227
           aligned line
228
           */
229
}
230
 
231
func _() {
232
        /*
233
           freestanding comment
234
           aligned              line
235
           aligned line */
236
}
237
 
238
func _() {
239
        /*
240
                freestanding comment
241
                aligned         line
242
                aligned line
243
        */
244
}
245
 
246
func _() {
247
        /*
248
                freestanding comment
249
                aligned         line
250
                aligned line
251
                */
252
}
253
 
254
func _() {
255
        /*
256
                freestanding comment
257
                aligned         line
258
                aligned line */
259
}
260
 
261
func _() {
262
        /* freestanding comment
263
           aligned line
264
        */
265
}
266
 
267
func _() {
268
        /* freestanding comment
269
           aligned line
270
           */
271
}
272
 
273
func _() {
274
        /* freestanding comment
275
           aligned line */
276
}
277
 
278
func _() {
279
        /*      freestanding comment
280
                aligned line
281
        */
282
}
283
 
284
func _() {
285
        /*      freestanding comment
286
                aligned line
287
                */
288
}
289
 
290
func _() {
291
        /*      freestanding comment
292
                aligned line */
293
}
294
 
295
 
296
func _() {
297
        /*
298
           freestanding comment
299
           aligned line
300
        */
301
}
302
 
303
func _() {
304
        /*
305
           freestanding comment
306
           aligned line
307
           */
308
}
309
 
310
func _() {
311
        /*
312
           freestanding comment
313
           aligned line */
314
}
315
 
316
func _() {
317
        /*
318
                freestanding comment
319
                aligned line
320
        */
321
}
322
 
323
func _() {
324
        /*
325
                freestanding comment
326
                aligned line
327
                */
328
}
329
 
330
func _() {
331
        /*
332
                freestanding comment
333
                aligned line */
334
}
335
 
336
/*
337
 * line
338
 * of
339
 * stars
340
 */
341
 
342
/* another line
343
 * of
344
 * stars */
345
 
346
/*      and another line
347
 *      of
348
 *      stars */
349
 
350
/* a line of
351
 * stars */
352
 
353
/*      and another line of
354
 *      stars */
355
 
356
/* a line of stars
357
*/
358
 
359
/*      and another line of
360
*/
361
 
362
/* a line of stars
363
 */
364
 
365
/*      and another line of
366
 */
367
 
368
/*
369
aligned in middle
370
here
371
        not here
372
*/
373
 
374
/*
375
blank line in middle:
376
 
377
with no leading spaces on blank line.
378
*/
379
 
380
/*
381
   aligned in middle
382
   here
383
           not here
384
*/
385
 
386
/*
387
        blank line in middle:
388
 
389
        with no leading spaces on blank line.
390
*/
391
 
392
func _() {
393
        /*
394
         * line
395
         * of
396
         * stars
397
         */
398
 
399
        /*
400
        aligned in middle
401
        here
402
                not here
403
        */
404
 
405
        /*
406
        blank line in middle:
407
 
408
        with no leading spaces on blank line.
409
*/
410
}
411
 
412
 
413
// Some interesting interspersed comments
414
func _(/* this */x/* is *//* an */ int) {
415
}
416
 
417
func _(/* no params */) {}
418
 
419
func _() {
420
        f(/* no args */)
421
}
422
 
423
func (/* comment1 */ T /* comment2 */) _() {}
424
 
425
func _() { /* one-line functions with comments are formatted as multi-line functions */ }
426
 
427
func _() {
428
        _ = 0
429
        /* closing curly brace should be on new line */ }
430
 
431
func _() {
432
        _ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */}
433
}
434
 
435
 
436
// Comments immediately adjacent to punctuation (for which the go/printer
437
// may only have estimated position information) must remain after the punctuation.
438
func _() {
439
        _ = T{
440
                1,    // comment after comma
441
                2,    /* comment after comma */
442
                3  ,  // comment after comma
443
        }
444
        _ = T{
445
                1  ,// comment after comma
446
                2  ,/* comment after comma */
447
                3,// comment after comma
448
        }
449
        _ = T{
450
                /* comment before literal */1,
451
                2/* comment before comma - ok to move after comma */,
452
                3  /* comment before comma - ok to move after comma */  ,
453
        }
454
 
455
        for
456
                i=0;// comment after semicolon
457
                i<9;/* comment after semicolon */
458
                i++{// comment after opening curly brace
459
        }
460
 
461
        // TODO(gri) the last comment in this example should be aligned */
462
        for
463
                i=0;// comment after semicolon
464
                i<9/* comment before semicolon - ok to move after semicolon */;
465
                i++ /* comment before opening curly brace */ {
466
        }
467
}
468
 
469
 
470
// Line comments with tabs
471
func _() {
472
var     finput          *bufio.Reader                   // input file
473
var     stderr          *bufio.Writer
474
var     ftable          *bufio.Writer                   // y.go file
475
var     foutput         *bufio.Writer                   // y.output file
476
 
477
var     oflag           string                          // -o [y.go]            - y.go file
478
var     vflag           string                          // -v [y.output]        - y.output file
479
var     lflag           bool                            // -l                   - disable line directives
480
}
481
 
482
 
483
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */

powered by: WebSVN 2.1.0

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