OSDN Git Service

Update Go library to last weekly.
[pf3gnuchains/gcc-fork.git] / libgo / go / go / printer / testdata / declarations.input
1 // 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 imports
6
7 import "io"
8
9 import (
10         _ "io"
11 )
12
13 import _ "io"
14
15 import (
16         "io"
17         "io"
18         "io"
19 )
20
21 import (
22         "io"
23         aLongRename "io"
24
25         b "io"
26 )
27
28 import (
29        "unrenamed"
30        renamed "renameMe"
31        . "io"
32        _ "io"
33        "io"
34        . "os"
35 )
36
37 // no newlines between consecutive single imports, but
38 // respect extra line breaks in the source (at most one empty line)
39 import _ "io"
40 import _ "io"
41 import _ "io"
42
43 import _ "os"
44 import _ "os"
45 import _ "os"
46
47
48 import _ "fmt"
49 import _ "fmt"
50 import _ "fmt"
51
52 import "foo"  // a comment
53 import "bar"  // a comment
54
55 import (
56         _ "foo"
57         // a comment
58         "bar"
59         "foo"  // a comment
60         "bar"  // a comment
61 )
62
63 // comments + renames
64 import (
65        "unrenamed" // a comment
66        renamed "renameMe"
67        . "io" /* a comment */
68        _ "io/ioutil" // a comment
69        "io" // testing alignment
70        . "os"
71        // a comment
72 )
73
74 // a case that caused problems in the past (comment placement)
75 import (
76         . "fmt"
77         "io"
78         "malloc"        // for the malloc count test only
79         "math"
80         "strings"
81         "testing"
82 )
83
84 // more import examples
85 import (
86         "xxx"
87         "much longer name" // comment
88         "short name" // comment
89 )
90
91 import (
92         _ "xxx"
93         "much longer name" // comment
94 )
95
96 import (
97         mymath "math"
98         "/foo/bar/long_package_path" // a comment
99 )
100
101 import (
102         "package_a" // comment
103         "package_b"
104         my_better_c "package_c" // comment
105         "package_d" // comment
106         my_e "package_e" // comment
107
108         "package_a"    // comment
109         "package_bb"
110         "package_ccc"  // comment
111         "package_dddd" // comment
112 )
113
114 // at least one empty line between declarations of different kind
115 import _ "io"
116 var _ int
117
118
119 // printing of constant literals
120 const (
121         _ = "foobar"
122         _ = "a۰۱۸"
123         _ = "foo६४"
124         _ = "bar9876"
125         _ = 0
126         _ = 1
127         _ = 123456789012345678890
128         _ = 01234567
129         _ = 0xcafebabe
130         _ = 0.
131         _ = .0
132         _ = 3.14159265
133         _ = 1e0
134         _ = 1e+100
135         _ = 1e-100
136         _ = 2.71828e-1000
137         _ = 0i
138         _ = 1i
139         _ = 012345678901234567889i
140         _ = 123456789012345678890i
141         _ = 0.i
142         _ = .0i
143         _ = 3.14159265i
144         _ = 1e0i
145         _ = 1e+100i
146         _ = 1e-100i
147         _ = 2.71828e-1000i
148         _ = 'a'
149         _ = '\000'
150         _ = '\xFF'
151         _ = '\uff16'
152         _ = '\U0000ff16'
153         _ = `foobar`
154         _ = `foo
155 ---
156 ---
157 bar`
158 )
159
160
161 func _() {
162         type _ int
163         type _ *int
164         type _ []int
165         type _ map[string]int
166         type _ chan int
167         type _ func() int
168
169         var _ int
170         var _ *int
171         var _ []int
172         var _ map[string]int
173         var _ chan int
174         var _ func() int
175
176         type _ struct{}
177         type _ *struct{}
178         type _ []struct{}
179         type _ map[string]struct{}
180         type _ chan struct{}
181         type _ func() struct{}
182
183         type _ interface{}
184         type _ *interface{}
185         type _ []interface{}
186         type _ map[string]interface{}
187         type _ chan interface{}
188         type _ func() interface{}
189
190         var _ struct{}
191         var _ *struct{}
192         var _ []struct{}
193         var _ map[string]struct{}
194         var _ chan struct{}
195         var _ func() struct{}
196
197         var _ interface{}
198         var _ *interface{}
199         var _ []interface{}
200         var _ map[string]interface{}
201         var _ chan interface{}
202         var _ func() interface{}
203 }
204
205
206 // don't lose blank lines in grouped declarations
207 const (
208         _ int = 0
209         _ float = 1
210
211         _ string = "foo"
212
213         _ = iota
214         _
215         
216         // a comment
217         _
218
219         _
220 )
221
222
223 type (
224         _ int
225         _ struct {}
226         
227         _ interface{}
228         
229         // a comment
230         _ map[string]int
231 )
232
233
234 var (
235         _ int = 0
236         _ float = 1
237
238         _ string = "foo"
239
240         _ bool
241         
242         // a comment
243         _ bool
244 )
245
246
247 // don't lose blank lines in this struct
248 type _ struct {
249         String struct {
250                 Str, Len int
251         }
252         Slice struct {
253                 Array, Len, Cap int
254         }
255         Eface struct {
256                 Typ, Ptr int
257         }
258
259         UncommonType struct {
260                 Name, PkgPath int
261         }
262         CommonType struct {
263                 Size, Hash, Alg, Align, FieldAlign, String, UncommonType int
264         }
265         Type struct {
266                 Typ, Ptr int
267         }
268         StructField struct {
269                 Name, PkgPath, Typ, Tag, Offset int
270         }
271         StructType struct {
272                 Fields int
273         }
274         PtrType struct {
275                 Elem int
276         }
277         SliceType struct {
278                 Elem int
279         }
280         ArrayType struct {
281                 Elem, Len int
282         }
283
284         Stktop struct {
285                 Stackguard, Stackbase, Gobuf int
286         }
287         Gobuf struct {
288                 Sp, Pc, G int
289         }
290         G struct {
291                 Stackbase, Sched, Status, Alllink int
292         }
293 }
294
295
296 // no tabs for single or ungrouped decls
297 func _() {
298         const xxxxxx = 0
299         type x int
300         var xxx int
301         var yyyy float = 3.14
302         var zzzzz = "bar"
303
304         const (
305                 xxxxxx = 0
306         )
307         type (
308                 x int
309         )
310         var (
311                 xxx int
312         )
313         var (
314                 yyyy float = 3.14
315         )
316         var (
317                 zzzzz = "bar"
318         )
319 }
320
321 // tabs for multiple or grouped decls
322 func _() {
323         // no entry has a type
324         const (
325                 zzzzzz = 1
326                 z = 2
327                 zzz = 3
328         )
329         // some entries have a type
330         const (
331                 xxxxxx = 1
332                 x = 2
333                 xxx = 3
334                 yyyyyyyy float = iota
335                 yyyy = "bar"
336                 yyy
337                 yy = 2
338         )
339 }
340
341 func _() {
342         // no entry has a type
343         var (
344                 zzzzzz = 1
345                 z = 2
346                 zzz = 3
347         )
348         // no entry has a value
349         var (
350                 _ int
351                 _ float
352                 _ string
353
354                 _ int  // comment
355                 _ float  // comment
356                 _ string  // comment
357         )
358         // some entries have a type
359         var (
360                 xxxxxx int
361                 x float
362                 xxx string
363                 yyyyyyyy int = 1234
364                 y float = 3.14
365                 yyyy = "bar"
366                 yyy string = "foo"
367         )
368         // mixed entries - all comments should be aligned
369         var (
370                 a, b, c int
371                 x = 10
372                 d int  // comment
373                 y = 20  // comment
374                 f, ff, fff, ffff int = 0, 1, 2, 3  // comment
375         )
376         // respect original line breaks
377         var _ = []T {
378                 T{0x20, "Telugu"},
379         }
380         var _ = []T {
381                 // respect original line breaks
382                 T{0x20, "Telugu"},
383         }
384 }
385
386 func _() {
387         type (
388                 xxxxxx int
389                 x float
390                 xxx string
391                 xxxxx []x
392                 xx struct{}
393                 xxxxxxx struct {
394                         _, _ int
395                         _ float
396                 }
397                 xxxx chan<- string
398         )
399 }
400
401 // alignment of "=" in consecutive lines (extended example from issue 1414)
402 const (
403         umax uint                  = ^uint(0) // maximum value for a uint
404         bpu  = 1 << (5 + umax>>63)            // bits per uint
405         foo
406         bar  = -1
407 )
408
409 // typical enum
410 const (
411         a MyType = iota
412         abcd
413         b
414         c
415         def
416 )
417
418 // excerpt from godoc.go
419 var (
420         goroot = flag.String("goroot", runtime.GOROOT(), "Go root directory")
421         testDir = flag.String("testdir", "", "Go root subdirectory - for testing only (faster startups)")
422         pkgPath = flag.String("path", "", "additional package directories (colon-separated)")
423         filter = flag.String("filter", "", "filter file containing permitted package directory paths")
424         filterMin = flag.Int("filter_minutes", 0, "filter file update interval in minutes; disabled if <= 0")
425         filterDelay delayTime // actual filter update interval in minutes; usually filterDelay == filterMin, but filterDelay may back off exponentially
426 )
427
428
429 // formatting of structs
430 type _ struct{}
431
432 type _ struct{ /* this comment should be visible */ }
433
434 type _ struct{
435         // this comment should be visible and properly indented
436 }
437
438 type _ struct {  // this comment must not change indentation
439         f int
440         f, ff, fff, ffff int
441 }
442
443 type _ struct {
444         string
445 }
446
447 type _ struct {
448         string  // comment
449 }
450
451 type _ struct {
452         string "tag"
453 }
454
455 type _ struct {
456         string "tag"  // comment
457 }
458
459 type _ struct {
460         f int
461 }
462
463 type _ struct {
464         f int  // comment
465 }
466
467 type _ struct {
468         f int "tag"
469 }
470
471 type _ struct {
472         f int "tag"  // comment
473 }
474
475 type _ struct {
476         bool
477         a, b, c int
478         int "tag"
479         ES // comment
480         float "tag"  // comment
481         f int  // comment
482         f, ff, fff, ffff int  // comment
483         g float "tag"
484         h float "tag"  // comment
485 }
486
487 type _ struct { a, b,
488 c, d int  // this line should be indented
489 u, v, w, x float // this line should be indented
490 p, q,
491 r, s float // this line should be indented
492 }
493
494
495 // difficult cases
496 type _ struct {
497         bool  // comment
498         text []byte  // comment
499 }
500
501
502 // formatting of interfaces
503 type EI interface{}
504
505 type _ interface {
506         EI
507 }
508
509 type _ interface {
510         f()
511         fffff()
512 }
513
514 type _ interface {
515         EI
516         f()
517         fffffg()
518 }
519
520 type _ interface {  // this comment must not change indentation
521         EI  // here's a comment
522         f()  // no blank between identifier and ()
523         fffff()  // no blank between identifier and ()
524         gggggggggggg(x, y, z int) ()  // hurray
525 }
526
527
528 // formatting of variable declarations
529 func _() {
530         type day struct { n int; short, long string }
531         var (
532                 Sunday = day{ 0, "SUN", "Sunday" }
533                 Monday = day{ 1, "MON", "Monday" }
534                 Tuesday = day{ 2, "TUE", "Tuesday" }
535                 Wednesday = day{ 3, "WED", "Wednesday" }
536                 Thursday = day{ 4, "THU", "Thursday" }
537                 Friday = day{ 5, "FRI", "Friday" }
538                 Saturday = day{ 6, "SAT", "Saturday" }
539         )
540 }
541
542
543 // formatting of multi-line variable declarations
544 var a1, b1, c1 int  // all on one line
545
546 var a2, b2,
547 c2 int  // this line should be indented
548
549 var (a3, b3,
550 c3, d3 int  // this line should be indented
551 a4, b4, c4 int  // this line should be indented
552 )
553
554
555 func _() {
556         var privateKey2 = &Block{Type: "RSA PRIVATE KEY",
557                                         Headers: map[string]string{},
558                                         Bytes: []uint8{0x30, 0x82, 0x1, 0x3a, 0x2, 0x1, 0x0, 0x2,
559                         0x41, 0x0, 0xb2, 0x99, 0xf, 0x49, 0xc4, 0x7d, 0xfa, 0x8c,
560                         0xd4, 0x0, 0xae, 0x6a, 0x4d, 0x1b, 0x8a, 0x3b, 0x6a, 0x13,
561                         0x64, 0x2b, 0x23, 0xf2, 0x8b, 0x0, 0x3b, 0xfb, 0x97, 0x79,
562                 },
563         }
564 }
565
566
567 func _() {
568         var Universe = Scope {
569                 Names: map[string]*Ident {
570                         // basic types
571                         "bool": nil,
572                         "byte": nil,
573                         "int8": nil,
574                         "int16": nil,
575                         "int32": nil,
576                         "int64": nil,
577                         "uint8": nil,
578                         "uint16": nil,
579                         "uint32": nil,
580                         "uint64": nil,
581                         "float32": nil,
582                         "float64": nil,
583                         "string": nil,
584
585                         // convenience types
586                         "int": nil,
587                         "uint": nil,
588                         "uintptr": nil,
589                         "float": nil,
590
591                         // constants
592                         "false": nil,
593                         "true": nil,
594                         "iota": nil,
595                         "nil": nil,
596
597                         // functions
598                         "cap": nil,
599                         "len": nil,
600                         "new": nil,
601                         "make": nil,
602                         "panic": nil,
603                         "panicln": nil,
604                         "print": nil,
605                         "println": nil,
606                 },
607         }
608 }
609
610
611 // alignment of map composite entries
612 var _ = map[int]int{
613         // small key sizes: always align even if size ratios are large
614         a: a,
615         abcdefghabcdefgh: a,
616         ab: a,
617         abc: a,
618         abcdefgabcdefg: a,
619         abcd: a,
620         abcde: a,
621         abcdef: a,
622
623         // mixed key sizes: align when key sizes change within accepted ratio
624         abcdefgh: a,
625         abcdefghabcdefg: a,
626         abcdefghij: a,
627         abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij: a, // outlier - do not align with previous line
628         abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij: a, // align with previous line
629
630         ab: a, // do not align with previous line
631         abcde: a, // align with previous line
632 }
633
634
635 func _() {
636         var _ = T{
637                 a,      // must introduce trailing comma
638         }
639 }
640
641
642 // formatting of function results
643 func _() func() {}
644 func _() func(int) { return nil }
645 func _() func(int) int { return nil }
646 func _() func(int) func(int) func() { return nil }
647
648
649 // formatting of consecutive single-line functions
650 func _() {}
651 func _() {}
652 func _() {}
653
654 func _() {}  // an empty line before this function
655 func _() {}
656 func _() {}
657
658 func _() { f(1, 2, 3) }
659 func _(x int) int { y := x; return y+1 }
660 func _() int { type T struct{}; var x T; return x }
661
662 // these must remain multi-line since they are multi-line in the source
663 func _() {
664         f(1, 2, 3)
665 }
666 func _(x int) int {
667         y := x; return y+1
668 }
669 func _() int {
670         type T struct{}; var x T; return x
671 }
672
673
674 // making function declarations safe for new semicolon rules
675 func _() { /* multi-line func because of comment */ }
676
677 func _() {
678 /* multi-line func because block is on multiple lines */ }
679
680
681 // ellipsis parameters
682 func _(...int)
683 func _(...*int)
684 func _(...[]int)
685 func _(...struct{})
686 func _(bool, ...interface{})
687 func _(bool, ...func())
688 func _(bool, ...func(...int))
689 func _(bool, ...map[string]int)
690 func _(bool, ...chan int)
691
692 func _(b bool, x ...int)
693 func _(b bool, x ...*int)
694 func _(b bool, x ...[]int)
695 func _(b bool, x ...struct{})
696 func _(x ...interface{})
697 func _(x ...func())
698 func _(x ...func(...int))
699 func _(x ...map[string]int)
700 func _(x ...chan int)
701
702
703 // these parameter lists must remain multi-line since they are multi-line in the source
704 func _(bool,
705 int) {
706 }
707 func _(x bool,
708 y int) {
709 }
710 func _(x,
711 y bool) {
712 }
713 func _(bool, // comment
714 int) {
715 }
716 func _(x bool, // comment
717 y int) {
718 }
719 func _(x, // comment
720 y bool) {
721 }
722 func _(bool, // comment
723 // comment
724 int) {
725 }
726 func _(x bool, // comment
727 // comment
728 y int) {
729 }
730 func _(x, // comment
731 // comment
732 y bool) {
733 }
734 func _(bool,
735 // comment
736 int) {
737 }
738 func _(x bool,
739 // comment
740 y int) {
741 }
742 func _(x,
743 // comment
744 y bool) {
745 }
746 func _(x, // comment
747 y,// comment
748 z bool) {
749 }
750 func _(x, // comment
751         y,// comment
752         z bool) {
753 }
754 func _(x int,   // comment
755         y float,        // comment
756         z bool) {
757 }
758
759
760 // properly indent multi-line signatures
761 func ManageStatus(in <-chan *Status, req <-chan Request,
762 stat chan<- *TargetInfo,
763 TargetHistorySize int) {
764 }
765
766 func MultiLineSignature0(
767 a, b, c int,
768 ) {}
769
770 func MultiLineSignature1(
771 a, b, c int,
772 u, v, w float,
773 ) {}
774
775 func MultiLineSignature2(
776 a, b,
777 c int,
778 ) {}
779
780 func MultiLineSignature3(
781 a, b,
782 c int, u, v,
783 w float,
784                 x ...int) {}
785
786 func MultiLineSignature4(
787 a, b, c int,
788 u, v,
789 w float,
790                 x ...int) {}
791
792 func MultiLineSignature5(
793 a, b, c int,
794 u, v, w float,
795 p, q,
796 r string,
797                 x ...int) {}
798
799 // make sure it also works for methods in interfaces
800 type _ interface {
801 MultiLineSignature0(
802 a, b, c int,
803 )
804
805 MultiLineSignature1(
806 a, b, c int,
807 u, v, w float,
808 )
809
810 MultiLineSignature2(
811 a, b,
812 c int,
813 )
814
815 MultiLineSignature3(
816 a, b,
817 c int, u, v,
818 w float,
819                 x ...int)
820
821 MultiLineSignature4(
822 a, b, c int,
823 u, v,
824 w float,
825                 x ...int)
826
827 MultiLineSignature5(
828 a, b, c int,
829 u, v, w float,
830 p, q,
831 r string,
832                 x ...int)
833 }