Skip to content

Commit a5899ee

Browse files
committed
Minor improvements to file_types
No intended functionality change.
1 parent 97b152d commit a5899ee

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

include/swift/Basic/FileTypes.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "swift/Basic/LLVM.h"
1717
#include "llvm/ADT/DenseMapInfo.h"
18+
#include "llvm/ADT/STLExtras.h"
1819
#include "llvm/ADT/StringRef.h"
19-
#include <functional>
2020

2121
namespace swift {
2222
namespace file_types {
@@ -58,8 +58,12 @@ bool isAfterLLVM(ID Id);
5858
/// These need to be passed to the Swift frontend
5959
bool isPartOfSwiftCompilation(ID Id);
6060

61-
template <typename Fn> void forAllTypes(const Fn &fn);
62-
} // namespace file_types
61+
static inline void forAllTypes(llvm::function_ref<void(file_types::ID)> fn) {
62+
for (uint8_t i = 0; i < static_cast<uint8_t>(TY_INVALID); ++i)
63+
fn(static_cast<ID>(i));
64+
}
65+
66+
} // end namespace file_types
6367
} // end namespace swift
6468

6569
namespace llvm {
@@ -72,14 +76,6 @@ template <> struct DenseMapInfo<swift::file_types::ID> {
7276
static unsigned getHashValue(ID Val) { return (unsigned)Val * 37U; }
7377
static bool isEqual(ID LHS, ID RHS) { return LHS == RHS; }
7478
};
75-
} // namespace llvm
76-
77-
template <typename Fn> void swift::file_types::forAllTypes(const Fn &fn) {
78-
static_assert(
79-
std::is_constructible<std::function<void(file_types::ID)>, Fn>::value,
80-
"must have the signature 'void(file_types::ID)'");
81-
for (uint8_t i = 0; i < static_cast<uint8_t>(TY_INVALID); ++i)
82-
fn(static_cast<ID>(i));
83-
}
79+
} // end namespace llvm
8480

8581
#endif

lib/Basic/FileTypes.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020
using namespace swift;
2121
using namespace swift::file_types;
2222

23+
namespace {
2324
struct TypeInfo {
2425
const char *Name;
2526
const char *Flags;
2627
const char *Extension;
2728
};
29+
} // end anonymous namespace
2830

2931
static const TypeInfo TypeInfos[] = {
30-
#define TYPE(NAME, ID, TEMP_SUFFIX, FLAGS) \
31-
{ NAME, FLAGS, TEMP_SUFFIX },
32+
#define TYPE(NAME, ID, EXTENSION, FLAGS) \
33+
{ NAME, FLAGS, EXTENSION },
3234
#include "swift/Basic/FileTypes.def"
3335
};
3436

@@ -48,15 +50,15 @@ ID file_types::lookupTypeForExtension(StringRef Ext) {
4850
return TY_INVALID;
4951
assert(Ext.front() == '.' && "not a file extension");
5052
return llvm::StringSwitch<file_types::ID>(Ext.drop_front())
51-
#define TYPE(NAME, ID, SUFFIX, FLAGS) \
52-
.Case(SUFFIX, TY_##ID)
53+
#define TYPE(NAME, ID, EXTENSION, FLAGS) \
54+
.Case(EXTENSION, TY_##ID)
5355
#include "swift/Basic/FileTypes.def"
5456
.Default(TY_INVALID);
5557
}
5658

5759
ID file_types::lookupTypeForName(StringRef Name) {
5860
return llvm::StringSwitch<file_types::ID>(Name)
59-
#define TYPE(NAME, ID, SUFFIX, FLAGS) \
61+
#define TYPE(NAME, ID, EXTENSION, FLAGS) \
6062
.Case(NAME, TY_##ID)
6163
#include "swift/Basic/FileTypes.def"
6264
.Default(TY_INVALID);

0 commit comments

Comments
 (0)