@@ -936,7 +936,16 @@ func emitScopeNodeInfo(tw *trap.Writer, nd ast.Node, lbl trap.Label) {
936936
937937// extractExpr extracts AST information for the given expression and all its subexpressions
938938func 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 ) {
940949 return
941950 }
942951
@@ -948,9 +957,6 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
948957 case * ast.BadExpr :
949958 kind = dbscheme .BadExpr .Index ()
950959 case * ast.Ident :
951- if expr == nil {
952- return
953- }
954960 kind = dbscheme .IdentExpr .Index ()
955961 dbscheme .LiteralsTable .Emit (tw , lbl , expr .Name , expr .Name )
956962 def := tw .Package .TypesInfo .Defs [expr ]
@@ -984,15 +990,9 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
984990 }
985991 }
986992 case * ast.Ellipsis :
987- if expr == nil {
988- return
989- }
990993 kind = dbscheme .EllipsisExpr .Index ()
991994 extractExpr (tw , expr .Elt , lbl , 0 , false )
992995 case * ast.BasicLit :
993- if expr == nil {
994- return
995- }
996996 value := ""
997997 switch expr .Kind {
998998 case token .INT :
@@ -1016,36 +1016,21 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
10161016 }
10171017 dbscheme .LiteralsTable .Emit (tw , lbl , value , expr .Value )
10181018 case * ast.FuncLit :
1019- if expr == nil {
1020- return
1021- }
10221019 kind = dbscheme .FuncLitExpr .Index ()
10231020 extractExpr (tw , expr .Type , lbl , 0 , false )
10241021 extractStmt (tw , expr .Body , lbl , 1 )
10251022 case * ast.CompositeLit :
1026- if expr == nil {
1027- return
1028- }
10291023 kind = dbscheme .CompositeLitExpr .Index ()
10301024 extractExpr (tw , expr .Type , lbl , 0 , false )
10311025 extractExprs (tw , expr .Elts , lbl , 1 , 1 )
10321026 case * ast.ParenExpr :
1033- if expr == nil {
1034- return
1035- }
10361027 kind = dbscheme .ParenExpr .Index ()
10371028 extractExpr (tw , expr .X , lbl , 0 , false )
10381029 case * ast.SelectorExpr :
1039- if expr == nil {
1040- return
1041- }
10421030 kind = dbscheme .SelectorExpr .Index ()
10431031 extractExpr (tw , expr .X , lbl , 0 , false )
10441032 extractExpr (tw , expr .Sel , lbl , 1 , false )
10451033 case * ast.IndexExpr :
1046- if expr == nil {
1047- return
1048- }
10491034 typeofx := typeOf (tw , expr .X )
10501035 if typeofx == nil {
10511036 // 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
10651050 extractExpr (tw , expr .X , lbl , 0 , false )
10661051 extractExpr (tw , expr .Index , lbl , 1 , false )
10671052 case * ast.IndexListExpr :
1068- if expr == nil {
1069- return
1070- }
10711053 typeofx := typeOf (tw , expr .X )
10721054 if typeofx == nil {
10731055 // 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
10841066 extractExpr (tw , expr .X , lbl , 0 , false )
10851067 extractExprs (tw , expr .Indices , lbl , 1 , 1 )
10861068 case * ast.SliceExpr :
1087- if expr == nil {
1088- return
1089- }
10901069 kind = dbscheme .SliceExpr .Index ()
10911070 extractExpr (tw , expr .X , lbl , 0 , false )
10921071 extractExpr (tw , expr .Low , lbl , 1 , false )
10931072 extractExpr (tw , expr .High , lbl , 2 , false )
10941073 extractExpr (tw , expr .Max , lbl , 3 , false )
10951074 case * ast.TypeAssertExpr :
1096- if expr == nil {
1097- return
1098- }
10991075 kind = dbscheme .TypeAssertExpr .Index ()
11001076 extractExpr (tw , expr .X , lbl , 0 , false )
11011077 // expr.Type can be `nil` if this is the `x.(type)` in a type switch.
11021078 if expr .Type != nil {
11031079 extractExpr (tw , expr .Type , lbl , 1 , false )
11041080 }
11051081 case * ast.CallExpr :
1106- if expr == nil {
1107- return
1108- }
11091082 kind = dbscheme .CallOrConversionExpr .Index ()
11101083 extractExpr (tw , expr .Fun , lbl , 0 , false )
11111084 extractExprs (tw , expr .Args , lbl , 1 , 1 )
11121085 if expr .Ellipsis .IsValid () {
11131086 dbscheme .HasEllipsisTable .Emit (tw , lbl )
11141087 }
11151088 case * ast.StarExpr :
1116- if expr == nil {
1117- return
1118- }
11191089 kind = dbscheme .StarExpr .Index ()
11201090 extractExpr (tw , expr .X , lbl , 0 , false )
11211091 case * ast.KeyValueExpr :
1122- if expr == nil {
1123- return
1124- }
11251092 kind = dbscheme .KeyValueExpr .Index ()
11261093 extractExpr (tw , expr .Key , lbl , 0 , false )
11271094 extractExpr (tw , expr .Value , lbl , 1 , false )
11281095 case * ast.UnaryExpr :
1129- if expr == nil {
1130- return
1131- }
11321096 if expr .Op == token .TILDE {
11331097 kind = dbscheme .TypeSetLiteralExpr .Index ()
11341098 } else {
@@ -1140,9 +1104,6 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
11401104 }
11411105 extractExpr (tw , expr .X , lbl , 0 , false )
11421106 case * ast.BinaryExpr :
1143- if expr == nil {
1144- return
1145- }
11461107 _ , isUnionType := typeOf (tw , expr ).(* types.Union )
11471108 if expr .Op == token .OR && isUnionType {
11481109 kind = dbscheme .TypeSetLiteralExpr .Index ()
@@ -1158,46 +1119,28 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
11581119 extractExpr (tw , expr .Y , lbl , 1 , false )
11591120 }
11601121 case * ast.ArrayType :
1161- if expr == nil {
1162- return
1163- }
11641122 kind = dbscheme .ArrayTypeExpr .Index ()
11651123 extractExpr (tw , expr .Len , lbl , 0 , false )
11661124 extractExpr (tw , expr .Elt , lbl , 1 , false )
11671125 case * ast.StructType :
1168- if expr == nil {
1169- return
1170- }
11711126 kind = dbscheme .StructTypeExpr .Index ()
11721127 extractFields (tw , expr .Fields , lbl , 0 , 1 )
11731128 case * ast.FuncType :
1174- if expr == nil {
1175- return
1176- }
11771129 kind = dbscheme .FuncTypeExpr .Index ()
11781130 extractFields (tw , expr .Params , lbl , 0 , 1 )
11791131 extractFields (tw , expr .Results , lbl , - 1 , - 1 )
11801132 emitScopeNodeInfo (tw , expr , lbl )
11811133 case * ast.InterfaceType :
1182- if expr == nil {
1183- return
1184- }
11851134 kind = dbscheme .InterfaceTypeExpr .Index ()
11861135 // expr.Methods contains methods, embedded interfaces and type set
11871136 // literals.
11881137 makeTypeSetLiteralsUnionTyped (tw , expr .Methods )
11891138 extractFields (tw , expr .Methods , lbl , 0 , 1 )
11901139 case * ast.MapType :
1191- if expr == nil {
1192- return
1193- }
11941140 kind = dbscheme .MapTypeExpr .Index ()
11951141 extractExpr (tw , expr .Key , lbl , 0 , false )
11961142 extractExpr (tw , expr .Value , lbl , 1 , false )
11971143 case * ast.ChanType :
1198- if expr == nil {
1199- return
1200- }
12011144 tp := dbscheme .ChanTypeExprs [expr .Dir ]
12021145 if tp == nil {
12031146 log .Fatalf ("unsupported channel direction %v" , expr .Dir )
@@ -1299,7 +1242,15 @@ func extractFields(tw *trap.Writer, fields *ast.FieldList, parent trap.Label, id
12991242// extractStmt extracts AST information for a given statement and all other statements or expressions
13001243// nested inside it
13011244func 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 ) {
13031254 return
13041255 }
13051256
@@ -1309,37 +1260,22 @@ func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
13091260 case * ast.BadStmt :
13101261 kind = dbscheme .BadStmtType .Index ()
13111262 case * ast.DeclStmt :
1312- if stmt == nil {
1313- return
1314- }
13151263 kind = dbscheme .DeclStmtType .Index ()
13161264 extractDecl (tw , stmt .Decl , lbl , 0 )
13171265 case * ast.EmptyStmt :
13181266 kind = dbscheme .EmptyStmtType .Index ()
13191267 case * ast.LabeledStmt :
1320- if stmt == nil {
1321- return
1322- }
13231268 kind = dbscheme .LabeledStmtType .Index ()
13241269 extractExpr (tw , stmt .Label , lbl , 0 , false )
13251270 extractStmt (tw , stmt .Stmt , lbl , 1 )
13261271 case * ast.ExprStmt :
1327- if stmt == nil {
1328- return
1329- }
13301272 kind = dbscheme .ExprStmtType .Index ()
13311273 extractExpr (tw , stmt .X , lbl , 0 , false )
13321274 case * ast.SendStmt :
1333- if stmt == nil {
1334- return
1335- }
13361275 kind = dbscheme .SendStmtType .Index ()
13371276 extractExpr (tw , stmt .Chan , lbl , 0 , false )
13381277 extractExpr (tw , stmt .Value , lbl , 1 , false )
13391278 case * ast.IncDecStmt :
1340- if stmt == nil {
1341- return
1342- }
13431279 if stmt .Tok == token .INC {
13441280 kind = dbscheme .IncStmtType .Index ()
13451281 } else if stmt .Tok == token .DEC {
@@ -1349,9 +1285,6 @@ func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
13491285 }
13501286 extractExpr (tw , stmt .X , lbl , 0 , false )
13511287 case * ast.AssignStmt :
1352- if stmt == nil {
1353- return
1354- }
13551288 tp := dbscheme .AssignStmtTypes [stmt .Tok ]
13561289 if tp == nil {
13571290 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) {
13601293 extractExprs (tw , stmt .Lhs , lbl , - 1 , - 1 )
13611294 extractExprs (tw , stmt .Rhs , lbl , 1 , 1 )
13621295 case * ast.GoStmt :
1363- if stmt == nil {
1364- return
1365- }
13661296 kind = dbscheme .GoStmtType .Index ()
13671297 extractExpr (tw , stmt .Call , lbl , 0 , false )
13681298 case * ast.DeferStmt :
1369- if stmt == nil {
1370- return
1371- }
13721299 kind = dbscheme .DeferStmtType .Index ()
13731300 extractExpr (tw , stmt .Call , lbl , 0 , false )
13741301 case * ast.ReturnStmt :
13751302 kind = dbscheme .ReturnStmtType .Index ()
13761303 extractExprs (tw , stmt .Results , lbl , 0 , 1 )
13771304 case * ast.BranchStmt :
1378- if stmt == nil {
1379- return
1380- }
13811305 switch stmt .Tok {
13821306 case token .BREAK :
13831307 kind = dbscheme .BreakStmtType .Index ()
@@ -1392,52 +1316,34 @@ func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
13921316 }
13931317 extractExpr (tw , stmt .Label , lbl , 0 , false )
13941318 case * ast.BlockStmt :
1395- if stmt == nil {
1396- return
1397- }
13981319 kind = dbscheme .BlockStmtType .Index ()
13991320 extractStmts (tw , stmt .List , lbl , 0 , 1 )
14001321 emitScopeNodeInfo (tw , stmt , lbl )
14011322 case * ast.IfStmt :
1402- if stmt == nil {
1403- return
1404- }
14051323 kind = dbscheme .IfStmtType .Index ()
14061324 extractStmt (tw , stmt .Init , lbl , 0 )
14071325 extractExpr (tw , stmt .Cond , lbl , 1 , false )
14081326 extractStmt (tw , stmt .Body , lbl , 2 )
14091327 extractStmt (tw , stmt .Else , lbl , 3 )
14101328 emitScopeNodeInfo (tw , stmt , lbl )
14111329 case * ast.CaseClause :
1412- if stmt == nil {
1413- return
1414- }
14151330 kind = dbscheme .CaseClauseType .Index ()
14161331 extractExprs (tw , stmt .List , lbl , - 1 , - 1 )
14171332 extractStmts (tw , stmt .Body , lbl , 0 , 1 )
14181333 emitScopeNodeInfo (tw , stmt , lbl )
14191334 case * ast.SwitchStmt :
1420- if stmt == nil {
1421- return
1422- }
14231335 kind = dbscheme .ExprSwitchStmtType .Index ()
14241336 extractStmt (tw , stmt .Init , lbl , 0 )
14251337 extractExpr (tw , stmt .Tag , lbl , 1 , false )
14261338 extractStmt (tw , stmt .Body , lbl , 2 )
14271339 emitScopeNodeInfo (tw , stmt , lbl )
14281340 case * ast.TypeSwitchStmt :
1429- if stmt == nil {
1430- return
1431- }
14321341 kind = dbscheme .TypeSwitchStmtType .Index ()
14331342 extractStmt (tw , stmt .Init , lbl , 0 )
14341343 extractStmt (tw , stmt .Assign , lbl , 1 )
14351344 extractStmt (tw , stmt .Body , lbl , 2 )
14361345 emitScopeNodeInfo (tw , stmt , lbl )
14371346 case * ast.CommClause :
1438- if stmt == nil {
1439- return
1440- }
14411347 kind = dbscheme .CommClauseType .Index ()
14421348 extractStmt (tw , stmt .Comm , lbl , 0 )
14431349 extractStmts (tw , stmt .Body , lbl , 1 , 1 )
@@ -1446,19 +1352,13 @@ func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
14461352 kind = dbscheme .SelectStmtType .Index ()
14471353 extractStmt (tw , stmt .Body , lbl , 0 )
14481354 case * ast.ForStmt :
1449- if stmt == nil {
1450- return
1451- }
14521355 kind = dbscheme .ForStmtType .Index ()
14531356 extractStmt (tw , stmt .Init , lbl , 0 )
14541357 extractExpr (tw , stmt .Cond , lbl , 1 , false )
14551358 extractStmt (tw , stmt .Post , lbl , 2 )
14561359 extractStmt (tw , stmt .Body , lbl , 3 )
14571360 emitScopeNodeInfo (tw , stmt , lbl )
14581361 case * ast.RangeStmt :
1459- if stmt == nil {
1460- return
1461- }
14621362 kind = dbscheme .RangeStmtType .Index ()
14631363 extractExpr (tw , stmt .Key , lbl , 0 , false )
14641364 extractExpr (tw , stmt .Value , lbl , 1 , false )
@@ -1486,15 +1386,15 @@ func extractStmts(tw *trap.Writer, stmts []ast.Stmt, parent trap.Label, idx int,
14861386
14871387// extractDecl extracts AST information for the given declaration
14881388func 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+ }
14891392 lbl := tw .Labeler .LocalID (decl )
14901393 var kind int
14911394 switch decl := decl .(type ) {
14921395 case * ast.BadDecl :
14931396 kind = dbscheme .BadDeclType .Index ()
14941397 case * ast.GenDecl :
1495- if decl == nil {
1496- return
1497- }
14981398 switch decl .Tok {
14991399 case token .IMPORT :
15001400 kind = dbscheme .ImportDeclType .Index ()
@@ -1512,9 +1412,6 @@ func extractDecl(tw *trap.Writer, decl ast.Decl, parent trap.Label, idx int) {
15121412 }
15131413 extractDoc (tw , decl .Doc , lbl )
15141414 case * ast.FuncDecl :
1515- if decl == nil {
1516- return
1517- }
15181415 kind = dbscheme .FuncDeclType .Index ()
15191416 extractFields (tw , decl .Recv , lbl , - 1 , - 1 )
15201417 extractExpr (tw , decl .Name , lbl , 0 , false )
0 commit comments