aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index ce7392c..6c6277c 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -323,6 +323,14 @@ static void parsePreprocessorArgs(
for (const auto *currentArg :
args.filtered(clang::driver::options::OPT_fintrinsic_modules_path))
opts.searchDirectoriesFromIntrModPath.emplace_back(currentArg->getValue());
+
+ // -cpp/-nocpp
+ if (const auto *currentArg = args.getLastArg(
+ clang::driver::options::OPT_cpp, clang::driver::options::OPT_nocpp))
+ opts.macrosFlag_ =
+ (currentArg->getOption().matches(clang::driver::options::OPT_cpp))
+ ? PPMacrosFlag::Include
+ : PPMacrosFlag::Exclude;
}
/// Parses all semantic related arguments and populates the variables
@@ -471,13 +479,9 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
return success;
}
-/// Collect the macro definitions provided by the given preprocessor
-/// options into the parser options.
-///
-/// \param [in] ppOpts The preprocessor options
-/// \param [out] opts The fortran options
-static void collectMacroDefinitions(
- const PreprocessorOptions &ppOpts, Fortran::parser::Options &opts) {
+void CompilerInvocation::collectMacroDefinitions() {
+ auto &ppOpts = this->preprocessorOpts();
+
for (unsigned i = 0, n = ppOpts.macros.size(); i != n; ++i) {
llvm::StringRef macro = ppOpts.macros[i].first;
bool isUndef = ppOpts.macros[i].second;
@@ -488,7 +492,7 @@ static void collectMacroDefinitions(
// For an #undef'd macro, we only care about the name.
if (isUndef) {
- opts.predefinitions.emplace_back(
+ parserOpts_.predefinitions.emplace_back(
macroName.str(), std::optional<std::string>{});
continue;
}
@@ -501,7 +505,7 @@ static void collectMacroDefinitions(
llvm::StringRef::size_type End = macroBody.find_first_of("\n\r");
macroBody = macroBody.substr(0, End);
}
- opts.predefinitions.emplace_back(
+ parserOpts_.predefinitions.emplace_back(
macroName, std::optional<std::string>(macroBody.str()));
}
}
@@ -557,8 +561,6 @@ void CompilerInvocation::setFortranOpts() {
fortranOptions.features = frontendOptions.features_;
fortranOptions.encoding = frontendOptions.encoding_;
- collectMacroDefinitions(preprocessorOptions, fortranOptions);
-
// Adding search directories specified by -I
fortranOptions.searchDirectories.insert(
fortranOptions.searchDirectories.end(),