Skip to content

Commit fd209e5

Browse files
committed
Swift: extract InoutType
1 parent 189a47e commit fd209e5

File tree

9 files changed

+45
-5
lines changed

9 files changed

+45
-5
lines changed

swift/codegen/schema.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ ErrorType:
100100

101101
InOutType:
102102
_extends: Type
103+
object_type: Type
103104

104105
LValueType:
105106
_extends: Type

swift/extractor/visitors/TypeVisitor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,11 @@ codeql::VariadicSequenceType TypeVisitor::translateVariadicSequenceType(
271271
return entry;
272272
}
273273

274+
codeql::InOutType TypeVisitor::translateInOutType(const swift::InOutType& type) {
275+
codeql::InOutType entry{dispatcher_.assignNewLabel(type)};
276+
entry.object_type = dispatcher_.fetchLabel(type.getObjectType());
277+
fillType(type, entry);
278+
return entry;
279+
}
280+
274281
} // namespace codeql

swift/extractor/visitors/TypeVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
4242
codeql::DynamicSelfType translateDynamicSelfType(const swift::DynamicSelfType& type);
4343
codeql::VariadicSequenceType translateVariadicSequenceType(
4444
const swift::VariadicSequenceType& type);
45+
codeql::InOutType translateInOutType(const swift::InOutType& type);
4546

4647
private:
4748
void fillType(const swift::TypeBase& type, codeql::Type& entry);

swift/ql/lib/codeql/swift/generated/type/InOutType.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ import codeql.swift.elements.type.Type
33

44
class InOutTypeBase extends @in_out_type, Type {
55
override string getAPrimaryQlClass() { result = "InOutType" }
6+
7+
Type getObjectType() {
8+
exists(Type x |
9+
in_out_types(this, x) and
10+
result = x.resolve()
11+
)
12+
}
613
}

swift/ql/lib/swift.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ error_types( //dir=type
253253
);
254254

255255
in_out_types( //dir=type
256-
unique int id: @in_out_type
256+
unique int id: @in_out_type,
257+
int object_type: @type ref
257258
);
258259

259260
l_value_types( //dir=type
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| inout Int | getDiagnosticsName: | inout Int | getCanonicalType: | inout Int | getObjectType: | Int |
2+
| inout S | getDiagnosticsName: | inout S | getCanonicalType: | inout S | getObjectType: | S |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from InOutType x, string getDiagnosticsName, Type getCanonicalType, Type getObjectType
6+
where
7+
toBeTested(x) and
8+
not x.isUnknown() and
9+
getDiagnosticsName = x.getDiagnosticsName() and
10+
getCanonicalType = x.getCanonicalType() and
11+
getObjectType = x.getObjectType()
12+
select x, "getDiagnosticsName:", getDiagnosticsName, "getCanonicalType:", getCanonicalType,
13+
"getObjectType:", getObjectType

swift/ql/test/extractor-tests/generated/type/InOutType/MISSING_SOURCE.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
func foo(_: inout Int) {}
2+
3+
var x: Int = 42
4+
5+
foo(&x)
6+
7+
struct S {
8+
mutating func bar() {}
9+
}
10+
11+
var s: S
12+
s.bar()

0 commit comments

Comments
 (0)