本文整理汇总了Golang中go/ast.SelectorExpr类的典型用法代码示例。如果您正苦于以下问题:Golang SelectorExpr类的具体用法?Golang SelectorExpr怎么用?Golang SelectorExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SelectorExpr类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: replaceTestingTsMethodCalls
/*
* rewrite t.Fail() or any other *testing.T method by replacing with T().Fail()
* This function receives a selector expression (eg: t.Fail()) and
* the name of the *testing.T param from the function declaration. Rewrites the
* selector expression in place if the target was a *testing.T
*/
func replaceTestingTsMethodCalls(selectorExpr *ast.SelectorExpr, testingT string) {
ident, ok := selectorExpr.X.(*ast.Ident)
if !ok {
return
}
if ident.Name == testingT {
selectorExpr.X = newGinkgoTFromIdent(ident)
}
}
开发者ID:COLDTURNIP,项目名称:kubernetes,代码行数:16,代码来源:testfile_rewriter.go
示例2: 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}
}
开发者ID:kyeongdong,项目名称:3,代码行数:23,代码来源:selector.go
示例3: 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...)...),
//.........这里部分代码省略.........
开发者ID:Karthikvb,项目名称:15640_projects,代码行数:101,代码来源:call.go
注:本文中的go/ast.SelectorExpr类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论