9#ifndef FORTRAN_PARSER_PARSE_STATE_H_
10#define FORTRAN_PARSER_PARSE_STATE_H_
18#include "user-state.h"
19#include "flang/Common/Fortran-features.h"
20#include "flang/Common/idioms.h"
21#include "flang/Parser/characters.h"
22#include "flang/Parser/message.h"
23#include "flang/Parser/provenance.h"
33using common::LanguageFeature;
38 : p_{cooked.AsCharBlock().begin()}, limit_{cooked.AsCharBlock().end()} {}
40 : p_{that.p_}, limit_{that.limit_}, context_{that.context_},
41 userState_{that.userState_}, inFixedForm_{that.inFixedForm_},
42 anyErrorRecovery_{that.anyErrorRecovery_},
43 anyConformanceViolation_{that.anyConformanceViolation_},
44 deferMessages_{that.deferMessages_},
45 anyDeferredMessages_{that.anyDeferredMessages_},
46 anyTokenMatched_{that.anyTokenMatched_} {}
48 : p_{that.p_}, limit_{that.limit_}, messages_{std::move(that.messages_)},
49 context_{std::move(that.context_)}, userState_{that.userState_},
50 inFixedForm_{that.inFixedForm_},
51 anyErrorRecovery_{that.anyErrorRecovery_},
52 anyConformanceViolation_{that.anyConformanceViolation_},
53 deferMessages_{that.deferMessages_},
54 anyDeferredMessages_{that.anyDeferredMessages_},
55 anyTokenMatched_{that.anyTokenMatched_} {}
57 p_ = that.p_, limit_ = that.limit_, context_ = that.context_;
58 userState_ = that.userState_, inFixedForm_ = that.inFixedForm_;
59 anyErrorRecovery_ = that.anyErrorRecovery_;
60 anyConformanceViolation_ = that.anyConformanceViolation_;
61 deferMessages_ = that.deferMessages_;
62 anyDeferredMessages_ = that.anyDeferredMessages_;
63 anyTokenMatched_ = that.anyTokenMatched_;
67 p_ = that.p_, limit_ = that.limit_, messages_ = std::move(that.messages_);
68 context_ = std::move(that.context_);
69 userState_ = that.userState_, inFixedForm_ = that.inFixedForm_;
70 anyErrorRecovery_ = that.anyErrorRecovery_;
71 anyConformanceViolation_ = that.anyConformanceViolation_;
72 deferMessages_ = that.deferMessages_;
73 anyDeferredMessages_ = that.anyDeferredMessages_;
74 anyTokenMatched_ = that.anyTokenMatched_;
78 const Messages &messages()
const {
return messages_; }
79 Messages &messages() {
return messages_; }
84 bool anyErrorRecovery()
const {
return anyErrorRecovery_; }
85 void set_anyErrorRecovery() { anyErrorRecovery_ =
true; }
87 bool anyConformanceViolation()
const {
return anyConformanceViolation_; }
88 void set_anyConformanceViolation() { anyConformanceViolation_ =
true; }
90 UserState *userState()
const {
return userState_; }
96 bool inFixedForm()
const {
return inFixedForm_; }
102 bool deferMessages()
const {
return deferMessages_; }
103 ParseState &set_deferMessages(
bool yes =
true) {
104 deferMessages_ = yes;
108 bool anyDeferredMessages()
const {
return anyDeferredMessages_; }
109 ParseState &set_anyDeferredMessages(
bool yes =
true) {
110 anyDeferredMessages_ = yes;
114 bool anyTokenMatched()
const {
return anyTokenMatched_; }
115 ParseState &set_anyTokenMatched(
bool yes =
true) {
116 anyTokenMatched_ = yes;
120 const char *GetLocation()
const {
return p_; }
124 m->SetContext(context_.get());
130 context_ = context_->attachment();
133 template <
typename... A>
void Say(
CharBlock range, A &&...args) {
134 if (deferMessages_) {
135 anyDeferredMessages_ =
true;
137 messages_.Say(range, std::forward<A>(args)...).SetContext(context_.get());
140 template <
typename... A>
void Say(
const MessageFixedText &text, A &&...args) {
141 Say(p_, text, std::forward<A>(args)...);
143 template <
typename... A>
145 Say(p_, text, std::forward<A>(args)...);
149 Nonstandard(p_, lf, msg);
153 anyConformanceViolation_ =
true;
154 if (userState_ && userState_->features().ShouldWarn(lf)) {
159 if (userState_ && !userState_->features().IsEnabled(lf)) {
162 Nonstandard(lf, msg);
166 bool IsAtEnd()
const {
return p_ >= limit_; }
168 const char *UncheckedAdvance(std::size_t n = 1) {
169 const char *result{p_};
174 std::optional<const char *> GetNextChar() {
176 return UncheckedAdvance();
182 std::optional<const char *> PeekAtNextChar()
const {
190 std::size_t BytesRemaining()
const {
191 std::size_t remain = limit_ - p_;
196 if (prev.anyTokenMatched_) {
197 if (!anyTokenMatched_ || prev.p_ > p_) {
198 anyTokenMatched_ =
true;
200 messages_ = std::move(prev.messages_);
201 }
else if (prev.p_ == p_) {
202 messages_.Merge(std::move(prev.messages_));
205 anyDeferredMessages_ |= prev.anyDeferredMessages_;
206 anyConformanceViolation_ |= prev.anyConformanceViolation_;
207 anyErrorRecovery_ |= prev.anyErrorRecovery_;
212 const char *p_{
nullptr}, *limit_{
nullptr};
220 bool inFixedForm_{
false};
221 bool anyErrorRecovery_{
false};
222 bool anyConformanceViolation_{
false};
223 bool deferMessages_{
false};
224 bool anyDeferredMessages_{
false};
225 bool anyTokenMatched_{
false};
Definition: char-block.h:28
Definition: provenance.h:233
Definition: message.h:160
Definition: message.h:188
Definition: message.h:319
Definition: parse-state.h:35
Definition: user-state.h:35
Definition: check-expression.h:19