summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-05-25 01:28:59 -0400
committerPietro Gagliardi <[email protected]>2014-05-25 01:28:59 -0400
commit3929dea8186c4a69d59aa04330430f1c4c597a64 (patch)
treeb834a93ad26373424145d01d2bfc3cf6f0077ac1
parent8de17f0adef1d91b2e035e87a21f335903c16a0e (diff)
Even more work on the Windows constant generator. There are still some edge cases involving variables that I need to resolve, and I still need to write the code that actually runs the generated program.
-rw-r--r--experiments/windowsconstgen.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/experiments/windowsconstgen.go b/experiments/windowsconstgen.go
index a1411aa..213747d 100644
--- a/experiments/windowsconstgen.go
+++ b/experiments/windowsconstgen.go
@@ -8,6 +8,7 @@ import (
"go/token"
"go/ast"
"go/parser"
+ "sort"
)
func getPackage(path string) (pkg *ast.Package) {
@@ -68,6 +69,11 @@ func gatherNames(pkg *ast.Package) {
}
}
+func preamble(pkg string) string {
+ return "// autogenerated by windowsconstgen; do not edit\n" +
+ "package " + pkg + "\n"
+}
+
func main() {
if len(os.Args) != 2 {
panic("usage: " + os.Args[0] + " path")
@@ -84,7 +90,25 @@ func main() {
panic(s)
}
+ // keep sorted for git
+ consts := make([]string, 0, len(known))
+
for ident, kind := range known {
- fmt.Printf("%-30s %s\n", ident, kind)
+ if kind == "const" || kind == "var" {
+ consts = append(consts, ident)
+ }
+ }
+ sort.Strings(consts)
+
+ fmt.Printf("%s" +
+ "import \"fmt\"\n" +
+ "// #include <windows.h>\n" +
+ "import \"C\"\n" +
+ "func main() {\n" +
+ " fmt.Println(%q)\n",
+ preamble("main"), preamble("ui"))
+ for _, ident := range consts {
+ fmt.Printf(" fmt.Println(\"const %s =\", C.%s)\n", ident, ident[1:])
}
+ fmt.Printf("}\n")
}