本文整理匯總了Golang中subc/compile/arch.LV.Storage方法的典型用法代碼示例。如果您正苦於以下問題:Golang LV.Storage方法的具體用法?Golang LV.Storage怎麽用?Golang LV.Storage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類subc/compile/arch.LV
的用法示例。
在下文中一共展示了LV.Storage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ident
// ident generates code for an identifier by loading it into the accumulator.
func (c *compiler) ident(e *ast.Ident, lv *arch.LV, tv types.TypeAndValue) *node {
lv.Ident = true
lv.Type = tv.Type.Underlying()
lv.Name = e.Name
_, isFunc := tv.Type.(*types.Signature)
if isFunc {
if x, ok := c.Uses[e]; ok {
switch x := x.(type) {
case *types.Func:
lv.Storage = x.Storage()
return newNode(opAddr, lv, nil, nil, nil)
case *types.Fwrd:
return newNode(opAddr, lv, nil, nil, nil)
}
}
}
v, found := c.variable(e, c.Uses)
if !found {
lv.Ident = false
return nil
}
s, found := c.symbol(v)
if !found {
lv.Ident = false
return nil
}
_, isRecord := lv.Type.(*types.Record)
// arrays decay to pointers, so we need to get the original type
// because the type and value by the typechecker is recorded as a pointer
array, isArray := v.Type().(*types.Array)
lv.Addr = s.Addr
lv.Value = s.Value
lv.Storage = v.Storage()
switch {
// constants
case tv.Value != nil:
lv.Value = tv.Value
return newNode(opLit, lv, nil, nil, nil)
case isArray:
lv.Type = types.NewPointer(array.Elem(), nil)
return newNode(opAddr, lv, nil, nil, nil)
case isRecord:
lv.Ident = false
return newNode(opAddr, lv, nil, nil, nil)
// variable that a integer or a pointer
default:
lv.Addressable = true
return newNode(opIdent, lv, nil, nil, nil)
}
}