Swift: implement extraction of new properties

This commit is contained in:
Paolo Tranquilli
2022-11-11 12:17:07 +01:00
parent 3de650e19d
commit 41977d1dbb
2 changed files with 27 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
#include <swift/AST/GenericParamList.h>
#include <swift/AST/ParameterList.h>
#include "swift/extractor/infra/SwiftDiagnosticKind.h"
#include "swift/AST/PropertyWrappers.h"
namespace codeql {
namespace {
@@ -85,6 +86,11 @@ std::optional<codeql::ParamDecl> DeclTranslator::translateParamDecl(const swift:
}
fillVarDecl(decl, *entry);
entry->is_inout = decl.isInOut();
if (auto wrapped = decl.getPropertyWrapperWrappedValueVar()) {
entry->property_wrapper_local_wrapped_var = dispatcher.fetchLabel(wrapped);
entry->property_wrapper_local_wrapped_var_binding =
dispatcher.fetchLabel(wrapped->getParentPatternBinding());
}
return entry;
}
@@ -355,6 +361,16 @@ void DeclTranslator::fillVarDecl(const swift::VarDecl& decl, codeql::VarDecl& en
dispatcher.fetchOptionalLabel(decl.getPropertyWrapperBackingPropertyType());
}
fillAbstractStorageDecl(decl, entry);
if (auto backing = decl.getPropertyWrapperBackingProperty()) {
entry.property_wrapper_backing_var = dispatcher.fetchLabel(backing);
entry.property_wrapper_backing_var_binding =
dispatcher.fetchLabel(backing->getParentPatternBinding());
}
if (auto projection = decl.getPropertyWrapperProjectionVar()) {
entry.property_wrapper_projection_var = dispatcher.fetchLabel(projection);
entry.property_wrapper_projection_var_binding =
dispatcher.fetchLabel(projection->getParentPatternBinding());
}
}
void DeclTranslator::fillNominalTypeDecl(const swift::NominalTypeDecl& decl,

View File

@@ -3469,18 +3469,19 @@ declarations.swift:
#-----| getElement(0): [ReturnStmt] return ...
#-----| getResult(): [MemberRefExpr] .wrappedValue
#-----| getBase(): [DeclRefExpr] _x
#-----| getPropertyWrapperBackingVarBinding(): [PatternBindingDecl] var ... = ...
# 77| getInit(0): [CallExpr] call to init()
# 77| getFunction(): [ConstructorRefCallExpr] call to init()
# 77| getFunction(): [DeclRefExpr] init()
# 77| getArgument(0): [Argument] : ZeroWrapper.Type
# 77| getExpr(): [TypeExpr] ZeroWrapper.Type
# 77| getTypeRepr(): [TypeRepr] ZeroWrapper
# 77| getPattern(0): [TypedPattern] ... as ...
# 77| getSubPattern(): [NamedPattern] _x
# 77| getPropertyWrapperBackingVar(): [ConcreteVarDecl] _x
# 77| Type = ZeroWrapper
# 78| getElement(2): [ReturnStmt] return ...
# 78| getResult(): [DeclRefExpr] x
# 77| [CallExpr] call to init()
# 77| getFunction(): [ConstructorRefCallExpr] call to init()
# 77| getFunction(): [DeclRefExpr] init()
# 77| getArgument(0): [Argument] : ZeroWrapper.Type
# 77| getExpr(): [TypeExpr] ZeroWrapper.Type
# 77| getTypeRepr(): [TypeRepr] ZeroWrapper
# 77| [TypedPattern] ... as ...
# 77| getSubPattern(): [NamedPattern] _x
# 77| [ConcreteVarDecl] _x
# 77| Type = ZeroWrapper
# 81| [StructDecl] HasPropertyAndObserver
# 82| getMember(0): [PatternBindingDecl] var ... = ...
# 82| getPattern(0): [TypedPattern] ... as ...