mirror of https://github.com/exaloop/codon
Update IR attributes
parent
f0a21fa3ef
commit
b72f54acc3
|
@ -67,24 +67,24 @@ std::ostream &TupleLiteralAttribute::doFormat(std::ostream &os) const {
|
|||
const std::string ListLiteralAttribute::AttributeName = "listLiteralAttribute";
|
||||
|
||||
std::unique_ptr<Attribute> ListLiteralAttribute::clone(util::CloneVisitor &cv) const {
|
||||
std::vector<Value *> elementsCloned;
|
||||
for (auto *val : elements)
|
||||
elementsCloned.push_back(cv.clone(val));
|
||||
std::vector<LiteralElement> elementsCloned;
|
||||
for (auto &e : elements)
|
||||
elementsCloned.push_back({cv.clone(e.value), e.star});
|
||||
return std::make_unique<ListLiteralAttribute>(elementsCloned);
|
||||
}
|
||||
|
||||
std::unique_ptr<Attribute>
|
||||
ListLiteralAttribute::forceClone(util::CloneVisitor &cv) const {
|
||||
std::vector<Value *> elementsCloned;
|
||||
for (auto *val : elements)
|
||||
elementsCloned.push_back(cv.forceClone(val));
|
||||
std::vector<LiteralElement> elementsCloned;
|
||||
for (auto &e : elements)
|
||||
elementsCloned.push_back({cv.forceClone(e.value), e.star});
|
||||
return std::make_unique<ListLiteralAttribute>(elementsCloned);
|
||||
}
|
||||
|
||||
std::ostream &ListLiteralAttribute::doFormat(std::ostream &os) const {
|
||||
std::vector<std::string> strings;
|
||||
for (auto *val : elements)
|
||||
strings.push_back(fmt::format(FMT_STRING("{}"), *val));
|
||||
for (auto &e : elements)
|
||||
strings.push_back(fmt::format(FMT_STRING("{}{}"), e.star ? "*" : "", *e.value));
|
||||
fmt::print(os, FMT_STRING("[{}]"), fmt::join(strings.begin(), strings.end(), ","));
|
||||
return os;
|
||||
}
|
||||
|
@ -92,24 +92,24 @@ std::ostream &ListLiteralAttribute::doFormat(std::ostream &os) const {
|
|||
const std::string SetLiteralAttribute::AttributeName = "setLiteralAttribute";
|
||||
|
||||
std::unique_ptr<Attribute> SetLiteralAttribute::clone(util::CloneVisitor &cv) const {
|
||||
std::vector<Value *> elementsCloned;
|
||||
for (auto *val : elements)
|
||||
elementsCloned.push_back(cv.clone(val));
|
||||
std::vector<LiteralElement> elementsCloned;
|
||||
for (auto &e : elements)
|
||||
elementsCloned.push_back({cv.clone(e.value), e.star});
|
||||
return std::make_unique<SetLiteralAttribute>(elementsCloned);
|
||||
}
|
||||
|
||||
std::unique_ptr<Attribute>
|
||||
SetLiteralAttribute::forceClone(util::CloneVisitor &cv) const {
|
||||
std::vector<Value *> elementsCloned;
|
||||
for (auto *val : elements)
|
||||
elementsCloned.push_back(cv.forceClone(val));
|
||||
std::vector<LiteralElement> elementsCloned;
|
||||
for (auto &e : elements)
|
||||
elementsCloned.push_back({cv.forceClone(e.value), e.star});
|
||||
return std::make_unique<SetLiteralAttribute>(elementsCloned);
|
||||
}
|
||||
|
||||
std::ostream &SetLiteralAttribute::doFormat(std::ostream &os) const {
|
||||
std::vector<std::string> strings;
|
||||
for (auto *val : elements)
|
||||
strings.push_back(fmt::format(FMT_STRING("{}"), *val));
|
||||
for (auto &e : elements)
|
||||
strings.push_back(fmt::format(FMT_STRING("{}{}"), e.star ? "*" : "", *e.value));
|
||||
fmt::print(os, FMT_STRING("set([{}])"),
|
||||
fmt::join(strings.begin(), strings.end(), ","));
|
||||
return os;
|
||||
|
|
|
@ -132,14 +132,22 @@ private:
|
|||
std::ostream &doFormat(std::ostream &os) const override;
|
||||
};
|
||||
|
||||
/// Information about an element in a collection literal
|
||||
struct LiteralElement {
|
||||
/// the element value
|
||||
Value *value;
|
||||
/// true if preceded by "*", as in "[*x]"
|
||||
bool star;
|
||||
};
|
||||
|
||||
/// Attribute attached to IR structures corresponding to list literals
|
||||
struct ListLiteralAttribute : public Attribute {
|
||||
static const std::string AttributeName;
|
||||
|
||||
/// values contained in list literal
|
||||
std::vector<Value *> elements;
|
||||
/// elements contained in list literal
|
||||
std::vector<LiteralElement> elements;
|
||||
|
||||
explicit ListLiteralAttribute(std::vector<Value *> elements)
|
||||
explicit ListLiteralAttribute(std::vector<LiteralElement> elements)
|
||||
: elements(std::move(elements)) {}
|
||||
|
||||
std::unique_ptr<Attribute> clone(util::CloneVisitor &cv) const override;
|
||||
|
@ -153,10 +161,10 @@ private:
|
|||
struct SetLiteralAttribute : public Attribute {
|
||||
static const std::string AttributeName;
|
||||
|
||||
/// values contained in set literal
|
||||
std::vector<Value *> elements;
|
||||
/// elements contained in set literal
|
||||
std::vector<LiteralElement> elements;
|
||||
|
||||
explicit SetLiteralAttribute(std::vector<Value *> elements)
|
||||
explicit SetLiteralAttribute(std::vector<LiteralElement> elements)
|
||||
: elements(std::move(elements)) {}
|
||||
|
||||
std::unique_ptr<Attribute> clone(util::CloneVisitor &cv) const override;
|
||||
|
|
Loading…
Reference in New Issue