Permalink
Browse files

Some fixes + Gofmt

- Some fixes to generator.
- Gofmt some files.
  • Loading branch information...
1 parent 0f4bd7b commit ecf1559e6ae1629305596447bba2958cf927789c @chsc committed Dec 13, 2011
Showing with 46 additions and 59 deletions.
  1. +1 −1 enumreader_test.go
  2. +1 −1 funcreader_test.go
  3. +7 −19 generator.go
  4. +18 −19 group.go
  5. +18 −18 group_test.go
  6. +1 −1 tmreader_test.go
View
@@ -5,8 +5,8 @@
package main
import (
- "testing"
"strings"
+ "testing"
)
var testEnumsStr = "###########\n" +
View
@@ -5,9 +5,9 @@
package main
import (
+ "reflect"
"strings"
"testing"
- "reflect"
)
var testFuntionsStr = "###########\n" +
View
@@ -39,7 +39,7 @@ func generatePackage(packageName string, pak *Package, typeMap TypeMap) error {
return err
}
defer w.Close()
- return writePackage(w, packageName, pak, typeMap);
+ return writePackage(w, packageName, pak, typeMap)
}
func writePackage(w io.Writer, packageName string, pak *Package, typeMap TypeMap) error {
@@ -71,7 +71,7 @@ func writePackage(w io.Writer, packageName string, pak *Package, typeMap TypeMap
fmt.Fprintf(w, "#ifndef GLAPI\n")
fmt.Fprintf(w, "#define GLAPI extern\n")
fmt.Fprintf(w, "#endif\n\n")
-
+
fmt.Fprintf(w, "typedef unsigned int GLenum;\n")
fmt.Fprintf(w, "typedef unsigned char GLboolean;\n")
fmt.Fprintf(w, "typedef unsigned int GLbitfield;\n")
@@ -106,7 +106,6 @@ func writePackage(w io.Writer, packageName string, pak *Package, typeMap TypeMap
fmt.Fprintf(w, "*/\n")
fmt.Fprintf(w, "import \"C\"\n\n")
-
fmt.Fprintf(w, "// EOF")
return nil
}
@@ -115,14 +114,14 @@ func writeCFuncTypeDefs(w io.Writer, functions FunctionCategories, typeMap TypeM
for cat, fs := range functions {
fmt.Fprintf(w, "// %s\n", cat)
for _, f := range fs {
- rtype, _ = tm.Resolve(f.Return)
+ rtype, _ := typeMap.Resolve(f.Return)
fmt.Fprintf(w, "typedef %s (APIENTRYP ptrgogl%s)(", rtype, f.Name)
for p := 0; p < len(f.Parameters); p++ {
- rtype, _ = tm.Resolve(f.Parameters[p].Type)
+ ptype, _ := typeMap.Resolve(f.Parameters[p].Type)
if f.Parameters[p].InArray {
- fmt.Fprintf(w, "%s *%s", rtype, f.Parameters[p].Name)
+ fmt.Fprintf(w, "%s *%s", ptype, f.Parameters[p].Name)
} else {
- fmt.Fprintf(w, "%s %s", rtype, f.Parameters[p].Name)
+ fmt.Fprintf(w, "%s %s", ptype, f.Parameters[p].Name)
}
if p < len(f.Parameters)-1 {
fmt.Fprintf(w, ", ")
@@ -134,16 +133,6 @@ func writeCFuncTypeDefs(w io.Writer, functions FunctionCategories, typeMap TypeM
fmt.Fprintf(w, "\n")
}
-
-
-
-
-
-
-
-
-
-
func writeGoEnumDefinitions(enums EnumCategories, w io.Writer) {
fmt.Fprintf(w, "const (\n")
for name, enums := range enums {
@@ -181,7 +170,6 @@ func writeGoFunctionDefinitions(functions FunctionCategories, w io.Writer) {
}
}
-
func writeCFunctionDeclarations(functions FunctionCategories, w io.Writer) {
fmt.Fprintf(w, "// /* function declarations */\n")
for cat, fs := range functions {
@@ -210,7 +198,7 @@ func writeCFunctionDeclarations(functions FunctionCategories, w io.Writer) {
}
func writeGetProcAddrsDeclarations(functions FunctionCategories, w io.Writer) {
-
+
for cat, fs := range functions {
fmt.Fprintf(w, "// int init_%s() {\n", cat)
for _, f := range fs {
View
@@ -5,8 +5,8 @@
package main
import (
- "strings"
"fmt"
+ "strings"
)
type PackageGroupFunc func(category string) (packageNames []string)
@@ -51,28 +51,27 @@ func GroupPackagesByVendorFunc(category string, supportedVersions []Version, dep
}
packages := make([]string, 0, 8)
switch pc.CategoryType {
- case CategoryExtension:
- packages = append(packages, strings.ToLower(pc.Vendor))
- case CategoryVersion:
- for _, ver := range supportedVersions {
- if ver.Compare(pc.Version) >= 0 {
- packages = append(packages, fmt.Sprintf("gl%d%d", ver.Major, ver.Minor))
- if ver.Compare(deprecatedVersions[0]) >= 0 {
- packages = append(packages, fmt.Sprintf("gl%d%dc", ver.Major, ver.Minor))
- }
+ case CategoryExtension:
+ packages = append(packages, strings.ToLower(pc.Vendor))
+ case CategoryVersion:
+ for _, ver := range supportedVersions {
+ if ver.Compare(pc.Version) >= 0 {
+ packages = append(packages, fmt.Sprintf("gl%d%d", ver.Major, ver.Minor))
+ if ver.Compare(deprecatedVersions[0]) >= 0 {
+ packages = append(packages, fmt.Sprintf("gl%d%dc", ver.Major, ver.Minor))
}
}
- case CategoryDeprecatedVersion:
- for _, ver := range supportedVersions {
- if ver.Compare(pc.Version) >= 0 {
- if ver.Compare(deprecatedVersions[0]) < 0 {
- packages = append(packages, fmt.Sprintf("gl%d%d", ver.Major, ver.Minor))
- } else {
- packages = append(packages, fmt.Sprintf("gl%d%dc", ver.Major, ver.Minor))
- }
+ }
+ case CategoryDeprecatedVersion:
+ for _, ver := range supportedVersions {
+ if ver.Compare(pc.Version) >= 0 {
+ if ver.Compare(deprecatedVersions[0]) < 0 {
+ packages = append(packages, fmt.Sprintf("gl%d%d", ver.Major, ver.Minor))
+ } else {
+ packages = append(packages, fmt.Sprintf("gl%d%dc", ver.Major, ver.Minor))
}
}
+ }
}
return packages
}
-
View
@@ -8,7 +8,7 @@ import (
"testing"
)
-func checkEnumCats(paks Packages, t *testing.T, pak string, cats... string) {
+func checkEnumCats(paks Packages, t *testing.T, pak string, cats ...string) {
if p, ok := paks[pak]; ok {
if len(cats) != len(p.Enums) {
t.Errorf("len(cats) != len(p.Enums)")
@@ -25,7 +25,7 @@ func checkEnumCats(paks Packages, t *testing.T, pak string, cats... string) {
t.Errorf("Package not found: %v", pak)
}
-func checkFuncCats(paks Packages, t *testing.T, pak string, cats... string) {
+func checkFuncCats(paks Packages, t *testing.T, pak string, cats ...string) {
if p, ok := paks[pak]; ok {
if len(cats) != len(p.Functions) {
t.Errorf("len(cats) != len(p.Functions)")
@@ -49,13 +49,13 @@ func TestPackageGrouping(t *testing.T) {
e["VERSION_1_3"] = Enums{}
e["VERSION_1_3_DEPRECATED"] = Enums{}
- e["VERSION_2_1"] = Enums{}
+ e["VERSION_2_1"] = Enums{}
e["VERSION_2_1_DEPRECATED"] = Enums{}
- e["VERSION_2_3"] = Enums{}
+ e["VERSION_2_3"] = Enums{}
e["VERSION_2_3_DEPRECATED"] = Enums{}
- e["VERSION_3_1"] = Enums{}
+ e["VERSION_3_1"] = Enums{}
e["EXT_1"] = Enums{}
e["NV_1"] = Enums{}
@@ -64,45 +64,45 @@ func TestPackageGrouping(t *testing.T) {
f["EXT_1"] = []*Function{}
f["NV_1"] = []*Function{}
f["ATI_1"] = []*Function{}
-
- suppV := []Version{{1,3}, {2,1}, {2,3}, {3,1}}
- deprV := []Version{{3,1}}
-
- p := GroupEnumsAndFunctions(e, f,
- func (category string) (packageNames []string) {
+
+ suppV := []Version{{1, 3}, {2, 1}, {2, 3}, {3, 1}}
+ deprV := []Version{{3, 1}}
+
+ p := GroupEnumsAndFunctions(e, f,
+ func(category string) (packageNames []string) {
return GroupPackagesByVendorFunc(category, suppV, deprV)
})
-
+
for n, pa := range p {
t.Logf("%s:\n %s\n", n, pa)
}
if len(p) != 8 {
t.Errorf("Wrong number of categories.")
}
-
+
checkEnumCats(p, t, "nv", "NV_1")
checkEnumCats(p, t, "ati", "ATI_1")
checkEnumCats(p, t, "ext", "EXT_1")
checkEnumCats(p, t, "gl13", "VERSION_1_3", "VERSION_1_3_DEPRECATED")
checkEnumCats(p, t, "gl21",
- "VERSION_1_3", "VERSION_1_3_DEPRECATED",
+ "VERSION_1_3", "VERSION_1_3_DEPRECATED",
"VERSION_2_1", "VERSION_2_1_DEPRECATED")
checkEnumCats(p, t, "gl23",
- "VERSION_1_3", "VERSION_1_3_DEPRECATED",
+ "VERSION_1_3", "VERSION_1_3_DEPRECATED",
"VERSION_2_1", "VERSION_2_1_DEPRECATED",
"VERSION_2_3", "VERSION_2_3_DEPRECATED")
checkEnumCats(p, t, "gl31",
- "VERSION_1_3",
+ "VERSION_1_3",
"VERSION_2_1",
"VERSION_2_3",
"VERSION_3_1")
checkEnumCats(p, t, "gl31c",
- "VERSION_1_3", "VERSION_1_3_DEPRECATED",
+ "VERSION_1_3", "VERSION_1_3_DEPRECATED",
"VERSION_2_1", "VERSION_2_1_DEPRECATED",
"VERSION_2_3", "VERSION_2_3_DEPRECATED",
"VERSION_3_1")
-
+
checkFuncCats(p, t, "nv", "NV_1")
checkFuncCats(p, t, "ati", "ATI_1")
checkFuncCats(p, t, "ext", "EXT_1")
View
@@ -5,8 +5,8 @@
package main
import (
- "testing"
"strings"
+ "testing"
)
var testTypeMapStr = "Test1,*,*, GLType1,*,*\n" +

0 comments on commit ecf1559

Please sign in to comment.