mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
630fee4500
This commit adds the static methods:
- model::Qualifier::isConst
- model::Qualifier::isArray
- model::Qualifier::isPointer
These methods replace the old, non-static, methods:
- model::Qualifier::isConst
- model::Qualifier::isArray
- model::Qualifier::isPointer
Having these method static is very helpful for filtering, when
iterating on sequences of qualifiers, such as:
for (const auto &Q :
llvm::make_filter_range(Qualifiers, Qualifier::isPointer)) {
// do stuff with Q
}
This will be very helpful for defining other helper functions for
model::QualifiedType.
This commit also drops the non-static version of the methods, since they
are redundant, and because they would cause ambiguity and failure of
type inference in the snippet above, making them effectively useless for
the goal they were designed for, which is filtering ranges.
75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
#pragma once
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "revng/Model/Architecture.h"
|
|
#include "revng/Model/QualifierKind.h"
|
|
#include "revng/Model/VerifyHelper.h"
|
|
|
|
/* TUPLE-TREE-YAML
|
|
name: Qualifier
|
|
doc: A qualifier for a model::Type
|
|
type: struct
|
|
fields:
|
|
- name: Kind
|
|
type: QualifierKind::Values
|
|
- name: Size
|
|
doc: Size in bytes for Pointer, number of elements for Array, 0 otherwise
|
|
type: uint64_t
|
|
optional: true
|
|
TUPLE-TREE-YAML */
|
|
|
|
#include "revng/Model/Generated/Early/Qualifier.h"
|
|
|
|
class model::Qualifier : public model::generated::Qualifier {
|
|
public:
|
|
using generated::Qualifier::Qualifier;
|
|
|
|
public:
|
|
// Kind is not Invalid, Pointer and Const have no Size, Array has Size.
|
|
bool verify() const debug_function;
|
|
bool verify(bool Assert) const debug_function;
|
|
bool verify(VerifyHelper &VH) const;
|
|
void dump() const debug_function;
|
|
|
|
public:
|
|
static Qualifier createConst() { return Qualifier(QualifierKind::Const, 0); }
|
|
|
|
static Qualifier createPointer(uint64_t Size) {
|
|
return Qualifier(QualifierKind::Pointer, Size);
|
|
}
|
|
|
|
static Qualifier createPointer(model::Architecture::Values Architecture) {
|
|
return createPointer(getPointerSize(Architecture));
|
|
}
|
|
|
|
static Qualifier createArray(uint64_t S) {
|
|
return Qualifier(QualifierKind::Array, S);
|
|
}
|
|
|
|
public:
|
|
static bool isConst(const Qualifier &Q) {
|
|
revng_assert(Q.verify(true));
|
|
return Q.Kind == QualifierKind::Const;
|
|
}
|
|
|
|
static bool isArray(const Qualifier &Q) {
|
|
revng_assert(Q.verify(true));
|
|
return Q.Kind == QualifierKind::Array;
|
|
}
|
|
|
|
static bool isPointer(const Qualifier &Q) {
|
|
revng_assert(Q.verify(true));
|
|
return Q.Kind == QualifierKind::Pointer;
|
|
}
|
|
|
|
public:
|
|
auto operator<(const Qualifier &Other) const {
|
|
return this->Kind < Other.Kind && this->Size < Other.Size;
|
|
}
|
|
};
|
|
|
|
#include "revng/Model/Generated/Late/Qualifier.h"
|