Skip to content

Commit 41977d1

Browse files
committed
Swift: implement extraction of new properties
1 parent 3de650e commit 41977d1

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

swift/extractor/translators/DeclTranslator.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <swift/AST/GenericParamList.h>
44
#include <swift/AST/ParameterList.h>
55
#include "swift/extractor/infra/SwiftDiagnosticKind.h"
6+
#include "swift/AST/PropertyWrappers.h"
67

78
namespace codeql {
89
namespace {
@@ -85,6 +86,11 @@ std::optional<codeql::ParamDecl> DeclTranslator::translateParamDecl(const swift:
8586
}
8687
fillVarDecl(decl, *entry);
8788
entry->is_inout = decl.isInOut();
89+
if (auto wrapped = decl.getPropertyWrapperWrappedValueVar()) {
90+
entry->property_wrapper_local_wrapped_var = dispatcher.fetchLabel(wrapped);
91+
entry->property_wrapper_local_wrapped_var_binding =
92+
dispatcher.fetchLabel(wrapped->getParentPatternBinding());
93+
}
8894
return entry;
8995
}
9096

@@ -355,6 +361,16 @@ void DeclTranslator::fillVarDecl(const swift::VarDecl& decl, codeql::VarDecl& en
355361
dispatcher.fetchOptionalLabel(decl.getPropertyWrapperBackingPropertyType());
356362
}
357363
fillAbstractStorageDecl(decl, entry);
364+
if (auto backing = decl.getPropertyWrapperBackingProperty()) {
365+
entry.property_wrapper_backing_var = dispatcher.fetchLabel(backing);
366+
entry.property_wrapper_backing_var_binding =
367+
dispatcher.fetchLabel(backing->getParentPatternBinding());
368+
}
369+
if (auto projection = decl.getPropertyWrapperProjectionVar()) {
370+
entry.property_wrapper_projection_var = dispatcher.fetchLabel(projection);
371+
entry.property_wrapper_projection_var_binding =
372+
dispatcher.fetchLabel(projection->getParentPatternBinding());
373+
}
358374
}
359375

360376
void DeclTranslator::fillNominalTypeDecl(const swift::NominalTypeDecl& decl,

swift/ql/test/library-tests/ast/PrintAst.expected

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,18 +3469,19 @@ declarations.swift:
34693469
#-----| getElement(0): [ReturnStmt] return ...
34703470
#-----| getResult(): [MemberRefExpr] .wrappedValue
34713471
#-----| getBase(): [DeclRefExpr] _x
3472+
#-----| getPropertyWrapperBackingVarBinding(): [PatternBindingDecl] var ... = ...
3473+
# 77| getInit(0): [CallExpr] call to init()
3474+
# 77| getFunction(): [ConstructorRefCallExpr] call to init()
3475+
# 77| getFunction(): [DeclRefExpr] init()
3476+
# 77| getArgument(0): [Argument] : ZeroWrapper.Type
3477+
# 77| getExpr(): [TypeExpr] ZeroWrapper.Type
3478+
# 77| getTypeRepr(): [TypeRepr] ZeroWrapper
3479+
# 77| getPattern(0): [TypedPattern] ... as ...
3480+
# 77| getSubPattern(): [NamedPattern] _x
3481+
# 77| getPropertyWrapperBackingVar(): [ConcreteVarDecl] _x
3482+
# 77| Type = ZeroWrapper
34723483
# 78| getElement(2): [ReturnStmt] return ...
34733484
# 78| getResult(): [DeclRefExpr] x
3474-
# 77| [CallExpr] call to init()
3475-
# 77| getFunction(): [ConstructorRefCallExpr] call to init()
3476-
# 77| getFunction(): [DeclRefExpr] init()
3477-
# 77| getArgument(0): [Argument] : ZeroWrapper.Type
3478-
# 77| getExpr(): [TypeExpr] ZeroWrapper.Type
3479-
# 77| getTypeRepr(): [TypeRepr] ZeroWrapper
3480-
# 77| [TypedPattern] ... as ...
3481-
# 77| getSubPattern(): [NamedPattern] _x
3482-
# 77| [ConcreteVarDecl] _x
3483-
# 77| Type = ZeroWrapper
34843485
# 81| [StructDecl] HasPropertyAndObserver
34853486
# 82| getMember(0): [PatternBindingDecl] var ... = ...
34863487
# 82| getPattern(0): [TypedPattern] ... as ...

0 commit comments

Comments
 (0)