From 851a5a00f9bfd2034b03d2f6b5cc3c09b60162a4 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Fri, 27 Jul 2018 15:18:36 -0700 Subject: [PATCH] [flang] add isModuleFile flag to parser::Options, use it Original-commit: flang-compiler/f18@0727140f53cadad7740e524fd9300a1ca8b12044 Reviewed-on: https://github.com/flang-compiler/f18/pull/151 Tree-same-pre-rewrite: false --- flang/lib/parser/parsing.cc | 4 ++-- flang/lib/parser/parsing.h | 1 + flang/lib/semantics/mod-file.cc | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/flang/lib/parser/parsing.cc b/flang/lib/parser/parsing.cc index 7b1205c739e5..f8afcef5e7a3 100644 --- a/flang/lib/parser/parsing.cc +++ b/flang/lib/parser/parsing.cc @@ -78,8 +78,8 @@ void Parsing::Prescan(const std::string &path, Options options) { prescanner.AddCompilerDirectiveSentinel("$omp"); prescanner.AddCompilerDirectiveSentinel("$"); // OMP conditional line } - ProvenanceRange range{ - allSources.AddIncludedFile(*sourceFile, ProvenanceRange{})}; + ProvenanceRange range{allSources.AddIncludedFile( + *sourceFile, ProvenanceRange{}, options.isModuleFile)}; prescanner.Prescan(range); cooked_.Marshal(); } diff --git a/flang/lib/parser/parsing.h b/flang/lib/parser/parsing.h index 313c5421d237..911f5981920a 100644 --- a/flang/lib/parser/parsing.h +++ b/flang/lib/parser/parsing.h @@ -42,6 +42,7 @@ struct Options { std::vector searchDirectories; std::vector predefinitions; bool instrumentedParse{false}; + bool isModuleFile{false}; }; class Parsing { diff --git a/flang/lib/semantics/mod-file.cc b/flang/lib/semantics/mod-file.cc index ca11e34d2720..568426b49858 100644 --- a/flang/lib/semantics/mod-file.cc +++ b/flang/lib/semantics/mod-file.cc @@ -355,7 +355,9 @@ bool ModFileReader::Read(const SourceName &modName) { } // TODO: Construct parsing with an AllSources reference to share provenance parser::Parsing parsing; - parsing.Prescan(*path, {}); + parser::Options options; + options.isModuleFile = true; + parsing.Prescan(*path, options); parsing.Parse(&std::cout); auto &parseTree{parsing.parseTree()}; if (!parsing.messages().empty() || !parsing.consumedWholeFile() || @@ -372,6 +374,7 @@ bool ModFileReader::Read(const SourceName &modName) { return false; } auto &modSymbol{*it->second}; + // TODO: Preserve the CookedSource rather than a copy of its string. modSymbol.scope()->set_chars(std::string{parsing.cooked().data()}); modSymbol.set(Symbol::Flag::ModFile); return true;