Skip to content

Commit 4799861

Browse files
committed
Merge branch 'redsun82/codegen-new-parent-child' into redsun82/rust-item-reorg
2 parents e4056c0 + de72e68 commit 4799861

File tree

2,022 files changed

+27827
-22116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,022 files changed

+27827
-22116
lines changed

cpp/ql/lib/semmlecode.cpp.dbscheme.stats

Lines changed: 8685 additions & 8650 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Previously, `DefinedType.getBaseType` gave the underlying type. It now gives the right hand side of the type declaration, as the documentation indicated that it should.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: deprecated
3+
---
4+
* The class `BuiltinType` is now deprecated. Use the new replacement `BuiltinTypeEntity` instead.
5+
* The class `DeclaredType` is now deprecated. Use the new replacement `DeclaredTypeEntity` instead.

go/ql/lib/semmle/go/Decls.qll

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,20 @@ class TypeSpec extends @typespec, Spec, TypeParamDeclParent {
381381
string getName() { result = this.getNameExpr().getName() }
382382

383383
/**
384-
* Gets the expression denoting the underlying type to which the newly declared type is bound.
384+
* Gets the declared type of this specifier.
385+
*
386+
* Note that for alias types this will give the underlying type.
387+
*/
388+
Type getDeclaredType() { result = this.getNameExpr().getType() }
389+
390+
/**
391+
* Gets the expression denoting the underlying type to which the declared type is bound.
385392
*/
386393
Expr getTypeExpr() { result = this.getChildExpr(1) }
387394

395+
/** Gets the underlying type to which the declared type is bound. */
396+
Type getRhsType() { result = this.getTypeExpr().getType() }
397+
388398
override string toString() { result = "type declaration specifier" }
389399

390400
override string getAPrimaryQlClass() { result = "TypeSpec" }
@@ -461,6 +471,7 @@ class FieldBase extends @field, ExprParent {
461471
* Examples:
462472
*
463473
* ```go
474+
* io.Reader
464475
* Name string `json:"name"`
465476
* x, y int
466477
* ```
@@ -469,8 +480,9 @@ class FieldBase extends @field, ExprParent {
469480
*
470481
* ```go
471482
* struct {
472-
* Name string `json:"name"`
473-
* x, y int
483+
* io.Reader // embedded field
484+
* Name string `json:"name"` // field with tag
485+
* x, y int // declares two fields with the same type
474486
* }
475487
* ```
476488
*/
@@ -482,12 +494,24 @@ class FieldDecl extends FieldBase, Documentable, ExprParent {
482494
/**
483495
* Gets the expression representing the name of the `i`th field declared in this declaration
484496
* (0-based).
497+
*
498+
* This is not defined for embedded fields.
485499
*/
486500
Expr getNameExpr(int i) {
487501
i >= 0 and
488502
result = this.getChildExpr(i + 1)
489503
}
490504

505+
/**
506+
* Gets the `i`th field declared in this declaration (0-based).
507+
*
508+
* This is not defined for embedded fields.
509+
*/
510+
Field getField(int i) { this.getNameExpr(i).(Ident).declares(result) }
511+
512+
/** Holds if this field declaration declares an embedded type. */
513+
predicate isEmbedded() { not exists(this.getNameExpr(_)) }
514+
491515
/** Gets the tag expression of this field declaration, if any. */
492516
Expr getTag() { result = this.getChildExpr(-1) }
493517

go/ql/lib/semmle/go/Scopes.qll

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,19 @@ class TypeEntity extends Entity, @typeobject { }
202202
class TypeParamParentEntity extends Entity, @typeparamparentobject { }
203203

204204
/** A named type which has a declaration. */
205-
class DeclaredType extends TypeEntity, DeclaredEntity, TypeParamParentEntity, @decltypeobject {
205+
class DeclaredTypeEntity extends TypeEntity, DeclaredEntity, TypeParamParentEntity, @decltypeobject {
206206
/** Gets the declaration specifier declaring this type. */
207207
TypeSpec getSpec() { result.getNameExpr() = this.getDeclaration() }
208208
}
209209

210+
/** DEPRECATED: Use `DeclaredTypeEntity` instead. */
211+
deprecated class DeclaredType = DeclaredTypeEntity;
212+
210213
/** A built-in type. */
211-
class BuiltinType extends TypeEntity, BuiltinEntity, @builtintypeobject { }
214+
class BuiltinTypeEntity extends TypeEntity, BuiltinEntity, @builtintypeobject { }
215+
216+
/** DEPRECATED: Use `BuiltinTypeEntity` instead. */
217+
deprecated class BuiltinType = BuiltinTypeEntity;
212218

213219
/** A built-in or declared constant, variable, field, method or function. */
214220
class ValueEntity extends Entity, @valueobject {
@@ -754,64 +760,64 @@ private predicate builtinFunction(
754760
module Builtin {
755761
// built-in types
756762
/** Gets the built-in type `bool`. */
757-
BuiltinType bool() { result.getName() = "bool" }
763+
BuiltinTypeEntity bool() { result.getName() = "bool" }
758764

759765
/** Gets the built-in type `byte`. */
760-
BuiltinType byte() { result.getName() = "byte" }
766+
BuiltinTypeEntity byte() { result.getName() = "byte" }
761767

762768
/** Gets the built-in type `complex64`. */
763-
BuiltinType complex64() { result.getName() = "complex64" }
769+
BuiltinTypeEntity complex64() { result.getName() = "complex64" }
764770

765771
/** Gets the built-in type `complex128`. */
766-
BuiltinType complex128() { result.getName() = "complex128" }
772+
BuiltinTypeEntity complex128() { result.getName() = "complex128" }
767773

768774
/** Gets the built-in type `error`. */
769-
BuiltinType error() { result.getName() = "error" }
775+
BuiltinTypeEntity error() { result.getName() = "error" }
770776

771777
/** Gets the built-in type `float32`. */
772-
BuiltinType float32() { result.getName() = "float32" }
778+
BuiltinTypeEntity float32() { result.getName() = "float32" }
773779

774780
/** Gets the built-in type `float64`. */
775-
BuiltinType float64() { result.getName() = "float64" }
781+
BuiltinTypeEntity float64() { result.getName() = "float64" }
776782

777783
/** Gets the built-in type `int`. */
778-
BuiltinType int_() { result.getName() = "int" }
784+
BuiltinTypeEntity int_() { result.getName() = "int" }
779785

780786
/** Gets the built-in type `int8`. */
781-
BuiltinType int8() { result.getName() = "int8" }
787+
BuiltinTypeEntity int8() { result.getName() = "int8" }
782788

783789
/** Gets the built-in type `int16`. */
784-
BuiltinType int16() { result.getName() = "int16" }
790+
BuiltinTypeEntity int16() { result.getName() = "int16" }
785791

786792
/** Gets the built-in type `int32`. */
787-
BuiltinType int32() { result.getName() = "int32" }
793+
BuiltinTypeEntity int32() { result.getName() = "int32" }
788794

789795
/** Gets the built-in type `int64`. */
790-
BuiltinType int64() { result.getName() = "int64" }
796+
BuiltinTypeEntity int64() { result.getName() = "int64" }
791797

792798
/** Gets the built-in type `rune`. */
793-
BuiltinType rune() { result.getName() = "rune" }
799+
BuiltinTypeEntity rune() { result.getName() = "rune" }
794800

795801
/** Gets the built-in type `string`. */
796-
BuiltinType string_() { result.getName() = "string" }
802+
BuiltinTypeEntity string_() { result.getName() = "string" }
797803

798804
/** Gets the built-in type `uint`. */
799-
BuiltinType uint() { result.getName() = "uint" }
805+
BuiltinTypeEntity uint() { result.getName() = "uint" }
800806

801807
/** Gets the built-in type `uint8`. */
802-
BuiltinType uint8() { result.getName() = "uint8" }
808+
BuiltinTypeEntity uint8() { result.getName() = "uint8" }
803809

804810
/** Gets the built-in type `uint16`. */
805-
BuiltinType uint16() { result.getName() = "uint16" }
811+
BuiltinTypeEntity uint16() { result.getName() = "uint16" }
806812

807813
/** Gets the built-in type `uint32`. */
808-
BuiltinType uint32() { result.getName() = "uint32" }
814+
BuiltinTypeEntity uint32() { result.getName() = "uint32" }
809815

810816
/** Gets the built-in type `uint64`. */
811-
BuiltinType uint64() { result.getName() = "uint64" }
817+
BuiltinTypeEntity uint64() { result.getName() = "uint64" }
812818

813819
/** Gets the built-in type `uintptr`. */
814-
BuiltinType uintptr() { result.getName() = "uintptr" }
820+
BuiltinTypeEntity uintptr() { result.getName() = "uintptr" }
815821

816822
// built-in constants
817823
/** Gets the built-in constant `true`. */

go/ql/lib/semmle/go/Types.qll

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,15 @@ deprecated class NamedType = DefinedType;
10381038

10391039
/** A defined type. */
10401040
class DefinedType extends @definedtype, CompositeType {
1041-
/** Gets the type which this type is defined to be. */
1042-
Type getBaseType() { underlying_type(this, result) }
1041+
/**
1042+
* Gets the type which this type is defined to be, if available.
1043+
*
1044+
* Note that this is only defined for types declared in the project being
1045+
* analyzed. It will not be defined for types declared in external packages.
1046+
*/
1047+
Type getBaseType() {
1048+
result = this.getEntity().(DeclaredTypeEntity).getSpec().getTypeExpr().getType()
1049+
}
10431050

10441051
override Method getMethod(string m) {
10451052
result = CompositeType.super.getMethod(m)
@@ -1049,7 +1056,7 @@ class DefinedType extends @definedtype, CompositeType {
10491056
or
10501057
// handle promoted methods
10511058
exists(StructType s, Type embedded |
1052-
s = this.getBaseType() and
1059+
s = this.getUnderlyingType() and
10531060
s.hasOwnField(_, _, embedded, true) and
10541061
// ensure `m` can be promoted
10551062
not s.hasOwnField(_, m, _, _) and
@@ -1063,7 +1070,7 @@ class DefinedType extends @definedtype, CompositeType {
10631070
)
10641071
}
10651072

1066-
override Type getUnderlyingType() { result = this.getBaseType().getUnderlyingType() }
1073+
override Type getUnderlyingType() { underlying_type(this, result) }
10671074
}
10681075

10691076
/**
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| main.go:3:6:3:15 | type declaration specifier | status | int | def |
2-
| main.go:5:6:5:20 | type declaration specifier | intlist | []int | alias |
1+
| main.go:3:6:3:15 | type declaration specifier | status | status | main.go:3:13:3:15 | int | int | def |
2+
| main.go:5:6:5:20 | type declaration specifier | intlist | []int | main.go:5:16:5:20 | array type | []int | alias |

go/ql/test/library-tests/semmle/go/Decl/TypeSpec.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import go
22

33
from TypeSpec ts, string kind
44
where if ts instanceof AliasSpec then kind = "alias" else kind = "def"
5-
select ts, ts.getName(), ts.getTypeExpr().getType().pp(), kind
5+
select ts, ts.getName(), ts.getDeclaredType().pp(), ts.getTypeExpr(), ts.getRhsType().pp(), kind
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
| aliases.go:19:6:19:7 | S3 | struct { x int } |
2+
| aliases.go:29:6:29:11 | MyType | struct { x MyTypeT } |
3+
| cyclic.go:3:6:3:6 | s | struct { * s } |
4+
| cyclic.go:7:6:7:6 | t | struct { * u; f int } |
5+
| cyclic.go:12:6:12:6 | u | struct { t } |
6+
| cyclic.go:16:6:16:6 | v | struct { s } |
7+
| depth.go:5:6:5:6 | a | struct { b; c } |
8+
| depth.go:10:6:10:6 | b | struct { f int } |
9+
| depth.go:14:6:14:6 | c | struct { d } |
10+
| depth.go:18:6:18:6 | d | struct { f string } |
11+
| embedded.go:3:6:3:8 | Baz | struct { A string } |
12+
| embedded.go:7:6:7:8 | Qux | struct { * Baz } |
13+
| embedded.go:11:6:11:14 | EmbedsBaz | struct { Qux; Baz string } |
14+
| generic.go:3:6:3:19 | GenericStruct1 | struct { valueField T; pointerField * T; arrayField [10]T; sliceField []T; mapField [string]T } |
15+
| generic.go:11:6:11:27 | CircularGenericStruct1 | struct { pointerField * CircularGenericStruct1 } |
16+
| generic.go:15:6:15:31 | UsesCircularGenericStruct1 | struct { root CircularGenericStruct1 } |
17+
| generic.go:19:6:19:19 | GenericStruct2 | struct { structField GenericStruct1; mapField [S]T } |
18+
| generic.go:24:6:24:20 | GenericStruct2b | struct { structField GenericStruct2 } |
19+
| generic.go:28:6:28:27 | CircularGenericStruct2 | struct { pointerField * CircularGenericStruct2 } |
20+
| generic.go:32:6:32:21 | GenericInterface | interface { GetT func() T } |
21+
| generic.go:36:6:36:17 | GenericArray | [10]T |
22+
| generic.go:37:6:37:19 | GenericPointer | * T |
23+
| generic.go:38:6:38:17 | GenericSlice | []T |
24+
| generic.go:39:6:39:16 | GenericMap1 | [string]V |
25+
| generic.go:40:6:40:16 | GenericMap2 | [K]V |
26+
| generic.go:41:6:41:19 | GenericChannel | chan<- T |
27+
| generic.go:42:6:42:14 | MyMapType | [string]int |
28+
| generic.go:43:6:43:19 | GenericDefined | MyMapType |
29+
| generic.go:44:6:44:16 | MyFuncType1 | func(T) |
30+
| generic.go:45:6:45:16 | MyFuncType2 | func(T1) T2 |
31+
| generic.go:47:6:47:16 | MyInterface | interface { clone func() MyInterface; dummy1 func() [10]U; dummy11 func() GenericArray; dummy12 func() GenericPointer; dummy13 func() GenericSlice; dummy14 func() GenericMap1; dummy15 func() GenericMap2; dummy17 func() GenericChannel; dummy18 func() GenericDefined; dummy19 func() MyFuncType1; dummy2 func() * U; dummy20 func() MyFuncType2; dummy3 func() []U; dummy4 func() [U]U; dummy5 func() chan<- U; dummy6 func() MyMapType; dummy7 func() MyFuncType2 } |
32+
| generic.go:67:6:67:22 | HasBlankTypeParam | struct { } |
33+
| generic.go:68:6:68:23 | HasBlankTypeParams | struct { } |
34+
| generic.go:84:6:84:21 | GenericSignature | func(T) T |
35+
| interface.go:3:6:3:7 | i0 | comparable |
36+
| interface.go:5:6:5:7 | i1 | interface { int } |
37+
| interface.go:9:6:9:7 | i2 | interface { ~string } |
38+
| interface.go:13:6:13:7 | i3 | interface { [5]int \| ~string } |
39+
| interface.go:18:6:18:7 | i4 | interface { i1 \| i2 \| float32 } |
40+
| interface.go:23:6:23:7 | i5 | interface { []uint8; int \| ~[]uint8 } |
41+
| interface.go:28:6:28:7 | i6 | interface { ~[]int \| ~string; String func() string } |
42+
| interface.go:34:6:34:7 | i7 | interface { [5]int \| ~string; ~string; String func() string } |
43+
| interface.go:41:6:41:7 | i8 | interface { ~[]int \| ~string; String func() string; StringA func() string } |
44+
| interface.go:47:6:47:7 | i9 | interface { ~[]int \| ~string; String func() string; StringB func() string } |
45+
| interface.go:52:6:52:8 | i10 | interface { comparable } |
46+
| interface.go:57:6:57:8 | i11 | interface { [5]uint8 \| string; int } |
47+
| interface.go:63:6:63:8 | i12 | interface { comparable; []uint8 \| string } |
48+
| interface.go:69:6:69:8 | i13 | interface { comparable; []uint8 \| string } |
49+
| interface.go:75:6:75:8 | i14 | interface { []uint8 \| string; ~[]int \| ~string; String func() string; StringA func() string } |
50+
| interface.go:81:6:81:8 | i15 | interface { []uint8 \| string; ~[]int \| ~string; String func() string; StringB func() string } |
51+
| interface.go:87:6:87:8 | i16 | interface { } |
52+
| interface.go:91:6:91:8 | i17 | interface { StringA func() string } |
53+
| interface.go:95:6:95:8 | i18 | interface { comparable; StringA func() string } |
54+
| interface.go:101:6:101:8 | i19 | interface { StringB func() string } |
55+
| interface.go:105:6:105:8 | i20 | interface { comparable; StringB func() string } |
56+
| interface.go:114:6:114:19 | testComparable | struct { } |
57+
| interface.go:115:6:115:20 | testComparable0 | struct { } |
58+
| interface.go:116:6:116:20 | testComparable1 | struct { } |
59+
| interface.go:117:6:117:20 | testComparable2 | struct { } |
60+
| interface.go:118:6:118:20 | testComparable3 | struct { } |
61+
| interface.go:119:6:119:20 | testComparable4 | struct { } |
62+
| interface.go:120:6:120:20 | testComparable5 | struct { } |
63+
| interface.go:121:6:121:20 | testComparable6 | struct { } |
64+
| interface.go:122:6:122:20 | testComparable7 | struct { } |
65+
| interface.go:123:6:123:20 | testComparable8 | struct { } |
66+
| interface.go:124:6:124:20 | testComparable9 | struct { } |
67+
| interface.go:125:6:125:21 | testComparable10 | struct { } |
68+
| interface.go:126:6:126:21 | testComparable11 | struct { } |
69+
| interface.go:127:6:127:21 | testComparable12 | struct { } |
70+
| interface.go:128:6:128:21 | testComparable13 | struct { } |
71+
| interface.go:129:6:129:21 | testComparable14 | struct { } |
72+
| interface.go:130:6:130:21 | testComparable15 | struct { } |
73+
| interface.go:131:6:131:21 | testComparable16 | struct { } |
74+
| interface.go:132:6:132:21 | testComparable17 | struct { } |
75+
| interface.go:133:6:133:21 | testComparable18 | struct { } |
76+
| interface.go:134:6:134:21 | testComparable19 | struct { } |
77+
| interface.go:135:6:135:21 | testComparable20 | struct { } |
78+
| interface.go:136:6:136:21 | testComparable21 | struct { } |
79+
| interface.go:137:6:137:21 | testComparable22 | struct { } |
80+
| interface.go:138:6:138:21 | testComparable23 | struct { } |
81+
| main.go:17:6:17:20 | EmbedsNameClash | struct { NameClash } |
82+
| pkg1/embedding.go:8:6:8:9 | base | struct { } |
83+
| pkg1/embedding.go:19:6:19:13 | embedder | struct { base } |
84+
| pkg1/embedding.go:22:6:22:16 | ptrembedder | struct { * base } |
85+
| pkg1/embedding.go:25:6:25:14 | embedder2 | struct { embedder } |
86+
| pkg1/embedding.go:28:6:28:14 | embedder3 | struct { embedder } |
87+
| pkg1/embedding.go:35:6:35:14 | embedder4 | struct { base; f int } |
88+
| pkg1/interfaces.go:3:6:3:6 | A | interface { m func() } |
89+
| pkg1/interfaces.go:7:6:7:6 | B | interface { m func() ; n func() } |
90+
| pkg1/interfaces.go:12:6:12:6 | C | interface { n func() ; o func() } |
91+
| pkg1/interfaces.go:17:6:17:14 | AEmbedded | interface { m func() } |
92+
| pkg1/interfaces.go:21:6:21:7 | AC | interface { m func() ; n func() ; o func() } |
93+
| pkg1/interfaces.go:26:6:26:14 | AExtended | interface { m func() ; n func() } |
94+
| pkg1/interfaces.go:31:6:31:7 | A2 | interface { m func() } |
95+
| pkg1/interfaces.go:35:6:35:24 | MixedExportedAndNot | interface { Exported func() ; notExported func() } |
96+
| pkg1/promotedStructs.go:4:6:4:6 | S | struct { SField string } |
97+
| pkg1/promotedStructs.go:13:6:13:6 | P | struct { PField string } |
98+
| pkg1/promotedStructs.go:22:6:22:12 | SEmbedS | struct { S } |
99+
| pkg1/promotedStructs.go:25:6:25:12 | SEmbedP | struct { P } |
100+
| pkg1/tst.go:5:6:5:6 | T | struct { f int; Foo; Bar } |
101+
| pkg1/tst.go:11:6:11:7 | T2 | struct { Foo Foo; Bar } |
102+
| pkg1/tst.go:16:6:16:7 | T3 | struct { * Foo; * Bar } |
103+
| pkg1/tst.go:21:6:21:7 | T4 | struct { * Foo; Bar Bar } |
104+
| pkg1/tst.go:26:6:26:8 | Foo | struct { val int; flag bool } |
105+
| pkg1/tst.go:31:6:31:8 | Bar | struct { flag bool } |
106+
| pkg1/tst.go:61:6:61:14 | NameClash | struct { NameClash } |
107+
| pkg2/tst.go:3:6:3:6 | T | struct { g int } |
108+
| pkg2/tst.go:7:6:7:6 | G | struct { g int } |
109+
| pkg2/tst.go:11:6:11:24 | MixedExportedAndNot | interface { Exported func() ; notExported func() } |
110+
| pkg2/tst.go:16:6:16:14 | NameClash | struct { NCField string } |
111+
| struct_tags.go:3:6:3:7 | S1 | struct { field1 int `tag1a`; field2 int `tag2a` } |
112+
| struct_tags.go:8:6:8:7 | S2 | struct { field1 int `tag1b`; field2 int `tag2b` } |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import go
2+
3+
from DefinedType dt, Type tp
4+
where tp = dt.getBaseType()
5+
select dt, tp.pp()

0 commit comments

Comments
 (0)