forked from skelterjohn/gorf
/
dscan.go
52 lines (41 loc) · 1.05 KB
/
dscan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2011 John Asmuth. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"os"
"go/ast"
"fmt"
"rog-go.googlecode.com/hg/exp/go/types"
)
func ScanCmd(args []string) (err os.Error) {
ScanAllForImports(LocalRoot)
for _, path := range args {
pkg := LocalImporter(path)
ast.Walk(DepthWalker(0), pkg)
}
return
}
type DepthWalker int
func (this DepthWalker) Visit(node ast.Node) ast.Visitor {
if node == nil {
return this+1
}
buffer := ""
for i:=0;i<int(this); i++ {
buffer += " "
}
fmt.Printf("%sPos: %d %s\n", buffer, node.Pos(), AllSources.Position(node.Pos()))
fmt.Printf("%sEnd: %d %s\n", buffer, node.End(), AllSources.Position(node.End()))
fmt.Printf("%s%T\n", buffer, node)
fmt.Printf("%s%v\n", buffer, node)
if e, ok := node.(ast.Expr); ok {
obj, typ := types.ExprType(e, LocalImporter)
fmt.Printf("%s%v\n", buffer, obj)
fmt.Printf("%s%v\n", buffer, typ)
}
fmt.Println()
switch n := node.(type) {
}
return this+1
}