mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Unexport some unused lang/check API
This commit is contained in:
1 parent
1004d898d5
commit
117a6c829b
4 files changed
+46
-79
No files matched your search
@@ -934,7 +934,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
|||||||
case t.KeyDot:
|
case t.KeyDot:
|
||||||
// TODO: delete this hack that only matches "in".
|
// TODO: delete this hack that only matches "in".
|
||||||
if n.LHS().Expr().Ident().Key() == t.KeyIn {
|
if n.LHS().Expr().Ident().Key() == t.KeyIn {
|
||||||
for _, o := range q.f.Func.In().Fields() {
|
for _, o := range q.astFunc.In().Fields() {
|
||||||
o := o.Field()
|
o := o.Field()
|
||||||
if o.Name() == n.Ident() {
|
if o.Name() == n.Ident() {
|
||||||
return q.bcheckTypeExpr(o.XType())
|
return q.bcheckTypeExpr(o.XType())
|
||||||
|
|||||||
+29
-62
@@ -60,27 +60,6 @@ func (e *Error) Error() string {
|
|||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Const struct {
|
|
||||||
QID t.QID // Qualified ID of the const name.
|
|
||||||
Const *a.Const
|
|
||||||
}
|
|
||||||
|
|
||||||
type Func struct {
|
|
||||||
QQID t.QQID // Double-qualified ID of the func name.
|
|
||||||
Func *a.Func
|
|
||||||
LocalVars TypeMap
|
|
||||||
}
|
|
||||||
|
|
||||||
type Status struct {
|
|
||||||
QID t.QID // Qualified ID of the status message.
|
|
||||||
Status *a.Status
|
|
||||||
}
|
|
||||||
|
|
||||||
type Struct struct {
|
|
||||||
QID t.QID // Qualified ID of the struct name.
|
|
||||||
Struct *a.Struct
|
|
||||||
}
|
|
||||||
|
|
||||||
type usee struct {
|
type usee struct {
|
||||||
consts map[t.QID]*a.Const
|
consts map[t.QID]*a.Const
|
||||||
funcs map[t.QQID]*a.Func
|
funcs map[t.QQID]*a.Func
|
||||||
@@ -116,10 +95,11 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
|
|||||||
resolveUse: resolveUse,
|
resolveUse: resolveUse,
|
||||||
reasonMap: rMap,
|
reasonMap: rMap,
|
||||||
packageID: base38.Max + 1,
|
packageID: base38.Max + 1,
|
||||||
consts: map[t.QID]Const{},
|
consts: map[t.QID]*a.Const{},
|
||||||
funcs: map[t.QQID]Func{},
|
funcs: map[t.QQID]*a.Func{},
|
||||||
statuses: map[t.QID]Status{},
|
localVars: map[t.QQID]typeMap{},
|
||||||
structs: map[t.QID]Struct{},
|
statuses: map[t.QID]*a.Status{},
|
||||||
|
structs: map[t.QID]*a.Struct{},
|
||||||
usees: map[t.ID]*usee{},
|
usees: map[t.ID]*usee{},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,10 +156,11 @@ type Checker struct {
|
|||||||
packageID uint32
|
packageID uint32
|
||||||
otherPackageID *a.PackageID
|
otherPackageID *a.PackageID
|
||||||
|
|
||||||
consts map[t.QID]Const
|
consts map[t.QID]*a.Const
|
||||||
funcs map[t.QQID]Func
|
funcs map[t.QQID]*a.Func
|
||||||
statuses map[t.QID]Status
|
localVars map[t.QQID]typeMap
|
||||||
structs map[t.QID]Struct
|
statuses map[t.QID]*a.Status
|
||||||
|
structs map[t.QID]*a.Struct
|
||||||
|
|
||||||
// usees are the packages referred to in the `use "foo/bar"` lines. The
|
// usees are the packages referred to in the `use "foo/bar"` lines. The
|
||||||
// keys are the use path base: `bar`, not `"foo/bar"`.
|
// keys are the use path base: `bar`, not `"foo/bar"`.
|
||||||
@@ -190,11 +171,7 @@ type Checker struct {
|
|||||||
unsortedStructs []*a.Struct
|
unsortedStructs []*a.Struct
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checker) PackageID() uint32 { return c.packageID }
|
func (c *Checker) PackageID() uint32 { return c.packageID }
|
||||||
func (c *Checker) Consts() map[t.QID]Const { return c.consts }
|
|
||||||
func (c *Checker) Funcs() map[t.QQID]Func { return c.funcs }
|
|
||||||
func (c *Checker) Statuses() map[t.QID]Status { return c.statuses }
|
|
||||||
func (c *Checker) Structs() map[t.QID]Struct { return c.structs }
|
|
||||||
|
|
||||||
func (c *Checker) checkPackageID(node *a.Node) error {
|
func (c *Checker) checkPackageID(node *a.Node) error {
|
||||||
n := node.PackageID()
|
n := node.PackageID()
|
||||||
@@ -306,14 +283,11 @@ func (c *Checker) checkStatus(node *a.Node) error {
|
|||||||
Err: fmt.Errorf("check: duplicate status %s", qid.Str(c.tm)),
|
Err: fmt.Errorf("check: duplicate status %s", qid.Str(c.tm)),
|
||||||
Filename: n.Filename(),
|
Filename: n.Filename(),
|
||||||
Line: n.Line(),
|
Line: n.Line(),
|
||||||
OtherFilename: other.Status.Filename(),
|
OtherFilename: other.Filename(),
|
||||||
OtherLine: other.Status.Line(),
|
OtherLine: other.Line(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.statuses[qid] = Status{
|
c.statuses[qid] = n
|
||||||
QID: qid,
|
|
||||||
Status: n,
|
|
||||||
}
|
|
||||||
n.Node().SetTypeChecked()
|
n.Node().SetTypeChecked()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -326,14 +300,11 @@ func (c *Checker) checkConst(node *a.Node) error {
|
|||||||
Err: fmt.Errorf("check: duplicate const %s", qid.Str(c.tm)),
|
Err: fmt.Errorf("check: duplicate const %s", qid.Str(c.tm)),
|
||||||
Filename: n.Filename(),
|
Filename: n.Filename(),
|
||||||
Line: n.Line(),
|
Line: n.Line(),
|
||||||
OtherFilename: other.Const.Filename(),
|
OtherFilename: other.Filename(),
|
||||||
OtherLine: other.Const.Line(),
|
OtherLine: other.Line(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.consts[qid] = Const{
|
c.consts[qid] = n
|
||||||
QID: qid,
|
|
||||||
Const: n,
|
|
||||||
}
|
|
||||||
|
|
||||||
q := &checker{
|
q := &checker{
|
||||||
c: c,
|
c: c,
|
||||||
@@ -399,14 +370,11 @@ func (c *Checker) checkStructDecl(node *a.Node) error {
|
|||||||
Err: fmt.Errorf("check: duplicate struct %s", qid.Str(c.tm)),
|
Err: fmt.Errorf("check: duplicate struct %s", qid.Str(c.tm)),
|
||||||
Filename: n.Filename(),
|
Filename: n.Filename(),
|
||||||
Line: n.Line(),
|
Line: n.Line(),
|
||||||
OtherFilename: other.Struct.Filename(),
|
OtherFilename: other.Filename(),
|
||||||
OtherLine: other.Struct.Line(),
|
OtherLine: other.Line(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.structs[qid] = Struct{
|
c.structs[qid] = n
|
||||||
QID: qid,
|
|
||||||
Struct: n,
|
|
||||||
}
|
|
||||||
c.unsortedStructs = append(c.unsortedStructs, n)
|
c.unsortedStructs = append(c.unsortedStructs, n)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -501,8 +469,8 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
|
|||||||
Err: fmt.Errorf("check: duplicate function %s", qqid.Str(c.tm)),
|
Err: fmt.Errorf("check: duplicate function %s", qqid.Str(c.tm)),
|
||||||
Filename: n.Filename(),
|
Filename: n.Filename(),
|
||||||
Line: n.Line(),
|
Line: n.Line(),
|
||||||
OtherFilename: other.Func.Filename(),
|
OtherFilename: other.Filename(),
|
||||||
OtherLine: other.Func.Line(),
|
OtherLine: other.Line(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,7 +480,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
|
|||||||
oQID := n.Out().QID()
|
oQID := n.Out().QID()
|
||||||
outTyp := a.NewTypeExpr(0, oQID[0], oQID[1], nil, nil, nil)
|
outTyp := a.NewTypeExpr(0, oQID[0], oQID[1], nil, nil, nil)
|
||||||
outTyp.Node().SetTypeChecked()
|
outTyp.Node().SetTypeChecked()
|
||||||
localVars := TypeMap{
|
localVars := typeMap{
|
||||||
t.IDIn: inTyp,
|
t.IDIn: inTyp,
|
||||||
t.IDOut: outTyp,
|
t.IDOut: outTyp,
|
||||||
}
|
}
|
||||||
@@ -530,11 +498,8 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
|
|||||||
pTyp.Node().SetTypeChecked()
|
pTyp.Node().SetTypeChecked()
|
||||||
localVars[t.IDThis] = pTyp
|
localVars[t.IDThis] = pTyp
|
||||||
}
|
}
|
||||||
c.funcs[qqid] = Func{
|
c.funcs[qqid] = n
|
||||||
QQID: qqid,
|
c.localVars[qqid] = localVars
|
||||||
Func: n,
|
|
||||||
LocalVars: localVars,
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,7 +526,8 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
|
|||||||
c: c,
|
c: c,
|
||||||
tm: c.tm,
|
tm: c.tm,
|
||||||
reasonMap: c.reasonMap,
|
reasonMap: c.reasonMap,
|
||||||
f: c.funcs[n.QQID()],
|
astFunc: c.funcs[n.QQID()],
|
||||||
|
localVars: c.localVars[n.QQID()],
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in the TypeMap with all local variables. Note that they have
|
// Fill in the TypeMap with all local variables. Note that they have
|
||||||
@@ -646,7 +612,8 @@ type checker struct {
|
|||||||
c *Checker
|
c *Checker
|
||||||
tm *t.Map
|
tm *t.Map
|
||||||
reasonMap reasonMap
|
reasonMap reasonMap
|
||||||
f Func
|
astFunc *a.Func
|
||||||
|
localVars typeMap
|
||||||
|
|
||||||
errFilename string
|
errFilename string
|
||||||
errLine uint32
|
errLine uint32
|
||||||
|
|||||||
@@ -55,10 +55,10 @@ var (
|
|||||||
typeExprPlaceholder32 = a.NewTypeExpr(0, 0, t.IDU32, nil, nil, nil)
|
typeExprPlaceholder32 = a.NewTypeExpr(0, 0, t.IDU32, nil, nil, nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
// TypeMap maps from variable names (as token IDs) to types.
|
// typeMap maps from variable names (as token IDs) to types.
|
||||||
type TypeMap map[t.ID]*a.TypeExpr
|
type typeMap map[t.ID]*a.TypeExpr
|
||||||
|
|
||||||
var builtInTypeMap = TypeMap{
|
var builtInTypeMap = typeMap{
|
||||||
t.IDU8: typeExprU8,
|
t.IDU8: typeExprU8,
|
||||||
t.IDU16: typeExprU16,
|
t.IDU16: typeExprU16,
|
||||||
t.IDU32: typeExprU32,
|
t.IDU32: typeExprU32,
|
||||||
@@ -152,7 +152,7 @@ func (c *Checker) resolveFunc(typ *a.TypeExpr) (*a.Func, error) {
|
|||||||
} else if f != nil {
|
} else if f != nil {
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
if f := c.funcs[qqid].Func; f != nil {
|
if f := c.funcs[qqid]; f != nil {
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
// lTyp is from a used package: `use "foo"` followed by `foo.bar`.
|
// lTyp is from a used package: `use "foo"` followed by `foo.bar`.
|
||||||
|
|||||||
+12
-12
@@ -50,13 +50,13 @@ func (q *checker) tcheckVars(block []*a.Node) error {
|
|||||||
case a.KVar:
|
case a.KVar:
|
||||||
o := o.Var()
|
o := o.Var()
|
||||||
name := o.Name()
|
name := o.Name()
|
||||||
if _, ok := q.f.LocalVars[name]; ok {
|
if _, ok := q.localVars[name]; ok {
|
||||||
return fmt.Errorf("check: duplicate var %q", name.Str(q.tm))
|
return fmt.Errorf("check: duplicate var %q", name.Str(q.tm))
|
||||||
}
|
}
|
||||||
if err := q.tcheckTypeExpr(o.XType(), 0); err != nil {
|
if err := q.tcheckTypeExpr(o.XType(), 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
q.f.LocalVars[name] = o.XType()
|
q.localVars[name] = o.XType()
|
||||||
|
|
||||||
case a.KWhile:
|
case a.KWhile:
|
||||||
if err := q.tcheckVars(o.While().Body()); err != nil {
|
if err := q.tcheckVars(o.While().Body()); err != nil {
|
||||||
@@ -388,8 +388,8 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
return nil
|
return nil
|
||||||
|
|
||||||
} else if id1.IsIdent() {
|
} else if id1.IsIdent() {
|
||||||
if q.f.LocalVars != nil {
|
if q.localVars != nil {
|
||||||
if typ, ok := q.f.LocalVars[id1]; ok {
|
if typ, ok := q.localVars[id1]; ok {
|
||||||
n.SetMType(typ)
|
n.SetMType(typ)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -398,7 +398,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
// TODO: check somewhere that a global ident (i.e. a const) is
|
// TODO: check somewhere that a global ident (i.e. a const) is
|
||||||
// not directly in the LHS of an assignment.
|
// not directly in the LHS of an assignment.
|
||||||
n.SetGlobalIdent()
|
n.SetGlobalIdent()
|
||||||
n.SetMType(c.Const.XType())
|
n.SetMType(c.XType())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: look for other (global) names: consts, funcs, statuses,
|
// TODO: look for other (global) names: consts, funcs, statuses,
|
||||||
@@ -524,7 +524,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
nominalKeyword := n.Operator()
|
nominalKeyword := n.Operator()
|
||||||
declaredKeyword := t.ID(0)
|
declaredKeyword := t.ID(0)
|
||||||
if s, ok := q.c.statuses[n.StatusQID()]; ok {
|
if s, ok := q.c.statuses[n.StatusQID()]; ok {
|
||||||
declaredKeyword = s.Status.Keyword()
|
declaredKeyword = s.Keyword()
|
||||||
} else {
|
} else {
|
||||||
msg, _ := t.Unescape(n.Ident().Str(q.tm))
|
msg, _ := t.Unescape(n.Ident().Str(q.tm))
|
||||||
z, ok := builtin.StatusMap[msg]
|
z, ok := builtin.StatusMap[msg]
|
||||||
@@ -717,7 +717,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if f == nil {
|
} else if f == nil {
|
||||||
f = q.c.funcs[qqid].Func
|
f = q.c.funcs[qqid]
|
||||||
}
|
}
|
||||||
if f != nil {
|
if f != nil {
|
||||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.Ident(), lTyp.Node(), nil, nil))
|
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.Ident(), lTyp.Node(), nil, nil))
|
||||||
@@ -725,16 +725,16 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s := (*a.Struct)(nil)
|
s := (*a.Struct)(nil)
|
||||||
if q.f.Func != nil && lQID[0] == 0 {
|
if q.astFunc != nil && lQID[0] == 0 {
|
||||||
switch lQID[1].Key() {
|
switch lQID[1].Key() {
|
||||||
case t.KeyIn:
|
case t.KeyIn:
|
||||||
s = q.f.Func.In()
|
s = q.astFunc.In()
|
||||||
case t.KeyOut:
|
case t.KeyOut:
|
||||||
s = q.f.Func.Out()
|
s = q.astFunc.Out()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s == nil {
|
if s == nil {
|
||||||
s = q.c.structs[lQID].Struct
|
s = q.c.structs[lQID]
|
||||||
if s == nil && builtInTypeMap[lQID[1]] == nil {
|
if s == nil && builtInTypeMap[lQID[1]] == nil {
|
||||||
return fmt.Errorf("check: no struct type %q found for expression %q", lTyp.Str(q.tm), lhs.Str(q.tm))
|
return fmt.Errorf("check: no struct type %q found for expression %q", lTyp.Str(q.tm), lhs.Str(q.tm))
|
||||||
}
|
}
|
||||||
@@ -1068,7 +1068,7 @@ swtch:
|
|||||||
break swtch
|
break swtch
|
||||||
}
|
}
|
||||||
for _, s := range q.c.structs {
|
for _, s := range q.c.structs {
|
||||||
if s.QID == qid {
|
if s.QID() == qid {
|
||||||
break swtch
|
break swtch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user