case _Name:
d.LocalPkgName = p.name()
case _Dot:
- d.LocalPkgName = p.newName(".")
+ d.LocalPkgName = NewName(p.pos(), ".")
p.next()
}
d.Path = p.oliteral()
case _Type:
if p.mode&AllowGenerics != 0 {
// TODO(gri) factor this better
- type_ := new(Name)
- type_.pos = p.pos()
- type_.Value = "type" // cannot have a method named "type"
+ type_ := NewName(p.pos(), "type") // cannot have a method named "type"
p.next()
if p.tok != _Semi && p.tok != _Rbrace {
f := new(Field)
typ = par.Type
if par.Name == nil {
pos = typ.Pos()
- n := p.newName("_")
- n.pos = pos // correct position
- par.Name = n
+ par.Name = NewName(pos, "_")
}
} else if typ != nil {
par.Type = typ
// ----------------------------------------------------------------------------
// Common productions
-func (p *parser) newName(value string) *Name {
- n := new(Name)
- n.pos = p.pos()
- n.Value = value
- return n
-}
-
func (p *parser) name() *Name {
// no tracing to avoid overly verbose output
if p.tok == _Name {
- n := p.newName(p.lit)
+ n := NewName(p.pos(), p.lit)
p.next()
return n
}
- n := p.newName("_")
+ n := NewName(p.pos(), "_")
p.syntaxError("expecting name")
p.advance()
return n
case p.tok == _Name:
x = p.name()
default:
- x = p.newName("_")
+ x = NewName(p.pos(), "_")
p.syntaxError("expecting name")
p.advance(_Dot, _Semi, _Rbrace)
}
check.errorf(arg, "receiver type parameter %s must be an identifier", arg)
}
if par == nil {
- par = newName(arg.Pos(), "_")
+ par = syntax.NewName(arg.Pos(), "_")
}
tparams = append(tparams, par)
}
}
}
-func newName(pos syntax.Pos, value string) *syntax.Name {
- n := new(syntax.Name)
- // TODO(gri) why does this not work?
- //n.pos = pos
- n.Value = value
- return n
-}
-
func (check *Checker) switchStmt(inner stmtContext, s *syntax.SwitchStmt) {
// init statement already handled
if len(s.Body) > 0 {
pos = s.Body[0].Pos()
}
- x.expr = newName(pos, "true")
+ x.expr = syntax.NewName(pos, "true")
}
check.multipleSwitchDefaults(s.Body)