Skip to content

Commit ca5eacf

Browse files
authored
Merge pull request #18203 from jrose-apple/strung-out
Consistently get extensions from FileTypes.h.
2 parents ff70528 + a5899ee commit ca5eacf

28 files changed

+174
-156
lines changed

include/swift/Frontend/Types.def renamed to include/swift/Basic/FileTypes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TYPE("swiftinterface", SwiftModuleInterfaceFile, "swiftinterface", "")
5252
TYPE("assembly", Assembly, "s", "")
5353
TYPE("raw-sil", RawSIL, "sil", "")
5454
TYPE("raw-sib", RawSIB, "sib", "")
55-
TYPE("llvm-ir", LLVM_IR, "ir", "")
55+
TYPE("llvm-ir", LLVM_IR, "ll", "")
5656
TYPE("llvm-bc", LLVM_BC, "bc", "")
5757
TYPE("diagnostics", SerializedDiagnostics, "dia", "")
5858
TYPE("objc-header", ObjCHeader, "h", "")

include/swift/Frontend/FileTypes.h renamed to include/swift/Basic/FileTypes.h

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
//===--- FileTypes.h - Input & Temporary Driver Types -----------*- C++ -*-===//
1+
//===--- FileTypes.h - Input & output formats used by the tools -*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef SWIFT_FRONTEND_FILETYPES_H
14-
#define SWIFT_FRONTEND_FILETYPES_H
13+
#ifndef SWIFT_BASIC_FILETYPES_H
14+
#define SWIFT_BASIC_FILETYPES_H
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 {
2323
enum ID : uint8_t {
24-
#define TYPE(NAME, ID, TEMP_SUFFIX, FLAGS) TY_##ID,
25-
#include "swift/Frontend/Types.def"
24+
#define TYPE(NAME, ID, EXTENSION, FLAGS) TY_##ID,
25+
#include "swift/Basic/FileTypes.def"
2626
#undef TYPE
2727
TY_INVALID
2828
};
2929

3030
/// Return the name of the type for \p Id.
3131
StringRef getTypeName(ID Id);
3232

33-
/// Return the suffix to use when creating a temp file of this type,
34-
/// or null if unspecified.
35-
StringRef getTypeTempSuffix(ID Id);
33+
/// Return the extension to use when creating a file of this type,
34+
/// or an empty string if unspecified.
35+
StringRef getExtension(ID Id);
3636

3737
/// Lookup the type to use for the file extension \p Ext.
3838
/// If the extension is empty or is otherwise not recognized, return
@@ -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

include/swift/Driver/Action.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#ifndef SWIFT_DRIVER_ACTION_H
1414
#define SWIFT_DRIVER_ACTION_H
1515

16+
#include "swift/Basic/FileTypes.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/Driver/Util.h"
18-
#include "swift/Frontend/FileTypes.h"
1919
#include "llvm/ADT/ArrayRef.h"
2020
#include "llvm/ADT/Optional.h"
2121
#include "llvm/ADT/StringSwitch.h"

include/swift/Driver/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#define SWIFT_DRIVER_DRIVER_H
1919

2020
#include "swift/AST/IRGenOptions.h"
21+
#include "swift/Basic/FileTypes.h"
2122
#include "swift/Basic/LLVM.h"
2223
#include "swift/Basic/OptionSet.h"
2324
#include "swift/Basic/Sanitizers.h"
2425
#include "swift/Driver/Util.h"
25-
#include "swift/Frontend/FileTypes.h"
2626
#include "swift/Frontend/OutputFileMap.h"
2727
#include "llvm/ADT/DenseMap.h"
2828
#include "llvm/ADT/StringMap.h"

include/swift/Driver/Job.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
#ifndef SWIFT_DRIVER_JOB_H
1414
#define SWIFT_DRIVER_JOB_H
1515

16+
#include "swift/Basic/FileTypes.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/Driver/Action.h"
1819
#include "swift/Driver/Util.h"
19-
#include "swift/Frontend/FileTypes.h"
2020
#include "swift/Frontend/OutputFileMap.h"
2121
#include "llvm/ADT/ArrayRef.h"
2222
#include "llvm/ADT/DenseMap.h"

include/swift/Driver/PrettyStackTrace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef SWIFT_DRIVER_PRETTYSTACKTRACE_H
1414
#define SWIFT_DRIVER_PRETTYSTACKTRACE_H
1515

16-
#include "swift/Frontend/FileTypes.h"
16+
#include "swift/Basic/FileTypes.h"
1717
#include "llvm/Support/PrettyStackTrace.h"
1818

1919
namespace swift {

include/swift/Driver/ToolChain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
#ifndef SWIFT_DRIVER_TOOLCHAIN_H
1414
#define SWIFT_DRIVER_TOOLCHAIN_H
1515

16+
#include "swift/Basic/FileTypes.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/Driver/Action.h"
1819
#include "swift/Driver/Job.h"
19-
#include "swift/Frontend/FileTypes.h"
2020
#include "swift/Option/Options.h"
2121
#include "llvm/ADT/Triple.h"
2222
#include "llvm/Option/Option.h"

include/swift/Driver/Util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#ifndef SWIFT_DRIVER_UTIL_H
1414
#define SWIFT_DRIVER_UTIL_H
1515

16+
#include "swift/Basic/FileTypes.h"
1617
#include "swift/Basic/LLVM.h"
17-
#include "swift/Frontend/FileTypes.h"
1818
#include "llvm/ADT/SmallVector.h"
1919

2020
namespace llvm {

include/swift/Frontend/FrontendOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_FRONTEND_FRONTENDOPTIONS_H
1414
#define SWIFT_FRONTEND_FRONTENDOPTIONS_H
1515

16+
#include "swift/Basic/FileTypes.h"
1617
#include "swift/Frontend/FrontendInputsAndOutputs.h"
1718
#include "swift/Frontend/InputFile.h"
1819
#include "llvm/ADT/Hashing.h"
@@ -312,7 +313,7 @@ class FrontendOptions {
312313
static bool doesActionProduceOutput(ActionType);
313314
static bool doesActionProduceTextualOutput(ActionType);
314315
static bool needsProperModuleName(ActionType);
315-
static StringRef suffixForPrincipalOutputFileForAction(ActionType);
316+
static file_types::ID formatForPrincipalOutputFileForAction(ActionType);
316317
};
317318

318319
}

include/swift/Frontend/OutputFileMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#ifndef SWIFT_DRIVER_OUTPUTFILEMAP_H
1414
#define SWIFT_DRIVER_OUTPUTFILEMAP_H
1515

16+
#include "swift/Basic/FileTypes.h"
1617
#include "swift/Basic/LLVM.h"
17-
#include "swift/Frontend/FileTypes.h"
1818
#include "llvm/ADT/DenseMap.h"
1919
#include "llvm/ADT/StringMap.h"
2020
#include "llvm/ADT/StringSet.h"

include/swift/Strings.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,6 @@
1818

1919
namespace swift {
2020

21-
/// The extension for serialized modules.
22-
constexpr static const char SERIALIZED_MODULE_EXTENSION[] = "swiftmodule";
23-
/// The extension for serialized documentation comments.
24-
constexpr static const char SERIALIZED_MODULE_DOC_EXTENSION[] = "swiftdoc";
25-
/// The extension for PCH files.
26-
constexpr static const char PCH_EXTENSION[] = "pch";
27-
/// The extension for replacement map files.
28-
constexpr static const char REMAP_EXTENSION[] = "remap";
29-
/// The extension for SIL files.
30-
constexpr static const char SIL_EXTENSION[] = "sil";
31-
/// The extension for SIB files.
32-
constexpr static const char SIB_EXTENSION[] = "sib";
33-
/// The extension for LLVM IR files.
34-
constexpr static const char LLVM_BC_EXTENSION[] = "bc";
35-
constexpr static const char LLVM_IR_EXTENSION[] = "ll";
3621
/// The name of the standard library, which is a reserved module name.
3722
constexpr static const char STDLIB_NAME[] = "Swift";
3823
/// The name of the Onone support library, which is a reserved module name.

lib/Basic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ add_swift_library(swiftBasic STATIC
7272
Edit.cpp
7373
EditorPlaceholder.cpp
7474
FileSystem.cpp
75+
FileTypes.cpp
7576
JSONSerialization.cpp
7677
LangOptions.cpp
7778
LLVMContext.cpp

lib/Frontend/Types.cpp renamed to lib/Basic/FileTypes.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
//===--- Types.cpp - Driver input & temporary type information ------------===//
1+
//===--- FileTypes.cpp - Input & output formats used by the tools ---------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/Frontend/FileTypes.h"
13+
#include "swift/Basic/FileTypes.h"
1414

15+
#include "swift/Strings.h"
1516
#include "llvm/ADT/STLExtras.h"
1617
#include "llvm/ADT/StringSwitch.h"
1718
#include "llvm/Support/ErrorHandling.h"
1819

1920
using namespace swift;
2021
using namespace swift::file_types;
2122

23+
namespace {
2224
struct TypeInfo {
2325
const char *Name;
2426
const char *Flags;
25-
const char *TempSuffix;
27+
const char *Extension;
2628
};
29+
} // end anonymous namespace
2730

2831
static const TypeInfo TypeInfos[] = {
29-
#define TYPE(NAME, ID, TEMP_SUFFIX, FLAGS) \
30-
{ NAME, FLAGS, TEMP_SUFFIX },
31-
#include "swift/Frontend/Types.def"
32+
#define TYPE(NAME, ID, EXTENSION, FLAGS) \
33+
{ NAME, FLAGS, EXTENSION },
34+
#include "swift/Basic/FileTypes.def"
3235
};
3336

3437
static const TypeInfo &getInfo(unsigned Id) {
@@ -38,26 +41,26 @@ static const TypeInfo &getInfo(unsigned Id) {
3841

3942
StringRef file_types::getTypeName(ID Id) { return getInfo(Id).Name; }
4043

41-
StringRef file_types::getTypeTempSuffix(ID Id) {
42-
return getInfo(Id).TempSuffix;
44+
StringRef file_types::getExtension(ID Id) {
45+
return getInfo(Id).Extension;
4346
}
4447

4548
ID file_types::lookupTypeForExtension(StringRef Ext) {
4649
if (Ext.empty())
4750
return TY_INVALID;
4851
assert(Ext.front() == '.' && "not a file extension");
4952
return llvm::StringSwitch<file_types::ID>(Ext.drop_front())
50-
#define TYPE(NAME, ID, SUFFIX, FLAGS) \
51-
.Case(SUFFIX, TY_##ID)
52-
#include "swift/Frontend/Types.def"
53+
#define TYPE(NAME, ID, EXTENSION, FLAGS) \
54+
.Case(EXTENSION, TY_##ID)
55+
#include "swift/Basic/FileTypes.def"
5356
.Default(TY_INVALID);
5457
}
5558

5659
ID file_types::lookupTypeForName(StringRef Name) {
5760
return llvm::StringSwitch<file_types::ID>(Name)
58-
#define TYPE(NAME, ID, SUFFIX, FLAGS) \
61+
#define TYPE(NAME, ID, EXTENSION, FLAGS) \
5962
.Case(NAME, TY_##ID)
60-
#include "swift/Frontend/Types.def"
63+
#include "swift/Basic/FileTypes.def"
6164
.Default(TY_INVALID);
6265
}
6366

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "swift/Parse/Lexer.h"
3737
#include "swift/Parse/Parser.h"
3838
#include "swift/Config.h"
39-
#include "swift/Strings.h"
4039
#include "clang/AST/ASTContext.h"
4140
#include "clang/AST/Mangle.h"
4241
#include "clang/Basic/CharInfo.h"
@@ -419,7 +418,7 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
419418
auto languageVersion = ctx.LangOpts.EffectiveLanguageVersion;
420419

421420
if (llvm::sys::path::extension(importerOpts.BridgingHeader)
422-
.endswith(PCH_EXTENSION)) {
421+
.endswith(file_types::getExtension(file_types::TY_PCH))) {
423422
invocationArgStrs.insert(invocationArgStrs.end(), {
424423
"-include-pch", importerOpts.BridgingHeader
425424
});
@@ -788,7 +787,7 @@ Optional<std::string>
788787
ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
789788
StringRef SwiftPCHHash, bool &isExplicit) {
790789
if (llvm::sys::path::extension(ImporterOptions.BridgingHeader)
791-
.endswith(PCH_EXTENSION)) {
790+
.endswith(file_types::getExtension(file_types::TY_PCH))) {
792791
isExplicit = true;
793792
return ImporterOptions.BridgingHeader;
794793
}
@@ -879,8 +878,8 @@ ClangImporter::create(ASTContext &ctx,
879878
for (auto &argStr : invocationArgStrs)
880879
invocationArgs.push_back(argStr.c_str());
881880

882-
if (llvm::sys::path::extension(importerOpts.BridgingHeader).endswith(
883-
PCH_EXTENSION)) {
881+
if (llvm::sys::path::extension(importerOpts.BridgingHeader)
882+
.endswith(file_types::getExtension(file_types::TY_PCH))) {
884883
importer->Impl.setSinglePCHImport(importerOpts.BridgingHeader);
885884
importer->Impl.IsReadingBridgingPCH = true;
886885
if (tracker) {
@@ -1289,7 +1288,8 @@ bool ClangImporter::importBridgingHeader(StringRef header, ModuleDecl *adapter,
12891288
SourceLoc diagLoc,
12901289
bool trackParsedSymbols,
12911290
bool implicitImport) {
1292-
if (llvm::sys::path::extension(header).endswith(PCH_EXTENSION)) {
1291+
if (llvm::sys::path::extension(header)
1292+
.endswith(file_types::getExtension(file_types::TY_PCH))) {
12931293
Impl.ImportedHeaderOwners.push_back(adapter);
12941294
// We already imported this with -include-pch above, so we should have
12951295
// collected a bunch of PCH-encoded module imports that we just need to

lib/ClangImporter/ImporterImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include "swift/AST/Module.h"
2929
#include "swift/AST/Type.h"
3030
#include "swift/AST/ForeignErrorConvention.h"
31+
#include "swift/Basic/FileTypes.h"
3132
#include "swift/Basic/StringExtras.h"
32-
#include "swift/Strings.h"
3333
#include "clang/AST/ASTContext.h"
3434
#include "clang/AST/DeclVisitor.h"
3535
#include "clang/Basic/IdentifierTable.h"
@@ -1360,7 +1360,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
13601360
void setSinglePCHImport(Optional<std::string> PCHFilename) {
13611361
if (PCHFilename.hasValue()) {
13621362
assert(llvm::sys::path::extension(PCHFilename.getValue())
1363-
.endswith(PCH_EXTENSION) &&
1363+
.endswith(file_types::getExtension(file_types::TY_PCH)) &&
13641364
"Single PCH imported filename doesn't have .pch extension!");
13651365
}
13661366
SinglePCHImport = PCHFilename;

0 commit comments

Comments
 (0)