mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
Generate an include guard.
This commit is contained in:
1 parent
1db9602294
commit
227e0373ab
3 files changed
+15
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
a "github.com/google/puffs/lang/ast"
|
||||
t "github.com/google/puffs/lang/token"
|
||||
@@ -31,6 +32,9 @@ type Generator struct {
|
||||
func (g *Generator) Generate(pkgName string, m *t.IDMap, files []*a.File) ([]byte, error) {
|
||||
b := &bytes.Buffer{}
|
||||
|
||||
includeGuard := "PUFFS_" + strings.ToUpper(pkgName) + "_H"
|
||||
fmt.Fprintf(b, "#ifndef %s\n#define %s\n\n", includeGuard, includeGuard)
|
||||
|
||||
// Write preamble.
|
||||
fmt.Fprintf(b, "// Code generated by puffs-gen-%c. DO NOT EDIT.\n\n", g.Extension)
|
||||
b.WriteString(preamble)
|
||||
@@ -66,6 +70,7 @@ func (g *Generator) Generate(pkgName string, m *t.IDMap, files []*a.File) ([]byt
|
||||
|
||||
// Finish up the header, which is also the first part of the .c file.
|
||||
b.WriteString("\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n")
|
||||
fmt.Fprintf(b, "#endif // %s\n\n", includeGuard)
|
||||
if g.Extension == 'h' {
|
||||
return format(b)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user