本文整理汇总了Golang中go/ast.StarExpr.Elt方法的典型用法代码示例。如果您正苦于以下问题:Golang StarExpr.Elt方法的具体用法?Golang StarExpr.Elt怎么用?Golang StarExpr.Elt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.StarExpr
的用法示例。
在下文中一共展示了StarExpr.Elt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: infer_type
// RETURNS:
// - type expression which represents a full name of a type
// - bool whether a type expression is actually a type (used internally)
// - scope in which type makes sense
func infer_type(v ast.Expr, scope *scope, index int) (ast.Expr, *scope, bool) {
switch t := v.(type) {
case *ast.CompositeLit:
return t.Type, scope, true
case *ast.Ident:
if d := scope.lookup(t.Name); d != nil {
if d.class == decl_package {
return ast.NewIdent(t.Name), scope, false
}
typ, scope := d.infer_type()
return typ, scope, d.class == decl_type
}
case *ast.UnaryExpr:
switch t.Op {
case token.AND:
// &a makes sense only with values, don't even check for type
it, s, _ := infer_type(t.X, scope, -1)
if it == nil {
break
}
e := new(ast.StarExpr)
e.X = it
return e, s, false
case token.ARROW:
// <-a makes sense only with values
it, s, _ := infer_type(t.X, scope, -1)
if it == nil {
break
}
switch index {
case -1, 0:
it, s = advance_to_type(chan_predicate, it, s)
return it.(*ast.ChanType).Value, s, false
case 1:
// technically it's a value, but in case of index == 1
// it is always the last infer operation
return ast.NewIdent("bool"), g_universe_scope, false
}
case token.ADD, token.NOT, token.SUB, token.XOR:
it, s, _ := infer_type(t.X, scope, -1)
if it == nil {
break
}
return it, s, false
}
case *ast.BinaryExpr:
switch t.Op {
case token.EQL, token.NEQ, token.LSS, token.LEQ,
token.GTR, token.GEQ, token.LOR, token.LAND:
// logic operations, the result is a bool, always
return ast.NewIdent("bool"), g_universe_scope, false
case token.ADD, token.SUB, token.MUL, token.QUO, token.OR,
token.XOR, token.REM, token.AND, token.AND_NOT:
// try X, then Y, they should be the same anyway
it, s, _ := infer_type(t.X, scope, -1)
if it == nil {
it, s, _ = infer_type(t.Y, scope, -1)
if it == nil {
break
}
}
return it, s, false
case token.SHL, token.SHR:
// try only X for shifts, Y is always uint
it, s, _ := infer_type(t.X, scope, -1)
if it == nil {
break
}
return it, s, false
}
case *ast.IndexExpr:
// something[another] always returns a value and it works on a value too
it, s, _ := infer_type(t.X, scope, -1)
if it == nil {
break
}
it, s = advance_to_type(index_predicate, it, s)
switch t := it.(type) {
case *ast.ArrayType:
return t.Elt, s, false
case *ast.Ellipsis:
return t.Elt, s, false
case *ast.MapType:
switch index {
case -1, 0:
return t.Value, s, false
case 1:
return ast.NewIdent("bool"), g_universe_scope, false
}
}
case *ast.SliceExpr:
// something[start : end] always returns a value
it, s, _ := infer_type(t.X, scope, -1)
if it == nil {
break
//.........这里部分代码省略.........