Beispiel #1
0
func (vis *pointerTransformVisitor) makeNewNode(i *ast.Ident, depth int) ast.Expr {
	d := depth
	i.NamePos += token.Pos(d)
	switch {
	case depth > 0:
		res := &ast.UnaryExpr{i.NamePos - token.Pos(depth), token.AND, nil}
		e := res
		for depth > 1 {
			e.X = &ast.UnaryExpr{i.NamePos - token.Pos(depth), token.AND, nil}
			e = e.X.(*ast.UnaryExpr)
			depth--
		}
		e.X = i
		return res
	case depth < 0:
		res := &ast.StarExpr{i.NamePos - token.Pos(depth), nil}
		e := res
		for depth < -1 {
			e.X = &ast.StarExpr{i.NamePos - token.Pos(depth), nil}
			e = e.X.(*ast.StarExpr)
			depth++
		}
		e.X = i
		return res
	}
	return i
}