本文整理汇总了Golang中code/google/com/p/go/tools/go/types.Config.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.Error方法的具体用法?Golang Config.Error怎么用?Golang Config.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/go/tools/go/types.Config
的用法示例。
在下文中一共展示了Config.Error方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TranslatePackage
func TranslatePackage(importPath string, files []*ast.File, fileSet *token.FileSet, config *types.Config) ([]byte, error) {
info := &types.Info{
Types: make(map[ast.Expr]types.Type),
Values: make(map[ast.Expr]exact.Value),
Objects: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
}
var errList ErrorList
var previousErr error
config.Error = func(err error) {
if previousErr != nil && previousErr.Error() == err.Error() {
return
}
errList = append(errList, err)
previousErr = err
}
config.Sizes = sizes32
typesPkg, err := config.Check(importPath, fileSet, files, info)
if errList != nil {
return nil, errList
}
if err != nil {
return nil, err
}
config.Packages[importPath] = typesPkg
c := &PkgContext{
pkg: typesPkg,
info: info,
pkgVars: make(map[string]string),
objectVars: make(map[types.Object]string),
allVarNames: make(map[string]int),
postLoopStmt: make(map[string]ast.Stmt),
positions: make(map[int]token.Pos),
}
for _, name := range ReservedKeywords {
c.allVarNames[name] = 1
}
functionsByType := make(map[types.Type][]*ast.FuncDecl)
functionsByObject := make(map[types.Object]*ast.FuncDecl)
var initStmts []ast.Stmt
var typeSpecs []*ast.TypeSpec
var constSpecs []*ast.ValueSpec
var varSpecs []*ast.ValueSpec
for _, file := range files {
for _, decl := range file.Decls {
switch d := decl.(type) {
case *ast.FuncDecl:
sig := c.info.Objects[d.Name].(*types.Func).Type().(*types.Signature)
var recvType types.Type
if sig.Recv() != nil {
recvType = sig.Recv().Type()
if ptr, isPtr := recvType.(*types.Pointer); isPtr {
recvType = ptr.Elem()
}
}
if sig.Recv() == nil && d.Name.Name == "init" {
initStmts = append(initStmts, d.Body.List...)
continue
}
functionsByType[recvType] = append(functionsByType[recvType], d)
o := c.info.Objects[d.Name]
functionsByObject[o] = d
if sig.Recv() == nil {
c.objectName(o) // register toplevel name
}
case *ast.GenDecl:
switch d.Tok {
case token.TYPE:
for _, spec := range d.Specs {
s := spec.(*ast.TypeSpec)
typeSpecs = append(typeSpecs, s)
c.objectName(c.info.Objects[s.Name]) // register toplevel name
}
case token.CONST:
for _, spec := range d.Specs {
s := spec.(*ast.ValueSpec)
constSpecs = append(constSpecs, s)
for _, name := range s.Names {
if !isBlank(name) {
c.objectName(c.info.Objects[name]) // register toplevel name
}
}
}
case token.VAR:
for _, spec := range d.Specs {
s := spec.(*ast.ValueSpec)
varSpecs = append(varSpecs, s)
for _, name := range s.Names {
if !isBlank(name) {
c.objectName(c.info.Objects[name]) // register toplevel name
}
}
}
}
}
}
//.........这里部分代码省略.........