Alias<fsyntax_only>;
+// Non-aliases:
+
+def _SLASH_Tc : CLJoinedOrSeparate<"Tc">, HelpText<"Specify a C source file">,
+ MetaVarName<"<filename>">;
+def _SLASH_TC : CLFlag<"TC">, HelpText<"Treat all source files as C">;
+def _SLASH_Tp : CLJoinedOrSeparate<"Tp">, HelpText<"Specify a C++ source file">,
+ MetaVarName<"<filename>">;
+def _SLASH_TP : CLFlag<"TP">, HelpText<"Treat all source files as C++">;
+
+
// Ignored:
def _SLASH_analyze_ : CLIgnoredFlag<"analyze-">;
def _SLASH_Oi : CLFlag<"Oi">;
def _SLASH_RTC : CLJoined<"RTC">;
def _SLASH_showIncludes : CLJoined<"showIncludes">;
-def _SLASH_Tc : CLJoined<"Tc">;
-def _SLASH_TC : CLFlag<"TC">;
-def _SLASH_Tp : CLJoined<"Tp">;
-def _SLASH_TP : CLFlag<"TP">;
def _SLASH_w : CLJoined<"w">;
def _SLASH_Zc : CLJoined<"Zc:">;
def _SLASH_ZI : CLFlag<"ZI">;
}
}
+/// \brief Check that the file referenced by Value exists. If it doesn't,
+/// issue a diagnostic and return false.
+static bool DiagnoseInputExistance(const Driver &D, const DerivedArgList &Args,
+ StringRef Value) {
+ if (!D.getCheckInputsExist())
+ return true;
+
+ // stdin always exists.
+ if (Value == "-")
+ return true;
+
+ SmallString<64> Path(Value);
+ if (Arg *WorkDir = Args.getLastArg(options::OPT_working_directory)) {
+ if (!llvm::sys::path::is_absolute(Path.str())) {
+ SmallString<64> Directory(WorkDir->getValue());
+ llvm::sys::path::append(Directory, Value);
+ Path.assign(Directory);
+ }
+ }
+
+ if (llvm::sys::fs::exists(Twine(Path)))
+ return true;
+
+ D.Diag(clang::diag::err_drv_no_such_file) << Path.str();
+ return false;
+}
+
+static Arg* MakeInputArg(const DerivedArgList &Args, OptTable *Opts,
+ StringRef Value) {
+ unsigned Index = Args.getBaseArgs().MakeIndex(Value);
+ Arg *A = Opts->ParseOneArg(Args, Index);
+ A->claim();
+ return A;
+}
+
// Construct a the list of inputs and their types.
void Driver::BuildInputs(const ToolChain &TC, const DerivedArgList &Args,
InputList &Inputs) const {
types::ID InputType = types::TY_Nothing;
Arg *InputTypeArg = 0;
+ // The /TC and /TP options set the input type to C or C++ globally.
+ if (Arg *TCTP = Args.getLastArg(options::OPT__SLASH_TC,
+ options::OPT__SLASH_TP)) {
+ InputTypeArg = TCTP;
+ unsigned opposite;
+
+ if (TCTP->getOption().matches(options::OPT__SLASH_TC)) {
+ InputType = types::TY_C;
+ opposite = options::OPT__SLASH_TP;
+ } else {
+ InputType = types::TY_CXX;
+ opposite = options::OPT__SLASH_TC;
+ }
+
+ if (Arg *OppositeArg = Args.getLastArg(opposite)) {
+ Diag(clang::diag::warn_drv_overriding_t_option)
+ << OppositeArg->getSpelling() << InputTypeArg->getSpelling();
+ }
+
+ // No driver mode exposes -x and /TC or /TP; we don't support mixing them.
+ assert(!Args.hasArg(options::OPT_x) && "-x and /TC or /TP is not allowed");
+ }
+
for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
it != ie; ++it) {
Arg *A = *it;
Ty = InputType;
}
- // Check that the file exists, if enabled.
- if (CheckInputsExist && memcmp(Value, "-", 2) != 0) {
- SmallString<64> Path(Value);
- if (Arg *WorkDir = Args.getLastArg(options::OPT_working_directory)) {
- if (!llvm::sys::path::is_absolute(Path.str())) {
- SmallString<64> Directory(WorkDir->getValue());
- llvm::sys::path::append(Directory, Value);
- Path.assign(Directory);
- }
- }
-
- if (!llvm::sys::fs::exists(Twine(Path)))
- Diag(clang::diag::err_drv_no_such_file) << Path.str();
- else
- Inputs.push_back(std::make_pair(Ty, A));
- } else
+ if (DiagnoseInputExistance(*this, Args, Value))
Inputs.push_back(std::make_pair(Ty, A));
+ } else if (A->getOption().matches(options::OPT__SLASH_Tc)) {
+ StringRef Value = A->getValue();
+ if (DiagnoseInputExistance(*this, Args, Value)) {
+ Arg *InputArg = MakeInputArg(Args, Opts, A->getValue());
+ Inputs.push_back(std::make_pair(types::TY_C, InputArg));
+ }
+ A->claim();
+ } else if (A->getOption().matches(options::OPT__SLASH_Tp)) {
+ StringRef Value = A->getValue();
+ if (DiagnoseInputExistance(*this, Args, Value)) {
+ Arg *InputArg = MakeInputArg(Args, Opts, A->getValue());
+ Inputs.push_back(std::make_pair(types::TY_CXX, InputArg));
+ }
+ A->claim();
} else if (A->getOption().hasFlag(options::LinkerInput)) {
// Just treat as object type, we could make a special type for this if
// necessary.
if (CCCIsCPP() && Inputs.empty()) {
// If called as standalone preprocessor, stdin is processed
// if no other input is present.
- unsigned Index = Args.getBaseArgs().MakeIndex("-");
- Arg *A = Opts->ParseOneArg(Args, Index);
- A->claim();
+ Arg *A = MakeInputArg(Args, Opts, "-");
Inputs.push_back(std::make_pair(types::TY_C, A));
}
}