mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
Change "$foo" to base."$foo"
This commit is contained in:
1 parent
875362ea07
commit
9e5aec5d25
11 files changed
+71
-59
No files matched your search
@@ -114,7 +114,7 @@ func Do(args []string) error {
|
|||||||
"// !! INSERT base-private.h.\n": insertBasePrivateH,
|
"// !! INSERT base-private.h.\n": insertBasePrivateH,
|
||||||
"// !! INSERT base-public.h.\n": insertBasePublicH,
|
"// !! INSERT base-public.h.\n": insertBasePublicH,
|
||||||
"// !! INSERT wuffs_base__status strings.\n": func(b *buffer) error {
|
"// !! INSERT wuffs_base__status strings.\n": func(b *buffer) error {
|
||||||
for _, z := range builtin.StatusList {
|
for _, z := range builtin.Statuses {
|
||||||
if z == "" {
|
if z == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -183,9 +183,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type status struct {
|
type status struct {
|
||||||
cName string
|
cName string
|
||||||
msg string
|
msg string
|
||||||
public bool
|
fromThisPkg bool
|
||||||
|
public bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func statusMsgIsError(msg string) bool {
|
func statusMsgIsError(msg string) bool {
|
||||||
@@ -254,7 +255,7 @@ func insertBasePrivateH(buf *buffer) error {
|
|||||||
func insertBasePublicH(buf *buffer) error {
|
func insertBasePublicH(buf *buffer) error {
|
||||||
if err := expandBangBangInsert(buf, baseBasePublicH, map[string]func(*buffer) error{
|
if err := expandBangBangInsert(buf, baseBasePublicH, map[string]func(*buffer) error{
|
||||||
"// !! INSERT wuffs_base__status names.\n": func(b *buffer) error {
|
"// !! INSERT wuffs_base__status names.\n": func(b *buffer) error {
|
||||||
for _, z := range builtin.StatusList {
|
for _, z := range builtin.Statuses {
|
||||||
pre := "warning"
|
pre := "warning"
|
||||||
if statusMsgIsError(z) {
|
if statusMsgIsError(z) {
|
||||||
pre = "error"
|
pre = "error"
|
||||||
@@ -299,6 +300,15 @@ func (g *gen) generate() ([]byte, error) {
|
|||||||
if err := g.forEachStatus(b, bothPubPri, (*gen).gatherStatuses); err != nil {
|
if err := g.forEachStatus(b, bothPubPri, (*gen).gatherStatuses); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
for _, z := range builtin.Statuses {
|
||||||
|
id, err := g.tm.Insert(`"` + z + `"`)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := g.addStatus(t.QID{t.IDBase, id}, z, true); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Make a topologically sorted list of structs.
|
// Make a topologically sorted list of structs.
|
||||||
unsortedStructs := []*a.Struct(nil)
|
unsortedStructs := []*a.Struct(nil)
|
||||||
@@ -392,7 +402,7 @@ func (g *gen) genHeader(b *buffer) error {
|
|||||||
b.writes("// ---------------- Status Codes\n\n")
|
b.writes("// ---------------- Status Codes\n\n")
|
||||||
|
|
||||||
for _, z := range g.statusList {
|
for _, z := range g.statusList {
|
||||||
if !z.public {
|
if !z.fromThisPkg || !z.public {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
b.printf("extern const char* %s;\n", z.cName)
|
b.printf("extern const char* %s;\n", z.cName)
|
||||||
@@ -449,7 +459,7 @@ func (g *gen) genImpl(b *buffer) error {
|
|||||||
b.writes("// ---------------- Status Codes Implementations\n\n")
|
b.writes("// ---------------- Status Codes Implementations\n\n")
|
||||||
|
|
||||||
for _, z := range g.statusList {
|
for _, z := range g.statusList {
|
||||||
if z.msg == "" {
|
if !z.fromThisPkg || z.msg == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
b.printf("const char* %s = \"%s%s: %s\";\n", z.cName, z.msg[:1], g.pkgName, z.msg[1:])
|
b.printf("const char* %s = \"%s%s: %s\";\n", z.cName, z.msg[:1], g.pkgName, z.msg[1:])
|
||||||
@@ -595,17 +605,24 @@ func (g *gen) gatherStatuses(b *buffer, n *a.Status) error {
|
|||||||
if !ok || msg == "" {
|
if !ok || msg == "" {
|
||||||
return fmt.Errorf("bad status message %q", raw)
|
return fmt.Errorf("bad status message %q", raw)
|
||||||
}
|
}
|
||||||
errSus := "error__"
|
return g.addStatus(n.QID(), msg, n.Public())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *gen) addStatus(qid t.QID, msg string, public bool) error {
|
||||||
|
category := "warning__"
|
||||||
if msg[0] == '$' {
|
if msg[0] == '$' {
|
||||||
errSus = "suspension__"
|
category = "suspension__"
|
||||||
|
} else if msg[0] == '?' {
|
||||||
|
category = "error__"
|
||||||
}
|
}
|
||||||
z := status{
|
z := status{
|
||||||
cName: g.pkgPrefix + errSus + cName(msg, ""),
|
cName: g.packagePrefix(qid) + category + cName(msg, ""),
|
||||||
msg: msg,
|
msg: msg,
|
||||||
public: n.Public(),
|
fromThisPkg: qid[0] == 0,
|
||||||
|
public: public,
|
||||||
}
|
}
|
||||||
g.statusList = append(g.statusList, z)
|
g.statusList = append(g.statusList, z)
|
||||||
g.statusMap[n.QID()] = z
|
g.statusMap[qid] = z
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ package cgen
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/wuffs/lang/builtin"
|
|
||||||
|
|
||||||
a "github.com/google/wuffs/lang/ast"
|
a "github.com/google/wuffs/lang/ast"
|
||||||
t "github.com/google/wuffs/lang/token"
|
t "github.com/google/wuffs/lang/token"
|
||||||
)
|
)
|
||||||
@@ -79,19 +77,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
|
|||||||
if z := g.statusMap[n.StatusQID()]; z.cName != "" {
|
if z := g.statusMap[n.StatusQID()]; z.cName != "" {
|
||||||
b.writes(z.cName)
|
b.writes(z.cName)
|
||||||
} else {
|
} else {
|
||||||
msg, _ := t.Unescape(n.Ident().Str(g.tm))
|
return fmt.Errorf("unrecognized status %s", n.StatusQID().Str(g.tm))
|
||||||
if !builtin.StatusMap[msg] {
|
|
||||||
return fmt.Errorf("no status code for %q", msg)
|
|
||||||
}
|
|
||||||
b.writes("wuffs_base__")
|
|
||||||
if statusMsgIsError(msg) {
|
|
||||||
b.writes("error__")
|
|
||||||
} else if statusMsgIsSuspension(msg) {
|
|
||||||
b.writes("suspension__")
|
|
||||||
} else {
|
|
||||||
b.writes("warning__")
|
|
||||||
}
|
|
||||||
b.writes(cName(msg, ""))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@
|
|||||||
- Marked some internal status codes as private.
|
- Marked some internal status codes as private.
|
||||||
- Removed closed-for-read/write built-in status codes.
|
- Removed closed-for-read/write built-in status codes.
|
||||||
- Changed the string messages for built-in status codes.
|
- Changed the string messages for built-in status codes.
|
||||||
- Changed `error "foo"` to `"?foo"`.
|
- Changed `error "foo"` to `"?foo"` or `base."?bar"`.
|
||||||
- Added warnings as another status code category.
|
- Added warnings as another status code category.
|
||||||
- Made the status type a `const char *`, not an `int32_t`.
|
- Made the status type a `const char *`, not an `int32_t`.
|
||||||
- Disallowed `__double_underscore` prefixed names.
|
- Disallowed `__double_underscore` prefixed names.
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import (
|
|||||||
t "github.com/google/wuffs/lang/token"
|
t "github.com/google/wuffs/lang/token"
|
||||||
)
|
)
|
||||||
|
|
||||||
var StatusList = [...]string{
|
var Statuses = [...]string{
|
||||||
// Warnings.
|
// Warnings.
|
||||||
"~end of data",
|
"~end of data",
|
||||||
|
|
||||||
@@ -42,14 +42,6 @@ var StatusList = [...]string{
|
|||||||
"?disabled by previous error",
|
"?disabled by previous error",
|
||||||
}
|
}
|
||||||
|
|
||||||
var StatusMap = map[string]bool{}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
for _, s := range StatusList {
|
|
||||||
StatusMap[s] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: a collection of forbidden variable names like and, or, not, as, ref,
|
// TODO: a collection of forbidden variable names like and, or, not, as, ref,
|
||||||
// deref, false, true, in, out, this, u8, u16, etc?
|
// deref, false, true, in, out, this, u8, u16, etc?
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,14 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, z := range builtin.Statuses {
|
||||||
|
id, err := tm.Insert(`"` + z + `"`)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.statuses[t.QID{t.IDBase, id}] = nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, phase := range phases {
|
for _, phase := range phases {
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if phase.kind == a.KInvalid {
|
if phase.kind == a.KInvalid {
|
||||||
@@ -586,6 +594,10 @@ func (c *Checker) checkAllTypeChecked(node *a.Node) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, v := range c.statuses {
|
for _, v := range c.statuses {
|
||||||
|
if v == nil {
|
||||||
|
// Built-in statuses have a nil v node.
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := allTypeChecked(c.tm, v.AsNode()); err != nil {
|
if err := allTypeChecked(c.tm, v.AsNode()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-6
@@ -18,8 +18,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/google/wuffs/lang/builtin"
|
|
||||||
|
|
||||||
a "github.com/google/wuffs/lang/ast"
|
a "github.com/google/wuffs/lang/ast"
|
||||||
t "github.com/google/wuffs/lang/token"
|
t "github.com/google/wuffs/lang/token"
|
||||||
)
|
)
|
||||||
@@ -385,10 +383,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
|
|
||||||
} else if id1.IsStrLiteral(q.tm) {
|
} else if id1.IsStrLiteral(q.tm) {
|
||||||
if _, ok := q.c.statuses[n.StatusQID()]; !ok {
|
if _, ok := q.c.statuses[n.StatusQID()]; !ok {
|
||||||
msg, _ := t.Unescape(n.Ident().Str(q.tm))
|
return fmt.Errorf("check: unrecognized status %s", n.StatusQID().Str(q.tm))
|
||||||
if _, ok := builtin.StatusMap[msg]; !ok {
|
|
||||||
return fmt.Errorf("check: no error or status with message %q", msg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
n.SetMType(typeExprStatus)
|
n.SetMType(typeExprStatus)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+11
-1
@@ -1017,7 +1017,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
|||||||
}
|
}
|
||||||
lhs := a.NewExpr(0, 0, 0, id, nil, nil, nil, nil)
|
lhs := a.NewExpr(0, 0, 0, id, nil, nil, nil, nil)
|
||||||
|
|
||||||
for {
|
for first := true; ; first = false {
|
||||||
flags := a.Flags(0)
|
flags := a.Flags(0)
|
||||||
switch p.peek1() {
|
switch p.peek1() {
|
||||||
default:
|
default:
|
||||||
@@ -1056,6 +1056,16 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
|||||||
|
|
||||||
case t.IDDot:
|
case t.IDDot:
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
|
|
||||||
|
if x := p.peek1(); x.IsStrLiteral(p.tm) {
|
||||||
|
if !first {
|
||||||
|
return nil, fmt.Errorf(`parse: string literal %s has too many package qualifiers at %s:%d`,
|
||||||
|
x.Str(p.tm), p.filename, p.line())
|
||||||
|
}
|
||||||
|
p.src = p.src[1:]
|
||||||
|
return a.NewExpr(0, 0, id, x, nil, nil, nil, nil), nil
|
||||||
|
}
|
||||||
|
|
||||||
selector, err := p.parseIdent()
|
selector, err := p.parseIdent()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -235,9 +235,9 @@ pri func decoder.decode_uncompressed!??(dst base.io_writer, src base.io_reader)
|
|||||||
}
|
}
|
||||||
length -= n_copied
|
length -= n_copied
|
||||||
if args.dst.available() == 0 {
|
if args.dst.available() == 0 {
|
||||||
yield "$short write"
|
yield base."$short write"
|
||||||
} else {
|
} else {
|
||||||
yield "$short read"
|
yield base."$short read"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yield "$short write"
|
yield base."$short write"
|
||||||
}
|
}
|
||||||
// Copy from the start of this.history, if we wrapped around.
|
// Copy from the start of this.history, if we wrapped around.
|
||||||
if hlen > 0 {
|
if hlen > 0 {
|
||||||
@@ -233,7 +233,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
|||||||
}
|
}
|
||||||
hlen -= n_copied
|
hlen -= n_copied
|
||||||
hdist ~mod+= n_copied
|
hdist ~mod+= n_copied
|
||||||
yield "$short write"
|
yield base."$short write"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +250,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
length -= n_copied
|
length -= n_copied
|
||||||
yield "$short write"
|
yield base."$short write"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ pub struct decoder?(
|
|||||||
|
|
||||||
pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_reader) {
|
pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_reader) {
|
||||||
if this.call_sequence >= 1 {
|
if this.call_sequence >= 1 {
|
||||||
return "?bad call sequence"
|
return base."?bad call sequence"
|
||||||
}
|
}
|
||||||
this.dirty_y.reset!()
|
this.dirty_y.reset!()
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
|
|||||||
|
|
||||||
pub func decoder.restart_frame!??(index base.u64, io_position base.u64) {
|
pub func decoder.restart_frame!??(index base.u64, io_position base.u64) {
|
||||||
if this.call_sequence == 0 {
|
if this.call_sequence == 0 {
|
||||||
return "?bad call sequence"
|
return base."?bad call sequence"
|
||||||
}
|
}
|
||||||
this.end_of_data = false
|
this.end_of_data = false
|
||||||
this.restarted = true
|
this.restarted = true
|
||||||
@@ -212,7 +212,7 @@ pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_
|
|||||||
// This is a new "if", not an "else", because the calls above can modify
|
// This is a new "if", not an "else", because the calls above can modify
|
||||||
// this.end_of_data.
|
// this.end_of_data.
|
||||||
if this.end_of_data {
|
if this.end_of_data {
|
||||||
return "~end of data"
|
return base."~end of data"
|
||||||
}
|
}
|
||||||
|
|
||||||
var blend base.u8 = 0
|
var blend base.u8 = 0
|
||||||
@@ -255,7 +255,7 @@ pri func decoder.skip_frame!??(src base.io_reader) {
|
|||||||
// TODO: honor args.opts.
|
// TODO: honor args.opts.
|
||||||
pub func decoder.decode_frame!??(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8, opts nptr base.decode_frame_options) {
|
pub func decoder.decode_frame!??(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8, opts nptr base.decode_frame_options) {
|
||||||
if args.workbuf.length() < (this.width as base.u64) {
|
if args.workbuf.length() < (this.width as base.u64) {
|
||||||
return "?bad workbuf length"
|
return base."?bad workbuf length"
|
||||||
}
|
}
|
||||||
if this.call_sequence != 2 {
|
if this.call_sequence != 2 {
|
||||||
this.decode_frame_config!??(dst:nullptr, src:args.src)
|
this.decode_frame_config!??(dst:nullptr, src:args.src)
|
||||||
@@ -281,7 +281,7 @@ pri func decoder.decode_up_to_id_part1!??(src base.io_reader) {
|
|||||||
if not this.restarted {
|
if not this.restarted {
|
||||||
this.frame_config_io_position = args.src.position()
|
this.frame_config_io_position = args.src.position()
|
||||||
} else if this.frame_config_io_position != args.src.position() {
|
} else if this.frame_config_io_position != args.src.position() {
|
||||||
return "?bad restart"
|
return base."?bad restart"
|
||||||
} else {
|
} else {
|
||||||
this.restarted = false
|
this.restarted = false
|
||||||
}
|
}
|
||||||
@@ -634,7 +634,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
block_size ~sat-= args.src.since_mark().length()
|
block_size ~sat-= args.src.since_mark().length()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block_size == 0) and (z == "$short read") {
|
if (block_size == 0) and (z == base."$short read") {
|
||||||
break:inner
|
break:inner
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -647,7 +647,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
this.previous_lzw_decode_ended_abruptly = false
|
this.previous_lzw_decode_ended_abruptly = false
|
||||||
break:inner
|
break:inner
|
||||||
}
|
}
|
||||||
if z == "$short write" {
|
if z == base."$short write" {
|
||||||
continue:inner
|
continue:inner
|
||||||
}
|
}
|
||||||
yield z
|
yield z
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
this.flush!??(dst:args.dst)
|
this.flush!??(dst:args.dst)
|
||||||
j = 0
|
j = 0
|
||||||
}
|
}
|
||||||
yield "$short read"
|
yield base."$short read"
|
||||||
}
|
}
|
||||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||||
args.src.skip_fast!(actual:1, worst_case:1)
|
args.src.skip_fast!(actual:1, worst_case:1)
|
||||||
@@ -259,6 +259,6 @@ pri func decoder.flush!??(dst base.io_writer) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
i = (i + ((n & 8191) as base.u32)) & 8191
|
i = (i + ((n & 8191) as base.u32)) & 8191
|
||||||
yield "$short write"
|
yield base."$short write"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user