[flang] Debugging new provenance support.

Original-commit: flang-compiler/f18@1233f666da
Reviewed-on: https://github.com/flang-compiler/f18/pull/9
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2018-02-09 15:56:02 -08:00 committed by GitHub
parent 09865ffe7b
commit 90c3cad9a7
6 changed files with 17 additions and 5 deletions

View File

@ -8,7 +8,7 @@ void Message::Emit(std::ostream &o, const AllSources &sources) const {
context_->Emit(o, sources);
}
sources.Identify(o, provenance_, "");
o << ": " << message_ << '\n';
o << " " << message_ << '\n';
}
void Messages::Emit(std::ostream &o, const AllSources &sources) const {

View File

@ -28,6 +28,7 @@ void TokenSequence::clear() {
start_.clear();
nextStart_ = 0;
char_.clear();
provenances_.clear();
}
void TokenSequence::pop_back() {

View File

@ -89,7 +89,8 @@ public:
}
TokenSequence(TokenSequence &&that)
: start_{std::move(that.start_)},
nextStart_{that.nextStart_}, char_{std::move(that.char_)} {}
nextStart_{that.nextStart_}, char_{std::move(that.char_)},
provenances_{std::move(that.provenances_)} {}
TokenSequence(const std::string &s) { Put(s, 0); } // TODO predefined prov.
TokenSequence &operator=(const TokenSequence &that) {
@ -121,7 +122,6 @@ public:
}
void CloseToken() {
// CHECK(char_.size() > nextStart_);
start_.emplace_back(nextStart_);
nextStart_ = char_.size();
}

View File

@ -4,6 +4,11 @@
namespace Fortran {
namespace parser {
void OffsetToProvenanceMappings::clear() {
bytes_ = 0;
provenanceMap_.clear();
}
void OffsetToProvenanceMappings::Put(ProvenanceRange range) {
if (provenanceMap_.empty()) {
provenanceMap_.push_back({bytes_, range});
@ -96,7 +101,7 @@ void AllSources::Identify(
std::pair<int, int> pos{
inc.source.FindOffsetLineAndColumn(at - origin.start)};
o << prefix << "at line " << pos.first << ", column "
<< pos.second << "in the file " << inc.source.path() << '\n';
<< pos.second << " in the file " << inc.source.path() << '\n';
if (origin.replaces.bytes > 0) {
o << prefix << " that was included\n";
Identify(o, origin.replaces.start, indented);
@ -192,6 +197,8 @@ ProvenanceRange CookedSource::GetProvenance(const char *at) const {
}
void CookedSource::Marshal() {
CHECK(provenanceMap_.size() == buffer_.size());
provenanceMap_.Put(sources_.AddCompilerInsertion("EOF"));
data_.resize(buffer_.size());
char *p{&data_[0]};
for (char ch : buffer_) {

View File

@ -40,6 +40,7 @@ class OffsetToProvenanceMappings {
public:
OffsetToProvenanceMappings() {}
size_t size() const { return bytes_; }
void clear();
void shrink_to_fit() { provenanceMap_.shrink_to_fit(); }
void Put(ProvenanceRange);
void Put(const OffsetToProvenanceMappings &);

View File

@ -153,7 +153,10 @@ int main(int argc, char *const argv[]) {
std::cout << "demo PASS\n" << *result << '\n';
} else {
std::cerr << "demo FAIL\n";
allSources.Identify(std::cerr, state.GetProvenance(), " ");
if (!state.IsAtEnd()) {
std::cerr << "final position: ";
allSources.Identify(std::cerr, state.GetProvenance(), " ");
}
state.messages()->Emit(std::cerr, allSources);
return EXIT_FAILURE;
}