"bufio"
"bytes"
"cmd/compile/internal/types"
+ "cmd/internal/src"
"encoding/binary"
"fmt"
"math/big"
}
p.tag(constTag)
- p.pos(n)
+ p.pos(n.Pos)
// TODO(gri) In inlined functions, constants are used directly
// so they should never occur as re-exported objects. We may
// not need the qualified name here. See also comment above.
if IsAlias(sym) {
p.tag(aliasTag)
- p.pos(n)
+ p.pos(n.Pos)
p.qualifiedName(sym)
} else {
p.tag(typeTag)
if n.Type.Etype == TFUNC && n.Class() == PFUNC {
// function
p.tag(funcTag)
- p.pos(n)
+ p.pos(n.Pos)
p.qualifiedName(sym)
sig := asNode(sym.Def).Type
} else {
// variable
p.tag(varTag)
- p.pos(n)
+ p.pos(n.Pos)
p.qualifiedName(sym)
p.typ(asNode(sym.Def).Type)
}
// -64 is the smallest int that fits in a single byte as a varint.
const deltaNewFile = -64
-func (p *exporter) pos(n *Node) {
+func (p *exporter) pos(pos src.XPos) {
if !p.posInfoFormat {
return
}
- file, line := fileLine(n)
+ file, line := fileLine(pos)
if file == p.prevFile {
// common case: write line delta
// delta == deltaNewFile means different file
}
}
-func fileLine(n *Node) (file string, line int) {
- if n != nil {
- pos := Ctxt.PosTable.Pos(n.Pos)
- file = pos.Base().AbsFilename()
- line = int(pos.RelLine())
- }
+func fileLine(pos0 src.XPos) (file string, line int) {
+ pos := Ctxt.PosTable.Pos(pos0)
+ file = pos.Base().AbsFilename()
+ line = int(pos.RelLine())
return
}
}
p.tag(namedTag)
- p.pos(n)
+ p.pos(n.Pos)
p.qualifiedName(tsym)
// write underlying type
Fatalf("invalid symbol name: %s (%v)", m.Sym.Name, m.Sym)
}
- p.pos(asNode(m.Nname))
+ p.pos(asNode(m.Nname).Pos)
p.fieldSym(m.Sym, false)
sig := m.Type
}
func (p *exporter) field(f *types.Field) {
- p.pos(asNode(f.Nname))
+ p.pos(asNode(f.Nname).Pos)
p.fieldName(f)
p.typ(f.Type)
p.string(f.Note)
if p.trace {
p.tracef("\n")
}
- p.pos(asNode(m.Nname))
+ p.pos(asNode(m.Nname).Pos)
p.typ(m.Type)
}
if p.trace && len(embeddeds) > 0 {
}
func (p *exporter) method(m *types.Field) {
- p.pos(asNode(m.Nname))
+ if m.Nname != nil {
+ p.pos(asNode(m.Nname).Pos)
+ } else {
+ p.pos(src.NoXPos)
+ }
p.methodName(m.Sym)
p.paramList(m.Type.Params(), false)
p.paramList(m.Type.Results(), false)
break
}
p.op(OLITERAL)
- p.pos(n)
+ p.pos(n.Pos)
p.typ(unidealType(n.Type, n.Val()))
p.value(n.Val())
// These nodes have the special property that they are names with a left OTYPE and a right ONAME.
if n.isMethodExpression() {
p.op(OXDOT)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left) // n.Left.Op == OTYPE
p.fieldSym(n.Right.Sym, true)
break
}
p.op(ONAME)
- p.pos(n)
+ p.pos(n.Pos)
p.sym(n)
// case OPACK, ONONAME:
case OTYPE:
p.op(OTYPE)
- p.pos(n)
+ p.pos(n.Pos)
p.typ(n.Type)
// case OTARRAY, OTMAP, OTCHAN, OTSTRUCT, OTINTER, OTFUNC:
case OPTRLIT:
p.op(OPTRLIT)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.bool(n.Implicit())
case OSTRUCTLIT:
p.op(OSTRUCTLIT)
- p.pos(n)
+ p.pos(n.Pos)
p.typ(n.Type)
p.elemList(n.List) // special handling of field names
case OARRAYLIT, OSLICELIT, OMAPLIT:
p.op(OCOMPLIT)
- p.pos(n)
+ p.pos(n.Pos)
p.typ(n.Type)
p.exprList(n.List)
case OKEY:
p.op(OKEY)
- p.pos(n)
+ p.pos(n.Pos)
p.exprsOrNil(n.Left, n.Right)
// case OSTRUCTKEY:
case OXDOT, ODOT, ODOTPTR, ODOTINTER, ODOTMETH:
p.op(OXDOT)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.fieldSym(n.Sym, true)
case ODOTTYPE, ODOTTYPE2:
p.op(ODOTTYPE)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.typ(n.Type)
case OINDEX, OINDEXMAP:
p.op(OINDEX)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.expr(n.Right)
case OSLICE, OSLICESTR, OSLICEARR:
p.op(OSLICE)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
low, high, _ := n.SliceBounds()
p.exprsOrNil(low, high)
case OSLICE3, OSLICE3ARR:
p.op(OSLICE3)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
low, high, max := n.SliceBounds()
p.exprsOrNil(low, high)
case OCOPY, OCOMPLEX:
// treated like other builtin calls (see e.g., OREAL)
p.op(op)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.expr(n.Right)
p.op(OEND)
case OCONV, OCONVIFACE, OCONVNOP, OARRAYBYTESTR, OARRAYRUNESTR, OSTRARRAYBYTE, OSTRARRAYRUNE, ORUNESTR:
p.op(OCONV)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.typ(n.Type)
case OREAL, OIMAG, OAPPEND, OCAP, OCLOSE, ODELETE, OLEN, OMAKE, ONEW, OPANIC, ORECOVER, OPRINT, OPRINTN:
p.op(op)
- p.pos(n)
+ p.pos(n.Pos)
if n.Left != nil {
p.expr(n.Left)
p.op(OEND)
case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER, OGETG:
p.op(OCALL)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.exprList(n.List)
p.bool(n.Isddd())
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
p.op(op) // must keep separate from OMAKE for importer
- p.pos(n)
+ p.pos(n.Pos)
p.typ(n.Type)
switch {
default:
// unary expressions
case OPLUS, OMINUS, OADDR, OCOM, OIND, ONOT, ORECV:
p.op(op)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
// binary expressions
case OADD, OAND, OANDAND, OANDNOT, ODIV, OEQ, OGE, OGT, OLE, OLT,
OLSH, OMOD, OMUL, ONE, OOR, OOROR, ORSH, OSEND, OSUB, OXOR:
p.op(op)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.expr(n.Right)
case OADDSTR:
p.op(OADDSTR)
- p.pos(n)
+ p.pos(n.Pos)
p.exprList(n.List)
case OCMPSTR, OCMPIFACE:
p.op(n.SubOp())
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.expr(n.Right)
// TODO(gri) these should not be exported in the first place
// TODO(gri) why is this considered an expression in fmt.go?
p.op(ODCLCONST)
- p.pos(n)
+ p.pos(n.Pos)
default:
Fatalf("cannot export %v (%d) node\n"+
switch op := n.Op; op {
case ODCL:
p.op(ODCL)
- p.pos(n.Left) // use declared variable's pos
+ p.pos(n.Left.Pos) // use declared variable's pos
p.sym(n.Left)
p.typ(n.Left.Type)
// the "v = <N>" again.
if n.Right != nil {
p.op(OAS)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
p.expr(n.Right)
}
case OASOP:
p.op(OASOP)
- p.pos(n)
+ p.pos(n.Pos)
p.op(n.SubOp())
p.expr(n.Left)
if p.bool(!n.Implicit()) {
case OAS2, OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
p.op(OAS2)
- p.pos(n)
+ p.pos(n.Pos)
p.exprList(n.List)
p.exprList(n.Rlist)
case ORETURN:
p.op(ORETURN)
- p.pos(n)
+ p.pos(n.Pos)
p.exprList(n.List)
// case ORETJMP:
case OPROC, ODEFER:
p.op(op)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
case OIF:
p.op(OIF)
- p.pos(n)
+ p.pos(n.Pos)
p.stmtList(n.Ninit)
p.expr(n.Left)
p.stmtList(n.Nbody)
case OFOR:
p.op(OFOR)
- p.pos(n)
+ p.pos(n.Pos)
p.stmtList(n.Ninit)
p.exprsOrNil(n.Left, n.Right)
p.stmtList(n.Nbody)
case ORANGE:
p.op(ORANGE)
- p.pos(n)
+ p.pos(n.Pos)
p.stmtList(n.List)
p.expr(n.Right)
p.stmtList(n.Nbody)
case OSELECT, OSWITCH:
p.op(op)
- p.pos(n)
+ p.pos(n.Pos)
p.stmtList(n.Ninit)
p.exprsOrNil(n.Left, nil)
p.stmtList(n.List)
case OCASE, OXCASE:
p.op(OXCASE)
- p.pos(n)
+ p.pos(n.Pos)
p.stmtList(n.List)
p.stmtList(n.Nbody)
case OFALL:
p.op(OFALL)
- p.pos(n)
+ p.pos(n.Pos)
case OBREAK, OCONTINUE:
p.op(op)
- p.pos(n)
+ p.pos(n.Pos)
p.exprsOrNil(n.Left, nil)
case OEMPTY:
case OGOTO, OLABEL:
p.op(op)
- p.pos(n)
+ p.pos(n.Pos)
p.expr(n.Left)
default: