[flang][driver] Rename the accessors/mutators (NFC)

As per point 3 in [1]:

```
Accessor member functions are named with the non-public data member's
name, less the trailing underscore.  Mutator member functions are named
set_...
```

Originally we just followed the LLVM's style, which is incompatible with
Flang. This patch renames the accessors and mutators accordingly.

`getDiagnostics` and `GetDiagnostics` are replaced with one accessor:
`diagnostics`. `SetDiagnostics` was neither implemented nor used, so
it's deleted.

[1] https://github.com/llvm/llvm-project/blob/master/flang/docs/C++style.md#naming

Differential Revision: https://reviews.llvm.org/D90300
This commit is contained in:
Andrzej Warzynski 2020-10-28 10:47:48 +00:00
parent 0df197516b
commit 9ffb5b0469
12 changed files with 45 additions and 54 deletions

View File

@ -58,20 +58,20 @@ public:
/// @name Compiler Invocation
/// {
CompilerInvocation &GetInvocation() {
CompilerInvocation &invocation() {
assert(invocation_ && "Compiler instance has no invocation!");
return *invocation_;
};
/// Replace the current invocation.
void SetInvocation(std::shared_ptr<CompilerInvocation> value);
void set_invocation(std::shared_ptr<CompilerInvocation> value);
/// }
/// @name File manager
/// {
/// Return the current allSources.
Fortran::parser::AllSources &GetAllSources() const { return *allSources_; }
Fortran::parser::AllSources &allSources() const { return *allSources_; }
bool HasAllSources() const { return allSources_ != nullptr; }
@ -96,9 +96,9 @@ public:
return invocation_->GetDiagnosticOpts();
}
FrontendOptions &GetFrontendOpts() { return invocation_->GetFrontendOpts(); }
const FrontendOptions &GetFrontendOpts() const {
return invocation_->GetFrontendOpts();
FrontendOptions &frontendOpts() { return invocation_->frontendOpts(); }
const FrontendOptions &frontendOpts() const {
return invocation_->frontendOpts();
}
/// }
@ -108,26 +108,17 @@ public:
bool HasDiagnostics() const { return diagnostics_ != nullptr; }
/// Get the current diagnostics engine.
clang::DiagnosticsEngine &GetDiagnostics() const {
clang::DiagnosticsEngine &diagnostics() const {
assert(diagnostics_ && "Compiler instance has no diagnostics!");
return *diagnostics_;
}
/// Replace the current diagnostics engine.
void SetDiagnostics(clang::DiagnosticsEngine *value);
clang::DiagnosticConsumer &GetDiagnosticClient() const {
assert(diagnostics_ && diagnostics_->getClient() &&
"Compiler instance has no diagnostic client!");
return *diagnostics_->getClient();
}
/// Get the current diagnostics engine.
clang::DiagnosticsEngine &getDiagnostics() const {
assert(diagnostics_ && "Compiler instance has no diagnostics!");
return *diagnostics_;
}
/// {
/// @name Output Files
/// {
@ -192,7 +183,7 @@ public:
/// }
/// @name Output Stream Methods
/// {
void SetOutputStream(std::unique_ptr<llvm::raw_pwrite_stream> outStream) {
void set_outputStream(std::unique_ptr<llvm::raw_pwrite_stream> outStream) {
outputStream_ = std::move(outStream);
}

View File

@ -46,8 +46,8 @@ class CompilerInvocation : public CompilerInvocationBase {
public:
CompilerInvocation() = default;
FrontendOptions &GetFrontendOpts() { return frontendOpts_; }
const FrontendOptions &GetFrontendOpts() const { return frontendOpts_; }
FrontendOptions &frontendOpts() { return frontendOpts_; }
const FrontendOptions &frontendOpts() const { return frontendOpts_; }
/// Create a compiler invocation from a list of input options.
/// \returns true on success.

View File

@ -48,31 +48,31 @@ public:
/// @name Compiler Instance Access
/// @{
CompilerInstance &GetCompilerInstance() const {
CompilerInstance &instance() const {
assert(instance_ && "Compiler instance not registered!");
return *instance_;
}
void SetCompilerInstance(CompilerInstance *value) { instance_ = value; }
void set_instance(CompilerInstance *value) { instance_ = value; }
/// @}
/// @name Current File Information
/// @{
const FrontendInputFile &GetCurrentInput() const { return currentInput_; }
const FrontendInputFile &currentInput() const { return currentInput_; }
llvm::StringRef GetCurrentFile() const {
assert(!currentInput_.IsEmpty() && "No current file!");
return currentInput_.GetFile();
return currentInput_.file();
}
llvm::StringRef GetCurrentFileOrBufferName() const {
assert(!currentInput_.IsEmpty() && "No current file!");
return currentInput_.IsFile()
? currentInput_.GetFile()
: currentInput_.GetBuffer()->getBufferIdentifier();
? currentInput_.file()
: currentInput_.buffer()->getBufferIdentifier();
}
void SetCurrentInput(const FrontendInputFile &currentInput);
void set_currentInput(const FrontendInputFile &currentInput);
/// @}
/// @name Public Action Interface

View File

@ -91,18 +91,18 @@ public:
FrontendInputFile(const llvm::MemoryBuffer *buffer, InputKind kind)
: buffer_(buffer), kind_(kind) {}
InputKind GetKind() const { return kind_; }
InputKind kind() const { return kind_; }
bool IsEmpty() const { return file_.empty() && buffer_ == nullptr; }
bool IsFile() const { return !IsBuffer(); }
bool IsBuffer() const { return buffer_ != nullptr; }
llvm::StringRef GetFile() const {
llvm::StringRef file() const {
assert(IsFile());
return file_;
}
const llvm::MemoryBuffer *GetBuffer() const {
const llvm::MemoryBuffer *buffer() const {
assert(IsBuffer() && "Requested buffer_, but it is empty!");
return buffer_;
}

View File

@ -26,7 +26,7 @@ CompilerInstance::~CompilerInstance() {
assert(outputFiles_.empty() && "Still output files in flight?");
}
void CompilerInstance::SetInvocation(
void CompilerInstance::set_invocation(
std::shared_ptr<CompilerInvocation> value) {
invocation_ = std::move(value);
}
@ -69,7 +69,7 @@ CompilerInstance::CreateDefaultOutputFile(
// Get the path of the output file
std::string outputFilePath =
GetOutputFilePath(GetFrontendOpts().outputFile_, baseName, extension);
GetOutputFilePath(frontendOpts().outputFile_, baseName, extension);
// Create the output file
std::unique_ptr<llvm::raw_pwrite_stream> os =
@ -120,7 +120,7 @@ void CompilerInstance::ClearOutputFiles(bool eraseFiles) {
bool CompilerInstance::ExecuteAction(FrontendAction &act) {
// Connect Input to a CompileInstance
for (const FrontendInputFile &fif : GetFrontendOpts().inputs_) {
for (const FrontendInputFile &fif : frontendOpts().inputs_) {
if (act.BeginSourceFile(*this, fif)) {
if (llvm::Error err = act.Execute()) {
consumeError(std::move(err));

View File

@ -176,7 +176,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
}
// Parse the frontend args
ParseFrontendArgs(res.GetFrontendOpts(), args, diags);
ParseFrontendArgs(res.frontendOpts(), args, diags);
return success;
}

View File

@ -13,7 +13,7 @@
using namespace Fortran::frontend;
void FrontendAction::SetCurrentInput(const FrontendInputFile &currentInput) {
void FrontendAction::set_currentInput(const FrontendInputFile &currentInput) {
this->currentInput_ = currentInput;
}
@ -21,8 +21,8 @@ void FrontendAction::SetCurrentInput(const FrontendInputFile &currentInput) {
// Deallocate compiler instance, input and output descriptors
static void BeginSourceFileCleanUp(FrontendAction &fa, CompilerInstance &ci) {
ci.ClearOutputFiles(/*EraseFiles=*/true);
fa.SetCurrentInput(FrontendInputFile());
fa.SetCompilerInstance(nullptr);
fa.set_currentInput(FrontendInputFile());
fa.set_instance(nullptr);
}
bool FrontendAction::BeginSourceFile(
@ -31,8 +31,8 @@ bool FrontendAction::BeginSourceFile(
FrontendInputFile input(realInput);
assert(!instance_ && "Already processing a source file!");
assert(!realInput.IsEmpty() && "Unexpected empty filename!");
SetCurrentInput(realInput);
SetCompilerInstance(&ci);
set_currentInput(realInput);
set_instance(&ci);
if (!ci.HasAllSources()) {
BeginSourceFileCleanUp(*this, ci);
return false;
@ -41,7 +41,7 @@ bool FrontendAction::BeginSourceFile(
}
bool FrontendAction::ShouldEraseOutputFiles() {
return GetCompilerInstance().getDiagnostics().hasErrorOccurred();
return instance().diagnostics().hasErrorOccurred();
}
llvm::Error FrontendAction::Execute() {
@ -50,12 +50,12 @@ llvm::Error FrontendAction::Execute() {
}
void FrontendAction::EndSourceFile() {
CompilerInstance &ci = GetCompilerInstance();
CompilerInstance &ci = instance();
// Cleanup the output streams, and erase the output files if instructed by the
// FrontendAction.
ci.ClearOutputFiles(/*EraseFiles=*/ShouldEraseOutputFiles());
SetCompilerInstance(nullptr);
SetCurrentInput(FrontendInputFile());
set_instance(nullptr);
set_currentInput(FrontendInputFile());
}

View File

@ -23,8 +23,8 @@ void InputOutputTestAction::ExecuteAction() {
bool binaryMode = true;
// Set/store input file info into CompilerInstance.
CompilerInstance &ci = GetCompilerInstance();
Fortran::parser::AllSources &allSources{ci.GetAllSources()};
CompilerInstance &ci = instance();
Fortran::parser::AllSources &allSources{ci.allSources()};
const Fortran::parser::SourceFile *sf;
sf = allSources.Open(path, error_stream);
llvm::ArrayRef<char> fileContent = sf->content();

View File

@ -24,7 +24,7 @@ namespace Fortran::frontend {
static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
CompilerInstance &ci) {
ActionKind ak = ci.GetFrontendOpts().programAction_;
ActionKind ak = ci.frontendOpts().programAction_;
switch (ak) {
case InputOutputTest:
return std::make_unique<InputOutputTestAction>();
@ -52,7 +52,7 @@ std::unique_ptr<FrontendAction> CreateFrontendAction(CompilerInstance &ci) {
}
bool ExecuteCompilerInvocation(CompilerInstance *flang) {
// Honor -help.
if (flang->GetFrontendOpts().showHelp_) {
if (flang->frontendOpts().showHelp_) {
clang::driver::getDriverOptTable().PrintHelp(llvm::outs(),
"flang-new -fc1 [options] file...", "LLVM 'Flang' Compiler",
/*Include=*/clang::driver::options::FC1Option,
@ -62,7 +62,7 @@ bool ExecuteCompilerInvocation(CompilerInstance *flang) {
}
// Honor -version.
if (flang->GetFrontendOpts().showVersion_) {
if (flang->frontendOpts().showVersion_) {
llvm::cl::PrintVersionMessage();
return true;
}

View File

@ -46,9 +46,9 @@ int fc1_main(llvm::ArrayRef<const char *> argv, const char *argv0) {
new clang::DiagnosticOptions();
clang::DiagnosticsEngine diags(diagID, &*diagOpts, diagsBuffer);
bool success =
CompilerInvocation::CreateFromArgs(flang->GetInvocation(), argv, diags);
CompilerInvocation::CreateFromArgs(flang->invocation(), argv, diags);
diagsBuffer->FlushDiagnostics(flang->getDiagnostics());
diagsBuffer->FlushDiagnostics(flang->diagnostics());
if (!success)
return 1;

View File

@ -47,7 +47,7 @@ TEST(CompilerInstance, SanityCheckForFileManager) {
llvm::raw_string_ostream error_stream{buf};
CompilerInstance compInst;
const Fortran::parser::SourceFile *sf =
compInst.GetAllSources().Open(testFilePath, error_stream);
compInst.allSources().Open(testFilePath, error_stream);
// 3. Verify the content of the input file
// This is just a sanity check to make sure that CompilerInstance is capable

View File

@ -45,9 +45,9 @@ TEST(FrontendAction, TestInputOutputTestAction) {
CompilerInstance compInst;
compInst.CreateDiagnostics();
auto invocation = std::make_shared<CompilerInvocation>();
invocation->GetFrontendOpts().programAction_ = InputOutputTest;
compInst.SetInvocation(std::move(invocation));
compInst.GetFrontendOpts().inputs_.push_back(
invocation->frontendOpts().programAction_ = InputOutputTest;
compInst.set_invocation(std::move(invocation));
compInst.frontendOpts().inputs_.push_back(
FrontendInputFile(/*File=*/testFilePath, Language::Fortran));
// 3. Set-up the output stream. Using output buffer wrapped as an output
@ -55,7 +55,7 @@ TEST(FrontendAction, TestInputOutputTestAction) {
llvm::SmallVector<char, 256> outputFileBuffer;
std::unique_ptr<llvm::raw_pwrite_stream> outputFileStream(
new llvm::raw_svector_ostream(outputFileBuffer));
compInst.SetOutputStream(std::move(outputFileStream));
compInst.set_outputStream(std::move(outputFileStream));
// 4. Run the earlier defined FrontendAction
bool success = ExecuteCompilerInvocation(&compInst);