mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 01:01:35 +01:00
Rename PUFFS to WUFFS, part 7 of N
This commit is contained in:
1 parent
eda3130628
commit
3c708dfe59
23 files changed
+1610
-1610
No files matched your search
@@ -39,7 +39,7 @@ var (
|
||||
)
|
||||
|
||||
// Prefixes are prepended to names to form a namespace and to avoid e.g.
|
||||
// "double" being a valid Puffs variable name but not a valid C one.
|
||||
// "double" being a valid Wuffs variable name but not a valid C one.
|
||||
const (
|
||||
aPrefix = "a_" // Function argument.
|
||||
bPrefix = "b_" // Derived from a function argument.
|
||||
@@ -50,17 +50,17 @@ const (
|
||||
vPrefix = "v_" // Local variable.
|
||||
)
|
||||
|
||||
// Do transpiles a Puffs program to a C program.
|
||||
// Do transpiles a Wuffs program to a C program.
|
||||
//
|
||||
// The arguments list the source Puffs files. If no arguments are given, it
|
||||
// The arguments list the source Wuffs files. If no arguments are given, it
|
||||
// reads from stdin.
|
||||
//
|
||||
// The generated program is written to stdout.
|
||||
func Do(args []string) error {
|
||||
return generate.Do(args, func(pkgName string, tm *t.Map, c *check.Checker, files []*a.File) ([]byte, error) {
|
||||
g := &gen{
|
||||
PKGPREFIX: "PUFFS_" + strings.ToUpper(pkgName) + "__",
|
||||
pkgPrefix: "puffs_" + pkgName + "__",
|
||||
PKGPREFIX: "WUFFS_" + strings.ToUpper(pkgName) + "__",
|
||||
pkgPrefix: "wuffs_" + pkgName + "__",
|
||||
pkgName: pkgName,
|
||||
tm: tm,
|
||||
checker: c,
|
||||
@@ -153,8 +153,8 @@ func (b *buffer) writes(s string) { *b = append(*b, s.
|
||||
func (b *buffer) writex(s []byte) { *b = append(*b, s...) }
|
||||
|
||||
type gen struct {
|
||||
PKGPREFIX string // e.g. "PUFFS_JPEG__"
|
||||
pkgPrefix string // e.g. "puffs_jpeg__"
|
||||
PKGPREFIX string // e.g. "WUFFS_JPEG__"
|
||||
pkgPrefix string // e.g. "wuffs_jpeg__"
|
||||
pkgName string // e.g. "jpeg"
|
||||
|
||||
tm *t.Map
|
||||
@@ -211,7 +211,7 @@ func (g *gen) generate() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (g *gen) genHeader(b *buffer) error {
|
||||
includeGuard := "PUFFS_" + strings.ToUpper(g.pkgName) + "_H"
|
||||
includeGuard := "WUFFS_" + strings.ToUpper(g.pkgName) + "_H"
|
||||
b.printf("#ifndef %s\n#define %s\n\n", includeGuard, includeGuard)
|
||||
|
||||
b.printf("// Code generated by wuffs-c. DO NOT EDIT.\n\n")
|
||||
@@ -492,7 +492,7 @@ func (g *gen) writeConstList(b *buffer, n *a.Expr) error {
|
||||
func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
||||
// For API/ABI compatibility, the very first field in the struct's
|
||||
// private_impl must be the status code. This lets the initializer callee
|
||||
// set "self->private_impl.status = PUFFS_ETC__ERROR_BAD_PUFFS_VERSION;"
|
||||
// set "self->private_impl.status = WUFFS_ETC__ERROR_BAD_WUFFS_VERSION;"
|
||||
// regardless of the sizeof(*self) struct reserved by the caller and even
|
||||
// if the caller and callee were built with different versions.
|
||||
structName := n.Name().String(g.tm)
|
||||
@@ -563,10 +563,10 @@ func (g *gen) writeInitializerSignature(b *buffer, n *a.Struct, public bool) err
|
||||
b.printf("// It should be called before any other %s%s__* function.\n",
|
||||
g.pkgPrefix, structName)
|
||||
b.printf("//\n")
|
||||
b.printf("// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.\n")
|
||||
b.printf("// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.\n")
|
||||
}
|
||||
b.printf("void %s%s__initialize(%s%s *self", g.pkgPrefix, structName, g.pkgPrefix, structName)
|
||||
b.printf(", uint32_t puffs_version, uint32_t for_internal_use_only")
|
||||
b.printf(", uint32_t wuffs_version, uint32_t for_internal_use_only")
|
||||
b.printf(")")
|
||||
return nil
|
||||
}
|
||||
@@ -592,14 +592,14 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
||||
b.printf("{\n")
|
||||
b.printf("if (!self) { return; }\n")
|
||||
|
||||
b.printf("if (puffs_version != PUFFS_VERSION) {\n")
|
||||
b.printf("self->private_impl.status = %sERROR_BAD_PUFFS_VERSION;\n", g.PKGPREFIX)
|
||||
b.printf("if (wuffs_version != WUFFS_VERSION) {\n")
|
||||
b.printf("self->private_impl.status = %sERROR_BAD_WUFFS_VERSION;\n", g.PKGPREFIX)
|
||||
b.printf("return;\n")
|
||||
b.printf("}\n")
|
||||
|
||||
b.writes("if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {" +
|
||||
b.writes("if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {" +
|
||||
"memset(self, 0, sizeof(*self)); }\n")
|
||||
b.writes("self->private_impl.magic = PUFFS_BASE__MAGIC;\n")
|
||||
b.writes("self->private_impl.magic = WUFFS_BASE__MAGIC;\n")
|
||||
|
||||
for _, f := range n.Fields() {
|
||||
f := f.Field()
|
||||
@@ -621,7 +621,7 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
||||
continue
|
||||
}
|
||||
b.printf("%s%s__initialize(&self->private_impl.%s%s,"+
|
||||
"PUFFS_VERSION, PUFFS_BASE__ALREADY_ZEROED);\n",
|
||||
"WUFFS_VERSION, WUFFS_BASE__ALREADY_ZEROED);\n",
|
||||
g.pkgPrefix, x.Name().String(g.tm), fPrefix, f.Name().String(g.tm))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user