[flang] Finish cleaning up debug-parser.
Original-commit: flang-compiler/f18@0ef551025a Reviewed-on: https://github.com/flang-compiler/f18/pull/66 Tree-same-pre-rewrite: false
This commit is contained in:
parent
cc589b2e8e
commit
30f337a36d
|
@ -2,7 +2,7 @@ add_library(FortranParser
|
|||
char-buffer.cc
|
||||
char-set.cc
|
||||
characters.cc
|
||||
# debug-parser.cc # not to be used in production, it uses std::cout
|
||||
debug-parser.cc
|
||||
idioms.cc
|
||||
instrumented-parser.cc
|
||||
message.cc
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "debug-parser.h"
|
||||
#include <iostream>
|
||||
#include "user-state.h"
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace Fortran {
|
||||
|
@ -7,13 +8,15 @@ namespace parser {
|
|||
|
||||
std::optional<Success> DebugParser::Parse(ParseState &state) const {
|
||||
if (auto ustate = state.userState()) {
|
||||
const CookedSource &cooked{ustate->cooked()};
|
||||
if (auto context = state.context()) {
|
||||
context->Emit(std::cout, cooked);
|
||||
if (auto out = ustate->debugOutput()) {
|
||||
const CookedSource &cooked{ustate->cooked()};
|
||||
if (auto context = state.context()) {
|
||||
context->Emit(*out, cooked);
|
||||
}
|
||||
Provenance p{cooked.GetProvenance(state.GetLocation()).start()};
|
||||
cooked.allSources().Identify(*out, p, "", true);
|
||||
*out << " parser debug: " << std::string{str_, length_} << "\n\n";
|
||||
}
|
||||
Provenance p{cooked.GetProvenance(state.GetLocation()).start()};
|
||||
cooked.allSources().Identify(std::cout, p, "", true);
|
||||
std::cout << " parser debug: " << std::string{str_, length_} << "\n\n";
|
||||
}
|
||||
return {Success{}};
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
// Implements the parser with syntax "(YOUR MESSAGE HERE)"_debug for use
|
||||
// in temporary modifications to the grammar intended for tracing the
|
||||
// flow of the parsers. Not to be used in production.
|
||||
// When this feature is in use for temporary debugging, be sure to
|
||||
// compile and link debug-parser.cc.
|
||||
|
||||
#include "basic-parsers.h"
|
||||
#include "parse-state.h"
|
||||
|
|
|
@ -78,9 +78,11 @@ void Parsing::DumpParsingLog(std::ostream &out) const {
|
|||
log_.Dump(out, cooked_);
|
||||
}
|
||||
|
||||
void Parsing::Parse() {
|
||||
void Parsing::Parse(std::ostream *out) {
|
||||
UserState userState{cooked_};
|
||||
userState.set_instrumentedParse(options_.instrumentedParse).set_log(&log_);
|
||||
userState.set_debugOutput(out)
|
||||
.set_instrumentedParse(options_.instrumentedParse)
|
||||
.set_log(&log_);
|
||||
ParseState parseState{cooked_};
|
||||
parseState.set_inFixedForm(options_.isFixedForm)
|
||||
.set_encoding(options_.encoding)
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
void DumpCookedChars(std::ostream &) const;
|
||||
void DumpProvenance(std::ostream &) const;
|
||||
void DumpParsingLog(std::ostream &) const;
|
||||
void Parse();
|
||||
void Parse(std::ostream *debugOutput = nullptr);
|
||||
void ClearLog();
|
||||
|
||||
void Identify(std::ostream &o, const char *at, const std::string &prefix,
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "parse-tree.h"
|
||||
#include <cinttypes>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
|
||||
|
@ -27,6 +28,12 @@ public:
|
|||
|
||||
const CookedSource &cooked() const { return cooked_; }
|
||||
|
||||
std::ostream *debugOutput() const { return debugOutput_; }
|
||||
UserState &set_debugOutput(std::ostream *out) {
|
||||
debugOutput_ = out;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ParsingLog *log() const { return log_; }
|
||||
UserState &set_log(ParsingLog *log) {
|
||||
log_ = log;
|
||||
|
@ -71,6 +78,8 @@ public:
|
|||
private:
|
||||
const CookedSource &cooked_;
|
||||
|
||||
std::ostream *debugOutput_{nullptr};
|
||||
|
||||
ParsingLog *log_{nullptr};
|
||||
bool instrumentedParse_{false};
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ std::string CompileFortran(
|
|||
parsing.DumpCookedChars(std::cout);
|
||||
return {};
|
||||
}
|
||||
parsing.Parse();
|
||||
parsing.Parse(&std::cout);
|
||||
if (options.instrumentedParse) {
|
||||
parsing.DumpParsingLog(std::cout);
|
||||
return {};
|
||||
|
|
Loading…
Reference in New Issue