@@ -28,10 +28,11 @@ func parsePIC(_ *Tree, l line, _ *Record) *Record {
2828 }
2929
3030 return & Record {
31- Name : l .items [4 ].val ,
32- Length : length ,
33- depth : l .items [2 ].val ,
34- Typ : parsePICType (picNumDef ),
31+ depthMap : map [string ]* Record {},
32+ Name : l .items [4 ].val ,
33+ Length : length ,
34+ depth : l .items [2 ].val ,
35+ Typ : parsePICType (picNumDef ),
3536 }
3637}
3738
@@ -48,9 +49,10 @@ func parseRedefines(_ *Tree, l line, root *Record) *Record {
4849 }
4950
5051 r := & Record {
51- Name : l .items [4 ].val ,
52- Length : length ,
53- Typ : parsePICType (picNumDef ),
52+ depthMap : map [string ]* Record {},
53+ Name : l .items [4 ].val ,
54+ Length : length ,
55+ Typ : parsePICType (picNumDef ),
5456 }
5557
5658 target := l .items [8 ].val
@@ -75,7 +77,7 @@ func parseGroupRedefines(t *Tree, l line, root *Record) *Record {
7577 log .Fatalln (fmt .Sprintf ("redefinition target %s does not exist" , target ))
7678 }
7779
78- if dst .depthMap == nil {
80+ if dst .depthMap == nil || len ( dst . depthMap ) == 0 {
7981 // then check whether a node has children at this depth
8082 parent , seenGroup := root .depthMap [dst .depth ]
8183 if seenGroup {
@@ -116,11 +118,12 @@ func parseOccurs(_ *Tree, l line, _ *Record) *Record {
116118 }
117119
118120 return & Record {
119- Name : l .items [4 ].val ,
120- Length : length ,
121- Occurs : n ,
122- depth : l .items [2 ].val ,
123- Typ : parsePICType (picNumDef ),
121+ Name : l .items [4 ].val ,
122+ Length : length ,
123+ Occurs : n ,
124+ depth : l .items [2 ].val ,
125+ depthMap : map [string ]* Record {},
126+ Typ : parsePICType (picNumDef ),
124127 }
125128}
126129
@@ -212,20 +215,24 @@ func parseNonNumDelimitedStruct(t *Tree, l line, root *Record) *Record {
212215// | |-picA
213216// |-group2
214217// | |-picA
215- func parseStruct (t * Tree , l line , root * Record , nameIdx , groupIdx int ) * Record {
218+ func parseStruct (_ * Tree , l line , _ * Record , nameIdx , groupIdx int ) * Record {
216219 newNode := & Record {
217- Name : l .items [nameIdx ].val ,
218- Typ : reflect .Struct ,
219- depth : l .items [groupIdx ].val ,
220+ Name : l .items [nameIdx ].val ,
221+ Typ : reflect .Struct ,
222+ depth : l .items [groupIdx ].val ,
223+ depthMap : map [string ]* Record {},
220224 }
221225
222- return delve ( t , root , newNode )
226+ return newNode
223227}
224228
225229func delve (t * Tree , root * Record , newRecord * Record ) * Record {
226230 parent , seenGroup := root .depthMap [newRecord .depth ]
227231 if seenGroup {
228232 parent .Children = append (parent .Children , newRecord )
233+ if newRecord .depthMap == nil || len (newRecord .depthMap ) == 0 {
234+ copyDepthMap (parent , newRecord )
235+ }
229236 t .parseLines (newRecord )
230237 l := newRecord .Length
231238 if newRecord .Occurs > 0 {
@@ -237,7 +244,7 @@ func delve(t *Tree, root *Record, newRecord *Record) *Record {
237244 return parent
238245 }
239246
240- if root .depthMap == nil {
247+ if root .depthMap == nil || len ( root . depthMap ) == 0 {
241248 root .depthMap = make (map [string ]* Record )
242249 }
243250
@@ -258,7 +265,7 @@ func delve(t *Tree, root *Record, newRecord *Record) *Record {
258265}
259266
260267func copyDepthMap (src , dst * Record ) {
261- if dst .depthMap == nil {
268+ if dst .depthMap == nil || len ( dst . depthMap ) == 0 {
262269 dst .depthMap = make (map [string ]* Record )
263270 }
264271
0 commit comments