mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Swift: implement ignoring of removed classes
This commit is contained in:
@@ -9,25 +9,39 @@
|
||||
|
||||
namespace codeql {
|
||||
|
||||
// codegen goes with QL acronym convention (Sil instead of SIL), we need to remap it to Swift's
|
||||
// convention
|
||||
using SILBlockStorageTypeTag = SilBlockStorageTypeTag;
|
||||
using SILBoxTypeTag = SilBoxTypeTag;
|
||||
using SILFunctionTypeTag = SilFunctionTypeTag;
|
||||
using SILTokenTypeTag = SilTokenTypeTag;
|
||||
|
||||
// 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;
|
||||
// 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;
|
||||
|
||||
#define MAP_TYPE_TO_TAG(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_base_of_v<PARENT##Tag, 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 OVERRIDE_TAG(TYPE, TAG) \
|
||||
|
||||
@@ -584,6 +584,7 @@ static int translatePropertyWrapperValueKind(swift::AppliedPropertyWrapperExpr::
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
codeql::AppliedPropertyWrapperExpr ExprTranslator::translateAppliedPropertyWrapperExpr(
|
||||
const swift::AppliedPropertyWrapperExpr& expr) {
|
||||
auto entry = createExprEntry(expr);
|
||||
|
||||
@@ -62,10 +62,15 @@ DEFINE_TRANSLATE_CHECKER(TypeRepr, , )
|
||||
// superclasses by default and instead provide our own TBD default (using the exact type).
|
||||
// Moreover, if the implementation class has translate##CLASS##KIND (that uses generated C++
|
||||
// classes), for the class of for a parent thereof, we want to use that. We detect that by using the
|
||||
// type traits HasTranslate##CLASS##KIND defined above
|
||||
// type traits HasTranslate##CLASS##KIND defined above.
|
||||
// A special case is for explicitly ignored classes marked with void, which we should never
|
||||
// encounter.
|
||||
#define DEFINE_VISIT(KIND, CLASS, PARENT) \
|
||||
void visit##CLASS##KIND(swift::CLASS##KIND* e) { \
|
||||
if constexpr (detail::HasTranslate##CLASS##KIND<CrtpSubclass>::value) { \
|
||||
if constexpr (std::is_same_v<CLASS##KIND##Tag, void>) { \
|
||||
std::cerr << "Unexpected " #CLASS #KIND "\n"; \
|
||||
return; \
|
||||
} else if constexpr (detail::HasTranslate##CLASS##KIND<CrtpSubclass>::value) { \
|
||||
dispatcher.emit(static_cast<CrtpSubclass*>(this)->translate##CLASS##KIND(*e)); \
|
||||
} else if constexpr (detail::HasTranslate##PARENT<CrtpSubclass>::value) { \
|
||||
dispatcher.emit(static_cast<CrtpSubclass*>(this)->translate##PARENT(*e)); \
|
||||
@@ -105,9 +110,6 @@ class AstTranslatorBase : private swift::ASTVisitor<CrtpSubclass>,
|
||||
|
||||
#define PATTERN(CLASS, PARENT) DEFINE_VISIT(Pattern, CLASS, PARENT)
|
||||
#include "swift/AST/PatternNodes.def"
|
||||
|
||||
#define TYPEREPR(CLASS, PARENT) DEFINE_VISIT(TypeRepr, CLASS, PARENT)
|
||||
#include "swift/AST/TypeReprNodes.def"
|
||||
};
|
||||
|
||||
// base class for our type visitor, getting a SwiftDispatcher member and define_visit emission for
|
||||
|
||||
Reference in New Issue
Block a user