From 4257a68c277470b4cf050f736340630c70934387 Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Fri, 10 Jul 2020 14:08:37 +0100 Subject: [PATCH 1/3] Include newlines in messages printed by `go-gen-dbscheme`. --- extractor/cli/go-gen-dbscheme/go-gen-dbscheme.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extractor/cli/go-gen-dbscheme/go-gen-dbscheme.go b/extractor/cli/go-gen-dbscheme/go-gen-dbscheme.go index 2a757b47f5b..94831c2b451 100644 --- a/extractor/cli/go-gen-dbscheme/go-gen-dbscheme.go +++ b/extractor/cli/go-gen-dbscheme/go-gen-dbscheme.go @@ -22,10 +22,10 @@ func main() { f, err := os.Create(out) if err != nil { - fmt.Fprintf(os.Stderr, "Unable to open file %s for writing.", out) + fmt.Fprintf(os.Stderr, "Unable to open file %s for writing.\n", out) os.Exit(1) } dbscheme.PrintDbScheme(f) f.Close() - fmt.Printf("Dbscheme written to file %s.", out) + fmt.Printf("Dbscheme written to file %s.\n", out) } From 1a8688a8f4452ca5dfe6cdd4acf49865b6c5604c Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Fri, 10 Jul 2020 14:12:51 +0100 Subject: [PATCH 2/3] Extract enough information to distinguish type definitions from alias declarations. --- extractor/dbscheme/tables.go | 8 +- extractor/extractor.go | 6 +- ql/src/go.dbscheme | 5 +- ql/src/go.dbscheme.stats | 1218 +++++++++-------- ql/src/semmle/go/Decls.qll | 37 +- .../semmle/go/Decl/TypeSpec.expected | 2 + .../library-tests/semmle/go/Decl/TypeSpec.ql | 5 + ql/test/library-tests/semmle/go/Decl/main.go | 5 + .../go.dbscheme | 434 ++++++ .../old.dbscheme | 431 ++++++ .../upgrade.properties | 2 + 11 files changed, 1551 insertions(+), 602 deletions(-) create mode 100644 ql/test/library-tests/semmle/go/Decl/TypeSpec.expected create mode 100644 ql/test/library-tests/semmle/go/Decl/TypeSpec.ql create mode 100644 ql/test/library-tests/semmle/go/Decl/main.go create mode 100644 upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/go.dbscheme create mode 100644 upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/old.dbscheme create mode 100644 upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/upgrade.properties diff --git a/extractor/dbscheme/tables.go b/extractor/dbscheme/tables.go index a3fb0993411..56ac11411db 100644 --- a/extractor/dbscheme/tables.go +++ b/extractor/dbscheme/tables.go @@ -441,7 +441,13 @@ var ImportSpecType = SpecKind.NewBranch("@importspec") var ValueSpecType = SpecKind.NewBranch("@valuespec") // TypeSpecType is the type of type declaration specification nodes -var TypeSpecType = SpecKind.NewBranch("@typespec") +var TypeSpecType = NewUnionType("@typespec") + +// TypeDefSpecType is the type of type declaration specification nodes corresponding to type definitions +var TypeDefSpecType = SpecKind.NewBranch("@typedefspec", TypeSpecType) + +// AliasSpecType is the type of type declaration specification nodes corresponding to alias declarations +var AliasSpecType = SpecKind.NewBranch("@aliasspec", TypeSpecType) // ObjectType is the type of objects (that is, declared entities) var ObjectType = NewPrimaryKeyType("@object") diff --git a/extractor/extractor.go b/extractor/extractor.go index 4bcbe1421bf..1a69f141a52 100644 --- a/extractor/extractor.go +++ b/extractor/extractor.go @@ -1149,7 +1149,11 @@ func extractSpec(tw *trap.Writer, spec ast.Spec, parent trap.Label, idx int) { if spec == nil { return } - kind = dbscheme.TypeSpecType.Index() + if spec.Assign.IsValid() { + kind = dbscheme.AliasSpecType.Index() + } else { + kind = dbscheme.TypeDefSpecType.Index() + } extractExpr(tw, spec.Name, lbl, 0) extractExpr(tw, spec.Type, lbl, 1) extractDoc(tw, spec.Doc, lbl) diff --git a/ql/src/go.dbscheme b/ql/src/go.dbscheme index bcb9599aba6..bcbec1b0e44 100644 --- a/ql/src/go.dbscheme +++ b/ql/src/go.dbscheme @@ -317,7 +317,10 @@ case @decl.kind of case @spec.kind of 0 = @importspec | 1 = @valuespec -| 2 = @typespec; +| 2 = @typedefspec +| 3 = @aliasspec; + +@typespec = @typedefspec | @aliasspec; case @object.kind of 0 = @pkgobject diff --git a/ql/src/go.dbscheme.stats b/ql/src/go.dbscheme.stats index 90d111d74e7..6eac39b9263 100644 --- a/ql/src/go.dbscheme.stats +++ b/ql/src/go.dbscheme.stats @@ -14,7 +14,7 @@ @location_default - 537326 + 537408 @file @@ -22,7 +22,7 @@ @folder - 222 + 223 @comment_group @@ -30,7 +30,7 @@ @slashslashcomment - 24890 + 24891 @slashstarcomment @@ -38,7 +38,7 @@ @ident - 237281 + 237316 @ellipsis @@ -46,7 +46,7 @@ @intlit - 7680 + 7683 @floatlit @@ -58,7 +58,7 @@ @stringlit - 24889 + 24892 @funclit @@ -66,23 +66,23 @@ @compositelit - 2703 + 2704 @parenexpr - 342 + 343 @selectorexpr - 54345 + 54353 @indexexpr - 4580 + 4581 @sliceexpr - 835 + 836 @typeassertexpr @@ -90,11 +90,11 @@ @callorconversionexpr - 32032 + 32041 @starexpr - 10359 + 10360 @keyvalueexpr @@ -102,7 +102,7 @@ @arraytypeexpr - 3464 + 3465 @structtypeexpr @@ -134,7 +134,7 @@ @addressexpr - 1738 + 1739 @arrowexpr @@ -158,7 +158,7 @@ @lssexpr - 784 + 785 @leqexpr @@ -166,7 +166,7 @@ @gtrexpr - 618 + 619 @geqexpr @@ -178,7 +178,7 @@ @subexpr - 556 + 557 @orexpr @@ -250,7 +250,7 @@ @declstmt - 1452 + 1454 @labeledstmt @@ -258,7 +258,7 @@ @exprstmt - 7604 + 7605 @sendstmt @@ -302,11 +302,11 @@ @blockstmt - 19356 + 19358 @ifstmt - 9726 + 9728 @caseclause @@ -338,11 +338,11 @@ @assignstmt - 7477 + 7478 @definestmt - 9511 + 9514 @addassignstmt @@ -402,7 +402,7 @@ @constdecl - 278 + 280 @typedecl @@ -422,15 +422,19 @@ @importspec - 3466 + 3468 @valuespec - 3054 + 3056 - @typespec - 1365 + @typedefspec + 1349 + + + @aliasspec + 16 @universescope @@ -438,19 +442,19 @@ @packagescope - 342 + 341 @localscope - 36424 + 36428 @pkgobject - 3466 + 3468 @decltypeobject - 3526 + 3499 @builtintypeobject @@ -458,7 +462,7 @@ @declconstobject - 8262 + 8489 @builtinconstobject @@ -466,11 +470,11 @@ @declvarobject - 50424 + 50367 @declfunctionobject - 17441 + 17257 @builtinfunctionobject @@ -582,11 +586,11 @@ @arraytype - 284 + 292 @slicetype - 620 + 617 @structtype @@ -598,7 +602,7 @@ @interfacetype - 237 + 232 @tupletype @@ -606,11 +610,11 @@ @signaturetype - 7753 + 7772 @maptype - 417 + 416 @sendchantype @@ -626,7 +630,7 @@ @namedtype - 3488 + 3471 @complexliteraltype @@ -634,7 +638,7 @@ @package - 342 + 341 @modcommentblock @@ -1358,11 +1362,11 @@ locations_default - 537326 + 537408 id - 537326 + 537408 file @@ -1396,7 +1400,7 @@ 1 2 - 537326 + 537408 @@ -1412,7 +1416,7 @@ 1 2 - 537326 + 537408 @@ -1428,7 +1432,7 @@ 1 2 - 537326 + 537408 @@ -1444,7 +1448,7 @@ 1 2 - 537326 + 537408 @@ -1460,7 +1464,7 @@ 1 2 - 537326 + 537408 @@ -1476,17 +1480,17 @@ 2 30 - 41 + 40 30 - 122 + 121 40 - 122 + 121 211 - 40 + 41 211 @@ -1552,67 +1556,67 @@ 2 12 - 42 - - - 12 - 27 - 42 - - - 27 - 46 - 40 - - - 46 - 63 - 43 - - - 63 - 79 - 40 - - - 79 - 94 - 40 - - - 95 - 121 - 40 - - - 121 - 154 - 40 - - - 154 - 191 - 40 - - - 193 - 250 41 - 254 - 337 + 12 + 26 40 - 340 - 558 + 26 + 45 + 41 + + + 45 + 61 40 - 571 + 61 + 75 + 41 + + + 75 + 93 + 42 + + + 93 + 120 + 41 + + + 120 + 153 + 40 + + + 153 + 190 + 40 + + + 190 + 247 + 40 + + + 249 + 325 + 40 + + + 336 + 544 + 40 + + + 554 10233 - 35 + 37 @@ -1632,13 +1636,13 @@ 11 - 34 - 40 + 35 + 41 - 34 + 35 46 - 45 + 44 46 @@ -1704,12 +1708,12 @@ 2 13 - 41 + 40 13 32 - 43 + 44 32 @@ -1780,7 +1784,7 @@ 2 18 - 41 + 40 19 @@ -1790,7 +1794,7 @@ 46 59 - 42 + 43 59 @@ -2095,7 +2099,7 @@ 773 - 1789 + 1790 16 @@ -2105,7 +2109,7 @@ 4029 - 8598 + 8601 16 @@ -2114,8 +2118,8 @@ 16 - 27989 - 55545 + 27991 + 55558 3 @@ -2165,7 +2169,7 @@ 16 - 203 + 204 300 16 @@ -2180,8 +2184,8 @@ 16 - 431 - 458 + 432 + 459 16 @@ -2650,27 +2654,27 @@ 287 - 913 + 915 20 - 1001 + 1002 2526 20 2555 - 5281 + 5288 20 - 5733 - 10000 + 5734 + 10001 20 10080 - 20357 + 20361 19 @@ -2715,24 +2719,24 @@ 20 - 242 + 243 370 20 371 - 429 + 430 20 430 453 - 22 + 21 453 524 - 19 + 20 @@ -2772,7 +2776,7 @@ 152 - 413 + 414 20 @@ -2899,7 +2903,7 @@ 151 - 406 + 407 20 @@ -3008,12 +3012,12 @@ 1 2 - 184 + 183 2 3 - 73 + 74 3 @@ -3039,12 +3043,12 @@ 1 2 - 188 + 187 2 3 - 81 + 82 3 @@ -3070,12 +3074,12 @@ 1 2 - 189 + 188 2 3 - 78 + 79 3 @@ -3101,12 +3105,12 @@ 1 2 - 253 + 252 2 3 - 64 + 65 3 @@ -3132,12 +3136,12 @@ 1 2 - 257 + 256 2 3 - 66 + 67 3 @@ -3158,12 +3162,12 @@ 1 2 - 260 + 259 2 3 - 62 + 63 3 @@ -3214,12 +3218,12 @@ 6 10 - 13 + 12 10 31 - 11 + 12 @@ -3259,13 +3263,13 @@ 6 - 9 - 11 + 10 + 13 - 9 + 10 25 - 12 + 10 @@ -3704,15 +3708,15 @@ folders - 222 + 223 id - 222 + 223 name - 222 + 223 simple @@ -3730,7 +3734,7 @@ 1 2 - 222 + 223 @@ -3746,7 +3750,7 @@ 1 2 - 222 + 223 @@ -3762,7 +3766,7 @@ 1 2 - 222 + 223 @@ -3778,7 +3782,7 @@ 1 2 - 222 + 223 @@ -3794,12 +3798,12 @@ 1 2 - 164 + 163 2 3 - 18 + 19 3 @@ -3820,12 +3824,12 @@ 1 2 - 164 + 163 2 3 - 18 + 19 3 @@ -3840,15 +3844,15 @@ containerparent - 744 + 745 parent - 222 + 223 child - 744 + 745 @@ -3862,7 +3866,7 @@ 1 2 - 126 + 127 2 @@ -3908,7 +3912,7 @@ 1 2 - 744 + 745 @@ -3918,15 +3922,15 @@ has_location - 599313 + 599403 locatable - 599313 + 599403 location - 537326 + 537408 @@ -3940,7 +3944,7 @@ 1 2 - 599313 + 599403 @@ -3956,12 +3960,12 @@ 1 2 - 475654 + 475728 2 3 - 61628 + 61636 3 @@ -4272,11 +4276,11 @@ comments - 25736 + 25737 id - 25736 + 25737 kind @@ -4306,7 +4310,7 @@ 1 2 - 25736 + 25737 @@ -4322,7 +4326,7 @@ 1 2 - 25736 + 25737 @@ -4338,7 +4342,7 @@ 1 2 - 25736 + 25737 @@ -4354,7 +4358,7 @@ 1 2 - 25736 + 25737 @@ -4373,8 +4377,8 @@ 1 - 24890 - 24891 + 24891 + 24892 1 @@ -4454,12 +4458,12 @@ 1 2 - 7838 + 7837 2 3 - 1788 + 1789 3 @@ -4511,12 +4515,12 @@ 1 2 - 7838 + 7837 2 3 - 1788 + 1789 3 @@ -4547,12 +4551,12 @@ 1 2 - 7838 + 7837 2 3 - 1818 + 1819 3 @@ -4918,11 +4922,11 @@ exprs - 413969 + 414037 id - 413969 + 414037 kind @@ -4930,7 +4934,7 @@ parent - 219286 + 219324 idx @@ -4948,7 +4952,7 @@ 1 2 - 413969 + 414037 @@ -4964,7 +4968,7 @@ 1 2 - 413969 + 414037 @@ -4980,7 +4984,7 @@ 1 2 - 413969 + 414037 @@ -5015,12 +5019,12 @@ 248 - 343 + 344 4 509 - 619 + 620 4 @@ -5035,22 +5039,22 @@ 1272 - 2704 + 2705 4 3244 - 4581 + 4582 4 5616 - 10360 + 10361 4 - 24889 - 237282 + 24892 + 237317 4 @@ -5086,7 +5090,7 @@ 233 - 323 + 324 4 @@ -5096,7 +5100,7 @@ 676 - 789 + 790 4 @@ -5110,18 +5114,18 @@ 4 - 2581 + 2582 3985 4 - 4251 - 10114 + 4252 + 10115 4 - 14083 - 154721 + 14086 + 154744 4 @@ -5199,17 +5203,17 @@ 1 2 - 65795 + 65804 2 3 - 133306 + 133334 3 5 - 17888 + 17889 5 @@ -5230,17 +5234,17 @@ 1 2 - 137240 + 137263 2 3 - 75799 + 75813 3 7 - 6247 + 6248 @@ -5256,17 +5260,17 @@ 1 2 - 65795 + 65804 2 3 - 133306 + 133334 3 5 - 17888 + 17889 5 @@ -5301,7 +5305,7 @@ 4 - 179978 + 180006 288 @@ -5358,7 +5362,7 @@ 4 - 179978 + 180006 288 @@ -5369,19 +5373,19 @@ literals - 270715 + 270756 expr - 270715 + 270756 value - 25793 + 25795 raw - 27591 + 27594 @@ -5395,7 +5399,7 @@ 1 2 - 270715 + 270756 @@ -5411,7 +5415,7 @@ 1 2 - 270715 + 270756 @@ -5432,22 +5436,22 @@ 2 3 - 3292 + 3291 3 4 - 1781 + 1783 4 6 - 1934 + 1931 6 12 - 1964 + 1968 12 @@ -5473,12 +5477,12 @@ 1 2 - 24050 + 24051 2 5 - 1743 + 1744 @@ -5494,32 +5498,32 @@ 1 2 - 16039 + 16038 2 3 - 3519 + 3521 3 4 - 1868 + 1869 4 7 - 2554 + 2553 7 18 - 2128 + 2129 18 6833 - 1483 + 1484 @@ -5535,7 +5539,7 @@ 1 2 - 27591 + 27594 @@ -5545,19 +5549,19 @@ constvalues - 43919 + 43931 expr - 43919 + 43931 value - 16894 + 16896 exact - 16895 + 16897 @@ -5571,7 +5575,7 @@ 1 2 - 43919 + 43931 @@ -5587,7 +5591,7 @@ 1 2 - 43919 + 43931 @@ -5603,7 +5607,7 @@ 1 2 - 14930 + 14932 2 @@ -5629,7 +5633,7 @@ 1 2 - 16893 + 16895 2 @@ -5650,7 +5654,7 @@ 1 2 - 14931 + 14933 2 @@ -5676,7 +5680,7 @@ 1 2 - 16895 + 16897 @@ -5922,11 +5926,11 @@ stmts - 73979 + 73990 id - 73979 + 73990 kind @@ -5934,7 +5938,7 @@ parent - 41539 + 41543 idx @@ -5952,7 +5956,7 @@ 1 2 - 73979 + 73990 @@ -5968,7 +5972,7 @@ 1 2 - 73979 + 73990 @@ -5984,7 +5988,7 @@ 1 2 - 73979 + 73990 @@ -6044,17 +6048,17 @@ 3476 - 7605 + 7606 3 9225 - 9727 + 9729 3 - 19356 - 19357 + 19358 + 19359 1 @@ -6110,22 +6114,22 @@ 606 - 1153 + 1154 3 1719 - 5671 + 5672 3 - 5911 + 5912 9226 3 - 18818 - 18819 + 18820 + 18821 1 @@ -6213,7 +6217,7 @@ 1 2 - 29359 + 29362 2 @@ -6228,7 +6232,7 @@ 5 82 - 2393 + 2394 @@ -6244,7 +6248,7 @@ 1 2 - 31415 + 31418 2 @@ -6254,7 +6258,7 @@ 3 5 - 3596 + 3597 5 @@ -6275,7 +6279,7 @@ 1 2 - 29359 + 29362 2 @@ -6290,7 +6294,7 @@ 5 82 - 2393 + 2394 @@ -6345,12 +6349,12 @@ 314 - 1278 + 1279 7 - 1719 - 24877 + 1720 + 24879 6 @@ -6467,12 +6471,12 @@ 314 - 1278 + 1279 7 - 1719 - 24877 + 1720 + 24879 6 @@ -6483,11 +6487,11 @@ decls - 8688 + 8690 id - 8688 + 8690 kind @@ -6495,7 +6499,7 @@ parent - 1949 + 1951 idx @@ -6513,7 +6517,7 @@ 1 2 - 8688 + 8690 @@ -6529,7 +6533,7 @@ 1 2 - 8688 + 8690 @@ -6545,7 +6549,7 @@ 1 2 - 8688 + 8690 @@ -6559,8 +6563,8 @@ 12 - 278 - 279 + 280 + 281 1 @@ -6595,8 +6599,8 @@ 12 - 194 - 195 + 196 + 197 1 @@ -6669,7 +6673,7 @@ 1 2 - 1458 + 1460 2 @@ -6705,7 +6709,7 @@ 1 2 - 1461 + 1463 2 @@ -6741,7 +6745,7 @@ 1 2 - 1458 + 1460 2 @@ -6826,7 +6830,7 @@ 323 - 1950 + 1952 7 @@ -6928,7 +6932,7 @@ 323 - 1950 + 1952 7 @@ -6939,19 +6943,19 @@ specs - 7885 + 7889 id - 7885 + 7889 kind - 3 + 4 parent - 3875 + 3877 idx @@ -6969,7 +6973,7 @@ 1 2 - 7885 + 7889 @@ -6985,7 +6989,7 @@ 1 2 - 7885 + 7889 @@ -7001,7 +7005,7 @@ 1 2 - 7885 + 7889 @@ -7015,18 +7019,23 @@ 12 - 1365 - 1366 + 16 + 17 1 - 3054 - 3055 + 1349 + 1350 1 - 3466 - 3467 + 3056 + 3057 + 1 + + + 3468 + 3469 1 @@ -7040,19 +7049,24 @@ 12 + + 16 + 17 + 1 + 479 480 1 - 1349 - 1350 + 1333 + 1334 1 - 2047 - 2048 + 2049 + 2050 1 @@ -7066,6 +7080,11 @@ 12 + + 1 + 2 + 1 + 14 15 @@ -7095,12 +7114,12 @@ 1 2 - 3205 + 3206 2 6 - 342 + 343 6 @@ -7126,7 +7145,7 @@ 1 2 - 3875 + 3877 @@ -7142,12 +7161,12 @@ 1 2 - 3205 + 3206 2 6 - 342 + 343 6 @@ -7197,7 +7216,7 @@ 188 - 3876 + 3878 9 @@ -7224,7 +7243,12 @@ 3 4 - 14 + 13 + + + 4 + 5 + 1 @@ -7264,7 +7288,7 @@ 188 - 3876 + 3878 9 @@ -7275,11 +7299,11 @@ scopes - 36767 + 36770 id - 36767 + 36770 kind @@ -7297,7 +7321,7 @@ 1 2 - 36767 + 36770 @@ -7316,13 +7340,13 @@ 1 - 342 - 343 + 341 + 342 1 - 36424 - 36425 + 36428 + 36429 1 @@ -7333,15 +7357,15 @@ scopenesting - 36766 + 36769 inner - 36766 + 36769 outer - 21710 + 21713 @@ -7355,7 +7379,7 @@ 1 2 - 36766 + 36769 @@ -7371,12 +7395,12 @@ 1 2 - 16962 + 16964 2 3 - 2473 + 2474 3 @@ -7385,7 +7409,7 @@ 7 - 343 + 342 516 @@ -7396,15 +7420,15 @@ scopenodes - 36424 + 36428 node - 36424 + 36428 scope - 36424 + 36428 @@ -7418,7 +7442,7 @@ 1 2 - 36424 + 36428 @@ -7434,7 +7458,7 @@ 1 2 - 36424 + 36428 @@ -7444,11 +7468,11 @@ objects - 83210 + 83171 id - 83210 + 83171 kind @@ -7456,7 +7480,7 @@ name - 29409 + 29534 @@ -7470,7 +7494,7 @@ 1 2 - 83210 + 83171 @@ -7486,7 +7510,7 @@ 1 2 - 83210 + 83171 @@ -7520,28 +7544,28 @@ 1 - 3466 - 3467 + 3468 + 3469 1 - 3526 - 3527 + 3499 + 3500 1 - 8262 - 8263 + 8489 + 8490 1 - 17441 - 17442 + 17257 + 17258 1 - 50424 - 50425 + 50367 + 50368 1 @@ -7581,23 +7605,23 @@ 1 - 2937 - 2938 + 2924 + 2925 1 - 7822 - 7823 + 8048 + 8049 1 - 9789 - 9790 + 9833 + 9834 1 - 10708 - 10709 + 10579 + 10580 1 @@ -7614,22 +7638,22 @@ 1 2 - 24165 + 24323 2 3 - 2593 + 2561 3 17 - 2228 + 2229 17 - 2198 - 423 + 2197 + 421 @@ -7645,12 +7669,12 @@ 1 2 - 27682 + 27802 2 6 - 1727 + 1732 @@ -7660,15 +7684,15 @@ objectscopes - 53810 + 53877 object - 53810 + 53877 scope - 13943 + 13942 @@ -7682,7 +7706,7 @@ 1 2 - 53810 + 53877 @@ -7698,7 +7722,7 @@ 1 2 - 7114 + 7112 2 @@ -7708,7 +7732,7 @@ 3 4 - 1275 + 1276 4 @@ -7722,7 +7746,7 @@ 15 - 2484 + 2520 266 @@ -7733,15 +7757,15 @@ objecttypes - 83208 + 83169 object - 83208 + 83169 tp - 13063 + 13062 @@ -7755,7 +7779,7 @@ 1 2 - 83208 + 83169 @@ -7771,32 +7795,32 @@ 1 2 - 7609 + 7630 2 3 - 2069 + 2070 3 4 - 872 + 862 4 7 - 1156 + 1150 7 - 24 - 983 + 25 + 993 - 24 - 4235 - 374 + 25 + 4231 + 357 @@ -7806,15 +7830,15 @@ methodreceivers - 9670 + 9624 method - 9670 + 9624 receiver - 9670 + 9624 @@ -7828,7 +7852,7 @@ 1 2 - 9670 + 9624 @@ -7844,7 +7868,7 @@ 1 2 - 9670 + 9624 @@ -7854,11 +7878,11 @@ fieldstructs - 10605 + 10591 field - 10605 + 10591 struct @@ -7876,7 +7900,7 @@ 1 2 - 10605 + 10591 @@ -7892,37 +7916,37 @@ 1 2 - 251 + 249 2 3 - 660 + 664 3 4 - 450 + 446 4 5 - 284 + 286 5 6 - 191 + 192 6 8 - 200 + 203 8 13 - 194 + 190 13 @@ -7937,15 +7961,15 @@ methodhosts - 801 + 792 method - 681 + 672 host - 246 + 241 @@ -7959,7 +7983,7 @@ 1 2 - 619 + 610 2 @@ -7985,7 +8009,7 @@ 1 2 - 99 + 95 2 @@ -8005,7 +8029,7 @@ 5 6 - 16 + 15 6 @@ -8025,15 +8049,15 @@ defs - 40698 + 40703 ident - 40698 + 40703 object - 40485 + 40490 @@ -8047,7 +8071,7 @@ 1 2 - 40698 + 40703 @@ -8063,7 +8087,7 @@ 1 2 - 40378 + 40383 2 @@ -8078,15 +8102,15 @@ uses - 195872 + 195902 ident - 195872 + 195902 object - 41610 + 41616 @@ -8100,7 +8124,7 @@ 1 2 - 195872 + 195902 @@ -8116,32 +8140,32 @@ 1 2 - 15495 + 15493 2 3 - 9723 + 9727 3 4 - 5053 + 5056 4 5 - 2975 + 2974 5 7 - 3202 + 3203 7 14 - 3335 + 3336 14 @@ -8156,11 +8180,11 @@ types - 17636 + 17637 id - 17636 + 17637 kind @@ -8178,7 +8202,7 @@ 1 2 - 17636 + 17637 @@ -8202,8 +8226,8 @@ 3 - 237 - 418 + 232 + 417 3 @@ -8213,7 +8237,7 @@ 2339 - 7754 + 7773 3 @@ -8224,11 +8248,11 @@ type_of - 397900 + 397965 expr - 397900 + 397965 tp @@ -8246,7 +8270,7 @@ 1 2 - 397900 + 397965 @@ -8262,12 +8286,12 @@ 1 2 - 2011 + 2010 2 3 - 961 + 962 3 @@ -8282,7 +8306,7 @@ 5 7 - 784 + 783 7 @@ -8292,7 +8316,7 @@ 10 15 - 736 + 737 15 @@ -8311,7 +8335,7 @@ 150 - 46948 + 46949 303 @@ -8322,15 +8346,15 @@ typename - 3488 + 3471 tp - 3488 + 3471 name - 2909 + 2903 @@ -8344,7 +8368,7 @@ 1 2 - 3488 + 3471 @@ -8364,13 +8388,13 @@ 2 - 3 - 212 + 4 + 265 - 3 + 4 16 - 113 + 54 @@ -8380,11 +8404,11 @@ key_type - 417 + 416 map - 417 + 416 tp @@ -8402,7 +8426,7 @@ 1 2 - 417 + 416 @@ -8448,15 +8472,15 @@ element_type - 1374 + 1378 container - 1374 + 1378 tp - 889 + 892 @@ -8470,7 +8494,7 @@ 1 2 - 1374 + 1378 @@ -8486,7 +8510,7 @@ 1 2 - 753 + 756 2 @@ -8554,15 +8578,15 @@ underlying_type - 3488 + 3471 named - 3488 + 3471 tp - 2681 + 2677 @@ -8576,7 +8600,7 @@ 1 2 - 3488 + 3471 @@ -8592,12 +8616,12 @@ 1 2 - 2508 + 2505 2 - 150 - 173 + 148 + 172 @@ -8607,11 +8631,11 @@ component_types - 35096 + 35194 parent - 10884 + 10898 index @@ -8619,11 +8643,11 @@ name - 5292 + 5339 tp - 4184 + 4170 @@ -8637,7 +8661,7 @@ 1 2 - 1166 + 1157 2 @@ -8647,27 +8671,27 @@ 3 4 - 2795 + 2791 4 5 - 1374 + 1377 5 6 - 740 + 759 6 14 - 824 + 828 14 62 - 105 + 106 @@ -8683,22 +8707,22 @@ 1 2 - 8671 + 8684 2 3 - 708 + 712 3 6 - 977 + 975 6 61 - 528 + 527 @@ -8714,32 +8738,32 @@ 1 2 - 2237 + 2232 2 3 - 4333 + 4348 3 4 - 2373 + 2379 4 5 - 1065 + 1068 5 - 12 - 819 + 13 + 822 - 12 + 13 52 - 57 + 49 @@ -8769,48 +8793,48 @@ 6 - 12 + 11 6 - 12 - 18 + 11 + 17 + 5 + + + 17 + 23 6 - 18 - 26 + 24 + 42 6 - 26 - 47 + 47 + 70 6 - 51 - 82 + 81 + 152 6 - 90 - 185 + 186 + 490 6 - 227 - 793 + 794 + 5839 6 - 1448 - 6238 - 6 - - - 9957 - 9958 - 1 + 6255 + 9984 + 2 @@ -8839,39 +8863,39 @@ 6 - 10 - 16 + 9 + 15 5 - 17 - 23 - 6 + 16 + 22 + 5 - 23 - 35 + 22 + 33 6 36 - 67 + 59 6 - 76 - 142 + 66 + 112 6 - 167 - 449 + 143 + 355 6 - 595 - 1217 - 5 + 455 + 1228 + 6 @@ -8901,49 +8925,49 @@ 6 - 9 + 8 6 - 10 + 9 14 - 4 + 6 14 18 - 4 - - - 18 - 21 6 - 23 - 32 + 18 + 28 6 32 - 48 - 5 - - - 51 - 102 + 46 6 - 116 - 294 + 47 + 84 6 - 453 - 2093 + 103 + 216 6 + + 297 + 1836 + 6 + + + 2095 + 2096 + 1 + @@ -8958,22 +8982,22 @@ 1 2 - 3693 + 3760 2 3 - 864 + 847 3 5 - 414 + 406 5 - 8652 - 321 + 8671 + 326 @@ -8989,22 +9013,22 @@ 1 2 - 4093 + 4133 2 3 - 699 + 704 3 6 - 422 + 423 6 28 - 78 + 79 @@ -9020,22 +9044,22 @@ 1 2 - 4385 + 4427 2 3 - 496 + 498 3 16 - 397 + 401 16 - 2944 - 14 + 2936 + 13 @@ -9056,27 +9080,27 @@ 2 3 - 815 + 795 3 4 - 392 + 400 4 6 - 376 + 374 6 11 - 329 + 330 11 - 2102 - 280 + 2115 + 279 @@ -9092,27 +9116,27 @@ 1 2 - 2048 + 2042 2 3 - 846 + 836 3 4 - 559 + 561 4 5 - 346 + 347 5 10 - 325 + 324 10 @@ -9133,12 +9157,12 @@ 1 2 - 2823 + 2808 2 3 - 840 + 841 3 @@ -9147,7 +9171,7 @@ 5 - 677 + 679 188 @@ -9158,15 +9182,15 @@ array_length - 284 + 292 tp - 284 + 292 len - 99 + 103 @@ -9180,7 +9204,7 @@ 1 2 - 284 + 292 @@ -9196,32 +9220,32 @@ 1 2 - 59 + 62 2 3 - 14 + 16 3 - 4 + 5 8 - 4 - 7 + 5 + 8 8 - 7 - 15 + 10 + 16 8 - 15 - 26 - 2 + 26 + 27 + 1 @@ -9231,15 +9255,15 @@ type_objects - 3488 + 3471 tp - 3488 + 3471 object - 3488 + 3471 @@ -9253,7 +9277,7 @@ 1 2 - 3488 + 3471 @@ -9269,7 +9293,7 @@ 1 2 - 3488 + 3471 @@ -9279,23 +9303,23 @@ packages - 342 + 341 id - 342 + 341 name - 277 + 276 path - 342 + 341 scope - 342 + 341 @@ -9309,7 +9333,7 @@ 1 2 - 342 + 341 @@ -9325,7 +9349,7 @@ 1 2 - 342 + 341 @@ -9341,7 +9365,7 @@ 1 2 - 342 + 341 @@ -9357,7 +9381,7 @@ 1 2 - 251 + 250 2 @@ -9383,7 +9407,7 @@ 1 2 - 251 + 250 2 @@ -9409,7 +9433,7 @@ 1 2 - 251 + 250 2 @@ -9435,7 +9459,7 @@ 1 2 - 342 + 341 @@ -9451,7 +9475,7 @@ 1 2 - 342 + 341 @@ -9467,7 +9491,7 @@ 1 2 - 342 + 341 @@ -9483,7 +9507,7 @@ 1 2 - 342 + 341 @@ -9499,7 +9523,7 @@ 1 2 - 342 + 341 @@ -9515,7 +9539,7 @@ 1 2 - 342 + 341 diff --git a/ql/src/semmle/go/Decls.qll b/ql/src/semmle/go/Decls.qll index 031a287f757..205c666b210 100644 --- a/ql/src/semmle/go/Decls.qll +++ b/ql/src/semmle/go/Decls.qll @@ -371,7 +371,16 @@ class ValueSpec extends @valuespec, Spec { } /** - * A type declaration specifier. + * A type declaration specifier, which is either a type definition or an alias declaration. + * + * Examples: + * + * ``` + * type ( + * status int + * intlist = []int + * ) + * ``` */ class TypeSpec extends @typespec, Spec { /** Gets the identifier denoting the name of the declared type. */ @@ -380,7 +389,9 @@ class TypeSpec extends @typespec, Spec { /** Gets the name of the declared type. */ string getName() { result = getNameExpr().getName() } - /** Gets the expression denoting the underlying type to which the newly declared type is aliased. */ + /** + * Gets the expression denoting the underlying type to which the newly declared type is bound. + */ Expr getTypeExpr() { result = getChildExpr(1) } override string toString() { result = "type declaration specifier" } @@ -388,6 +399,28 @@ class TypeSpec extends @typespec, Spec { override string getAPrimaryQlClass() { result = "TypeSpec" } } +/** + * An alias declaration specifier. + * + * Examples: + * + * ``` + * type intlist = []int + * ``` + */ +class AliasSpec extends @aliasspec, TypeSpec { } + +/** + * A type definition specifier. + * + * Examples: + * + * ``` + * type status int + * ``` + */ +class TypeDefSpec extends @typedefspec, TypeSpec { } + /** * A field declaration, of a struct, a function (in which case this is a parameter or result variable), * or an interface (in which case this is a method or embedding spec). diff --git a/ql/test/library-tests/semmle/go/Decl/TypeSpec.expected b/ql/test/library-tests/semmle/go/Decl/TypeSpec.expected new file mode 100644 index 00000000000..73f614a03f1 --- /dev/null +++ b/ql/test/library-tests/semmle/go/Decl/TypeSpec.expected @@ -0,0 +1,2 @@ +| main.go:3:6:3:15 | type declaration specifier | status | int | def | +| main.go:5:6:5:20 | type declaration specifier | intlist | []int | alias | diff --git a/ql/test/library-tests/semmle/go/Decl/TypeSpec.ql b/ql/test/library-tests/semmle/go/Decl/TypeSpec.ql new file mode 100644 index 00000000000..70a527d311c --- /dev/null +++ b/ql/test/library-tests/semmle/go/Decl/TypeSpec.ql @@ -0,0 +1,5 @@ +import go + +from TypeSpec ts, string kind +where if ts instanceof AliasSpec then kind = "alias" else kind = "def" +select ts, ts.getName(), ts.getTypeExpr().getType().pp(), kind diff --git a/ql/test/library-tests/semmle/go/Decl/main.go b/ql/test/library-tests/semmle/go/Decl/main.go new file mode 100644 index 00000000000..dfd449d5476 --- /dev/null +++ b/ql/test/library-tests/semmle/go/Decl/main.go @@ -0,0 +1,5 @@ +package main + +type status int + +type intlist = []int diff --git a/upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/go.dbscheme b/upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/go.dbscheme new file mode 100644 index 00000000000..bcbec1b0e44 --- /dev/null +++ b/upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/go.dbscheme @@ -0,0 +1,434 @@ +/** Auto-generated dbscheme; do not edit. */ + + +/** Duplicate code **/ + +duplicateCode( + unique int id : @duplication, + varchar(900) relativePath : string ref, + int equivClass : int ref); + +similarCode( + unique int id : @similarity, + varchar(900) relativePath : string ref, + int equivClass : int ref); + +@duplication_or_similarity = @duplication | @similarity; + +tokens( + int id : @duplication_or_similarity ref, + int offset : int ref, + int beginLine : int ref, + int beginColumn : int ref, + int endLine : int ref, + int endColumn : int ref); + +/** External data **/ + +externalData( + int id : @externalDataElement, + varchar(900) path : string ref, + int column: int ref, + varchar(900) value : string ref +); + +snapshotDate(unique date snapshotDate : date ref); + +sourceLocationPrefix(varchar(900) prefix : string ref); + +locations_default(unique int id: @location_default, int file: @file ref, int beginLine: int ref, int beginColumn: int ref, + int endLine: int ref, int endColumn: int ref); + +numlines(int element_id: @sourceline ref, int num_lines: int ref, int num_code: int ref, int num_comment: int ref); + +files(unique int id: @file, string name: string ref, string simple: string ref, string ext: string ref, int fromSource: int ref); + +folders(unique int id: @folder, string name: string ref, string simple: string ref); + +containerparent(int parent: @container ref, unique int child: @container ref); + +has_location(unique int locatable: @locatable ref, int location: @location ref); + +#keyset[parent, idx] +comment_groups(unique int id: @comment_group, int parent: @file ref, int idx: int ref); + +comments(unique int id: @comment, int kind: int ref, int parent: @comment_group ref, int idx: int ref, string text: string ref); + +doc_comments(unique int node: @documentable ref, int comment: @comment_group ref); + +#keyset[parent, idx] +exprs(unique int id: @expr, int kind: int ref, int parent: @exprparent ref, int idx: int ref); + +literals(unique int expr: @expr ref, string value: string ref, string raw: string ref); + +constvalues(unique int expr: @expr ref, string value: string ref, string exact: string ref); + +fields(unique int id: @field, int parent: @fieldparent ref, int idx: int ref); + +#keyset[parent, idx] +stmts(unique int id: @stmt, int kind: int ref, int parent: @stmtparent ref, int idx: int ref); + +#keyset[parent, idx] +decls(unique int id: @decl, int kind: int ref, int parent: @declparent ref, int idx: int ref); + +#keyset[parent, idx] +specs(unique int id: @spec, int kind: int ref, int parent: @gendecl ref, int idx: int ref); + +scopes(unique int id: @scope, int kind: int ref); + +scopenesting(unique int inner: @scope ref, int outer: @scope ref); + +scopenodes(unique int node: @scopenode ref, int scope: @localscope ref); + +objects(unique int id: @object, int kind: int ref, string name: string ref); + +objectscopes(unique int object: @object ref, int scope: @scope ref); + +objecttypes(unique int object: @object ref, int tp: @type ref); + +methodreceivers(unique int method: @object ref, int receiver: @object ref); + +fieldstructs(unique int field: @object ref, int struct: @structtype ref); + +methodhosts(int method: @object ref, int host: @namedtype ref); + +defs(int ident: @ident ref, int object: @object ref); + +uses(int ident: @ident ref, int object: @object ref); + +types(unique int id: @type, int kind: int ref); + +type_of(unique int expr: @expr ref, int tp: @type ref); + +typename(unique int tp: @type ref, string name: string ref); + +key_type(unique int map: @maptype ref, int tp: @type ref); + +element_type(unique int container: @containertype ref, int tp: @type ref); + +base_type(unique int ptr: @pointertype ref, int tp: @type ref); + +underlying_type(unique int named: @namedtype ref, int tp: @type ref); + +#keyset[parent, index] +component_types(int parent: @compositetype ref, int index: int ref, string name: string ref, int tp: @type ref); + +array_length(unique int tp: @arraytype ref, string len: string ref); + +type_objects(unique int tp: @type ref, int object: @object ref); + +packages(unique int id: @package, string name: string ref, string path: string ref, int scope: @packagescope ref); + +#keyset[parent, idx] +modexprs(unique int id: @modexpr, int kind: int ref, int parent: @modexprparent ref, int idx: int ref); + +#keyset[parent, idx] +modtokens(string token: string ref, int parent: @modexpr ref, int idx: int ref); + +#keyset[package, idx] +errors(unique int id: @error, int kind: int ref, string msg: string ref, string rawpos: string ref, + string file: string ref, int line: int ref, int col: int ref, int package: @package ref, int idx: int ref); + +@container = @file | @folder; + +@locatable = @node | @localscope; + +@node = @documentable | @exprparent | @modexprparent | @fieldparent | @stmtparent | @declparent | @scopenode + | @comment_group | @comment; + +@documentable = @file | @field | @spec | @gendecl | @funcdecl | @modexpr; + +@exprparent = @funcdef | @file | @expr | @field | @stmt | @decl | @spec; + +@modexprparent = @file | @modexpr; + +@fieldparent = @decl | @structtypeexpr | @functypeexpr | @interfacetypeexpr; + +@stmtparent = @funcdef | @stmt | @decl; + +@declparent = @file | @declstmt; + +@funcdef = @funclit | @funcdecl; + +@scopenode = @file | @functypeexpr | @blockstmt | @ifstmt | @caseclause | @switchstmt | @commclause | @loopstmt; + +@location = @location_default; + +@sourceline = @locatable; + +case @comment.kind of + 0 = @slashslashcomment +| 1 = @slashstarcomment; + +case @expr.kind of + 0 = @badexpr +| 1 = @ident +| 2 = @ellipsis +| 3 = @intlit +| 4 = @floatlit +| 5 = @imaglit +| 6 = @charlit +| 7 = @stringlit +| 8 = @funclit +| 9 = @compositelit +| 10 = @parenexpr +| 11 = @selectorexpr +| 12 = @indexexpr +| 13 = @sliceexpr +| 14 = @typeassertexpr +| 15 = @callorconversionexpr +| 16 = @starexpr +| 17 = @keyvalueexpr +| 18 = @arraytypeexpr +| 19 = @structtypeexpr +| 20 = @functypeexpr +| 21 = @interfacetypeexpr +| 22 = @maptypeexpr +| 23 = @plusexpr +| 24 = @minusexpr +| 25 = @notexpr +| 26 = @complementexpr +| 27 = @derefexpr +| 28 = @addressexpr +| 29 = @arrowexpr +| 30 = @lorexpr +| 31 = @landexpr +| 32 = @eqlexpr +| 33 = @neqexpr +| 34 = @lssexpr +| 35 = @leqexpr +| 36 = @gtrexpr +| 37 = @geqexpr +| 38 = @addexpr +| 39 = @subexpr +| 40 = @orexpr +| 41 = @xorexpr +| 42 = @mulexpr +| 43 = @quoexpr +| 44 = @remexpr +| 45 = @shlexpr +| 46 = @shrexpr +| 47 = @andexpr +| 48 = @andnotexpr +| 49 = @sendchantypeexpr +| 50 = @recvchantypeexpr +| 51 = @sendrcvchantypeexpr; + +@basiclit = @intlit | @floatlit | @imaglit | @charlit | @stringlit; + +@operatorexpr = @logicalexpr | @arithmeticexpr | @bitwiseexpr | @unaryexpr | @binaryexpr; + +@logicalexpr = @logicalunaryexpr | @logicalbinaryexpr; + +@arithmeticexpr = @arithmeticunaryexpr | @arithmeticbinaryexpr; + +@bitwiseexpr = @bitwiseunaryexpr | @bitwisebinaryexpr; + +@unaryexpr = @logicalunaryexpr | @bitwiseunaryexpr | @arithmeticunaryexpr | @derefexpr | @addressexpr | @arrowexpr; + +@logicalunaryexpr = @notexpr; + +@bitwiseunaryexpr = @complementexpr; + +@arithmeticunaryexpr = @plusexpr | @minusexpr; + +@binaryexpr = @logicalbinaryexpr | @bitwisebinaryexpr | @arithmeticbinaryexpr | @comparison; + +@logicalbinaryexpr = @lorexpr | @landexpr; + +@bitwisebinaryexpr = @shiftexpr | @orexpr | @xorexpr | @andexpr | @andnotexpr; + +@arithmeticbinaryexpr = @addexpr | @subexpr | @mulexpr | @quoexpr | @remexpr; + +@shiftexpr = @shlexpr | @shrexpr; + +@comparison = @equalitytest | @relationalcomparison; + +@equalitytest = @eqlexpr | @neqexpr; + +@relationalcomparison = @lssexpr | @leqexpr | @gtrexpr | @geqexpr; + +@chantypeexpr = @sendchantypeexpr | @recvchantypeexpr | @sendrcvchantypeexpr; + +case @stmt.kind of + 0 = @badstmt +| 1 = @declstmt +| 2 = @emptystmt +| 3 = @labeledstmt +| 4 = @exprstmt +| 5 = @sendstmt +| 6 = @incstmt +| 7 = @decstmt +| 8 = @gostmt +| 9 = @deferstmt +| 10 = @returnstmt +| 11 = @breakstmt +| 12 = @continuestmt +| 13 = @gotostmt +| 14 = @fallthroughstmt +| 15 = @blockstmt +| 16 = @ifstmt +| 17 = @caseclause +| 18 = @exprswitchstmt +| 19 = @typeswitchstmt +| 20 = @commclause +| 21 = @selectstmt +| 22 = @forstmt +| 23 = @rangestmt +| 24 = @assignstmt +| 25 = @definestmt +| 26 = @addassignstmt +| 27 = @subassignstmt +| 28 = @mulassignstmt +| 29 = @quoassignstmt +| 30 = @remassignstmt +| 31 = @andassignstmt +| 32 = @orassignstmt +| 33 = @xorassignstmt +| 34 = @shlassignstmt +| 35 = @shrassignstmt +| 36 = @andnotassignstmt; + +@incdecstmt = @incstmt | @decstmt; + +@assignment = @simpleassignstmt | @compoundassignstmt; + +@simpleassignstmt = @assignstmt | @definestmt; + +@compoundassignstmt = @addassignstmt | @subassignstmt | @mulassignstmt | @quoassignstmt | @remassignstmt + | @andassignstmt | @orassignstmt | @xorassignstmt | @shlassignstmt | @shrassignstmt | @andnotassignstmt; + +@branchstmt = @breakstmt | @continuestmt | @gotostmt | @fallthroughstmt; + +@switchstmt = @exprswitchstmt | @typeswitchstmt; + +@loopstmt = @forstmt | @rangestmt; + +case @decl.kind of + 0 = @baddecl +| 1 = @importdecl +| 2 = @constdecl +| 3 = @typedecl +| 4 = @vardecl +| 5 = @funcdecl; + +@gendecl = @importdecl | @constdecl | @typedecl | @vardecl; + +case @spec.kind of + 0 = @importspec +| 1 = @valuespec +| 2 = @typedefspec +| 3 = @aliasspec; + +@typespec = @typedefspec | @aliasspec; + +case @object.kind of + 0 = @pkgobject +| 1 = @decltypeobject +| 2 = @builtintypeobject +| 3 = @declconstobject +| 4 = @builtinconstobject +| 5 = @declvarobject +| 6 = @declfunctionobject +| 7 = @builtinfunctionobject +| 8 = @labelobject; + +@declobject = @decltypeobject | @declconstobject | @declvarobject | @declfunctionobject; + +@builtinobject = @builtintypeobject | @builtinconstobject | @builtinfunctionobject; + +@typeobject = @decltypeobject | @builtintypeobject; + +@valueobject = @constobject | @varobject | @functionobject; + +@constobject = @declconstobject | @builtinconstobject; + +@varobject = @declvarobject; + +@functionobject = @declfunctionobject | @builtinfunctionobject; + +case @scope.kind of + 0 = @universescope +| 1 = @packagescope +| 2 = @localscope; + +case @type.kind of + 0 = @invalidtype +| 1 = @boolexprtype +| 2 = @inttype +| 3 = @int8type +| 4 = @int16type +| 5 = @int32type +| 6 = @int64type +| 7 = @uinttype +| 8 = @uint8type +| 9 = @uint16type +| 10 = @uint32type +| 11 = @uint64type +| 12 = @uintptrtype +| 13 = @float32type +| 14 = @float64type +| 15 = @complex64type +| 16 = @complex128type +| 17 = @stringexprtype +| 18 = @unsafepointertype +| 19 = @boolliteraltype +| 20 = @intliteraltype +| 21 = @runeliteraltype +| 22 = @floatliteraltype +| 23 = @complexliteraltype +| 24 = @stringliteraltype +| 25 = @nilliteraltype +| 26 = @arraytype +| 27 = @slicetype +| 28 = @structtype +| 29 = @pointertype +| 30 = @interfacetype +| 31 = @tupletype +| 32 = @signaturetype +| 33 = @maptype +| 34 = @sendchantype +| 35 = @recvchantype +| 36 = @sendrcvchantype +| 37 = @namedtype; + +@basictype = @booltype | @numerictype | @stringtype | @literaltype | @invalidtype | @unsafepointertype; + +@booltype = @boolexprtype | @boolliteraltype; + +@numerictype = @integertype | @floattype | @complextype; + +@integertype = @signedintegertype | @unsignedintegertype; + +@signedintegertype = @inttype | @int8type | @int16type | @int32type | @int64type | @intliteraltype | @runeliteraltype; + +@unsignedintegertype = @uinttype | @uint8type | @uint16type | @uint32type | @uint64type | @uintptrtype; + +@floattype = @float32type | @float64type | @floatliteraltype; + +@complextype = @complex64type | @complex128type | @complexliteraltype; + +@stringtype = @stringexprtype | @stringliteraltype; + +@literaltype = @boolliteraltype | @intliteraltype | @runeliteraltype | @floatliteraltype | @complexliteraltype + | @stringliteraltype | @nilliteraltype; + +@compositetype = @containertype | @structtype | @pointertype | @interfacetype | @tupletype | @signaturetype | @namedtype; + +@containertype = @arraytype | @slicetype | @maptype | @chantype; + +@chantype = @sendchantype | @recvchantype | @sendrcvchantype; + +case @modexpr.kind of + 0 = @modcommentblock +| 1 = @modline +| 2 = @modlineblock +| 3 = @modlparen +| 4 = @modrparen; + +case @error.kind of + 0 = @unknownerror +| 1 = @listerror +| 2 = @parseerror +| 3 = @typeerror; + diff --git a/upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/old.dbscheme b/upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/old.dbscheme new file mode 100644 index 00000000000..bcb9599aba6 --- /dev/null +++ b/upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/old.dbscheme @@ -0,0 +1,431 @@ +/** Auto-generated dbscheme; do not edit. */ + + +/** Duplicate code **/ + +duplicateCode( + unique int id : @duplication, + varchar(900) relativePath : string ref, + int equivClass : int ref); + +similarCode( + unique int id : @similarity, + varchar(900) relativePath : string ref, + int equivClass : int ref); + +@duplication_or_similarity = @duplication | @similarity; + +tokens( + int id : @duplication_or_similarity ref, + int offset : int ref, + int beginLine : int ref, + int beginColumn : int ref, + int endLine : int ref, + int endColumn : int ref); + +/** External data **/ + +externalData( + int id : @externalDataElement, + varchar(900) path : string ref, + int column: int ref, + varchar(900) value : string ref +); + +snapshotDate(unique date snapshotDate : date ref); + +sourceLocationPrefix(varchar(900) prefix : string ref); + +locations_default(unique int id: @location_default, int file: @file ref, int beginLine: int ref, int beginColumn: int ref, + int endLine: int ref, int endColumn: int ref); + +numlines(int element_id: @sourceline ref, int num_lines: int ref, int num_code: int ref, int num_comment: int ref); + +files(unique int id: @file, string name: string ref, string simple: string ref, string ext: string ref, int fromSource: int ref); + +folders(unique int id: @folder, string name: string ref, string simple: string ref); + +containerparent(int parent: @container ref, unique int child: @container ref); + +has_location(unique int locatable: @locatable ref, int location: @location ref); + +#keyset[parent, idx] +comment_groups(unique int id: @comment_group, int parent: @file ref, int idx: int ref); + +comments(unique int id: @comment, int kind: int ref, int parent: @comment_group ref, int idx: int ref, string text: string ref); + +doc_comments(unique int node: @documentable ref, int comment: @comment_group ref); + +#keyset[parent, idx] +exprs(unique int id: @expr, int kind: int ref, int parent: @exprparent ref, int idx: int ref); + +literals(unique int expr: @expr ref, string value: string ref, string raw: string ref); + +constvalues(unique int expr: @expr ref, string value: string ref, string exact: string ref); + +fields(unique int id: @field, int parent: @fieldparent ref, int idx: int ref); + +#keyset[parent, idx] +stmts(unique int id: @stmt, int kind: int ref, int parent: @stmtparent ref, int idx: int ref); + +#keyset[parent, idx] +decls(unique int id: @decl, int kind: int ref, int parent: @declparent ref, int idx: int ref); + +#keyset[parent, idx] +specs(unique int id: @spec, int kind: int ref, int parent: @gendecl ref, int idx: int ref); + +scopes(unique int id: @scope, int kind: int ref); + +scopenesting(unique int inner: @scope ref, int outer: @scope ref); + +scopenodes(unique int node: @scopenode ref, int scope: @localscope ref); + +objects(unique int id: @object, int kind: int ref, string name: string ref); + +objectscopes(unique int object: @object ref, int scope: @scope ref); + +objecttypes(unique int object: @object ref, int tp: @type ref); + +methodreceivers(unique int method: @object ref, int receiver: @object ref); + +fieldstructs(unique int field: @object ref, int struct: @structtype ref); + +methodhosts(int method: @object ref, int host: @namedtype ref); + +defs(int ident: @ident ref, int object: @object ref); + +uses(int ident: @ident ref, int object: @object ref); + +types(unique int id: @type, int kind: int ref); + +type_of(unique int expr: @expr ref, int tp: @type ref); + +typename(unique int tp: @type ref, string name: string ref); + +key_type(unique int map: @maptype ref, int tp: @type ref); + +element_type(unique int container: @containertype ref, int tp: @type ref); + +base_type(unique int ptr: @pointertype ref, int tp: @type ref); + +underlying_type(unique int named: @namedtype ref, int tp: @type ref); + +#keyset[parent, index] +component_types(int parent: @compositetype ref, int index: int ref, string name: string ref, int tp: @type ref); + +array_length(unique int tp: @arraytype ref, string len: string ref); + +type_objects(unique int tp: @type ref, int object: @object ref); + +packages(unique int id: @package, string name: string ref, string path: string ref, int scope: @packagescope ref); + +#keyset[parent, idx] +modexprs(unique int id: @modexpr, int kind: int ref, int parent: @modexprparent ref, int idx: int ref); + +#keyset[parent, idx] +modtokens(string token: string ref, int parent: @modexpr ref, int idx: int ref); + +#keyset[package, idx] +errors(unique int id: @error, int kind: int ref, string msg: string ref, string rawpos: string ref, + string file: string ref, int line: int ref, int col: int ref, int package: @package ref, int idx: int ref); + +@container = @file | @folder; + +@locatable = @node | @localscope; + +@node = @documentable | @exprparent | @modexprparent | @fieldparent | @stmtparent | @declparent | @scopenode + | @comment_group | @comment; + +@documentable = @file | @field | @spec | @gendecl | @funcdecl | @modexpr; + +@exprparent = @funcdef | @file | @expr | @field | @stmt | @decl | @spec; + +@modexprparent = @file | @modexpr; + +@fieldparent = @decl | @structtypeexpr | @functypeexpr | @interfacetypeexpr; + +@stmtparent = @funcdef | @stmt | @decl; + +@declparent = @file | @declstmt; + +@funcdef = @funclit | @funcdecl; + +@scopenode = @file | @functypeexpr | @blockstmt | @ifstmt | @caseclause | @switchstmt | @commclause | @loopstmt; + +@location = @location_default; + +@sourceline = @locatable; + +case @comment.kind of + 0 = @slashslashcomment +| 1 = @slashstarcomment; + +case @expr.kind of + 0 = @badexpr +| 1 = @ident +| 2 = @ellipsis +| 3 = @intlit +| 4 = @floatlit +| 5 = @imaglit +| 6 = @charlit +| 7 = @stringlit +| 8 = @funclit +| 9 = @compositelit +| 10 = @parenexpr +| 11 = @selectorexpr +| 12 = @indexexpr +| 13 = @sliceexpr +| 14 = @typeassertexpr +| 15 = @callorconversionexpr +| 16 = @starexpr +| 17 = @keyvalueexpr +| 18 = @arraytypeexpr +| 19 = @structtypeexpr +| 20 = @functypeexpr +| 21 = @interfacetypeexpr +| 22 = @maptypeexpr +| 23 = @plusexpr +| 24 = @minusexpr +| 25 = @notexpr +| 26 = @complementexpr +| 27 = @derefexpr +| 28 = @addressexpr +| 29 = @arrowexpr +| 30 = @lorexpr +| 31 = @landexpr +| 32 = @eqlexpr +| 33 = @neqexpr +| 34 = @lssexpr +| 35 = @leqexpr +| 36 = @gtrexpr +| 37 = @geqexpr +| 38 = @addexpr +| 39 = @subexpr +| 40 = @orexpr +| 41 = @xorexpr +| 42 = @mulexpr +| 43 = @quoexpr +| 44 = @remexpr +| 45 = @shlexpr +| 46 = @shrexpr +| 47 = @andexpr +| 48 = @andnotexpr +| 49 = @sendchantypeexpr +| 50 = @recvchantypeexpr +| 51 = @sendrcvchantypeexpr; + +@basiclit = @intlit | @floatlit | @imaglit | @charlit | @stringlit; + +@operatorexpr = @logicalexpr | @arithmeticexpr | @bitwiseexpr | @unaryexpr | @binaryexpr; + +@logicalexpr = @logicalunaryexpr | @logicalbinaryexpr; + +@arithmeticexpr = @arithmeticunaryexpr | @arithmeticbinaryexpr; + +@bitwiseexpr = @bitwiseunaryexpr | @bitwisebinaryexpr; + +@unaryexpr = @logicalunaryexpr | @bitwiseunaryexpr | @arithmeticunaryexpr | @derefexpr | @addressexpr | @arrowexpr; + +@logicalunaryexpr = @notexpr; + +@bitwiseunaryexpr = @complementexpr; + +@arithmeticunaryexpr = @plusexpr | @minusexpr; + +@binaryexpr = @logicalbinaryexpr | @bitwisebinaryexpr | @arithmeticbinaryexpr | @comparison; + +@logicalbinaryexpr = @lorexpr | @landexpr; + +@bitwisebinaryexpr = @shiftexpr | @orexpr | @xorexpr | @andexpr | @andnotexpr; + +@arithmeticbinaryexpr = @addexpr | @subexpr | @mulexpr | @quoexpr | @remexpr; + +@shiftexpr = @shlexpr | @shrexpr; + +@comparison = @equalitytest | @relationalcomparison; + +@equalitytest = @eqlexpr | @neqexpr; + +@relationalcomparison = @lssexpr | @leqexpr | @gtrexpr | @geqexpr; + +@chantypeexpr = @sendchantypeexpr | @recvchantypeexpr | @sendrcvchantypeexpr; + +case @stmt.kind of + 0 = @badstmt +| 1 = @declstmt +| 2 = @emptystmt +| 3 = @labeledstmt +| 4 = @exprstmt +| 5 = @sendstmt +| 6 = @incstmt +| 7 = @decstmt +| 8 = @gostmt +| 9 = @deferstmt +| 10 = @returnstmt +| 11 = @breakstmt +| 12 = @continuestmt +| 13 = @gotostmt +| 14 = @fallthroughstmt +| 15 = @blockstmt +| 16 = @ifstmt +| 17 = @caseclause +| 18 = @exprswitchstmt +| 19 = @typeswitchstmt +| 20 = @commclause +| 21 = @selectstmt +| 22 = @forstmt +| 23 = @rangestmt +| 24 = @assignstmt +| 25 = @definestmt +| 26 = @addassignstmt +| 27 = @subassignstmt +| 28 = @mulassignstmt +| 29 = @quoassignstmt +| 30 = @remassignstmt +| 31 = @andassignstmt +| 32 = @orassignstmt +| 33 = @xorassignstmt +| 34 = @shlassignstmt +| 35 = @shrassignstmt +| 36 = @andnotassignstmt; + +@incdecstmt = @incstmt | @decstmt; + +@assignment = @simpleassignstmt | @compoundassignstmt; + +@simpleassignstmt = @assignstmt | @definestmt; + +@compoundassignstmt = @addassignstmt | @subassignstmt | @mulassignstmt | @quoassignstmt | @remassignstmt + | @andassignstmt | @orassignstmt | @xorassignstmt | @shlassignstmt | @shrassignstmt | @andnotassignstmt; + +@branchstmt = @breakstmt | @continuestmt | @gotostmt | @fallthroughstmt; + +@switchstmt = @exprswitchstmt | @typeswitchstmt; + +@loopstmt = @forstmt | @rangestmt; + +case @decl.kind of + 0 = @baddecl +| 1 = @importdecl +| 2 = @constdecl +| 3 = @typedecl +| 4 = @vardecl +| 5 = @funcdecl; + +@gendecl = @importdecl | @constdecl | @typedecl | @vardecl; + +case @spec.kind of + 0 = @importspec +| 1 = @valuespec +| 2 = @typespec; + +case @object.kind of + 0 = @pkgobject +| 1 = @decltypeobject +| 2 = @builtintypeobject +| 3 = @declconstobject +| 4 = @builtinconstobject +| 5 = @declvarobject +| 6 = @declfunctionobject +| 7 = @builtinfunctionobject +| 8 = @labelobject; + +@declobject = @decltypeobject | @declconstobject | @declvarobject | @declfunctionobject; + +@builtinobject = @builtintypeobject | @builtinconstobject | @builtinfunctionobject; + +@typeobject = @decltypeobject | @builtintypeobject; + +@valueobject = @constobject | @varobject | @functionobject; + +@constobject = @declconstobject | @builtinconstobject; + +@varobject = @declvarobject; + +@functionobject = @declfunctionobject | @builtinfunctionobject; + +case @scope.kind of + 0 = @universescope +| 1 = @packagescope +| 2 = @localscope; + +case @type.kind of + 0 = @invalidtype +| 1 = @boolexprtype +| 2 = @inttype +| 3 = @int8type +| 4 = @int16type +| 5 = @int32type +| 6 = @int64type +| 7 = @uinttype +| 8 = @uint8type +| 9 = @uint16type +| 10 = @uint32type +| 11 = @uint64type +| 12 = @uintptrtype +| 13 = @float32type +| 14 = @float64type +| 15 = @complex64type +| 16 = @complex128type +| 17 = @stringexprtype +| 18 = @unsafepointertype +| 19 = @boolliteraltype +| 20 = @intliteraltype +| 21 = @runeliteraltype +| 22 = @floatliteraltype +| 23 = @complexliteraltype +| 24 = @stringliteraltype +| 25 = @nilliteraltype +| 26 = @arraytype +| 27 = @slicetype +| 28 = @structtype +| 29 = @pointertype +| 30 = @interfacetype +| 31 = @tupletype +| 32 = @signaturetype +| 33 = @maptype +| 34 = @sendchantype +| 35 = @recvchantype +| 36 = @sendrcvchantype +| 37 = @namedtype; + +@basictype = @booltype | @numerictype | @stringtype | @literaltype | @invalidtype | @unsafepointertype; + +@booltype = @boolexprtype | @boolliteraltype; + +@numerictype = @integertype | @floattype | @complextype; + +@integertype = @signedintegertype | @unsignedintegertype; + +@signedintegertype = @inttype | @int8type | @int16type | @int32type | @int64type | @intliteraltype | @runeliteraltype; + +@unsignedintegertype = @uinttype | @uint8type | @uint16type | @uint32type | @uint64type | @uintptrtype; + +@floattype = @float32type | @float64type | @floatliteraltype; + +@complextype = @complex64type | @complex128type | @complexliteraltype; + +@stringtype = @stringexprtype | @stringliteraltype; + +@literaltype = @boolliteraltype | @intliteraltype | @runeliteraltype | @floatliteraltype | @complexliteraltype + | @stringliteraltype | @nilliteraltype; + +@compositetype = @containertype | @structtype | @pointertype | @interfacetype | @tupletype | @signaturetype | @namedtype; + +@containertype = @arraytype | @slicetype | @maptype | @chantype; + +@chantype = @sendchantype | @recvchantype | @sendrcvchantype; + +case @modexpr.kind of + 0 = @modcommentblock +| 1 = @modline +| 2 = @modlineblock +| 3 = @modlparen +| 4 = @modrparen; + +case @error.kind of + 0 = @unknownerror +| 1 = @listerror +| 2 = @parseerror +| 3 = @typeerror; + diff --git a/upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/upgrade.properties b/upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/upgrade.properties new file mode 100644 index 00000000000..13eb58608f5 --- /dev/null +++ b/upgrades/bcb9599aba6c9ac4d617fac314b9a999b3a5b40e/upgrade.properties @@ -0,0 +1,2 @@ +description: Extract more information about alias declarations +compatibility: backwards From 4eac5a1d4efc39ad9c22761bd7183ad05795817a Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Fri, 10 Jul 2020 14:39:59 +0100 Subject: [PATCH 3/3] Add test to demonstrate that aliases have entities. There are, however, no corresponding types. --- ql/test/library-tests/semmle/go/Decl/TypeEntities.expected | 2 ++ ql/test/library-tests/semmle/go/Decl/TypeEntities.ql | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 ql/test/library-tests/semmle/go/Decl/TypeEntities.expected create mode 100644 ql/test/library-tests/semmle/go/Decl/TypeEntities.ql diff --git a/ql/test/library-tests/semmle/go/Decl/TypeEntities.expected b/ql/test/library-tests/semmle/go/Decl/TypeEntities.expected new file mode 100644 index 00000000000..2de33d12407 --- /dev/null +++ b/ql/test/library-tests/semmle/go/Decl/TypeEntities.expected @@ -0,0 +1,2 @@ +| main.go:3:6:3:11 | status | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Decl | status | +| main.go:5:6:5:12 | intlist | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Decl | []int | diff --git a/ql/test/library-tests/semmle/go/Decl/TypeEntities.ql b/ql/test/library-tests/semmle/go/Decl/TypeEntities.ql new file mode 100644 index 00000000000..14a54691250 --- /dev/null +++ b/ql/test/library-tests/semmle/go/Decl/TypeEntities.ql @@ -0,0 +1,4 @@ +import go + +from TypeEntity te +select te, te.getPackage(), te.getType().pp()