当前位置: 首页>>代码示例>>Golang>>正文


Golang BlockStmt.Rbrace方法代码示例

本文整理汇总了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
}
开发者ID:ricardo-rossi,项目名称:godebug,代码行数:27,代码来源:gen.go

示例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
}
开发者ID:9cc9,项目名称:dea_ng,代码行数:7,代码来源:printer.go


注:本文中的go/ast.BlockStmt.Rbrace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。