Commit e37f81b4 authored by Russ Cox's avatar Russ Cox

template: use new reflect interface (CL 31107)

R=r
DELTA=16  (3 added, 1 deleted, 12 changed)
OCL=31121
CL=31288
parent f1bc7120
...@@ -569,12 +569,12 @@ func (st *state) findVar(s string) reflect.Value { ...@@ -569,12 +569,12 @@ func (st *state) findVar(s string) reflect.Value {
return st.data return st.data
} }
data := reflect.Indirect(st.data); data := reflect.Indirect(st.data);
typ, ok := data.Type().(reflect.StructType); typ, ok := data.Type().(*reflect.StructType);
if ok { if ok {
for i := 0; i < typ.Len(); i++ { for i := 0; i < typ.NumField(); i++ {
name, ftyp, tag, offset := typ.Field(i); f := typ.Field(i);
if name == s { if f.Name == s {
return data.(reflect.StructValue).Field(i) return data.(*reflect.StructValue).Field(i)
} }
} }
} }
...@@ -587,13 +587,15 @@ func empty(v reflect.Value, indirect_ok bool) bool { ...@@ -587,13 +587,15 @@ func empty(v reflect.Value, indirect_ok bool) bool {
if v == nil { if v == nil {
return true return true
} }
switch v.Type().Kind() { switch v := v.(type) {
case reflect.StringKind: case *reflect.StringValue:
return v.(reflect.StringValue).Get() == ""; return v.Get() == "";
case reflect.StructKind: case *reflect.StructValue:
return false; return false;
case reflect.ArrayKind: case *reflect.ArrayValue:
return v.(reflect.ArrayValue).Len() == 0; return v.Len() == 0;
case *reflect.SliceValue:
return v.Len() == 0;
} }
return true; return true;
} }
...@@ -701,7 +703,8 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) { ...@@ -701,7 +703,8 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) {
field = reflect.Indirect(field); field = reflect.Indirect(field);
// Must be an array/slice // Must be an array/slice
if field != nil && field.Kind() != reflect.ArrayKind { array, ok := field.(reflect.ArrayOrSliceValue);
if !ok {
t.execError(st, r.linenum, ".repeated: %s has bad type %s", r.field, field.Type()); t.execError(st, r.linenum, ".repeated: %s has bad type %s", r.field, field.Type());
} }
if empty(field, true) { if empty(field, true) {
...@@ -724,7 +727,6 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) { ...@@ -724,7 +727,6 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) {
end = r.altstart end = r.altstart
} }
if field != nil { if field != nil {
array := field.(reflect.ArrayValue);
for j := 0; j < array.Len(); j++ { for j := 0; j < array.Len(); j++ {
newst := st.clone(array.Elem(j)); newst := st.clone(array.Elem(j));
for i := start; i < end; { for i := start; i < end; {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment