本文整理汇总了Golang中go/ast.ReturnStmt类的典型用法代码示例。如果您正苦于以下问题:Golang ReturnStmt类的具体用法?Golang ReturnStmt怎么用?Golang ReturnStmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReturnStmt类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: parseReturnStmt
func (p *parser) parseReturnStmt(n *parse.Node) ast.Stmt {
ret := ast.ReturnStmt{
Return: token.Pos(n.Child(0).Pos()),
}
if n.ChildCount() > 1 {
ret.Results = p.parseExprList(n.Child(1))
}
return &ret
}
开发者ID:h12w,项目名称:gombi,代码行数:9,代码来源:parser.go
示例2: 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
})
}
开发者ID:go-nosql,项目名称:golang,代码行数:50,代码来源:stmt.go
示例3: 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
}
开发者ID:bjwbell,项目名称:gensimd,代码行数:15,代码来源:parse.go
注:本文中的go/ast.ReturnStmt类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论