forked from OSchip/llvm-project
[flang] Restructure inter-class references for clarity.
Original-commit: flang-compiler/f18@1836cd5d06 Reviewed-on: https://github.com/flang-compiler/f18/pull/9 Tree-same-pre-rewrite: false
This commit is contained in:
parent
f5202dd68f
commit
3bca5d088e
|
@ -23,7 +23,8 @@ public:
|
||||||
if (auto context = state->context()) {
|
if (auto context = state->context()) {
|
||||||
std::cout << *context;
|
std::cout << *context;
|
||||||
}
|
}
|
||||||
state->GetAllSources().Identify(std::cout, state->GetProvenance(), "");
|
state->cooked().allSources().Identify(
|
||||||
|
std::cout, state->GetProvenance(), "");
|
||||||
std::cout << " parser debug: " << std::string{str_, length_} << '\n';
|
std::cout << " parser debug: " << std::string{str_, length_} << '\n';
|
||||||
return {Success{}};
|
return {Success{}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ void Message::Emit(std::ostream &o, const AllSources &sources) const {
|
||||||
o << " " << message_ << '\n';
|
o << " " << message_ << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void Messages::Emit(std::ostream &o, const AllSources &sources) const {
|
void Messages::Emit(std::ostream &o) const {
|
||||||
for (const auto &msg : messages_) {
|
for (const auto &msg : messages_) {
|
||||||
msg.Emit(o, sources);
|
msg.Emit(o, allSources_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace parser
|
} // namespace parser
|
||||||
|
|
|
@ -57,9 +57,10 @@ public:
|
||||||
using iterator = list_type::iterator;
|
using iterator = list_type::iterator;
|
||||||
using const_iterator = list_type::const_iterator;
|
using const_iterator = list_type::const_iterator;
|
||||||
|
|
||||||
Messages() {}
|
explicit Messages(const AllSources &sources) : allSources_{sources} {}
|
||||||
Messages(Messages &&that)
|
Messages(Messages &&that)
|
||||||
: messages_{std::move(that.messages_)}, last_{that.last_} {}
|
: allSources_{that.allSources_}, messages_{std::move(that.messages_)},
|
||||||
|
last_{that.last_} {}
|
||||||
Messages &operator=(Messages &&that) {
|
Messages &operator=(Messages &&that) {
|
||||||
swap(that);
|
swap(that);
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -77,7 +78,10 @@ public:
|
||||||
const_iterator cbegin() const { return messages_.cbegin(); }
|
const_iterator cbegin() const { return messages_.cbegin(); }
|
||||||
const_iterator cend() const { return messages_.cend(); }
|
const_iterator cend() const { return messages_.cend(); }
|
||||||
|
|
||||||
|
const AllSources &allSources() const { return allSources_; }
|
||||||
|
|
||||||
void Put(Message &&m) {
|
void Put(Message &&m) {
|
||||||
|
CHECK(m.provenance() < allSources_.size());
|
||||||
if (messages_.empty()) {
|
if (messages_.empty()) {
|
||||||
messages_.emplace_front(std::move(m));
|
messages_.emplace_front(std::move(m));
|
||||||
last_ = messages_.begin();
|
last_ = messages_.begin();
|
||||||
|
@ -97,9 +101,10 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emit(std::ostream &, const AllSources &) const;
|
void Emit(std::ostream &) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const AllSources &allSources_;
|
||||||
list_type messages_;
|
list_type messages_;
|
||||||
iterator last_; // valid iff messages_ nonempty
|
iterator last_; // valid iff messages_ nonempty
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,10 +24,11 @@ class UserState;
|
||||||
class ParseState {
|
class ParseState {
|
||||||
public:
|
public:
|
||||||
ParseState(const CookedSource &cooked)
|
ParseState(const CookedSource &cooked)
|
||||||
: cooked_{cooked}, p_{&cooked[0]}, remaining_{cooked.size()} {}
|
: cooked_{cooked}, p_{&cooked[0]},
|
||||||
|
remaining_{cooked.size()}, messages_{*cooked.allSources()} {}
|
||||||
ParseState(const ParseState &that)
|
ParseState(const ParseState &that)
|
||||||
: cooked_{that.cooked_}, p_{that.p_},
|
: cooked_{that.cooked_}, p_{that.p_}, remaining_{that.remaining_},
|
||||||
remaining_{that.remaining_}, column_{that.column_},
|
column_{that.column_}, messages_{*that.cooked_.allSources()},
|
||||||
userState_{that.userState_}, inCharLiteral_{that.inCharLiteral_},
|
userState_{that.userState_}, inCharLiteral_{that.inCharLiteral_},
|
||||||
inFortran_{that.inFortran_}, inFixedForm_{that.inFixedForm_},
|
inFortran_{that.inFortran_}, inFixedForm_{that.inFixedForm_},
|
||||||
enableOldDebugLines_{that.enableOldDebugLines_}, columns_{that.columns_},
|
enableOldDebugLines_{that.enableOldDebugLines_}, columns_{that.columns_},
|
||||||
|
@ -69,15 +70,16 @@ public:
|
||||||
std::memcpy(&that, buffer, bytes);
|
std::memcpy(&that, buffer, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CookedSource &cooked() const { return cooked_; }
|
||||||
|
int column() const { return column_; }
|
||||||
|
Messages *messages() { return &messages_; }
|
||||||
|
|
||||||
bool anyErrorRecovery() const { return anyErrorRecovery_; }
|
bool anyErrorRecovery() const { return anyErrorRecovery_; }
|
||||||
void set_anyErrorRecovery() { anyErrorRecovery_ = true; }
|
void set_anyErrorRecovery() { anyErrorRecovery_ = true; }
|
||||||
|
|
||||||
UserState *userState() const { return userState_; }
|
UserState *userState() const { return userState_; }
|
||||||
void set_userState(UserState *u) { userState_ = u; }
|
void set_userState(UserState *u) { userState_ = u; }
|
||||||
|
|
||||||
int column() const { return column_; }
|
|
||||||
Messages *messages() { return &messages_; }
|
|
||||||
|
|
||||||
MessageContext context() const { return context_; }
|
MessageContext context() const { return context_; }
|
||||||
MessageContext set_context(MessageContext c) {
|
MessageContext set_context(MessageContext c) {
|
||||||
MessageContext was{context_};
|
MessageContext was{context_};
|
||||||
|
@ -157,7 +159,6 @@ public:
|
||||||
|
|
||||||
bool tabInCurrentLine() const { return tabInCurrentLine_; }
|
bool tabInCurrentLine() const { return tabInCurrentLine_; }
|
||||||
|
|
||||||
const AllSources &GetAllSources() const { return cooked_.sources(); }
|
|
||||||
const char *GetLocation() const { return p_; }
|
const char *GetLocation() const { return p_; }
|
||||||
Provenance GetProvenance(const char *at) const {
|
Provenance GetProvenance(const char *at) const {
|
||||||
return cooked_.GetProvenance(at).start;
|
return cooked_.GetProvenance(at).start;
|
||||||
|
|
|
@ -328,12 +328,16 @@ bool Preprocessor::MacroReplacement(
|
||||||
if (def.isPredefined()) {
|
if (def.isPredefined()) {
|
||||||
std::string name{def.replacement()[0].ToString()};
|
std::string name{def.replacement()[0].ToString()};
|
||||||
if (name == "__FILE__") {
|
if (name == "__FILE__") {
|
||||||
result->Put("\""s + prescanner_.GetCurrentPath() + '"');
|
result->Put("\""s +
|
||||||
|
prescanner_.allSources().GetPath(
|
||||||
|
prescanner_.GetCurrentProvenance()) +
|
||||||
|
'"');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (name == "__LINE__") {
|
if (name == "__LINE__") {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << prescanner_.GetCurrentLineNumber();
|
ss << prescanner_.allSources().GetLineNumber(
|
||||||
|
prescanner_.GetCurrentProvenance());
|
||||||
result->Put(ss.str());
|
result->Put(ss.str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,14 @@
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
namespace parser {
|
namespace parser {
|
||||||
|
|
||||||
CookedSource Prescanner::Prescan() {
|
CookedSource Prescanner::Prescan(AllSources *allSources) {
|
||||||
startProvenance_ = 0;
|
startProvenance_ = 0;
|
||||||
start_ = &allSources_[0];
|
start_ = &(*allSources)[0];
|
||||||
limit_ = start_ + allSources_.size();
|
limit_ = start_ + allSources->size();
|
||||||
lineStart_ = start_;
|
lineStart_ = start_;
|
||||||
|
BeginSourceLine(start_);
|
||||||
TokenSequence tokens, preprocessed;
|
TokenSequence tokens, preprocessed;
|
||||||
CookedSource cooked{allSources_};
|
CookedSource cooked{allSources};
|
||||||
while (lineStart_ < limit_) {
|
while (lineStart_ < limit_) {
|
||||||
if (CommentLinesAndPreprocessorDirectives() && lineStart_ >= limit_) {
|
if (CommentLinesAndPreprocessorDirectives() && lineStart_ >= limit_) {
|
||||||
break;
|
break;
|
||||||
|
@ -67,14 +68,6 @@ std::optional<TokenSequence> Prescanner::NextTokenizedLine() {
|
||||||
return {std::move(tokens)};
|
return {std::move(tokens)};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Prescanner::GetCurrentPath() const {
|
|
||||||
return allSources_.GetPath(GetCurrentProvenance());
|
|
||||||
}
|
|
||||||
|
|
||||||
int Prescanner::GetCurrentLineNumber() const {
|
|
||||||
return allSources_.GetLineNumber(GetCurrentProvenance());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Prescanner::NextLine() {
|
void Prescanner::NextLine() {
|
||||||
void *vstart{static_cast<void *>(const_cast<char *>(lineStart_))};
|
void *vstart{static_cast<void *>(const_cast<char *>(lineStart_))};
|
||||||
void *v{std::memchr(vstart, '\n', limit_ - lineStart_)};
|
void *v{std::memchr(vstart, '\n', limit_ - lineStart_)};
|
||||||
|
|
|
@ -20,8 +20,8 @@ namespace parser {
|
||||||
|
|
||||||
class Prescanner {
|
class Prescanner {
|
||||||
public:
|
public:
|
||||||
Prescanner(Messages &messages, AllSources &allSources)
|
explicit Prescanner(Messages &messages)
|
||||||
: messages_{messages}, allSources_{allSources}, preprocessor_{*this} {}
|
: messages_{messages}, preprocessor_{*this} {}
|
||||||
|
|
||||||
Messages &messages() const { return messages_; }
|
Messages &messages() const { return messages_; }
|
||||||
bool anyFatalErrors() const { return anyFatalErrors_; }
|
bool anyFatalErrors() const { return anyFatalErrors_; }
|
||||||
|
@ -43,7 +43,9 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CookedSource Prescan();
|
const AllSources &allSources() const { return messages_.allSources(); }
|
||||||
|
|
||||||
|
CookedSource Prescan(AllSources *);
|
||||||
std::optional<TokenSequence> NextTokenizedLine();
|
std::optional<TokenSequence> NextTokenizedLine();
|
||||||
Provenance GetCurrentProvenance() const { return GetProvenance(at_); }
|
Provenance GetCurrentProvenance() const { return GetProvenance(at_); }
|
||||||
std::string GetCurrentPath() const; // __FILE__
|
std::string GetCurrentPath() const; // __FILE__
|
||||||
|
@ -96,7 +98,6 @@ private:
|
||||||
void PayNewlineDebt(CookedSource *);
|
void PayNewlineDebt(CookedSource *);
|
||||||
|
|
||||||
Messages &messages_;
|
Messages &messages_;
|
||||||
AllSources &allSources_;
|
|
||||||
|
|
||||||
Provenance startProvenance_;
|
Provenance startProvenance_;
|
||||||
const char *start_{nullptr}; // beginning of sourceFile_ content
|
const char *start_{nullptr}; // beginning of sourceFile_ content
|
||||||
|
|
|
@ -199,7 +199,7 @@ ProvenanceRange CookedSource::GetProvenance(const char *at) const {
|
||||||
|
|
||||||
void CookedSource::Marshal() {
|
void CookedSource::Marshal() {
|
||||||
CHECK(provenanceMap_.size() == buffer_.size());
|
CHECK(provenanceMap_.size() == buffer_.size());
|
||||||
provenanceMap_.Put(sources_.AddCompilerInsertion("EOF"));
|
provenanceMap_.Put(allSources_->AddCompilerInsertion("EOF"));
|
||||||
data_.resize(buffer_.size());
|
data_.resize(buffer_.size());
|
||||||
char *p{&data_[0]};
|
char *p{&data_[0]};
|
||||||
for (char ch : buffer_) {
|
for (char ch : buffer_) {
|
||||||
|
|
|
@ -109,13 +109,13 @@ private:
|
||||||
|
|
||||||
class CookedSource {
|
class CookedSource {
|
||||||
public:
|
public:
|
||||||
explicit CookedSource(AllSources &sources) : sources_{sources} {}
|
explicit CookedSource(AllSources *sources) : allSources_{sources} {}
|
||||||
|
|
||||||
size_t size() const { return data_.size(); }
|
size_t size() const { return data_.size(); }
|
||||||
const char &operator[](size_t n) const { return data_[n]; }
|
const char &operator[](size_t n) const { return data_[n]; }
|
||||||
const char &at(size_t n) const { return data_.at(n); }
|
const char &at(size_t n) const { return data_.at(n); }
|
||||||
|
|
||||||
AllSources &sources() const { return sources_; }
|
AllSources *allSources() const { return allSources_; }
|
||||||
|
|
||||||
ProvenanceRange GetProvenance(const char *) const;
|
ProvenanceRange GetProvenance(const char *) const;
|
||||||
void Identify(std::ostream &, const char *) const;
|
void Identify(std::ostream &, const char *) const;
|
||||||
|
@ -130,7 +130,7 @@ public:
|
||||||
void Marshal(); // marshalls all text into one contiguous block
|
void Marshal(); // marshalls all text into one contiguous block
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AllSources &sources_;
|
AllSources *allSources_;
|
||||||
CharBuffer buffer_; // before Marshal()
|
CharBuffer buffer_; // before Marshal()
|
||||||
std::vector<char> data_; // all of it, prescanned and preprocessed
|
std::vector<char> data_; // all of it, prescanned and preprocessed
|
||||||
OffsetToProvenanceMappings provenanceMap_;
|
OffsetToProvenanceMappings provenanceMap_;
|
||||||
|
|
|
@ -105,15 +105,15 @@ int main(int argc, char *const argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Fortran::parser::AllSources allSources{sourceFile};
|
Fortran::parser::AllSources allSources{sourceFile};
|
||||||
Fortran::parser::Messages messages;
|
Fortran::parser::Messages messages{allSources};
|
||||||
Fortran::parser::Prescanner prescanner{messages, allSources};
|
Fortran::parser::Prescanner prescanner{messages};
|
||||||
Fortran::parser::CookedSource cooked{
|
Fortran::parser::CookedSource cooked{
|
||||||
prescanner.set_fixedForm(fixedForm)
|
prescanner.set_fixedForm(fixedForm)
|
||||||
.set_enableBackslashEscapesInCharLiterals(backslashEscapes)
|
.set_enableBackslashEscapesInCharLiterals(backslashEscapes)
|
||||||
.set_fixedFormColumnLimit(columns)
|
.set_fixedFormColumnLimit(columns)
|
||||||
.set_enableOldDebugLines(enableOldDebugLines)
|
.set_enableOldDebugLines(enableOldDebugLines)
|
||||||
.Prescan()};
|
.Prescan(&allSources)};
|
||||||
messages.Emit(std::cerr, allSources);
|
messages.Emit(std::cerr);
|
||||||
if (prescanner.anyFatalErrors()) {
|
if (prescanner.anyFatalErrors()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ int main(int argc, char *const argv[]) {
|
||||||
std::cerr << "final position: ";
|
std::cerr << "final position: ";
|
||||||
allSources.Identify(std::cerr, state.GetProvenance(), " ");
|
allSources.Identify(std::cerr, state.GetProvenance(), " ");
|
||||||
}
|
}
|
||||||
state.messages()->Emit(std::cerr, allSources);
|
state.messages()->Emit(std::cerr);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue