[flang] Split debug-parser.h, put code into debug-parser.cc.

Original-commit: flang-compiler/f18@b34d15ef6d
Reviewed-on: https://github.com/flang-compiler/f18/pull/66
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2018-04-20 15:56:19 -07:00
parent d2306759fc
commit cc589b2e8e
3 changed files with 25 additions and 14 deletions

View File

@ -2,6 +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
idioms.cc
instrumented-parser.cc
message.cc

View File

@ -0,0 +1,21 @@
#include "debug-parser.h"
#include <iostream>
#include <string>
namespace Fortran {
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);
}
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{}};
}
} // namespace parser
} // namespace Fortran

View File

@ -4,13 +4,13 @@
// 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"
#include <cstddef>
#include <iostream>
#include <optional>
#include <string>
namespace Fortran {
namespace parser {
@ -21,18 +21,7 @@ public:
constexpr DebugParser(const DebugParser &) = default;
constexpr DebugParser(const char *str, std::size_t n)
: str_{str}, length_{n} {}
std::optional<Success> Parse(ParseState &state) const {
if (auto ustate = state.userState()) {
const CookedSource &cooked{ustate->cooked()};
if (auto context = state.context()) {
context->Emit(std::cout, cooked);
}
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{}};
}
std::optional<Success> Parse(ParseState &) const;
private:
const char *const str_;