10 #include <hilti/ast/attribute.h> 11 #include <hilti/ast/expression.h> 12 #include <hilti/ast/function.h> 13 #include <hilti/ast/id.h> 14 #include <hilti/ast/type.h> 15 #include <hilti/ast/types/function.h> 16 #include <hilti/ast/types/unknown.h> 26 Field(
ID id, Type t, std::optional<AttributeSet> attrs = {},
Meta m =
Meta())
27 :
NodeBase(nodes(std::move(
id), std::move(t), node::none, std::move(attrs), node::none), std::move(m)) {}
28 Field(
ID id, Type t, Type aux_type, std::optional<AttributeSet> attrs,
Meta m =
Meta())
29 :
NodeBase(nodes(std::move(
id), std::move(t), std::move(aux_type), std::move(attrs), node::none),
31 Field(
ID id, ::hilti::function::CallingConvention cc,
type::Function ft, std::optional<AttributeSet> attrs = {},
33 :
NodeBase(nodes(std::move(
id), std::move(ft), node::none, std::move(attrs), node::none), std::move(m)),
36 :
NodeBase(nodes(std::move(
id), node::none, node::none, std::move(attrs), std::move(inline_func)),
38 _cc(inline_func.callingConvention()) {}
40 const auto& id()
const {
return child<ID>(0); }
42 auto callingConvention()
const {
return _cc; }
47 if ( ! _cache.type ) {
48 if (
auto func = inlineFunction() )
49 _cache.type = func->type();
51 _cache.type = type::effectiveType(child<Type>(1));
64 if (
auto t =
childs()[2].tryAs<Type>() )
65 return type::effectiveType(*t);
70 std::optional<Expression> default_()
const {
72 return *a->valueAs<Expression>();
77 auto isInternal()
const {
return AttributeSet::find(attributes(),
"&internal").has_value(); }
78 auto isOptional()
const {
return AttributeSet::find(attributes(),
"&optional").has_value(); }
79 auto isStatic()
const {
return AttributeSet::find(attributes(),
"&static").has_value(); }
80 auto isNoEmit()
const {
return AttributeSet::find(attributes(),
"&no-emit").has_value(); }
88 bool operator==(
const Field& other)
const {
89 return id() == other.id() && type() == other.type() && attributes() == other.attributes() && _cc == other._cc;
101 x.childs()[3] = attrs;
105 void clearCache() { _cache.type.reset(); }
108 ::hilti::function::CallingConvention _cc = ::hilti::function::CallingConvention::Standard;
110 mutable struct { std::optional<Type> type; } _cache;
122 _state().
flags += type::Flag::NoInheritScope;
125 Struct(std::vector<type::function::Parameter> params, std::vector<struct_::Field> fields,
Meta m =
Meta())
132 _state().
flags += type::Flag::NoInheritScope;
136 _state().
flags += type::Flag::NoInheritScope;
139 auto hasFinalizer()
const {
return field(
"~finally").has_value(); }
141 auto parameters()
const {
return childsOfType<type::function::Parameter>(); }
143 std::vector<NodeRef> parameterNodes() {
144 std::vector<NodeRef> params;
145 for (
auto& c :
childs() ) {
147 params.emplace_back(
NodeRef(c));
152 auto fields()
const {
return childsOfType<struct_::Field>(); }
155 std::vector<Type> types;
156 for (
auto c = ++
childs().begin(); c !=
childs().end(); c++ )
164 for (
auto c = ++
childs().begin(); c !=
childs().end(); c++ )
170 std::optional<struct_::Field> field(
const ID&
id)
const {
171 for (
auto f : fields() ) {
179 auto fields(
const ID&
id)
const {
180 std::vector<struct_::Field> x;
182 for (
const auto& f : fields() ) {
190 bool operator==(
const Struct& other)
const {
191 if ( typeID() && other.
typeID() )
192 return *typeID() == *other.
typeID();
194 return fields() == other.fields();
201 auto isEqual(
const Type& other)
const {
return node::isEqual(
this, other); }
204 std::vector<Node> params;
205 for (
auto c = ++
childs().begin(); c !=
childs().end(); c++ )
223 auto x = Type(s)._clone().as<
Struct>();
229 bool _wildcard =
false;
Definition: function.h:69
std::optional< Type > auxType() const
Definition: struct.h:63
auto & _typeNode()
Definition: struct.h:83
auto & childs() const
Definition: node.h:445
static Declaration setIsStructParameter(const Parameter &d)
Definition: parameter.h:119
const Node none
Definition: node.cc:12
type::Flags flags() const
Definition: type.h:159
void addChild(Node n)
Definition: node.h:434
auto isWildcard() const
Definition: struct.h:210
auto properties() const
Definition: struct.h:86
auto properties() const
Definition: struct.h:213
auto isEqual(const Type &other) const
Definition: struct.h:201
Definition: function.h:44
static Struct addField(const Struct &s, struct_::Field f)
Definition: struct.h:222
Definition: attribute.h:159
auto typeParameters() const
Definition: struct.h:203
Definition: parameter.h:45
static Field setAttributes(const Field &f, const AttributeSet &attrs)
Definition: struct.h:99
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
std::optional< ID > typeID() const
Definition: type.h:163
std::optional< Attribute > find(std::string_view tag) const
Definition: attribute.h:190
Definition: node_ref.h:44
auto transform(const std::vector< X > &x, F f)
Definition: util.h:86
auto _fieldNodes()
Definition: struct.h:198