Added comments and cleaned up ast nodes and parser
This commit is contained in:
1 parent
ae2a3c64ef
commit
1ec0433cfe
17 files changed
+747
-667
No files matched your search
@@ -82,11 +82,11 @@ namespace domain {
|
||||
|
||||
for (auto &inst: schema.componentInstances) {
|
||||
for (auto &pin: inst->component.getPins()) {
|
||||
if (pin.getConnection().getType() == PinConnection::REQUIRED) {
|
||||
if (pin.getConnection().has_value()) {
|
||||
if (!connectionExists(schema, inst, pin)) {
|
||||
context.instance = inst.get();
|
||||
context.attributes["instanceName"] = Value::fromString(inst->name);
|
||||
auto message = populateMessage(pin.getConnection().getMessage(), context);
|
||||
auto message = populateMessage(pin.getConnection().value(), context);
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-14
@@ -2,19 +2,7 @@
|
||||
|
||||
namespace domain {
|
||||
|
||||
PinConnection::PinConnection(std::string message, ConnectionType type)
|
||||
: message(message), type(type) {}
|
||||
|
||||
PinConnection::ConnectionType PinConnection::getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
std::string PinConnection::getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
Pin::Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, domain::ui::Pin pin,
|
||||
Pin::Pin(std::string name, PinType type, std::string tooltip, std::optional<std::string> connection, domain::ui::Pin pin,
|
||||
std::optional<std::vector<Value>> wires)
|
||||
: name(name), type(type), tooltip(tooltip), connection(connection), displayPin(pin), wires(wires) {}
|
||||
|
||||
@@ -34,7 +22,7 @@ namespace domain {
|
||||
return displayPin;
|
||||
}
|
||||
|
||||
PinConnection &Pin::getConnection() {
|
||||
std::optional<std::string> Pin::getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
+3
-22
@@ -9,25 +9,6 @@
|
||||
|
||||
namespace domain {
|
||||
|
||||
class PinConnection {
|
||||
public:
|
||||
enum ConnectionType {
|
||||
REQUIRED,
|
||||
OPTIONAL
|
||||
};
|
||||
|
||||
private:
|
||||
std::string message;
|
||||
ConnectionType type;
|
||||
|
||||
public:
|
||||
PinConnection(std::string message, ConnectionType type);
|
||||
|
||||
ConnectionType getType();
|
||||
|
||||
std::string getMessage();
|
||||
};
|
||||
|
||||
class Pin {
|
||||
public:
|
||||
enum PinType {
|
||||
@@ -40,13 +21,13 @@ namespace domain {
|
||||
std::string name;
|
||||
PinType type;
|
||||
std::string tooltip;
|
||||
PinConnection connection;
|
||||
std::optional<std::string> connection;
|
||||
domain::ui::Pin displayPin;
|
||||
|
||||
std::optional<std::vector<Value>> wires;
|
||||
|
||||
public:
|
||||
Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, domain::ui::Pin pin,
|
||||
Pin(std::string name, PinType type, std::string tooltip, std::optional<std::string> connection, domain::ui::Pin pin,
|
||||
std::optional<std::vector<Value>> wires);
|
||||
|
||||
std::string &getName();
|
||||
@@ -57,7 +38,7 @@ namespace domain {
|
||||
|
||||
ui::Pin &getDisplayPin();
|
||||
|
||||
PinConnection &getConnection();
|
||||
std::optional<std::string> getConnection();
|
||||
|
||||
std::optional<std::vector<Value>> &getWires();
|
||||
};
|
||||
|
||||
@@ -81,20 +81,20 @@ namespace domain {
|
||||
|
||||
Value toType(ValueNode node, Value::ValueType type = Value::ValueType::UNDEFINED) {
|
||||
if (type == Value::MEMORY_REFERENCE) {
|
||||
if (node.getType() == ValueNode::NIL) {
|
||||
if (node.is(ValueNode::NIL)) {
|
||||
return Value::fromMemoryReference(nullopt);
|
||||
} else {
|
||||
return Value::fromMemoryReference(node.asIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
if (node.getType() == ValueNode::BOOL) {
|
||||
if (node.is(ValueNode::BOOL)) {
|
||||
return Value::fromBool(node.asBool());
|
||||
} else if (node.getType() == ValueNode::INT) {
|
||||
} else if (node.is(ValueNode::INT)) {
|
||||
return Value::fromInt(node.asInt());
|
||||
} else if (node.getType() == ValueNode::STRING) {
|
||||
} else if (node.is(ValueNode::STRING)) {
|
||||
return Value::fromString(node.asString());
|
||||
} else if (node.getType() == ValueNode::NIL) {
|
||||
} else if (node.is(ValueNode::NIL)) {
|
||||
return Value::fromNull();
|
||||
}
|
||||
return Value::fromReference(node.asIdentifier(), Value::UNDEFINED);
|
||||
@@ -120,14 +120,6 @@ namespace domain {
|
||||
return Pin::IN_OUT;
|
||||
}
|
||||
|
||||
PinConnection::ConnectionType toType(PinConnectionNode::ConnectionType type) {
|
||||
if (type == PinConnectionNode::OPTIONAL) {
|
||||
return PinConnection::OPTIONAL;
|
||||
}
|
||||
return PinConnection::REQUIRED;
|
||||
}
|
||||
|
||||
|
||||
Popup::PopupType toType(PopupNode::PopupType type) {
|
||||
if (type == PopupNode::AUTOMATIC) {
|
||||
return Popup::AUTOMATIC;
|
||||
@@ -274,7 +266,7 @@ namespace domain {
|
||||
|
||||
|
||||
std::optional<AddressSpace> SchemaCreator::loadAddressSpace(AddressSpaceNode node) {
|
||||
return AddressSpace(node.name.value, node.start.value, node.end.value);
|
||||
return AddressSpace(node.name.value, node.range.first.value, node.range.second.value);
|
||||
}
|
||||
|
||||
std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node) {
|
||||
@@ -584,12 +576,10 @@ namespace domain {
|
||||
}
|
||||
ui::Pin displayPin = *display->getItems()[0].pin;
|
||||
|
||||
|
||||
if (!node.connection) {
|
||||
errors.emplace_back(node.span, "missing @connection");
|
||||
return nullopt;
|
||||
std::optional<std::string> connection = std::nullopt;
|
||||
if (node.connection) {
|
||||
connection = node.connection->asString();
|
||||
}
|
||||
auto connection = loadPinConnection(*node.connection);
|
||||
|
||||
std::optional<std::vector<Value>> wiresOpt = std::nullopt;
|
||||
if (node.wires.has_value()) {
|
||||
@@ -610,47 +600,74 @@ namespace domain {
|
||||
return Pin(pinName, type, tooltip, connection, displayPin, wiresOpt);
|
||||
}
|
||||
|
||||
Color readColor(std::vector<SourceError>& errors, DisplayItemNode& item, std::string property, Color _default) {
|
||||
auto color = item.asColor(property, _default);
|
||||
if(!color.has_value()) {
|
||||
errors.emplace_back(item.span, "expected color");
|
||||
return _default;
|
||||
}
|
||||
return *color;
|
||||
}
|
||||
|
||||
std::string readString(std::vector<SourceError>& errors, DisplayItemNode& item, std::string property, std::string _default = "") {
|
||||
auto value = item.asString(property, _default);
|
||||
if(!value.has_value()) {
|
||||
errors.emplace_back(item.span, "expected string");
|
||||
return _default;
|
||||
}
|
||||
return *value;
|
||||
}
|
||||
|
||||
long long int readInt(std::vector<SourceError>& errors, DisplayItemNode& item, std::string property, long long int _default = 0) {
|
||||
auto value = item.asInt(property, _default);
|
||||
if(!value.has_value()) {
|
||||
errors.emplace_back(item.span, "expected int");
|
||||
return _default;
|
||||
}
|
||||
return *value;
|
||||
}
|
||||
|
||||
std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node) {
|
||||
std::vector<ui::Item> items;
|
||||
for (auto &item: node.items) {
|
||||
ui::Item displayItem;
|
||||
std::string type = item.type.value;
|
||||
|
||||
auto fillColor = item.asColor(&errors, "fillColor", Color(255, 255, 255, 255));
|
||||
auto lineColor = item.asColor(&errors, "lineColor", Color(0, 0, 0, 255));
|
||||
auto fillColor = readColor(errors, item, "fillColor", Color(255, 255, 255, 255));
|
||||
auto lineColor = readColor(errors, item, "lineColor", Color(0, 0, 0, 255));
|
||||
|
||||
if (type == "text") {
|
||||
long long int x, y, w, h;
|
||||
std::string text;
|
||||
auto color = item.asColor(&errors, "color", Color(0, 0, 0, 255));
|
||||
x = item.asInt(&errors, "x");
|
||||
y = item.asInt(&errors, "y");
|
||||
w = item.asInt(&errors, "w");
|
||||
h = item.asInt(&errors, "h");
|
||||
text = item.asString(&errors, "text");
|
||||
auto color = readColor(errors, item, "color", Color(0, 0, 0, 255));
|
||||
x = readInt(errors, item, "x");
|
||||
y = readInt(errors, item, "y");
|
||||
w = readInt(errors, item, "w");
|
||||
h = readInt(errors, item, "h");
|
||||
text = readString(errors, item, "text");
|
||||
displayItem.text = ui::Text(x, y, w, h, text, color);
|
||||
} else if (type == "rect") {
|
||||
long long int x, y, w, h;
|
||||
x = item.asInt(&errors, "x");
|
||||
y = item.asInt(&errors, "y");
|
||||
w = item.asInt(&errors, "w");
|
||||
h = item.asInt(&errors, "h");
|
||||
x = readInt(errors, item, "x");
|
||||
y = readInt(errors, item, "y");
|
||||
w = readInt(errors, item, "w");
|
||||
h = readInt(errors, item, "h");
|
||||
displayItem.rect = ui::Rect(x, y, w, h, {lineColor, fillColor});
|
||||
} else if (type == "line") {
|
||||
long long int x1, y1, x2, y2;
|
||||
x1 = item.asInt(&errors, "x1");
|
||||
y1 = item.asInt(&errors, "y1");
|
||||
x2 = item.asInt(&errors, "x2");
|
||||
y2 = item.asInt(&errors, "y2");
|
||||
x1 = readInt(errors, item, "x1");
|
||||
y1 = readInt(errors, item, "y1");
|
||||
x2 = readInt(errors, item, "x2");
|
||||
y2 = readInt(errors, item, "y2");
|
||||
displayItem.line = ui::Line(x1, y1, x2, y2, {lineColor, fillColor});
|
||||
} else if (type == "pin") {
|
||||
long long int x, y, w, h;
|
||||
x = item.asInt(&errors, "x");
|
||||
y = item.asInt(&errors, "y");
|
||||
w = item.asInt(&errors, "w");
|
||||
h = item.asInt(&errors, "h");
|
||||
std::string _orientation = item.asString(&errors, "orientation", "bottom");
|
||||
std::string _pinType = item.asString(&errors, "type", "out");
|
||||
x = readInt(errors, item, "x");
|
||||
y = readInt(errors, item, "y");
|
||||
w = readInt(errors, item, "w");
|
||||
h = readInt(errors, item, "h");
|
||||
std::string _orientation = readString(errors, item, "orientation", "bottom");
|
||||
std::string _pinType = readString(errors, item, "type", "out");
|
||||
|
||||
ui::PinOrientation orientation;
|
||||
if (_orientation == "left") {
|
||||
@@ -679,11 +696,11 @@ namespace domain {
|
||||
displayItem.pin = ui::Pin(x, y, w, h, orientation, pinType, {lineColor, fillColor});
|
||||
} else if (type == "bus") {
|
||||
long long int x, y, w, h;
|
||||
x = item.asInt(&errors, "x");
|
||||
y = item.asInt(&errors, "y");
|
||||
w = item.asInt(&errors, "w");
|
||||
h = item.asInt(&errors, "h");
|
||||
std::string _orientation = item.asString(&errors, "orientation", "bottom");
|
||||
x = readInt(errors, item, "x");
|
||||
y = readInt(errors, item, "y");
|
||||
w = readInt(errors, item, "w");
|
||||
h = readInt(errors, item, "h");
|
||||
std::string _orientation = readString(errors, item, "orientation", "bottom");
|
||||
|
||||
ui::BusOrientation orientation;
|
||||
if (_orientation == "horizontal") {
|
||||
@@ -703,13 +720,6 @@ namespace domain {
|
||||
return Display(items);
|
||||
}
|
||||
|
||||
|
||||
PinConnection SchemaCreator::loadPinConnection(PinConnectionNode node) {
|
||||
std::string message = node.message.asString();
|
||||
PinConnection::ConnectionType type = toType(node.type.value);
|
||||
return {message, type};
|
||||
}
|
||||
|
||||
std::optional<Attribute> SchemaCreator::loadAttribute(AttributeNode node) {
|
||||
std::string name = node.name.value;
|
||||
pushAdditional(name);
|
||||
|
||||
@@ -58,8 +58,6 @@ namespace domain {
|
||||
std::optional<Wire> loadWire(WireNode node);
|
||||
std::optional<Pin> loadPin(PinNode pins);
|
||||
|
||||
PinConnection loadPinConnection(PinConnectionNode node);
|
||||
|
||||
std::optional<Connection> loadConnection(ConnectionNode node);
|
||||
std::optional<Bus> loadBus(BusNode node);
|
||||
|
||||
|
||||
Reference in new issue
Block a user