本文整理汇总了Golang中go/ast.ReturnStmt.Pos方法的典型用法代码示例。如果您正苦于以下问题:Golang ReturnStmt.Pos方法的具体用法?Golang ReturnStmt.Pos怎么用?Golang ReturnStmt.Pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.ReturnStmt
的用法示例。
在下文中一共展示了ReturnStmt.Pos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: compileReturnStmt
func (a *stmtCompiler) compileReturnStmt(s *ast.ReturnStmt) {
if a.fnType == nil {
a.diag("cannot return at the top level")
return
}
if len(s.Results) == 0 && (len(a.fnType.Out) == 0 || a.outVarsNamed) {
// Simple case. Simply exit from the function.
a.flow.putTerm()
a.push(func(v *Thread) { v.pc = returnPC })
return
}
bc := a.enterChild()
defer bc.exit()
// Compile expressions
bad := false
rs := make([]*expr, len(s.Results))
for i, re := range s.Results {
rs[i] = a.compileExpr(bc.block, false, re)
if rs[i] == nil {
bad = true
}
}
if bad {
return
}
// Create assigner
// However, if the expression list in the "return" statement
// is a single call to a multi-valued function, the values
// returned from the called function will be returned from
// this one.
assign := a.compileAssign(s.Pos(), bc.block, NewMultiType(a.fnType.Out), rs, "return", "value")
// XXX(Spec) "The result types of the current function and the
// called function must match." Match is fuzzy. It should
// say that they must be assignment compatible.
// Compile
start := len(a.fnType.In)
nout := len(a.fnType.Out)
a.flow.putTerm()
a.push(func(t *Thread) {
assign(multiV(t.f.Vars[start:start+nout]), t)
t.pc = returnPC
})
}
示例2: validRetStmt
func (f *File) validRetStmt(ret *ast.ReturnStmt) *Error {
// returning nothing is ok
if ret.Results == nil || len(ret.Results) == 0 {
return nil
}
// Cannot return multiple values
if len(ret.Results) > 1 {
return &Error{errors.New("Return statements can only have one result"), ret.Pos()}
}
expr := ret.Results[0]
if err := f.validRetExpr(expr); err != nil {
return err
}
return nil
}