diff --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md --- a/flang/docs/FlangDriver.md +++ b/flang/docs/FlangDriver.md @@ -211,7 +211,7 @@ `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 diff --git a/flang/include/flang/Frontend/CompilerInstance.h b/flang/include/flang/Frontend/CompilerInstance.h --- a/flang/include/flang/Frontend/CompilerInstance.h +++ b/flang/include/flang/Frontend/CompilerInstance.h @@ -179,7 +179,7 @@ /// /// \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. diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h --- a/flang/include/flang/Frontend/FrontendOptions.h +++ b/flang/include/flang/Frontend/FrontendOptions.h @@ -199,21 +199,24 @@ }; /// 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 { @@ -221,38 +224,33 @@ unsigned startColumn; unsigned endColumn; }; - GetDefinitionVals getDefVals_; + GetDefinitionVals getDefVals; /// The input files and their types. - std::vector inputs_; + std::vector 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. diff --git a/flang/include/flang/Frontend/PreprocessorOptions.h b/flang/include/flang/Frontend/PreprocessorOptions.h --- a/flang/include/flang/Frontend/PreprocessorOptions.h +++ b/flang/include/flang/Frontend/PreprocessorOptions.h @@ -31,9 +31,11 @@ /// 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> 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 @@ -42,7 +44,7 @@ // Search directories specified by the user with -fintrinsic-modules-path std::vector searchDirectoriesFromIntrModPath; - PPMacrosFlag macrosFlag_ = PPMacrosFlag::Unknown; + PPMacrosFlag macrosFlag = PPMacrosFlag::Unknown; // -P: Suppress #line directives in -E output bool noLineDirectives{false}; @@ -50,9 +52,6 @@ // -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); } diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp --- a/flang/lib/Frontend/CompilerInstance.cpp +++ b/flang/lib/Frontend/CompilerInstance.cpp @@ -89,7 +89,7 @@ // 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 os = @@ -150,7 +150,7 @@ 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)); diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -89,15 +89,15 @@ // Tweak the frontend configuration based on the frontend action static void setUpFrontendBasedOnAction(FrontendOptions &opts) { - assert(opts.programAction_ != Fortran::frontend::InvalidAction && + assert(opts.programAction != Fortran::frontend::InvalidAction && "Fortran frontend action not set!"); - if (opts.programAction_ == DebugDumpParsingLog) - opts.instrumentedParse_ = true; + if (opts.programAction == DebugDumpParsingLog) + opts.instrumentedParse = true; - if (opts.programAction_ == DebugDumpProvenance || - opts.programAction_ == Fortran::frontend::GetDefinition) - opts.needProvenanceRangeToCharBlockMappings_ = true; + if (opts.programAction == DebugDumpProvenance || + opts.programAction == Fortran::frontend::GetDefinition) + opts.needProvenanceRangeToCharBlockMappings = true; } static bool ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args, @@ -105,7 +105,7 @@ unsigned numErrorsBefore = diags.getNumErrors(); // By default the frontend driver creates a ParseSyntaxOnly action. - opts.programAction_ = ParseSyntaxOnly; + opts.programAction = ParseSyntaxOnly; // Identify the action (i.e. opts.ProgramAction) if (const llvm::opt::Arg *a = @@ -115,58 +115,58 @@ llvm_unreachable("Invalid option in group!"); } case clang::driver::options::OPT_test_io: - opts.programAction_ = InputOutputTest; + opts.programAction = InputOutputTest; break; case clang::driver::options::OPT_E: - opts.programAction_ = PrintPreprocessedInput; + opts.programAction = PrintPreprocessedInput; break; case clang::driver::options::OPT_fsyntax_only: - opts.programAction_ = ParseSyntaxOnly; + opts.programAction = ParseSyntaxOnly; break; case clang::driver::options::OPT_emit_obj: - opts.programAction_ = EmitObj; + opts.programAction = EmitObj; break; case clang::driver::options::OPT_fdebug_unparse: - opts.programAction_ = DebugUnparse; + opts.programAction = DebugUnparse; break; case clang::driver::options::OPT_fdebug_unparse_no_sema: - opts.programAction_ = DebugUnparseNoSema; + opts.programAction = DebugUnparseNoSema; break; case clang::driver::options::OPT_fdebug_unparse_with_symbols: - opts.programAction_ = DebugUnparseWithSymbols; + opts.programAction = DebugUnparseWithSymbols; break; case clang::driver::options::OPT_fdebug_dump_symbols: - opts.programAction_ = DebugDumpSymbols; + opts.programAction = DebugDumpSymbols; break; case clang::driver::options::OPT_fdebug_dump_parse_tree: - opts.programAction_ = DebugDumpParseTree; + opts.programAction = DebugDumpParseTree; break; case clang::driver::options::OPT_fdebug_dump_all: - opts.programAction_ = DebugDumpAll; + opts.programAction = DebugDumpAll; break; case clang::driver::options::OPT_fdebug_dump_parse_tree_no_sema: - opts.programAction_ = DebugDumpParseTreeNoSema; + opts.programAction = DebugDumpParseTreeNoSema; break; case clang::driver::options::OPT_fdebug_dump_provenance: - opts.programAction_ = DebugDumpProvenance; + opts.programAction = DebugDumpProvenance; break; case clang::driver::options::OPT_fdebug_dump_parsing_log: - opts.programAction_ = DebugDumpParsingLog; + opts.programAction = DebugDumpParsingLog; break; case clang::driver::options::OPT_fdebug_measure_parse_tree: - opts.programAction_ = DebugMeasureParseTree; + opts.programAction = DebugMeasureParseTree; break; case clang::driver::options::OPT_fdebug_pre_fir_tree: - opts.programAction_ = DebugPreFIRTree; + opts.programAction = DebugPreFIRTree; break; case clang::driver::options::OPT_fget_symbols_sources: - opts.programAction_ = GetSymbolsSources; + opts.programAction = GetSymbolsSources; break; case clang::driver::options::OPT_fget_definition: - opts.programAction_ = GetDefinition; + opts.programAction = GetDefinition; break; case clang::driver::options::OPT_init_only: - opts.programAction_ = InitOnly; + opts.programAction = InitOnly; break; // TODO: @@ -193,15 +193,15 @@ break; } } - opts.getDefVals_.line = optVals[0]; - opts.getDefVals_.startColumn = optVals[1]; - opts.getDefVals_.endColumn = optVals[2]; + opts.getDefVals.line = optVals[0]; + opts.getDefVals.startColumn = optVals[1]; + opts.getDefVals.endColumn = optVals[2]; } } - opts.outputFile_ = args.getLastArgValue(clang::driver::options::OPT_o); - opts.showHelp_ = args.hasArg(clang::driver::options::OPT_help); - opts.showVersion_ = args.hasArg(clang::driver::options::OPT_version); + opts.outputFile = args.getLastArgValue(clang::driver::options::OPT_o); + opts.showHelp = args.hasArg(clang::driver::options::OPT_help); + opts.showVersion = args.hasArg(clang::driver::options::OPT_version); // Get the input kind (from the value passed via `-x`) InputKind dashX(Language::Unknown); @@ -227,7 +227,7 @@ // Collect the input files and save them in our instance of FrontendOptions. std::vector inputs = args.getAllArgValues(clang::driver::options::OPT_INPUT); - opts.inputs_.clear(); + opts.inputs.clear(); if (inputs.empty()) // '-' is the default input if none is given. inputs.push_back("-"); @@ -242,19 +242,19 @@ dashX = ik; } - opts.inputs_.emplace_back(std::move(inputs[i]), ik); + opts.inputs.emplace_back(std::move(inputs[i]), ik); } - // Set fortranForm_ based on options -ffree-form and -ffixed-form. + // Set fortranForm based on options -ffree-form and -ffixed-form. if (const auto *arg = args.getLastArg(clang::driver::options::OPT_ffixed_form, clang::driver::options::OPT_ffree_form)) { - opts.fortranForm_ = + opts.fortranForm = arg->getOption().matches(clang::driver::options::OPT_ffixed_form) ? FortranForm::FixedForm : FortranForm::FreeForm; } - // Set fixedFormColumns_ based on -ffixed-line-length= + // Set fixedFormColumns based on -ffixed-line-length= if (const auto *arg = args.getLastArg(clang::driver::options::OPT_ffixed_line_length_EQ)) { llvm::StringRef argValue = llvm::StringRef(arg->getValue()); @@ -268,53 +268,52 @@ diags.Report(clang::diag::err_drv_negative_columns) << arg->getOption().getName() << arg->getValue(); } else if (columns == 0) { - opts.fixedFormColumns_ = 1000000; + opts.fixedFormColumns = 1000000; } else if (columns < 7) { diags.Report(clang::diag::err_drv_small_columns) << arg->getOption().getName() << arg->getValue() << "7"; } else { - opts.fixedFormColumns_ = columns; + opts.fixedFormColumns = columns; } } if (const llvm::opt::Arg *arg = args.getLastArg(clang::driver::options::OPT_fimplicit_none, clang::driver::options::OPT_fno_implicit_none)) { - opts.features_.Enable( + opts.features.Enable( Fortran::common::LanguageFeature::ImplicitNoneTypeAlways, arg->getOption().matches(clang::driver::options::OPT_fimplicit_none)); } if (const llvm::opt::Arg *arg = args.getLastArg(clang::driver::options::OPT_fbackslash, clang::driver::options::OPT_fno_backslash)) { - opts.features_.Enable(Fortran::common::LanguageFeature::BackslashEscapes, + opts.features.Enable(Fortran::common::LanguageFeature::BackslashEscapes, arg->getOption().matches(clang::driver::options::OPT_fbackslash)); } if (const llvm::opt::Arg *arg = args.getLastArg(clang::driver::options::OPT_flogical_abbreviations, clang::driver::options::OPT_fno_logical_abbreviations)) { - opts.features_.Enable( - Fortran::common::LanguageFeature::LogicalAbbreviations, + opts.features.Enable(Fortran::common::LanguageFeature::LogicalAbbreviations, arg->getOption().matches( clang::driver::options::OPT_flogical_abbreviations)); } if (const llvm::opt::Arg *arg = args.getLastArg(clang::driver::options::OPT_fxor_operator, clang::driver::options::OPT_fno_xor_operator)) { - opts.features_.Enable(Fortran::common::LanguageFeature::XOROperator, + opts.features.Enable(Fortran::common::LanguageFeature::XOROperator, arg->getOption().matches(clang::driver::options::OPT_fxor_operator)); } if (args.hasArg( clang::driver::options::OPT_falternative_parameter_statement)) { - opts.features_.Enable(Fortran::common::LanguageFeature::OldStyleParameter); + opts.features.Enable(Fortran::common::LanguageFeature::OldStyleParameter); } if (const llvm::opt::Arg *arg = args.getLastArg(clang::driver::options::OPT_finput_charset_EQ)) { llvm::StringRef argValue = arg->getValue(); if (argValue == "utf-8") { - opts.encoding_ = Fortran::parser::Encoding::UTF_8; + opts.encoding = Fortran::parser::Encoding::UTF_8; } else if (argValue == "latin-1") { - opts.encoding_ = Fortran::parser::Encoding::LATIN_1; + opts.encoding = Fortran::parser::Encoding::LATIN_1; } else { diags.Report(clang::diag::err_drv_invalid_value) << arg->getAsString(args) << argValue; @@ -322,7 +321,7 @@ } setUpFrontendBasedOnAction(opts); - opts.dashX_ = dashX; + opts.dashX = dashX; return diags.getNumErrors() == numErrorsBefore; } @@ -367,7 +366,7 @@ // -cpp/-nocpp if (const auto *currentArg = args.getLastArg( clang::driver::options::OPT_cpp, clang::driver::options::OPT_nocpp)) - opts.macrosFlag_ = + opts.macrosFlag = (currentArg->getOption().matches(clang::driver::options::OPT_cpp)) ? PPMacrosFlag::Include : PPMacrosFlag::Exclude; @@ -473,11 +472,11 @@ // -fopenmp and -fopenacc if (args.hasArg(clang::driver::options::OPT_fopenacc)) { - res.frontendOpts().features_.Enable( + res.frontendOpts().features.Enable( Fortran::common::LanguageFeature::OpenACC); } if (args.hasArg(clang::driver::options::OPT_fopenmp)) { - res.frontendOpts().features_.Enable( + res.frontendOpts().features.Enable( Fortran::common::LanguageFeature::OpenMP); } @@ -601,11 +600,11 @@ "__flang_patchlevel__", FLANG_VERSION_PATCHLEVEL_STRING); // Add predefinitions based on extensions enabled - if (frontendOptions.features_.IsEnabled( + if (frontendOptions.features.IsEnabled( Fortran::common::LanguageFeature::OpenACC)) { fortranOptions.predefinitions.emplace_back("_OPENACC", "202011"); } - if (frontendOptions.features_.IsEnabled( + if (frontendOptions.features.IsEnabled( Fortran::common::LanguageFeature::OpenMP)) { fortranOptions.predefinitions.emplace_back("_OPENMP", "201511"); } @@ -617,14 +616,14 @@ const auto &preprocessorOptions = preprocessorOpts(); auto &moduleDirJ = moduleDir(); - if (frontendOptions.fortranForm_ != FortranForm::Unknown) { + if (frontendOptions.fortranForm != FortranForm::Unknown) { fortranOptions.isFixedForm = - frontendOptions.fortranForm_ == FortranForm::FixedForm; + frontendOptions.fortranForm == FortranForm::FixedForm; } - fortranOptions.fixedFormColumns = frontendOptions.fixedFormColumns_; + fortranOptions.fixedFormColumns = frontendOptions.fixedFormColumns; - fortranOptions.features = frontendOptions.features_; - fortranOptions.encoding = frontendOptions.encoding_; + fortranOptions.features = frontendOptions.features; + fortranOptions.encoding = frontendOptions.encoding; // Adding search directories specified by -I fortranOptions.searchDirectories.insert( @@ -646,10 +645,10 @@ if (moduleDirJ.compare(".") != 0) fortranOptions.searchDirectories.emplace_back(moduleDirJ); - if (frontendOptions.instrumentedParse_) + if (frontendOptions.instrumentedParse) fortranOptions.instrumentedParse = true; - if (frontendOptions.needProvenanceRangeToCharBlockMappings_) + if (frontendOptions.needProvenanceRangeToCharBlockMappings) fortranOptions.needProvenanceRangeToCharBlockMappings = true; if (enableConformanceChecks()) { diff --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp --- a/flang/lib/Frontend/FrontendAction.cpp +++ b/flang/lib/Frontend/FrontendAction.cpp @@ -73,8 +73,8 @@ // * `-cpp/-nocpp`, or // * the file extension (if the user didn't express any preference) // to decide whether to include them or not. - if ((invoc.preprocessorOpts().macrosFlag_ == PPMacrosFlag::Include) || - (invoc.preprocessorOpts().macrosFlag_ == PPMacrosFlag::Unknown && + if ((invoc.preprocessorOpts().macrosFlag == PPMacrosFlag::Include) || + (invoc.preprocessorOpts().macrosFlag == PPMacrosFlag::Unknown && currentInput().MustBePreprocessed())) { invoc.setDefaultPredefinitions(); invoc.collectMacroDefinitions(); @@ -82,7 +82,7 @@ // Decide between fixed and free form (if the user didn't express any // preference, use the file extension to decide) - if (invoc.frontendOpts().fortranForm_ == FortranForm::Unknown) { + if (invoc.frontendOpts().fortranForm == FortranForm::Unknown) { invoc.fortranOpts().isFixedForm = currentInput().IsFixedForm(); } diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp --- a/flang/lib/Frontend/FrontendActions.cpp +++ b/flang/lib/Frontend/FrontendActions.cpp @@ -74,7 +74,7 @@ Fortran::parser::Options parserOptions = ci.invocation().fortranOpts(); - if (ci.invocation().frontendOpts().fortranForm_ == FortranForm::Unknown) { + if (ci.invocation().frontendOpts().fortranForm == FortranForm::Unknown) { // Switch between fixed and free form format based on the input file // extension. // @@ -437,7 +437,7 @@ unsigned diagID = ci.diagnostics().getCustomDiagID( clang::DiagnosticsEngine::Error, "Symbol not found"); - auto gdv = ci.invocation().frontendOpts().getDefVals_; + auto gdv = ci.invocation().frontendOpts().getDefVals; auto charBlock{cs.GetCharBlockFromLineAndColumns( gdv.line, gdv.startColumn, gdv.endColumn)}; if (!charBlock) { diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp --- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -24,7 +24,7 @@ static std::unique_ptr CreateFrontendBaseAction( CompilerInstance &ci) { - ActionKind ak = ci.frontendOpts().programAction_; + ActionKind ak = ci.frontendOpts().programAction; switch (ak) { case InputOutputTest: return std::make_unique(); @@ -84,7 +84,7 @@ } bool ExecuteCompilerInvocation(CompilerInstance *flang) { // Honor -help. - if (flang->frontendOpts().showHelp_) { + if (flang->frontendOpts().showHelp) { clang::driver::getDriverOptTable().printHelp(llvm::outs(), "flang-new -fc1 [options] file...", "LLVM 'Flang' Compiler", /*Include=*/clang::driver::options::FC1Option, @@ -94,7 +94,7 @@ } // Honor -version. - if (flang->frontendOpts().showVersion_) { + if (flang->frontendOpts().showVersion) { llvm::cl::PrintVersionMessage(); return true; } diff --git a/flang/unittests/Frontend/FrontendActionTest.cpp b/flang/unittests/Frontend/FrontendActionTest.cpp --- a/flang/unittests/Frontend/FrontendActionTest.cpp +++ b/flang/unittests/Frontend/FrontendActionTest.cpp @@ -62,7 +62,7 @@ invocation_ = std::make_shared(); compInst_.set_invocation(std::move(invocation_)); - compInst_.frontendOpts().inputs_.push_back( + compInst_.frontendOpts().inputs.push_back( FrontendInputFile(inputFilePath_, Language::Fortran)); } @@ -86,7 +86,7 @@ inputFileOs_.reset(); // Set-up the action kind. - compInst_.invocation().frontendOpts().programAction_ = InputOutputTest; + compInst_.invocation().frontendOpts().programAction = InputOutputTest; // Set-up the output stream. Using output buffer wrapped as an output // stream, as opposed to an actual file (or a file descriptor). @@ -115,7 +115,7 @@ inputFileOs_.reset(); // Set-up the action kind. - compInst_.invocation().frontendOpts().programAction_ = PrintPreprocessedInput; + compInst_.invocation().frontendOpts().programAction = PrintPreprocessedInput; compInst_.invocation().preprocessorOpts().noReformat = true; // Set-up the output stream. We are using output buffer wrapped as an output @@ -142,7 +142,7 @@ inputFileOs_.reset(); // Set-up the action kind. - compInst_.invocation().frontendOpts().programAction_ = ParseSyntaxOnly; + compInst_.invocation().frontendOpts().programAction = ParseSyntaxOnly; // Set-up the output stream for the semantic diagnostics. llvm::SmallVector outputDiagBuffer;