build: Commentf function

Convenience for adding a comment generated with fmt.Sprintf.

Updates #41
This commit is contained in:
Michael McLoughlin
2019-01-11 10:51:32 -08:00
parent 284ee13ada
commit 94033059eb
2 changed files with 9 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package build
import (
"errors"
"fmt"
"go/types"
"github.com/mmcloughlin/avo/attr"
@@ -138,6 +139,11 @@ func (c *Context) Comment(lines ...string) {
c.activefunc().AddComment(lines...)
}
// Commentf adds a formtted comment line.
func (c *Context) Commentf(format string, a ...interface{}) {
c.Comment(fmt.Sprintf(format, a...))
}
func (c *Context) activefunc() *ir.Function {
if c.function == nil {
c.adderrormessage("no active function")