Files
clang-p2996/flang/lib/Frontend/FrontendActions.cpp
Andrzej Warzynski 9ffb5b0469 [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
2020-11-02 10:55:13 +00:00

46 lines
1.6 KiB
C++

//===--- FrontendActions.cpp ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "flang/Frontend/FrontendActions.h"
#include "flang/Common/Fortran-features.h"
#include "flang/Common/default-kinds.h"
#include "flang/Frontend/CompilerInstance.h"
#include "flang/Parser/source.h"
#include "clang/Serialization/PCHContainerOperations.h"
using namespace Fortran::frontend;
void InputOutputTestAction::ExecuteAction() {
// Get the name of the file from FrontendInputFile current.
std::string path{GetCurrentFileOrBufferName()};
std::string buf;
llvm::raw_string_ostream error_stream{buf};
bool binaryMode = true;
// Set/store input file info into CompilerInstance.
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();
// Output file descriptor to receive the content of input file.
std::unique_ptr<llvm::raw_ostream> os;
// Do not write on the output file if using outputStream_.
if (ci.IsOutputStreamNull()) {
os = ci.CreateDefaultOutputFile(
binaryMode, GetCurrentFileOrBufferName(), "txt");
if (!os)
return;
(*os) << fileContent.data();
} else {
ci.WriteOutputStream(fileContent.data());
}
}