Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove buildit import from gotmake.

Tested-on: morland i686 GNU/Linux
  • Loading branch information...
commit 6613ec9c97c03ea114d38e08a0349db5ac8a4b29 1 parent 8ad0019
@droundy droundy authored
Showing with 54 additions and 57 deletions.
  1. +1 −1  Makefile
  2. +1 −1  Makefile.dev
  3. +0 −53 src/got/buildit.go
  4. +52 −2 src/gotmake.go
View
2  Makefile
@@ -85,7 +85,7 @@ bin/gotmake: src/gotmake.$(O)
$(LD) -o $@ $<
$(bindir)/gotmake: bin/gotmake
cp $< $@
-src/gotmake.$(O): src/gotmake.go src/got/buildit.$(O) src/gotgo/slice(string).$(O)
+src/gotmake.$(O): src/gotmake.go src/gotgo/slice(string).$(O)
tests/demo/list(int).$(O): tests/demo/list(int).go
View
2  Makefile.dev
@@ -92,7 +92,7 @@ bin/gotmake: src/gotmake.$(O)
$(LD) -o $@ $<
$(bindir)/gotmake: bin/gotmake
cp $< $@
-src/gotmake.$(O): src/gotmake.go src/got/buildit.$(O) src/gotgo/slice(string).$(O)
+src/gotmake.$(O): src/gotmake.go src/gotgo/slice(string).$(O)
tests/demo/list(int).$(O): tests/demo/list(int).go
View
53 src/got/buildit.go
@@ -11,13 +11,8 @@ import (
"fmt"
"exec"
"path"
- "strings"
- "bytes"
"go/scanner"
"go/token"
- "go/ast"
- "go/parser"
- "go/printer"
stringslice "../gotgo/slice(string)"
)
@@ -150,51 +145,3 @@ func TypeList(s *scanner.Scanner) (types []string, error os.Error) {
}
return
}
-
-type getimps struct {
- imps *[]string
-}
-func (g getimps) Visit(x interface{}) ast.Visitor {
- switch v := x.(type) {
- case *ast.SelectorExpr:
- *g.imps = stringslice.Append(*g.imps, pretty(v.X))
- }
- if x != nil {
- return g
- }
- return nil
-}
-
-// This parses an import statement, such as "./foo/bar(int,baz.T(foo.T))",
-// returning a list of types and a list of imports that are needed
-// (e.g. baz and foo in the above example).
-func ParseImport(s string) (types, imports []string) {
- // First, I want to cut off any preliminary directories, so the
- // import should look like a function call.
- n := strings.Index(s, "(")
- if n < 1 { return }
- start := 0
- for i := n-1; i>=0; i-- {
- if s[i] == '/' {
- start = i+1
- break
- }
- }
- s = s[start:]
- // Now we just need to parse the apparent function call...
- x, _ := parser.ParseExpr(s, s, nil)
- is := []string{}
- callexpr, ok := x.(*ast.CallExpr)
- if !ok { return } // FIXME: need error handling?
- for _, texpr := range callexpr.Args {
- types = stringslice.Append(types, pretty(texpr))
- ast.Walk(getimps{&is}, texpr)
- }
- return types, is
-}
-
-func pretty(expr interface{}) string {
- b := bytes.NewBufferString("")
- printer.Fprint(b, expr)
- return b.String()
-}
View
54 src/gotmake.go
@@ -17,8 +17,9 @@ import (
"path"
"sort"
"flag"
+ "bytes"
+ "go/printer"
stringslice "./gotgo/slice(string)"
- "./got/buildit"
)
var ignoreInstalled = flag.Bool("ignore-installed", true,
@@ -172,7 +173,7 @@ func createGofile(sourcePath, importPath string, names map[string]string) {
// ignore non-templated import...
default:
// Begin by scanning the type parameters in the import
- types, imps := buildit.ParseImport(sourcePath)
+ types, imps := ParseImport(sourcePath)
//fmt.Printf("# I see types %v and imports %v\n", types, imps)
basename := sourcePath[0:n]
gotname := basename + ".got"
@@ -354,3 +355,52 @@ func dirs(s string) (out []string) {
}
return out
}
+
+// This is a convenience type for finding the imports of a file.
+type getimps struct {
+ imps *[]string
+}
+func (g getimps) Visit(x interface{}) ast.Visitor {
+ switch v := x.(type) {
+ case *ast.SelectorExpr:
+ *g.imps = stringslice.Append(*g.imps, pretty(v.X))
+ }
+ if x != nil {
+ return g
+ }
+ return nil
+}
+
+// This parses an import statement, such as "./foo/bar(int,baz.T(foo.T))",
+// returning a list of types and a list of imports that are needed
+// (e.g. baz and foo in the above example).
+func ParseImport(s string) (types, imports []string) {
+ // First, I want to cut off any preliminary directories, so the
+ // import should look like a function call.
+ n := strings.Index(s, "(")
+ if n < 1 { return }
+ start := 0
+ for i := n-1; i>=0; i-- {
+ if s[i] == '/' {
+ start = i+1
+ break
+ }
+ }
+ s = s[start:]
+ // Now we just need to parse the apparent function call...
+ x, _ := parser.ParseExpr(s, s, nil)
+ is := []string{}
+ callexpr, ok := x.(*ast.CallExpr)
+ if !ok { return } // FIXME: need error handling?
+ for _, texpr := range callexpr.Args {
+ types = stringslice.Append(types, pretty(texpr))
+ ast.Walk(getimps{&is}, texpr)
+ }
+ return types, is
+}
+
+func pretty(expr interface{}) string {
+ b := bytes.NewBufferString("")
+ printer.Fprint(b, expr)
+ return b.String()
+}
Please sign in to comment.
Something went wrong with that request. Please try again.