8 #include <hilti/ast/expressions/coerced.h> 9 #include <hilti/ast/expressions/member.h> 10 #include <hilti/ast/operators/common.h> 11 #include <hilti/ast/types/any.h> 12 #include <hilti/ast/types/integer.h> 13 #include <hilti/ast/types/unknown.h> 15 #include <spicy/ast/types/bitfield.h> 20 namespace bitfield::detail {
31 static inline void checkName(
const Expression& op0,
const Expression& op1, Node& n) {
32 auto id = memberExpression(op1).id().local();
34 if (
const auto& f = op0.type().as<type::Bitfield>().bits(
id); ! f )
35 n.addError(
hilti::util::fmt(
"bitfield type does not have attribute '%s'",
id));
38 static inline Type itemType(
const Expression& op0,
const Expression& op1) {
39 if (
auto st = op0.type().tryAs<type::Bitfield>() ) {
40 if (
const auto& f = st->bits(memberExpression(op1).
id().local()) )
49 BEGIN_OPERATOR_CUSTOM(bitfield, Member)
52 return type::DocOnly(
"<field type>");
54 return detail::itemType(ops[0], ops[1]);
57 bool isLhs()
const {
return false; }
59 std::vector<hilti::operator_::Operand> operands()
const {
60 return {{.type = type::constant(type::Bitfield(type::Wildcard())), .doc =
"bitfield"},
61 {.type = type::Member(type::Wildcard()), .doc =
"<attribute>"}};
65 detail::checkName(i.op0(), i.op1(), p.
node);
68 std::string doc()
const {
70 Retrieves the value of a bitfield's attribute. This is the value of the 71 corresponding bits inside the underlying integer value, shifted to the very
Definition: visitor-types.h:28
E node
Definition: visitor-types.h:33
std::string fmt(const char *fmt, const Args &... args)
Definition: util.h:80