[flang] Debugging and a TODO.

Original-commit: flang-compiler/f18@4fab40bc37
Reviewed-on: https://github.com/flang-compiler/f18/pull/38
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler
2018-04-02 16:33:10 -07:00
parent 1e1ea723c5
commit 10907c73db
6 changed files with 48 additions and 29 deletions

View File

@@ -1187,13 +1187,11 @@ constexpr struct NextCh {
using resultType = const char *;
constexpr NextCh() {}
std::optional<const char *> Parse(ParseState *state) const {
if (state->IsAtEnd()) {
state->Say("end of file"_err_en_US);
return {};
if (std::optional<const char *> result{state->GetNextChar()}) {
return std::move(result);
}
const char *at{state->GetLocation()};
state->UncheckedAdvance();
return {at};
state->Say("end of file"_err_en_US);
return {};
}
} nextCh;

View File

@@ -747,11 +747,11 @@ constexpr auto exponentPart =
TYPE_CONTEXT_PARSER("REAL literal constant"_en_US,
construct<RealLiteralConstant>{}(
sourced(
(digitString >> "."_ch >>
(skipDigitString >> "."_ch >>
!(some(letter) >> "."_ch /* don't misinterpret 1.AND. */) >>
maybe(digitString) >> maybe(exponentPart) >> ok ||
"."_ch >> digitString >> maybe(exponentPart) >> ok ||
digitString >> exponentPart >> ok) >>
maybe(skipDigitString) >> maybe(exponentPart) >> ok ||
"."_ch >> skipDigitString >> maybe(exponentPart) >> ok ||
skipDigitString >> exponentPart >> ok) >>
construct<RealLiteralConstant::Real>{}),
maybe(underscore >> kindParam)))

View File

@@ -89,6 +89,7 @@ public:
Message &operator=(const Message &that) = default;
Message &operator=(Message &&that) = default;
// TODO: Change these to cover ranges of provenance
Message(Provenance p, MessageFixedText t, MessageContext c = nullptr)
: provenance_{p}, text_{t}, context_{c}, isFatal_{t.isFatal()} {}
Message(Provenance p, MessageFormattedText &&s, MessageContext c = nullptr)

View File

@@ -134,24 +134,24 @@ public:
bool IsAtEnd() const { return p_ >= limit_; }
char UncheckedAdvance(std::size_t n = 1) {
char result{*p_};
const char *UncheckedAdvance(std::size_t n = 1) {
const char *result{p_};
p_ += n;
return result;
}
std::optional<char> GetNextChar() {
std::optional<const char *> GetNextChar() {
if (p_ >= limit_) {
return {};
}
return {UncheckedAdvance()};
}
std::optional<char> PeekAtNextChar() {
std::optional<const char *> PeekAtNextChar() {
if (p_ >= limit_) {
return {};
}
return {*p_};
return {p_};
}
private:

View File

@@ -57,8 +57,8 @@ void Parsing::DumpCookedChars(std::ostream &out) const {
UserState userState;
ParseState parseState{cooked_};
parseState.set_inFixedForm(options_.isFixedForm).set_userState(&userState);
while (std::optional<char> ch{parseState.GetNextChar()}) {
out << *ch;
while (std::optional<const char *> p{parseState.GetNextChar()}) {
out << **p;
}
}

View File

@@ -85,8 +85,8 @@ constexpr struct Space {
using resultType = Success;
constexpr Space() {}
static std::optional<Success> Parse(ParseState *state) {
while (std::optional<char> ch{state->PeekAtNextChar()}) {
if (*ch != ' ') {
while (std::optional<const char *> p{state->PeekAtNextChar()}) {
if (**p != ' ') {
break;
}
state->UncheckedAdvance();
@@ -110,12 +110,13 @@ constexpr struct SpaceCheck {
using resultType = Success;
constexpr SpaceCheck() {}
static std::optional<Success> Parse(ParseState *state) {
if (std::optional<char> ch{state->PeekAtNextChar()}) {
if (*ch == ' ') {
if (std::optional<const char *> p{state->PeekAtNextChar()}) {
char ch{**p};
if (ch == ' ') {
state->UncheckedAdvance();
return space.Parse(state);
}
if (IsLegalInIdentifier(*ch)) {
if (IsLegalInIdentifier(ch)) {
MissingSpace(state);
}
}
@@ -263,7 +264,7 @@ struct CharLiteralChar {
ch -= '0';
for (int j = (ch > 3 ? 1 : 2); j-- > 0;) {
static constexpr auto octalDigit =
CharPredicateGuard{IsOctalDigit, "expected octal digit"_err_en_US};
CharPredicateGuard{IsOctalDigit, "expected octal digit"_en_US};
och = octalDigit.Parse(state);
if (och.has_value()) {
ch = 8 * ch + **och - '0';
@@ -275,7 +276,7 @@ struct CharLiteralChar {
ch = 0;
for (int j = 0; j++ < 2;) {
static constexpr auto hexDigit = CharPredicateGuard{
IsHexadecimalDigit, "expected hexadecimal digit"_err_en_US};
IsHexadecimalDigit, "expected hexadecimal digit"_en_US};
och = hexDigit.Parse(state);
if (och.has_value()) {
ch = 16 * ch + HexadecimalDigitValue(**och);
@@ -284,7 +285,7 @@ struct CharLiteralChar {
}
}
} else {
state->Say(at, "bad escaped character"_err_en_US);
state->Say(at, "bad escaped character"_en_US);
}
return {Result::Escaped(ch)};
}
@@ -438,6 +439,25 @@ struct DigitString {
}
};
constexpr struct SkipDigitString {
using resultType = Success;
static std::optional<Success> Parse(ParseState *state) {
if (std::optional<const char *> ch1{state->PeekAtNextChar()}) {
if (IsDecimalDigit(**ch1)) {
state->UncheckedAdvance();
while (std::optional<const char *> p{state->PeekAtNextChar()}) {
if (!IsDecimalDigit(**p)) {
break;
}
state->UncheckedAdvance();
}
return {Success{}};
}
}
return {};
}
} skipDigitString;
// Legacy feature: Hollerith literal constants
struct HollerithLiteral {
using resultType = std::string;
@@ -508,8 +528,8 @@ template<char goal> struct SkipPast {
constexpr SkipPast() {}
constexpr SkipPast(const SkipPast &) {}
static std::optional<Success> Parse(ParseState *state) {
while (std::optional<char> ch{state->GetNextChar()}) {
if (*ch == goal) {
while (std::optional<const char *> p{state->GetNextChar()}) {
if (**p == goal) {
return {Success{}};
}
}
@@ -522,8 +542,8 @@ template<char goal> struct SkipTo {
constexpr SkipTo() {}
constexpr SkipTo(const SkipTo &) {}
static std::optional<Success> Parse(ParseState *state) {
while (std::optional<char> ch{state->PeekAtNextChar()}) {
if (*ch == goal) {
while (std::optional<const char *> p{state->PeekAtNextChar()}) {
if (**p == goal) {
return {Success{}};
}
state->UncheckedAdvance();