本文整理汇总了Golang中go/ast.SelectorExpr.Pos方法的典型用法代码示例。如果您正苦于以下问题:Golang SelectorExpr.Pos方法的具体用法?Golang SelectorExpr.Pos怎么用?Golang SelectorExpr.Pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.SelectorExpr
的用法示例。
在下文中一共展示了SelectorExpr.Pos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: compileSelectorStmt
// compiles a selector statement like x.sel
func (w *World) compileSelectorStmt(n *ast.SelectorExpr) Expr {
x := w.compileExpr(n.X)
t := x.Type()
if t == nil {
panic(err(n.Pos(), "void does not have member", n.Sel.Name))
}
sel := strings.ToLower(n.Sel.Name)
N := ""
for i := 0; i < t.NumMethod(); i++ {
name := t.Method(i).Name
if strings.ToLower(name) == sel && unicode.IsUpper(rune(name[0])) && !strings.HasSuffix(name, GoExclusiveMethodSuffix) {
N = t.Method(i).Name
break
}
}
if N == "" {
panic(err(n.Pos(), t, "has no method", n.Sel.Name))
}
return &selector{x, N}
}
示例2: selector
func (check *checker) selector(x *operand, e *ast.SelectorExpr) {
// these must be declared before the "goto Error" statements
var (
obj Object
index []int
indirect bool
)
sel := e.Sel.Name
// If the identifier refers to a package, handle everything here
// so we don't need a "package" mode for operands: package names
// can only appear in qualified identifiers which are mapped to
// selector expressions.
if ident, ok := e.X.(*ast.Ident); ok {
if pkg, _ := check.scope.LookupParent(ident.Name).(*PkgName); pkg != nil {
check.recordUse(ident, pkg)
pkg.used = true
exp := pkg.pkg.scope.Lookup(sel)
if exp == nil {
if !pkg.pkg.fake {
check.errorf(e.Pos(), "%s not declared by package %s", sel, ident)
}
goto Error
}
if !exp.Exported() {
check.errorf(e.Pos(), "%s not exported by package %s", sel, ident)
// ok to continue
}
check.recordSelection(e, PackageObj, nil, exp, nil, false)
// Simplified version of the code for *ast.Idents:
// - imported objects are always fully initialized
switch exp := exp.(type) {
case *Const:
assert(exp.Val() != nil)
x.mode = constant
x.typ = exp.typ
x.val = exp.val
case *TypeName:
x.mode = typexpr
x.typ = exp.typ
case *Var:
x.mode = variable
x.typ = exp.typ
case *Func:
x.mode = value
x.typ = exp.typ
case *Builtin:
x.mode = builtin
x.typ = exp.typ
x.id = exp.id
default:
unreachable()
}
x.expr = e
return
}
}
check.exprOrType(x, e.X)
if x.mode == invalid {
goto Error
}
obj, index, indirect = LookupFieldOrMethod(x.typ, check.pkg, sel)
if obj == nil {
if index != nil {
// TODO(gri) should provide actual type where the conflict happens
check.invalidOp(e.Pos(), "ambiguous selector %s", sel)
} else {
check.invalidOp(e.Pos(), "%s has no field or method %s", x, sel)
}
goto Error
}
if x.mode == typexpr {
// method expression
m, _ := obj.(*Func)
if m == nil {
check.invalidOp(e.Pos(), "%s has no method %s", x, sel)
goto Error
}
// verify that m is in the method set of x.typ
if !indirect && ptrRecv(m) {
check.invalidOp(e.Pos(), "%s is not in method set of %s", sel, x.typ)
goto Error
}
check.recordSelection(e, MethodExpr, x.typ, m, index, indirect)
// the receiver type becomes the type of the first function
// argument of the method expression's function type
var params []*Var
sig := m.typ.(*Signature)
if sig.params != nil {
params = sig.params.vars
}
x.mode = value
x.typ = &Signature{
params: NewTuple(append([]*Var{NewVar(token.NoPos, check.pkg, "", x.typ)}, params...)...),
//.........这里部分代码省略.........