mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 16:47:28 +01:00
Delete obsolete wuffs_foo__status__string funcs
This commit is contained in:
1 parent
b840c80040
commit
c499f03bc7
6 files changed
+13
-748
No files matched your search
@@ -22,13 +22,7 @@
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE)
|
||||
|
||||
// !! INSERT wuffs_base__status__string data.
|
||||
|
||||
const char* //
|
||||
wuffs_base__status__string(int32_t status_code) {
|
||||
uint16_t o = wuffs_base__status__string_offsets[(uint8_t)(status_code >> 24)];
|
||||
return o ? wuffs_base__status__string_data + o : "unknown status";
|
||||
}
|
||||
// !! INSERT wuffs_base__status strings.
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) ||
|
||||
// defined(WUFFS_CONFIG__MODULE__BASE)
|
||||
|
||||
@@ -124,9 +124,6 @@ wuffs_base__status__is_suspension(wuffs_base__status z) {
|
||||
return z && (*z == '$');
|
||||
}
|
||||
|
||||
const char* //
|
||||
wuffs_base__status__string(int32_t status_code);
|
||||
|
||||
// --------
|
||||
|
||||
// Flicks are a unit of time. One flick (frame-tick) is 1 / 705_600_000 of a
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"math/big"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -33,7 +32,6 @@ import (
|
||||
"github.com/google/wuffs/lang/builtin"
|
||||
"github.com/google/wuffs/lang/check"
|
||||
"github.com/google/wuffs/lang/generate"
|
||||
"github.com/google/wuffs/lib/base38"
|
||||
|
||||
cf "github.com/google/wuffs/cmd/commonflags"
|
||||
|
||||
@@ -113,18 +111,7 @@ func Do(args []string) error {
|
||||
if err := expandBangBangInsert(&buf, baseBaseImplC, map[string]func(*buffer) error{
|
||||
"// !! INSERT base-private.h.\n": insertBasePrivateH,
|
||||
"// !! INSERT base-public.h.\n": insertBasePublicH,
|
||||
"// !! INSERT wuffs_base__status__string data.\n": func(b *buffer) error {
|
||||
messages := [256]string{}
|
||||
for _, z := range builtin.StatusList {
|
||||
if z.Message == "" {
|
||||
continue
|
||||
}
|
||||
messages[uint8(z.Value)] = z.Message[:1] + "base: " + z.Message[1:]
|
||||
}
|
||||
if err := genStatusStringData(b, "wuffs_base__", &messages); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
"// !! INSERT wuffs_base__status strings.\n": func(b *buffer) error {
|
||||
for _, z := range builtin.StatusList {
|
||||
pre := ""
|
||||
switch z.Keyword {
|
||||
@@ -135,8 +122,8 @@ func Do(args []string) error {
|
||||
default:
|
||||
continue
|
||||
}
|
||||
b.printf("const char* wuffs_base__%s__%s = \"%s\";\n",
|
||||
pre, cName(z.Message, ""), messages[uint8(z.Value)])
|
||||
b.printf("const char* wuffs_base__%s__%s = \"%sbase: %s\";\n",
|
||||
pre, cName(z.Message, ""), z.Message[:1], z.Message[1:])
|
||||
}
|
||||
return nil
|
||||
},
|
||||
@@ -267,12 +254,6 @@ func insertBasePublicH(buf *buffer) error {
|
||||
|
||||
if err := expandBangBangInsert(buf, baseBasePublicH, map[string]func(*buffer) error{
|
||||
"// !! INSERT wuffs_base__status names.\n": func(b *buffer) error {
|
||||
for _, z := range builtin.StatusList {
|
||||
code := int32(z.Value) << 24
|
||||
b.printf("#define %s %d // 0x%08X\n",
|
||||
strings.ToUpper(cName(z.String(), "WUFFS_BASE__")), code, uint32(code))
|
||||
}
|
||||
b.writes("\n")
|
||||
for _, z := range builtin.StatusList {
|
||||
pre := ""
|
||||
switch z.Keyword {
|
||||
@@ -298,36 +279,6 @@ func insertBasePublicH(buf *buffer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func genStatusStringData(b *buffer, pkgPrefix string, ss *[256]string) error {
|
||||
data := []byte{0x00}
|
||||
offsets := [256]uint16{}
|
||||
for i, s := range ss {
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
if len(data) > 0xFFFF {
|
||||
return errors.New("status string messages are too long")
|
||||
}
|
||||
offsets[i] = uint16(len(data))
|
||||
data = append(data, s...)
|
||||
data = append(data, 0x00)
|
||||
}
|
||||
|
||||
b.printf("static const char %sstatus__string_data[] = {\n", pkgPrefix)
|
||||
for _, x := range data {
|
||||
b.printf("0x%02X,", x)
|
||||
}
|
||||
b.writes("};\n\n")
|
||||
|
||||
b.printf("static const uint16_t %sstatus__string_offsets[] = {\n", pkgPrefix)
|
||||
for _, x := range offsets {
|
||||
b.printf("0x%04X,", x)
|
||||
}
|
||||
b.writes("};\n\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type gen struct {
|
||||
pkgPrefix string // e.g. "wuffs_jpeg__"
|
||||
pkgName string // e.g. "jpeg"
|
||||
@@ -410,15 +361,6 @@ func (g *gen) genHeader(b *buffer) error {
|
||||
|
||||
b.writes("// ---------------- Status Codes\n\n")
|
||||
|
||||
pkgID := g.checker.PackageID()
|
||||
b.printf("#define %spackageid %d // 0x%08X\n\n", g.pkgPrefix, pkgID, pkgID)
|
||||
|
||||
for _, s := range g.statusList {
|
||||
code := (int32(s.value) << 24) | int32(pkgID)
|
||||
b.printf("#define %s %d // 0x%08X\n", s.name, code, uint32(code))
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
for _, s := range g.statusList {
|
||||
if !s.public {
|
||||
continue
|
||||
@@ -427,8 +369,6 @@ func (g *gen) genHeader(b *buffer) error {
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
b.printf("const char* %sstatus__string(int32_t status_code);\n\n", g.pkgPrefix)
|
||||
|
||||
b.writes("// ---------------- Public Consts\n\n")
|
||||
if err := g.forEachConst(b, pubOnly, (*gen).writeConst); err != nil {
|
||||
return err
|
||||
@@ -474,43 +414,15 @@ func (g *gen) genImpl(b *buffer) error {
|
||||
|
||||
b.writes("// ---------------- Status Codes Implementations\n\n")
|
||||
|
||||
messages := [256]string{}
|
||||
{
|
||||
for _, s := range g.statusList {
|
||||
if s.msg == "" {
|
||||
continue
|
||||
}
|
||||
messages[uint8(s.value)] = s.msg[:1] + g.pkgName + ": " + s.msg[1:]
|
||||
for _, z := range g.statusList {
|
||||
if z.msg == "" {
|
||||
continue
|
||||
}
|
||||
if err := genStatusStringData(b, g.pkgPrefix, &messages); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range g.statusList {
|
||||
b.printf("const char* %s%s__%s = \"%s\";\n",
|
||||
g.pkgPrefix, s.cNamePrefix(), s.cName, messages[uint8(s.value)])
|
||||
b.printf("const char* %s%s__%s = \"%s%s: %s\";\n",
|
||||
g.pkgPrefix, z.cNamePrefix(), z.cName, z.msg[:1], g.pkgName, z.msg[1:])
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
b.printf("const char* %sstatus__string(int32_t status_code) {\n", g.pkgPrefix)
|
||||
b.printf("uint16_t o;")
|
||||
b.printf("switch (status_code & 0x%X) {\n", (1<<base38.MaxBits)-1)
|
||||
b.printf("case 0: return wuffs_base__status__string(status_code);\n")
|
||||
b.printf("case %spackageid:\n", g.pkgPrefix)
|
||||
b.printf("o = %sstatus__string_offsets[(uint8_t)(status_code >> 24)];\n", g.pkgPrefix)
|
||||
b.printf("if (o) { return %sstatus__string_data + o; } break;\n", g.pkgPrefix)
|
||||
for _, u := range g.usesList {
|
||||
// TODO: is path.Base always correct? Should we check
|
||||
// validName(packageName)?
|
||||
useePkgName := path.Base(u)
|
||||
b.printf("case wuffs_%s__packageid: return wuffs_%s__status__string(status_code);\n", useePkgName, useePkgName)
|
||||
}
|
||||
b.printf("}\n")
|
||||
b.printf("return \"unknown status\";\n")
|
||||
|
||||
b.writes("}\n\n")
|
||||
|
||||
b.writes("// ---------------- Private Consts\n\n")
|
||||
if err := g.forEachConst(b, priOnly, (*gen).writeConst); err != nil {
|
||||
return err
|
||||
|
||||
@@ -22,7 +22,7 @@ const baseBasePublicH = "" +
|
||||
"nt.com/nothings/stb/master/docs/stb_howto.txt\n#ifdef WUFFS_CONFIG__STATIC_FUNCTIONS\n#define WUFFS_BASE__MAYBE_STATIC static\n#else\n#define WUFFS_BASE__MAYBE_STATIC\n#endif\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n#else\n#define WUFFS_BASE__WARN_UNUSED_RESULT\n#endif\n\n// wuffs_base__empty_struct is used when a Wuffs function returns an empty\n// struct. In C, if a function f returns void, you can't say \"x = f()\", but in\n// Wuffs, if a function g returns empty, you can say \"y = g()\".\ntypedef struct {\n // private_impl is a placeholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n " +
|
||||
"//\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__empty_struct;\n\n// wuffs_base__utility is a placeholder receiver type. It enables what Java\n// calls static methods, as opposed to regular methods.\ntypedef struct {\n // private_impl is a placeholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n //\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__utility;\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// A status is either NULL (meaning OK or no error) or string message. That\n// message is human-readable, for programmers, but it is not for end users. It\n// is not localized, and does not contain additional contextual information\n// such as a source filename.\n//\n// Status strings are statically allocated and should never be free'd.\ntypedef const char* wuffs_base__status;\n\n// !! INSERT wuffs_base__status names.\n\nstatic inline bool //\nwuffs_base__status__is_error(wuffs_base__status z) {\n return z && (*z != '$');\n}\n\nstatic inline bool //\nwuffs_base__status__is_ok(wuffs_base__status z) {\n return z == NULL;\n}\n\nstatic inline bool //\nwuffs_base__status__is_suspension(wuffs_base__status z) {\n return z && (*z == '$');\n}\n\nconst char* //\nwuffs_base__status__string(int32_t status_code);\n\n" +
|
||||
"// --------\n\n// A status is either NULL (meaning OK or no error) or string message. That\n// message is human-readable, for programmers, but it is not for end users. It\n// is not localized, and does not contain additional contextual information\n// such as a source filename.\n//\n// Status strings are statically allocated and should never be free'd.\ntypedef const char* wuffs_base__status;\n\n// !! INSERT wuffs_base__status names.\n\nstatic inline bool //\nwuffs_base__status__is_error(wuffs_base__status z) {\n return z && (*z != '$');\n}\n\nstatic inline bool //\nwuffs_base__status__is_ok(wuffs_base__status z) {\n return z == NULL;\n}\n\nstatic inline bool //\nwuffs_base__status__is_suspension(wuffs_base__status z) {\n return z && (*z == '$');\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// Flicks are a unit of time. One flick (frame-tick) is 1 / 705_600_000 of a\n// second. See https://github.com/OculusVR/Flicks\ntypedef int64_t wuffs_base__flicks;\n\n#define WUFFS_BASE__FLICKS_PER_SECOND ((uint64_t)705600000)\n#define WUFFS_BASE__FLICKS_PER_MILLISECOND ((uint64_t)705600)\n\n" +
|
||||
"" +
|
||||
@@ -108,8 +108,7 @@ const baseBasePrivateH = "" +
|
||||
""
|
||||
|
||||
const baseBaseImplC = "" +
|
||||
"// Copyright 2018 The Wuffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// !! INSERT base-public.h.\n\n#ifdef WUFFS_IMPLEMENTATION\n\n// !! INSERT base-private.h.\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE)\n\n// !! INSERT wuffs_base__status__string data.\n\nconst char* //\nwuffs_base__status__string(int32_t status_code) {\n uint16_t o = wuffs_base__status__string_offsets[(uint8_t)(status_code >> 24)];\n return o ? wuffs_base__status__string_data + o : \"unknown status\";\n}" +
|
||||
"\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__BASE)\n\n#endif // WUFFS_IMPLEMENTATION\n" +
|
||||
"// Copyright 2018 The Wuffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// !! INSERT base-public.h.\n\n#ifdef WUFFS_IMPLEMENTATION\n\n// !! INSERT base-private.h.\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE)\n\n// !! INSERT wuffs_base__status strings.\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__BASE)\n\n#endif // WUFFS_IMPLEMENTATION\n" +
|
||||
""
|
||||
|
||||
const baseImagePublicH = "" +
|
||||
|
||||
Reference in new issue
Block a user