Skip to content

Commit 36b44bc

Browse files
committed
Basic: Introduce an x-macro for enumerating TypeIDZones
1 parent 537dd2b commit 36b44bc

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

include/swift/Basic/DefineTypeIDZone.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ template<> struct TypeIDZoneTypes<Zone::SWIFT_TYPEID_ZONE> {
4545
#undef SWIFT_TYPEID_NAMED
4646
#undef SWIFT_TYPEID_TEMPLATE1_NAMED
4747
#undef SWIFT_TYPEID_TEMPLATE2_NAMED
48+
Count
4849
};
4950
};
5051

5152
// Second pass: create specializations of TypeID for these types.
5253
#define SWIFT_TYPEID_NAMED(Type, Name) \
5354
template<> struct TypeID<Type> { \
54-
static const uint8_t zoneID = \
55-
static_cast<uint8_t>(Zone::SWIFT_TYPEID_ZONE); \
55+
static constexpr Zone zone = Zone::SWIFT_TYPEID_ZONE; \
56+
static const uint8_t zoneID = static_cast<uint8_t>(zone); \
5657
static const uint8_t localID = \
5758
TypeIDZoneTypes<Zone::SWIFT_TYPEID_ZONE>::Name; \
5859
\

include/swift/Basic/TypeID.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,9 @@
3131
namespace swift {
3232

3333
enum class Zone : uint8_t {
34-
C = 0,
35-
AST = 1,
36-
AccessControl = 11,
37-
IDETypes = 136,
38-
IDE = 137,
39-
IDETypeChecking = 97,
40-
NameLookup = 9,
41-
Parse = 8,
42-
TypeChecker = 10,
43-
SILGen = 12,
44-
SILOptimizer = 13,
45-
TBDGen = 14,
46-
IRGen = 20,
47-
48-
// N.B. This is not a formal zone and exists solely to support the unit tests.
49-
ArithmeticEvaluator = 255,
34+
#define SWIFT_TYPEID_ZONE(Name, Id) Name = Id,
35+
#include "swift/Basic/TypeIDZones.def"
36+
#undef SWIFT_TYPEID_ZONE
5037
};
5138

5239
static_assert(std::is_same<std::underlying_type<Zone>::type, uint8_t>::value,

include/swift/Basic/TypeIDZones.def

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- TypeIDZones.def - List of TypeID Zones -----------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This definition file describes the zones for TypeID.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
SWIFT_TYPEID_ZONE(C, 0)
18+
SWIFT_TYPEID_ZONE(AST, 1)
19+
20+
SWIFT_TYPEID_ZONE(Parse, 8)
21+
SWIFT_TYPEID_ZONE(NameLookup, 9)
22+
23+
SWIFT_TYPEID_ZONE(TypeChecker, 10)
24+
SWIFT_TYPEID_ZONE(AccessControl, 11)
25+
SWIFT_TYPEID_ZONE(SILGen, 12)
26+
SWIFT_TYPEID_ZONE(SILOptimizer, 13)
27+
SWIFT_TYPEID_ZONE(TBDGen, 14)
28+
29+
SWIFT_TYPEID_ZONE(IRGen, 20)
30+
31+
SWIFT_TYPEID_ZONE(IDETypeChecking, 97)
32+
33+
SWIFT_TYPEID_ZONE(IDETypes, 136)
34+
SWIFT_TYPEID_ZONE(IDE, 137)
35+
36+
// N.B. This is not a formal zone and exists solely to support the unit tests.
37+
SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255)

0 commit comments

Comments
 (0)