Skip to content

Commit 7b9f886

Browse files
committed
Swift: describe TrapTagTraits API and implementation
1 parent efa4565 commit 7b9f886

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

swift/codegen/templates/trap_traps.mustache

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,5 @@ inline std::ostream &operator<<(std::ostream &out, const {{name}}{{trap_affix}}
2929
<< {{#get_streamer}}e.{{field_name}}{{/get_streamer}}{{/fields}} << ")";
3030
return out;
3131
}
32-
{{#id}}
33-
34-
template <>
35-
struct TagToBindingTrapFunctor<typename {{type}}::Tag> {
36-
using type = {{name}}{{trap_affix}};
37-
};
38-
{{/id}}
3932
{{/traps}}
4033
}

swift/extractor/SwiftTagTraits.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22

3+
// This file implements the mapping needed by the API defined in the TrapTagTraits.h
34
#include <swift/AST/ASTVisitor.h>
5+
#include "swift/extractor/trap/TrapTagTraits.h"
46
#include "swift/extractor/trap/generated/TrapTags.h"
57

68
namespace codeql {
@@ -12,22 +14,22 @@ using SILBoxTypeTag = SilBoxTypeTag;
1214
using SILFunctionTypeTag = SilFunctionTypeTag;
1315
using SILTokenTypeTag = SilTokenTypeTag;
1416

15-
#define MAP_TYPE_TO_TAG(TYPE, TAG) \
16-
template <> \
17-
struct ToTagFunctor<swift::TYPE> { \
18-
using type = TAG; \
17+
#define MAP_TYPE_TO_TAG(TYPE, TAG) \
18+
template <> \
19+
struct detail::ToTagFunctor<swift::TYPE> { \
20+
using type = TAG; \
1921
}
2022
#define MAP_TAG(TYPE) MAP_TYPE_TO_TAG(TYPE, TYPE##Tag)
2123
#define MAP_SUBTAG(TYPE, PARENT) \
2224
MAP_TAG(TYPE); \
2325
static_assert(std::is_base_of_v<PARENT##Tag, TYPE##Tag>, \
2426
#PARENT "Tag must be a base of " #TYPE "Tag");
2527

26-
#define OVERRIDE_TAG(TYPE, TAG) \
27-
template <> \
28-
struct ToTagOverride<swift::TYPE> { \
29-
using type = TAG; \
30-
}; \
28+
#define OVERRIDE_TAG(TYPE, TAG) \
29+
template <> \
30+
struct detail::ToTagOverride<swift::TYPE> { \
31+
using type = TAG; \
32+
}; \
3133
static_assert(std::is_base_of_v<TYPE##Tag, TAG>, "override is not a subtag");
3234

3335
MAP_TAG(Stmt);

swift/extractor/trap/TrapTagTraits.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#pragma once
22

3+
// This file defines functors that can be specialized to define a mapping from arbitrary types to
4+
// label tags
5+
36
#include <type_traits>
47

58
namespace codeql {
69

10+
namespace detail {
711
template <typename T>
812
struct ToTagFunctor;
913
template <typename T>
1014
struct ToTagOverride : ToTagFunctor<T> {};
1115

12-
template <typename T>
13-
using ToTag = typename ToTagOverride<std::remove_const_t<T>>::type;
16+
} // namespace detail
1417

1518
template <typename T>
16-
struct TagToBindingTrapFunctor;
17-
18-
template <typename Tag>
19-
using TagToBindingTrap = typename TagToBindingTrapFunctor<Tag>::type;
19+
using ToTag = typename detail::ToTagOverride<std::remove_const_t<T>>::type;
2020

2121
} // namespace codeql

0 commit comments

Comments
 (0)