summaryrefslogtreecommitdiff
path: root/experiments
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-05-25 00:40:22 -0400
committerPietro Gagliardi <[email protected]>2014-05-25 00:40:45 -0400
commit4408c1bf42e6b7cb46783eac464add017cfd12a6 (patch)
tree54702a095e3a6bfd1cc97f738c440423ba990e58 /experiments
parent4632d8057696025577a165b797932b828caade32 (diff)
More work on the constant generation tool. We can almost actually write the generator portion now...
Diffstat (limited to 'experiments')
-rw-r--r--experiments/windowsconstgen.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/experiments/windowsconstgen.go b/experiments/windowsconstgen.go
index ed9561e..e09bee7 100644
--- a/experiments/windowsconstgen.go
+++ b/experiments/windowsconstgen.go
@@ -2,7 +2,7 @@
package main
import (
- "fmt"
+// "fmt"
"os"
"strings"
"go/token"
@@ -33,20 +33,35 @@ func main() {
}
do(pkg)
+ if len(unknown) > 0 {
+ s := "error: the following are still unknown!"
+ for k, _ := range unknown {
+ s += "\n" + k
+ }
+ panic(s)
+ }
}
type walker struct {
desired func(string) bool
}
+var known = map[string]string{}
+var unknown = map[string]struct{}{}
+
func (w *walker) Visit(node ast.Node) ast.Visitor {
if n, ok := node.(*ast.Ident); ok {
if w.desired(n.Name) {
- known := "<unknown>"
if n.Obj != nil {
- known = n.Obj.Kind.String()
+ delete(unknown, n.Name)
+ kind := n.Obj.Kind.String()
+ if known[n.Name] != "" && known[n.Name] != kind {
+ panic(n.Name + "(" + kind + ") already known to be a " + known[n.Name])
+ }
+ known[n.Name] = kind
+ } else if _, ok := known[n.Name]; !ok { // only if not known
+ unknown[n.Name] = struct{}{}
}
- fmt.Println(n.Name + "\t\t" + known)
}
}
return w