Commits

Sean Russell committed 13dfb25

Fixed numerous compilation errors
The go APIs probably changed since the last time Michael updated the code.
I did not attempt any other "code cleanups."

  • Participants
  • Parent commits d5d6d25

Comments (0)

Files changed (1)

 
 // Date: 2009-11-12
 // Updated: 2010-08-21
+// Updated: 2011-06-23
+//    Sean E. Russell <seanerussell@gmail.com>
+//    Fixed numerous compilation errors; the go APIs probably changed since the
+//    last time Michael updated it.
 
 //
 // usage: gotags filename [ filename... ] > tags
 
 package main
 
+
 import (
 	"container/vector"
 	"fmt"
 	"go/ast"
 	"go/parser"
+	"go/token"
 	"os"
 	"sort"
 )
 	tags vector.StringVector
 )
 
-func output_tag(name *ast.Ident, kind byte) {
+func output_tag(fset *token.FileSet, name *ast.Ident, kind byte) {
+	position := fset.Position( name.NamePos )
 	tags.Push(fmt.Sprintf("%s\t%s\t%d;\"\t%c",
-		name.Name(), name.Position.Filename, name.Position.Line, kind))
+		name.Name, position.Filename, position.Line, kind))
 }
 
 func main() {
 const FUNC, TYPE, VAR = 'f', 't', 'v'
 
 func parse_files() {
-	for i, m := 1, len(os.Args); i < m; i++ {
-		tree, ok := parser.ParseFile(os.Args[i], nil, nil, 0)
+	for _,f := range os.Args[1:] {
+		fileset := token.NewFileSet()
+		fi, _ := os.Lstat( f )
+		fileset.AddFile( f, fileset.Base(), int(fi.Size) )
+		tree, ok := parser.ParseFile(fileset, f, nil, 0)
 		if ok != nil {
-			println("error parsing file", os.Args[i], ok.String())
+			println("error parsing file", f, ok.String())
 			panic(nil)
 		}
 
 		for _, node := range tree.Decls {
 			switch n := node.(type) {
 			case *ast.FuncDecl:
-				output_tag(n.Name, FUNC)
+				output_tag(fileset, n.Name, FUNC)
 			case *ast.GenDecl:
-				do_gen_decl(n)
+				do_gen_decl(fileset, n)
 			}
 		}
 	}
 
 }
 
-func do_gen_decl(node *ast.GenDecl) {
+func do_gen_decl(fset *token.FileSet, node *ast.GenDecl) {
 	for _, v := range node.Specs {
 		switch n := v.(type) {
 		case *ast.TypeSpec:
-			output_tag(n.Name, TYPE)
+			output_tag(fset, n.Name, TYPE)
 
 		case *ast.ValueSpec:
 			for _, vv := range n.Names {
-				output_tag(vv, VAR)
+				output_tag(fset, vv, VAR)
 			}
 		}
 	}