Generate an include guard.

This commit is contained in:
Nigel Tao committed 2017-05-28 11:10:57 +10:00
1 parent 1db9602294
commit 227e0373ab
3 files changed
+15

No files matched your search

+5
View File
@@ -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)
}
+5
View File
@@ -1,3 +1,6 @@
#ifndef PUFFS_GIF_H
#define PUFFS_GIF_H
// Code generated by puffs-gen-c. DO NOT EDIT.
// Use of this source code is governed by a BSD-style license that can be found
@@ -70,6 +73,8 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self);
} // extern "C"
#endif
#endif // PUFFS_GIF_H
// ---------------- Private Structs
// ---------------- Private Constructor and Destructor Prototypes
+5
View File
@@ -1,3 +1,6 @@
#ifndef PUFFS_GIF_H
#define PUFFS_GIF_H
// Code generated by puffs-gen-h. DO NOT EDIT.
// Use of this source code is governed by a BSD-style license that can be found
@@ -69,3 +72,5 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // PUFFS_GIF_H