@@ -210,6 +210,77 @@ func (mod *Model) Check() error {
210210 return nil
211211}
212212
213+ // p_add adds a root recursively according to ty.
214+ //
215+ // add is responsible for setting the size, parent, class, attrs, and root
216+ // of all added nodes.
217+ //
218+ func (mod * Model ) p_add (ty types.Type , class Class , attrs Attrs , sk SrcKind , pos token.Pos , p , r Loc , sum * int ) Loc {
219+ n := Loc (uint32 (len (mod .locs )))
220+ l := loc {
221+ parent : p ,
222+ root : r ,
223+ class : class ,
224+ attrs : attrs }
225+ lastSum := * sum
226+ switch ty := ty .(type ) {
227+ case * types.Signature :
228+ // a virtual place for the func
229+ mod .locs = append (mod .locs , l )
230+ * sum ++
231+
232+ case * types.Basic , * types.Pointer , * types.Interface :
233+ mod .locs = append (mod .locs , l )
234+ * sum ++
235+ case * types.Array :
236+ mod .locs = append (mod .locs , l )
237+ * sum ++
238+ m := int (ty .Len ())
239+ for i := 0 ; i < m ; i ++ {
240+ mod .add (ty .Elem (), class , attrs , sk , pos , n , r , sum )
241+ }
242+ case * types.Map :
243+ mod .locs = append (mod .locs , l )
244+ * sum ++
245+ mod .add (ty .Key (), class , attrs , sk , pos , n , r , sum )
246+ mod .add (ty .Elem (), class , attrs , sk , pos , n , r , sum )
247+ case * types.Struct :
248+ mod .locs = append (mod .locs , l )
249+ * sum ++
250+ nf := ty .NumFields ()
251+ for i := 0 ; i < nf ; i ++ {
252+ fty := ty .Field (i ).Type ()
253+ mod .add (fty , class , attrs , sk , pos , n , r , sum )
254+ }
255+ case * types.Slice :
256+ mod .locs = append (mod .locs , l )
257+ * sum ++
258+ mod .add (ty .Elem (), class , attrs , sk , pos , n , r , sum )
259+ case * types.Chan :
260+ mod .locs = append (mod .locs , l )
261+ * sum ++
262+ mod .add (ty .Elem (), class , attrs , sk , pos , n , r , sum )
263+
264+ case * types.Tuple :
265+ mod .locs = append (mod .locs , l )
266+ * sum ++
267+ tn := ty .Len ()
268+ for i := 0 ; i < tn ; i ++ {
269+ mod .add (ty .At (i ).Type (), class , attrs , sk , pos , n , r , sum )
270+ }
271+ case * types.Named :
272+ // no space reserved for named types, go to
273+ // underlying
274+ return mod .add (ty .Underlying (), class , attrs , sk , pos , p , r , sum )
275+
276+ default :
277+ panic (fmt .Sprintf ("%s: unexpected/unimplemented" , ty ))
278+ }
279+ // we added a slot at dst[n] for ty, set it
280+ mod .locs [n ].lsz = mod .indexing .FromInt (* sum - lastSum )
281+ return n
282+ }
283+
213284// add adds a root recursively according to ty.
214285//
215286// add is responsible for setting the size, parent, class, attrs, and root
0 commit comments