llvm/flang/lib/parser/user-state.h
peter klausler 0ba1a14be2 [flang] Impose a directory structure. Move files around. Introduce
an intermediate "parser" namespace.

Original-commit: flang-compiler/f18@690b6f0d1e
Reviewed-on: https://github.com/flang-compiler/f18/pull/4
Tree-same-pre-rewrite: false
2018-02-07 12:04:42 -08:00

41 lines
1.1 KiB
C++

#ifndef FORTRAN_USER_STATE_H_
#define FORTRAN_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 <cinttypes>
#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_;
}
}
private:
std::unordered_set<Label> doLabels_;
int nonlabelDoConstructNestingDepth_{0};
};
} // namespace parser
} // namespace Fortran
#endif // FORTRAN_USER_STATE_H_