Skip to content

Commit

Permalink
[flang][nfc] Fix variable names in FrontendOptions & `PreprocessorO…
Browse files Browse the repository at this point in the history
…ptions`

As all member variables in `FrontendOptions` and `PreprocessorOptions`
are public, we should be naming them as `variable` rather than
`variable_` [1]. This patch fixes that.

Also, `FrontendOptions` & `PreprocessorOptions` are re-defined as a
structs rather than classes (all fields are meant to be public).

[1]
https://github.com/llvm/llvm-project/blob/main/flang/docs/C%2B%2Bstyle.md#naming

Differential Revision: https://reviews.llvm.org/D107062
  • Loading branch information
banach-space committed Aug 2, 2021
1 parent 2829391 commit 23d4c4f
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 101 deletions.
2 changes: 1 addition & 1 deletion flang/docs/FlangDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ add, you will have to add a dedicated entry in that enum (e.g.
`ParseFrontendArgs` function in the `CompilerInvocation.cpp` file, e.g.:
```cpp
case clang::driver::options::OPT_fsyntax_only:
opts.programAction_ = ParseSyntaxOnly;
opts.programAction = ParseSyntaxOnly;
break;
```
Note that this simply sets the program/frontend action within the frontend
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CompilerInstance {
///
/// \param binary The mode to open the file in.
/// \param baseInput If the invocation contains no output file name (i.e.
/// outputFile_ in FrontendOptions is empty), the input path
/// outputFile in FrontendOptions is empty), the input path
/// name to use for deriving the output path.
/// \param extension The extension to use for output names derived from
/// \p baseInput.
Expand Down
38 changes: 18 additions & 20 deletions flang/include/flang/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,60 +199,58 @@ class FrontendInputFile {
};

/// FrontendOptions - Options for controlling the behavior of the frontend.
class FrontendOptions {
public:
struct FrontendOptions {
FrontendOptions()
: showHelp(false), showVersion(false), instrumentedParse(false),
needProvenanceRangeToCharBlockMappings(false) {}

/// Show the -help text.
unsigned showHelp_ : 1;
unsigned showHelp : 1;

/// Show the -version text.
unsigned showVersion_ : 1;
unsigned showVersion : 1;

/// Instrument the parse to get a more verbose log
unsigned instrumentedParse_ : 1;
unsigned instrumentedParse : 1;

/// Enable Provenance to character-stream mapping. Allows e.g. IDEs to find
/// symbols based on source-code location. This is not needed in regular
/// compilation.
unsigned needProvenanceRangeToCharBlockMappings_ : 1;
unsigned needProvenanceRangeToCharBlockMappings : 1;

/// Input values from `-fget-definition`
struct GetDefinitionVals {
unsigned line;
unsigned startColumn;
unsigned endColumn;
};
GetDefinitionVals getDefVals_;
GetDefinitionVals getDefVals;

/// The input files and their types.
std::vector<FrontendInputFile> inputs_;
std::vector<FrontendInputFile> inputs;

/// The output file, if any.
std::string outputFile_;
std::string outputFile;

/// The frontend action to perform.
frontend::ActionKind programAction_;
frontend::ActionKind programAction;

// The form to process files in, if specified.
FortranForm fortranForm_ = FortranForm::Unknown;
FortranForm fortranForm = FortranForm::Unknown;

// The column after which characters are ignored in fixed form lines in the
// source file.
int fixedFormColumns_ = 72;
int fixedFormColumns = 72;

/// The input kind, either specified via -x argument or deduced from the input
/// file name.
InputKind dashX_;
InputKind dashX;

// Language features
common::LanguageFeatureControl features_;
common::LanguageFeatureControl features;

// Source file encoding
Fortran::parser::Encoding encoding_{Fortran::parser::Encoding::UTF_8};

public:
FrontendOptions()
: showHelp_(false), showVersion_(false), instrumentedParse_(false),
needProvenanceRangeToCharBlockMappings_(false) {}
Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8};

// Return the appropriate input kind for a file extension. For example,
/// "*.f" would return Language::Fortran.
Expand Down
11 changes: 5 additions & 6 deletions flang/include/flang/Frontend/PreprocessorOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ enum class PPMacrosFlag : uint8_t {

/// This class is used for passing the various options used
/// in preprocessor initialization to the parser options.
class PreprocessorOptions {
public:
struct PreprocessorOptions {
PreprocessorOptions() {}

std::vector<std::pair<std::string, /*isUndef*/ bool>> macros;

// Search directories specified by the user with -I
// TODO: When adding support for more options related to search paths,
// consider collecting them in a separate aggregate. For now we keep it here
Expand All @@ -42,17 +44,14 @@ class PreprocessorOptions {
// Search directories specified by the user with -fintrinsic-modules-path
std::vector<std::string> searchDirectoriesFromIntrModPath;

PPMacrosFlag macrosFlag_ = PPMacrosFlag::Unknown;
PPMacrosFlag macrosFlag = PPMacrosFlag::Unknown;

// -P: Suppress #line directives in -E output
bool noLineDirectives{false};

// -fno-reformat: Emit cooked character stream as -E output
bool noReformat{false};

public:
PreprocessorOptions() {}

void addMacroDef(llvm::StringRef name) {
macros.emplace_back(std::string(name), false);
}
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ CompilerInstance::CreateDefaultOutputFile(

// Get the path of the output file
std::string outputFilePath =
GetOutputFilePath(frontendOpts().outputFile_, baseName, extension);
GetOutputFilePath(frontendOpts().outputFile, baseName, extension);

// Create the output file
std::unique_ptr<llvm::raw_pwrite_stream> os =
Expand Down Expand Up @@ -150,7 +150,7 @@ bool CompilerInstance::ExecuteAction(FrontendAction &act) {
invoc.setSemanticsOpts(*this->allCookedSources_);

// Run the frontend action `act` for every input file.
for (const FrontendInputFile &fif : frontendOpts().inputs_) {
for (const FrontendInputFile &fif : frontendOpts().inputs) {
if (act.BeginSourceFile(*this, fif)) {
if (llvm::Error err = act.Execute()) {
consumeError(std::move(err));
Expand Down
Loading

0 comments on commit 23d4c4f

Please sign in to comment.