mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Add pkg to ast Func, Struct and TypeExpr nodes
This commit is contained in:
1 parent
10e4936f08
commit
ed03c5943a
16 files changed
+311
-245
No files matched your search
+38
-22
@@ -143,15 +143,15 @@ type Node struct {
|
||||
// Expr operator literal/ident . Expr
|
||||
// Field . . name Field
|
||||
// File . . . File
|
||||
// Func receiver . name Func
|
||||
// Func funcName receiverPkg receiverName Func
|
||||
// If . . . If
|
||||
// Iterate . label . Iterate
|
||||
// Jump keyword label . Jump
|
||||
// PackageID . literal . PackageID
|
||||
// Ret keyword . . Ret
|
||||
// Status keyword pkg literal Status
|
||||
// Struct . . name Struct
|
||||
// TypeExpr decorator . name TypeExpr
|
||||
// Struct . pkg name Struct
|
||||
// TypeExpr decorator pkg name TypeExpr
|
||||
// Use . literal . Use
|
||||
// Var operator . name Var
|
||||
// While . label . While
|
||||
@@ -238,11 +238,21 @@ func (n *Raw) SetFilenameLine(f string, l uint32) { n.filename, n.line = f, l }
|
||||
func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
|
||||
return n.Node().Walk(func(o *Node) error {
|
||||
switch o.Kind() {
|
||||
case KConst, KStatus:
|
||||
case KConst, KFunc, KStatus, KStruct, KTypeExpr:
|
||||
if o.id1 != 0 {
|
||||
return fmt.Errorf(`invalid SetPackage(%q) call: old package: got %q, want ""`,
|
||||
pkg.Str(tm), o.id1.Str(tm))
|
||||
}
|
||||
|
||||
// TODO: Add signed integer types, as per the builtin.Types var?
|
||||
//
|
||||
// Or, don't hard code these, and instead require built-in types to
|
||||
// have qualified names, such as "builtin.u8" or "base.reader1"?
|
||||
switch o.id2.Key() {
|
||||
case t.KeyU8, t.KeyU16, t.KeyU32, t.KeyU64, t.KeyBool, t.KeyStatus, t.KeyReader1, t.KeyWriter1:
|
||||
return nil
|
||||
}
|
||||
|
||||
o.id1 = pkg
|
||||
}
|
||||
return nil
|
||||
@@ -574,7 +584,8 @@ const MaxTypeExprDepth = 63
|
||||
|
||||
// TypeExpr is a type expression, such as "u32", "u32[..8]", "pkg.foo", "ptr
|
||||
// T", "[8] T" or "[] T":
|
||||
// - ID0: <0|package name|IDPtr|IDOpenBracket|IDColon>
|
||||
// - ID0: <0|IDPtr|IDOpenBracket|IDColon|IDOpenParen>
|
||||
// - ID1: <0|pkg>
|
||||
// - ID2: <0|type name>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
@@ -586,23 +597,25 @@ const MaxTypeExprDepth = 63
|
||||
//
|
||||
// An IDColon ID0 means "[] RHS". RHS is the inner type.
|
||||
//
|
||||
// An IDOpenParen ID0 means "LHS.ID1", a function or method type. LHS is the
|
||||
// An IDOpenParen ID0 means "LHS.ID2", a function or method type. LHS is the
|
||||
// receiver type, which may be nil. If non-nil, it will be a pointee type: "T"
|
||||
// instead of "ptr T", "ptr ptr T", etc.
|
||||
//
|
||||
// TODO: method effects: "foo" vs "foo!" vs "foo?".
|
||||
//
|
||||
// Other ID0 values mean a (possibly package-qualified) type like "pkg.foo" or
|
||||
// "foo". ID0 is the "pkg" or zero, ID1 is the "foo". Such a type can be
|
||||
// refined as "foo[LHS..MHS]". LHS and MHS are Expr's, possibly nil. For
|
||||
// example, the LHS for "u32[..4095]" is nil.
|
||||
// A zero ID0 means a (possibly package-qualified) type like "pkg.foo" or
|
||||
// "foo". ID1 is the "pkg" or zero, ID2 is the "foo".
|
||||
//
|
||||
// TODO: struct types, list types.
|
||||
// Numeric types can be refined as "foo[LHS..MHS]". LHS and MHS are Expr's,
|
||||
// possibly nil. For example, the LHS for "u32[..4095]" is nil.
|
||||
//
|
||||
// TODO: struct types, list types, nptr vs ptr.
|
||||
type TypeExpr Node
|
||||
|
||||
func (n *TypeExpr) Node() *Node { return (*Node)(n) }
|
||||
func (n *TypeExpr) Decorator() t.ID { return n.id0 }
|
||||
func (n *TypeExpr) Name() t.ID { return n.id2 }
|
||||
func (n *TypeExpr) QID() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *TypeExpr) FuncName() t.ID { return n.id2 }
|
||||
func (n *TypeExpr) ArrayLength() *Expr { return n.lhs.Expr() }
|
||||
func (n *TypeExpr) Receiver() *TypeExpr { return n.lhs.TypeExpr() }
|
||||
func (n *TypeExpr) Bounds() [2]*Expr { return [2]*Expr{n.lhs.Expr(), n.mhs.Expr()} }
|
||||
@@ -676,10 +689,11 @@ func (n *TypeExpr) Unrefined() *TypeExpr {
|
||||
return &o
|
||||
}
|
||||
|
||||
func NewTypeExpr(decorator t.ID, name t.ID, alenRecvMin *Node, max *Expr, inner *TypeExpr) *TypeExpr {
|
||||
func NewTypeExpr(decorator t.ID, pkg t.ID, name t.ID, alenRecvMin *Node, max *Expr, inner *TypeExpr) *TypeExpr {
|
||||
return &TypeExpr{
|
||||
kind: KTypeExpr,
|
||||
id0: decorator,
|
||||
id1: pkg,
|
||||
id2: name,
|
||||
lhs: alenRecvMin,
|
||||
mhs: max.Node(),
|
||||
@@ -694,8 +708,9 @@ const MaxBodyDepth = 255
|
||||
// - FlagsImpure is "ID1" vs "ID1!"
|
||||
// - FlagsSuspendible is "ID1" vs "ID1?", it implies FlagsImpure
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID0: <0|receiver>
|
||||
// - ID2: name
|
||||
// - ID0: funcName
|
||||
// - ID1: <0|receiverPkg> (set by calling SetPackage)
|
||||
// - ID2: <0|receiverName>
|
||||
// - LHS: <Struct> in-parameters
|
||||
// - RHS: <Struct> out-parameters
|
||||
// - List1: <Assert> asserts
|
||||
@@ -720,22 +735,22 @@ func (n *Func) Suspendible() bool { return n.flags&FlagsSuspendible != 0 }
|
||||
func (n *Func) Public() bool { return n.flags&FlagsPublic != 0 }
|
||||
func (n *Func) Filename() string { return n.filename }
|
||||
func (n *Func) Line() uint32 { return n.line }
|
||||
func (n *Func) QID() t.QID { return t.QID{n.id0, n.id2} }
|
||||
func (n *Func) Receiver() t.ID { return n.id0 }
|
||||
func (n *Func) Name() t.ID { return n.id2 }
|
||||
func (n *Func) QQID() t.QQID { return t.QQID{n.id1, n.id2, n.id0} }
|
||||
func (n *Func) Receiver() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *Func) FuncName() t.ID { return n.id0 }
|
||||
func (n *Func) In() *Struct { return n.lhs.Struct() }
|
||||
func (n *Func) Out() *Struct { return n.rhs.Struct() }
|
||||
func (n *Func) Asserts() []*Node { return n.list1 }
|
||||
func (n *Func) Body() []*Node { return n.list2 }
|
||||
|
||||
func NewFunc(flags Flags, filename string, line uint32, receiver t.ID, name t.ID, in *Struct, out *Struct, asserts []*Node, body []*Node) *Func {
|
||||
func NewFunc(flags Flags, filename string, line uint32, receiverName t.ID, funcName t.ID, in *Struct, out *Struct, asserts []*Node, body []*Node) *Func {
|
||||
return &Func{
|
||||
kind: KFunc,
|
||||
flags: flags,
|
||||
filename: filename,
|
||||
line: line,
|
||||
id0: receiver,
|
||||
id2: name,
|
||||
id0: funcName,
|
||||
id2: receiverName,
|
||||
lhs: in.Node(),
|
||||
rhs: out.Node(),
|
||||
list1: asserts,
|
||||
@@ -799,6 +814,7 @@ func NewConst(flags Flags, filename string, line uint32, name t.ID, xType *TypeE
|
||||
// Struct is "struct ID1(List0)":
|
||||
// - FlagsSuspendible is "ID1" vs "ID1?"
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - List0: <Field> fields
|
||||
type Struct Node
|
||||
@@ -808,7 +824,7 @@ func (n *Struct) Suspendible() bool { return n.flags&FlagsSuspendible != 0 }
|
||||
func (n *Struct) Public() bool { return n.flags&FlagsPublic != 0 }
|
||||
func (n *Struct) Filename() string { return n.filename }
|
||||
func (n *Struct) Line() uint32 { return n.line }
|
||||
func (n *Struct) Name() t.ID { return n.id2 }
|
||||
func (n *Struct) QID() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *Struct) Fields() []*Node { return n.list0 }
|
||||
|
||||
func NewStruct(flags Flags, filename string, line uint32, name t.ID, fields []*Node) *Struct {
|
||||
|
||||
+6
-9
@@ -22,14 +22,14 @@ func TopologicalSortStructs(ns []*Struct) (sorted []*Struct, ok bool) {
|
||||
// Algorithm is a depth-first search as per
|
||||
// https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search
|
||||
sorted = make([]*Struct, 0, len(ns))
|
||||
byName := map[t.ID]*Struct{}
|
||||
byQID := map[t.QID]*Struct{}
|
||||
for _, n := range ns {
|
||||
byName[n.Name()] = n
|
||||
byQID[n.QID()] = n
|
||||
}
|
||||
marks := map[*Struct]uint8{}
|
||||
for _, n := range ns {
|
||||
if _, ok := marks[n]; !ok {
|
||||
sorted, ok = tssVisit(sorted, n, byName, marks)
|
||||
sorted, ok = tssVisit(sorted, n, byQID, marks)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func TopologicalSortStructs(ns []*Struct) (sorted []*Struct, ok bool) {
|
||||
return sorted, true
|
||||
}
|
||||
|
||||
func tssVisit(dst []*Struct, n *Struct, byName map[t.ID]*Struct, marks map[*Struct]uint8) ([]*Struct, bool) {
|
||||
func tssVisit(dst []*Struct, n *Struct, byQID map[t.QID]*Struct, marks map[*Struct]uint8) ([]*Struct, bool) {
|
||||
const (
|
||||
unmarked = 0
|
||||
temporary = 1
|
||||
@@ -54,12 +54,9 @@ func tssVisit(dst []*Struct, n *Struct, byName map[t.ID]*Struct, marks map[*Stru
|
||||
|
||||
for _, f := range n.Fields() {
|
||||
x := f.Field().XType().Innermost()
|
||||
if x.Decorator() != 0 {
|
||||
continue
|
||||
}
|
||||
if o := byName[x.Name()]; o != nil {
|
||||
if o := byQID[x.QID()]; o != nil {
|
||||
var ok bool
|
||||
dst, ok = tssVisit(dst, o, byName, marks)
|
||||
dst, ok = tssVisit(dst, o, byQID, marks)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
+4
-6
@@ -176,7 +176,7 @@ func (n *TypeExpr) Str(tm *t.Map) string {
|
||||
return ""
|
||||
}
|
||||
if n.Decorator() == 0 && n.Min() == nil && n.Max() == nil {
|
||||
return tm.ByID(n.Name())
|
||||
return n.QID().Str(tm)
|
||||
}
|
||||
return string(n.appendStr(nil, tm, 0))
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (n *TypeExpr) appendStr(buf []byte, tm *t.Map, depth uint32) []byte {
|
||||
|
||||
switch n.Decorator().Key() {
|
||||
case 0:
|
||||
buf = append(buf, tm.ByID(n.Name())...)
|
||||
buf = append(buf, n.QID().Str(tm)...)
|
||||
case t.KeyPtr:
|
||||
buf = append(buf, "ptr "...)
|
||||
return n.Inner().appendStr(buf, tm, depth)
|
||||
@@ -208,11 +208,9 @@ func (n *TypeExpr) appendStr(buf []byte, tm *t.Map, depth uint32) []byte {
|
||||
buf = append(buf, "func "...)
|
||||
buf = n.Receiver().appendStr(buf, tm, depth)
|
||||
buf = append(buf, '.')
|
||||
return append(buf, tm.ByID(n.Name())...)
|
||||
return append(buf, n.FuncName().Str(tm)...)
|
||||
default:
|
||||
buf = append(buf, tm.ByID(n.Decorator())...)
|
||||
buf = append(buf, '.')
|
||||
buf = append(buf, tm.ByID(n.Name())...)
|
||||
return append(buf, "!invalid_type!"...)
|
||||
}
|
||||
if n.Min() != nil || n.Max() != nil {
|
||||
buf = append(buf, '[')
|
||||
|
||||
+22
-10
@@ -170,8 +170,10 @@ func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) {
|
||||
|
||||
func typeBounds(tm *t.Map, typ *a.TypeExpr) (*big.Int, *big.Int, error) {
|
||||
b := [2]*big.Int{}
|
||||
if key := typ.Name().Key(); typ.Decorator() == 0 && key < t.Key(len(numTypeBounds)) {
|
||||
b = numTypeBounds[key]
|
||||
if typ.Decorator() == 0 {
|
||||
if qid := typ.QID(); qid[0] == 0 && qid[1].Key() < t.Key(len(numTypeBounds)) {
|
||||
b = numTypeBounds[qid[1].Key()]
|
||||
}
|
||||
}
|
||||
if b[0] == nil || b[1] == nil {
|
||||
return nil, nil, nil
|
||||
@@ -940,7 +942,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
}
|
||||
lTyp := n.LHS().Expr().MType()
|
||||
return nil, nil, fmt.Errorf("check: no field named %q found in struct type %q for expression %q",
|
||||
n.ID1().Str(q.tm), lTyp.Name().Str(q.tm), n.Str(q.tm))
|
||||
n.ID1().Str(q.tm), lTyp.QID().Str(q.tm), n.Str(q.tm))
|
||||
}
|
||||
|
||||
if _, _, err := q.bcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||
@@ -1135,8 +1137,10 @@ func (q *checker) bcheckExprBinaryOp1(op t.Key, lhs *a.Expr, lMin *big.Int, lMax
|
||||
if typ.IsIdeal() {
|
||||
typ = rhs.MType()
|
||||
}
|
||||
b := numTypeBounds[typ.Name().Key()]
|
||||
return b[0], b[1], nil
|
||||
if qid := typ.QID(); qid[0] == 0 {
|
||||
b := numTypeBounds[qid[1].Key()]
|
||||
return b[0], b[1], nil
|
||||
}
|
||||
}
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprBinaryOp", op)
|
||||
}
|
||||
@@ -1175,18 +1179,26 @@ func (q *checker) bcheckTypeExpr(typ *a.TypeExpr) (*big.Int, *big.Int, error) {
|
||||
}
|
||||
|
||||
switch typ.Decorator().Key() {
|
||||
// TODO: case t.KeyOpenParen.
|
||||
case t.KeyPtr, t.KeyOpenBracket, t.KeyColon:
|
||||
return nil, nil, nil
|
||||
}
|
||||
switch typ.Name().Key() {
|
||||
case t.KeyReader1, t.KeyWriter1:
|
||||
return nil, nil, nil
|
||||
|
||||
// TODO: is the special cases for reader1 and writer1 superfluous with the
|
||||
// general purpose code for built-ins below?
|
||||
if qid := typ.QID(); qid[0] == 0 {
|
||||
switch qid[1].Key() {
|
||||
case t.KeyReader1, t.KeyWriter1:
|
||||
return nil, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
b := [2]*big.Int{}
|
||||
if key := typ.Name().Key(); key < t.Key(len(numTypeBounds)) {
|
||||
b = numTypeBounds[key]
|
||||
if qid := typ.QID(); qid[0] == 0 && qid[1].Key() < t.Key(len(numTypeBounds)) {
|
||||
b = numTypeBounds[qid[1].Key()]
|
||||
}
|
||||
// TODO: should || be && instead (see also func typeBounds)? Is this if
|
||||
// code superfluous?
|
||||
if b[0] == nil || b[1] == nil {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
+44
-41
@@ -66,7 +66,7 @@ type Const struct {
|
||||
}
|
||||
|
||||
type Func struct {
|
||||
QID t.QID // Qualified ID of the func name.
|
||||
QQID t.QQID // Double-qualified ID of the func name.
|
||||
Func *a.Func
|
||||
LocalVars TypeMap
|
||||
}
|
||||
@@ -77,15 +77,15 @@ type Status struct {
|
||||
}
|
||||
|
||||
type Struct struct {
|
||||
ID t.ID // ID of the struct name.
|
||||
QID t.QID // Qualified ID of the struct name.
|
||||
Struct *a.Struct
|
||||
}
|
||||
|
||||
type usee struct {
|
||||
consts map[t.QID]*a.Const
|
||||
funcs map[t.QID]*a.Func
|
||||
funcs map[t.QQID]*a.Func
|
||||
statuses map[t.QID]*a.Status
|
||||
structs map[t.ID]*a.Struct
|
||||
structs map[t.QID]*a.Struct
|
||||
}
|
||||
|
||||
func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte, error)) (*Checker, error) {
|
||||
@@ -117,9 +117,9 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
|
||||
reasonMap: rMap,
|
||||
packageID: base38.Max + 1,
|
||||
consts: map[t.QID]Const{},
|
||||
funcs: map[t.QID]Func{},
|
||||
funcs: map[t.QQID]Func{},
|
||||
statuses: map[t.QID]Status{},
|
||||
structs: map[t.ID]Struct{},
|
||||
structs: map[t.QID]Struct{},
|
||||
usees: map[t.ID]*usee{},
|
||||
}
|
||||
|
||||
@@ -177,24 +177,24 @@ type Checker struct {
|
||||
otherPackageID *a.PackageID
|
||||
|
||||
consts map[t.QID]Const
|
||||
funcs map[t.QID]Func
|
||||
funcs map[t.QQID]Func
|
||||
statuses map[t.QID]Status
|
||||
structs map[t.ID]Struct
|
||||
structs map[t.QID]Struct
|
||||
|
||||
// usees are the packages referred to in the `use "foo/bar"` lines. The
|
||||
// keys are the use path base: `bar`, not `"foo/bar"`.
|
||||
usees map[t.ID]*usee
|
||||
|
||||
builtInFuncs map[t.QID]*a.Func
|
||||
builtInSliceFuncs map[t.QID]*a.Func
|
||||
builtInFuncs map[t.QQID]*a.Func
|
||||
builtInSliceFuncs map[t.QQID]*a.Func
|
||||
unsortedStructs []*a.Struct
|
||||
}
|
||||
|
||||
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.QID]Func { return c.funcs }
|
||||
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.ID]Struct { return c.structs }
|
||||
func (c *Checker) Structs() map[t.QID]Struct { return c.structs }
|
||||
|
||||
func (c *Checker) checkPackageID(node *a.Node) error {
|
||||
n := node.PackageID()
|
||||
@@ -271,9 +271,9 @@ func (c *Checker) checkUse(node *a.Node) error {
|
||||
|
||||
u := &usee{
|
||||
consts: map[t.QID]*a.Const{},
|
||||
funcs: map[t.QID]*a.Func{},
|
||||
funcs: map[t.QQID]*a.Func{},
|
||||
statuses: map[t.QID]*a.Status{},
|
||||
structs: map[t.ID]*a.Struct{},
|
||||
structs: map[t.QID]*a.Struct{},
|
||||
}
|
||||
for _, n := range f.TopLevelDecls() {
|
||||
if err := n.Raw().SetPackage(c.tm, base); err != nil {
|
||||
@@ -285,13 +285,13 @@ func (c *Checker) checkUse(node *a.Node) error {
|
||||
u.consts[n.QID()] = n
|
||||
case a.KFunc:
|
||||
n := n.Func()
|
||||
u.funcs[n.QID()] = n
|
||||
u.funcs[n.QQID()] = n
|
||||
case a.KStatus:
|
||||
n := n.Status()
|
||||
u.statuses[n.QID()] = n
|
||||
case a.KStruct:
|
||||
n := n.Struct()
|
||||
u.structs[n.Name()] = n
|
||||
u.structs[n.QID()] = n
|
||||
}
|
||||
}
|
||||
c.usees[base] = u
|
||||
@@ -393,18 +393,18 @@ func (c *Checker) checkConstElement(n *a.Expr, nMin *big.Int, nMax *big.Int, nLi
|
||||
|
||||
func (c *Checker) checkStructDecl(node *a.Node) error {
|
||||
n := node.Struct()
|
||||
id := n.Name()
|
||||
if other, ok := c.structs[id]; ok {
|
||||
qid := n.QID()
|
||||
if other, ok := c.structs[qid]; ok {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("check: duplicate struct %q", id.Str(c.tm)),
|
||||
Err: fmt.Errorf("check: duplicate struct %s", qid.Str(c.tm)),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
OtherFilename: other.Struct.Filename(),
|
||||
OtherLine: other.Struct.Line(),
|
||||
}
|
||||
}
|
||||
c.structs[id] = Struct{
|
||||
ID: id,
|
||||
c.structs[qid] = Struct{
|
||||
QID: qid,
|
||||
Struct: n,
|
||||
}
|
||||
c.unsortedStructs = append(c.unsortedStructs, n)
|
||||
@@ -422,7 +422,7 @@ func (c *Checker) checkStructFields(node *a.Node) error {
|
||||
n := node.Struct()
|
||||
if err := c.checkFields(n.Fields(), true); err != nil {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("%v in struct %q", err, n.Name().Str(c.tm)),
|
||||
Err: fmt.Errorf("%v in struct %s", err, n.QID().Str(c.tm)),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
}
|
||||
@@ -455,7 +455,7 @@ func (c *Checker) checkFields(fields []*a.Node, banPtrTypes bool) error {
|
||||
}
|
||||
if dv := f.DefaultValue(); dv != nil {
|
||||
if f.XType().Decorator() != 0 {
|
||||
return fmt.Errorf("check: cannot set default value for qualified type %q for field %q",
|
||||
return fmt.Errorf("check: cannot set default value for type %q for field %q",
|
||||
f.XType().Str(c.tm), f.Name().Str(c.tm))
|
||||
}
|
||||
if err := q.tcheckExpr(dv, 0); err != nil {
|
||||
@@ -476,7 +476,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
|
||||
n := node.Func()
|
||||
if err := c.checkFields(n.In().Fields(), false); err != nil {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("%v in in-params for func %q", err, n.Name().Str(c.tm)),
|
||||
Err: fmt.Errorf("%v in in-params for func %s", err, n.QQID().Str(c.tm)),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
}
|
||||
@@ -484,7 +484,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
|
||||
n.In().Node().SetTypeChecked()
|
||||
if err := c.checkFields(n.Out().Fields(), false); err != nil {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("%v in out-params for func %q", err, n.Name().Str(c.tm)),
|
||||
Err: fmt.Errorf("%v in out-params for func %s", err, n.QQID().Str(c.tm)),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
}
|
||||
@@ -495,10 +495,10 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
|
||||
// suspendible), that we end with a return statement? Or is that an
|
||||
// implicit "return out"?
|
||||
|
||||
qid := n.QID()
|
||||
if other, ok := c.funcs[qid]; ok {
|
||||
qqid := n.QQID()
|
||||
if other, ok := c.funcs[qqid]; ok {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("check: duplicate function %q", qid.Str(c.tm)),
|
||||
Err: fmt.Errorf("check: duplicate function %s", qqid.Str(c.tm)),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
OtherFilename: other.Func.Filename(),
|
||||
@@ -506,30 +506,32 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
|
||||
}
|
||||
}
|
||||
|
||||
inTyp := a.NewTypeExpr(0, n.In().Name(), nil, nil, nil)
|
||||
iQID := n.In().QID()
|
||||
inTyp := a.NewTypeExpr(0, iQID[0], iQID[1], nil, nil, nil)
|
||||
inTyp.Node().SetTypeChecked()
|
||||
outTyp := a.NewTypeExpr(0, n.Out().Name(), nil, nil, nil)
|
||||
oQID := n.Out().QID()
|
||||
outTyp := a.NewTypeExpr(0, oQID[0], oQID[1], nil, nil, nil)
|
||||
outTyp.Node().SetTypeChecked()
|
||||
localVars := TypeMap{
|
||||
t.IDIn: inTyp,
|
||||
t.IDOut: outTyp,
|
||||
}
|
||||
if qid[0] != 0 {
|
||||
if _, ok := c.structs[qid[0]]; !ok {
|
||||
if qqid[1] != 0 {
|
||||
if _, ok := c.structs[t.QID{qqid[0], qqid[1]}]; !ok {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("check: no receiver struct defined for function %q", qid.Str(c.tm)),
|
||||
Err: fmt.Errorf("check: no receiver struct defined for function %s", qqid.Str(c.tm)),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
}
|
||||
}
|
||||
sTyp := a.NewTypeExpr(0, qid[0], nil, nil, nil)
|
||||
sTyp := a.NewTypeExpr(0, qqid[0], qqid[1], nil, nil, nil)
|
||||
sTyp.Node().SetTypeChecked()
|
||||
pTyp := a.NewTypeExpr(t.IDPtr, 0, nil, nil, sTyp)
|
||||
pTyp := a.NewTypeExpr(t.IDPtr, 0, 0, nil, nil, sTyp)
|
||||
pTyp.Node().SetTypeChecked()
|
||||
localVars[t.IDThis] = pTyp
|
||||
}
|
||||
c.funcs[qid] = Func{
|
||||
QID: qid,
|
||||
c.funcs[qqid] = Func{
|
||||
QQID: qqid,
|
||||
Func: n,
|
||||
LocalVars: localVars,
|
||||
}
|
||||
@@ -559,7 +561,7 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
|
||||
c: c,
|
||||
tm: c.tm,
|
||||
reasonMap: c.reasonMap,
|
||||
f: c.funcs[n.QID()],
|
||||
f: c.funcs[n.QQID()],
|
||||
}
|
||||
|
||||
// Fill in the TypeMap with all local variables. Note that they have
|
||||
@@ -630,10 +632,11 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
|
||||
func (c *Checker) checkFieldMethodCollisions(node *a.Node) error {
|
||||
n := node.Struct()
|
||||
for _, o := range n.Fields() {
|
||||
qid := t.QID{n.Name(), o.Field().Name()}
|
||||
if _, ok := c.funcs[qid]; ok {
|
||||
nQID := n.QID()
|
||||
qqid := t.QQID{nQID[0], nQID[1], o.Field().Name()}
|
||||
if _, ok := c.funcs[qqid]; ok {
|
||||
return fmt.Errorf("check: struct %q has both a field and method named %q",
|
||||
qid[0].Str(c.tm), qid[1].Str(c.tm))
|
||||
nQID.Str(c.tm), qqid[2].Str(c.tm))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestCheck(tt *testing.T) {
|
||||
break
|
||||
}
|
||||
|
||||
if got, want := fooBar.QID.Str(tm), "foo.bar"; got != want {
|
||||
if got, want := fooBar.QQID.Str(tm), "foo.bar"; got != want {
|
||||
tt.Fatalf("Funcs[0] name: got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
|
||||
+42
-47
@@ -34,25 +34,25 @@ var (
|
||||
|
||||
// typeExprFoo is an *ast.Node MType (implicit type).
|
||||
var (
|
||||
typeExprGeneric = a.NewTypeExpr(0, t.IDDiamond, nil, nil, nil)
|
||||
typeExprIdeal = a.NewTypeExpr(0, t.IDDoubleZ, nil, nil, nil)
|
||||
typeExprList = a.NewTypeExpr(0, t.IDDollar, nil, nil, nil)
|
||||
typeExprGeneric = a.NewTypeExpr(0, 0, t.IDDiamond, nil, nil, nil)
|
||||
typeExprIdeal = a.NewTypeExpr(0, 0, t.IDDoubleZ, nil, nil, nil)
|
||||
typeExprList = a.NewTypeExpr(0, 0, t.IDDollar, nil, nil, nil)
|
||||
|
||||
typeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil)
|
||||
typeExprU16 = a.NewTypeExpr(0, t.IDU16, nil, nil, nil)
|
||||
typeExprU32 = a.NewTypeExpr(0, t.IDU32, nil, nil, nil)
|
||||
typeExprU64 = a.NewTypeExpr(0, t.IDU64, nil, nil, nil)
|
||||
typeExprBool = a.NewTypeExpr(0, t.IDBool, nil, nil, nil)
|
||||
typeExprStatus = a.NewTypeExpr(0, t.IDStatus, nil, nil, nil)
|
||||
typeExprReader1 = a.NewTypeExpr(0, t.IDReader1, nil, nil, nil)
|
||||
typeExprWriter1 = a.NewTypeExpr(0, t.IDWriter1, nil, nil, nil)
|
||||
typeExprU8 = a.NewTypeExpr(0, 0, t.IDU8, nil, nil, nil)
|
||||
typeExprU16 = a.NewTypeExpr(0, 0, t.IDU16, nil, nil, nil)
|
||||
typeExprU32 = a.NewTypeExpr(0, 0, t.IDU32, nil, nil, nil)
|
||||
typeExprU64 = a.NewTypeExpr(0, 0, t.IDU64, nil, nil, nil)
|
||||
typeExprBool = a.NewTypeExpr(0, 0, t.IDBool, nil, nil, nil)
|
||||
typeExprStatus = a.NewTypeExpr(0, 0, t.IDStatus, nil, nil, nil)
|
||||
typeExprReader1 = a.NewTypeExpr(0, 0, t.IDReader1, nil, nil, nil)
|
||||
typeExprWriter1 = a.NewTypeExpr(0, 0, t.IDWriter1, nil, nil, nil)
|
||||
|
||||
typeExprSliceU8 = a.NewTypeExpr(t.IDColon, 0, nil, nil, typeExprU8)
|
||||
typeExprSliceU8 = a.NewTypeExpr(t.IDColon, 0, 0, nil, nil, typeExprU8)
|
||||
|
||||
// TODO: delete this.
|
||||
typeExprPlaceholder = a.NewTypeExpr(0, t.IDU8, nil, nil, nil)
|
||||
typeExprPlaceholder16 = a.NewTypeExpr(0, t.IDU16, nil, nil, nil)
|
||||
typeExprPlaceholder32 = a.NewTypeExpr(0, t.IDU32, nil, nil, nil)
|
||||
typeExprPlaceholder = a.NewTypeExpr(0, 0, t.IDU8, nil, nil, nil)
|
||||
typeExprPlaceholder16 = a.NewTypeExpr(0, 0, t.IDU16, nil, nil, nil)
|
||||
typeExprPlaceholder32 = a.NewTypeExpr(0, 0, t.IDU32, nil, nil, nil)
|
||||
)
|
||||
|
||||
// TypeMap maps from variable names (as token IDs) to types.
|
||||
@@ -69,7 +69,7 @@ var builtInTypeMap = TypeMap{
|
||||
t.IDWriter1: typeExprWriter1,
|
||||
}
|
||||
|
||||
func (c *Checker) builtInFunc(qid t.QID) (*a.Func, error) {
|
||||
func (c *Checker) builtInFunc(qqid t.QQID) (*a.Func, error) {
|
||||
if c.builtInFuncs == nil {
|
||||
err := error(nil)
|
||||
c.builtInFuncs, err = parseBuiltInFuncs(c.tm, builtin.Funcs, false)
|
||||
@@ -77,10 +77,10 @@ func (c *Checker) builtInFunc(qid t.QID) (*a.Func, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return c.builtInFuncs[qid], nil
|
||||
return c.builtInFuncs[qqid], nil
|
||||
}
|
||||
|
||||
func (c *Checker) builtInSliceFunc(qid t.QID) (*a.Func, error) {
|
||||
func (c *Checker) builtInSliceFunc(qqid t.QQID) (*a.Func, error) {
|
||||
if c.builtInSliceFuncs == nil {
|
||||
err := error(nil)
|
||||
c.builtInSliceFuncs, err = parseBuiltInFuncs(c.tm, builtin.SliceFuncs, true)
|
||||
@@ -88,11 +88,11 @@ func (c *Checker) builtInSliceFunc(qid t.QID) (*a.Func, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return c.builtInSliceFuncs[qid], nil
|
||||
return c.builtInSliceFuncs[qqid], nil
|
||||
}
|
||||
|
||||
func parseBuiltInFuncs(tm *t.Map, ss []string, generic bool) (map[t.QID]*a.Func, error) {
|
||||
m := map[t.QID]*a.Func{}
|
||||
func parseBuiltInFuncs(tm *t.Map, ss []string, generic bool) (map[t.QQID]*a.Func, error) {
|
||||
m := map[t.QQID]*a.Func{}
|
||||
buf := []byte(nil)
|
||||
opts := parse.Options{
|
||||
AllowBuiltIns: true,
|
||||
@@ -125,7 +125,7 @@ func parseBuiltInFuncs(tm *t.Map, ss []string, generic bool) (map[t.QID]*a.Func,
|
||||
return nil, fmt.Errorf("check: parsing %q: got %d top level decls, want %d", s, len(tlds), 1)
|
||||
}
|
||||
f := tlds[0].Func()
|
||||
m[f.QID()] = f
|
||||
m[f.QQID()] = f
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@@ -135,37 +135,32 @@ func (c *Checker) resolveFunc(typ *a.TypeExpr) (*a.Func, error) {
|
||||
return nil, fmt.Errorf("check: resolveFunc cannot look up non-func TypeExpr %q", typ.Str(c.tm))
|
||||
}
|
||||
lTyp := typ.Receiver()
|
||||
qid := t.QID{lTyp.Name(), typ.Name()}
|
||||
switch lTyp.Decorator().Key() {
|
||||
case 0:
|
||||
if f, err := c.builtInFunc(qid); err != nil {
|
||||
return nil, err
|
||||
} else if f != nil {
|
||||
return f, nil
|
||||
}
|
||||
if f := c.funcs[qid].Func; f != nil {
|
||||
return f, nil
|
||||
}
|
||||
|
||||
case t.KeyColon:
|
||||
lQID := lTyp.QID()
|
||||
qqid := t.QQID{lQID[0], lQID[1], typ.FuncName()}
|
||||
if lTyp.Decorator().Key() == t.KeyColon {
|
||||
// lTyp is a slice.
|
||||
qid[0] = t.IDDiamond
|
||||
if f, err := c.builtInSliceFunc(qid); err != nil {
|
||||
qqid[0] = 0
|
||||
qqid[1] = t.IDDiamond
|
||||
if f, err := c.builtInSliceFunc(qqid); err != nil {
|
||||
return nil, err
|
||||
} else if f != nil {
|
||||
return f, nil
|
||||
}
|
||||
|
||||
default:
|
||||
// lTyp is from a used package: `use "foo"` followed by `foo.bar`.
|
||||
u := c.usees[lTyp.Decorator()]
|
||||
if u == nil {
|
||||
return nil, fmt.Errorf("check: cannot resolve %q in type %q",
|
||||
lTyp.Decorator().Str(c.tm), lTyp.Str(c.tm))
|
||||
} else {
|
||||
if f, err := c.builtInFunc(qqid); err != nil {
|
||||
return nil, err
|
||||
} else if f != nil {
|
||||
return f, nil
|
||||
}
|
||||
if f := u.funcs[qid]; f != nil {
|
||||
// TODO: f.Receiver().Str(c.tm) should be "deflate.decoder", not
|
||||
// just "decoder".
|
||||
if f := c.funcs[qqid].Func; f != nil {
|
||||
return f, nil
|
||||
}
|
||||
// lTyp is from a used package: `use "foo"` followed by `foo.bar`.
|
||||
u := c.usees[qqid[0]]
|
||||
if u == nil {
|
||||
return nil, fmt.Errorf("check: cannot resolve %q in type %q", qqid[0].Str(c.tm), lTyp.Str(c.tm))
|
||||
}
|
||||
if f := u.funcs[qqid]; f != nil {
|
||||
return f, nil
|
||||
}
|
||||
}
|
||||
|
||||
+40
-32
@@ -511,7 +511,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
return fmt.Errorf("check: %s is a slice expression but %s has type %s, not an array or slice type",
|
||||
n.Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
|
||||
case t.KeyOpenBracket:
|
||||
n.SetMType(a.NewTypeExpr(t.IDColon, 0, nil, nil, lTyp.Inner()))
|
||||
n.SetMType(a.NewTypeExpr(t.IDColon, 0, 0, nil, nil, lTyp.Inner()))
|
||||
case t.KeyColon:
|
||||
n.SetMType(lTyp)
|
||||
}
|
||||
@@ -566,7 +566,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
genericType := (*a.TypeExpr)(nil)
|
||||
if f.Receiver().Key() == t.KeyDiamond {
|
||||
if f.Receiver() == (t.QID{0, t.IDDiamond}) {
|
||||
genericType = lhs.MType().Receiver()
|
||||
}
|
||||
|
||||
@@ -682,49 +682,51 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
lTyp := lhs.MType().Pointee()
|
||||
qid := t.QID{lTyp.Name(), n.ID1()}
|
||||
switch lTyp.Decorator().Key() {
|
||||
case 0:
|
||||
// No-op.
|
||||
lQID := lTyp.QID()
|
||||
qqid := t.QQID{lQID[0], lQID[1], n.ID1()}
|
||||
|
||||
case t.KeyColon:
|
||||
if key := lTyp.Decorator().Key(); key == t.KeyColon {
|
||||
// lTyp is a slice.
|
||||
qid[0] = t.IDDiamond
|
||||
if f, err := q.c.builtInSliceFunc(qid); err != nil {
|
||||
qqid[0] = 0
|
||||
qqid[1] = t.IDDiamond
|
||||
if f, err := q.c.builtInSliceFunc(qqid); err != nil {
|
||||
return err
|
||||
} else if f == nil {
|
||||
return fmt.Errorf("check: no slice method %q", n.ID1().Str(q.tm))
|
||||
}
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, n.ID1(), lTyp.Node(), nil, nil))
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.ID1(), lTyp.Node(), nil, nil))
|
||||
return nil
|
||||
} else if key != 0 {
|
||||
return fmt.Errorf("check: invalid type %q for dot-expression LHS %q", lTyp.Str(q.tm), lhs.Str(q.tm))
|
||||
}
|
||||
|
||||
default:
|
||||
if qqid[0] != 0 {
|
||||
// lTyp is from a used package: `use "foo"` followed by `foo.bar`.
|
||||
if u := q.c.usees[lTyp.Decorator()]; u == nil {
|
||||
if u := q.c.usees[qqid[0]]; u == nil {
|
||||
return fmt.Errorf("check: cannot resolve %q in type %q for expression %q",
|
||||
lTyp.Decorator().Str(q.tm), lTyp.Str(q.tm), lhs.Str(q.tm))
|
||||
} else if u.funcs[qid] == nil {
|
||||
qqid[0].Str(q.tm), lTyp.Str(q.tm), lhs.Str(q.tm))
|
||||
} else if u.funcs[qqid] == nil {
|
||||
return fmt.Errorf("check: no method named %q found in type %q for expression %q",
|
||||
n.ID1().Str(q.tm), lTyp.Str(q.tm), n.Str(q.tm))
|
||||
}
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, n.ID1(), lTyp.Node(), nil, nil))
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.ID1(), lTyp.Node(), nil, nil))
|
||||
return nil
|
||||
}
|
||||
|
||||
f, err := q.c.builtInFunc(qid)
|
||||
f, err := q.c.builtInFunc(qqid)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if f == nil {
|
||||
f = q.c.funcs[qid].Func
|
||||
f = q.c.funcs[qqid].Func
|
||||
}
|
||||
if f != nil {
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, n.ID1(), lTyp.Node(), nil, nil))
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.ID1(), lTyp.Node(), nil, nil))
|
||||
return nil
|
||||
}
|
||||
|
||||
s := (*a.Struct)(nil)
|
||||
if q.f.Func != nil {
|
||||
switch lTyp.Name().Key() {
|
||||
if q.f.Func != nil && lQID[0] == 0 {
|
||||
switch lQID[1].Key() {
|
||||
case t.KeyIn:
|
||||
s = q.f.Func.In()
|
||||
case t.KeyOut:
|
||||
@@ -732,9 +734,8 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
}
|
||||
if s == nil {
|
||||
name := lTyp.Name()
|
||||
s = q.c.structs[name].Struct
|
||||
if s == nil && builtInTypeMap[name] == nil {
|
||||
s = q.c.structs[lQID].Struct
|
||||
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))
|
||||
}
|
||||
}
|
||||
@@ -1034,8 +1035,19 @@ func (q *checker) tcheckTypeExpr(typ *a.TypeExpr, depth uint32) error {
|
||||
|
||||
swtch:
|
||||
switch typ.Decorator().Key() {
|
||||
// TODO: also check t.KeyOpenParen.
|
||||
case 0:
|
||||
if typ.Name().IsNumType() {
|
||||
qid := typ.QID()
|
||||
if qid[0] != 0 {
|
||||
if u := q.c.usees[qid[0]]; u == nil {
|
||||
return fmt.Errorf("check: cannot resolve %q in type %q", qid[0].Str(q.tm), typ.Str(q.tm))
|
||||
} else if u.structs[qid] == nil {
|
||||
return fmt.Errorf("check: cannot resolve type %q", typ.Str(q.tm))
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if qid[1].IsNumType() {
|
||||
for _, b := range typ.Bounds() {
|
||||
if b == nil {
|
||||
continue
|
||||
@@ -1052,15 +1064,15 @@ swtch:
|
||||
if typ.Min() != nil || typ.Max() != nil {
|
||||
// TODO: reject. You can only refine numeric types.
|
||||
}
|
||||
if _, ok := builtInTypeMap[typ.Name()]; ok {
|
||||
if _, ok := builtInTypeMap[qid[1]]; ok {
|
||||
break swtch
|
||||
}
|
||||
for _, s := range q.c.structs {
|
||||
if s.ID == typ.Name() {
|
||||
if s.QID == qid {
|
||||
break swtch
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("check: %q is not a type", typ.Name().Str(q.tm))
|
||||
return fmt.Errorf("check: %q is not a type", typ.Str(q.tm))
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
aLen := typ.ArrayLength()
|
||||
@@ -1079,11 +1091,7 @@ swtch:
|
||||
}
|
||||
|
||||
default:
|
||||
if u := q.c.usees[typ.Decorator()]; u == nil {
|
||||
return fmt.Errorf("check: cannot resolve %q in type %q", typ.Decorator().Str(q.tm), typ.Str(q.tm))
|
||||
} else if u.structs[typ.Name()] == nil {
|
||||
return fmt.Errorf("check: cannot resolve type %q", typ.Str(q.tm))
|
||||
}
|
||||
return fmt.Errorf("check: %q is not a type", typ.Str(q.tm))
|
||||
}
|
||||
typ.Node().SetTypeChecked()
|
||||
return nil
|
||||
|
||||
+3
-3
@@ -384,7 +384,7 @@ func (p *parser) parseTypeExpr() (*a.TypeExpr, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.NewTypeExpr(t.IDPtr, 0, nil, nil, rhs), nil
|
||||
return a.NewTypeExpr(t.IDPtr, 0, 0, nil, nil, rhs), nil
|
||||
}
|
||||
|
||||
if p.peek1().Key() == t.KeyOpenBracket {
|
||||
@@ -407,7 +407,7 @@ func (p *parser) parseTypeExpr() (*a.TypeExpr, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.NewTypeExpr(decorator, 0, lhs.Node(), nil, rhs), nil
|
||||
return a.NewTypeExpr(decorator, 0, 0, lhs.Node(), nil, rhs), nil
|
||||
}
|
||||
|
||||
pkg, name, err := p.parseQualifiedIdent()
|
||||
@@ -423,7 +423,7 @@ func (p *parser) parseTypeExpr() (*a.TypeExpr, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return a.NewTypeExpr(pkg, name, lhs.Node(), mhs, nil), nil
|
||||
return a.NewTypeExpr(0, pkg, name, lhs.Node(), mhs, nil), nil
|
||||
}
|
||||
|
||||
// parseBracket parses "[i:j]", "[i:]", "[:j]" and "[:]". A double dot replaces
|
||||
|
||||
+21
-3
@@ -99,12 +99,30 @@ func (x ID) IsXAssociativeOp() bool { return x.Key().isXOp() && x.IsAssociativeO
|
||||
// "bar"'s. QID[0] may be 0 for a plain "bar".
|
||||
type QID [2]ID
|
||||
|
||||
func (x QID) IsZero() bool { return x == QID{} }
|
||||
|
||||
// Str returns a string form of x.
|
||||
func (x QID) Str(m *Map) string {
|
||||
if x[0] == 0 {
|
||||
return m.ByID(x[1])
|
||||
if x[0] != 0 {
|
||||
return m.ByID(x[0]) + "." + m.ByID(x[1])
|
||||
}
|
||||
return m.ByID(x[0]) + "." + m.ByID(x[1])
|
||||
return m.ByID(x[1])
|
||||
}
|
||||
|
||||
// QQID is a double-qualified ID, such as "receiverPkg.receiverName.funcName".
|
||||
type QQID [3]ID
|
||||
|
||||
func (x QQID) IsZero() bool { return x == QQID{} }
|
||||
|
||||
// Str returns a string form of x.
|
||||
func (x QQID) Str(m *Map) string {
|
||||
if x[0] != 0 {
|
||||
return m.ByID(x[0]) + "." + m.ByID(x[1]) + "." + m.ByID(x[2])
|
||||
}
|
||||
if x[1] != 0 {
|
||||
return m.ByID(x[1]) + "." + m.ByID(x[2])
|
||||
}
|
||||
return m.ByID(x[2])
|
||||
}
|
||||
|
||||
// Token combines an ID and the line number it was seen.
|
||||
|
||||
Reference in new issue
Block a user