Skip to content

Commit 41fb55a

Browse files
committed
Swift: extract all ReferenceStorageTypes
1 parent fd209e5 commit 41fb55a

File tree

17 files changed

+98
-13
lines changed

17 files changed

+98
-13
lines changed

swift/codegen/schema.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ ExistentialType:
121121

122122
ReferenceStorageType:
123123
_extends: Type
124+
referent_type: Type
124125

125126
SilBlockStorageType:
126127
_extends: Type

swift/extractor/visitors/TypeVisitor.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,30 @@ codeql::InOutType TypeVisitor::translateInOutType(const swift::InOutType& type)
278278
return entry;
279279
}
280280

281+
codeql::UnmanagedStorageType TypeVisitor::translateUnmanagedStorageType(
282+
const swift::UnmanagedStorageType& type) {
283+
codeql::UnmanagedStorageType entry{dispatcher_.assignNewLabel(type)};
284+
fillReferenceStorageType(type, entry);
285+
return entry;
286+
}
287+
288+
codeql::UnownedStorageType TypeVisitor::translateUnownedStorageType(
289+
const swift::UnownedStorageType& type) {
290+
codeql::UnownedStorageType entry{dispatcher_.assignNewLabel(type)};
291+
fillReferenceStorageType(type, entry);
292+
return entry;
293+
}
294+
295+
codeql::WeakStorageType TypeVisitor::translateWeakStorageType(const swift::WeakStorageType& type) {
296+
codeql::WeakStorageType entry{dispatcher_.assignNewLabel(type)};
297+
fillReferenceStorageType(type, entry);
298+
return entry;
299+
}
300+
301+
void TypeVisitor::fillReferenceStorageType(const swift::ReferenceStorageType& type,
302+
codeql::ReferenceStorageType& entry) {
303+
entry.referent_type = dispatcher_.fetchLabel(type.getReferentType());
304+
fillType(type, entry);
305+
}
306+
281307
} // namespace codeql

swift/extractor/visitors/TypeVisitor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
4343
codeql::VariadicSequenceType translateVariadicSequenceType(
4444
const swift::VariadicSequenceType& type);
4545
codeql::InOutType translateInOutType(const swift::InOutType& type);
46+
codeql::UnmanagedStorageType translateUnmanagedStorageType(
47+
const swift::UnmanagedStorageType& type);
48+
codeql::WeakStorageType translateWeakStorageType(const swift::WeakStorageType& type);
49+
codeql::UnownedStorageType translateUnownedStorageType(const swift::UnownedStorageType& type);
4650

4751
private:
4852
void fillType(const swift::TypeBase& type, codeql::Type& entry);
4953
void fillArchetypeType(const swift::ArchetypeType& type, codeql::ArchetypeType& entry);
5054
void fillUnarySyntaxSugarType(const swift::UnarySyntaxSugarType& type,
5155
codeql::UnarySyntaxSugarType& entry);
56+
void fillReferenceStorageType(const swift::ReferenceStorageType& type,
57+
codeql::ReferenceStorageType& entry);
5258
void emitAnyFunctionType(const swift::AnyFunctionType* type, TrapLabel<AnyFunctionTypeTag> label);
5359
void emitBoundGenericType(swift::BoundGenericType* type, TrapLabel<BoundGenericTypeTag> label);
5460
void emitAnyGenericType(swift::AnyGenericType* type, TrapLabel<AnyGenericTypeTag> label);
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
// generated by codegen/codegen.py
22
import codeql.swift.elements.type.Type
33

4-
class ReferenceStorageTypeBase extends @reference_storage_type, Type { }
4+
class ReferenceStorageTypeBase extends @reference_storage_type, Type {
5+
Type getReferentType() {
6+
exists(Type x |
7+
reference_storage_types(this, x) and
8+
result = x.resolve()
9+
)
10+
}
11+
}

swift/ql/lib/swift.dbscheme

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ existential_types( //dir=type
285285
| @weak_storage_type
286286
;
287287

288+
#keyset[id]
289+
reference_storage_types( //dir=type
290+
int id: @reference_storage_type ref,
291+
int referent_type: @type ref
292+
);
293+
288294
sil_block_storage_types( //dir=type
289295
unique int id: @sil_block_storage_type
290296
);

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

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| A? | getDiagnosticsName: | A? | getCanonicalType: | Optional<A> | getReferentType: | A? |
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 UnmanagedStorageType x, string getDiagnosticsName, Type getCanonicalType, Type getReferentType
6+
where
7+
toBeTested(x) and
8+
not x.isUnknown() and
9+
getDiagnosticsName = x.getDiagnosticsName() and
10+
getCanonicalType = x.getCanonicalType() and
11+
getReferentType = x.getReferentType()
12+
select x, "getDiagnosticsName:", getDiagnosticsName, "getCanonicalType:", getCanonicalType,
13+
"getReferentType:", getReferentType
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A {
2+
unowned(unsafe) var x: A?
3+
}

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

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)