[flang-commits] [flang] 9ffb5b0 - [flang][driver] Rename the accessors/mutators (NFC)

Andrzej Warzynski via flang-commits flang-commits at lists.llvm.org
Mon Nov 2 03:28:56 PST 2020


Author: Andrzej Warzynski
Date: 2020-11-02T10:55:13Z
New Revision: 9ffb5b0469ae593f8b7e1d7d9ef6ea46cd366e6e

URL: https://github.com/llvm/llvm-project/commit/9ffb5b0469ae593f8b7e1d7d9ef6ea46cd366e6e
DIFF: https://github.com/llvm/llvm-project/commit/9ffb5b0469ae593f8b7e1d7d9ef6ea46cd366e6e.diff

LOG: [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

Added: 
    

Modified: 
    flang/include/flang/Frontend/CompilerInstance.h
    flang/include/flang/Frontend/CompilerInvocation.h
    flang/include/flang/Frontend/FrontendAction.h
    flang/include/flang/Frontend/FrontendOptions.h
    flang/lib/Frontend/CompilerInstance.cpp
    flang/lib/Frontend/CompilerInvocation.cpp
    flang/lib/Frontend/FrontendAction.cpp
    flang/lib/Frontend/FrontendActions.cpp
    flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
    flang/tools/flang-driver/fc1_main.cpp
    flang/unittests/Frontend/CompilerInstanceTest.cpp
    flang/unittests/Frontend/InputOutputTest.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Frontend/CompilerInstance.h b/flang/include/flang/Frontend/CompilerInstance.h
index c259be159366..b3f77896b8cb 100644
--- a/flang/include/flang/Frontend/CompilerInstance.h
+++ b/flang/include/flang/Frontend/CompilerInstance.h
@@ -58,20 +58,20 @@ class CompilerInstance {
   /// @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 @@ class CompilerInstance {
     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 @@ class CompilerInstance {
   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 @@ class CompilerInstance {
   /// }
   /// @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);
   }
 

diff  --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index e7764d49244a..223047c2afbd 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -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.

diff  --git a/flang/include/flang/Frontend/FrontendAction.h b/flang/include/flang/Frontend/FrontendAction.h
index 06121686b0d8..ccd2c2f0f7ae 100644
--- a/flang/include/flang/Frontend/FrontendAction.h
+++ b/flang/include/flang/Frontend/FrontendAction.h
@@ -48,31 +48,31 @@ class FrontendAction {
   /// @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

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index f1857043c8ab..fe07d044a08e 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -91,18 +91,18 @@ class FrontendInputFile {
   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_;
   }

diff  --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp
index 7f86920f3cf8..8f5d428dbb11 100644
--- a/flang/lib/Frontend/CompilerInstance.cpp
+++ b/flang/lib/Frontend/CompilerInstance.cpp
@@ -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));

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 69f1d57adc89..9f92b3dcec55 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -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;
 }

diff  --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp
index 024cc826aed2..ce88dd9e900b 100644
--- a/flang/lib/Frontend/FrontendAction.cpp
+++ b/flang/lib/Frontend/FrontendAction.cpp
@@ -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());
 }

diff  --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index fd4580330f18..0bea6cc6d09b 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -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();

diff  --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 171d70bcfac2..e205a5f9557d 100644
--- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -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;
   }

diff  --git a/flang/tools/flang-driver/fc1_main.cpp b/flang/tools/flang-driver/fc1_main.cpp
index ba6552b453f0..ecdceb9ba1cd 100644
--- a/flang/tools/flang-driver/fc1_main.cpp
+++ b/flang/tools/flang-driver/fc1_main.cpp
@@ -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;

diff  --git a/flang/unittests/Frontend/CompilerInstanceTest.cpp b/flang/unittests/Frontend/CompilerInstanceTest.cpp
index 932cacd85df3..df4bbb557c4d 100644
--- a/flang/unittests/Frontend/CompilerInstanceTest.cpp
+++ b/flang/unittests/Frontend/CompilerInstanceTest.cpp
@@ -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

diff  --git a/flang/unittests/Frontend/InputOutputTest.cpp b/flang/unittests/Frontend/InputOutputTest.cpp
index f2f28ae68561..882182fb1db3 100644
--- a/flang/unittests/Frontend/InputOutputTest.cpp
+++ b/flang/unittests/Frontend/InputOutputTest.cpp
@@ -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);


        


More information about the flang-commits mailing list