Skip to content

Commit 189a47e

Browse files
committed
Swift: extract VariadicSequenceType
1 parent 346110e commit 189a47e

File tree

6 files changed

+45
-25
lines changed

6 files changed

+45
-25
lines changed

swift/extractor/visitors/TypeVisitor.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,16 @@ void TypeVisitor::visitParenType(swift::ParenType* type) {
121121
dispatcher_.emit(ParenTypesTrap{label, typeLabel});
122122
}
123123

124-
void TypeVisitor::visitUnarySyntaxSugarType(swift::UnarySyntaxSugarType* type) {
125-
auto label = dispatcher_.assignNewLabel(type);
126-
emitUnarySyntaxSugarType(type, label);
127-
}
128-
129-
void TypeVisitor::visitOptionalType(swift::OptionalType* type) {
130-
auto label = dispatcher_.assignNewLabel(type);
131-
dispatcher_.emit(OptionalTypesTrap{label});
132-
emitUnarySyntaxSugarType(type, label);
124+
codeql::OptionalType TypeVisitor::translateOptionalType(const swift::OptionalType& type) {
125+
codeql::OptionalType entry{dispatcher_.assignNewLabel(type)};
126+
fillUnarySyntaxSugarType(type, entry);
127+
return entry;
133128
}
134129

135-
void TypeVisitor::visitArraySliceType(swift::ArraySliceType* type) {
136-
auto label = dispatcher_.assignNewLabel(type);
137-
dispatcher_.emit(ArraySliceTypesTrap{label});
138-
emitUnarySyntaxSugarType(type, label);
130+
codeql::ArraySliceType TypeVisitor::translateArraySliceType(const swift::ArraySliceType& type) {
131+
codeql::ArraySliceType entry{dispatcher_.assignNewLabel(type)};
132+
fillUnarySyntaxSugarType(type, entry);
133+
return entry;
139134
}
140135

141136
void TypeVisitor::visitDictionaryType(swift::DictionaryType* type) {
@@ -184,10 +179,11 @@ void TypeVisitor::visitBoundGenericType(swift::BoundGenericType* type) {
184179
emitBoundGenericType(type, label);
185180
}
186181

187-
void TypeVisitor::emitUnarySyntaxSugarType(const swift::UnarySyntaxSugarType* type,
188-
TrapLabel<UnarySyntaxSugarTypeTag> label) {
189-
assert(type->getBaseType() && "expect UnarySyntaxSugarType to have BaseType");
190-
dispatcher_.emit(UnarySyntaxSugarTypesTrap{label, dispatcher_.fetchLabel(type->getBaseType())});
182+
void TypeVisitor::fillUnarySyntaxSugarType(const swift::UnarySyntaxSugarType& type,
183+
codeql::UnarySyntaxSugarType& entry) {
184+
assert(type.getBaseType() && "expect UnarySyntaxSugarType to have BaseType");
185+
entry.base_type = dispatcher_.fetchLabel(type.getBaseType());
186+
fillType(type, entry);
191187
}
192188

193189
void TypeVisitor::emitAnyFunctionType(const swift::AnyFunctionType* type,
@@ -260,11 +256,19 @@ codeql::ExistentialType TypeVisitor::translateExistentialType(const swift::Exist
260256
fillType(type, entry);
261257
return entry;
262258
}
259+
263260
codeql::DynamicSelfType TypeVisitor::translateDynamicSelfType(const swift::DynamicSelfType& type) {
264261
codeql::DynamicSelfType entry{dispatcher_.assignNewLabel(type)};
265262
entry.static_self_type = dispatcher_.fetchLabel(type.getSelfType());
266263
fillType(type, entry);
267264
return entry;
268265
}
269266

267+
codeql::VariadicSequenceType TypeVisitor::translateVariadicSequenceType(
268+
const swift::VariadicSequenceType& type) {
269+
codeql::VariadicSequenceType entry{dispatcher_.assignNewLabel(type)};
270+
fillUnarySyntaxSugarType(type, entry);
271+
return entry;
272+
}
273+
270274
} // namespace codeql

swift/extractor/visitors/TypeVisitor.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
2727
void visitDependentMemberType(swift::DependentMemberType* type);
2828
void visitParenType(swift::ParenType* type);
2929
void visitUnarySyntaxSugarType(swift::UnarySyntaxSugarType* type);
30-
void visitOptionalType(swift::OptionalType* type);
31-
void visitArraySliceType(swift::ArraySliceType* type);
30+
codeql::OptionalType translateOptionalType(const swift::OptionalType& type);
31+
codeql::ArraySliceType translateArraySliceType(const swift::ArraySliceType& type);
3232
void visitDictionaryType(swift::DictionaryType* type);
3333
void visitGenericFunctionType(swift::GenericFunctionType* type);
3434
void visitGenericTypeParamType(swift::GenericTypeParamType* type);
@@ -40,12 +40,14 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
4040
codeql::NestedArchetypeType translateNestedArchetypeType(const swift::NestedArchetypeType& type);
4141
codeql::ExistentialType translateExistentialType(const swift::ExistentialType& type);
4242
codeql::DynamicSelfType translateDynamicSelfType(const swift::DynamicSelfType& type);
43+
codeql::VariadicSequenceType translateVariadicSequenceType(
44+
const swift::VariadicSequenceType& type);
4345

4446
private:
4547
void fillType(const swift::TypeBase& type, codeql::Type& entry);
4648
void fillArchetypeType(const swift::ArchetypeType& type, codeql::ArchetypeType& entry);
47-
void emitUnarySyntaxSugarType(const swift::UnarySyntaxSugarType* type,
48-
TrapLabel<UnarySyntaxSugarTypeTag> label);
49+
void fillUnarySyntaxSugarType(const swift::UnarySyntaxSugarType& type,
50+
codeql::UnarySyntaxSugarType& entry);
4951
void emitAnyFunctionType(const swift::AnyFunctionType* type, TrapLabel<AnyFunctionTypeTag> label);
5052
void emitBoundGenericType(swift::BoundGenericType* type, TrapLabel<BoundGenericTypeTag> label);
5153
void emitAnyGenericType(swift::AnyGenericType* type, TrapLabel<AnyGenericTypeTag> label);

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

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| Int... | getDiagnosticsName: | Int... | getCanonicalType: | Array<Int> | getBaseType: | Int |
2+
| T... | getDiagnosticsName: | T... | getCanonicalType: | Array<T> | getBaseType: | T |
3+
| T... | getDiagnosticsName: | T... | getCanonicalType: | Array<\u03c4_0_0> | getBaseType: | T |
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 VariadicSequenceType x, string getDiagnosticsName, Type getCanonicalType, Type getBaseType
6+
where
7+
toBeTested(x) and
8+
not x.isUnknown() and
9+
getDiagnosticsName = x.getDiagnosticsName() and
10+
getCanonicalType = x.getCanonicalType() and
11+
getBaseType = x.getBaseType()
12+
select x, "getDiagnosticsName:", getDiagnosticsName, "getCanonicalType:", getCanonicalType,
13+
"getBaseType:", getBaseType
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
func foo(ints: Int...) {}
2+
func bar<T>(args: T...) {}

0 commit comments

Comments
 (0)