llvm/flang/lib/parser/user-state.h
peter klausler 424ec7b35b [flang] Handle empty files gracefully.
Create interval.h.  Use std::size_t instead of bare size_t.  Redefine parser::Name to not be just a bare string.

Break out and rename CharBlock from token-sequence.h for use in the parse tree.

Incremental replacement of name strings with pointers to cooked characters.

Fix case sensitivity problem.

Use new CharBlock encoding to replace strings for real literal constants.

Normalized cooked character stream to lower case.

Simplify parsing now that cooked stream is lower case.  Replace Keyword in parse tree.

Add static_asserts to || and recovery parsers to enforce same result types.

Remove needless TODO comment inserted earlier.

Fix case conversion on prefixed character literals (f90_correct/dc04.f90).

Use CharBlock in user-state.h.

Complete transition from nextChar to nextCh (i.e., always use pointers).

Document extensions.  Begin work on compiler directive lines.

More documentation work.

Reformat prescan.cc.

More work on compiler directive scanning.

Original-commit: flang-compiler/f18@38d0404e16
Reviewed-on: https://github.com/flang-compiler/f18/pull/29
Tree-same-pre-rewrite: false
2018-03-23 13:32:55 -07:00

53 lines
1.5 KiB
C++

#ifndef FORTRAN_PARSER_USER_STATE_H_
#define FORTRAN_PARSER_USER_STATE_H_
// Instances of ParseState (parse-state.h) incorporate instances of this
// UserState class, which encapsulates any semantic information necessary for
// parse tree construction so as to avoid any need for representing
// state in static data.
#include "char-block.h"
#include <cinttypes>
#include <set>
#include <unordered_set>
namespace Fortran {
namespace parser {
class UserState {
public:
using Label = std::uint64_t;
bool IsDoLabel(Label label) const {
return doLabels_.find(label) != doLabels_.end();
}
bool InNonlabelDoConstruct() const {
return nonlabelDoConstructNestingDepth_ > 0;
}
void NewDoLabel(Label label) { doLabels_.insert(label); }
void NewSubprogram() {
doLabels_.clear();
nonlabelDoConstructNestingDepth_ = 0;
}
void EnterNonlabelDoConstruct() { ++nonlabelDoConstructNestingDepth_; }
void LeaveDoConstruct() {
if (nonlabelDoConstructNestingDepth_ > 0) {
--nonlabelDoConstructNestingDepth_;
}
}
void NoteDefinedOperator(const CharBlock &opr) {
definedOperators_.insert(opr);
}
bool IsDefinedOperator(const CharBlock &opr) const {
return definedOperators_.find(opr) != definedOperators_.end();
}
private:
std::unordered_set<Label> doLabels_;
int nonlabelDoConstructNestingDepth_{0};
std::set<CharBlock> definedOperators_;
};
} // namespace parser
} // namespace Fortran
#endif // FORTRAN_PARSER_USER_STATE_H_