Source file
src/go/ast/ast.go
1
2
3
4
5
6
7
8 package ast
9
10 import (
11 "go/token"
12 "strings"
13 )
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 type Node interface {
34 Pos() token.Pos
35 End() token.Pos
36 }
37
38
39 type Expr interface {
40 Node
41 exprNode()
42 }
43
44
45 type Stmt interface {
46 Node
47 stmtNode()
48 }
49
50
51 type Decl interface {
52 Node
53 declNode()
54 }
55
56
57
58
59
60
61
62
63
64
65 type Comment struct {
66 Slash token.Pos
67 Text string
68 }
69
70 func (c *Comment) Pos() token.Pos { return c.Slash }
71 func (c *Comment) End() token.Pos { return token.Pos(int(c.Slash) + len(c.Text)) }
72
73
74
75
76 type CommentGroup struct {
77 List []*Comment
78 }
79
80 func (g *CommentGroup) Pos() token.Pos { return g.List[0].Pos() }
81 func (g *CommentGroup) End() token.Pos { return g.List[len(g.List)-1].End() }
82
83 func isWhitespace(ch byte) bool { return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' }
84
85 func stripTrailingWhitespace(s string) string {
86 i := len(s)
87 for i > 0 && isWhitespace(s[i-1]) {
88 i--
89 }
90 return s[0:i]
91 }
92
93
94
95
96
97
98
99 func (g *CommentGroup) Text() string {
100 if g == nil {
101 return ""
102 }
103 comments := make([]string, len(g.List))
104 for i, c := range g.List {
105 comments[i] = c.Text
106 }
107
108 lines := make([]string, 0, 10)
109 for _, c := range comments {
110
111
112 switch c[1] {
113 case '/':
114
115 c = c[2:]
116 if len(c) == 0 {
117
118 break
119 }
120 if c[0] == ' ' {
121
122 c = c[1:]
123 break
124 }
125 if isDirective(c) {
126
127 continue
128 }
129 case '*':
130
131 c = c[2 : len(c)-2]
132 }
133
134
135 cl := strings.Split(c, "\n")
136
137
138 for _, l := range cl {
139 lines = append(lines, stripTrailingWhitespace(l))
140 }
141 }
142
143
144
145 n := 0
146 for _, line := range lines {
147 if line != "" || n > 0 && lines[n-1] != "" {
148 lines[n] = line
149 n++
150 }
151 }
152 lines = lines[0:n]
153
154
155 if n > 0 && lines[n-1] != "" {
156 lines = append(lines, "")
157 }
158
159 return strings.Join(lines, "\n")
160 }
161
162
163 func isDirective(c string) bool {
164
165
166 if strings.HasPrefix(c, "line ") {
167 return true
168 }
169
170
171
172 colon := strings.Index(c, ":")
173 if colon <= 0 || colon+1 >= len(c) {
174 return false
175 }
176 for i := 0; i <= colon+1; i++ {
177 if i == colon {
178 continue
179 }
180 b := c[i]
181 if !('a' <= b && b <= 'z' || '0' <= b && b <= '9') {
182 return false
183 }
184 }
185 return true
186 }
187
188
189
190
191
192
193
194
195
196 type Field struct {
197 Doc *CommentGroup
198 Names []*Ident
199 Type Expr
200 Tag *BasicLit
201 Comment *CommentGroup
202 }
203
204 func (f *Field) Pos() token.Pos {
205 if len(f.Names) > 0 {
206 return f.Names[0].Pos()
207 }
208 if f.Type != nil {
209 return f.Type.Pos()
210 }
211 return token.NoPos
212 }
213
214 func (f *Field) End() token.Pos {
215 if f.Tag != nil {
216 return f.Tag.End()
217 }
218 if f.Type != nil {
219 return f.Type.End()
220 }
221 if len(f.Names) > 0 {
222 return f.Names[len(f.Names)-1].End()
223 }
224 return token.NoPos
225 }
226
227
228
229 type FieldList struct {
230 Opening token.Pos
231 List []*Field
232 Closing token.Pos
233 }
234
235 func (f *FieldList) Pos() token.Pos {
236 if f.Opening.IsValid() {
237 return f.Opening
238 }
239
240
241 if len(f.List) > 0 {
242 return f.List[0].Pos()
243 }
244 return token.NoPos
245 }
246
247 func (f *FieldList) End() token.Pos {
248 if f.Closing.IsValid() {
249 return f.Closing + 1
250 }
251
252
253 if n := len(f.List); n > 0 {
254 return f.List[n-1].End()
255 }
256 return token.NoPos
257 }
258
259
260 func (f *FieldList) NumFields() int {
261 n := 0
262 if f != nil {
263 for _, g := range f.List {
264 m := len(g.Names)
265 if m == 0 {
266 m = 1
267 }
268 n += m
269 }
270 }
271 return n
272 }
273
274
275
276
277 type (
278
279
280
281
282 BadExpr struct {
283 From, To token.Pos
284 }
285
286
287 Ident struct {
288 NamePos token.Pos
289 Name string
290 Obj *Object
291 }
292
293
294
295
296 Ellipsis struct {
297 Ellipsis token.Pos
298 Elt Expr
299 }
300
301
302 BasicLit struct {
303 ValuePos token.Pos
304 Kind token.Token
305 Value string
306 }
307
308
309 FuncLit struct {
310 Type *FuncType
311 Body *BlockStmt
312 }
313
314
315 CompositeLit struct {
316 Type Expr
317 Lbrace token.Pos
318 Elts []Expr
319 Rbrace token.Pos
320 Incomplete bool
321 }
322
323
324 ParenExpr struct {
325 Lparen token.Pos
326 X Expr
327 Rparen token.Pos
328 }
329
330
331 SelectorExpr struct {
332 X Expr
333 Sel *Ident
334 }
335
336
337 IndexExpr struct {
338 X Expr
339 Lbrack token.Pos
340 Index Expr
341 Rbrack token.Pos
342 }
343
344
345
346 IndexListExpr struct {
347 X Expr
348 Lbrack token.Pos
349 Indices []Expr
350 Rbrack token.Pos
351 }
352
353
354 SliceExpr struct {
355 X Expr
356 Lbrack token.Pos
357 Low Expr
358 High Expr
359 Max Expr
360 Slice3 bool
361 Rbrack token.Pos
362 }
363
364
365
366
367 TypeAssertExpr struct {
368 X Expr
369 Lparen token.Pos
370 Type Expr
371 Rparen token.Pos
372 }
373
374
375 CallExpr struct {
376 Fun Expr
377 Lparen token.Pos
378 Args []Expr
379 Ellipsis token.Pos
380 Rparen token.Pos
381 }
382
383
384
385
386 StarExpr struct {
387 Star token.Pos
388 X Expr
389 }
390
391
392
393
394 UnaryExpr struct {
395 OpPos token.Pos
396 Op token.Token
397 X Expr
398 }
399
400
401 BinaryExpr struct {
402 X Expr
403 OpPos token.Pos
404 Op token.Token
405 Y Expr
406 }
407
408
409
410
411 KeyValueExpr struct {
412 Key Expr
413 Colon token.Pos
414 Value Expr
415 }
416 )
417
418
419
420
421 type ChanDir int
422
423 const (
424 SEND ChanDir = 1 << iota
425 RECV
426 )
427
428
429
430
431
432 type (
433
434 ArrayType struct {
435 Lbrack token.Pos
436 Len Expr
437 Elt Expr
438 }
439
440
441 StructType struct {
442 Struct token.Pos
443 Fields *FieldList
444 Incomplete bool
445 }
446
447
448
449
450 FuncType struct {
451 Func token.Pos
452 TypeParams *FieldList
453 Params *FieldList
454 Results *FieldList
455 }
456
457
458 InterfaceType struct {
459 Interface token.Pos
460 Methods *FieldList
461 Incomplete bool
462 }
463
464
465 MapType struct {
466 Map token.Pos
467 Key Expr
468 Value Expr
469 }
470
471
472 ChanType struct {
473 Begin token.Pos
474 Arrow token.Pos
475 Dir ChanDir
476 Value Expr
477 }
478 )
479
480
481
482 func (x *BadExpr) Pos() token.Pos { return x.From }
483 func (x *Ident) Pos() token.Pos { return x.NamePos }
484 func (x *Ellipsis) Pos() token.Pos { return x.Ellipsis }
485 func (x *BasicLit) Pos() token.Pos { return x.ValuePos }
486 func (x *FuncLit) Pos() token.Pos { return x.Type.Pos() }
487 func (x *CompositeLit) Pos() token.Pos {
488 if x.Type != nil {
489 return x.Type.Pos()
490 }
491 return x.Lbrace
492 }
493 func (x *ParenExpr) Pos() token.Pos { return x.Lparen }
494 func (x *SelectorExpr) Pos() token.Pos { return x.X.Pos() }
495 func (x *IndexExpr) Pos() token.Pos { return x.X.Pos() }
496 func (x *IndexListExpr) Pos() token.Pos { return x.X.Pos() }
497 func (x *SliceExpr) Pos() token.Pos { return x.X.Pos() }
498 func (x *TypeAssertExpr) Pos() token.Pos { return x.X.Pos() }
499 func (x *CallExpr) Pos() token.Pos { return x.Fun.Pos() }
500 func (x *StarExpr) Pos() token.Pos { return x.Star }
501 func (x *UnaryExpr) Pos() token.Pos { return x.OpPos }
502 func (x *BinaryExpr) Pos() token.Pos { return x.X.Pos() }
503 func (x *KeyValueExpr) Pos() token.Pos { return x.Key.Pos() }
504 func (x *ArrayType) Pos() token.Pos { return x.Lbrack }
505 func (x *StructType) Pos() token.Pos { return x.Struct }
506 func (x *FuncType) Pos() token.Pos {
507 if x.Func.IsValid() || x.Params == nil {
508 return x.Func
509 }
510 return x.Params.Pos()
511 }
512 func (x *InterfaceType) Pos() token.Pos { return x.Interface }
513 func (x *MapType) Pos() token.Pos { return x.Map }
514 func (x *ChanType) Pos() token.Pos { return x.Begin }
515
516 func (x *BadExpr) End() token.Pos { return x.To }
517 func (x *Ident) End() token.Pos { return token.Pos(int(x.NamePos) + len(x.Name)) }
518 func (x *Ellipsis) End() token.Pos {
519 if x.Elt != nil {
520 return x.Elt.End()
521 }
522 return x.Ellipsis + 3
523 }
524 func (x *BasicLit) End() token.Pos { return token.Pos(int(x.ValuePos) + len(x.Value)) }
525 func (x *FuncLit) End() token.Pos { return x.Body.End() }
526 func (x *CompositeLit) End() token.Pos { return x.Rbrace + 1 }
527 func (x *ParenExpr) End() token.Pos { return x.Rparen + 1 }
528 func (x *SelectorExpr) End() token.Pos { return x.Sel.End() }
529 func (x *IndexExpr) End() token.Pos { return x.Rbrack + 1 }
530 func (x *IndexListExpr) End() token.Pos { return x.Rbrack + 1 }
531 func (x *SliceExpr) End() token.Pos { return x.Rbrack + 1 }
532 func (x *TypeAssertExpr) End() token.Pos { return x.Rparen + 1 }
533 func (x *CallExpr) End() token.Pos { return x.Rparen + 1 }
534 func (x *StarExpr) End() token.Pos { return x.X.End() }
535 func (x *UnaryExpr) End() token.Pos { return x.X.End() }
536 func (x *BinaryExpr) End() token.Pos { return x.Y.End() }
537 func (x *KeyValueExpr) End() token.Pos { return x.Value.End() }
538 func (x *ArrayType) End() token.Pos { return x.Elt.End() }
539 func (x *StructType) End() token.Pos { return x.Fields.End() }
540 func (x *FuncType) End() token.Pos {
541 if x.Results != nil {
542 return x.Results.End()
543 }
544 return x.Params.End()
545 }
546 func (x *InterfaceType) End() token.Pos { return x.Methods.End() }
547 func (x *MapType) End() token.Pos { return x.Value.End() }
548 func (x *ChanType) End() token.Pos { return x.Value.End() }
549
550
551
552
553 func (*BadExpr) exprNode() {}
554 func (*Ident) exprNode() {}
555 func (*Ellipsis) exprNode() {}
556 func (*BasicLit) exprNode() {}
557 func (*FuncLit) exprNode() {}
558 func (*CompositeLit) exprNode() {}
559 func (*ParenExpr) exprNode() {}
560 func (*SelectorExpr) exprNode() {}
561 func (*IndexExpr) exprNode() {}
562 func (*IndexListExpr) exprNode() {}
563 func (*SliceExpr) exprNode() {}
564 func (*TypeAssertExpr) exprNode() {}
565 func (*CallExpr) exprNode() {}
566 func (*StarExpr) exprNode() {}
567 func (*UnaryExpr) exprNode() {}
568 func (*BinaryExpr) exprNode() {}
569 func (*KeyValueExpr) exprNode() {}
570
571 func (*ArrayType) exprNode() {}
572 func (*StructType) exprNode() {}
573 func (*FuncType) exprNode() {}
574 func (*InterfaceType) exprNode() {}
575 func (*MapType) exprNode() {}
576 func (*ChanType) exprNode() {}
577
578
579
580
581
582
583
584 func NewIdent(name string) *Ident { return &Ident{token.NoPos, name, nil} }
585
586
587
588 func IsExported(name string) bool { return token.IsExported(name) }
589
590
591
592 func (id *Ident) IsExported() bool { return token.IsExported(id.Name) }
593
594 func (id *Ident) String() string {
595 if id != nil {
596 return id.Name
597 }
598 return "<nil>"
599 }
600
601
602
603
604
605
606
607 type (
608
609
610
611
612 BadStmt struct {
613 From, To token.Pos
614 }
615
616
617 DeclStmt struct {
618 Decl Decl
619 }
620
621
622
623
624
625 EmptyStmt struct {
626 Semicolon token.Pos
627 Implicit bool
628 }
629
630
631 LabeledStmt struct {
632 Label *Ident
633 Colon token.Pos
634 Stmt Stmt
635 }
636
637
638
639
640 ExprStmt struct {
641 X Expr
642 }
643
644
645 SendStmt struct {
646 Chan Expr
647 Arrow token.Pos
648 Value Expr
649 }
650
651
652 IncDecStmt struct {
653 X Expr
654 TokPos token.Pos
655 Tok token.Token
656 }
657
658
659
660
661 AssignStmt struct {
662 Lhs []Expr
663 TokPos token.Pos
664 Tok token.Token
665 Rhs []Expr
666 }
667
668
669 GoStmt struct {
670 Go token.Pos
671 Call *CallExpr
672 }
673
674
675 DeferStmt struct {
676 Defer token.Pos
677 Call *CallExpr
678 }
679
680
681 ReturnStmt struct {
682 Return token.Pos
683 Results []Expr
684 }
685
686
687
688
689 BranchStmt struct {
690 TokPos token.Pos
691 Tok token.Token
692 Label *Ident
693 }
694
695
696 BlockStmt struct {
697 Lbrace token.Pos
698 List []Stmt
699 Rbrace token.Pos
700 }
701
702
703 IfStmt struct {
704 If token.Pos
705 Init Stmt
706 Cond Expr
707 Body *BlockStmt
708 Else Stmt
709 }
710
711
712 CaseClause struct {
713 Case token.Pos
714 List []Expr
715 Colon token.Pos
716 Body []Stmt
717 }
718
719
720 SwitchStmt struct {
721 Switch token.Pos
722 Init Stmt
723 Tag Expr
724 Body *BlockStmt
725 }
726
727
728 TypeSwitchStmt struct {
729 Switch token.Pos
730 Init Stmt
731 Assign Stmt
732 Body *BlockStmt
733 }
734
735
736 CommClause struct {
737 Case token.Pos
738 Comm Stmt
739 Colon token.Pos
740 Body []Stmt
741 }
742
743
744 SelectStmt struct {
745 Select token.Pos
746 Body *BlockStmt
747 }
748
749
750 ForStmt struct {
751 For token.Pos
752 Init Stmt
753 Cond Expr
754 Post Stmt
755 Body *BlockStmt
756 }
757
758
759 RangeStmt struct {
760 For token.Pos
761 Key, Value Expr
762 TokPos token.Pos
763 Tok token.Token
764 X Expr
765 Body *BlockStmt
766 }
767 )
768
769
770
771 func (s *BadStmt) Pos() token.Pos { return s.From }
772 func (s *DeclStmt) Pos() token.Pos { return s.Decl.Pos() }
773 func (s *EmptyStmt) Pos() token.Pos { return s.Semicolon }
774 func (s *LabeledStmt) Pos() token.Pos { return s.Label.Pos() }
775 func (s *ExprStmt) Pos() token.Pos { return s.X.Pos() }
776 func (s *SendStmt) Pos() token.Pos { return s.Chan.Pos() }
777 func (s *IncDecStmt) Pos() token.Pos { return s.X.Pos() }
778 func (s *AssignStmt) Pos() token.Pos { return s.Lhs[0].Pos() }
779 func (s *GoStmt) Pos() token.Pos { return s.Go }
780 func (s *DeferStmt) Pos() token.Pos { return s.Defer }
781 func (s *ReturnStmt) Pos() token.Pos { return s.Return }
782 func (s *BranchStmt) Pos() token.Pos { return s.TokPos }
783 func (s *BlockStmt) Pos() token.Pos { return s.Lbrace }
784 func (s *IfStmt) Pos() token.Pos { return s.If }
785 func (s *CaseClause) Pos() token.Pos { return s.Case }
786 func (s *SwitchStmt) Pos() token.Pos { return s.Switch }
787 func (s *TypeSwitchStmt) Pos() token.Pos { return s.Switch }
788 func (s *CommClause) Pos() token.Pos { return s.Case }
789 func (s *SelectStmt) Pos() token.Pos { return s.Select }
790 func (s *ForStmt) Pos() token.Pos { return s.For }
791 func (s *RangeStmt) Pos() token.Pos { return s.For }
792
793 func (s *BadStmt) End() token.Pos { return s.To }
794 func (s *DeclStmt) End() token.Pos { return s.Decl.End() }
795 func (s *EmptyStmt) End() token.Pos {
796 if s.Implicit {
797 return s.Semicolon
798 }
799 return s.Semicolon + 1
800 }
801 func (s *LabeledStmt) End() token.Pos { return s.Stmt.End() }
802 func (s *ExprStmt) End() token.Pos { return s.X.End() }
803 func (s *SendStmt) End() token.Pos { return s.Value.End() }
804 func (s *IncDecStmt) End() token.Pos {
805 return s.TokPos + 2
806 }
807 func (s *AssignStmt) End() token.Pos { return s.Rhs[len(s.Rhs)-1].End() }
808 func (s *GoStmt) End() token.Pos { return s.Call.End() }
809 func (s *DeferStmt) End() token.Pos { return s.Call.End() }
810 func (s *ReturnStmt) End() token.Pos {
811 if n := len(s.Results); n > 0 {
812 return s.Results[n-1].End()
813 }
814 return s.Return + 6
815 }
816 func (s *BranchStmt) End() token.Pos {
817 if s.Label != nil {
818 return s.Label.End()
819 }
820 return token.Pos(int(s.TokPos) + len(s.Tok.String()))
821 }
822 func (s *BlockStmt) End() token.Pos {
823 if s.Rbrace.IsValid() {
824 return s.Rbrace + 1
825 }
826 if n := len(s.List); n > 0 {
827 return s.List[n-1].End()
828 }
829 return s.Lbrace + 1
830 }
831 func (s *IfStmt) End() token.Pos {
832 if s.Else != nil {
833 return s.Else.End()
834 }
835 return s.Body.End()
836 }
837 func (s *CaseClause) End() token.Pos {
838 if n := len(s.Body); n > 0 {
839 return s.Body[n-1].End()
840 }
841 return s.Colon + 1
842 }
843 func (s *SwitchStmt) End() token.Pos { return s.Body.End() }
844 func (s *TypeSwitchStmt) End() token.Pos { return s.Body.End() }
845 func (s *CommClause) End() token.Pos {
846 if n := len(s.Body); n > 0 {
847 return s.Body[n-1].End()
848 }
849 return s.Colon + 1
850 }
851 func (s *SelectStmt) End() token.Pos { return s.Body.End() }
852 func (s *ForStmt) End() token.Pos { return s.Body.End() }
853 func (s *RangeStmt) End() token.Pos { return s.Body.End() }
854
855
856
857
858 func (*BadStmt) stmtNode() {}
859 func (*DeclStmt) stmtNode() {}
860 func (*EmptyStmt) stmtNode() {}
861 func (*LabeledStmt) stmtNode() {}
862 func (*ExprStmt) stmtNode() {}
863 func (*SendStmt) stmtNode() {}
864 func (*IncDecStmt) stmtNode() {}
865 func (*AssignStmt) stmtNode() {}
866 func (*GoStmt) stmtNode() {}
867 func (*DeferStmt) stmtNode() {}
868 func (*ReturnStmt) stmtNode() {}
869 func (*BranchStmt) stmtNode() {}
870 func (*BlockStmt) stmtNode() {}
871 func (*IfStmt) stmtNode() {}
872 func (*CaseClause) stmtNode() {}
873 func (*SwitchStmt) stmtNode() {}
874 func (*TypeSwitchStmt) stmtNode() {}
875 func (*CommClause) stmtNode() {}
876 func (*SelectStmt) stmtNode() {}
877 func (*ForStmt) stmtNode() {}
878 func (*RangeStmt) stmtNode() {}
879
880
881
882
883
884
885
886 type (
887
888 Spec interface {
889 Node
890 specNode()
891 }
892
893
894 ImportSpec struct {
895 Doc *CommentGroup
896 Name *Ident
897 Path *BasicLit
898 Comment *CommentGroup
899 EndPos token.Pos
900 }
901
902
903
904
905 ValueSpec struct {
906 Doc *CommentGroup
907 Names []*Ident
908 Type Expr
909 Values []Expr
910 Comment *CommentGroup
911 }
912
913
914 TypeSpec struct {
915 Doc *CommentGroup
916 Name *Ident
917 TypeParams *FieldList
918 Assign token.Pos
919 Type Expr
920 Comment *CommentGroup
921 }
922 )
923
924
925
926 func (s *ImportSpec) Pos() token.Pos {
927 if s.Name != nil {
928 return s.Name.Pos()
929 }
930 return s.Path.Pos()
931 }
932 func (s *ValueSpec) Pos() token.Pos { return s.Names[0].Pos() }
933 func (s *TypeSpec) Pos() token.Pos { return s.Name.Pos() }
934
935 func (s *ImportSpec) End() token.Pos {
936 if s.EndPos != 0 {
937 return s.EndPos
938 }
939 return s.Path.End()
940 }
941
942 func (s *ValueSpec) End() token.Pos {
943 if n := len(s.Values); n > 0 {
944 return s.Values[n-1].End()
945 }
946 if s.Type != nil {
947 return s.Type.End()
948 }
949 return s.Names[len(s.Names)-1].End()
950 }
951 func (s *TypeSpec) End() token.Pos { return s.Type.End() }
952
953
954
955
956 func (*ImportSpec) specNode() {}
957 func (*ValueSpec) specNode() {}
958 func (*TypeSpec) specNode() {}
959
960
961
962 type (
963
964
965
966
967 BadDecl struct {
968 From, To token.Pos
969 }
970
971
972
973
974
975
976
977
978
979
980
981
982 GenDecl struct {
983 Doc *CommentGroup
984 TokPos token.Pos
985 Tok token.Token
986 Lparen token.Pos
987 Specs []Spec
988 Rparen token.Pos
989 }
990
991
992 FuncDecl struct {
993 Doc *CommentGroup
994 Recv *FieldList
995 Name *Ident
996 Type *FuncType
997 Body *BlockStmt
998 }
999 )
1000
1001
1002
1003 func (d *BadDecl) Pos() token.Pos { return d.From }
1004 func (d *GenDecl) Pos() token.Pos { return d.TokPos }
1005 func (d *FuncDecl) Pos() token.Pos { return d.Type.Pos() }
1006
1007 func (d *BadDecl) End() token.Pos { return d.To }
1008 func (d *GenDecl) End() token.Pos {
1009 if d.Rparen.IsValid() {
1010 return d.Rparen + 1
1011 }
1012 return d.Specs[0].End()
1013 }
1014 func (d *FuncDecl) End() token.Pos {
1015 if d.Body != nil {
1016 return d.Body.End()
1017 }
1018 return d.Type.End()
1019 }
1020
1021
1022
1023
1024 func (*BadDecl) declNode() {}
1025 func (*GenDecl) declNode() {}
1026 func (*FuncDecl) declNode() {}
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050 type File struct {
1051 Doc *CommentGroup
1052 Package token.Pos
1053 Name *Ident
1054 Decls []Decl
1055 Scope *Scope
1056 Imports []*ImportSpec
1057 Unresolved []*Ident
1058 Comments []*CommentGroup
1059 }
1060
1061 func (f *File) Pos() token.Pos { return f.Package }
1062 func (f *File) End() token.Pos {
1063 if n := len(f.Decls); n > 0 {
1064 return f.Decls[n-1].End()
1065 }
1066 return f.Name.End()
1067 }
1068
1069
1070
1071
1072 type Package struct {
1073 Name string
1074 Scope *Scope
1075 Imports map[string]*Object
1076 Files map[string]*File
1077 }
1078
1079 func (p *Package) Pos() token.Pos { return token.NoPos }
1080 func (p *Package) End() token.Pos { return token.NoPos }
1081
View as plain text