1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#pragma once
namespace storm {
namespace syntax {
namespace glr {
STORM_PKG(lang.bnf.glr);
/**
* Store parent requirements for a parser state efficiently as a bitset.
*
* We expect there to be a fairly small number of requirements in the grammar, so we
* give productions used as requirements their own identifiers in this remark to keep
* the representation compact. This class stores a set of these identifiers and has
* support for operations on them.
*
* We also expect that most operations done by the parser do not modify these sets, and
* therefore the representation is immutable so that we can easily share the backing
* storage of the representation without creating copies and thereby adding pressure on
* the GC.
*/
class ParentReq {
STORM_VALUE;
public:
// Create an empty requirement set (no allocations required).
ParentReq();
// Create a requirement set with one element set.
ParentReq(Engine &e, Nat elem);
// Empty?
Bool STORM_FN empty() const { return data == null; }
Bool STORM_FN any() const { return data != null; }
// Count the number of set bits.
Nat STORM_FN count() const;
// Maximum possible set bit. May be larger than the actual maximum.
Nat STORM_FN max() const;
// Get a particular bit.
Bool STORM_FN get(Nat id) const;
// Create the union of two requirements.
ParentReq concat(Engine &e, ParentReq other) const;
// Remove elements from another ParentReq.
ParentReq remove(Engine &e, ParentReq other) const;
// Does this one contain all elements in 'other'?
Bool has(ParentReq other) const;
// Compare.
Bool STORM_FN operator ==(const ParentReq &o) const;
// Output.
void STORM_FN toS(StrBuf *to) const;
private:
// Create, explicitly specifying the data.
ParentReq(GcArray<Nat> *data);
// The actual data. Large enough to store all elements, but not larger than that. If
// no bits are set, this is null.
GcArray<Nat> *data;
};
wostream &operator <<(wostream &to, const ParentReq &r);
}
}
}
|