OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package eval | 5 package eval |
6 | 6 |
7 import ( | 7 import ( |
8 "go/ast" | 8 "go/ast" |
9 "go/token" | 9 "go/token" |
10 "log" | 10 "log" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 a.diagAt(x.Len, "array length must be non-negative") | 79 a.diagAt(x.Len, "array length must be non-negative") |
80 return nil | 80 return nil |
81 } | 81 } |
82 if elem == nil { | 82 if elem == nil { |
83 return nil | 83 return nil |
84 } | 84 } |
85 | 85 |
86 return NewArrayType(l, elem) | 86 return NewArrayType(l, elem) |
87 } | 87 } |
88 | 88 |
89 func countFields(fs []*ast.Field) int { | 89 func (a *typeCompiler) compileFields(fields *ast.FieldList, allowRec bool) ([]Ty
pe, []*ast.Ident, []token.Position, bool) { |
90 » n := 0 | 90 » n := fields.NumFields() |
91 » for _, f := range fs { | |
92 » » if f.Names == nil { | |
93 » » » n++ | |
94 » » } else { | |
95 » » » n += len(f.Names) | |
96 » » } | |
97 » } | |
98 » return n | |
99 } | |
100 | |
101 func (a *typeCompiler) compileFields(fs []*ast.Field, allowRec bool) ([]Type, []
*ast.Ident, []token.Position, bool) { | |
102 » n := countFields(fs) | |
103 ts := make([]Type, n) | 91 ts := make([]Type, n) |
104 ns := make([]*ast.Ident, n) | 92 ns := make([]*ast.Ident, n) |
105 ps := make([]token.Position, n) | 93 ps := make([]token.Position, n) |
| 94 bad := false |
106 | 95 |
107 » bad := false | 96 » if fields != nil { |
108 » i := 0 | 97 » » i := 0 |
109 » for _, f := range fs { | 98 » » for _, f := range fields.List { |
110 » » t := a.compileType(f.Type, allowRec) | 99 » » » t := a.compileType(f.Type, allowRec) |
111 » » if t == nil { | 100 » » » if t == nil { |
112 » » » bad = true | 101 » » » » bad = true |
113 » » } | 102 » » » } |
114 » » if f.Names == nil { | 103 » » » if f.Names == nil { |
115 » » » ns[i] = nil | 104 » » » » ns[i] = nil |
116 » » » ts[i] = t | 105 » » » » ts[i] = t |
117 » » » ps[i] = f.Type.Pos() | 106 » » » » ps[i] = f.Type.Pos() |
118 » » » i++ | 107 » » » » i++ |
119 » » » continue | 108 » » » » continue |
120 » » } | 109 » » » } |
121 » » for _, n := range f.Names { | 110 » » » for _, n := range f.Names { |
122 » » » ns[i] = n | 111 » » » » ns[i] = n |
123 » » » ts[i] = t | 112 » » » » ts[i] = t |
124 » » » ps[i] = n.Pos() | 113 » » » » ps[i] = n.Pos() |
125 » » » i++ | 114 » » » » i++ |
| 115 » » » } |
126 } | 116 } |
127 } | 117 } |
128 | 118 |
129 return ts, ns, ps, bad | 119 return ts, ns, ps, bad |
130 } | 120 } |
131 | 121 |
132 func (a *typeCompiler) compileStructType(x *ast.StructType, allowRec bool) Type
{ | 122 func (a *typeCompiler) compileStructType(x *ast.StructType, allowRec bool) Type
{ |
133 ts, names, poss, bad := a.compileFields(x.Fields, allowRec) | 123 ts, names, poss, bad := a.compileFields(x.Fields, allowRec) |
134 | 124 |
135 // XXX(Spec) The spec claims that field identifiers must be | 125 // XXX(Spec) The spec claims that field identifiers must be |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 func (a *compiler) compileFuncType(b *block, typ *ast.FuncType) *FuncDecl { | 400 func (a *compiler) compileFuncType(b *block, typ *ast.FuncType) *FuncDecl { |
411 tc := &typeCompiler{a, b, noLateCheck} | 401 tc := &typeCompiler{a, b, noLateCheck} |
412 res := tc.compileFuncType(typ, false) | 402 res := tc.compileFuncType(typ, false) |
413 if res != nil { | 403 if res != nil { |
414 if !tc.lateCheck() { | 404 if !tc.lateCheck() { |
415 res = nil | 405 res = nil |
416 } | 406 } |
417 } | 407 } |
418 return res | 408 return res |
419 } | 409 } |
OLD | NEW |