From: Craig Topper Date: Tue, 20 May 2014 04:51:16 +0000 (+0000) Subject: [C++11] Use 'nullptr'. Tooling edition. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=070be84e4ab23f9151d602fbe820e0f13c9ff21b;p=clang [C++11] Use 'nullptr'. Tooling edition. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209192 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index 164a38d423..94bdc8d25a 100644 --- a/lib/Tooling/CompilationDatabase.cpp +++ b/lib/Tooling/CompilationDatabase.cpp @@ -52,7 +52,7 @@ CompilationDatabase::loadFromDirectory(StringRef BuildDirectory, ErrorStream << It->getName() << ": " << DatabaseErrorMessage << "\n"; } ErrorMessage = ErrorStream.str(); - return NULL; + return nullptr; } static CompilationDatabase * @@ -76,7 +76,7 @@ findCompilationDatabaseFromDirectory(StringRef Directory, Directory = llvm::sys::path::parent_path(Directory); } ErrorMessage = ErrorStream.str(); - return NULL; + return nullptr; } CompilationDatabase * @@ -151,7 +151,7 @@ private: // options. class UnusedInputDiagConsumer : public DiagnosticConsumer { public: - UnusedInputDiagConsumer() : Other(0) {} + UnusedInputDiagConsumer() : Other(nullptr) {} // Useful for debugging, chain diagnostics to another consumer after // recording for our own purposes. @@ -290,13 +290,13 @@ FixedCompilationDatabase::loadFromCommandLine(int &Argc, Twine Directory) { const char **DoubleDash = std::find(Argv, Argv + Argc, StringRef("--")); if (DoubleDash == Argv + Argc) - return NULL; + return nullptr; std::vector CommandLine(DoubleDash + 1, Argv + Argc); Argc = DoubleDash - Argv; std::vector StrippedArgs; if (!stripPositionalArgs(CommandLine, StrippedArgs)) - return 0; + return nullptr; return new FixedCompilationDatabase(Directory, StrippedArgs); } diff --git a/lib/Tooling/JSONCompilationDatabase.cpp b/lib/Tooling/JSONCompilationDatabase.cpp index 5fe098045d..bba71f2367 100644 --- a/lib/Tooling/JSONCompilationDatabase.cpp +++ b/lib/Tooling/JSONCompilationDatabase.cpp @@ -125,7 +125,7 @@ class JSONCompilationDatabasePlugin : public CompilationDatabasePlugin { std::unique_ptr Database( JSONCompilationDatabase::loadFromFile(JSONDatabasePath, ErrorMessage)); if (!Database) - return NULL; + return nullptr; return Database.release(); } }; @@ -147,14 +147,14 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath, std::unique_ptr DatabaseBuffer; llvm::error_code Result = llvm::MemoryBuffer::getFile(FilePath, DatabaseBuffer); - if (Result != 0) { + if (Result != nullptr) { ErrorMessage = "Error while opening JSON database: " + Result.message(); - return NULL; + return nullptr; } std::unique_ptr Database( new JSONCompilationDatabase(DatabaseBuffer.release())); if (!Database->parse(ErrorMessage)) - return NULL; + return nullptr; return Database.release(); } @@ -166,7 +166,7 @@ JSONCompilationDatabase::loadFromBuffer(StringRef DatabaseString, std::unique_ptr Database( new JSONCompilationDatabase(DatabaseBuffer.release())); if (!Database->parse(ErrorMessage)) - return NULL; + return nullptr; return Database.release(); } @@ -235,12 +235,12 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { return false; } llvm::yaml::Node *Root = I->getRoot(); - if (Root == NULL) { + if (!Root) { ErrorMessage = "Error while parsing YAML."; return false; } llvm::yaml::SequenceNode *Array = dyn_cast(Root); - if (Array == NULL) { + if (!Array) { ErrorMessage = "Expected array."; return false; } @@ -248,30 +248,30 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { AE = Array->end(); AI != AE; ++AI) { llvm::yaml::MappingNode *Object = dyn_cast(&*AI); - if (Object == NULL) { + if (!Object) { ErrorMessage = "Expected object."; return false; } - llvm::yaml::ScalarNode *Directory = NULL; - llvm::yaml::ScalarNode *Command = NULL; - llvm::yaml::ScalarNode *File = NULL; + llvm::yaml::ScalarNode *Directory = nullptr; + llvm::yaml::ScalarNode *Command = nullptr; + llvm::yaml::ScalarNode *File = nullptr; for (llvm::yaml::MappingNode::iterator KVI = Object->begin(), KVE = Object->end(); KVI != KVE; ++KVI) { llvm::yaml::Node *Value = (*KVI).getValue(); - if (Value == NULL) { + if (!Value) { ErrorMessage = "Expected value."; return false; } llvm::yaml::ScalarNode *ValueString = dyn_cast(Value); - if (ValueString == NULL) { + if (!ValueString) { ErrorMessage = "Expected string as value."; return false; } llvm::yaml::ScalarNode *KeyString = dyn_cast((*KVI).getKey()); - if (KeyString == NULL) { + if (!KeyString) { ErrorMessage = "Expected strings as key."; return false; } diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp index df9600e78c..4b4056b8c0 100644 --- a/lib/Tooling/Refactoring.cpp +++ b/lib/Tooling/Refactoring.cpp @@ -53,7 +53,7 @@ bool Replacement::isApplicable() const { bool Replacement::apply(Rewriter &Rewrite) const { SourceManager &SM = Rewrite.getSourceMgr(); const FileEntry *Entry = SM.getFileManager().getFile(FilePath); - if (Entry == NULL) + if (!Entry) return false; FileID ID; // FIXME: Use SM.translateFile directly. @@ -106,7 +106,7 @@ void Replacement::setFromSourceLocation(const SourceManager &Sources, const std::pair DecomposedLocation = Sources.getDecomposedLoc(Start); const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first); - if (Entry != NULL) { + if (Entry) { // Make FilePath absolute so replacements can be applied correctly when // relative paths for files are used. llvm::SmallString<256> FilePath(Entry->getName()); diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index 3fe0c83870..35e3eb4af2 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -75,7 +75,7 @@ static const llvm::opt::ArgStringList *getCC1Arguments( Jobs.Print(error_stream, "; ", true); Diagnostics->Report(clang::diag::err_fe_expected_compiler_job) << error_stream.str(); - return NULL; + return nullptr; } // The one job we find should be to invoke clang again. @@ -83,7 +83,7 @@ static const llvm::opt::ArgStringList *getCC1Arguments( cast(*Jobs.begin()); if (StringRef(Cmd->getCreator().getName()) != "clang") { Diagnostics->Report(clang::diag::err_fe_expected_clang_command); - return NULL; + return nullptr; } return &Cmd->getArguments(); @@ -171,7 +171,7 @@ ToolInvocation::ToolInvocation(std::vector CommandLine, Action(Action), OwnsAction(false), Files(Files), - DiagConsumer(NULL) {} + DiagConsumer(nullptr) {} ToolInvocation::ToolInvocation(std::vector CommandLine, FrontendAction *FAction, FileManager *Files) @@ -179,7 +179,7 @@ ToolInvocation::ToolInvocation(std::vector CommandLine, Action(new SingleFrontendActionFactory(FAction)), OwnsAction(true), Files(Files), - DiagConsumer(NULL) {} + DiagConsumer(nullptr) {} ToolInvocation::~ToolInvocation() { if (OwnsAction) @@ -216,7 +216,7 @@ bool ToolInvocation::run() { Driver->BuildCompilation(llvm::makeArrayRef(Argv))); const llvm::opt::ArgStringList *const CC1Args = getCC1Arguments( &Diagnostics, Compilation.get()); - if (CC1Args == NULL) { + if (!CC1Args) { return false; } std::unique_ptr Invocation( @@ -271,7 +271,7 @@ bool FrontendActionFactory::runInvocation(CompilerInvocation *Invocation, ClangTool::ClangTool(const CompilationDatabase &Compilations, ArrayRef SourcePaths) - : Files(new FileManager(FileSystemOptions())), DiagConsumer(NULL) { + : Files(new FileManager(FileSystemOptions())), DiagConsumer(nullptr) { ArgsAdjusters.push_back(new ClangStripOutputAdjuster()); ArgsAdjusters.push_back(new ClangSyntaxOnlyAdjuster()); for (const auto &SourcePath : SourcePaths) { @@ -410,13 +410,14 @@ buildASTFromCodeWithArgs(const Twine &Code, std::vector> ASTs; ASTBuilderAction Action(ASTs); - ToolInvocation Invocation(getSyntaxOnlyToolArgs(Args, FileNameRef), &Action, 0); + ToolInvocation Invocation(getSyntaxOnlyToolArgs(Args, FileNameRef), &Action, + nullptr); SmallString<1024> CodeStorage; Invocation.mapVirtualFile(FileNameRef, Code.toNullTerminatedStringRef(CodeStorage)); if (!Invocation.run()) - return 0; + return nullptr; assert(ASTs.size() == 1); return std::move(ASTs[0]);