Skip to content

Commit 918a224

Browse files
committed
[ast] Define BuiltinTypeKind a derived enum from TypeKind that allows for exhaustive switching over builtin types.
I am going to use this to refactor some code in ASTPrinter onto BuiltinType wherein I use an exhaustive switch to print things as appropriate. Exhaustive switching over all builtin types just seems like a useful thing to have as well.
1 parent 75a5496 commit 918a224

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

include/swift/AST/Builtins.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
#ifndef SWIFT_AST_BUILTINS_H
1818
#define SWIFT_AST_BUILTINS_H
1919

20+
#include "swift/AST/Type.h"
21+
#include "swift/AST/Types.h"
2022
#include "swift/Basic/LLVM.h"
2123
#include "llvm/ADT/SmallVector.h"
2224
#include "llvm/IR/Attributes.h"
23-
#include "swift/AST/Type.h"
2425
#include "llvm/IR/Intrinsics.h"
2526
#include "llvm/Support/ErrorHandling.h"
2627

@@ -29,9 +30,17 @@ enum class AtomicOrdering;
2930
}
3031

3132
namespace swift {
32-
class ASTContext;
33-
class Identifier;
34-
class ValueDecl;
33+
34+
class ASTContext;
35+
class Identifier;
36+
class ValueDecl;
37+
38+
enum class BuiltinTypeKind : std::underlying_type<TypeKind>::type {
39+
#define TYPE(id, parent)
40+
#define BUILTIN_TYPE(id, parent) \
41+
id = std::underlying_type<TypeKind>::type(TypeKind::id),
42+
#include "swift/AST/TypeNodes.def"
43+
};
3544

3645
/// Get the builtin type for the given name.
3746
///
@@ -89,7 +98,6 @@ llvm::Intrinsic::ID getLLVMIntrinsicID(StringRef Name);
8998
llvm::Intrinsic::ID
9099
getLLVMIntrinsicIDForBuiltinWithOverflow(BuiltinValueKind ID);
91100

92-
93101
/// Create a ValueDecl for the builtin with the given name.
94102
///
95103
/// Returns null if the name does not identifier a known builtin value.

0 commit comments

Comments
 (0)