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, std::vector<hilti::rt::filesystem::path> search_dirs,
const Meta& m = Meta()) {
23 return declaration::ImportedModule(
hilti::ID(std::move(module), m), std::string(
".hlt"), {}, std::move(search_dirs),
27 inline auto import(std::string module, std::optional<ID> search_scope,
28 std::vector<hilti::rt::filesystem::path> search_dirs,
const Meta& m = Meta()) {
29 return declaration::ImportedModule(
hilti::ID(std::move(module), m), std::string(
".hlt"), std::move(search_scope),
30 std::move(search_dirs), m);
33 inline auto local(ID id_, Type t, Meta m = Meta()) {
34 return statement::Declaration(declaration::LocalVariable(std::move(id_), std::move(t), {},
false, std::move(m)));
37 inline auto local(ID id_, Expression init, Meta m = Meta()) {
38 return statement::Declaration(declaration::LocalVariable(std::move(id_), std::move(init),
false, std::move(m)));
41 inline auto local(ID id_, Type t, Expression init, Meta m = Meta()) {
42 return statement::Declaration(
43 declaration::LocalVariable(std::move(id_), std::move(t), std::move(init),
false, std::move(m)));
46 inline auto local(ID id_, Type t, std::vector<hilti::Expression> args, Meta m = Meta()) {
47 return statement::Declaration(
48 declaration::LocalVariable(std::move(id_), std::move(t), std::move(args), {},
false, std::move(m)));
51 inline auto global(ID id_, Type t, declaration::Linkage linkage = declaration::Linkage::Private, Meta m = Meta()) {
52 return declaration::GlobalVariable(std::move(id_), std::move(t), {}, linkage, std::move(m));
55 inline auto global(ID id_, Expression init, declaration::Linkage linkage = declaration::Linkage::Private,
57 return declaration::GlobalVariable(std::move(id_), std::move(init), linkage, std::move(m));
60 inline auto global(ID id_, Type t, Expression init, declaration::Linkage linkage = declaration::Linkage::Private,
62 return declaration::GlobalVariable(std::move(id_), std::move(t), std::move(init), linkage, std::move(m));
65 inline auto global(ID id_, Type t, std::vector<hilti::Expression> args,
66 declaration::Linkage linkage = declaration::Linkage::Private, Meta m = Meta()) {
67 return declaration::GlobalVariable(std::move(id_), std::move(t), std::move(args), {}, linkage, std::move(m));
70 inline auto type(ID
id, ::hilti::Type type, declaration::Linkage linkage = declaration::Linkage::Private,
72 return declaration::Type(std::move(
id), std::move(type), linkage, std::move(m));
75 inline auto type(ID
id, ::hilti::Type type, std::optional<AttributeSet> attrs,
76 declaration::Linkage linkage = declaration::Linkage::Private, Meta m = Meta()) {
77 return declaration::Type(std::move(
id), std::move(type), std::move(attrs), linkage, std::move(m));
80 inline auto constant(ID id_, Expression init, declaration::Linkage linkage = declaration::Linkage::Private,
82 return declaration::Constant(std::move(id_), std::move(init), linkage, std::move(m));
85 inline auto parameter(ID
id, Type type, type::function::parameter::Kind kind = type::function::parameter::Kind::In,
87 return type::function::Parameter(std::move(
id), std::move(type), kind, {}, std::move(m));
90 inline auto parameter(ID
id, Type type, Expression default_,
91 type::function::parameter::Kind kind = type::function::parameter::Kind::In, Meta m = Meta()) {
92 return type::function::Parameter(std::move(
id), std::move(type), kind, std::move(default_), std::move(m));
95 template<
typename... Params>
96 static auto parameters(Params&&... params) {
97 return std::vector<hilti::type::function::Parameter>{std::forward<Params>(params)...};
100 inline auto function(ID id, Type result,
const std::vector<type::function::Parameter>& params,
101 type::function::Flavor flavor = type::function::Flavor::Standard,
102 declaration::Linkage linkage = declaration::Linkage::Private,
103 function::CallingConvention cc = function::CallingConvention::Standard,
104 std::optional<AttributeSet> attrs = {},
const Meta& m = Meta()) {
105 auto ft = type::Function(type::function::Result(std::move(result), m), params, flavor, m);
106 auto f = Function(std::move(
id), std::move(ft), {}, cc, std::move(attrs), m);
107 return declaration::Function(std::move(f), linkage, m);
110 inline auto function(ID id, Type result,
const std::vector<type::function::Parameter>& params, Statement body,
111 type::function::Flavor flavor = type::function::Flavor::Standard,
112 declaration::Linkage linkage = declaration::Linkage::Private,
113 function::CallingConvention cc = function::CallingConvention::Standard,
114 std::optional<AttributeSet> attrs = {},
const Meta& m = Meta()) {
115 auto ft = type::Function(type::function::Result(std::move(result), m), params, flavor, m);
116 auto f = Function(std::move(
id), std::move(ft), std::move(body), cc, std::move(attrs), m);
117 return declaration::Function(std::move(f), linkage, m);
120 inline auto function(ID id, type::Function ftype, Statement body,
121 declaration::Linkage linkage = declaration::Linkage::Private,
122 function::CallingConvention cc = function::CallingConvention::Standard,
123 std::optional<AttributeSet> attrs = {},
const Meta& m = Meta()) {
124 auto f = Function(std::move(
id), std::move(ftype), std::move(body), cc, std::move(attrs), m);
125 return declaration::Function(std::move(f), linkage, m);