Swift: make mapping from swift types to tags explicit

This should decouple schema names from swift names, allowing to
rename schema names regardless of internal swift compiler names.
This commit is contained in:
Paolo Tranquilli
2022-11-25 13:10:33 +01:00
parent 53b86fd53b
commit edddaaa838
6 changed files with 357 additions and 91 deletions

View File

@@ -0,0 +1,42 @@
// this is a sanity check that the hierarchy in swift is mapped by the mapping in
// SwiftTypesToTagsMap.def to the hierarchy in schema.py
// We rely on that so that the LabelStore will preserve correct typing.
// For a class Derived: Base we could store the label for a Derived* pointer, and then fetch the
// label for the same pointer as Base*. If the mapping did not preserve inheritance, we would end up
// using a trap key of the DB type associated with Derived in a position expecting the incompatible
// DB type associated with Base.
#include "swift/extractor/infra/SwiftTagTraits.h"
using namespace codeql;
#define CHECK(KIND, TYPE, PARENT) \
static_assert(std::is_same_v<TrapTagOf<swift::TYPE##KIND>, void> || \
std::is_base_of_v<TrapTagOf<swift::PARENT>, TrapTagOf<swift::TYPE##KIND>>, \
"Tag of " #PARENT " must be a base of the tag of " #TYPE #KIND);
#define CHECK_CONCRETE(KIND, TYPE, PARENT) \
CHECK(KIND, TYPE, PARENT) \
static_assert( \
std::is_same_v<TrapTagOf<swift::TYPE##KIND>, void> || \
std::is_base_of_v<TrapTagOf<swift::TYPE##KIND>, ConcreteTrapTagOf<swift::TYPE##KIND>>, \
"Tag of " #TYPE #KIND " must be a base of its concrete tag");
#define STMT(CLASS, PARENT) CHECK_CONCRETE(Stmt, CLASS, PARENT)
#define ABSTRACT_STMT(CLASS, PARENT) CHECK(Stmt, CLASS, PARENT)
#include <swift/AST/StmtNodes.def>
#define EXPR(CLASS, PARENT) CHECK_CONCRETE(Expr, CLASS, PARENT)
#define ABSTRACT_EXPR(CLASS, PARENT) CHECK(Expr, CLASS, PARENT)
#include <swift/AST/ExprNodes.def>
#define DECL(CLASS, PARENT) CHECK_CONCRETE(Decl, CLASS, PARENT)
#define ABSTRACT_DECL(CLASS, PARENT) CHECK(Decl, CLASS, PARENT)
#include <swift/AST/DeclNodes.def>
#define PATTERN(CLASS, PARENT) CHECK_CONCRETE(Pattern, CLASS, PARENT)
#define ABSTRACT_PATTERN(CLASS, PARENT) CHECK(Pattern, CLASS, PARENT)
#include <swift/AST/PatternNodes.def>
#define TYPE(CLASS, PARENT) CHECK_CONCRETE(Type, CLASS, PARENT)
#define ABSTRACT_TYPE(CLASS, PARENT) CHECK(Type, CLASS, PARENT)
#include <swift/AST/TypeNodes.def>

View File

@@ -179,16 +179,16 @@ class SwiftDispatcher {
// it actually gets emitted to handle recursive cases such as recursive calls, or recursive type
// declarations
template <typename E, typename... Args, std::enable_if_t<IsStorable<E>>* = nullptr>
TrapLabelOf<E> assignNewLabel(const E& e, Args&&... args) {
TrapLabel<ConcreteTrapTagOf<E>> assignNewLabel(const E& e, Args&&... args) {
assert(waitingForNewLabel == Store::Handle{e} && "assignNewLabel called on wrong entity");
auto label = trap.createLabel<TrapTagOf<E>>(std::forward<Args>(args)...);
auto label = trap.createLabel<ConcreteTrapTagOf<E>>(std::forward<Args>(args)...);
store.insert(e, label);
waitingForNewLabel = std::monostate{};
return label;
}
template <typename E, typename... Args, std::enable_if_t<IsStorable<E*>>* = nullptr>
TrapLabelOf<E> assignNewLabel(const E& e, Args&&... args) {
TrapLabel<ConcreteTrapTagOf<E>> assignNewLabel(const E& e, Args&&... args) {
return assignNewLabel(&e, std::forward<Args>(args)...);
}

View File

@@ -1,100 +1,319 @@
#pragma once
// This file implements the mapping needed by the API defined in the TrapTagTraits.h, so that
// TrapTagOf/TrapLabelOf provide the tags/labels for specific swift entity types.
// TrapTagOf/TrapLabelOf/TrapClassOf provide the tags/labels for specific swift entity types.
#include <filesystem>
#include <swift/AST/ASTVisitor.h>
#include "swift/extractor/trap/TrapTagTraits.h"
#include "swift/extractor/trap/generated/TrapTags.h"
#include <swift/AST/ASTNode.h>
#include <swift/AST/Decl.h>
#include <swift/AST/Expr.h>
#include <swift/AST/Stmt.h>
#include <swift/AST/Pattern.h>
#include <swift/AST/TypeRepr.h>
#include <swift/AST/Type.h>
namespace codeql {
// OverloadSetRefExpr is collapsed with its only derived class OverloadedDeclRefExpr
using OverloadSetRefExprTag = OverloadedDeclRefExprTag;
// We don't really expect to see the following in extraction. Mapping these tags to void effectively
// ignores all elements of that class (with a message).
// only generated for code editing
using CodeCompletionExprTag = void;
using EditorPlaceholderExprTag = void;
// not present after the Sema phase
using ArrowExprTag = void;
// experimental variadic generics, implemented only in the frontend for now, thus not compilable
using PackExprTag = void;
using PackTypeTag = void;
using ReifyPackExprTag = void;
using PackExpansionTypeTag = void;
using SequenceArchetypeTypeTag = void;
// Placeholder types appear in ambiguous types but are anyway transformed to UnresolvedType
using PlaceholderTypeTag = void;
// SIL types that cannot really appear in the frontend run
using SILBlockStorageTypeTag = void;
using SILBoxTypeTag = void;
using SILFunctionTypeTag = void;
using SILTokenTypeTag = void;
// This is created during type checking and is only used for constraint checking
using TypeVariableTypeTag = void;
#define MAP_TYPE_TO_TAG(TYPE, TAG) \
#define MAP(TYPE, TAG) \
template <> \
struct detail::ToTagFunctor<TYPE> { \
using type = TAG; \
}
#define MAP_TAG(TYPE) MAP_TYPE_TO_TAG(swift::TYPE, TYPE##Tag)
#define MAP_SUBTAG(TYPE, PARENT) \
MAP_TAG(TYPE); \
static_assert(std::is_same_v<TYPE##Tag, void> || std::is_base_of_v<PARENT##Tag, TYPE##Tag>, \
#PARENT "Tag must be a base of " #TYPE "Tag");
};
#define MAP_CONCRETE(TYPE, TAG) \
template <> \
struct detail::ToTagConcreteOverride<TYPE> { \
using type = TAG; \
};
#define OVERRIDE_TAG(TYPE, TAG) \
template <> \
struct detail::ToTagOverride<swift::TYPE> { \
using type = TAG; \
}; \
static_assert(std::is_base_of_v<TYPE##Tag, TAG>, "override is not a subtag");
// clang-format off
// use indentation to recreate all involved type hierarchies
MAP(std::filesystem::path, DbFileTag)
MAP(swift::StmtCondition, StmtConditionTag)
MAP(swift::StmtConditionElement, ConditionElementTag)
MAP(swift::CaseLabelItem, CaseLabelItemTag)
MAP_TAG(Stmt);
MAP_TAG(StmtCondition);
MAP_TYPE_TO_TAG(swift::StmtConditionElement, ConditionElementTag);
MAP_TAG(CaseLabelItem);
#define ABSTRACT_STMT(CLASS, PARENT) MAP_SUBTAG(CLASS##Stmt, PARENT)
#define STMT(CLASS, PARENT) ABSTRACT_STMT(CLASS, PARENT)
#include <swift/AST/StmtNodes.def>
MAP(swift::Stmt, StmtTag)
MAP(swift::BraceStmt, BraceStmtTag)
MAP(swift::ReturnStmt, ReturnStmtTag)
MAP(swift::YieldStmt, YieldStmtTag)
MAP(swift::DeferStmt, DeferStmtTag)
MAP(swift::LabeledStmt, LabeledStmtTag)
MAP(swift::LabeledConditionalStmt, LabeledConditionalStmtTag)
MAP(swift::IfStmt, IfStmtTag)
MAP(swift::GuardStmt, GuardStmtTag)
MAP(swift::WhileStmt, WhileStmtTag)
MAP(swift::DoStmt, DoStmtTag)
MAP(swift::DoCatchStmt, DoCatchStmtTag)
MAP(swift::RepeatWhileStmt, RepeatWhileStmtTag)
MAP(swift::ForEachStmt, ForEachStmtTag)
MAP(swift::SwitchStmt, SwitchStmtTag)
MAP(swift::CaseStmt, CaseStmtTag)
MAP(swift::BreakStmt, BreakStmtTag)
MAP(swift::ContinueStmt, ContinueStmtTag)
MAP(swift::FallthroughStmt, FallthroughStmtTag)
MAP(swift::FailStmt, FailStmtTag)
MAP(swift::ThrowStmt, ThrowStmtTag)
MAP(swift::PoundAssertStmt, PoundAssertStmtTag)
MAP_TAG(Expr);
MAP_TAG(Argument);
#define ABSTRACT_EXPR(CLASS, PARENT) MAP_SUBTAG(CLASS##Expr, PARENT)
#define EXPR(CLASS, PARENT) ABSTRACT_EXPR(CLASS, PARENT)
#include <swift/AST/ExprNodes.def>
MAP(swift::Argument, ArgumentTag)
MAP(swift::Expr, ExprTag)
MAP(swift::ErrorExpr, ErrorExprTag)
MAP(swift::LiteralExpr, LiteralExprTag)
MAP(swift::NilLiteralExpr, NilLiteralExprTag)
MAP(swift::BuiltinLiteralExpr, BuiltinLiteralExprTag)
MAP(swift::BooleanLiteralExpr, BooleanLiteralExprTag)
MAP(swift::NumberLiteralExpr, NumberLiteralExprTag)
MAP(swift::IntegerLiteralExpr, IntegerLiteralExprTag)
MAP(swift::FloatLiteralExpr, FloatLiteralExprTag)
MAP(swift::StringLiteralExpr, StringLiteralExprTag)
MAP(swift::MagicIdentifierLiteralExpr, MagicIdentifierLiteralExprTag)
MAP(swift::InterpolatedStringLiteralExpr, InterpolatedStringLiteralExprTag)
MAP(swift::RegexLiteralExpr, RegexLiteralExprTag)
MAP(swift::ObjectLiteralExpr, ObjectLiteralExprTag)
MAP(swift::DiscardAssignmentExpr, DiscardAssignmentExprTag)
MAP(swift::DeclRefExpr, DeclRefExprTag)
MAP(swift::SuperRefExpr, SuperRefExprTag)
MAP(swift::TypeExpr, TypeExprTag)
MAP(swift::OtherConstructorDeclRefExpr, OtherConstructorDeclRefExprTag)
MAP(swift::DotSyntaxBaseIgnoredExpr, DotSyntaxBaseIgnoredExprTag)
MAP(swift::OverloadSetRefExpr, OverloadedDeclRefExprTag) // collapsed with its only derived class OverloadedDeclRefExpr
MAP(swift::OverloadedDeclRefExpr, OverloadedDeclRefExprTag)
MAP(swift::UnresolvedDeclRefExpr, UnresolvedDeclRefExprTag)
MAP(swift::LookupExpr, LookupExprTag)
MAP(swift::MemberRefExpr, MemberRefExprTag)
MAP(swift::SubscriptExpr, SubscriptExprTag)
MAP(swift::DynamicLookupExpr, DynamicLookupExprTag)
MAP(swift::DynamicMemberRefExpr, DynamicMemberRefExprTag)
MAP(swift::DynamicSubscriptExpr, DynamicSubscriptExprTag)
MAP(swift::UnresolvedSpecializeExpr, UnresolvedSpecializeExprTag)
MAP(swift::UnresolvedMemberExpr, UnresolvedMemberExprTag)
MAP(swift::UnresolvedDotExpr, UnresolvedDotExprTag)
MAP(swift::SequenceExpr, SequenceExprTag)
MAP(swift::IdentityExpr, IdentityExprTag)
MAP(swift::ParenExpr, ParenExprTag)
MAP(swift::DotSelfExpr, DotSelfExprTag)
MAP(swift::AwaitExpr, AwaitExprTag)
MAP(swift::UnresolvedMemberChainResultExpr, UnresolvedMemberChainResultExprTag)
MAP(swift::AnyTryExpr, AnyTryExprTag)
MAP(swift::TryExpr, TryExprTag)
MAP(swift::ForceTryExpr, ForceTryExprTag)
MAP(swift::OptionalTryExpr, OptionalTryExprTag)
MAP(swift::TupleExpr, TupleExprTag)
MAP(swift::CollectionExpr, CollectionExprTag)
MAP(swift::ArrayExpr, ArrayExprTag)
MAP(swift::DictionaryExpr, DictionaryExprTag)
MAP(swift::KeyPathApplicationExpr, KeyPathApplicationExprTag)
MAP(swift::TupleElementExpr, TupleElementExprTag)
MAP(swift::CaptureListExpr, CaptureListExprTag)
MAP(swift::AbstractClosureExpr, AbstractClosureExprTag)
MAP(swift::ClosureExpr, ClosureExprTag)
MAP(swift::AutoClosureExpr, AutoClosureExprTag)
MAP(swift::InOutExpr, InOutExprTag)
MAP(swift::VarargExpansionExpr, VarargExpansionExprTag)
MAP(swift::DynamicTypeExpr, DynamicTypeExprTag)
MAP(swift::RebindSelfInConstructorExpr, RebindSelfInConstructorExprTag)
MAP(swift::OpaqueValueExpr, OpaqueValueExprTag)
MAP(swift::PropertyWrapperValuePlaceholderExpr, PropertyWrapperValuePlaceholderExprTag)
MAP(swift::AppliedPropertyWrapperExpr, AppliedPropertyWrapperExprTag)
MAP(swift::DefaultArgumentExpr, DefaultArgumentExprTag)
MAP(swift::BindOptionalExpr, BindOptionalExprTag)
MAP(swift::OptionalEvaluationExpr, OptionalEvaluationExprTag)
MAP(swift::ForceValueExpr, ForceValueExprTag)
MAP(swift::OpenExistentialExpr, OpenExistentialExprTag)
MAP(swift::MakeTemporarilyEscapableExpr, MakeTemporarilyEscapableExprTag)
MAP(swift::ApplyExpr, ApplyExprTag)
MAP(swift::CallExpr, CallExprTag)
MAP(swift::PrefixUnaryExpr, PrefixUnaryExprTag)
MAP(swift::PostfixUnaryExpr, PostfixUnaryExprTag)
MAP(swift::BinaryExpr, BinaryExprTag)
MAP(swift::SelfApplyExpr, SelfApplyExprTag)
MAP(swift::DotSyntaxCallExpr, DotSyntaxCallExprTag)
MAP(swift::ConstructorRefCallExpr, ConstructorRefCallExprTag)
MAP(swift::ImplicitConversionExpr, ImplicitConversionExprTag)
MAP(swift::LoadExpr, LoadExprTag)
MAP(swift::DestructureTupleExpr, DestructureTupleExprTag)
MAP(swift::UnresolvedTypeConversionExpr, UnresolvedTypeConversionExprTag)
MAP(swift::FunctionConversionExpr, FunctionConversionExprTag)
MAP(swift::CovariantFunctionConversionExpr, CovariantFunctionConversionExprTag)
MAP(swift::CovariantReturnConversionExpr, CovariantReturnConversionExprTag)
MAP(swift::MetatypeConversionExpr, MetatypeConversionExprTag)
MAP(swift::CollectionUpcastConversionExpr, CollectionUpcastConversionExprTag)
MAP(swift::ErasureExpr, ErasureExprTag)
MAP(swift::AnyHashableErasureExpr, AnyHashableErasureExprTag)
MAP(swift::BridgeToObjCExpr, BridgeToObjCExprTag)
MAP(swift::BridgeFromObjCExpr, BridgeFromObjCExprTag)
MAP(swift::ConditionalBridgeFromObjCExpr, ConditionalBridgeFromObjCExprTag)
MAP(swift::DerivedToBaseExpr, DerivedToBaseExprTag)
MAP(swift::ArchetypeToSuperExpr, ArchetypeToSuperExprTag)
MAP(swift::InjectIntoOptionalExpr, InjectIntoOptionalExprTag)
MAP(swift::ClassMetatypeToObjectExpr, ClassMetatypeToObjectExprTag)
MAP(swift::ExistentialMetatypeToObjectExpr, ExistentialMetatypeToObjectExprTag)
MAP(swift::ProtocolMetatypeToObjectExpr, ProtocolMetatypeToObjectExprTag)
MAP(swift::InOutToPointerExpr, InOutToPointerExprTag)
MAP(swift::ArrayToPointerExpr, ArrayToPointerExprTag)
MAP(swift::StringToPointerExpr, StringToPointerExprTag)
MAP(swift::PointerToPointerExpr, PointerToPointerExprTag)
MAP(swift::ForeignObjectConversionExpr, ForeignObjectConversionExprTag)
MAP(swift::UnevaluatedInstanceExpr, UnevaluatedInstanceExprTag)
MAP(swift::UnderlyingToOpaqueExpr, UnderlyingToOpaqueExprTag)
MAP(swift::DifferentiableFunctionExpr, DifferentiableFunctionExprTag)
MAP(swift::LinearFunctionExpr, LinearFunctionExprTag)
MAP(swift::DifferentiableFunctionExtractOriginalExpr, DifferentiableFunctionExtractOriginalExprTag)
MAP(swift::LinearFunctionExtractOriginalExpr, LinearFunctionExtractOriginalExprTag)
MAP(swift::LinearToDifferentiableFunctionExpr, LinearToDifferentiableFunctionExprTag)
MAP(swift::ReifyPackExpr, void) // experimental variadic generics
MAP(swift::ExplicitCastExpr, ExplicitCastExprTag)
MAP(swift::CheckedCastExpr, CheckedCastExprTag)
MAP(swift::ForcedCheckedCastExpr, ForcedCheckedCastExprTag)
MAP(swift::ConditionalCheckedCastExpr, ConditionalCheckedCastExprTag)
MAP(swift::IsExpr, IsExprTag)
MAP(swift::CoerceExpr, CoerceExprTag)
MAP(swift::ArrowExpr, void) // not present after the Sema phase
MAP(swift::IfExpr, IfExprTag)
MAP(swift::EnumIsCaseExpr, EnumIsCaseExprTag)
MAP(swift::AssignExpr, AssignExprTag)
MAP(swift::CodeCompletionExpr, void) // only generated for code editing
MAP(swift::UnresolvedPatternExpr, UnresolvedPatternExprTag)
MAP(swift::LazyInitializerExpr, LazyInitializerExprTag)
MAP(swift::EditorPlaceholderExpr, void) // only generated for code editing
MAP(swift::ObjCSelectorExpr, ObjCSelectorExprTag)
MAP(swift::KeyPathExpr, KeyPathExprTag)
MAP(swift::KeyPathDotExpr, KeyPathDotExprTag)
MAP(swift::OneWayExpr, OneWayExprTag)
MAP(swift::TapExpr, TapExprTag)
MAP(swift::PackExpr, void) // experimental variadic generics
MAP_TAG(Decl);
#define ABSTRACT_DECL(CLASS, PARENT) MAP_SUBTAG(CLASS##Decl, PARENT)
#define DECL(CLASS, PARENT) ABSTRACT_DECL(CLASS, PARENT)
#include <swift/AST/DeclNodes.def>
MAP(swift::Decl, DeclTag)
MAP(swift::ValueDecl, ValueDeclTag)
MAP(swift::TypeDecl, TypeDeclTag)
MAP(swift::GenericTypeDecl, GenericTypeDeclTag)
MAP(swift::NominalTypeDecl, NominalTypeDeclTag)
MAP(swift::EnumDecl, EnumDeclTag)
MAP(swift::StructDecl, StructDeclTag)
MAP(swift::ClassDecl, ClassDeclTag)
MAP(swift::ProtocolDecl, ProtocolDeclTag)
MAP(swift::OpaqueTypeDecl, OpaqueTypeDeclTag)
MAP(swift::TypeAliasDecl, TypeAliasDeclTag)
MAP(swift::AbstractTypeParamDecl, AbstractTypeParamDeclTag)
MAP(swift::GenericTypeParamDecl, GenericTypeParamDeclTag)
MAP(swift::AssociatedTypeDecl, AssociatedTypeDeclTag)
MAP(swift::ModuleDecl, ModuleDeclTag)
MAP(swift::AbstractStorageDecl, AbstractStorageDeclTag)
MAP(swift::VarDecl, VarDeclTag)
MAP_CONCRETE(swift::VarDecl, ConcreteVarDeclTag)
MAP(swift::ParamDecl, ParamDeclTag)
MAP(swift::SubscriptDecl, SubscriptDeclTag)
MAP(swift::AbstractFunctionDecl, AbstractFunctionDeclTag)
MAP(swift::ConstructorDecl, ConstructorDeclTag)
MAP(swift::DestructorDecl, DestructorDeclTag)
MAP(swift::FuncDecl, FuncDeclTag)
MAP_CONCRETE(swift::FuncDecl, ConcreteFuncDeclTag)
MAP(swift::AccessorDecl, AccessorDeclTag)
MAP(swift::EnumElementDecl, EnumElementDeclTag)
MAP(swift::ExtensionDecl, ExtensionDeclTag)
MAP(swift::TopLevelCodeDecl, TopLevelCodeDeclTag)
MAP(swift::ImportDecl, ImportDeclTag)
MAP(swift::IfConfigDecl, IfConfigDeclTag)
MAP(swift::PoundDiagnosticDecl, PoundDiagnosticDeclTag)
MAP(swift::PrecedenceGroupDecl, PrecedenceGroupDeclTag)
MAP(swift::MissingMemberDecl, MissingMemberDeclTag)
MAP(swift::PatternBindingDecl, PatternBindingDeclTag)
MAP(swift::EnumCaseDecl, EnumCaseDeclTag)
MAP(swift::OperatorDecl, OperatorDeclTag)
MAP(swift::InfixOperatorDecl, InfixOperatorDeclTag)
MAP(swift::PrefixOperatorDecl, PrefixOperatorDeclTag)
MAP(swift::PostfixOperatorDecl, PostfixOperatorDeclTag)
MAP_TAG(Pattern);
#define ABSTRACT_PATTERN(CLASS, PARENT) MAP_SUBTAG(CLASS##Pattern, PARENT)
#define PATTERN(CLASS, PARENT) ABSTRACT_PATTERN(CLASS, PARENT)
#include <swift/AST/PatternNodes.def>
MAP(swift::Pattern, PatternTag)
MAP(swift::ParenPattern, ParenPatternTag)
MAP(swift::TuplePattern, TuplePatternTag)
MAP(swift::NamedPattern, NamedPatternTag)
MAP(swift::AnyPattern, AnyPatternTag)
MAP(swift::TypedPattern, TypedPatternTag)
MAP(swift::BindingPattern, BindingPatternTag)
MAP(swift::IsPattern, IsPatternTag)
MAP(swift::EnumElementPattern, EnumElementPatternTag)
MAP(swift::OptionalSomePattern, OptionalSomePatternTag)
MAP(swift::BoolPattern, BoolPatternTag)
MAP(swift::ExprPattern, ExprPatternTag)
MAP_TAG(TypeRepr);
MAP_TYPE_TO_TAG(swift::TypeBase, TypeTag);
#define ABSTRACT_TYPE(CLASS, PARENT) MAP_SUBTAG(CLASS##Type, PARENT)
#define TYPE(CLASS, PARENT) ABSTRACT_TYPE(CLASS, PARENT)
#include <swift/AST/TypeNodes.def>
OVERRIDE_TAG(FuncDecl, ConcreteFuncDeclTag);
OVERRIDE_TAG(VarDecl, ConcreteVarDeclTag);
MAP_TYPE_TO_TAG(std::filesystem::path, DbFileTag);
#undef MAP_TAG
#undef MAP_SUBTAG
#undef MAP_TYPE_TO_TAG
#undef OVERRIDE_TAG
// All the other macros defined here are undefined by the .def files
MAP(swift::TypeRepr, TypeReprTag)
MAP(swift::Type, TypeTag)
MAP(swift::TypeBase, TypeTag)
MAP(swift::ErrorType, ErrorTypeTag)
MAP(swift::UnresolvedType, UnresolvedTypeTag)
MAP(swift::PlaceholderType, void) // appears in ambiguous types but are then transformed to UnresolvedType
MAP(swift::BuiltinType, BuiltinTypeTag)
MAP(swift::AnyBuiltinIntegerType, AnyBuiltinIntegerTypeTag)
MAP(swift::BuiltinIntegerType, BuiltinIntegerTypeTag)
MAP(swift::BuiltinIntegerLiteralType, BuiltinIntegerLiteralTypeTag)
MAP(swift::BuiltinExecutorType, BuiltinExecutorTypeTag)
MAP(swift::BuiltinFloatType, BuiltinFloatTypeTag)
MAP(swift::BuiltinJobType, BuiltinJobTypeTag)
MAP(swift::BuiltinRawPointerType, BuiltinRawPointerTypeTag)
MAP(swift::BuiltinRawUnsafeContinuationType, BuiltinRawUnsafeContinuationTypeTag)
MAP(swift::BuiltinNativeObjectType, BuiltinNativeObjectTypeTag)
MAP(swift::BuiltinBridgeObjectType, BuiltinBridgeObjectTypeTag)
MAP(swift::BuiltinUnsafeValueBufferType, BuiltinUnsafeValueBufferTypeTag)
MAP(swift::BuiltinDefaultActorStorageType, BuiltinDefaultActorStorageTypeTag)
MAP(swift::BuiltinVectorType, BuiltinVectorTypeTag)
MAP(swift::TupleType, TupleTypeTag)
MAP(swift::ReferenceStorageType, ReferenceStorageTypeTag)
MAP(swift::WeakStorageType, WeakStorageTypeTag)
MAP(swift::UnownedStorageType, UnownedStorageTypeTag)
MAP(swift::UnmanagedStorageType, UnmanagedStorageTypeTag)
MAP(swift::AnyGenericType, AnyGenericTypeTag)
MAP(swift::NominalOrBoundGenericNominalType, NominalOrBoundGenericNominalTypeTag)
MAP(swift::NominalType, NominalTypeTag)
MAP(swift::EnumType, EnumTypeTag)
MAP(swift::StructType, StructTypeTag)
MAP(swift::ClassType, ClassTypeTag)
MAP(swift::ProtocolType, ProtocolTypeTag)
MAP(swift::BoundGenericType, BoundGenericTypeTag)
MAP(swift::BoundGenericClassType, BoundGenericClassTypeTag)
MAP(swift::BoundGenericEnumType, BoundGenericEnumTypeTag)
MAP(swift::BoundGenericStructType, BoundGenericStructTypeTag)
MAP(swift::UnboundGenericType, UnboundGenericTypeTag)
MAP(swift::AnyMetatypeType, AnyMetatypeTypeTag)
MAP(swift::MetatypeType, MetatypeTypeTag)
MAP(swift::ExistentialMetatypeType, ExistentialMetatypeTypeTag)
MAP(swift::ModuleType, ModuleTypeTag)
MAP(swift::DynamicSelfType, DynamicSelfTypeTag)
MAP(swift::SubstitutableType, SubstitutableTypeTag)
MAP(swift::ArchetypeType, ArchetypeTypeTag)
MAP(swift::PrimaryArchetypeType, PrimaryArchetypeTypeTag)
MAP(swift::OpaqueTypeArchetypeType, OpaqueTypeArchetypeTypeTag)
MAP(swift::OpenedArchetypeType, OpenedArchetypeTypeTag)
MAP(swift::SequenceArchetypeType, void) // experimental variadic generics
MAP(swift::GenericTypeParamType, GenericTypeParamTypeTag)
MAP(swift::DependentMemberType, DependentMemberTypeTag)
MAP(swift::AnyFunctionType, AnyFunctionTypeTag)
MAP(swift::FunctionType, FunctionTypeTag)
MAP(swift::GenericFunctionType, GenericFunctionTypeTag)
MAP(swift::SILFunctionType, void) // SIL types cannot really appear in the frontend run)
MAP(swift::SILBlockStorageType, void) // SIL types cannot really appear in the frontend run)
MAP(swift::SILBoxType, void) // SIL types cannot really appear in the frontend run)
MAP(swift::SILTokenType, void) // SIL types cannot really appear in the frontend run)
MAP(swift::ProtocolCompositionType, ProtocolCompositionTypeTag)
MAP(swift::ParameterizedProtocolType, ParameterizedProtocolTypeTag)
MAP(swift::ExistentialType, ExistentialTypeTag)
MAP(swift::LValueType, LValueTypeTag)
MAP(swift::InOutType, InOutTypeTag)
MAP(swift::PackType, void) // experimental variadic generics
MAP(swift::PackExpansionType, void) // experimental variadic generics
MAP(swift::TypeVariableType, void) // created during type checking and only used for constraint checking
MAP(swift::SugarType, SugarTypeTag)
MAP(swift::ParenType, ParenTypeTag)
MAP(swift::TypeAliasType, TypeAliasTypeTag)
MAP(swift::SyntaxSugarType, SyntaxSugarTypeTag)
MAP(swift::UnarySyntaxSugarType, UnarySyntaxSugarTypeTag)
MAP(swift::ArraySliceType, ArraySliceTypeTag)
MAP(swift::OptionalType, OptionalTypeTag)
MAP(swift::VariadicSequenceType, VariadicSequenceTypeTag)
MAP(swift::DictionaryType, DictionaryTypeTag)
// clang-format on
#undef MAP
#undef MAP_CONCRETE
} // namespace codeql

View File

@@ -65,9 +65,9 @@ class DeclTranslator : public AstTranslatorBase<DeclTranslator> {
codeql::AbstractStorageDecl& entry);
template <typename D>
std::optional<TrapClassOf<D>> createNamedEntry(const D& decl) {
auto id = dispatcher.assignNewLabel(decl, mangledName(decl));
auto createNamedEntry(const D& decl) {
std::optional<TrapClassOf<D>> entry;
auto id = dispatcher.assignNewLabel(decl, mangledName(decl));
if (dispatcher.shouldEmitDeclBody(decl)) {
entry.emplace(id);
fillDecl(decl, *entry);
@@ -76,7 +76,7 @@ class DeclTranslator : public AstTranslatorBase<DeclTranslator> {
}
template <typename D>
TrapClassOf<D> createEntry(const D& decl) {
auto createEntry(const D& decl) {
TrapClassOf<D> entry{dispatcher.template assignNewLabel(decl)};
fillDecl(decl, entry);
return entry;

View File

@@ -75,7 +75,7 @@ enum class TranslatorPolicy {
#define DEFINE_VISIT(KIND, CLASS, PARENT) \
public: \
static constexpr TranslatorPolicy getPolicyFor##CLASS##KIND() { \
if constexpr (std::is_same_v<CLASS##KIND##Tag, void>) { \
if constexpr (std::is_same_v<TrapTagOf<swift::CLASS##KIND>, void>) { \
return TranslatorPolicy::ignore; \
} else if constexpr (detail::HasTranslate##CLASS##KIND<CrtpSubclass>::value) { \
return TranslatorPolicy::translate; \

View File

@@ -4,6 +4,7 @@
// label tags
#include <type_traits>
#include "swift/extractor/trap/TrapLabel.h"
namespace codeql {
@@ -14,7 +15,7 @@ struct ToTagFunctor;
// can be instantiated to override the default mapping for special cases
template <typename T>
struct ToTagOverride : ToTagFunctor<T> {};
struct ToTagConcreteOverride : ToTagFunctor<T> {};
// must be instantiated to map trap labels to the corresponding generated binding trap entry
template <typename Label>
@@ -27,15 +28,19 @@ struct ToTrapClassFunctor;
template <typename T>
using TrapTagOf =
typename detail::ToTagOverride<std::remove_const_t<std::remove_pointer_t<T>>>::type;
typename detail::ToTagFunctor<std::remove_const_t<std::remove_pointer_t<T>>>::type;
template <typename T>
using ConcreteTrapTagOf =
typename detail::ToTagConcreteOverride<std::remove_const_t<std::remove_pointer_t<T>>>::type;
template <typename T>
using TrapLabelOf = TrapLabel<TrapTagOf<T>>;
template <typename T>
using BindingTrapOf = typename detail::ToBindingTrapFunctor<TrapLabelOf<T>>::type;
using BindingTrapOf = typename detail::ToBindingTrapFunctor<TrapLabel<ConcreteTrapTagOf<T>>>::type;
template <typename T>
using TrapClassOf = typename detail::ToTrapClassFunctor<TrapTagOf<T>>::type;
using TrapClassOf = typename detail::ToTrapClassFunctor<ConcreteTrapTagOf<T>>::type;
} // namespace codeql