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.
This commit is contained in:
parent
8de17f0ade
commit
3929dea818
|
@ -8,6 +8,7 @@ import (
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getPackage(path string) (pkg *ast.Package) {
|
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() {
|
func main() {
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) != 2 {
|
||||||
panic("usage: " + os.Args[0] + " path")
|
panic("usage: " + os.Args[0] + " path")
|
||||||
|
@ -84,7 +90,25 @@ func main() {
|
||||||
panic(s)
|
panic(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keep sorted for git
|
||||||
|
consts := make([]string, 0, len(known))
|
||||||
|
|
||||||
for ident, kind := range 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")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue