2020-02-25 23:11:52 +08:00
|
|
|
//===-- lib/Parser/instrumented-parser.cpp --------------------------------===//
|
2018-05-02 03:50:34 +08:00
|
|
|
//
|
2019-12-21 04:52:07 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-05-02 03:50:34 +08:00
|
|
|
//
|
2020-01-11 04:12:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-05-02 03:50:34 +08:00
|
|
|
|
2020-02-25 23:11:52 +08:00
|
|
|
#include "flang/Parser/instrumented-parser.h"
|
|
|
|
#include "flang/Parser/message.h"
|
|
|
|
#include "flang/Parser/provenance.h"
|
2020-02-28 23:11:03 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2018-04-20 04:03:23 +08:00
|
|
|
#include <map>
|
|
|
|
|
2018-05-03 04:48:12 +08:00
|
|
|
namespace Fortran::parser {
|
2018-04-20 04:03:23 +08:00
|
|
|
|
2018-04-20 08:02:12 +08:00
|
|
|
void ParsingLog::clear() { perPos_.clear(); }
|
|
|
|
|
2018-04-20 04:03:23 +08:00
|
|
|
// In the logs, just use the addresses of the message texts to sort the
|
|
|
|
// map keys.
|
|
|
|
bool operator<(const MessageFixedText &x, const MessageFixedText &y) {
|
2018-05-05 04:00:35 +08:00
|
|
|
return x.text().begin() < y.text().begin();
|
2018-04-20 04:03:23 +08:00
|
|
|
}
|
|
|
|
|
2018-04-20 06:46:02 +08:00
|
|
|
bool ParsingLog::Fails(
|
2018-04-20 08:02:12 +08:00
|
|
|
const char *at, const MessageFixedText &tag, ParseState &state) {
|
2018-07-11 08:09:07 +08:00
|
|
|
std::size_t offset{reinterpret_cast<std::size_t>(at)};
|
|
|
|
auto posIter{perPos_.find(offset)};
|
2018-04-20 06:46:02 +08:00
|
|
|
if (posIter == perPos_.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-11 08:09:07 +08:00
|
|
|
auto tagIter{posIter->second.perTag.find(tag)};
|
2018-04-20 06:46:02 +08:00
|
|
|
if (tagIter == posIter->second.perTag.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-11 08:09:07 +08:00
|
|
|
auto &entry{tagIter->second};
|
2018-04-20 08:02:12 +08:00
|
|
|
if (entry.deferred && !state.deferMessages()) {
|
2020-03-29 12:00:16 +08:00
|
|
|
return false; // don't fail fast, we want to generate messages
|
2018-04-20 08:02:12 +08:00
|
|
|
}
|
2018-04-20 06:46:02 +08:00
|
|
|
++entry.count;
|
2018-04-20 08:02:12 +08:00
|
|
|
if (!state.deferMessages()) {
|
|
|
|
state.messages().Copy(entry.messages);
|
|
|
|
}
|
2018-04-20 06:46:02 +08:00
|
|
|
return !entry.pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParsingLog::Note(const char *at, const MessageFixedText &tag, bool pass,
|
2018-04-20 08:02:12 +08:00
|
|
|
const ParseState &state) {
|
2018-07-11 08:09:07 +08:00
|
|
|
std::size_t offset{reinterpret_cast<std::size_t>(at)};
|
|
|
|
auto &entry{perPos_[offset].perTag[tag]};
|
2018-04-20 06:46:02 +08:00
|
|
|
if (++entry.count == 1) {
|
|
|
|
entry.pass = pass;
|
2018-04-20 08:02:12 +08:00
|
|
|
entry.deferred = state.deferMessages();
|
|
|
|
if (!entry.deferred) {
|
|
|
|
entry.messages.Copy(state.messages());
|
|
|
|
}
|
2018-04-20 04:03:23 +08:00
|
|
|
} else {
|
2018-04-20 06:46:02 +08:00
|
|
|
CHECK(entry.pass == pass);
|
2018-04-20 08:02:12 +08:00
|
|
|
if (entry.deferred && !state.deferMessages()) {
|
|
|
|
entry.deferred = false;
|
|
|
|
entry.messages.Copy(state.messages());
|
|
|
|
}
|
2018-04-20 04:03:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 23:11:03 +08:00
|
|
|
void ParsingLog::Dump(llvm::raw_ostream &o, const CookedSource &cooked) const {
|
2018-04-20 04:03:23 +08:00
|
|
|
for (const auto &posLog : perPos_) {
|
2018-04-20 06:46:02 +08:00
|
|
|
const char *at{reinterpret_cast<const char *>(posLog.first)};
|
2018-04-20 04:03:23 +08:00
|
|
|
for (const auto &tagLog : posLog.second.perTag) {
|
2018-04-20 06:46:02 +08:00
|
|
|
Message{at, tagLog.first}.Emit(o, cooked, true);
|
2018-07-11 08:09:07 +08:00
|
|
|
auto &entry{tagLog.second};
|
2018-04-20 08:02:12 +08:00
|
|
|
o << " " << (entry.pass ? "pass" : "fail") << " " << entry.count << '\n';
|
2019-10-03 03:40:52 +08:00
|
|
|
entry.messages.Emit(o, cooked);
|
2018-04-20 04:03:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::parser
|