Refactor puffs-gen-c's generate.

This commit is contained in:
Nigel Tao committed 2017-06-15 15:29:03 +10:00
1 parent 9c7b3af037
commit b79036ff32
1 file changed
+12 -2
+12 -2
View File
@@ -181,6 +181,14 @@ func (g *gen) generate() error {
return fmt.Errorf("cyclical struct definitions")
}
if err := g.genHeader(structs); err != nil {
return err
}
g.writes("// C HEADER ENDS HERE.\n\n")
return g.genImpl(structs)
}
func (g *gen) genHeader(structs []*a.Struct) error {
includeGuard := "PUFFS_" + strings.ToUpper(g.pkgName) + "_H"
g.printf("#ifndef %s\n#define %s\n\n", includeGuard, includeGuard)
@@ -232,10 +240,12 @@ func (g *gen) generate() error {
return err
}
// Finish up the header, which is also the first part of the .c file.
g.writes("\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n")
g.printf("#endif // %s\n\n", includeGuard)
g.writes("// C HEADER ENDS HERE.\n\n")
return nil
}
func (g *gen) genImpl(structs []*a.Struct) error {
g.writes(baseImpl)
g.writes("\n")