Added support for integers and null to connections

This commit is contained in:
Borna Rajkovic committed 2022-04-08 23:09:19 +02:00
1 parent 9bd68ecf23
commit dfc7bf48dc
10 files changed
+95 -39

No files matched your search

+38 -20
View File
@@ -58,6 +58,8 @@ Value toType(ValueNode node) {
return Value::fromInt(node.asInt());
} else if(node.getType() == ValueNode::STRING) {
return Value::fromString(node.asString());
} else if(node.getType() == ValueNode::NIL) {
return Value::fromNull();
}
return Value::fromReference(node.asIdentifier(), Value::UNDEFINED);
}
@@ -228,12 +230,12 @@ std::optional<Connection> ComdelGenerator::loadConnection(ConnectionNode node)
auto componentInstance = getComponentPin(component, pin);
if(!componentInstance) {
errors.push_back(SourceError(node.span, "pin does not exist"));
errors.emplace_back(node.span, "pin does not exist");
}
auto busInstance = getBus(bus);
if(!busInstance) {
errors.push_back(SourceError(node.span, "bus does not exist"));
errors.emplace_back(node.span, "bus does not exist");
}
std::set<std::string> wireNames;
@@ -258,12 +260,20 @@ std::optional<Connection> ComdelGenerator::loadConnection(ConnectionNode node)
std::vector<Value> wires;
for(uint i=0; i<node.wires.size(); i++) {
if(attributeNames.count(node.wires[i].value)) {
wires.push_back(Value::fromReference(node.wires[i].value, Value::ATTRIBUTE_REFERENCE));
} else if(wireNames.count(node.wires[i].value)) {
wires.push_back(Value::fromReference(node.wires[i].value, Value::WIRE_REFERENCE));
if(node.wires[i].is(ValueNode::NIL)) {
wires.push_back(Value::fromNull());
} else if(node.wires[i].is(ValueNode::INT)) {
wires.push_back(Value::fromInt(node.wires[i].asInt()));
} else if(node.wires[i].is(ValueNode::IDENTIFIER)) {
if(attributeNames.count(node.wires[i].asIdentifier())) {
wires.push_back(Value::fromReference(node.wires[i].asIdentifier(), Value::ATTRIBUTE_REFERENCE));
} else if(wireNames.count(node.wires[i].asIdentifier())) {
wires.push_back(Value::fromReference(node.wires[i].asIdentifier(), Value::WIRE_REFERENCE));
} else {
errors.emplace_back(node.wires[i].span, "unknown identifier");
}
} else {
errors.push_back(SourceError(node.wires[i].span, "unknown identifier"));
errors.emplace_back(node.wires[i].span, "unknown value type");
}
}
@@ -520,26 +530,34 @@ std::optional<Popup> ComdelGenerator::loadPopup(PopupNode node, std::string name
std::vector<Enumeration> enumeration;
if(node.enumerated) {
for(uint i=0; i<node.enumeration.size(); i++) {
if(toType(node.enumeration[i].value.getType()) != type) {
if(type == Value::INT || type == Value::STRING || type == Value::BOOL) {
auto value = toType(node.enumeration[i].value);
if(value.getType() == type) {
enumeration.push_back(Enumeration(node.enumeration[i].key.asString(), value));
} else {
errors.push_back(SourceError{node.enumeration[i].span, "wrong type"});
}
} else if(type == Value::WIRE_REFERENCE) {
auto value = toType(node.enumeration[i].value);
if(value.isType(Value::UNDEFINED)) {
if(current().doesWireExists(value.asReference())) {
value = Value::fromReference(value.asReference(), Value::WIRE_REFERENCE);
} else {
errors.push_back(SourceError{node.enumeration[i].span, "unknown wire"});
}
}
if(value.isType(Value::WIRE_REFERENCE) || value.isType(Value::INT) || value.isType(Value::NIL)) {
enumeration.push_back(Enumeration(node.enumeration[i].key.asString(), value));
} else {
errors.push_back(SourceError{node.enumeration[i].span, "wrong type"});
}
}
auto value = toType(node.enumeration[i].value);
if(value.isType(Value::UNDEFINED) && current().doesWireExists(value.asReference())) {
value = Value::fromReference(value.asReference(), Value::WIRE_REFERENCE);
} else {
errors.push_back(SourceError{node.enumeration[i].span, "unknown wire"});
}
if(value.getType() != type) {
errors.push_back(SourceError{node.enumeration[i].span, "wrong type"});
}
enumeration.push_back(Enumeration(node.enumeration[i].key.asString(), value));
}
} else {
if(type == Value::WIRE_REFERENCE && !current().inConnection) {
errors.push_back(SourceError{node.span, "@enumeration is required for attributes of type wire"});
}
}
pop();
+6
View File
@@ -105,4 +105,10 @@ Value Value::ofType(Value::ValueType type) {
}
Value Value::fromNull() {
Value val;
val.type = Value::NIL;
return val;
}
} // namespace domain
+2
View File
@@ -19,6 +19,7 @@ public:
ADDRESS_SPACE,
ATTRIBUTE_REFERENCE,
WIRE_REFERENCE,
NIL,
UNDEFINED,
};
@@ -54,6 +55,7 @@ public:
static Value fromInt(long long value);
static Value fromString(std::string value);
static Value fromBool(bool value);
static Value fromNull();
static Value fromAddressSpace(AddressSpace addressSpace);
static Value fromReference(std::string value, ValueType type);
static Value ofType(ValueType type);