@@ -936,7 +936,16 @@ func emitScopeNodeInfo(tw *trap.Writer, nd ast.Node, lbl trap.Label) {
936
936
937
937
// extractExpr extracts AST information for the given expression and all its subexpressions
938
938
func extractExpr (tw * trap.Writer , expr ast.Expr , parent trap.Label , idx int , skipExtractingValue bool ) {
939
- if expr == nil {
939
+ if expr == nil || expr == (* ast .Ident )(nil ) || expr == (* ast .BasicLit )(nil ) ||
940
+ expr == (* ast .Ellipsis )(nil ) || expr == (* ast .FuncLit )(nil ) ||
941
+ expr == (* ast .CompositeLit )(nil ) || expr == (* ast .SelectorExpr )(nil ) ||
942
+ expr == (* ast .IndexListExpr )(nil ) || expr == (* ast .SliceExpr )(nil ) ||
943
+ expr == (* ast .TypeAssertExpr )(nil ) || expr == (* ast .CallExpr )(nil ) ||
944
+ expr == (* ast .StarExpr )(nil ) || expr == (* ast .KeyValueExpr )(nil ) ||
945
+ expr == (* ast .UnaryExpr )(nil ) || expr == (* ast .BinaryExpr )(nil ) ||
946
+ expr == (* ast .ArrayType )(nil ) || expr == (* ast .StructType )(nil ) ||
947
+ expr == (* ast .FuncType )(nil ) || expr == (* ast .InterfaceType )(nil ) ||
948
+ expr == (* ast .MapType )(nil ) || expr == (* ast .ChanType )(nil ) {
940
949
return
941
950
}
942
951
@@ -948,9 +957,6 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
948
957
case * ast.BadExpr :
949
958
kind = dbscheme .BadExpr .Index ()
950
959
case * ast.Ident :
951
- if expr == nil {
952
- return
953
- }
954
960
kind = dbscheme .IdentExpr .Index ()
955
961
dbscheme .LiteralsTable .Emit (tw , lbl , expr .Name , expr .Name )
956
962
def := tw .Package .TypesInfo .Defs [expr ]
@@ -984,15 +990,9 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
984
990
}
985
991
}
986
992
case * ast.Ellipsis :
987
- if expr == nil {
988
- return
989
- }
990
993
kind = dbscheme .EllipsisExpr .Index ()
991
994
extractExpr (tw , expr .Elt , lbl , 0 , false )
992
995
case * ast.BasicLit :
993
- if expr == nil {
994
- return
995
- }
996
996
value := ""
997
997
switch expr .Kind {
998
998
case token .INT :
@@ -1016,36 +1016,21 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
1016
1016
}
1017
1017
dbscheme .LiteralsTable .Emit (tw , lbl , value , expr .Value )
1018
1018
case * ast.FuncLit :
1019
- if expr == nil {
1020
- return
1021
- }
1022
1019
kind = dbscheme .FuncLitExpr .Index ()
1023
1020
extractExpr (tw , expr .Type , lbl , 0 , false )
1024
1021
extractStmt (tw , expr .Body , lbl , 1 )
1025
1022
case * ast.CompositeLit :
1026
- if expr == nil {
1027
- return
1028
- }
1029
1023
kind = dbscheme .CompositeLitExpr .Index ()
1030
1024
extractExpr (tw , expr .Type , lbl , 0 , false )
1031
1025
extractExprs (tw , expr .Elts , lbl , 1 , 1 )
1032
1026
case * ast.ParenExpr :
1033
- if expr == nil {
1034
- return
1035
- }
1036
1027
kind = dbscheme .ParenExpr .Index ()
1037
1028
extractExpr (tw , expr .X , lbl , 0 , false )
1038
1029
case * ast.SelectorExpr :
1039
- if expr == nil {
1040
- return
1041
- }
1042
1030
kind = dbscheme .SelectorExpr .Index ()
1043
1031
extractExpr (tw , expr .X , lbl , 0 , false )
1044
1032
extractExpr (tw , expr .Sel , lbl , 1 , false )
1045
1033
case * ast.IndexExpr :
1046
- if expr == nil {
1047
- return
1048
- }
1049
1034
typeofx := typeOf (tw , expr .X )
1050
1035
if typeofx == nil {
1051
1036
// We are missing type information for `expr.X`, so we cannot
@@ -1065,9 +1050,6 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
1065
1050
extractExpr (tw , expr .X , lbl , 0 , false )
1066
1051
extractExpr (tw , expr .Index , lbl , 1 , false )
1067
1052
case * ast.IndexListExpr :
1068
- if expr == nil {
1069
- return
1070
- }
1071
1053
typeofx := typeOf (tw , expr .X )
1072
1054
if typeofx == nil {
1073
1055
// We are missing type information for `expr.X`, so we cannot
@@ -1084,51 +1066,33 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
1084
1066
extractExpr (tw , expr .X , lbl , 0 , false )
1085
1067
extractExprs (tw , expr .Indices , lbl , 1 , 1 )
1086
1068
case * ast.SliceExpr :
1087
- if expr == nil {
1088
- return
1089
- }
1090
1069
kind = dbscheme .SliceExpr .Index ()
1091
1070
extractExpr (tw , expr .X , lbl , 0 , false )
1092
1071
extractExpr (tw , expr .Low , lbl , 1 , false )
1093
1072
extractExpr (tw , expr .High , lbl , 2 , false )
1094
1073
extractExpr (tw , expr .Max , lbl , 3 , false )
1095
1074
case * ast.TypeAssertExpr :
1096
- if expr == nil {
1097
- return
1098
- }
1099
1075
kind = dbscheme .TypeAssertExpr .Index ()
1100
1076
extractExpr (tw , expr .X , lbl , 0 , false )
1101
1077
// expr.Type can be `nil` if this is the `x.(type)` in a type switch.
1102
1078
if expr .Type != nil {
1103
1079
extractExpr (tw , expr .Type , lbl , 1 , false )
1104
1080
}
1105
1081
case * ast.CallExpr :
1106
- if expr == nil {
1107
- return
1108
- }
1109
1082
kind = dbscheme .CallOrConversionExpr .Index ()
1110
1083
extractExpr (tw , expr .Fun , lbl , 0 , false )
1111
1084
extractExprs (tw , expr .Args , lbl , 1 , 1 )
1112
1085
if expr .Ellipsis .IsValid () {
1113
1086
dbscheme .HasEllipsisTable .Emit (tw , lbl )
1114
1087
}
1115
1088
case * ast.StarExpr :
1116
- if expr == nil {
1117
- return
1118
- }
1119
1089
kind = dbscheme .StarExpr .Index ()
1120
1090
extractExpr (tw , expr .X , lbl , 0 , false )
1121
1091
case * ast.KeyValueExpr :
1122
- if expr == nil {
1123
- return
1124
- }
1125
1092
kind = dbscheme .KeyValueExpr .Index ()
1126
1093
extractExpr (tw , expr .Key , lbl , 0 , false )
1127
1094
extractExpr (tw , expr .Value , lbl , 1 , false )
1128
1095
case * ast.UnaryExpr :
1129
- if expr == nil {
1130
- return
1131
- }
1132
1096
if expr .Op == token .TILDE {
1133
1097
kind = dbscheme .TypeSetLiteralExpr .Index ()
1134
1098
} else {
@@ -1140,9 +1104,6 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
1140
1104
}
1141
1105
extractExpr (tw , expr .X , lbl , 0 , false )
1142
1106
case * ast.BinaryExpr :
1143
- if expr == nil {
1144
- return
1145
- }
1146
1107
_ , isUnionType := typeOf (tw , expr ).(* types.Union )
1147
1108
if expr .Op == token .OR && isUnionType {
1148
1109
kind = dbscheme .TypeSetLiteralExpr .Index ()
@@ -1158,46 +1119,28 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
1158
1119
extractExpr (tw , expr .Y , lbl , 1 , false )
1159
1120
}
1160
1121
case * ast.ArrayType :
1161
- if expr == nil {
1162
- return
1163
- }
1164
1122
kind = dbscheme .ArrayTypeExpr .Index ()
1165
1123
extractExpr (tw , expr .Len , lbl , 0 , false )
1166
1124
extractExpr (tw , expr .Elt , lbl , 1 , false )
1167
1125
case * ast.StructType :
1168
- if expr == nil {
1169
- return
1170
- }
1171
1126
kind = dbscheme .StructTypeExpr .Index ()
1172
1127
extractFields (tw , expr .Fields , lbl , 0 , 1 )
1173
1128
case * ast.FuncType :
1174
- if expr == nil {
1175
- return
1176
- }
1177
1129
kind = dbscheme .FuncTypeExpr .Index ()
1178
1130
extractFields (tw , expr .Params , lbl , 0 , 1 )
1179
1131
extractFields (tw , expr .Results , lbl , - 1 , - 1 )
1180
1132
emitScopeNodeInfo (tw , expr , lbl )
1181
1133
case * ast.InterfaceType :
1182
- if expr == nil {
1183
- return
1184
- }
1185
1134
kind = dbscheme .InterfaceTypeExpr .Index ()
1186
1135
// expr.Methods contains methods, embedded interfaces and type set
1187
1136
// literals.
1188
1137
makeTypeSetLiteralsUnionTyped (tw , expr .Methods )
1189
1138
extractFields (tw , expr .Methods , lbl , 0 , 1 )
1190
1139
case * ast.MapType :
1191
- if expr == nil {
1192
- return
1193
- }
1194
1140
kind = dbscheme .MapTypeExpr .Index ()
1195
1141
extractExpr (tw , expr .Key , lbl , 0 , false )
1196
1142
extractExpr (tw , expr .Value , lbl , 1 , false )
1197
1143
case * ast.ChanType :
1198
- if expr == nil {
1199
- return
1200
- }
1201
1144
tp := dbscheme .ChanTypeExprs [expr .Dir ]
1202
1145
if tp == nil {
1203
1146
log .Fatalf ("unsupported channel direction %v" , expr .Dir )
@@ -1299,7 +1242,15 @@ func extractFields(tw *trap.Writer, fields *ast.FieldList, parent trap.Label, id
1299
1242
// extractStmt extracts AST information for a given statement and all other statements or expressions
1300
1243
// nested inside it
1301
1244
func extractStmt (tw * trap.Writer , stmt ast.Stmt , parent trap.Label , idx int ) {
1302
- if stmt == nil {
1245
+ if stmt == nil || stmt == (* ast .DeclStmt )(nil ) ||
1246
+ stmt == (* ast .LabeledStmt )(nil ) || stmt == (* ast .ExprStmt )(nil ) ||
1247
+ stmt == (* ast .SendStmt )(nil ) || stmt == (* ast .IncDecStmt )(nil ) ||
1248
+ stmt == (* ast .AssignStmt )(nil ) || stmt == (* ast .GoStmt )(nil ) ||
1249
+ stmt == (* ast .DeferStmt )(nil ) || stmt == (* ast .BranchStmt )(nil ) ||
1250
+ stmt == (* ast .BlockStmt )(nil ) || stmt == (* ast .IfStmt )(nil ) ||
1251
+ stmt == (* ast .CaseClause )(nil ) || stmt == (* ast .SwitchStmt )(nil ) ||
1252
+ stmt == (* ast .TypeSwitchStmt )(nil ) || stmt == (* ast .CommClause )(nil ) ||
1253
+ stmt == (* ast .ForStmt )(nil ) || stmt == (* ast .RangeStmt )(nil ) {
1303
1254
return
1304
1255
}
1305
1256
@@ -1309,37 +1260,22 @@ func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
1309
1260
case * ast.BadStmt :
1310
1261
kind = dbscheme .BadStmtType .Index ()
1311
1262
case * ast.DeclStmt :
1312
- if stmt == nil {
1313
- return
1314
- }
1315
1263
kind = dbscheme .DeclStmtType .Index ()
1316
1264
extractDecl (tw , stmt .Decl , lbl , 0 )
1317
1265
case * ast.EmptyStmt :
1318
1266
kind = dbscheme .EmptyStmtType .Index ()
1319
1267
case * ast.LabeledStmt :
1320
- if stmt == nil {
1321
- return
1322
- }
1323
1268
kind = dbscheme .LabeledStmtType .Index ()
1324
1269
extractExpr (tw , stmt .Label , lbl , 0 , false )
1325
1270
extractStmt (tw , stmt .Stmt , lbl , 1 )
1326
1271
case * ast.ExprStmt :
1327
- if stmt == nil {
1328
- return
1329
- }
1330
1272
kind = dbscheme .ExprStmtType .Index ()
1331
1273
extractExpr (tw , stmt .X , lbl , 0 , false )
1332
1274
case * ast.SendStmt :
1333
- if stmt == nil {
1334
- return
1335
- }
1336
1275
kind = dbscheme .SendStmtType .Index ()
1337
1276
extractExpr (tw , stmt .Chan , lbl , 0 , false )
1338
1277
extractExpr (tw , stmt .Value , lbl , 1 , false )
1339
1278
case * ast.IncDecStmt :
1340
- if stmt == nil {
1341
- return
1342
- }
1343
1279
if stmt .Tok == token .INC {
1344
1280
kind = dbscheme .IncStmtType .Index ()
1345
1281
} else if stmt .Tok == token .DEC {
@@ -1349,9 +1285,6 @@ func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
1349
1285
}
1350
1286
extractExpr (tw , stmt .X , lbl , 0 , false )
1351
1287
case * ast.AssignStmt :
1352
- if stmt == nil {
1353
- return
1354
- }
1355
1288
tp := dbscheme .AssignStmtTypes [stmt .Tok ]
1356
1289
if tp == nil {
1357
1290
log .Fatalf ("unsupported assignment statement with operator %v" , stmt .Tok )
@@ -1360,24 +1293,15 @@ func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
1360
1293
extractExprs (tw , stmt .Lhs , lbl , - 1 , - 1 )
1361
1294
extractExprs (tw , stmt .Rhs , lbl , 1 , 1 )
1362
1295
case * ast.GoStmt :
1363
- if stmt == nil {
1364
- return
1365
- }
1366
1296
kind = dbscheme .GoStmtType .Index ()
1367
1297
extractExpr (tw , stmt .Call , lbl , 0 , false )
1368
1298
case * ast.DeferStmt :
1369
- if stmt == nil {
1370
- return
1371
- }
1372
1299
kind = dbscheme .DeferStmtType .Index ()
1373
1300
extractExpr (tw , stmt .Call , lbl , 0 , false )
1374
1301
case * ast.ReturnStmt :
1375
1302
kind = dbscheme .ReturnStmtType .Index ()
1376
1303
extractExprs (tw , stmt .Results , lbl , 0 , 1 )
1377
1304
case * ast.BranchStmt :
1378
- if stmt == nil {
1379
- return
1380
- }
1381
1305
switch stmt .Tok {
1382
1306
case token .BREAK :
1383
1307
kind = dbscheme .BreakStmtType .Index ()
@@ -1392,52 +1316,34 @@ func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
1392
1316
}
1393
1317
extractExpr (tw , stmt .Label , lbl , 0 , false )
1394
1318
case * ast.BlockStmt :
1395
- if stmt == nil {
1396
- return
1397
- }
1398
1319
kind = dbscheme .BlockStmtType .Index ()
1399
1320
extractStmts (tw , stmt .List , lbl , 0 , 1 )
1400
1321
emitScopeNodeInfo (tw , stmt , lbl )
1401
1322
case * ast.IfStmt :
1402
- if stmt == nil {
1403
- return
1404
- }
1405
1323
kind = dbscheme .IfStmtType .Index ()
1406
1324
extractStmt (tw , stmt .Init , lbl , 0 )
1407
1325
extractExpr (tw , stmt .Cond , lbl , 1 , false )
1408
1326
extractStmt (tw , stmt .Body , lbl , 2 )
1409
1327
extractStmt (tw , stmt .Else , lbl , 3 )
1410
1328
emitScopeNodeInfo (tw , stmt , lbl )
1411
1329
case * ast.CaseClause :
1412
- if stmt == nil {
1413
- return
1414
- }
1415
1330
kind = dbscheme .CaseClauseType .Index ()
1416
1331
extractExprs (tw , stmt .List , lbl , - 1 , - 1 )
1417
1332
extractStmts (tw , stmt .Body , lbl , 0 , 1 )
1418
1333
emitScopeNodeInfo (tw , stmt , lbl )
1419
1334
case * ast.SwitchStmt :
1420
- if stmt == nil {
1421
- return
1422
- }
1423
1335
kind = dbscheme .ExprSwitchStmtType .Index ()
1424
1336
extractStmt (tw , stmt .Init , lbl , 0 )
1425
1337
extractExpr (tw , stmt .Tag , lbl , 1 , false )
1426
1338
extractStmt (tw , stmt .Body , lbl , 2 )
1427
1339
emitScopeNodeInfo (tw , stmt , lbl )
1428
1340
case * ast.TypeSwitchStmt :
1429
- if stmt == nil {
1430
- return
1431
- }
1432
1341
kind = dbscheme .TypeSwitchStmtType .Index ()
1433
1342
extractStmt (tw , stmt .Init , lbl , 0 )
1434
1343
extractStmt (tw , stmt .Assign , lbl , 1 )
1435
1344
extractStmt (tw , stmt .Body , lbl , 2 )
1436
1345
emitScopeNodeInfo (tw , stmt , lbl )
1437
1346
case * ast.CommClause :
1438
- if stmt == nil {
1439
- return
1440
- }
1441
1347
kind = dbscheme .CommClauseType .Index ()
1442
1348
extractStmt (tw , stmt .Comm , lbl , 0 )
1443
1349
extractStmts (tw , stmt .Body , lbl , 1 , 1 )
@@ -1446,19 +1352,13 @@ func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
1446
1352
kind = dbscheme .SelectStmtType .Index ()
1447
1353
extractStmt (tw , stmt .Body , lbl , 0 )
1448
1354
case * ast.ForStmt :
1449
- if stmt == nil {
1450
- return
1451
- }
1452
1355
kind = dbscheme .ForStmtType .Index ()
1453
1356
extractStmt (tw , stmt .Init , lbl , 0 )
1454
1357
extractExpr (tw , stmt .Cond , lbl , 1 , false )
1455
1358
extractStmt (tw , stmt .Post , lbl , 2 )
1456
1359
extractStmt (tw , stmt .Body , lbl , 3 )
1457
1360
emitScopeNodeInfo (tw , stmt , lbl )
1458
1361
case * ast.RangeStmt :
1459
- if stmt == nil {
1460
- return
1461
- }
1462
1362
kind = dbscheme .RangeStmtType .Index ()
1463
1363
extractExpr (tw , stmt .Key , lbl , 0 , false )
1464
1364
extractExpr (tw , stmt .Value , lbl , 1 , false )
@@ -1486,15 +1386,15 @@ func extractStmts(tw *trap.Writer, stmts []ast.Stmt, parent trap.Label, idx int,
1486
1386
1487
1387
// extractDecl extracts AST information for the given declaration
1488
1388
func extractDecl (tw * trap.Writer , decl ast.Decl , parent trap.Label , idx int ) {
1389
+ if decl == (* ast .FuncDecl )(nil ) || decl == (* ast .GenDecl )(nil ) {
1390
+ return
1391
+ }
1489
1392
lbl := tw .Labeler .LocalID (decl )
1490
1393
var kind int
1491
1394
switch decl := decl .(type ) {
1492
1395
case * ast.BadDecl :
1493
1396
kind = dbscheme .BadDeclType .Index ()
1494
1397
case * ast.GenDecl :
1495
- if decl == nil {
1496
- return
1497
- }
1498
1398
switch decl .Tok {
1499
1399
case token .IMPORT :
1500
1400
kind = dbscheme .ImportDeclType .Index ()
@@ -1512,9 +1412,6 @@ func extractDecl(tw *trap.Writer, decl ast.Decl, parent trap.Label, idx int) {
1512
1412
}
1513
1413
extractDoc (tw , decl .Doc , lbl )
1514
1414
case * ast.FuncDecl :
1515
- if decl == nil {
1516
- return
1517
- }
1518
1415
kind = dbscheme .FuncDeclType .Index ()
1519
1416
extractFields (tw , decl .Recv , lbl , - 1 , - 1 )
1520
1417
extractExpr (tw , decl .Name , lbl , 0 , false )
0 commit comments