Add base.PIXEL_FORMAT__ETC constants

This commit is contained in:
Nigel Tao committed 2020-06-09 12:34:34 +10:00
1 parent 983c5cd90e
commit 7e32336de0
10 files changed
+127 -46

No files matched your search

+18 -7
View File
@@ -731,7 +731,7 @@ func (q *checker) bcheckExpr(n *a.Expr, depth uint32) (bounds, error) {
return b, nil
}
if n.ConstValue() != nil {
return bcheckExprConstValue(n), nil
return bcheckExprConstValue(n)
}
nb, err := q.bcheckExpr1(n, depth)
@@ -756,23 +756,34 @@ func (q *checker) bcheckExpr(n *a.Expr, depth uint32) (bounds, error) {
return nb, nil
}
func bcheckExprConstValue(n *a.Expr) bounds {
func bcheckExprConstValue(n *a.Expr) (bounds, error) {
if o := n.LHS(); o != nil {
bcheckExprConstValue(o.AsExpr())
if _, err := bcheckExprConstValue(o.AsExpr()); err != nil {
return bounds{}, err
}
}
if o := n.MHS(); o != nil {
bcheckExprConstValue(o.AsExpr())
if _, err := bcheckExprConstValue(o.AsExpr()); err != nil {
return bounds{}, err
}
}
if o := n.RHS(); o != nil && n.Operator() != t.IDXBinaryAs {
bcheckExprConstValue(o.AsExpr())
if _, err := bcheckExprConstValue(o.AsExpr()); err != nil {
return bounds{}, err
}
}
for _, o := range n.Args() {
bcheckExprConstValue(o.AsExpr())
if _, err := bcheckExprConstValue(o.AsExpr()); err != nil {
return bounds{}, err
}
}
cv := n.ConstValue()
if cv == nil {
return bounds{}, fmt.Errorf("check: constant expression has nil ConstValue")
}
b := bounds{cv, cv}
n.SetMBounds(b)
return b
return b, nil
}
func (q *checker) bcheckExpr1(n *a.Expr, depth uint32) (bounds, error) {
+28 -1
View File
@@ -94,7 +94,9 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
statuses: map[t.QID]*a.Status{},
structs: map[t.QID]*a.Struct{},
useBaseNames: map[t.ID]struct{}{},
useBaseNames: map[t.ID]struct{}{
t.IDBase: struct{}{},
},
builtInSliceFuncs: map[t.QQID]*a.Func{},
builtInTableFuncs: map[t.QQID]*a.Func{},
@@ -127,6 +129,31 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
})
}
for _, z := range builtin.Consts {
name, err := tm.Insert(z.Name)
if err != nil {
return nil, err
}
xType := (*a.TypeExpr)(nil)
switch z.Type {
case t.IDU32:
xType = typeExprU32
case t.IDU64:
xType = typeExprU64
default:
return nil, fmt.Errorf("check: unsupported built-in const type %q", z.Type.Str(tm))
}
value, err := tm.Insert(z.Value)
if err != nil {
return nil, err
}
cNode := a.NewConst(0, "", 0, name, xType, a.NewExpr(0, 0, 0, value, nil, nil, nil, nil))
if err := c.checkConst(cNode.AsNode()); err != nil {
return nil, err
}
c.consts[t.QID{t.IDBase, name}] = cNode
}
for _, z := range builtin.Statuses {
id, err := tm.Insert(z)
if err != nil {
+1
View File
@@ -35,6 +35,7 @@ var (
typeExprIdeal = a.NewTypeExpr(0, t.IDBase, t.IDQIdeal, nil, nil, nil)
typeExprList = a.NewTypeExpr(0, t.IDBase, t.IDComma, nil, nil, nil)
typeExprNullptr = a.NewTypeExpr(0, t.IDBase, t.IDQNullptr, nil, nil, nil)
typeExprPackage = a.NewTypeExpr(0, t.IDBase, t.IDQPackage, nil, nil, nil)
typeExprPlaceholder = a.NewTypeExpr(0, t.IDBase, t.IDQPlaceholder, nil, nil, nil)
typeExprTypeExpr = a.NewTypeExpr(0, t.IDBase, t.IDQTypeExpr, nil, nil, nil)
+22 -9
View File
@@ -366,17 +366,12 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
return nil
}
}
if c, ok := q.c.consts[t.QID{0, id1}]; ok {
// TODO: check somewhere that a global ident (i.e. a const) is
// not directly in the LHS of an assignment.
n.SetGlobalIdent()
n.SetConstValue(c.Value().ConstValue())
n.SetMType(c.XType())
if _, ok := q.c.useBaseNames[id1]; ok {
n.SetConstValue(zero)
n.SetMType(typeExprPackage)
return nil
}
// TODO: look for other (global) names: consts, funcs, statuses,
// structs from used packages.
return fmt.Errorf("check: unrecognized identifier %q", id1.Str(q.tm))
return q.tcheckExprXDotY(n, 0, id1)
}
switch id1 {
@@ -491,6 +486,21 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
n.Operator(), n.Str(q.tm))
}
func (q *checker) tcheckExprXDotY(n *a.Expr, x t.ID, y t.ID) error {
qid := t.QID{x, y}
if c, ok := q.c.consts[qid]; ok {
// TODO: check somewhere that a global ident (i.e. a const) is
// not directly in the LHS of an assignment.
n.SetGlobalIdent()
n.SetConstValue(c.Value().ConstValue())
n.SetMType(c.XType())
return nil
}
// TODO: look for other (global) names: consts, funcs, statuses,
// structs from used packages.
return fmt.Errorf("check: unrecognized identifier %q", qid.Str(q.tm))
}
func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
lhs := n.LHS().AsExpr()
if err := q.tcheckExpr(lhs, depth); err != nil {
@@ -569,6 +579,9 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
if err := q.tcheckExpr(lhs, depth); err != nil {
return err
}
if lhs.MType() == typeExprPackage {
return q.tcheckExprXDotY(n, lhs.Ident(), n.Ident())
}
lTyp := lhs.MType().Pointee()
lQID := lTyp.QID()
qqid := t.QQID{lQID[0], lQID[1], n.Ident()}