24 while (name.ends_with(
'*')) {
25 name.erase(name.size() - 1);
28 if (name.contains(
'*')) {
29 context.error(
"identifier cannot contain '*' in middle of itself");
33 if (name.starts_with(
'/')) {
35 std::stringstream ss(name);
36 for (std::string term; std::getline(ss, term,
'/');) {
37 _terms.push_back(term);
41 _terms.push_back(name);
46 if (strcmp(node->name(),
"assembly") == 0) {
51 const auto name = node->first_attribute(
"id");
53 context.
error(
"identifier missing in declaration");
57 _name =
name->value();
61#define NODE_HANDLER MLLIFContext &context, rapidxml::xml_node<> *node, std::shared_ptr<Decl> parent
62#define NODE_INIT(t) [](NODE_HANDLER) -> std::shared_ptr<Decl> { return std::make_shared<t##Decl>(context, node, parent); }
63 std::map<std::string, std::shared_ptr<Decl> (*)(
NODE_HANDLER)> handlers = {
74 if (!handlers.contains(node->name())) {
75 context.
error(std::format(
"unrecognized tag '{}'", node->name()));
79 auto decl = handlers[node->name()](context, node,
parent);
84 for (
auto child = node->first_node(); child; child = child->next_sibling()) {
85 decl->_children.push_back(
Create(context, child,
parent));
92 const auto size = node->first_attribute(
"size");
93 const auto align = node->first_attribute(
"align");
100 const auto returns = node->first_attribute(
"ret");
101 const auto sym = node->first_attribute(
"sym");
104 context.
error(std::format(
"return type missing for function '{}'",
name()));
107 context.
error(std::format(
"symbol name missing for function '{}'",
name()));
114 _symbol = sym->value();
118 const auto type = node->first_attribute(
"type");
120 context.
error(std::format(
"type missing for parameter '{}'",
name()));
124 _type =
Type(context,
type->value());
static std::shared_ptr< Decl > Create(MLLIFContext &context, rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
const std::shared_ptr< Decl > & parent() const
Decl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
const std::string & name() const
FunctionDecl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
const Type & returns() const
void error(const std::string &what)
ObjectDecl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
const std::string & align() const
const std::string & size() const
const Type & type() const
ParamDecl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)