summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/google/gops/internal/obj/stringer.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-03-23 23:28:55 +0100
committerWim <wim@42.be>2017-03-23 23:28:55 +0100
commit2f68519b3c6b5a70028882c99afeb76f291b7725 (patch)
tree2555d0b8b81491f136a176a58e2618a25edc8edc /vendor/github.com/google/gops/internal/obj/stringer.go
parentefe641f202653dfd3bc7bde221188e098db3def7 (diff)
downloadmatterbridge-msglm-2f68519b3c6b5a70028882c99afeb76f291b7725.tar.gz
matterbridge-msglm-2f68519b3c6b5a70028882c99afeb76f291b7725.tar.bz2
matterbridge-msglm-2f68519b3c6b5a70028882c99afeb76f291b7725.zip
Add gops agentv0.10.2-dev
Diffstat (limited to 'vendor/github.com/google/gops/internal/obj/stringer.go')
-rw-r--r--vendor/github.com/google/gops/internal/obj/stringer.go104
1 files changed, 104 insertions, 0 deletions
diff --git a/vendor/github.com/google/gops/internal/obj/stringer.go b/vendor/github.com/google/gops/internal/obj/stringer.go
new file mode 100644
index 00000000..2ba213e5
--- /dev/null
+++ b/vendor/github.com/google/gops/internal/obj/stringer.go
@@ -0,0 +1,104 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build ignore
+
+// This is a mini version of the stringer tool customized for the Anames table
+// in the architecture support for obj.
+// This version just generates the slice of strings, not the String method.
+
+package main
+
+import (
+ "bufio"
+ "flag"
+ "fmt"
+ "log"
+ "os"
+ "regexp"
+ "strings"
+)
+
+var (
+ input = flag.String("i", "", "input file name")
+ output = flag.String("o", "", "output file name")
+ pkg = flag.String("p", "", "package name")
+)
+
+var Are = regexp.MustCompile(`^\tA([A-Z0-9]+)`)
+
+func main() {
+ flag.Parse()
+ if *input == "" || *output == "" || *pkg == "" {
+ flag.Usage()
+ os.Exit(2)
+ }
+ in, err := os.Open(*input)
+ if err != nil {
+ log.Fatal(err)
+ }
+ fd, err := os.Create(*output)
+ if err != nil {
+ log.Fatal(err)
+ }
+ out := bufio.NewWriter(fd)
+ defer out.Flush()
+ var on = false
+ s := bufio.NewScanner(in)
+ first := true
+ for s.Scan() {
+ line := s.Text()
+ if !on {
+ // First relevant line contains "= obj.ABase".
+ // If we find it, delete the = so we don't stop immediately.
+ const prefix = "= obj.ABase"
+ index := strings.Index(line, prefix)
+ if index < 0 {
+ continue
+ }
+ // It's on. Start with the header.
+ fmt.Fprintf(out, header, *input, *output, *pkg, *pkg)
+ on = true
+ line = line[:index]
+ }
+ // Strip comments so their text won't defeat our heuristic.
+ index := strings.Index(line, "//")
+ if index > 0 {
+ line = line[:index]
+ }
+ index = strings.Index(line, "/*")
+ if index > 0 {
+ line = line[:index]
+ }
+ // Termination condition: Any line with an = changes the sequence,
+ // so stop there, and stop at a closing brace.
+ if strings.HasPrefix(line, "}") || strings.ContainsRune(line, '=') {
+ break
+ }
+ sub := Are.FindStringSubmatch(line)
+ if len(sub) < 2 {
+ continue
+ }
+ if first {
+ fmt.Fprintf(out, "\tobj.A_ARCHSPECIFIC: %q,\n", sub[1])
+ first = false
+ } else {
+ fmt.Fprintf(out, "\t%q,\n", sub[1])
+ }
+ }
+ fmt.Fprintln(out, "}")
+ if s.Err() != nil {
+ log.Fatal(err)
+ }
+}
+
+const header = `// Generated by stringer -i %s -o %s -p %s
+// Do not edit.
+
+package %s
+
+import "github.com/google/gops/internal/obj"
+
+var Anames = []string{
+`