本文整理汇总了Golang中go/scanner.ErrorList.Err方法的典型用法代码示例。如果您正苦于以下问题:Golang ErrorList.Err方法的具体用法?Golang ErrorList.Err怎么用?Golang ErrorList.Err使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/scanner.ErrorList
的用法示例。
在下文中一共展示了ErrorList.Err方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ResolveQualifiedIdents
// ResolveQualifiedIdents resolves the selectors of qualified
// identifiers by associating the correct ast.Object with them.
// TODO(gri): Eventually, this functionality should be subsumed
// by Check.
//
func ResolveQualifiedIdents(fset *token.FileSet, pkg *ast.Package) error {
var errors scanner.ErrorList
findObj := func(pkg *ast.Object, name *ast.Ident) *ast.Object {
scope := pkg.Data.(*ast.Scope)
obj := scope.Lookup(name.Name)
if obj == nil {
errors.Add(fset.Position(name.Pos()), fmt.Sprintf("no %s in package %s", name.Name, pkg.Name))
}
return obj
}
ast.Inspect(pkg, func(n ast.Node) bool {
if s, ok := n.(*ast.SelectorExpr); ok {
if x, ok := s.X.(*ast.Ident); ok && x.Obj != nil && x.Obj.Kind == ast.Pkg {
// find selector in respective package
s.Sel.Obj = findObj(x.Obj, s.Sel)
}
return false
}
return true
})
return errors.Err()
}
示例2: CompileStmtList
func (w *World) CompileStmtList(fset *token.FileSet, stmts []ast.Stmt) (Code, error) {
if len(stmts) == 1 {
if s, ok := stmts[0].(*ast.ExprStmt); ok {
return w.CompileExpr(fset, s.X)
}
}
errors := new(scanner.ErrorList)
cc := &compiler{fset, errors, 0, 0}
cb := newCodeBuf()
fc := &funcCompiler{
compiler: cc,
fnType: nil,
outVarsNamed: false,
codeBuf: cb,
flow: newFlowBuf(cb),
labels: make(map[string]*label),
}
bc := &blockCompiler{
funcCompiler: fc,
block: w.scope.block,
}
nerr := cc.numError()
for _, stmt := range stmts {
bc.compileStmt(stmt)
}
fc.checkLabels()
if nerr != cc.numError() {
errors.Sort()
return nil, errors.Err()
}
return &stmtCode{w, fc.get()}, nil
}
示例3: CompileExpr
func (w *World) CompileExpr(fset *token.FileSet, e ast.Expr) (Code, error) {
errors := new(scanner.ErrorList)
cc := &compiler{fset, errors, 0, 0}
ec := cc.compileExpr(w.scope.block, false, e)
if ec == nil {
errors.Sort()
return nil, errors.Err()
}
var eval func(Value, *Thread)
switch t := ec.t.(type) {
case *idealIntType:
// nothing
case *idealFloatType:
// nothing
default:
if tm, ok := t.(*MultiType); ok && len(tm.Elems) == 0 {
return &stmtCode{w, code{ec.exec}}, nil
}
eval = genAssign(ec.t, ec)
}
return &exprCode{w, ec, eval}, nil
}