diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index 164a38d4232393abf3cdd28b6e0e557214b0757b..94bdc8d25a4199d79fa0ed36af45ac8f220f0b02 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<const char *> CommandLine(DoubleDash + 1, Argv + Argc); Argc = DoubleDash - Argv; std::vector<std::string> 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 5fe098045dc3dc5e627e0afbb1a8a451fc442781..bba71f23674a4cf00673309785e9190076c19a6e 100644 --- a/lib/Tooling/JSONCompilationDatabase.cpp +++ b/lib/Tooling/JSONCompilationDatabase.cpp @@ -125,7 +125,7 @@ class JSONCompilationDatabasePlugin : public CompilationDatabasePlugin { std::unique_ptr<CompilationDatabase> 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<llvm::MemoryBuffer> 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<JSONCompilationDatabase> 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<JSONCompilationDatabase> 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<llvm::yaml::SequenceNode>(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<llvm::yaml::MappingNode>(&*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<llvm::yaml::ScalarNode>(Value); - if (ValueString == NULL) { + if (!ValueString) { ErrorMessage = "Expected string as value."; return false; } llvm::yaml::ScalarNode *KeyString = dyn_cast<llvm::yaml::ScalarNode>((*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 df9600e78c76c6f4b954e0a3c56aa4f4df48330e..4b4056b8c0a2aa6d27bf75d46dec08ac17cb3f81 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<FileID, unsigned> 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 3fe0c8387014e96665ba4a3f3f5c2ec73c135085..35e3eb4af2212ca52b287adf6e9bd10b5620d46e 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<clang::driver::Command>(*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<std::string> CommandLine, Action(Action), OwnsAction(false), Files(Files), - DiagConsumer(NULL) {} + DiagConsumer(nullptr) {} ToolInvocation::ToolInvocation(std::vector<std::string> CommandLine, FrontendAction *FAction, FileManager *Files) @@ -179,7 +179,7 @@ ToolInvocation::ToolInvocation(std::vector<std::string> 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<clang::CompilerInvocation> Invocation( @@ -271,7 +271,7 @@ bool FrontendActionFactory::runInvocation(CompilerInvocation *Invocation, ClangTool::ClangTool(const CompilationDatabase &Compilations, ArrayRef<std::string> 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<std::unique_ptr<ASTUnit>> 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]);