irc: add ListNode support; fix recursive attrset scoping
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I1657bc6a05c264f0ae0dd2c94d32b1046a6a6964
This commit is contained in:
parent
6587d07833
commit
6612479286
1 changed files with 24 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "ir_gen.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
@ -97,7 +98,8 @@ struct IRGenerator::Impl {
|
|||
return std::make_shared<Node>(*n);
|
||||
}
|
||||
if (auto* n = node.get_if<VarNode>()) {
|
||||
uint32_t idx = name_resolver.resolve(n->name.value_or(""));
|
||||
std::string var_name = n->name.value_or("");
|
||||
uint32_t idx = name_resolver.resolve(var_name);
|
||||
VarNode converted(idx);
|
||||
converted.name = n->name;
|
||||
converted.line = n->line;
|
||||
|
|
@ -121,12 +123,17 @@ struct IRGenerator::Impl {
|
|||
}
|
||||
if (auto* n = node.get_if<AttrsetNode>()) {
|
||||
AttrsetNode attrs(n->recursive, n->line);
|
||||
name_resolver.enter_scope();
|
||||
for (const auto& binding : n->attrs) {
|
||||
if (!binding.is_dynamic()) {
|
||||
name_resolver.bind(binding.static_name.value());
|
||||
|
||||
// Only enter a new scope for recursive attrsets
|
||||
if (n->recursive) {
|
||||
name_resolver.enter_scope();
|
||||
for (const auto& binding : n->attrs) {
|
||||
if (!binding.is_dynamic()) {
|
||||
name_resolver.bind(binding.static_name.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& binding : n->attrs) {
|
||||
if (binding.is_dynamic()) {
|
||||
attrs.attrs.push_back(AttrBinding(convert(binding.dynamic_name), convert(binding.value)));
|
||||
|
|
@ -134,7 +141,10 @@ struct IRGenerator::Impl {
|
|||
attrs.attrs.push_back(AttrBinding(binding.static_name.value(), convert(binding.value)));
|
||||
}
|
||||
}
|
||||
name_resolver.exit_scope();
|
||||
|
||||
if (n->recursive) {
|
||||
name_resolver.exit_scope();
|
||||
}
|
||||
return std::make_shared<Node>(attrs);
|
||||
}
|
||||
if (auto* n = node.get_if<SelectNode>()) {
|
||||
|
|
@ -208,6 +218,14 @@ struct IRGenerator::Impl {
|
|||
auto operand = convert(n->operand);
|
||||
return std::make_shared<Node>(UnaryOpNode(n->op, operand, n->line));
|
||||
}
|
||||
if (auto* n = node.get_if<ListNode>()) {
|
||||
std::vector<std::shared_ptr<Node>> elements;
|
||||
elements.reserve(n->elements.size());
|
||||
for (const auto& elem : n->elements) {
|
||||
elements.push_back(convert(elem));
|
||||
}
|
||||
return std::make_shared<Node>(ListNode(std::move(elements), n->line));
|
||||
}
|
||||
return std::make_shared<Node>(ConstNullNode{});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue