From a0a6177d337ce39d6934e87376aa9467a361d22b Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Fri, 15 Aug 2014 18:58:12 +0000 Subject: [PATCH] [cleanup] Factor out initializing the DianosticOptions. NFC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215755 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/driver/driver.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index d9cc527fbd..1bb94a8ad8 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -320,6 +320,22 @@ static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient, DiagClient->setPrefix(ExeBasename); } +// This lets us create the DiagnosticsEngine with a properly-filled-out +// DiagnosticOptions instance. +static DiagnosticOptions * +CreateAndPopulateDiagOpts(SmallVectorImpl &argv) { + auto *DiagOpts = new DiagnosticOptions; + std::unique_ptr Opts(createDriverOptTable()); + unsigned MissingArgIndex, MissingArgCount; + std::unique_ptr Args(Opts->ParseArgs( + argv.begin() + 1, argv.end(), MissingArgIndex, MissingArgCount)); + // We ignore MissingArgCount and the return value of ParseDiagnosticArgs. + // Any errors that would be diagnosed here will also be diagnosed later, + // when the DiagnosticsEngine actually exists. + (void) ParseDiagnosticArgs(*DiagOpts, *Args); + return DiagOpts; +} + int main(int argc_, const char **argv_) { llvm::sys::PrintStackTraceOnErrorSignal(); llvm::PrettyStackTraceProgram X(argc_, argv_); @@ -370,19 +386,9 @@ int main(int argc_, const char **argv_) { std::string Path = GetExecutablePath(argv[0], CanonicalPrefixes); - IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions; - { - std::unique_ptr Opts(createDriverOptTable()); - unsigned MissingArgIndex, MissingArgCount; - std::unique_ptr Args(Opts->ParseArgs( - argv.begin() + 1, argv.end(), MissingArgIndex, MissingArgCount)); - // We ignore MissingArgCount and the return value of ParseDiagnosticArgs. - // Any errors that would be diagnosed here will also be diagnosed later, - // when the DiagnosticsEngine actually exists. - (void) ParseDiagnosticArgs(*DiagOpts, *Args); - } - // Now we can create the DiagnosticsEngine with a properly-filled-out - // DiagnosticOptions instance. + IntrusiveRefCntPtr DiagOpts = + CreateAndPopulateDiagOpts(argv); + TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); FixupDiagPrefixExeName(DiagClient, Path); -- 2.50.1