|
| 1 | +// this is a sanity check that the hierarchy in swift is mapped by the mapping in |
| 2 | +// SwiftTypesToTagsMap.def to the hierarchy in schema.py |
| 3 | +// We rely on that so that the LabelStore will preserve correct typing. |
| 4 | +// For a class Derived: Base we could store the label for a Derived* pointer, and then fetch the |
| 5 | +// label for the same pointer as Base*. If the mapping did not preserve inheritance, we would end up |
| 6 | +// using a trap key of the DB type associated with Derived in a position expecting the incompatible |
| 7 | +// DB type associated with Base. |
| 8 | + |
| 9 | +#include "swift/extractor/infra/SwiftTagTraits.h" |
| 10 | + |
| 11 | +using namespace codeql; |
| 12 | + |
| 13 | +#define CHECK(KIND, TYPE, PARENT) \ |
| 14 | + static_assert(std::is_same_v<TrapTagOf<swift::TYPE##KIND>, void> || \ |
| 15 | + std::is_base_of_v<TrapTagOf<swift::PARENT>, TrapTagOf<swift::TYPE##KIND>>, \ |
| 16 | + "Tag of " #PARENT " must be a base of the tag of " #TYPE #KIND); |
| 17 | +#define CHECK_CONCRETE(KIND, TYPE, PARENT) \ |
| 18 | + CHECK(KIND, TYPE, PARENT) \ |
| 19 | + static_assert( \ |
| 20 | + std::is_same_v<TrapTagOf<swift::TYPE##KIND>, void> || \ |
| 21 | + std::is_base_of_v<TrapTagOf<swift::TYPE##KIND>, ConcreteTrapTagOf<swift::TYPE##KIND>>, \ |
| 22 | + "Tag of " #TYPE #KIND " must be a base of its concrete tag"); |
| 23 | + |
| 24 | +#define STMT(CLASS, PARENT) CHECK_CONCRETE(Stmt, CLASS, PARENT) |
| 25 | +#define ABSTRACT_STMT(CLASS, PARENT) CHECK(Stmt, CLASS, PARENT) |
| 26 | +#include <swift/AST/StmtNodes.def> |
| 27 | + |
| 28 | +#define EXPR(CLASS, PARENT) CHECK_CONCRETE(Expr, CLASS, PARENT) |
| 29 | +#define ABSTRACT_EXPR(CLASS, PARENT) CHECK(Expr, CLASS, PARENT) |
| 30 | +#include <swift/AST/ExprNodes.def> |
| 31 | + |
| 32 | +#define DECL(CLASS, PARENT) CHECK_CONCRETE(Decl, CLASS, PARENT) |
| 33 | +#define ABSTRACT_DECL(CLASS, PARENT) CHECK(Decl, CLASS, PARENT) |
| 34 | +#include <swift/AST/DeclNodes.def> |
| 35 | + |
| 36 | +#define PATTERN(CLASS, PARENT) CHECK_CONCRETE(Pattern, CLASS, PARENT) |
| 37 | +#define ABSTRACT_PATTERN(CLASS, PARENT) CHECK(Pattern, CLASS, PARENT) |
| 38 | +#include <swift/AST/PatternNodes.def> |
| 39 | + |
| 40 | +#define TYPE(CLASS, PARENT) CHECK_CONCRETE(Type, CLASS, PARENT) |
| 41 | +#define ABSTRACT_TYPE(CLASS, PARENT) CHECK(Type, CLASS, PARENT) |
| 42 | +#include <swift/AST/TypeNodes.def> |
0 commit comments