Skip to content

[Driver] Remove unused input type code (NFCI) #12263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class ToolChain {
const OutputInfo &OI) const;

/// Return the default language type to use for the given extension.
/// If the extension is empty or is otherwise not recognized, return
/// the invalid type \c TY_INVALID.
virtual types::ID lookupTypeForExtension(StringRef Ext) const;

/// Check whether a clang library with a given name exists.
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Driver/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace types {
StringRef getTypeTempSuffix(ID Id);

/// Lookup the type to use for the file extension \p Ext.
/// If the extension is empty or is otherwise not recognized, return
/// the invalid type \c TY_INVALID.
ID lookupTypeForExtension(StringRef Ext);

/// Lookup the type to use for the name \p Name.
Expand Down
37 changes: 11 additions & 26 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,39 +926,26 @@ static bool checkInputExistence(const Driver &D, const DerivedArgList &Args,
void Driver::buildInputs(const ToolChain &TC,
const DerivedArgList &Args,
InputFileList &Inputs) const {
types::ID InputType = types::TY_Nothing;
Arg *InputTypeArg = nullptr;

llvm::StringMap<StringRef> SourceFileNames;

for (Arg *A : Args) {
if (A->getOption().getKind() == Option::InputClass) {
StringRef Value = A->getValue();
types::ID Ty = types::TY_INVALID;

if (InputType == types::TY_Nothing) {
// If there was an explicit arg for this, claim it.
if (InputTypeArg)
InputTypeArg->claim();

// stdin must be handled specially.
if (Value.equals("-")) {
// By default, treat stdin as Swift input.
// FIXME: should we limit this inference to specific modes?
Ty = types::TY_Swift;
} else {
// Otherwise lookup by extension.
Ty = TC.lookupTypeForExtension(llvm::sys::path::extension(Value));
// stdin must be handled specially.
if (Value.equals("-")) {
// By default, treat stdin as Swift input.
Ty = types::TY_Swift;
} else {
// Otherwise lookup by extension.
Ty = TC.lookupTypeForExtension(llvm::sys::path::extension(Value));

if (Ty == types::TY_INVALID) {
// FIXME: should we adjust this inference in certain modes?
Ty = types::TY_Object;
}
if (Ty == types::TY_INVALID) {
// By default, treat inputs with no extension, or with an
// extension that isn't recognized, as object files.
Ty = types::TY_Object;
}
} else {
assert(InputTypeArg && "InputType set w/o InputTypeArg");
InputTypeArg->claim();
Ty = InputType;
}

if (checkInputExistence(*this, Args, Diags, Value))
Expand All @@ -973,8 +960,6 @@ void Driver::buildInputs(const ToolChain &TC,
}
}
}

// FIXME: add -x support (or equivalent)
}
}

Expand Down