[cfe-commits] r90092 - in /cfe/trunk: include/clang/Frontend/CompilerInvocation.h lib/Driver/CC1Options.cpp tools/driver/cc1_main.cpp
Daniel Dunbar
daniel at zuster.org
Sun Nov 29 12:58:50 PST 2009
Author: ddunbar
Date: Sun Nov 29 14:58:50 2009
New Revision: 90092
URL: http://llvm.org/viewvc/llvm-project?rev=90092&view=rev
Log:
Change CompilerInvocation::CreateFromArgs to report errors using a proper diagnostic engine.
- Clients that care about having the diagnostics output honor the user-controllable diagnostic options can buffer the diagnostics and issue them later.
Modified:
cfe/trunk/include/clang/Frontend/CompilerInvocation.h
cfe/trunk/lib/Driver/CC1Options.cpp
cfe/trunk/tools/driver/cc1_main.cpp
Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInvocation.h?rev=90092&r1=90091&r2=90092&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInvocation.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h Sun Nov 29 14:58:50 2009
@@ -31,6 +31,8 @@
namespace clang {
+class Diagnostic;
+
/// CompilerInvocation - Helper class for holding the data necessary to invoke
/// the compiler.
///
@@ -77,8 +79,6 @@
/// CreateFromArgs - Create a compiler invocation from a list of input
/// options.
///
- /// FIXME: Documenting error behavior.
- ///
/// \param Res [out] - The resulting invocation.
/// \param ArgBegin - The first element in the argument vector.
/// \param ArgEnd - The last element in the argument vector.
@@ -86,9 +86,11 @@
/// compiler path.
/// \param MainAddr - The address of main (or some other function in the main
/// executable), for finding the builtin compiler path.
+ /// \param Diags - The diagnostic engine to use for errors.
static void CreateFromArgs(CompilerInvocation &Res, const char **ArgBegin,
const char **ArgEnd, const char *Argv0,
- void *MainAddr);
+ void *MainAddr,
+ Diagnostic &Diags);
/// toArgs - Convert the CompilerInvocation to a list of strings suitable for
/// passing to CreateFromArgs.
Modified: cfe/trunk/lib/Driver/CC1Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/CC1Options.cpp?rev=90092&r1=90091&r2=90092&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/CC1Options.cpp (original)
+++ cfe/trunk/lib/Driver/CC1Options.cpp Sun Nov 29 14:58:50 2009
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Driver/CC1Options.h"
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/Version.h"
#include "clang/Driver/ArgList.h"
#include "clang/Driver/Arg.h"
@@ -662,7 +663,8 @@
const char **ArgBegin,
const char **ArgEnd,
const char *Argv0,
- void *MainAddr) {
+ void *MainAddr,
+ Diagnostic &Diags) {
// Parse the arguments.
llvm::OwningPtr<OptTable> Opts(createCC1OptTable());
unsigned MissingArgIndex, MissingArgCount;
@@ -678,6 +680,14 @@
<< " value )\n";
}
+ // Issue errors on unknown arguments.
+ for (arg_iterator it = InputArgs->filtered_begin(OPT_UNKNOWN),
+ ie = InputArgs->filtered_end(); it != ie; ++it) {
+ unsigned ID = Diags.getCustomDiagID(Diagnostic::Error,
+ "unknown argument: '%0'");
+ Diags.Report(ID) << it->getAsString(*InputArgs);
+ }
+
ParseAnalyzerArgs(Res.getAnalyzerOpts(), *InputArgs);
ParseCodeGenArgs(Res.getCodeGenOpts(), *InputArgs);
ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *InputArgs);
Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=90092&r1=90091&r2=90092&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Sun Nov 29 14:58:50 2009
@@ -53,7 +53,7 @@
llvm::errs() << "cc1 creating invocation.\n";
CompilerInvocation Invocation;
CompilerInvocation::CreateFromArgs(Invocation, ArgBegin, ArgEnd,
- Argv0, MainAddr);
+ Argv0, MainAddr, Diags);
// Convert the invocation back to argument strings.
std::vector<std::string> InvocationArgs;
@@ -72,7 +72,8 @@
// same thing.
CompilerInvocation Invocation2;
CompilerInvocation::CreateFromArgs(Invocation2, Invocation2Args.begin(),
- Invocation2Args.end(), Argv0, MainAddr);
+ Invocation2Args.end(), Argv0, MainAddr,
+ Diags);
// FIXME: Implement CompilerInvocation comparison.
if (true) {
More information about the cfe-commits
mailing list