9 #include <hilti/rt/filesystem.h> 11 #include <hilti/ast/declarations/all.h> 12 #include <hilti/ast/function.h> 13 #include <hilti/ast/statements/declaration.h> 14 #include <hilti/ast/types/function.h> 18 inline auto import(std::string module,
const Meta& m = Meta()) {
19 return declaration::ImportedModule(
hilti::ID(std::move(module), m), std::string(
".hlt"), m);
22 inline auto import(std::string module,
const std::string& parse_extension,
const Meta& m = Meta()) {
23 return declaration::ImportedModule(
hilti::ID(std::move(module), m), parse_extension, m);
26 inline auto import(std::string module,
const std::string& parse_extension,
27 std::vector<hilti::rt::filesystem::path> search_dirs,
const Meta& m = Meta()) {
28 return declaration::ImportedModule(
hilti::ID(std::move(module), m), parse_extension, {}, std::move(search_dirs), m);
31 inline auto import(std::string module,
const std::string& parse_extension, std::optional<ID> search_scope,
32 std::vector<hilti::rt::filesystem::path> search_dirs,
const Meta& m = Meta()) {
33 return declaration::ImportedModule(
hilti::ID(std::move(module), m), parse_extension, std::move(search_scope),
34 std::move(search_dirs), m);
37 inline auto local(ID id_, Type t, Meta m = Meta()) {
38 return statement::Declaration(declaration::LocalVariable(std::move(id_), std::move(t), {},
false, std::move(m)));
41 inline auto local(ID id_, Expression init, Meta m = Meta()) {
42 return statement::Declaration(declaration::LocalVariable(std::move(id_), std::move(init),
false, std::move(m)));
45 inline auto local(ID id_, Type t, Expression init, Meta m = Meta()) {
46 return statement::Declaration(
47 declaration::LocalVariable(std::move(id_), std::move(t), std::move(init),
false, std::move(m)));
50 inline auto local(ID id_, Type t, std::vector<hilti::Expression> args, Meta m = Meta()) {
51 return statement::Declaration(
52 declaration::LocalVariable(std::move(id_), std::move(t), std::move(args), {},
false, std::move(m)));
55 inline auto global(ID id_, Type t, declaration::Linkage linkage = declaration::Linkage::Private, Meta m = Meta()) {
56 return declaration::GlobalVariable(std::move(id_), std::move(t), {}, linkage, std::move(m));
59 inline auto global(ID id_, Expression init, declaration::Linkage linkage = declaration::Linkage::Private,
61 return declaration::GlobalVariable(std::move(id_), std::move(init), linkage, std::move(m));
64 inline auto global(ID id_, Type t, Expression init, declaration::Linkage linkage = declaration::Linkage::Private,
66 return declaration::GlobalVariable(std::move(id_), std::move(t), std::move(init), linkage, std::move(m));
69 inline auto global(ID id_, Type t, std::vector<hilti::Expression> args,
70 declaration::Linkage linkage = declaration::Linkage::Private, Meta m = Meta()) {
71 return declaration::GlobalVariable(std::move(id_), std::move(t), std::move(args), {}, linkage, std::move(m));
74 inline auto type(ID
id, ::
hilti::Type type, declaration::Linkage linkage = declaration::Linkage::Private,
76 return declaration::Type(std::move(
id), std::move(type), linkage, std::move(m));
79 inline auto type(ID
id, ::
hilti::Type type, std::optional<AttributeSet> attrs,
80 declaration::Linkage linkage = declaration::Linkage::Private, Meta m = Meta()) {
81 return declaration::Type(std::move(
id), std::move(type), std::move(attrs), linkage, std::move(m));
84 inline auto constant(ID id_, Expression init, declaration::Linkage linkage = declaration::Linkage::Private,
86 return declaration::Constant(std::move(id_), std::move(init), linkage, std::move(m));
89 inline auto parameter(ID
id, Type type, type::function::parameter::Kind kind = type::function::parameter::Kind::In,
91 return type::function::Parameter(std::move(
id), std::move(type), kind, {}, std::move(m));
94 inline auto parameter(ID
id, Type type, Expression default_,
95 type::function::parameter::Kind kind = type::function::parameter::Kind::In, Meta m = Meta()) {
96 return type::function::Parameter(std::move(
id), std::move(type), kind, std::move(default_), std::move(m));
99 template<
typename... Params>
100 static auto parameters(Params&&... params) {
101 return std::vector<hilti::type::function::Parameter>{std::forward<Params>(params)...};
104 inline auto function(ID id, Type result,
const std::vector<type::function::Parameter>& params,
105 type::function::Flavor flavor = type::function::Flavor::Standard,
106 declaration::Linkage linkage = declaration::Linkage::Private,
107 function::CallingConvention cc = function::CallingConvention::Standard,
108 std::optional<AttributeSet> attrs = {},
const Meta& m = Meta()) {
109 auto ft = type::Function(type::function::Result(std::move(result), m), params, flavor, m);
110 auto f = Function(std::move(
id), std::move(ft), {}, cc, std::move(attrs), m);
111 return declaration::Function(std::move(f), linkage, m);
114 inline auto function(ID id, Type result,
const std::vector<type::function::Parameter>& params, Statement body,
115 type::function::Flavor flavor = type::function::Flavor::Standard,
116 declaration::Linkage linkage = declaration::Linkage::Private,
117 function::CallingConvention cc = function::CallingConvention::Standard,
118 std::optional<AttributeSet> attrs = {},
const Meta& m = Meta()) {
119 auto ft = type::Function(type::function::Result(std::move(result), m), params, flavor, m);
120 auto f = Function(std::move(
id), std::move(ft), std::move(body), cc, std::move(attrs), m);
121 return declaration::Function(std::move(f), linkage, m);
124 inline auto function(ID id, type::Function ftype, Statement body,
125 declaration::Linkage linkage = declaration::Linkage::Private,
126 function::CallingConvention cc = function::CallingConvention::Standard,
127 std::optional<AttributeSet> attrs = {},
const Meta& m = Meta()) {
128 auto f = Function(std::move(
id), std::move(ftype), std::move(body), cc, std::move(attrs), m);
129 return declaration::Function(std::move(f), linkage, m);