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);
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 const auto& type()
const {
return child<Type>(1).as<Type>(); }
56 const auto& ftype()
const {
return child<Type>(1).as<type::Function>(); }
57 auto body()
const {
return childs()[2].tryAs<Statement>(); }
58 auto attributes()
const {
return childs()[3].tryAs<
AttributeSet>(); }
59 auto callingConvention()
const {
return _cc; }
60 bool isStatic()
const {
return AttributeSet::find(attributes(),
"&static").has_value(); }
62 bool operator==(
const Function& other)
const {
63 return id() == other.id() && type() == other.type() && body() == other.body() &&
64 attributes() == other.attributes() && callingConvention() == other.callingConvention();
67 void setBody(Statement b) { childs()[2] = std::move(b); }
68 void setID(
ID id) { childs()[0] = std::move(
id); }
69 void setResultType(
Type t) { childs()[1].as<
type::Function>().setResultType(std::move(t)); }
78 function::CallingConvention _cc = function::CallingConvention::Standard;
Definition: function.h:71
const Node none
Definition: node.cc:14
Definition: function.h:44
Definition: attribute.h:145
Node & _typeNode()
Definition: function.h:72
hilti::optional_ref< const Attribute > find(std::string_view tag) const
Definition: attribute.h:171
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
Definition: node-ref.h:44
auto properties() const
Definition: function.h:75