Skip to content

Commit d4b2e16

Browse files
committed
Model ObjCHeader Inputs
These inputs were previously modeled as Swift files, which would lead to bizarre situations where parts of the pipeline expecting Swift inputs actually wound up parsing Objective-C.
1 parent cedef16 commit d4b2e16

File tree

7 files changed

+21
-1
lines changed

7 files changed

+21
-1
lines changed

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class FrontendInputsAndOutputs {
153153
bool shouldTreatAsLLVM() const;
154154
bool shouldTreatAsSIL() const;
155155
bool shouldTreatAsModuleInterface() const;
156+
bool shouldTreatAsObjCHeader() const;
156157

157158
bool areAllNonPrimariesSIB() const;
158159

include/swift/Frontend/InputFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ enum class InputFileKind {
2626
SwiftLibrary,
2727
SwiftModuleInterface,
2828
SIL,
29-
LLVM
29+
LLVM,
30+
ObjCHeader,
3031
};
3132

3233
// Inputs may include buffers that override contents, and eventually should

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ bool ArgsToFrontendOptionsConverter::setUpInputKindAndImmediateArgs() {
423423
Opts.InputKind = InputFileKind::SIL;
424424
else if (Opts.InputsAndOutputs.shouldTreatAsLLVM())
425425
Opts.InputKind = InputFileKind::LLVM;
426+
else if (Opts.InputsAndOutputs.shouldTreatAsObjCHeader())
427+
Opts.InputKind = InputFileKind::ObjCHeader;
426428
else if (Opts.InputsAndOutputs.shouldTreatAsModuleInterface())
427429
Opts.InputKind = InputFileKind::SwiftModuleInterface;
428430
else if (Args.hasArg(OPT_parse_as_library))

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ SourceFileKind CompilerInvocation::getSourceFileKind() const {
238238
return SourceFileKind::SIL;
239239
case InputFileKind::None:
240240
case InputFileKind::LLVM:
241+
case InputFileKind::ObjCHeader:
241242
llvm_unreachable("Trying to convert from unsupported InputFileKind");
242243
}
243244

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ static bool shouldTreatSingleInputAsMain(InputFileKind inputKind) {
586586
return true;
587587
case InputFileKind::SwiftLibrary:
588588
case InputFileKind::LLVM:
589+
case InputFileKind::ObjCHeader:
589590
case InputFileKind::None:
590591
return false;
591592
}

lib/Frontend/FrontendInputsAndOutputs.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,19 @@ bool FrontendInputsAndOutputs::shouldTreatAsSIL() const {
199199
llvm_unreachable("Either all primaries or none must end with .sil");
200200
}
201201

202+
bool FrontendInputsAndOutputs::shouldTreatAsObjCHeader() const {
203+
if (hasSingleInput()) {
204+
StringRef InputExt = llvm::sys::path::extension(getFilenameOfFirstInput());
205+
switch (file_types::lookupTypeForExtension(InputExt)) {
206+
case file_types::TY_ObjCHeader:
207+
return true;
208+
default:
209+
return false;
210+
}
211+
}
212+
return false;
213+
}
214+
202215
bool FrontendInputsAndOutputs::areAllNonPrimariesSIB() const {
203216
for (const InputFile &input : AllInputs) {
204217
if (input.isPrimary())

lib/FrontendTool/TBD.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ bool swift::inputFileKindCanHaveTBDValidated(InputFileKind kind) {
6969
case InputFileKind::None:
7070
case InputFileKind::SIL:
7171
case InputFileKind::LLVM:
72+
case InputFileKind::ObjCHeader:
7273
return false;
7374
}
7475
llvm_unreachable("unhandled kind");

0 commit comments

Comments
 (0)