本文整理汇总了Golang中go/ast.BlockStmt.Rbrace方法的典型用法代码示例。如果您正苦于以下问题:Golang BlockStmt.Rbrace方法的具体用法?Golang BlockStmt.Rbrace怎么用?Golang BlockStmt.Rbrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.BlockStmt
的用法示例。
在下文中一共展示了BlockStmt.Rbrace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: rewriteFnWithRecovers
func rewriteFnWithRecovers(body *ast.BlockStmt, fnType *ast.FuncType) (wrapped *ast.FuncLit) {
// The formatting of the channel declaration is ugly, but it's presented this way here to show how it will look in the actual output.
// As far as I know, I would need to set the token.Pos values for the left and right braces of the struct and interface type literals
// in order to get them on one line, but I don't think I can do that without computing all of the other token.Pos values for everything
// else I generate.
// TODO: These identifiers will probably conflict if there is a nested function that also has unnamed outputs. Should probably make a better gensym.
outputDecls, outputs := inputsOrOutputs(fnType.Results, idents.result)
if len(outputs) > 0 {
body.List = astPrintf(`%s = func() (%s) {%s}()`, outputs, fnType.Results, body.List)
}
body.List = astPrintf(`
{{%s}}
_r := make(chan chan interface {
})
recovers, panicChan := godebug.EnterFuncWithRecovers(_r, func(ctx *godebug.Context) {
%s
})
for recoverChan := range recovers {
recoverChan <- recover()
}
if panicVal, ok := <-panicChan; ok {
panic(panicVal)
}
{{return %s}}`, outputDecls, body.List, outputs)
body.Rbrace = token.NoPos // without this I was getting extra whitespace at the end of the function
return wrapped
}
示例2: trimBlock
func (lp *linePrinter) trimBlock(stmt *ast.BlockStmt) *ast.BlockStmt {
if !lp.trim(stmt) {
return lp.emptyBlock(stmt)
}
stmt.Rbrace = stmt.Lbrace
return stmt
}