| 1247 | } |
| 1248 | |
| 1249 | func (a *application) applyList(parent ast.Node, name string) { |
| 1250 | // avoid heap-allocating a new iterator for each applyList call; reuse a.iter instead |
| 1251 | saved := a.iter |
| 1252 | a.iter.index = 0 |
| 1253 | for { |
| 1254 | // must reload parent.name each time, since cursor modifications might change it |
| 1255 | v := reflect.Indirect(reflect.ValueOf(parent)).FieldByName(name) |
| 1256 | if a.iter.index >= v.Len() { |
| 1257 | break |
| 1258 | } |
| 1259 | |
| 1260 | // element x may be nil in a bad AST - be cautious |
| 1261 | var x ast.Node |
| 1262 | if e := v.Index(a.iter.index); e.IsValid() { |
| 1263 | x = e.Interface().(ast.Node) |
| 1264 | } |
| 1265 | |
| 1266 | a.iter.step = 1 |
| 1267 | a.apply(parent, name, &a.iter, x) |
| 1268 | a.iter.index += a.iter.step |
| 1269 | } |
| 1270 | a.iter = saved |
| 1271 | } |