Skip to content

Commit 7a7440a

Browse files
committed
Swift: move createEntry to SwiftDispatcher
1 parent 5b5a52f commit 7a7440a

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

java/ql/test/stubs/apache-commons-collections4-4.4/org/apache/commons/collections4/map/AbstractHashedMap.java

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/apache-commons-collections4-4.4/org/apache/commons/collections4/map/AbstractLinkedMap.java

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/extractor/infra/SwiftDispatcher.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ class SwiftDispatcher {
112112
return assignNewLabel(&e, std::forward<Args>(args)...);
113113
}
114114

115+
// convenience methods for structured C++ creation
116+
template <typename E, typename... Args, std::enable_if_t<!std::is_pointer_v<E>>* = nullptr>
117+
auto createEntry(const E& e, Args&&... args) {
118+
return TrapClassOf<E>{assignNewLabel(&e, std::forward<Args>(args)...)};
119+
}
120+
115121
template <typename Tag>
116122
TrapLabel<Tag> createLabel() {
117123
auto ret = arena.allocateLabel<Tag>();

swift/extractor/visitors/TypeVisitor.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ void TypeVisitor::visitParenType(swift::ParenType* type) {
122122
}
123123

124124
codeql::OptionalType TypeVisitor::translateOptionalType(const swift::OptionalType& type) {
125-
auto entry = createEntry(type);
125+
auto entry = createTypeEntry(type);
126126
fillUnarySyntaxSugarType(type, entry);
127127
return entry;
128128
}
129129

130130
codeql::ArraySliceType TypeVisitor::translateArraySliceType(const swift::ArraySliceType& type) {
131-
auto entry = createEntry(type);
131+
auto entry = createTypeEntry(type);
132132
fillUnarySyntaxSugarType(type, entry);
133133
return entry;
134134
}
@@ -163,7 +163,7 @@ void TypeVisitor::visitLValueType(swift::LValueType* type) {
163163

164164
codeql::PrimaryArchetypeType TypeVisitor::translatePrimaryArchetypeType(
165165
const swift::PrimaryArchetypeType& type) {
166-
auto entry = createEntry(type);
166+
auto entry = createTypeEntry(type);
167167
fillArchetypeType(type, entry);
168168
return entry;
169169
}
@@ -229,7 +229,7 @@ void TypeVisitor::emitAnyGenericType(swift::AnyGenericType* type,
229229

230230
codeql::NestedArchetypeType TypeVisitor::translateNestedArchetypeType(
231231
const swift::NestedArchetypeType& type) {
232-
auto entry = createEntry(type);
232+
auto entry = createTypeEntry(type);
233233
entry.parent = dispatcher_.fetchLabel(type.getParent());
234234
entry.associated_type_declaration = dispatcher_.fetchLabel(type.getAssocType());
235235
fillArchetypeType(type, entry);
@@ -248,26 +248,26 @@ void TypeVisitor::fillArchetypeType(const swift::ArchetypeType& type, ArchetypeT
248248
}
249249

250250
codeql::ExistentialType TypeVisitor::translateExistentialType(const swift::ExistentialType& type) {
251-
auto entry = createEntry(type);
251+
auto entry = createTypeEntry(type);
252252
entry.constraint = dispatcher_.fetchLabel(type.getConstraintType());
253253
return entry;
254254
}
255255

256256
codeql::DynamicSelfType TypeVisitor::translateDynamicSelfType(const swift::DynamicSelfType& type) {
257-
auto entry = createEntry(type);
257+
auto entry = createTypeEntry(type);
258258
entry.static_self_type = dispatcher_.fetchLabel(type.getSelfType());
259259
return entry;
260260
}
261261

262262
codeql::VariadicSequenceType TypeVisitor::translateVariadicSequenceType(
263263
const swift::VariadicSequenceType& type) {
264-
auto entry = createEntry(type);
264+
auto entry = createTypeEntry(type);
265265
fillUnarySyntaxSugarType(type, entry);
266266
return entry;
267267
}
268268

269269
codeql::InOutType TypeVisitor::translateInOutType(const swift::InOutType& type) {
270-
auto entry = createEntry(type);
270+
auto entry = createTypeEntry(type);
271271
entry.object_type = dispatcher_.fetchLabel(type.getObjectType());
272272
return entry;
273273
}
@@ -300,19 +300,19 @@ void TypeVisitor::fillReferenceStorageType(const swift::ReferenceStorageType& ty
300300

301301
codeql::ProtocolCompositionType TypeVisitor::translateProtocolCompositionType(
302302
const swift::ProtocolCompositionType& type) {
303-
auto entry = createEntry(type);
303+
auto entry = createTypeEntry(type);
304304
entry.members = dispatcher_.fetchRepeatedLabels(type.getMembers());
305305
return entry;
306306
}
307307

308308
codeql::BuiltinIntegerLiteralType TypeVisitor::translateBuiltinIntegerLiteralType(
309309
const swift::BuiltinIntegerLiteralType& type) {
310-
return createEntry(type);
310+
return createTypeEntry(type);
311311
}
312312

313313
codeql::BuiltinIntegerType TypeVisitor::translateBuiltinIntegerType(
314314
const swift::BuiltinIntegerType& type) {
315-
auto entry = createEntry(type);
315+
auto entry = createTypeEntry(type);
316316
if (type.isFixedWidth()) {
317317
entry.width = type.getFixedWidth();
318318
}
@@ -321,51 +321,51 @@ codeql::BuiltinIntegerType TypeVisitor::translateBuiltinIntegerType(
321321

322322
codeql::BuiltinBridgeObjectType TypeVisitor::translateBuiltinBridgeObjectType(
323323
const swift::BuiltinBridgeObjectType& type) {
324-
return createEntry(type);
324+
return createTypeEntry(type);
325325
}
326326

327327
codeql::BuiltinDefaultActorStorageType TypeVisitor::translateBuiltinDefaultActorStorageType(
328328
const swift::BuiltinDefaultActorStorageType& type) {
329-
return createEntry(type);
329+
return createTypeEntry(type);
330330
}
331331

332332
codeql::BuiltinExecutorType TypeVisitor::translateBuiltinExecutorType(
333333
const swift::BuiltinExecutorType& type) {
334-
return createEntry(type);
334+
return createTypeEntry(type);
335335
}
336336

337337
codeql::BuiltinFloatType TypeVisitor::translateBuiltinFloatType(
338338
const swift::BuiltinFloatType& type) {
339-
return createEntry(type);
339+
return createTypeEntry(type);
340340
}
341341

342342
codeql::BuiltinJobType TypeVisitor::translateBuiltinJobType(const swift::BuiltinJobType& type) {
343-
return createEntry(type);
343+
return createTypeEntry(type);
344344
}
345345

346346
codeql::BuiltinNativeObjectType TypeVisitor::translateBuiltinNativeObjectType(
347347
const swift::BuiltinNativeObjectType& type) {
348-
return createEntry(type);
348+
return createTypeEntry(type);
349349
}
350350

351351
codeql::BuiltinRawPointerType TypeVisitor::translateBuiltinRawPointerType(
352352
const swift::BuiltinRawPointerType& type) {
353-
return createEntry(type);
353+
return createTypeEntry(type);
354354
}
355355

356356
codeql::BuiltinRawUnsafeContinuationType TypeVisitor::translateBuiltinRawUnsafeContinuationType(
357357
const swift::BuiltinRawUnsafeContinuationType& type) {
358-
return createEntry(type);
358+
return createTypeEntry(type);
359359
}
360360

361361
codeql::BuiltinUnsafeValueBufferType TypeVisitor::translateBuiltinUnsafeValueBufferType(
362362
const swift::BuiltinUnsafeValueBufferType& type) {
363-
return createEntry(type);
363+
return createTypeEntry(type);
364364
}
365365

366366
codeql::BuiltinVectorType TypeVisitor::translateBuiltinVectorType(
367367
const swift::BuiltinVectorType& type) {
368-
return createEntry(type);
368+
return createTypeEntry(type);
369369
}
370370

371371
} // namespace codeql

swift/extractor/visitors/TypeVisitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
8181
void emitAnyGenericType(swift::AnyGenericType* type, TrapLabel<AnyGenericTypeTag> label);
8282

8383
template <typename T>
84-
auto createEntry(const T& type) {
85-
TrapClassOf<T> entry{dispatcher_.assignNewLabel(type)};
84+
auto createTypeEntry(const T& type) {
85+
auto entry = dispatcher_.createEntry(type);
8686
fillType(type, entry);
8787
return entry;
8888
}

0 commit comments

Comments
 (0)