xref: /freebsd/contrib/llvm-project/clang/lib/ARCMigrate/ARCMTActions.cpp (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
10b57cec5SDimitry Andric //===--- ARCMTActions.cpp - ARC Migrate Tool Frontend Actions ---*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "clang/ARCMigrate/ARCMTActions.h"
100b57cec5SDimitry Andric #include "clang/ARCMigrate/ARCMT.h"
110b57cec5SDimitry Andric #include "clang/Frontend/CompilerInstance.h"
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric using namespace clang;
140b57cec5SDimitry Andric using namespace arcmt;
150b57cec5SDimitry Andric 
BeginInvocation(CompilerInstance & CI)160b57cec5SDimitry Andric bool CheckAction::BeginInvocation(CompilerInstance &CI) {
170b57cec5SDimitry Andric   if (arcmt::checkForManualIssues(CI.getInvocation(), getCurrentInput(),
180b57cec5SDimitry Andric                                   CI.getPCHContainerOperations(),
190b57cec5SDimitry Andric                                   CI.getDiagnostics().getClient()))
200b57cec5SDimitry Andric     return false; // errors, stop the action.
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric   // We only want to see warnings reported from arcmt::checkForManualIssues.
230b57cec5SDimitry Andric   CI.getDiagnostics().setIgnoreAllWarnings(true);
240b57cec5SDimitry Andric   return true;
250b57cec5SDimitry Andric }
260b57cec5SDimitry Andric 
CheckAction(std::unique_ptr<FrontendAction> WrappedAction)270b57cec5SDimitry Andric CheckAction::CheckAction(std::unique_ptr<FrontendAction> WrappedAction)
280b57cec5SDimitry Andric   : WrapperFrontendAction(std::move(WrappedAction)) {}
290b57cec5SDimitry Andric 
BeginInvocation(CompilerInstance & CI)300b57cec5SDimitry Andric bool ModifyAction::BeginInvocation(CompilerInstance &CI) {
310b57cec5SDimitry Andric   return !arcmt::applyTransformations(CI.getInvocation(), getCurrentInput(),
320b57cec5SDimitry Andric                                       CI.getPCHContainerOperations(),
330b57cec5SDimitry Andric                                       CI.getDiagnostics().getClient());
340b57cec5SDimitry Andric }
350b57cec5SDimitry Andric 
ModifyAction(std::unique_ptr<FrontendAction> WrappedAction)360b57cec5SDimitry Andric ModifyAction::ModifyAction(std::unique_ptr<FrontendAction> WrappedAction)
370b57cec5SDimitry Andric   : WrapperFrontendAction(std::move(WrappedAction)) {}
380b57cec5SDimitry Andric 
BeginInvocation(CompilerInstance & CI)390b57cec5SDimitry Andric bool MigrateAction::BeginInvocation(CompilerInstance &CI) {
400b57cec5SDimitry Andric   if (arcmt::migrateWithTemporaryFiles(
410b57cec5SDimitry Andric           CI.getInvocation(), getCurrentInput(), CI.getPCHContainerOperations(),
42*bdd1243dSDimitry Andric           CI.getDiagnostics().getClient(), MigrateDir, EmitPremigrationARCErrors,
430b57cec5SDimitry Andric           PlistOut))
440b57cec5SDimitry Andric     return false; // errors, stop the action.
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric   // We only want to see diagnostics emitted by migrateWithTemporaryFiles.
470b57cec5SDimitry Andric   CI.getDiagnostics().setIgnoreAllWarnings(true);
480b57cec5SDimitry Andric   return true;
490b57cec5SDimitry Andric }
500b57cec5SDimitry Andric 
MigrateAction(std::unique_ptr<FrontendAction> WrappedAction,StringRef migrateDir,StringRef plistOut,bool emitPremigrationARCErrors)510b57cec5SDimitry Andric MigrateAction::MigrateAction(std::unique_ptr<FrontendAction> WrappedAction,
520b57cec5SDimitry Andric                              StringRef migrateDir,
530b57cec5SDimitry Andric                              StringRef plistOut,
540b57cec5SDimitry Andric                              bool emitPremigrationARCErrors)
550b57cec5SDimitry Andric   : WrapperFrontendAction(std::move(WrappedAction)), MigrateDir(migrateDir),
56*bdd1243dSDimitry Andric     PlistOut(plistOut), EmitPremigrationARCErrors(emitPremigrationARCErrors) {
570b57cec5SDimitry Andric   if (MigrateDir.empty())
580b57cec5SDimitry Andric     MigrateDir = "."; // user current directory if none is given.
590b57cec5SDimitry Andric }
60