mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
Allow scalar constants in type expressions
This commit is contained in:
1 parent
278200f560
commit
8bbdcc4ce1
7 files changed
+58
-18
No files matched your search
@@ -318,10 +318,11 @@ type gen struct {
|
||||
// generated C code (due to line numbers changing) when editing Wuffs code.
|
||||
genlinenum bool
|
||||
|
||||
statusList []status
|
||||
statusMap map[t.QID]status
|
||||
structList []*a.Struct
|
||||
structMap map[t.QID]*a.Struct
|
||||
scalarConstsMap map[t.QID]*a.Const
|
||||
statusList []status
|
||||
statusMap map[t.QID]status
|
||||
structList []*a.Struct
|
||||
structMap map[t.QID]*a.Struct
|
||||
|
||||
currFunk funk
|
||||
funks map[t.QQID]funk
|
||||
@@ -350,6 +351,11 @@ func (g *gen) generate() ([]byte, error) {
|
||||
}
|
||||
}
|
||||
|
||||
g.scalarConstsMap = map[t.QID]*a.Const{}
|
||||
if err := g.forEachConst(b, bothPubPri, (*gen).gatherScalarConsts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Make a topologically sorted list of structs.
|
||||
unsortedStructs := []*a.Struct(nil)
|
||||
for _, file := range g.files {
|
||||
@@ -667,6 +673,13 @@ func (g *gen) addStatus(qid t.QID, msg string, public bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gen) gatherScalarConsts(b *buffer, n *a.Const) error {
|
||||
if cv := n.Value().ConstValue(); cv != nil {
|
||||
g.scalarConstsMap[n.QID()] = n
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gen) writeConst(b *buffer, n *a.Const) error {
|
||||
if n.Public() {
|
||||
b.writes("WUFFS_BASE__MAYBE_STATIC ")
|
||||
|
||||
Reference in new issue
Block a user