LEFT | RIGHT |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 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 // This file contains the pieces of the tool that use typechecking from the go/t
ypes package. | 5 // This file contains the pieces of the tool that use typechecking from the go/t
ypes package. |
6 | 6 |
7 package main | 7 package main |
8 | 8 |
9 import ( | 9 import ( |
10 "go/ast" | 10 "go/ast" |
(...skipping 15 matching lines...) Expand all Loading... |
26 // past the first error. There is no need for that function to do anythi
ng. | 26 // past the first error. There is no need for that function to do anythi
ng. |
27 config := types.Config{ | 27 config := types.Config{ |
28 Error: func(error) {}, | 28 Error: func(error) {}, |
29 } | 29 } |
30 info := &types.Info{ | 30 info := &types.Info{ |
31 Types: pkg.types, | 31 Types: pkg.types, |
32 Values: pkg.values, | 32 Values: pkg.values, |
33 Objects: pkg.idents, | 33 Objects: pkg.idents, |
34 Implicits: pkg.implicits, | 34 Implicits: pkg.implicits, |
35 } | 35 } |
36 » _, err := config.Check(pkg.path, fs, astFiles, info) | 36 » var err error |
| 37 » pkg.typesPackage, err = config.Check(pkg.path, fs, astFiles, info) |
37 // Update spans. | 38 // Update spans. |
38 for id, obj := range pkg.idents { | 39 for id, obj := range pkg.idents { |
39 pkg.growSpan(id, obj) | 40 pkg.growSpan(id, obj) |
40 } | 41 } |
41 return err | 42 return err |
42 } | 43 } |
43 | 44 |
44 // isStruct reports whether the composite literal c is a struct. | 45 // isStruct reports whether the composite literal c is a struct. |
45 // If it is not (probably a struct), it returns a printable form of the type. | 46 // If it is not (probably a struct), it returns a printable form of the type. |
46 func (pkg *Package) isStruct(c *ast.CompositeLit) (bool, string) { | 47 func (pkg *Package) isStruct(c *ast.CompositeLit) (bool, string) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 return false | 279 return false |
279 } | 280 } |
280 // Finally the real questions. | 281 // Finally the real questions. |
281 // There must be one result. | 282 // There must be one result. |
282 if sig.Results().Len() != 1 { | 283 if sig.Results().Len() != 1 { |
283 return false | 284 return false |
284 } | 285 } |
285 // It must have return type "string" from the universe. | 286 // It must have return type "string" from the universe. |
286 return sig.Results().At(0).Type() == types.Typ[types.String] | 287 return sig.Results().At(0).Type() == types.Typ[types.String] |
287 } | 288 } |
LEFT | RIGHT |