9#ifndef FORTRAN_PARSER_PROVENANCE_H_
10#define FORTRAN_PARSER_PROVENANCE_H_
12#include "char-block.h"
13#include "char-buffer.h"
14#include "characters.h"
16#include "flang/Common/idioms.h"
17#include "flang/Common/interval.h"
18#include "llvm/Support/raw_ostream.h"
50class AllCookedSources;
55 Provenance(std::size_t offset) : offset_{offset} { CHECK(offset > 0); }
61 std::size_t offset()
const {
return offset_; }
64 CHECK(n > -
static_cast<ptrdiff_t
>(offset_));
65 return {offset_ +
static_cast<std::size_t
>(n)};
67 Provenance operator+(std::size_t n)
const {
return {offset_ + n}; }
70 return offset_ - that.offset_;
72 bool operator<(
Provenance that)
const {
return offset_ < that.offset_; }
73 bool operator<=(
Provenance that)
const {
return !(that < *
this); }
74 bool operator==(
Provenance that)
const {
return offset_ == that.offset_; }
75 bool operator!=(
Provenance that)
const {
return !(*
this == that); }
78 std::size_t offset_{0};
92 bool empty()
const {
return map_.empty(); }
95 llvm::raw_ostream &Dump(llvm::raw_ostream &)
const;
101 struct WhollyPrecedes {
105 std::multimap<ProvenanceRange, std::size_t, WhollyPrecedes> map_;
117 void shrink_to_fit();
118 std::size_t SizeInBytes()
const;
122 void RemoveLastBytes(std::size_t);
124 llvm::raw_ostream &Dump(llvm::raw_ostream &)
const;
127 struct ContiguousProvenanceMapping {
134 std::vector<ContiguousProvenanceMapping> provenanceMap_;
144 std::size_t size()
const {
return range_.size(); }
146 Encoding encoding()
const {
return encoding_; }
152 void ClearSearchPath();
153 void AppendSearchPathDirectory(std::string);
154 const SourceFile *OpenPath(std::string path, llvm::raw_ostream &error);
155 const SourceFile *Open(std::string path, llvm::raw_ostream &error,
156 std::optional<std::string> &&prependPath = std::nullopt);
157 const SourceFile *ReadStandardInput(llvm::raw_ostream &error);
169 bool IsValid(
Provenance at)
const {
return range_.Contains(at); }
171 return range.size() > 0 && range_.Contains(range);
173 void setShowColors(
bool showColors) { showColors_ = showColors; }
174 bool getShowColors()
const {
return showColors_; }
175 std::optional<ProvenanceRange> GetInclusionInfo(
176 const std::optional<ProvenanceRange> &)
const;
177 void EmitMessage(llvm::raw_ostream &,
const std::optional<ProvenanceRange> &,
178 const std::string &message,
const std::string &prefix,
179 llvm::raw_ostream::Colors color,
bool echoSourceLine =
false)
const;
181 Provenance, std::size_t *offset =
nullptr,
bool topLevel =
false)
const;
183 std::optional<SourcePosition> GetSourcePosition(
Provenance)
const;
184 std::optional<ProvenanceRange> GetFirstFileProvenance()
const;
185 std::string GetPath(
Provenance,
bool topLevel =
false)
const;
187 Provenance CompilerInsertionProvenance(
char ch);
189 llvm::raw_ostream &Dump(llvm::raw_ostream &)
const;
194 bool isModule{
false};
198 std::string expansion;
200 struct CompilerInsertion {
207 bool isModule =
false);
209 const std::string &expansion);
212 const char &operator[](std::size_t)
const;
214 std::variant<Inclusion, Macro, CompilerInsertion> u;
221 std::vector<Origin> origin_;
223 std::map<char, Provenance> compilerInsertionProvenance_;
224 std::vector<std::unique_ptr<SourceFile>> ownedSourceFiles_;
225 std::list<std::string> searchPath_;
226 Encoding encoding_{Encoding::UTF_8};
227 bool showColors_{
false};
237 int number()
const {
return number_; }
238 void set_number(
int n) { number_ = n; }
241 std::optional<ProvenanceRange> GetProvenanceRange(
CharBlock)
const;
246 std::size_t Put(
const char *data, std::size_t bytes) {
247 return buffer_.Put(data, bytes);
249 std::size_t Put(
const std::string &s) {
return buffer_.Put(s); }
250 std::size_t Put(
char ch) {
return buffer_.Put(&ch, 1); }
253 return buffer_.Put(&ch, 1);
259 provenanceMap_.Put(pm);
262 void MarkPossibleFixedFormContinuation() {
263 possibleFixedFormContinuations_.push_back(BufferedBytes());
266 std::size_t BufferedBytes()
const;
268 void CompileProvenanceRangeToOffsetMappings(
AllSources &);
269 llvm::raw_ostream &Dump(llvm::raw_ostream &)
const;
278 std::list<std::size_t> possibleFixedFormContinuations_;
286 AllSources &allSources() {
return allSources_; }
287 const AllSources &allSources()
const {
return allSources_; }
294 bool IsValid(
ProvenanceRange r)
const {
return allSources_.IsValid(r); }
296 std::optional<ProvenanceRange> GetProvenanceRange(
CharBlock)
const;
297 std::optional<CharBlock> GetCharBlockFromLineAndColumns(
298 int line,
int startColumn,
int endColumn)
const;
299 std::optional<std::pair<SourcePosition, SourcePosition>>
302 void Dump(llvm::raw_ostream &)
const;
312 std::list<CookedSource> cooked_;
313 std::map<CharBlock, const CookedSource &, CharBlockPointerComparator> index_;
Definition: provenance.h:281
Definition: provenance.h:139
Definition: char-block.h:28
Definition: char-buffer.h:23
Definition: provenance.h:233
Definition: provenance.h:112
Definition: provenance.h:88
Definition: provenance.h:52
Definition: check-expression.h:19
Definition: parse-tree.h:3401