Skip to content

Commit 90ad36e

Browse files
committed
Swift: update extractor
1 parent ce1c4b8 commit 90ad36e

File tree

5 files changed

+45
-47
lines changed

5 files changed

+45
-47
lines changed

swift/extractor/infra/SwiftTagTraits.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ MAP(swift::Expr, ExprTag)
7777
MAP(swift::DeclRefExpr, DeclRefExprTag)
7878
MAP(swift::SuperRefExpr, SuperRefExprTag)
7979
MAP(swift::TypeExpr, TypeExprTag)
80-
MAP(swift::OtherConstructorDeclRefExpr, OtherConstructorDeclRefExprTag)
80+
MAP(swift::OtherConstructorDeclRefExpr, OtherInitializerRefExprTag)
8181
MAP(swift::DotSyntaxBaseIgnoredExpr, DotSyntaxBaseIgnoredExprTag)
8282
MAP(swift::OverloadSetRefExpr, OverloadedDeclRefExprTag) // collapsed with its only derived class OverloadedDeclRefExpr
8383
MAP(swift::OverloadedDeclRefExpr, OverloadedDeclRefExprTag)
@@ -108,13 +108,13 @@ MAP(swift::Expr, ExprTag)
108108
MAP(swift::KeyPathApplicationExpr, KeyPathApplicationExprTag)
109109
MAP(swift::TupleElementExpr, TupleElementExprTag)
110110
MAP(swift::CaptureListExpr, CaptureListExprTag)
111-
MAP(swift::AbstractClosureExpr, AbstractClosureExprTag)
112-
MAP(swift::ClosureExpr, ClosureExprTag)
111+
MAP(swift::AbstractClosureExpr, ClosureExprTag)
112+
MAP(swift::ClosureExpr, ExplicitClosureExprTag)
113113
MAP(swift::AutoClosureExpr, AutoClosureExprTag)
114114
MAP(swift::InOutExpr, InOutExprTag)
115115
MAP(swift::VarargExpansionExpr, VarargExpansionExprTag)
116116
MAP(swift::DynamicTypeExpr, DynamicTypeExprTag)
117-
MAP(swift::RebindSelfInConstructorExpr, RebindSelfInConstructorExprTag)
117+
MAP(swift::RebindSelfInConstructorExpr, RebindSelfInInitializerExprTag)
118118
MAP(swift::OpaqueValueExpr, OpaqueValueExprTag)
119119
MAP(swift::PropertyWrapperValuePlaceholderExpr, PropertyWrapperValuePlaceholderExprTag)
120120
MAP(swift::AppliedPropertyWrapperExpr, AppliedPropertyWrapperExprTag)
@@ -131,7 +131,7 @@ MAP(swift::Expr, ExprTag)
131131
MAP(swift::BinaryExpr, BinaryExprTag)
132132
MAP(swift::SelfApplyExpr, SelfApplyExprTag)
133133
MAP(swift::DotSyntaxCallExpr, DotSyntaxCallExprTag)
134-
MAP(swift::ConstructorRefCallExpr, ConstructorRefCallExprTag)
134+
MAP(swift::ConstructorRefCallExpr, InitializerRefCallExprTag)
135135
MAP(swift::ImplicitConversionExpr, ImplicitConversionExprTag)
136136
MAP(swift::LoadExpr, LoadExprTag)
137137
MAP(swift::DestructureTupleExpr, DestructureTupleExprTag)
@@ -178,7 +178,7 @@ MAP(swift::Expr, ExprTag)
178178
MAP(swift::AssignExpr, AssignExprTag)
179179
MAP(swift::CodeCompletionExpr, void) // only generated for code editing
180180
MAP(swift::UnresolvedPatternExpr, UnresolvedPatternExprTag)
181-
MAP(swift::LazyInitializerExpr, LazyInitializerExprTag)
181+
MAP(swift::LazyInitializerExpr, LazyInitializationExprTag)
182182
MAP(swift::EditorPlaceholderExpr, void) // only generated for code editing
183183
MAP(swift::ObjCSelectorExpr, ObjCSelectorExprTag)
184184
MAP(swift::KeyPathExpr, KeyPathExprTag)
@@ -207,12 +207,12 @@ MAP(swift::Decl, DeclTag)
207207
MAP_CONCRETE(swift::VarDecl, ConcreteVarDeclTag)
208208
MAP(swift::ParamDecl, ParamDeclTag)
209209
MAP(swift::SubscriptDecl, SubscriptDeclTag)
210-
MAP(swift::AbstractFunctionDecl, AbstractFunctionDeclTag)
211-
MAP(swift::ConstructorDecl, ConstructorDeclTag)
212-
MAP(swift::DestructorDecl, DestructorDeclTag)
213-
MAP(swift::FuncDecl, FuncDeclTag)
214-
MAP_CONCRETE(swift::FuncDecl, ConcreteFuncDeclTag)
215-
MAP(swift::AccessorDecl, AccessorDeclTag)
210+
MAP(swift::AbstractFunctionDecl, FunctionTag)
211+
MAP(swift::ConstructorDecl, InitializerTag)
212+
MAP(swift::DestructorDecl, DeinitializerTag)
213+
MAP(swift::FuncDecl, AccessorOrNamedFunctionTag)
214+
MAP_CONCRETE(swift::FuncDecl, NamedFunctionTag)
215+
MAP(swift::AccessorDecl, AccessorTag)
216216
MAP(swift::EnumElementDecl, EnumElementDeclTag)
217217
MAP(swift::ExtensionDecl, ExtensionDeclTag)
218218
MAP(swift::TopLevelCodeDecl, TopLevelCodeDeclTag)

