(f *function, name string, base bool)
| 1024 | } |
| 1025 | |
| 1026 | func singleVariableHelper(f *function, name string, base bool) (e exprDesc, found bool) { |
| 1027 | owningBlock := func(b *block, level int) *block { |
| 1028 | for b.activeVariableCount > level { |
| 1029 | b = b.previous |
| 1030 | } |
| 1031 | return b |
| 1032 | } |
| 1033 | find := func() (int, bool) { |
| 1034 | for i := f.activeVariableCount - 1; i >= 0; i-- { |
| 1035 | if name == f.LocalVariable(i).name { |
| 1036 | return i, true |
| 1037 | } |
| 1038 | } |
| 1039 | return 0, false |
| 1040 | } |
| 1041 | findUpValue := func() (int, bool) { |
| 1042 | for i, u := range f.f.upValues { |
| 1043 | if u.name == name { |
| 1044 | return i, true |
| 1045 | } |
| 1046 | } |
| 1047 | return 0, false |
| 1048 | } |
| 1049 | if f == nil { |
| 1050 | return |
| 1051 | } |
| 1052 | var v int |
| 1053 | if v, found = find(); found { |
| 1054 | if e = makeExpression(kindLocal, v); !base { |
| 1055 | owningBlock(f.block, v).hasUpValue = true |
| 1056 | } |
| 1057 | return |
| 1058 | } |
| 1059 | if v, found = findUpValue(); found { |
| 1060 | return makeExpression(kindUpValue, v), true |
| 1061 | } |
| 1062 | if e, found = singleVariableHelper(f.previous, name, false); !found { |
| 1063 | return |
| 1064 | } |
| 1065 | return makeExpression(kindUpValue, f.makeUpValue(name, e)), true |
| 1066 | } |
| 1067 | |
| 1068 | func (f *function) SingleVariable(name string) (e exprDesc) { |
| 1069 | var found bool |
no test coverage detected