From bcbebd5674114329173b475d4663b26408cf6dc2 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sat, 30 Oct 2021 15:05:19 -0700 Subject: [PATCH] build: global Function() and SignatureExpr() (#215) Exposes a few functions on Context that are not available globally. This oversight suggests that #33 or #133 would be reasonable. `Signature()` is currently excluded because it causes a conflict for users who have dot-imported both `build` and `gotypes`. For example: https://github.com/segmentio/asm/blob/18af27c3ce38682a2545f2d95e5ef564dd312d6e/build/base64/decode_asm.go#L13-L14 https://github.com/phoreproject/bls/blob/a88a5ae26844d7293359422888d7c7f69f43c845/asm/asm.go#L6-L7 --- build/global.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/global.go b/build/global.go index 162ca7e..39b58bf 100644 --- a/build/global.go +++ b/build/global.go @@ -122,6 +122,9 @@ func Store(src reg.Register, dst gotypes.Component) { ctx.Store(src, dst) } // Dereference loads a pointer and returns its element type. func Dereference(ptr gotypes.Component) gotypes.Component { return ctx.Dereference(ptr) } +// Function starts building a new function with the given name. +func Function(name string) { ctx.Function(name) } + // Doc sets documentation comment lines for the currently active function. func Doc(lines ...string) { ctx.Doc(lines...) } @@ -131,6 +134,9 @@ func Pragma(directive string, args ...string) { ctx.Pragma(directive, args...) } // Attributes sets function attributes for the currently active function. func Attributes(a attr.Attribute) { ctx.Attributes(a) } +// SignatureExpr parses the signature expression and sets it as the active function's signature. +func SignatureExpr(expr string) { ctx.SignatureExpr(expr) } + // Implement starts building a function of the given name, whose type is // specified by a stub in the containing package. func Implement(name string) { ctx.Implement(name) }