mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
Rename Struct.Optional to Struct.Classy
This commit is contained in:
1 parent
7fc98dee00
commit
db04cf346f
4 files changed
+16
-11
No files matched your search
@@ -647,7 +647,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
|||||||
b.writes("//\n")
|
b.writes("//\n")
|
||||||
b.writes("// It is a struct, not a struct*, so that it can be stack allocated.\n")
|
b.writes("// It is a struct, not a struct*, so that it can be stack allocated.\n")
|
||||||
b.writes("struct {\n")
|
b.writes("struct {\n")
|
||||||
if n.Optional() {
|
if n.Classy() {
|
||||||
b.printf("wuffs_base__status status;\n")
|
b.printf("wuffs_base__status status;\n")
|
||||||
b.writes("uint32_t magic;\n")
|
b.writes("uint32_t magic;\n")
|
||||||
b.writes("\n")
|
b.writes("\n")
|
||||||
@@ -661,7 +661,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
|||||||
b.writes(";\n")
|
b.writes(";\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.Optional() {
|
if n.Classy() {
|
||||||
b.writeb('\n')
|
b.writeb('\n')
|
||||||
for _, file := range g.files {
|
for _, file := range g.files {
|
||||||
for _, tld := range file.TopLevelDecls() {
|
for _, tld := range file.TopLevelDecls() {
|
||||||
@@ -871,7 +871,7 @@ func (g *gen) writeInitializerSignature(b *buffer, n *a.Struct, public bool) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) writeInitializerPrototype(b *buffer, n *a.Struct) error {
|
func (g *gen) writeInitializerPrototype(b *buffer, n *a.Struct) error {
|
||||||
if !n.Optional() {
|
if !n.Classy() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := g.writeInitializerSignature(b, n, n.Public()); err != nil {
|
if err := g.writeInitializerSignature(b, n, n.Public()); err != nil {
|
||||||
@@ -882,7 +882,7 @@ func (g *gen) writeInitializerPrototype(b *buffer, n *a.Struct) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
||||||
if !n.Optional() {
|
if !n.Classy() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := g.writeInitializerSignature(b, n, false); err != nil {
|
if err := g.writeInitializerSignature(b, n, false); err != nil {
|
||||||
|
|||||||
+4
-4
@@ -318,11 +318,11 @@ func (h *genHelper) genWuffs(dirname string, qualifiedFilenames []string) error
|
|||||||
if !n.Public() {
|
if !n.Public() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
effect := ""
|
classy := ""
|
||||||
if n.Optional() {
|
if n.Classy() {
|
||||||
effect = "?"
|
classy = "?"
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "pub struct %s%s()\n", n.QID().Str(&h.tm), effect)
|
fmt.Fprintf(out, "pub struct %s%s()\n", n.QID().Str(&h.tm), classy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-2
@@ -99,6 +99,7 @@ const (
|
|||||||
FlagsHasBreak = Flags(0x00000200)
|
FlagsHasBreak = Flags(0x00000200)
|
||||||
FlagsHasContinue = Flags(0x00000400)
|
FlagsHasContinue = Flags(0x00000400)
|
||||||
FlagsGlobalIdent = Flags(0x00000800)
|
FlagsGlobalIdent = Flags(0x00000800)
|
||||||
|
FlagsClassy = Flags(0x00001000)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f Flags) AsEffect() Effect { return Effect(f) }
|
func (f Flags) AsEffect() Effect { return Effect(f) }
|
||||||
@@ -894,15 +895,19 @@ func NewConst(flags Flags, filename string, line uint32, name t.ID, xType *TypeE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Struct is "struct ID2(List0)":
|
// Struct is "struct ID2(List0)" or "struct ID2?(List0)":
|
||||||
// - FlagsPublic is "pub" vs "pri"
|
// - FlagsPublic is "pub" vs "pri"
|
||||||
|
// - FlagsClassy is "ID2" vs "ID2?"
|
||||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||||
// - ID2: name
|
// - ID2: name
|
||||||
// - List0: <Field> fields
|
// - List0: <Field> fields
|
||||||
|
//
|
||||||
|
// The question mark indicates a classy struct - one that supports methods,
|
||||||
|
// especially coroutines.
|
||||||
type Struct Node
|
type Struct Node
|
||||||
|
|
||||||
func (n *Struct) AsNode() *Node { return (*Node)(n) }
|
func (n *Struct) AsNode() *Node { return (*Node)(n) }
|
||||||
func (n *Struct) Optional() bool { return n.flags&Flags(EffectOptional) != 0 }
|
func (n *Struct) Classy() bool { return n.flags&FlagsClassy != 0 }
|
||||||
func (n *Struct) Public() bool { return n.flags&FlagsPublic != 0 }
|
func (n *Struct) Public() bool { return n.flags&FlagsPublic != 0 }
|
||||||
func (n *Struct) Filename() string { return n.filename }
|
func (n *Struct) Filename() string { return n.filename }
|
||||||
func (n *Struct) Line() uint32 { return n.line }
|
func (n *Struct) Line() uint32 { return n.line }
|
||||||
|
|||||||
+1
-1
@@ -269,7 +269,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.peek1() == t.IDQuestion {
|
if p.peek1() == t.IDQuestion {
|
||||||
flags |= a.EffectOptional.AsFlags()
|
flags |= a.FlagsClassy
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
}
|
}
|
||||||
fields, err := p.parseList(t.IDCloseParen, (*parser).parseFieldNode)
|
fields, err := p.parseList(t.IDCloseParen, (*parser).parseFieldNode)
|
||||||
|
|||||||
Reference in new issue
Block a user