@@ -133,7 +133,7 @@ func fmtNode(n Node, s fmt.State, verb rune) {
133
133
// %+v prints Dump.
134
134
// Otherwise we print Go syntax.
135
135
if s .Flag ('+' ) && verb == 'v' {
136
- dumpNode (s , n , 1 )
136
+ dumpNode (s , n , 1 , nil )
137
137
return
138
138
}
139
139
@@ -872,7 +872,7 @@ func ellipsisIf(b bool) string {
872
872
func (l Nodes ) Format (s fmt.State , verb rune ) {
873
873
if s .Flag ('+' ) && verb == 'v' {
874
874
// %+v is DumpList output
875
- dumpNodes (s , l , 1 )
875
+ dumpNodes (s , l , 1 , nil )
876
876
return
877
877
}
878
878
@@ -904,20 +904,23 @@ func Dump(s string, n Node) {
904
904
// DumpList prints the message s followed by a debug dump of each node in the list.
905
905
func DumpList (s string , list Nodes ) {
906
906
var buf bytes.Buffer
907
- FDumpList (& buf , s , list )
907
+ FDumpList (& buf , s , list , nil )
908
908
os .Stdout .Write (buf .Bytes ())
909
909
}
910
910
911
911
// FDumpList prints to w the message s followed by a debug dump of each node in the list.
912
- func FDumpList (w io.Writer , s string , list Nodes ) {
912
+ func FDumpList (w io.Writer , s string , list Nodes , f * Func ) {
913
913
io .WriteString (w , s )
914
- dumpNodes (w , list , 1 )
914
+ dumpNodes (w , list , 1 , f )
915
915
io .WriteString (w , "\n " )
916
916
}
917
917
918
918
// indent prints indentation to w.
919
- func indent (w io.Writer , depth int ) {
919
+ func indent (w io.Writer , depth int , counter int64 ) {
920
920
fmt .Fprint (w , "\n " )
921
+ if base .Flag .PgoBbProfile {
922
+ fmt .Fprintf (w , "%d " , counter )
923
+ }
921
924
for i := 0 ; i < depth ; i ++ {
922
925
fmt .Fprint (w , ". " )
923
926
}
@@ -1048,8 +1051,8 @@ func dumpNodeHeader(w io.Writer, n Node) {
1048
1051
}
1049
1052
}
1050
1053
1051
- func dumpNode (w io.Writer , n Node , depth int ) {
1052
- indent (w , depth )
1054
+ func dumpNode (w io.Writer , n Node , depth int , f * Func ) {
1055
+ indent (w , depth , GetCounter ( f , n ) )
1053
1056
if depth > 40 {
1054
1057
fmt .Fprint (w , "..." )
1055
1058
return
@@ -1062,8 +1065,8 @@ func dumpNode(w io.Writer, n Node, depth int) {
1062
1065
1063
1066
if len (n .Init ()) != 0 {
1064
1067
fmt .Fprintf (w , "%+v-init" , n .Op ())
1065
- dumpNodes (w , n .Init (), depth + 1 )
1066
- indent (w , depth )
1068
+ dumpNodes (w , n .Init (), depth + 1 , f )
1069
+ indent (w , depth , GetCounter ( f , n ) )
1067
1070
}
1068
1071
1069
1072
switch n .Op () {
@@ -1116,23 +1119,23 @@ func dumpNode(w io.Writer, n Node, depth int) {
1116
1119
dumpNodeHeader (w , n )
1117
1120
fn := n
1118
1121
if len (fn .Dcl ) > 0 {
1119
- indent (w , depth )
1122
+ indent (w , depth , GetCounter ( f , n ) )
1120
1123
fmt .Fprintf (w , "%+v-Dcl" , n .Op ())
1121
1124
for _ , dcl := range n .Dcl {
1122
- dumpNode (w , dcl , depth + 1 )
1125
+ dumpNode (w , dcl , depth + 1 , f )
1123
1126
}
1124
1127
}
1125
1128
if len (fn .ClosureVars ) > 0 {
1126
- indent (w , depth )
1129
+ indent (w , depth , GetCounter ( f , n ) )
1127
1130
fmt .Fprintf (w , "%+v-ClosureVars" , n .Op ())
1128
1131
for _ , cv := range fn .ClosureVars {
1129
- dumpNode (w , cv , depth + 1 )
1132
+ dumpNode (w , cv , depth + 1 , f )
1130
1133
}
1131
1134
}
1132
1135
if len (fn .Body ) > 0 {
1133
- indent (w , depth )
1136
+ indent (w , depth , GetCounter ( f , n ) )
1134
1137
fmt .Fprintf (w , "%+v-body" , n .Op ())
1135
- dumpNodes (w , fn .Body , depth + 1 )
1138
+ dumpNodes (w , fn .Body , depth + 1 , f )
1136
1139
}
1137
1140
return
1138
1141
}
@@ -1164,30 +1167,34 @@ func dumpNode(w io.Writer, n Node, depth int) {
1164
1167
switch val := vf .Interface ().(type ) {
1165
1168
case Node :
1166
1169
if name != "" {
1167
- indent (w , depth )
1170
+ indent (w , depth , GetCounter ( f , n ) )
1168
1171
fmt .Fprintf (w , "%+v-%s" , n .Op (), name )
1169
1172
}
1170
- dumpNode (w , val , depth + 1 )
1173
+ dumpNode (w , val , depth + 1 , f )
1171
1174
case Nodes :
1172
1175
if len (val ) == 0 {
1173
1176
continue
1174
1177
}
1175
1178
if name != "" {
1176
- indent (w , depth )
1179
+ c := GetCounter (f , n )
1180
+ if len (val ) > 0 {
1181
+ c = GetCounter (f , val [0 ])
1182
+ }
1183
+ indent (w , depth , c )
1177
1184
fmt .Fprintf (w , "%+v-%s" , n .Op (), name )
1178
1185
}
1179
- dumpNodes (w , val , depth + 1 )
1186
+ dumpNodes (w , val , depth + 1 , f )
1180
1187
default :
1181
1188
if vf .Kind () == reflect .Slice && vf .Type ().Elem ().Implements (nodeType ) {
1182
1189
if vf .Len () == 0 {
1183
1190
continue
1184
1191
}
1185
1192
if name != "" {
1186
- indent (w , depth )
1193
+ indent (w , depth , GetCounter ( f , n ) )
1187
1194
fmt .Fprintf (w , "%+v-%s" , n .Op (), name )
1188
1195
}
1189
1196
for i , n := 0 , vf .Len (); i < n ; i ++ {
1190
- dumpNode (w , vf .Index (i ).Interface ().(Node ), depth + 1 )
1197
+ dumpNode (w , vf .Index (i ).Interface ().(Node ), depth + 1 , f )
1191
1198
}
1192
1199
}
1193
1200
}
@@ -1196,13 +1203,13 @@ func dumpNode(w io.Writer, n Node, depth int) {
1196
1203
1197
1204
var nodeType = reflect .TypeOf ((* Node )(nil )).Elem ()
1198
1205
1199
- func dumpNodes (w io.Writer , list Nodes , depth int ) {
1206
+ func dumpNodes (w io.Writer , list Nodes , depth int , f * Func ) {
1200
1207
if len (list ) == 0 {
1201
1208
fmt .Fprintf (w , " <nil>" )
1202
1209
return
1203
1210
}
1204
1211
1205
1212
for _ , n := range list {
1206
- dumpNode (w , n , depth )
1213
+ dumpNode (w , n , depth , f )
1207
1214
}
1208
1215
}
0 commit comments