本文整理匯總了Golang中rsc/io/grind/grinder.EditBuffer.BeforeComments方法的典型用法代碼示例。如果您正苦於以下問題:Golang EditBuffer.BeforeComments方法的具體用法?Golang EditBuffer.BeforeComments怎麽用?Golang EditBuffer.BeforeComments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rsc/io/grind/grinder.EditBuffer
的用法示例。
在下文中一共展示了EditBuffer.BeforeComments方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: findTargetBlock
func findTargetBlock(pkg *grinder.Package, edit *grinder.EditBuffer, fn *ast.FuncDecl, blocks *block.Graph, labelname string) (target targetBlock, ok bool) {
if debug {
println("FINDTARGET", labelname)
}
lstmt := blocks.Label[labelname]
if lstmt == nil {
return
}
list := grinder.BlockList(blocks.Map[lstmt].Root)
if list == nil {
return
}
ulstmt := grinder.Unlabel(lstmt)
for i := 0; i < len(list); i++ {
if grinder.Unlabel(list[i]) == ulstmt {
// Found statement. Find extent of block.
if debug {
println("FOUND")
}
end := i
for ; ; end++ {
if end >= len(list) {
if debug {
println("EARLY END")
}
// List ended without terminating statement.
// Unless this is the top-most block, we can't hoist this code.
if blocks.Map[lstmt].Root != fn.Body {
return
}
// Top-most block. Implicit return at end of list.
target.needReturn = true
break
}
if end > i && grinder.IsGotoTarget(blocks, list[end]) {
if debug {
println("FOUND TARGET")
}
target.needGoto = list[end].(*ast.LabeledStmt).Label.Name
break
}
if grinder.IsTerminatingStmt(blocks, list[end]) {
if debug {
println("TERMINATING")
}
end++
break
}
}
if end <= i {
if debug {
println("NOTHING")
}
return
}
if debug {
println("OK")
}
target.dead = i > 0 && grinder.IsTerminatingStmt(blocks, list[i-1])
target.start = lstmt.Pos()
target.comment = edit.BeforeComments(target.start)
target.endLabel = lstmt.Colon + 1
target.end = edit.End(list[end-1])
target.code = strings.TrimSpace(edit.TextAt(lstmt.Colon+1, target.end))
target.short = end == i+1 && (isReturn(grinder.Unlabel(list[i])) || isEmpty(grinder.Unlabel(list[i])) && target.needReturn)
target.objs = gatherObjs(pkg, fn, lstmt.Pos(), list[i:end])
return target, true
}
}
return
}