8 #include <hilti/ast/attribute.h> 9 #include <hilti/ast/node.h> 10 #include <hilti/ast/statement.h> 11 #include <hilti/ast/type.h> 12 #include <hilti/ast/types/function.h> 19 enum class CallingConvention {
26 constexpr util::enum_::Value<CallingConvention> conventions[] = {
27 {CallingConvention::Extern,
"extern"},
28 {CallingConvention::ExternNoSuspend,
"extern-no-suspend"},
29 {CallingConvention::Standard,
"<standard>"},
33 constexpr
auto to_string(CallingConvention cc) {
return util::enum_::to_string(cc, detail::conventions); }
35 namespace calling_convention {
36 constexpr
inline auto from_string(
const std::string_view& s) {
37 return util::enum_::from_string<CallingConvention>(s, detail::conventions);
46 Function(
ID id, Type type, std::optional<Statement> body,
47 function::CallingConvention cc = function::CallingConvention::Standard,
48 std::optional<AttributeSet> attrs = {},
Meta m =
Meta())
49 :
NodeBase(nodes(std::move(
id), std::move(type), std::move(body), std::move(attrs)), std::move(m)), _cc(cc) {}
53 const auto& id()
const {
return child<ID>(0); }
54 auto type()
const {
return type::effectiveType(child<Type>(1)).as<
type::Function>(); }
55 auto body()
const {
return childs()[2].tryReferenceAs<Statement>(); }
56 auto attributes()
const {
return childs()[3].tryReferenceAs<
AttributeSet>(); }
57 auto callingConvention()
const {
return _cc; }
58 bool isStatic()
const {
return AttributeSet::find(attributes(),
"&static").has_value(); }
60 bool operator==(
const Function& other)
const {
61 return id() == other.id() && type() == other.type() && body() == other.body() &&
62 attributes() == other.attributes() && callingConvention() == other.callingConvention();
82 function::CallingConvention _cc = function::CallingConvention::Standard;
Definition: function.h:69
static Function setBody(const Function &d, const Statement &b)
Definition: function.h:75
const Node none
Definition: node.cc:12
Definition: function.h:44
Definition: attribute.h:159
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
std::optional< Attribute > find(std::string_view tag) const
Definition: attribute.h:190
auto properties() const
Definition: function.h:66