swift/extractor/translators/DeclTranslator.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@ std::string constructName(const swift::DeclName& declName) {
2424
}
2525
} // namespace
2626

27-
codeql::ConcreteFuncDecl DeclTranslator::translateFuncDecl(const swift::FuncDecl& decl) {
27+
codeql::NamedFunction DeclTranslator::translateFuncDecl(const swift::FuncDecl& decl) {
2828
auto entry = createEntry(decl);
29-
fillAbstractFunctionDecl(decl, entry);
29+
fillFunction(decl, entry);
3030
return entry;
3131
}
3232

33-
codeql::ConstructorDecl DeclTranslator::translateConstructorDecl(
34-
const swift::ConstructorDecl& decl) {
33+
codeql::Initializer DeclTranslator::translateConstructorDecl(const swift::ConstructorDecl& decl) {
3534
auto entry = createEntry(decl);
36-
fillAbstractFunctionDecl(decl, entry);
35+
fillFunction(decl, entry);
3736
return entry;
3837
}
3938

40-
codeql::DestructorDecl DeclTranslator::translateDestructorDecl(const swift::DestructorDecl& decl) {
39+
codeql::Deinitializer DeclTranslator::translateDestructorDecl(const swift::DestructorDecl& decl) {
4140
auto entry = createEntry(decl);
42-
fillAbstractFunctionDecl(decl, entry);
41+
fillFunction(decl, entry);
4342
return entry;
4443
}
4544

@@ -173,7 +172,7 @@ codeql::TypeAliasDecl DeclTranslator::translateTypeAliasDecl(const swift::TypeAl
173172
return entry;
174173
}
175174

176-
codeql::AccessorDecl DeclTranslator::translateAccessorDecl(const swift::AccessorDecl& decl) {
175+
codeql::Accessor DeclTranslator::translateAccessorDecl(const swift::AccessorDecl& decl) {
177176
auto entry = createEntry(decl);
178177
switch (decl.getAccessorKind()) {
179178
case swift::AccessorKind::Get:
@@ -201,7 +200,7 @@ codeql::AccessorDecl DeclTranslator::translateAccessorDecl(const swift::Accessor
201200
entry.is_unsafe_mutable_address = true;
202201
break;
203202
}
204-
fillAbstractFunctionDecl(decl, entry);
203+
fillFunction(decl, entry);
205204
return entry;
206205
}
207206

@@ -251,8 +250,8 @@ codeql::ModuleDecl DeclTranslator::translateModuleDecl(const swift::ModuleDecl&
251250
return entry;
252251
}
253252

254-
void DeclTranslator::fillAbstractFunctionDecl(const swift::AbstractFunctionDecl& decl,
255-
codeql::AbstractFunctionDecl& entry) {
253+
void DeclTranslator::fillFunction(const swift::AbstractFunctionDecl& decl,
254+
codeql::Function& entry) {
256255
assert(decl.hasParameterList() && "Expect functions to have a parameter list");
257256
entry.name = !decl.hasName() ? "(unnamed function decl)" : constructName(decl.getName());
258257
entry.body = dispatcher.fetchOptionalLabel(decl.getBody());
@@ -328,7 +327,7 @@ void DeclTranslator::fillValueDecl(const swift::ValueDecl& decl, codeql::ValueDe
328327

329328
void DeclTranslator::fillAbstractStorageDecl(const swift::AbstractStorageDecl& decl,
330329
codeql::AbstractStorageDecl& entry) {
331-
entry.accessor_decls = dispatcher.fetchRepeatedLabels(decl.getAllAccessors());
330+
entry.accessors = dispatcher.fetchRepeatedLabels(decl.getAllAccessors());
332331
fillValueDecl(decl, entry);
333332
}
334333

swift/extractor/translators/DeclTranslator.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class DeclTranslator : public AstTranslatorBase<DeclTranslator> {
1616
public:
1717
using AstTranslatorBase<DeclTranslator>::AstTranslatorBase;
1818

19-
codeql::ConcreteFuncDecl translateFuncDecl(const swift::FuncDecl& decl);
20-
codeql::ConstructorDecl translateConstructorDecl(const swift::ConstructorDecl& decl);
21-
codeql::DestructorDecl translateDestructorDecl(const swift::DestructorDecl& decl);
19+
codeql::NamedFunction translateFuncDecl(const swift::FuncDecl& decl);
20+
codeql::Initializer translateConstructorDecl(const swift::ConstructorDecl& decl);
21+
codeql::Deinitializer translateDestructorDecl(const swift::DestructorDecl& decl);
2222
codeql::PrefixOperatorDecl translatePrefixOperatorDecl(const swift::PrefixOperatorDecl& decl);
2323
codeql::PostfixOperatorDecl translatePostfixOperatorDecl(const swift::PostfixOperatorDecl& decl);
2424
codeql::InfixOperatorDecl translateInfixOperatorDecl(const swift::InfixOperatorDecl& decl);
@@ -37,7 +37,7 @@ class DeclTranslator : public AstTranslatorBase<DeclTranslator> {
3737
const swift::GenericTypeParamDecl& decl);
3838
codeql::AssociatedTypeDecl translateAssociatedTypeDecl(const swift::AssociatedTypeDecl& decl);
3939
codeql::TypeAliasDecl translateTypeAliasDecl(const swift::TypeAliasDecl& decl);
40-
codeql::AccessorDecl translateAccessorDecl(const swift::AccessorDecl& decl);
40+
codeql::Accessor translateAccessorDecl(const swift::AccessorDecl& decl);
4141
codeql::SubscriptDecl translateSubscriptDecl(const swift::SubscriptDecl& decl);
4242
codeql::ExtensionDecl translateExtensionDecl(const swift::ExtensionDecl& decl);
4343
codeql::ImportDecl translateImportDecl(const swift::ImportDecl& decl);
@@ -49,8 +49,7 @@ class DeclTranslator : public AstTranslatorBase<DeclTranslator> {
4949
codeql::CapturedDecl translateCapturedValue(const swift::CapturedValue& capture);
5050

5151
private:
52-
void fillAbstractFunctionDecl(const swift::AbstractFunctionDecl& decl,
53-
codeql::AbstractFunctionDecl& entry);
52+
void fillFunction(const swift::AbstractFunctionDecl& decl, codeql::Function& entry);
5453
void fillOperatorDecl(const swift::OperatorDecl& decl, codeql::OperatorDecl& entry);
5554
void fillTypeDecl(const swift::TypeDecl& decl, codeql::TypeDecl& entry);
5655
void fillIterableDeclContext(const swift::IterableDeclContext& decl, codeql::Decl& entry);

swift/extractor/translators/ExprTranslator.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ codeql::OptionalEvaluationExpr ExprTranslator::translateOptionalEvaluationExpr(
211211
return entry;
212212
}
213213

214-
codeql::RebindSelfInConstructorExpr ExprTranslator::translateRebindSelfInConstructorExpr(
214+
codeql::RebindSelfInInitializerExpr ExprTranslator::translateRebindSelfInConstructorExpr(
215215
const swift::RebindSelfInConstructorExpr& expr) {
216216
auto entry = createExprEntry(expr);
217217
entry.sub_expr = dispatcher.fetchLabel(expr.getSubExpr());
@@ -300,7 +300,7 @@ codeql::OptionalTryExpr ExprTranslator::translateOptionalTryExpr(
300300
return entry;
301301
}
302302

303-
codeql::ConstructorRefCallExpr ExprTranslator::translateConstructorRefCallExpr(
303+
codeql::InitializerRefCallExpr ExprTranslator::translateConstructorRefCallExpr(
304304
const swift::ConstructorRefCallExpr& expr) {
305305
auto entry = createExprEntry(expr);
306306
fillSelfApplyExpr(expr, entry);
@@ -313,16 +313,16 @@ codeql::DiscardAssignmentExpr ExprTranslator::translateDiscardAssignmentExpr(
313313
return entry;
314314
}
315315

316-
codeql::ClosureExpr ExprTranslator::translateClosureExpr(const swift::ClosureExpr& expr) {
316+
codeql::ExplicitClosureExpr ExprTranslator::translateClosureExpr(const swift::ClosureExpr& expr) {
317317
auto entry = createExprEntry(expr);
318-
fillAbstractClosureExpr(expr, entry);
318+
fillClosureExpr(expr, entry);
319319
return entry;
320320
}
321321

322322
codeql::AutoClosureExpr ExprTranslator::translateAutoClosureExpr(
323323
const swift::AutoClosureExpr& expr) {
324324
auto entry = createExprEntry(expr);
325-
fillAbstractClosureExpr(expr, entry);
325+
fillClosureExpr(expr, entry);
326326
return entry;
327327
}
328328

@@ -393,7 +393,7 @@ codeql::KeyPathExpr ExprTranslator::translateKeyPathExpr(const swift::KeyPathExp
393393
return entry;
394394
}
395395

396-
codeql::LazyInitializerExpr ExprTranslator::translateLazyInitializerExpr(
396+
codeql::LazyInitializationExpr ExprTranslator::translateLazyInitializerExpr(
397397
const swift::LazyInitializerExpr& expr) {
398398
auto entry = createExprEntry(expr);
399399
entry.sub_expr = dispatcher.fetchLabel(expr.getSubExpr());
@@ -427,10 +427,10 @@ codeql::KeyPathApplicationExpr ExprTranslator::translateKeyPathApplicationExpr(
427427
return entry;
428428
}
429429

430-
codeql::OtherConstructorDeclRefExpr ExprTranslator::translateOtherConstructorDeclRefExpr(
430+
codeql::OtherInitializerRefExpr ExprTranslator::translateOtherConstructorDeclRefExpr(
431431
const swift::OtherConstructorDeclRefExpr& expr) {
432432
auto entry = createExprEntry(expr);
433-
entry.constructor_decl = dispatcher.fetchLabel(expr.getDecl());
433+
entry.initializer = dispatcher.fetchLabel(expr.getDecl());
434434
return entry;
435435
}
436436

@@ -472,8 +472,8 @@ codeql::ErrorExpr ExprTranslator::translateErrorExpr(const swift::ErrorExpr& exp
472472
return entry;
473473
}
474474

475-
void ExprTranslator::fillAbstractClosureExpr(const swift::AbstractClosureExpr& expr,
476-
codeql::AbstractClosureExpr& entry) {
475+
void ExprTranslator::fillClosureExpr(const swift::AbstractClosureExpr& expr,
476+
codeql::ClosureExpr& entry) {
477477
assert(expr.getParameters() && "AbstractClosureExpr has getParameters()");
478478
entry.params = dispatcher.fetchRepeatedLabels(*expr.getParameters());
479479
entry.body = dispatcher.fetchLabel(expr.getBody());

swift/extractor/translators/ExprTranslator.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ExprTranslator : public AstTranslatorBase<ExprTranslator> {
3939
codeql::OpenExistentialExpr translateOpenExistentialExpr(const swift::OpenExistentialExpr& expr);
4040
codeql::OptionalEvaluationExpr translateOptionalEvaluationExpr(
4141
const swift::OptionalEvaluationExpr& expr);
42-
codeql::RebindSelfInConstructorExpr translateRebindSelfInConstructorExpr(
42+
codeql::RebindSelfInInitializerExpr translateRebindSelfInConstructorExpr(
4343
const swift::RebindSelfInConstructorExpr& expr);
4444
codeql::SuperRefExpr translateSuperRefExpr(const swift::SuperRefExpr& expr);
4545
codeql::DotSyntaxCallExpr translateDotSyntaxCallExpr(const swift::DotSyntaxCallExpr& expr);
@@ -69,11 +69,11 @@ class ExprTranslator : public AstTranslatorBase<ExprTranslator> {
6969
codeql::TryExpr translateTryExpr(const swift::TryExpr& expr);
7070
codeql::ForceTryExpr translateForceTryExpr(const swift::ForceTryExpr& expr);
7171
codeql::OptionalTryExpr translateOptionalTryExpr(const swift::OptionalTryExpr& expr);
72-
codeql::ConstructorRefCallExpr translateConstructorRefCallExpr(
72+
codeql::InitializerRefCallExpr translateConstructorRefCallExpr(
7373
const swift::ConstructorRefCallExpr& expr);
7474
codeql::DiscardAssignmentExpr translateDiscardAssignmentExpr(
7575
const swift::DiscardAssignmentExpr& expr);
76-
codeql::ClosureExpr translateClosureExpr(const swift::ClosureExpr& expr);
76+
codeql::ExplicitClosureExpr translateClosureExpr(const swift::ClosureExpr& expr);
7777
codeql::AutoClosureExpr translateAutoClosureExpr(const swift::AutoClosureExpr& expr);
7878
codeql::CoerceExpr translateCoerceExpr(const swift::CoerceExpr& expr);
7979
codeql::ConditionalCheckedCastExpr translateConditionalCheckedCastExpr(
@@ -85,13 +85,14 @@ class ExprTranslator : public AstTranslatorBase<ExprTranslator> {
8585
codeql::DictionaryExpr translateDictionaryExpr(const swift::DictionaryExpr& expr);
8686
codeql::MemberRefExpr translateMemberRefExpr(const swift::MemberRefExpr& expr);
8787
codeql::KeyPathExpr translateKeyPathExpr(const swift::KeyPathExpr& expr);
88-
codeql::LazyInitializerExpr translateLazyInitializerExpr(const swift::LazyInitializerExpr& expr);
88+
codeql::LazyInitializationExpr translateLazyInitializerExpr(
89+
const swift::LazyInitializerExpr& expr);
8990
codeql::ForceValueExpr translateForceValueExpr(const swift::ForceValueExpr& expr);
9091
codeql::IfExpr translateIfExpr(const swift::IfExpr& expr);
9192
codeql::KeyPathDotExpr translateKeyPathDotExpr(const swift::KeyPathDotExpr& expr);
9293
codeql::KeyPathApplicationExpr translateKeyPathApplicationExpr(
9394
const swift::KeyPathApplicationExpr& expr);
94-
codeql::OtherConstructorDeclRefExpr translateOtherConstructorDeclRefExpr(
95+
codeql::OtherInitializerRefExpr translateOtherConstructorDeclRefExpr(
9596
const swift::OtherConstructorDeclRefExpr& expr);
9697
codeql::UnresolvedDeclRefExpr translateUnresolvedDeclRefExpr(
9798
const swift::UnresolvedDeclRefExpr& expr);
@@ -118,8 +119,7 @@ class ExprTranslator : public AstTranslatorBase<ExprTranslator> {
118119
codeql::RegexLiteralExpr translateRegexLiteralExpr(const swift::RegexLiteralExpr& expr);
119120

120121
private:
121-
void fillAbstractClosureExpr(const swift::AbstractClosureExpr& expr,
122-
codeql::AbstractClosureExpr& entry);
122+
void fillClosureExpr(const swift::AbstractClosureExpr& expr, codeql::ClosureExpr& entry);
123123
TrapLabel<ArgumentTag> emitArgument(const swift::Argument& arg);
124124
TrapLabel<KeyPathComponentTag> emitKeyPathComponent(const swift::KeyPathExpr::Component& expr);
125125
void fillExplicitCastExpr(const swift::ExplicitCastExpr& expr, codeql::ExplicitCastExpr& entry);

0 commit comments

Comments
 (0)