Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aac972c6ca | ||
|
|
5cf8235608 | ||
|
|
cbff8ff5f2 | ||
|
|
0a658a4aba | ||
|
|
1100a9f0b9 | ||
|
|
f11551fef6 | ||
|
|
281926cb8b | ||
|
|
e2e0506041 | ||
|
|
59b19062ff | ||
|
|
bb423c2184 | ||
|
|
65020c2b7f | ||
|
|
23764776f1 | ||
|
|
05fa2abbb0 | ||
|
|
e7fd7df154 | ||
|
|
45a668fc46 | ||
|
|
74a7ef3e7a | ||
|
|
fb8aafb2a9 | ||
|
|
9ff6633777 | ||
|
|
5ccd9b2fa4 | ||
|
|
344fe7cfa6 |
No files matched your search
+1
-1
@@ -38,5 +38,5 @@ add_executable(SchemeEditor
|
|||||||
comdel/parser/comdellexer.cpp
|
comdel/parser/comdellexer.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
mainwindow.ui
|
mainwindow.ui
|
||||||
comdel/domain/comdelvalidator.cpp comdel/domain/comdelvalidator.h comdel/display/dialogmanager.cpp comdel/display/dialogmanager.h comdel/display/attribute_dialog.cpp comdel/display/attribute_dialog.h comdel/display/name_dialog.cpp comdel/display/name_dialog.h)
|
comdel/domain/comdelvalidator.cpp comdel/domain/comdelvalidator.h comdel/display/attribute_dialog.cpp comdel/display/attribute_dialog.h comdel/display/name_dialog.cpp comdel/display/name_dialog.h comdel/domain/comdel_generator.cpp comdel/domain/comdel_generator.h comdel/display/library_list.cpp comdel/display/library_list.h)
|
||||||
target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)
|
target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||||
@@ -3,3 +3,64 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "attribute_dialog.h"
|
#include "attribute_dialog.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
namespace display {
|
||||||
|
|
||||||
|
void AttributeDialog::onUpdate() {
|
||||||
|
auto oldValue = attributeValue->value;
|
||||||
|
|
||||||
|
attributeValue->value = value;
|
||||||
|
domain::ComdelValidator validator(domain::getSupportedValidators());
|
||||||
|
|
||||||
|
domain::ValidationContext context;
|
||||||
|
|
||||||
|
for (auto &addressSpace: MainWindow::getLibrary()->getAddressSpaces()) {
|
||||||
|
context.addressSpaces.insert(std::make_pair(addressSpace.getName(), addressSpace));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto validationErrors = validator.validateAttribute(attributeValue, context);
|
||||||
|
if(validationErrors.empty()) {
|
||||||
|
accept();
|
||||||
|
} else {
|
||||||
|
bool canAccept = true;
|
||||||
|
|
||||||
|
std::vector<domain::ValidationError> errors;
|
||||||
|
std::vector<domain::ValidationError> warnings;
|
||||||
|
for(auto& err: validationErrors) {
|
||||||
|
if(err.type == domain::Action::ERROR) {
|
||||||
|
errors.push_back(err);
|
||||||
|
} else {
|
||||||
|
warnings.push_back(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!errors.empty()) {
|
||||||
|
canAccept = false;
|
||||||
|
auto errorDialog = new ErrorDialog(errors);
|
||||||
|
errorDialog->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& warning: warnings) {
|
||||||
|
auto warningDialog = new WarningDialog(warning);
|
||||||
|
int response = warningDialog->exec();
|
||||||
|
if(response == QDialog::Rejected) {
|
||||||
|
canAccept = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(canAccept) {
|
||||||
|
accept();
|
||||||
|
} else {
|
||||||
|
attributeValue->value = oldValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MemoryDialog::onUpdate() {
|
||||||
|
attributeValue->value = value;
|
||||||
|
accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,22 +2,52 @@
|
|||||||
#define ATTRIBUTE_DIALOG_H
|
#define ATTRIBUTE_DIALOG_H
|
||||||
|
|
||||||
#include <QIntValidator>
|
#include <QIntValidator>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QComboBox>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QRadioButton>
|
#include <QRadioButton>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <utility>
|
||||||
#include <comdel/domain/instanceattribute.h>
|
#include <comdel/domain/instanceattribute.h>
|
||||||
|
|
||||||
#include <comdel/domain/value.h>
|
#include <comdel/domain/value.h>
|
||||||
|
#include "comdel/domain/comdelvalidator.h"
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
class AttributeDialog: public QDialog {
|
class AttributeDialog: public QDialog {
|
||||||
|
domain::Value value;
|
||||||
|
|
||||||
|
long long int parseInt(std::string expression) {
|
||||||
|
try {
|
||||||
|
if (expression.size() > 2) {
|
||||||
|
if (expression.substr(0, 2) == "0x") {
|
||||||
|
return std::stoll(expression, 0, 16);
|
||||||
|
} else if (expression.substr(0, 2) == "0b") {
|
||||||
|
return std::stoll(expression, 0, 2);
|
||||||
|
} else {
|
||||||
|
return std::stoll(expression, 0, 10);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return std::stoll(expression, 0, 10);
|
||||||
|
}
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
domain::InstanceAttribute* attributeValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AttributeDialog(domain::InstanceAttribute *attribute) {
|
AttributeDialog(domain::InstanceAttribute *attribute) {
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
attributeValue = attribute;
|
||||||
|
|
||||||
this->setWindowTitle(QString::fromStdString("Izmjeni " + attribute->attribute.getName()));
|
this->setWindowTitle(QString::fromStdString("Izmjeni " + attribute->attribute.getName()));
|
||||||
|
|
||||||
auto layout = new QVBoxLayout(this);
|
auto layout = new QVBoxLayout(this);
|
||||||
@@ -28,12 +58,29 @@ public:
|
|||||||
layout->addWidget(new QLabel(popup.getText().c_str()));
|
layout->addWidget(new QLabel(popup.getText().c_str()));
|
||||||
|
|
||||||
auto type = attribute->attribute.getDefault().getType();
|
auto type = attribute->attribute.getDefault().getType();
|
||||||
|
value = attribute->value;
|
||||||
|
|
||||||
if(attribute->attribute.getPopup()->isEnumerated()) {
|
if(attribute->attribute.getPopup()->isEnumerated()) {
|
||||||
|
auto* combo = new QComboBox(this);
|
||||||
|
auto enumeration = attribute->attribute.getPopup()->getEnumeration();
|
||||||
|
for(auto entry: enumeration) {
|
||||||
|
combo->addItem(QString::fromStdString(entry.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AttributeDialog::onEnumerationChanged);
|
||||||
|
layout->addWidget(combo);
|
||||||
|
|
||||||
|
for(int i=0; i<enumeration.size(); i++) {
|
||||||
|
if(attributeValue->value.equals(enumeration[i].getValue())) {
|
||||||
|
combo->setCurrentIndex(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if(!(type == domain::Value::ValueType::WIRE_REFERENCE || type == domain::Value::ValueType::BOOL)) {
|
} else if(!(type == domain::Value::ValueType::WIRE_REFERENCE || type == domain::Value::ValueType::BOOL)) {
|
||||||
|
|
||||||
auto edit = new QLineEdit(this);
|
auto edit = new QLineEdit(this);
|
||||||
|
connect(edit, &QLineEdit::textChanged, this, &AttributeDialog::onTextChanged);
|
||||||
layout->addWidget(edit);
|
layout->addWidget(edit);
|
||||||
|
|
||||||
switch (attribute->attribute.getDefault().getType()) {
|
switch (attribute->attribute.getDefault().getType()) {
|
||||||
@@ -46,15 +93,20 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else if(type == domain::Value::ValueType::BOOL) {
|
} else if(type == domain::Value::ValueType::BOOL) {
|
||||||
auto *group = new QGroupBox(this);
|
auto *group = new QGroupBox(this);
|
||||||
group->setCheckable(true);
|
|
||||||
group->setChecked(true);
|
auto *radioLayout = new QHBoxLayout(group);
|
||||||
|
group->setLayout(radioLayout);
|
||||||
|
|
||||||
auto isTrue = new QRadioButton("true", group);
|
auto isTrue = new QRadioButton("true", group);
|
||||||
|
connect(isTrue, &QRadioButton::clicked, [this]() {
|
||||||
|
this->value = domain::Value::fromBool(true);
|
||||||
|
});
|
||||||
auto isFalse = new QRadioButton("false", group);
|
auto isFalse = new QRadioButton("false", group);
|
||||||
|
connect(isFalse, &QRadioButton::clicked, [this]() {
|
||||||
|
this->value = domain::Value::fromBool(false);
|
||||||
|
});
|
||||||
|
|
||||||
if(attribute->value.asBool()) {
|
if(attribute->value.asBool()) {
|
||||||
isTrue->setChecked(true);
|
isTrue->setChecked(true);
|
||||||
@@ -62,14 +114,155 @@ public:
|
|||||||
isFalse->setChecked(true);
|
isFalse->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
radioLayout->addWidget(isTrue);
|
||||||
|
radioLayout->addWidget(isFalse);
|
||||||
layout->addWidget(group);
|
layout->addWidget(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto button = new QPushButton("Ažuriraj");
|
||||||
|
connect(button, &QPushButton::clicked, this, &AttributeDialog::onUpdate);
|
||||||
|
|
||||||
|
layout->addWidget(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onTextChanged(const QString& string) {
|
||||||
|
switch (value.getType()) {
|
||||||
|
case domain::Value::STRING:
|
||||||
|
value.setString(string.toStdString());
|
||||||
|
break;
|
||||||
|
case domain::Value::INT:
|
||||||
|
value = domain::Value::fromInt(parseInt(string.toStdString()));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void onEnumerationChanged(int index) {
|
||||||
|
value = attributeValue->attribute.getPopup()->getEnumeration()[index].getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onUpdate();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class MemoryDialog: public QDialog {
|
||||||
|
domain::Value value;
|
||||||
|
|
||||||
|
domain::InstanceAttribute* attributeValue;
|
||||||
|
std::vector<std::string> memoryInstances;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MemoryDialog(domain::InstanceAttribute *attribute, std::vector<std::shared_ptr<domain::ComponentInstance>> instances) {
|
||||||
|
memoryInstances = std::vector<std::string>();
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
attributeValue = attribute;
|
||||||
|
|
||||||
|
this->setWindowTitle(QString::fromStdString("Izmjeni " + attribute->attribute.getName()));
|
||||||
|
|
||||||
|
for(auto& instance: instances) {
|
||||||
|
if(instance->component.getType() == domain::Component::MEMORY) {
|
||||||
|
memoryInstances.push_back(instance->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto layout = new QVBoxLayout(this);
|
||||||
|
this->setLayout(layout);
|
||||||
|
auto popup = *attribute->attribute.getPopup();
|
||||||
|
|
||||||
|
layout->addWidget(new QLabel(popup.getTitle().c_str()));
|
||||||
|
layout->addWidget(new QLabel(popup.getText().c_str()));
|
||||||
|
|
||||||
|
value = attribute->value;
|
||||||
|
|
||||||
|
auto* combo = new QComboBox(this);
|
||||||
|
for(auto& entry: memoryInstances) {
|
||||||
|
combo->addItem(QString::fromStdString(entry));
|
||||||
|
}
|
||||||
|
combo->addItem("null");
|
||||||
|
|
||||||
|
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MemoryDialog::onMemoryChanged);
|
||||||
|
layout->addWidget(combo);
|
||||||
|
|
||||||
|
combo->setCurrentIndex(memoryInstances.size());
|
||||||
|
for(int i=0; i<memoryInstances.size(); i++) {
|
||||||
|
if(attributeValue->value.asMemoryReference().has_value() && attributeValue->value.asMemoryReference() == memoryInstances[i]) {
|
||||||
|
combo->setCurrentIndex(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto button = new QPushButton("Ažuriraj");
|
||||||
|
connect(button, &QPushButton::clicked, this, &MemoryDialog::onUpdate);
|
||||||
|
|
||||||
|
layout->addWidget(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
void onMemoryChanged(int index) {
|
||||||
|
if(index == memoryInstances.size()) {
|
||||||
|
value = domain::Value::fromMemoryReference(std::nullopt);
|
||||||
|
} else {
|
||||||
|
value = domain::Value::fromMemoryReference(memoryInstances[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onUpdate();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ErrorDialog: public QDialog {
|
||||||
|
|
||||||
|
public:
|
||||||
|
ErrorDialog(std::vector<domain::ValidationError> errors) {
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
this->setWindowTitle("Greške");
|
||||||
|
|
||||||
|
auto layout = new QVBoxLayout(this);
|
||||||
|
this->setLayout(layout);
|
||||||
|
|
||||||
|
for(auto& err: errors) {
|
||||||
|
layout->addWidget(new QLabel(QString::fromStdString(err.message), this));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class WarningDialog: public QDialog {
|
||||||
|
|
||||||
|
public:
|
||||||
|
WarningDialog(domain::ValidationError error) {
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
this->setWindowTitle("Upozorenje");
|
||||||
|
|
||||||
|
auto layout = new QVBoxLayout(this);
|
||||||
|
this->setLayout(layout);
|
||||||
|
|
||||||
|
layout->addWidget(new QLabel(QString::fromStdString(error.message), this));
|
||||||
|
|
||||||
|
auto buttonLayout = new QHBoxLayout(this);
|
||||||
|
|
||||||
|
auto okButton = new QPushButton("U redu", this);
|
||||||
|
auto cancelButton = new QPushButton("Odustani", this);
|
||||||
|
|
||||||
|
connect(okButton, &QPushButton::clicked, [this]() { accept(); });
|
||||||
|
connect(cancelButton, &QPushButton::clicked, [this]() { reject(); });
|
||||||
|
|
||||||
|
buttonLayout->addWidget(okButton);
|
||||||
|
buttonLayout->addWidget(cancelButton);
|
||||||
|
|
||||||
|
layout->addItem(buttonLayout);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //ATTRIBUTE_DIALOG_H
|
#endif //ATTRIBUTE_DIALOG_H
|
||||||
@@ -1,129 +1,160 @@
|
|||||||
#include "component_display.h"
|
#include "component_display.h"
|
||||||
|
#include "attribute_dialog.h"
|
||||||
|
#include "name_dialog.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QLine>
|
||||||
#include <QGraphicsSceneContextMenuEvent>
|
#include <QGraphicsSceneContextMenuEvent>
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "dialogmanager.h"
|
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
ComponentWrapper *ComponentWrapper::ofWire(domain::WireInstance *wire) {
|
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||||
auto component = new ComponentWrapper();
|
|
||||||
component->wireInstance = wire;
|
|
||||||
component->redraw();
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
ComponentWrapper *ComponentWrapper::ofComponent(domain::ComponentInstance *instance) {
|
|
||||||
auto component = new ComponentWrapper();
|
|
||||||
component->componentInstance = instance;
|
|
||||||
component->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
||||||
component->componentItem = new ComponentItem(instance, component);
|
|
||||||
|
|
||||||
for(auto& pin: instance->component.getPins()) {
|
|
||||||
component->pinItems.push_back(new PinItem(pin, component));
|
|
||||||
}
|
|
||||||
|
|
||||||
component->redraw();
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
ComponentWrapper *ComponentWrapper::ofBus(domain::BusInstance *instance) {
|
|
||||||
auto component = new ComponentWrapper();
|
|
||||||
component->busInstance = instance;
|
|
||||||
component->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
||||||
component->redraw();
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
void ComponentWrapper::clear() {
|
|
||||||
for(auto item: childItems()) {
|
|
||||||
this->removeFromGroup(item);
|
|
||||||
item->scene()->removeItem(item);
|
|
||||||
delete item;
|
|
||||||
}
|
|
||||||
if(componentInstance) {
|
|
||||||
componentItem->clear();
|
|
||||||
for(auto pinItem: pinItems) {
|
|
||||||
pinItem->clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ComponentWrapper::redraw() {
|
|
||||||
|
|
||||||
if(componentInstance) {
|
|
||||||
addToGroup(componentItem);
|
|
||||||
componentItem->redraw();
|
|
||||||
for(auto pinItem: pinItems) {
|
|
||||||
addToGroup(pinItem);
|
|
||||||
pinItem->redraw();
|
|
||||||
}
|
|
||||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(componentInstance->name)));
|
|
||||||
}
|
|
||||||
if(busInstance && busInstance->bus.getDisplay()) {
|
|
||||||
busInstance->bus.getDisplay()->render(this);
|
|
||||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(busInstance->name)));
|
|
||||||
}
|
|
||||||
if(wireInstance) {
|
|
||||||
wireInstance->display.render(this);
|
|
||||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(wireInstance->name)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ComponentItem::ComponentItem(domain::ComponentInstance *instance, QGraphicsItem *parent): componentInstance(instance) {
|
|
||||||
setParentItem(parent);
|
|
||||||
redraw();
|
|
||||||
setToolTip(QString::fromStdString(this->componentInstance->component.getTooltip()));
|
|
||||||
}
|
|
||||||
void ComponentItem::redraw() {
|
|
||||||
componentInstance->component.getDisplay().render(this);
|
|
||||||
}
|
|
||||||
void ComponentItem::clear() {
|
|
||||||
for(auto item: childItems()) {
|
|
||||||
this->removeFromGroup(item);
|
|
||||||
item->scene()->removeItem(item);
|
|
||||||
delete item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ComponentItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
auto instance = this->componentInstance;
|
menu.addAction("Izmjeni ime", [this](){
|
||||||
menu.addAction("Izmjeni ime", [instance, this](){
|
auto dialog = new NameDialog(this->instance.get());
|
||||||
DialogManager::updateName(instance);
|
dialog->exec();
|
||||||
auto *wrapper = static_cast<ComponentWrapper*>(this->parentItem());
|
|
||||||
wrapper->clear();
|
|
||||||
wrapper->redraw();
|
|
||||||
});
|
});
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
for(auto attr: componentInstance->attributes) {
|
for(int i=0; i<this->instance->attributes.size(); i++) {
|
||||||
|
auto* attr = &this->instance->attributes[i];
|
||||||
bool enabled = attr->attribute.getPopup().has_value();
|
bool enabled = attr->attribute.getPopup().has_value();
|
||||||
|
|
||||||
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
||||||
[attr, this]() {
|
[attr]() {
|
||||||
DialogManager::updateAttribute(attr);
|
if(attr->value.getType() == domain::Value::MEMORY_REFERENCE) {
|
||||||
|
auto dialog = new MemoryDialog(attr, MainWindow::getSchema()->componentInstances);
|
||||||
this->redraw();
|
dialog->exec();
|
||||||
|
} else {
|
||||||
|
auto dialog = new AttributeDialog(attr);
|
||||||
|
dialog->exec();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
action->setEnabled(enabled);
|
action->setEnabled(enabled);
|
||||||
}
|
}
|
||||||
menu.exec(event->screenPos());
|
menu.exec(event->screenPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
PinItem::PinItem(domain::Pin pin, QGraphicsItem *parent): pin(pin) {
|
void Pin::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||||
setParentItem(parent);
|
QMenu menu;
|
||||||
redraw();
|
menu.addAction("Connect pin", [&]() {});
|
||||||
setToolTip(QString::fromStdString(pin.getTooltip()));
|
menu.exec(event->screenPos());
|
||||||
}
|
}
|
||||||
void PinItem::redraw() {
|
|
||||||
pin.getDisplay().render(this);
|
void Pin::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
}
|
if(event->button() == Qt::MouseButton::LeftButton) {
|
||||||
void PinItem::clear() {
|
auto view = dynamic_cast<Schema*>(this->scene()->views()[0]);
|
||||||
for(auto item: childItems()) {
|
view->state = Schema::CREATING_CONNECTION;
|
||||||
this->removeFromGroup(item);
|
view->context.pin = this;
|
||||||
item->scene()->removeItem(item);
|
view->context.startingPoint = dynamic_cast<ComponentGroup*>(this->parentItem())->pos() + QPointF(pin.getDisplayPin().getConnectionX(), pin.getDisplayPin().getConnectionY());
|
||||||
delete item;
|
view->context.line = new QGraphicsLineItem(QLineF(view->context.startingPoint, event->scenePos()));
|
||||||
|
this->scene()->addItem(view->context.line);
|
||||||
|
|
||||||
|
view->showConnectable(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Pin::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
auto view = dynamic_cast<Schema*>(this->scene()->views()[0]);
|
||||||
|
if(view->state == Schema::CREATING_CONNECTION) {
|
||||||
|
auto line = view->context.line->line();
|
||||||
|
line.setP2(event->scenePos());
|
||||||
|
view->context.line->setLine(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pin::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
if(event->button() == Qt::MouseButton::LeftButton) {
|
||||||
|
auto view = dynamic_cast<Schema*>(this->scene()->views()[0]);
|
||||||
|
view->state = Schema::DEFAULT;
|
||||||
|
this->scene()->removeItem(view->context.line);
|
||||||
|
delete view->context.line;
|
||||||
|
view->removeConnectable(event->scenePos());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||||
|
QMenu menu;
|
||||||
|
menu.addAction("Izmjeni ime", [this](){
|
||||||
|
auto dialog = new NameDialog(this->busInstance.get());
|
||||||
|
dialog->exec();
|
||||||
|
});
|
||||||
|
menu.exec(event->screenPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant BusGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
|
||||||
|
if (change == ItemPositionChange && scene()) {
|
||||||
|
// value is the new position.
|
||||||
|
QPointF newPos = value.toPointF();
|
||||||
|
busInstance->position.first = newPos.x();
|
||||||
|
busInstance->position.second = newPos.y();
|
||||||
|
|
||||||
|
auto view = dynamic_cast<Schema*>(scene()->views()[0]);
|
||||||
|
view->updateConnections();
|
||||||
|
}
|
||||||
|
return QGraphicsItem::itemChange(change, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
BusGroup::BusGroup(const std::shared_ptr<domain::BusInstance> &instance): busInstance(instance) {
|
||||||
|
setFlag(ItemIsMovable, true);
|
||||||
|
setFlag(ItemSendsGeometryChanges, true);
|
||||||
|
|
||||||
|
setHandlesChildEvents(false);
|
||||||
|
|
||||||
|
bus = new display::Bus(instance);
|
||||||
|
addToGroup(bus);
|
||||||
|
|
||||||
|
setPos(instance->position.first, instance->position.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant ComponentGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
|
||||||
|
if (change == ItemPositionChange && scene()) {
|
||||||
|
// value is the new position.
|
||||||
|
QPointF newPos = value.toPointF();
|
||||||
|
componentInstance->position.first = newPos.x();
|
||||||
|
componentInstance->position.second = newPos.y();
|
||||||
|
|
||||||
|
auto view = dynamic_cast<Schema*>(scene()->views()[0]);
|
||||||
|
view->updateConnections();
|
||||||
|
}
|
||||||
|
return QGraphicsItem::itemChange(change, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BusConnection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||||
|
QMenu menu;
|
||||||
|
menu.addAction("Ukloni poveznicu", [this](){});
|
||||||
|
menu.addSeparator();
|
||||||
|
for(int i=0; i<this->connection->attributes.size(); i++) {
|
||||||
|
auto* attr = &this->connection->attributes[i];
|
||||||
|
bool enabled = attr->attribute.getPopup().has_value();
|
||||||
|
|
||||||
|
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
||||||
|
[attr]() {
|
||||||
|
auto dialog = new AttributeDialog(attr);
|
||||||
|
dialog->exec();
|
||||||
|
});
|
||||||
|
action->setEnabled(enabled);
|
||||||
|
}
|
||||||
|
menu.exec(event->screenPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectConnection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||||
|
QMenu menu;
|
||||||
|
menu.addAction("Ukloni poveznicu", [this](){});
|
||||||
|
menu.addSeparator();
|
||||||
|
for(int i=0; i<this->connection->attributes.size(); i++) {
|
||||||
|
auto* attr = &this->connection->attributes[i];
|
||||||
|
bool enabled = attr->attribute.getPopup().has_value();
|
||||||
|
|
||||||
|
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
||||||
|
[attr]() {
|
||||||
|
auto dialog = new AttributeDialog(attr);
|
||||||
|
dialog->exec();
|
||||||
|
});
|
||||||
|
action->setEnabled(enabled);
|
||||||
|
}
|
||||||
|
menu.exec(event->screenPos());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace display
|
} // namespace display
|
||||||
@@ -5,70 +5,171 @@
|
|||||||
#include <comdel/domain/wireinstance.h>
|
#include <comdel/domain/wireinstance.h>
|
||||||
|
|
||||||
#include <QGraphicsItemGroup>
|
#include <QGraphicsItemGroup>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include "comdel/domain/connectioninstance.h"
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
class ComponentItem: public QGraphicsItemGroup
|
class Pin: public QGraphicsItemGroup
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
ComponentItem(domain::ComponentInstance *instance, QGraphicsItem *parent);
|
|
||||||
void redraw();
|
|
||||||
void clear();
|
|
||||||
private:
|
private:
|
||||||
domain::ComponentInstance *componentInstance;
|
domain::Pin pin;
|
||||||
|
std::shared_ptr<domain::ComponentInstance> componentInstance;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Pin(domain::Pin pin, std::shared_ptr<domain::ComponentInstance> componentInstance): pin(pin), componentInstance(componentInstance) {
|
||||||
|
pin.getDisplayPin().render(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|
||||||
|
domain::Pin& getPin() {
|
||||||
|
return pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
domain::ComponentInstance* getComponentInstance() {
|
||||||
|
return componentInstance.get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Component: public QGraphicsItemGroup
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::shared_ptr<domain::ComponentInstance> instance;
|
||||||
|
public:
|
||||||
|
Component(const std::shared_ptr<domain::ComponentInstance>& instance): instance(instance) {
|
||||||
|
setFlag(ItemSendsGeometryChanges, true);
|
||||||
|
|
||||||
|
instance->component.getDisplay().render(this);
|
||||||
|
}
|
||||||
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class Bus: public QGraphicsItemGroup
|
||||||
|
{
|
||||||
|
std::shared_ptr<domain::BusInstance> busInstance;
|
||||||
|
public:
|
||||||
|
Bus(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
||||||
|
instance->bus.getDisplayBus()->render(this, instance->size);
|
||||||
|
}
|
||||||
|
domain::BusInstance *getBusInstance() { return busInstance.get(); }
|
||||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PinItem: public QGraphicsItemGroup
|
class ComponentGroup: public QGraphicsItemGroup
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
PinItem(domain::Pin pin, QGraphicsItem *parent);
|
|
||||||
void redraw();
|
|
||||||
void clear();
|
|
||||||
private:
|
private:
|
||||||
domain::Pin pin;
|
std::shared_ptr<domain::ComponentInstance> componentInstance;
|
||||||
|
std::vector<display::Pin*> pins;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
std::shared_ptr<domain::ComponentInstance> getComponentInstance() { return componentInstance; }
|
||||||
|
std::vector<display::Pin*>& getPins() { return pins; }
|
||||||
|
|
||||||
|
explicit ComponentGroup(const std::shared_ptr<domain::ComponentInstance>& instance): componentInstance(instance) {
|
||||||
|
setFlag(ItemIsMovable, true);
|
||||||
|
setFlag(ItemSendsGeometryChanges, true);
|
||||||
|
|
||||||
|
setHandlesChildEvents(false);
|
||||||
|
|
||||||
|
addToGroup(new display::Component(instance));
|
||||||
|
|
||||||
|
for(auto &pin: instance->component.getPins()) {
|
||||||
|
pins.push_back(new display::Pin(pin, componentInstance));
|
||||||
|
addToGroup(pins.back());
|
||||||
|
}
|
||||||
|
|
||||||
|
setPos(instance->position.first, instance->position.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ComponentWrapper: public QGraphicsItemGroup
|
class BusGroup: public QGraphicsItemGroup
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
static ComponentWrapper *ofComponent(domain::ComponentInstance *instance);
|
|
||||||
static ComponentWrapper *ofBus(domain::BusInstance *instance);
|
|
||||||
static ComponentWrapper *ofWire(domain::WireInstance *wire);
|
|
||||||
|
|
||||||
ComponentWrapper() {
|
|
||||||
this->setHandlesChildEvents(false);
|
|
||||||
}
|
|
||||||
void redraw();
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
|
|
||||||
QVariant itemChange( GraphicsItemChange change, const QVariant &value ) override
|
|
||||||
{
|
|
||||||
auto response = QGraphicsItem::itemChange(change, value);
|
|
||||||
if (change == ItemPositionChange){
|
|
||||||
if(componentInstance != nullptr) {
|
|
||||||
componentInstance->position.first = (int)scenePos().x();
|
|
||||||
componentInstance->position.second = (int)scenePos().y();
|
|
||||||
} else if(busInstance != nullptr) {
|
|
||||||
busInstance->position.first = (int)scenePos().x();
|
|
||||||
busInstance->position.second = (int)scenePos().y();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
domain::ComponentInstance *componentInstance = nullptr;
|
std::shared_ptr<domain::BusInstance> busInstance;
|
||||||
domain::BusInstance *busInstance = nullptr;
|
display::Bus* bus;
|
||||||
domain::WireInstance *wireInstance = nullptr;
|
|
||||||
|
|
||||||
ComponentItem *componentItem;
|
public:
|
||||||
std::vector<PinItem*> pinItems;
|
explicit BusGroup(const std::shared_ptr<domain::BusInstance>& instance);
|
||||||
|
|
||||||
|
display::Bus* getBus() { return bus; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class BusConnection: public QGraphicsLineItem
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
domain::BusConnectionInstance* connection;
|
||||||
|
ComponentGroup* component;
|
||||||
|
BusGroup* bus;
|
||||||
|
|
||||||
|
public:
|
||||||
|
BusConnection(domain::BusConnectionInstance* connection, ComponentGroup *component, BusGroup *bus): connection(connection), component(component), bus(bus) {
|
||||||
|
updateConnection();
|
||||||
|
|
||||||
|
setHandlesChildEvents(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateConnection() {
|
||||||
|
auto busPosition = bus->boundingRect();
|
||||||
|
auto pin = connection->instance->component.getPin(connection->connection.getComponent().pin).getDisplayPin();
|
||||||
|
|
||||||
|
setLine(connection->instance->position.first + pin.getConnectionX(), connection->instance->position.second + pin.getConnectionY(), connection->bus->position.first + busPosition.width()/2, connection->bus->position.second + busPosition.height()/2);
|
||||||
|
|
||||||
|
connection->start.first = connection->instance->position.first + pin.getConnectionX();
|
||||||
|
connection->start.second = connection->instance->position.second + pin.getConnectionY();
|
||||||
|
connection->end.first = connection->bus->position.first + busPosition.width()/2;
|
||||||
|
connection->end.second = connection->bus->position.second + busPosition.height()/2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class DirectConnection: public QGraphicsLineItem
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
domain::DirectConnectionInstance* connection;
|
||||||
|
ComponentGroup* first;
|
||||||
|
ComponentGroup* second;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DirectConnection(domain::DirectConnectionInstance* connection, ComponentGroup *first, ComponentGroup *second): connection(connection), first(first), second(second) {
|
||||||
|
updateConnection();
|
||||||
|
setHandlesChildEvents(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateConnection() {
|
||||||
|
auto pin1 = connection->instance->component.getPin(connection->connection.getComponent().pin).getDisplayPin();
|
||||||
|
auto pin2 = connection->secondInstance->component.getPin(connection->connection.getSecondComponent()->pin).getDisplayPin();
|
||||||
|
|
||||||
|
setLine(connection->instance->position.first + pin1.getConnectionX(), connection->instance->position.second + pin1.getConnectionY(),
|
||||||
|
connection->secondInstance->position.first + pin2.getConnectionX(), connection->secondInstance->position.second + pin2.getConnectionY());
|
||||||
|
|
||||||
|
connection->start.first = connection->instance->position.first + pin1.getConnectionX();
|
||||||
|
connection->start.second = connection->instance->position.second + pin1.getConnectionY();
|
||||||
|
connection->end.first = connection->secondInstance->position.first + pin2.getConnectionX();
|
||||||
|
connection->end.second = connection->secondInstance->position.second + pin2.getConnectionY();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace display
|
} // namespace display
|
||||||
|
|
||||||
#endif // DISPLAY_COMPONENT_H
|
#endif // DISPLAY_COMPONENT_H
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by bbr on 18. 04. 2022..
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "dialogmanager.h"
|
|
||||||
#include "attribute_dialog.h"
|
|
||||||
#include "name_dialog.h"
|
|
||||||
|
|
||||||
namespace display {
|
|
||||||
|
|
||||||
void DialogManager::updateAttribute(domain::InstanceAttribute *attribute) {
|
|
||||||
auto dialog = new AttributeDialog(attribute);
|
|
||||||
dialog->exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DialogManager::updateName(domain::ComponentInstance *instance) {
|
|
||||||
auto dialog = new NameDialog(instance);
|
|
||||||
dialog->exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef DIALOG_MANAGER_H
|
|
||||||
#define DIALOG_MANAGER_H
|
|
||||||
|
|
||||||
#include <comdel/domain/instanceattribute.h>
|
|
||||||
#include <comdel/domain/instance.h>
|
|
||||||
|
|
||||||
namespace display {
|
|
||||||
|
|
||||||
class DialogManager {
|
|
||||||
public:
|
|
||||||
static void updateAttribute(domain::InstanceAttribute *attribute);
|
|
||||||
|
|
||||||
static void updateName(domain::ComponentInstance *instance);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //DIALOG_MANAGER_H
|
|
||||||
@@ -11,8 +11,8 @@ Library::Library()
|
|||||||
auto layout = new QVBoxLayout();
|
auto layout = new QVBoxLayout();
|
||||||
this->setLayout(layout);
|
this->setLayout(layout);
|
||||||
|
|
||||||
componentList = new QListWidget();
|
componentList = new LibraryList(this);
|
||||||
busList = new QListWidget();
|
busList = new LibraryList(this);
|
||||||
|
|
||||||
layout->setMargin(4);
|
layout->setMargin(4);
|
||||||
layout->addWidget(new QLabel("Components:"));
|
layout->addWidget(new QLabel("Components:"));
|
||||||
@@ -34,14 +34,14 @@ void Library::setLibrary(std::optional<domain::Library> library) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(auto& component: library->getComponents()) {
|
for(auto& component: library->getComponents()) {
|
||||||
auto item = new QListWidgetItem{QString::fromStdString(component.getName())};
|
auto item = new LibraryListItem{component.getName(), "comdel/component", component.getName(), componentList};
|
||||||
item->setToolTip(QString::fromStdString(component.getTooltip()));
|
item->setToolTip(QString::fromStdString(component.getTooltip()));
|
||||||
componentList->addItem(item);
|
componentList->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto& bus: library->getBuses()) {
|
for(auto& bus: library->getBuses()) {
|
||||||
if(bus.getType() == domain::Bus::REGULAR) {
|
if(bus.getType() == domain::Bus::REGULAR) {
|
||||||
auto item = new QListWidgetItem{QString::fromStdString(bus.getName())};
|
auto item = new LibraryListItem{bus.getName(), "comdel/bus", bus.getName(), busList};
|
||||||
item->setToolTip(QString::fromStdString(bus.getTooltip()));
|
item->setToolTip(QString::fromStdString(bus.getTooltip()));
|
||||||
busList->addItem(item);
|
busList->addItem(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include <comdel/domain/library.h>
|
#include <comdel/domain/library.h>
|
||||||
|
#include "library_list.h"
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
@@ -18,8 +19,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::optional<domain::Library> library;
|
std::optional<domain::Library> library;
|
||||||
|
|
||||||
QListWidget *componentList;
|
LibraryList *componentList;
|
||||||
QListWidget *busList;
|
LibraryList *busList;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// Created by bbr on 22.05.22..
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "library_list.h"
|
||||||
|
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QDrag>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
|
namespace display {
|
||||||
|
|
||||||
|
LibraryList::LibraryList(QWidget *parent): QListWidget(parent) {
|
||||||
|
setDragDropMode(DragOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
QMimeData *LibraryList::mimeData(const QList<QListWidgetItem *> items) const {
|
||||||
|
for(auto qItem: items) {
|
||||||
|
// we only allow one item to be dragged at a time
|
||||||
|
auto item = dynamic_cast<LibraryListItem*>(qItem);
|
||||||
|
auto* md = new QMimeData();
|
||||||
|
md->setData(QString::fromStdString(item->mimeType), QByteArray::fromStdString(item->value));
|
||||||
|
return md;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
LibraryListItem::LibraryListItem(std::string title, std::string mimeType, std::string value, QListWidget *parent): QListWidgetItem(parent), mimeType(mimeType), value(value) {
|
||||||
|
setText(QString::fromStdString(title));
|
||||||
|
}
|
||||||
|
} // display
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// Created by bbr on 22.05.22..
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SCHEMEEDITOR_LIBRARY_LIST_H
|
||||||
|
#define SCHEMEEDITOR_LIBRARY_LIST_H
|
||||||
|
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QList>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
|
namespace display {
|
||||||
|
|
||||||
|
class LibraryList: public QListWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
LibraryList(QWidget *parent);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QMimeData *mimeData(const QList<QListWidgetItem*> items) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class LibraryListItem: public QListWidgetItem {
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string mimeType;
|
||||||
|
std::string value;
|
||||||
|
|
||||||
|
LibraryListItem(std::string title, std::string mimeType, std::string value, QListWidget *parent);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // display
|
||||||
|
|
||||||
|
#endif //SCHEMEEDITOR_LIBRARY_LIST_H
|
||||||
@@ -13,12 +13,27 @@ namespace display {
|
|||||||
|
|
||||||
class NameDialog: public QDialog {
|
class NameDialog: public QDialog {
|
||||||
|
|
||||||
QLineEdit *edit;
|
QLineEdit *edit = nullptr;
|
||||||
domain::ComponentInstance *instance;
|
domain::ComponentInstance *componentInstance = nullptr;
|
||||||
|
domain::BusInstance *busInstance = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
NameDialog(domain::ComponentInstance *instance): instance(instance) {
|
NameDialog(domain::ComponentInstance *instance): componentInstance(instance) {
|
||||||
|
auto *layout = new QVBoxLayout(this);
|
||||||
|
layout->addWidget(new QLabel("Izmjeni ime", this));
|
||||||
|
|
||||||
|
edit = new QLineEdit(this);
|
||||||
|
edit->insert(instance->name.c_str());
|
||||||
|
layout->addWidget(edit);
|
||||||
|
this->setWindowTitle("Izmjeni ime");
|
||||||
|
auto *button = new QPushButton("Ažuriraj", this);
|
||||||
|
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
||||||
|
layout->addWidget(button);
|
||||||
|
this->setLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
NameDialog(domain::BusInstance *instance): busInstance(instance) {
|
||||||
auto *layout = new QVBoxLayout(this);
|
auto *layout = new QVBoxLayout(this);
|
||||||
layout->addWidget(new QLabel("Izmjeni ime", this));
|
layout->addWidget(new QLabel("Izmjeni ime", this));
|
||||||
|
|
||||||
@@ -34,7 +49,11 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onNameChange() {
|
void onNameChange() {
|
||||||
instance->name = this->edit->text().toStdString();
|
if(componentInstance != nullptr) {
|
||||||
|
componentInstance->name = this->edit->text().toStdString();
|
||||||
|
} else if(busInstance != nullptr) {
|
||||||
|
busInstance->name = this->edit->text().toStdString();
|
||||||
|
}
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,40 +1,264 @@
|
|||||||
#include "component_display.h"
|
#include "component_display.h"
|
||||||
#include "schema_display.h"
|
#include "schema_display.h"
|
||||||
|
|
||||||
|
#include <QDrag>
|
||||||
|
#include <QDragEnterEvent>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
Schema::Schema()
|
Schema::Schema()
|
||||||
{
|
{
|
||||||
|
this->selectedBrush.setColor(QColor::fromRgb(20,20,125));
|
||||||
|
this->selectedPen.setColor(QColor::fromRgb(20, 20, 125));
|
||||||
|
|
||||||
this->setScene(&scene);
|
this->setScene(&scene);
|
||||||
|
this->setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Schema::setSchema(domain::Schema* schema)
|
void Schema::setSchema(domain::Schema* _schema, domain::Library* _library)
|
||||||
{
|
{
|
||||||
|
components.clear();
|
||||||
|
buses.clear();
|
||||||
|
|
||||||
scene.clear();
|
scene.clear();
|
||||||
this->schema = schema;
|
busConnections.clear();
|
||||||
|
this->schema = _schema;
|
||||||
|
this->library = _library;
|
||||||
if(schema != nullptr) {
|
if(schema != nullptr) {
|
||||||
for(auto &instance: schema->instances) {
|
for(auto &instance: schema->componentInstances) {
|
||||||
ComponentWrapper *group = nullptr;
|
auto group = new display::ComponentGroup(instance);
|
||||||
auto component = dynamic_cast<domain::ComponentInstance*>(instance);
|
for(auto pin: group->getPins()) {
|
||||||
if(component) {
|
display::Pin* p = pin;
|
||||||
group = ComponentWrapper::ofComponent(component);
|
domain::ConnectionComponent connection{instance->name, p->getPin().getName()};
|
||||||
|
pins.insert(std::make_pair(connection, p));
|
||||||
}
|
}
|
||||||
auto bus = dynamic_cast<domain::BusInstance*>(instance);
|
components.insert(std::make_pair(instance->name, group));
|
||||||
if(bus) {
|
scene.addItem(group);
|
||||||
group = ComponentWrapper::ofBus(bus);
|
|
||||||
}
|
}
|
||||||
if(group != nullptr) {
|
for(auto &instance: schema->busInstances) {
|
||||||
group->setPos(instance->position.first, instance->position.second);
|
if(instance->bus.getDisplayBus().has_value()) {
|
||||||
|
auto group = new display::BusGroup(instance);
|
||||||
|
buses.insert(std::make_pair(instance->name, group));
|
||||||
scene.addItem(group);
|
scene.addItem(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(auto &wire: schema->wires) {
|
for(auto &connection: schema->connections) {
|
||||||
auto group = ComponentWrapper::ofWire(wire);
|
auto busInstance = dynamic_cast<domain::BusConnectionInstance*>(connection.get());
|
||||||
group->setPos(wire->position.first, wire->position.second);
|
if(busInstance != nullptr) {
|
||||||
|
auto con = new display::BusConnection(busInstance, components[busInstance->instance->name], buses[busInstance->bus->name]);
|
||||||
|
busConnections.push_back(con);
|
||||||
|
scene.addItem(con);
|
||||||
|
}
|
||||||
|
auto directInstance = dynamic_cast<domain::DirectConnectionInstance*>(connection.get());
|
||||||
|
if(directInstance != nullptr) {
|
||||||
|
auto con = new display::DirectConnection(directInstance, components[directInstance->instance->name], components[directInstance->secondInstance->name]);
|
||||||
|
directConnections.push_back(con);
|
||||||
|
scene.addItem(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Schema::updateConnections() {
|
||||||
|
if(schema != nullptr) {
|
||||||
|
for(auto conn: busConnections) {
|
||||||
|
conn->updateConnection();
|
||||||
|
}
|
||||||
|
for(auto conn: directConnections) {
|
||||||
|
conn->updateConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Schema::dragEnterEvent(QDragEnterEvent *event) {
|
||||||
|
if(event->mimeData()->hasFormat("comdel/component") ||
|
||||||
|
event->mimeData()->hasFormat("comdel/bus")) {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Schema::dropEvent(QDropEvent *event) {
|
||||||
|
if(event->mimeData()->hasFormat("comdel/component")) {
|
||||||
|
auto component = library->getComponent(event->mimeData()->data("comdel/component").toStdString());
|
||||||
|
|
||||||
|
auto attributes = std::vector<domain::InstanceAttribute>();
|
||||||
|
for(auto attr: component.getAttributes()) {
|
||||||
|
attributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto currentPos = this->mapToScene(event->pos());
|
||||||
|
|
||||||
|
auto instance = std::make_shared<domain::ComponentInstance>(component.getInstanceName(), attributes, std::make_pair(currentPos.x(), currentPos.y()), component);
|
||||||
|
schema->componentInstances.push_back(instance);
|
||||||
|
|
||||||
|
auto group = new display::ComponentGroup(instance);
|
||||||
scene.addItem(group);
|
scene.addItem(group);
|
||||||
|
for(auto pin: group->getPins()) {
|
||||||
|
display::Pin* p = pin;
|
||||||
|
domain::ConnectionComponent connection{instance->name, p->getPin().getName()};
|
||||||
|
pins.insert(std::make_pair(connection, p));
|
||||||
|
}
|
||||||
|
|
||||||
|
components[instance->name] = group;
|
||||||
|
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
if(event->mimeData()->hasFormat("comdel/bus")) {
|
||||||
|
auto bus = library->getBus(event->mimeData()->data("comdel/bus").toStdString());
|
||||||
|
|
||||||
|
auto currentPos = this->mapToScene(event->pos());
|
||||||
|
|
||||||
|
auto instance = std::make_shared<domain::BusInstance>(bus.getName(), std::make_pair(currentPos.x(), currentPos.y()), bus);
|
||||||
|
schema->busInstances.push_back(instance);
|
||||||
|
|
||||||
|
auto group = new display::BusGroup(instance);
|
||||||
|
scene.addItem(group);
|
||||||
|
buses[instance->name] = group;
|
||||||
|
|
||||||
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Schema::dragMoveEvent(QDragMoveEvent *event) {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Schema::removeConnectable(QPointF endPoint) {
|
||||||
|
auto instance = context.pin->getComponentInstance();
|
||||||
|
auto& pin = context.pin->getPin();
|
||||||
|
|
||||||
|
auto busInstances = getAvailableConnectionBusses(instance, pin);
|
||||||
|
|
||||||
|
for(auto &bus: busInstances) {
|
||||||
|
auto rect = buses[bus->name]->boundingRect();
|
||||||
|
rect = QRectF(buses[bus->name]->x(), buses[bus->name]->y(), rect.width(), rect.height());
|
||||||
|
|
||||||
|
if(rect.contains(endPoint)) {
|
||||||
|
auto con = library->getConnection({instance->component.getName(), pin.getName()}, bus->bus.getName());
|
||||||
|
if(con.has_value()) {
|
||||||
|
std::vector<domain::InstanceAttribute> attributes;
|
||||||
|
for(auto attr: con->getAttributes()) {
|
||||||
|
attributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto conInstance = std::make_shared<domain::BusConnectionInstance>(instance, attributes, bus, *con);
|
||||||
|
schema->connections.push_back(conInstance);
|
||||||
|
|
||||||
|
if (conInstance != nullptr) {
|
||||||
|
auto c = new display::BusConnection(conInstance.get(), components[conInstance->instance->name],
|
||||||
|
buses[conInstance->bus->name]);
|
||||||
|
busConnections.push_back(c);
|
||||||
|
scene.addItem(c);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pinInstances = getAvailableConnectionPins(instance, pin);
|
||||||
|
|
||||||
|
for(auto &pinInstance: pinInstances) {
|
||||||
|
auto rect = pins[pinInstance]->boundingRect();
|
||||||
|
rect.setX(pins[pinInstance]->scenePos().x());
|
||||||
|
rect.setY(pins[pinInstance]->scenePos().y());
|
||||||
|
|
||||||
|
if(rect.contains(endPoint)) {
|
||||||
|
auto name = components[pinInstance.component]->getComponentInstance()->component.getName();
|
||||||
|
auto con = library->getConnection({instance->component.getName(), pin.getName()}, {name, pinInstance.pin});
|
||||||
|
if(con.has_value()) {
|
||||||
|
auto bus = library->getBus(con->getBus());
|
||||||
|
auto busInstance = std::make_shared<domain::BusInstance>(bus.getName(), bus);
|
||||||
|
schema->busInstances.push_back(busInstance);
|
||||||
|
|
||||||
|
std::vector<domain::InstanceAttribute> attributes;
|
||||||
|
for(auto attr: con->getAttributes()) {
|
||||||
|
attributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto conInstance = std::make_shared<domain::DirectConnectionInstance>(instance, components[pinInstance.component]->getComponentInstance().get(), attributes, busInstance.get(), *con);
|
||||||
|
schema->connections.push_back(conInstance);
|
||||||
|
|
||||||
|
if (conInstance != nullptr) {
|
||||||
|
auto c = new display::DirectConnection(conInstance.get(), components[conInstance->instance->name], components[conInstance->secondInstance->name]);
|
||||||
|
directConnections.push_back(c);
|
||||||
|
scene.addItem(c);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateConnections();
|
||||||
|
|
||||||
|
|
||||||
|
for(auto& item: this->context.selectable) {
|
||||||
|
this->scene.removeItem(item);
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
this->context.selectable.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Schema::showConnectable(Pin *domainPin) {
|
||||||
|
auto& pin = domainPin->getPin();
|
||||||
|
|
||||||
|
auto busInstances = getAvailableConnectionBusses(domainPin->getComponentInstance(), domainPin->getPin());
|
||||||
|
|
||||||
|
for(auto bus: busInstances) {
|
||||||
|
auto& group = buses[bus->name];
|
||||||
|
auto rect = new QGraphicsRectItem(group->boundingRect());
|
||||||
|
rect->setPen(selectedPen);
|
||||||
|
rect->setPos(group->scenePos());
|
||||||
|
|
||||||
|
auto _rect = rect->rect();
|
||||||
|
_rect.setWidth(_rect.width() + 1);
|
||||||
|
_rect.setHeight(_rect.height() + 1);
|
||||||
|
rect->setRect(_rect);
|
||||||
|
|
||||||
|
context.selectable.push_back(rect);
|
||||||
|
scene.addItem(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<domain::ConnectionComponent> pinInstances = getAvailableConnectionPins(domainPin->getComponentInstance(), domainPin->getPin());
|
||||||
|
|
||||||
|
for(auto& pinInstance: pinInstances) {
|
||||||
|
auto& instance = pins[pinInstance];
|
||||||
|
auto rect = new QGraphicsRectItem(instance->boundingRect());
|
||||||
|
rect->setPen(selectedPen);
|
||||||
|
rect->setPos(instance->scenePos());
|
||||||
|
|
||||||
|
auto _rect = rect->rect();
|
||||||
|
_rect.setWidth(_rect.width() + 1);
|
||||||
|
_rect.setHeight(_rect.height() + 1);
|
||||||
|
rect->setRect(_rect);
|
||||||
|
|
||||||
|
context.selectable.push_back(rect);
|
||||||
|
scene.addItem(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<domain::BusInstance*> Schema::getAvailableConnectionBusses(domain::ComponentInstance *instance, domain::Pin &pin) {
|
||||||
|
std::vector<domain::BusInstance*> instances;
|
||||||
|
for(const auto& bus: schema->busInstances) {
|
||||||
|
if(library->hasConnection(domain::ConnectionComponent{instance->component.getName(), pin.getName()}, bus->bus.getName())) {
|
||||||
|
instances.push_back(bus.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<domain::ConnectionComponent> Schema::getAvailableConnectionPins(domain::ComponentInstance *instance, domain::Pin &pin) {
|
||||||
|
std::vector<domain::ConnectionComponent> instances;
|
||||||
|
domain::ConnectionComponent source{instance->component.getName(), pin.getName()};
|
||||||
|
for(const auto& entry: pins) {
|
||||||
|
std::string name = components[entry.first.component]->getComponentInstance()->component.getName();
|
||||||
|
if(library->hasConnection(source, domain::ConnectionComponent{name, entry.first.pin})) {
|
||||||
|
instances.push_back(entry.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instances;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace display
|
} // namespace display
|
||||||
@@ -4,23 +4,72 @@
|
|||||||
|
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
|
|
||||||
#include <comdel/domain/schema.h>
|
#include <comdel/domain/schema.h>
|
||||||
|
#include <comdel/domain/library.h>
|
||||||
|
#include "component_display.h"
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
|
class BusConnection;
|
||||||
|
|
||||||
class Schema: public QGraphicsView
|
class Schema: public QGraphicsView
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
QBrush selectedBrush;
|
||||||
|
QPen selectedPen;
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
DEFAULT,
|
||||||
|
CREATING_CONNECTION
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Context {
|
||||||
|
display::Pin *pin = nullptr;
|
||||||
|
QPointF startingPoint;
|
||||||
|
QGraphicsLineItem *line = nullptr;
|
||||||
|
std::vector<QGraphicsRectItem*> selectable;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::map<std::string, display::ComponentGroup*> components;
|
||||||
|
std::map<std::string, display::BusGroup*> buses;
|
||||||
|
std::map<domain::ConnectionComponent, display::Pin*> pins;
|
||||||
|
|
||||||
|
State state = DEFAULT;
|
||||||
|
Context context;
|
||||||
|
|
||||||
Schema();
|
Schema();
|
||||||
|
|
||||||
void setSchema(domain::Schema* schema);
|
std::vector<BusConnection*> busConnections;
|
||||||
|
std::vector<DirectConnection*> directConnections;
|
||||||
|
|
||||||
|
void setSchema(domain::Schema* schema, domain::Library* library);
|
||||||
|
|
||||||
|
void updateConnections();
|
||||||
|
|
||||||
|
void removeConnectable(QPointF f);
|
||||||
|
|
||||||
|
void showConnectable(Pin *pin);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
|
void dropEvent(QDropEvent *event) override;
|
||||||
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QGraphicsScene scene;
|
QGraphicsScene scene;
|
||||||
|
|
||||||
domain::Schema* schema;
|
domain::Schema* schema;
|
||||||
|
domain::Library* library;
|
||||||
|
|
||||||
|
std::vector<domain::BusInstance*> getAvailableConnectionBusses(domain::ComponentInstance *instance, domain::Pin &pin);
|
||||||
|
|
||||||
|
std::vector<domain::ConnectionComponent> getAvailableConnectionPins(domain::ComponentInstance *instance, domain::Pin &pin);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace display
|
} // namespace display
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <algorithm>
|
||||||
#include "addressspace.h"
|
#include "addressspace.h"
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Enumeration::Enumeration(std::string name, Value value)
|
|||||||
: name(name), value(value)
|
: name(name), value(value)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string Enumeration::getName() {
|
std::string& Enumeration::getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
Value Enumeration::getValue() {
|
Value Enumeration::getValue() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef DOMAIN_ATTRIBUTE_H
|
#ifndef DOMAIN_ATTRIBUTE_H
|
||||||
#define DOMAIN_ATTRIBUTE_H
|
#define DOMAIN_ATTRIBUTE_H
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "rule.h"
|
#include "rule.h"
|
||||||
@@ -14,7 +15,7 @@ class Enumeration {
|
|||||||
public:
|
public:
|
||||||
Enumeration(std::string name, Value value);
|
Enumeration(std::string name, Value value);
|
||||||
|
|
||||||
std::string getName();
|
std::string& getName();
|
||||||
Value getValue();
|
Value getValue();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -45,6 +46,11 @@ public:
|
|||||||
bool isEnumerated();
|
bool isEnumerated();
|
||||||
std::vector<Enumeration> &getEnumeration();
|
std::vector<Enumeration> &getEnumeration();
|
||||||
|
|
||||||
|
void setEnumeration(std::vector<Enumeration> enums) {
|
||||||
|
enumerated = true;
|
||||||
|
enumeration = std::move(enums);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Attribute
|
class Attribute
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ Wire::WireType Wire::getType() {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bus::Bus(std::string name, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires, std::optional<Display> display)
|
Bus::Bus(std::string name, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires, std::optional<ui::Bus> displayBus)
|
||||||
: name(name), tooltip(tooltip), type(type), count(count), wires(wires), display(display)
|
: name(name), tooltip(tooltip), type(type), count(count), wires(wires), displayBus(displayBus)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string Bus::getName() {
|
std::string Bus::getName() {
|
||||||
@@ -42,12 +42,11 @@ Bus::BusType Bus::getType() {
|
|||||||
std::pair<int, int> Bus::getCount() {
|
std::pair<int, int> Bus::getCount() {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
std::optional<Display> Bus::getDisplay() {
|
|
||||||
return display;
|
|
||||||
}
|
|
||||||
std::vector<Wire> Bus::getWires() {
|
std::vector<Wire> Bus::getWires() {
|
||||||
return wires;
|
return wires;
|
||||||
}
|
}
|
||||||
|
std::optional<ui::Bus> Bus::getDisplayBus() {
|
||||||
|
return displayBus;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
+4
-4
@@ -47,7 +47,7 @@ public:
|
|||||||
enum BusType {
|
enum BusType {
|
||||||
AUTOMATIC,
|
AUTOMATIC,
|
||||||
REGULAR,
|
REGULAR,
|
||||||
AUTOMATIC_SINGLE
|
SINGLE_AUTOMATIC
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
std::string name;
|
std::string name;
|
||||||
@@ -55,18 +55,18 @@ private:
|
|||||||
BusType type;
|
BusType type;
|
||||||
|
|
||||||
std::pair<int, int> count;
|
std::pair<int, int> count;
|
||||||
std::optional<Display> display;
|
std::optional<ui::Bus> displayBus;
|
||||||
std::vector<Wire> wires;
|
std::vector<Wire> wires;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Bus(std::string name, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires, std::optional<Display> display = std::nullopt);
|
Bus(std::string name, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires, std::optional<ui::Bus> display = std::nullopt);
|
||||||
|
|
||||||
std::string getName();
|
std::string getName();
|
||||||
std::string getTooltip();
|
std::string getTooltip();
|
||||||
BusType getType();
|
BusType getType();
|
||||||
std::pair<int, int> getCount();
|
std::pair<int, int> getCount();
|
||||||
std::vector<Wire> getWires();
|
std::vector<Wire> getWires();
|
||||||
std::optional<Display> getDisplay();
|
std::optional<ui::Bus> getDisplayBus();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|||||||
@@ -0,0 +1,351 @@
|
|||||||
|
//
|
||||||
|
// Created by bbr on 08.05.22..
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include "comdel_generator.h"
|
||||||
|
|
||||||
|
namespace domain {
|
||||||
|
|
||||||
|
void generateSchemaFile(std::string& librarySource, Schema *schema, std::ostream &buffer) {
|
||||||
|
buffer << "@source " << librarySource << std::endl << std::endl;
|
||||||
|
|
||||||
|
buffer << "@schema {" << std::endl;
|
||||||
|
|
||||||
|
for(auto &componentInstance: schema->componentInstances) {
|
||||||
|
buffer << "\t" << "@instance " << componentInstance->name << " " << componentInstance->component.getName() << " {" << std::endl;
|
||||||
|
buffer << "\t\t" << "@position (" << componentInstance->position.first << ", " << componentInstance->position.second << ")" << std::endl;
|
||||||
|
|
||||||
|
for(auto &attribute: componentInstance->attributes) {
|
||||||
|
buffer << "\t\t" << "@attribute " << attribute.name << " " << attribute.value.stringify() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer << "\t}" << std::endl << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto &busInstance: schema->busInstances) {
|
||||||
|
buffer << "\t" << "@instance " << busInstance->name << " " << busInstance->bus.getName() << " {" << std::endl;
|
||||||
|
buffer << "\t\t" << "@position (" << busInstance->position.first << ", " << busInstance->position.second << ")" << std::endl;
|
||||||
|
buffer << "\t\t" << "@size " << busInstance->size << std::endl;
|
||||||
|
buffer << "\t}" << std::endl << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto &conn: schema->connections) {
|
||||||
|
auto busConn = dynamic_cast<domain::BusConnectionInstance*>(conn.get());
|
||||||
|
if(busConn) {
|
||||||
|
buffer << "\t" << "@connection (" << busConn->instance->name << "." << busConn->connection.getComponent().pin << ", " << busConn->bus->name << ") {" << std::endl;
|
||||||
|
|
||||||
|
for(auto attribute: busConn->attributes) {
|
||||||
|
buffer << "\t\t" << "@attribute " << attribute.name << " " << attribute.value.stringify() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer << "\t" << "}" << std::endl;
|
||||||
|
}
|
||||||
|
auto dirConn = dynamic_cast<domain::DirectConnectionInstance*>(conn.get());
|
||||||
|
if(dirConn) {
|
||||||
|
buffer << "\t" << "@connection (" << dirConn->instance->name << "." << dirConn->connection.getComponent().pin << ", "
|
||||||
|
<< dirConn->bus->name << ", "
|
||||||
|
<< dirConn->secondInstance->name << "." << dirConn->connection.getSecondComponent()->pin
|
||||||
|
<< ") {" << std::endl;
|
||||||
|
|
||||||
|
for(auto attribute: dirConn->attributes) {
|
||||||
|
buffer << "\t\t" << "@attribute " << attribute.name << " " << attribute.value.stringify() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer << "\t" << "}" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer << "}" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<std::string> createImports(Schema *schema);
|
||||||
|
|
||||||
|
std::map<string, string> generateWires(Schema *schema, ostream &ostream);
|
||||||
|
|
||||||
|
void generateSubComponents(Schema *schema, map <string, string> &wires, ostream &buffer);
|
||||||
|
|
||||||
|
void generateDisplay(Schema *schema, ostream &buffer);
|
||||||
|
|
||||||
|
void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer) {
|
||||||
|
buffer << library.getHeader() << std::endl;
|
||||||
|
|
||||||
|
std::set<std::string> imports = createImports(schema);
|
||||||
|
|
||||||
|
for(auto& import: imports) {
|
||||||
|
buffer << "#include \"" << library.getComponentDirectory() << "\\" << import << "\"" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer << "\n\n" << std::endl;
|
||||||
|
|
||||||
|
buffer << "component System" << std::endl << "{" << std::endl;
|
||||||
|
|
||||||
|
if(library.getComponentHeader().has_value()) {
|
||||||
|
buffer << library.getComponentHeader().value() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto wires = generateWires(schema, buffer);
|
||||||
|
|
||||||
|
generateSubComponents(schema, wires, buffer);
|
||||||
|
|
||||||
|
generateDisplay(schema, buffer);
|
||||||
|
|
||||||
|
buffer << "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateBus(BusInstance *bus, ostream &buffer);
|
||||||
|
void generateConnection(ConnectionInstance *connection, ostream &buffer);
|
||||||
|
|
||||||
|
void generateDisplay(Schema *schema, ostream &buffer) {
|
||||||
|
buffer << "\n\tdisplay {\n";
|
||||||
|
|
||||||
|
for(auto &component: schema->componentInstances) {
|
||||||
|
buffer << "\t\tcomponent { x: " << component->position.first << "; y: " << component->position.second << "; ref: \"" << component->name << "\"; }" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto &bus: schema->busInstances) {
|
||||||
|
generateBus(bus.get(), buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer << "\n";
|
||||||
|
|
||||||
|
for(auto &connection: schema->connections) {
|
||||||
|
generateConnection(connection.get(), buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer << "\t}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateConnection(ConnectionInstance *connection, ostream &buffer) {
|
||||||
|
buffer << "\t\tline {x1:" << connection->start.first << "; y1:" << connection->start.second << "; " <<
|
||||||
|
"x2:" << connection->end.first << "; y2:" << connection->end.second << ";}" << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateBus(BusInstance *bus, ostream &buffer) {
|
||||||
|
buffer << "\n";
|
||||||
|
buffer << "\t\t// " << bus->name << " bus\n\n";
|
||||||
|
|
||||||
|
if(bus->bus.getDisplayBus().has_value()) {
|
||||||
|
bus->bus.getDisplayBus()->comdel(buffer, bus->position.first, bus->position.second, bus->size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateWire(std::string &name, Wire& wire, ostream &buffer);
|
||||||
|
|
||||||
|
std::map<string, string> generateWires(Schema *schema, ostream &buffer) {
|
||||||
|
std::set<string> usedNames;
|
||||||
|
std::map<string, string> usedMappings;
|
||||||
|
for(auto &bus: schema->busInstances) {
|
||||||
|
buffer << "\t//" << bus->name << std::endl;
|
||||||
|
for(auto& wire: bus->bus.getWires()) {
|
||||||
|
std::string name = wire.getName();
|
||||||
|
if(usedNames.count(wire.getName()) > 0) {
|
||||||
|
name = bus->name + "__" + wire.getName();
|
||||||
|
}
|
||||||
|
if(wire.isHidden()) {
|
||||||
|
name = "--" + name;
|
||||||
|
}
|
||||||
|
usedNames.insert(name);
|
||||||
|
usedMappings.insert(std::make_pair(bus->name + "." + wire.getName(), name));
|
||||||
|
|
||||||
|
generateWire(name, wire, buffer);
|
||||||
|
}
|
||||||
|
buffer << std::endl << std::endl;
|
||||||
|
}
|
||||||
|
return usedMappings;
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateWire(std::string &name, Wire& wire, ostream &buffer) {
|
||||||
|
buffer << "\t";
|
||||||
|
switch (wire.getType()) {
|
||||||
|
case Wire::R_WIRE:
|
||||||
|
buffer << "r_wire";
|
||||||
|
break;
|
||||||
|
case Wire::WIRED_AND:
|
||||||
|
buffer << "wired_and";
|
||||||
|
break;
|
||||||
|
case Wire::WIRED_OR:
|
||||||
|
buffer << "wired_or";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
buffer << "wire";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wire.getWidth() != 1) {
|
||||||
|
buffer << "<" << wire.getWidth() << ">";
|
||||||
|
}
|
||||||
|
buffer << " " << name << ";" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<std::string> createImports(Schema *schema) {
|
||||||
|
std::set<std::string> importSet;
|
||||||
|
for(auto &component: schema->componentInstances) {
|
||||||
|
importSet.insert(component->component.getSource());
|
||||||
|
}
|
||||||
|
return importSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateAutomaticPin(DirectConnectionInstance *connection, string name, string pin, map<string, string> wireNames, stringstream &buffer);
|
||||||
|
|
||||||
|
void generateSingleAutomaticPin(DirectConnectionInstance *instance, string name, string pin,
|
||||||
|
map <string, string> &wireNames,
|
||||||
|
stringstream &buffer);
|
||||||
|
|
||||||
|
void generateComponent(Schema *schema, map <string, string> &wires, ostream &buffer,
|
||||||
|
shared_ptr <ComponentInstance> &component);
|
||||||
|
|
||||||
|
void generateSubComponents(Schema *schema, map<string, string> &wires, ostream &buffer) {
|
||||||
|
|
||||||
|
buffer << "\t// components --------------------------------------------" << std::endl;
|
||||||
|
|
||||||
|
for(auto& component: schema->componentInstances) {
|
||||||
|
if(component->component.getType() == Component::MEMORY) {
|
||||||
|
generateComponent(schema, wires, buffer, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(auto& component: schema->componentInstances) {
|
||||||
|
if(component->component.getType() != Component::MEMORY) {
|
||||||
|
generateComponent(schema, wires, buffer, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateComponent(Schema *schema, map <string, string> &wires, ostream &buffer,
|
||||||
|
shared_ptr <ComponentInstance> &component) {
|
||||||
|
buffer << "\tsubcomponent " << component->component.getName() << " " << component->name;
|
||||||
|
|
||||||
|
std::optional<InstanceAttribute> memory;
|
||||||
|
|
||||||
|
std::vector<InstanceAttribute> attributes;
|
||||||
|
for(auto& attr: component->attributes) {
|
||||||
|
if(attr.name != "_memory") {
|
||||||
|
attributes.push_back(attr);
|
||||||
|
} else if(attr.name == "_memory" && attr.value.asMemoryReference().has_value()) {
|
||||||
|
memory = attr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!attributes.empty()) {
|
||||||
|
buffer << "<";
|
||||||
|
buffer << attributes[0].value.stringify();
|
||||||
|
for(int i=1; i<attributes.size(); i++) {
|
||||||
|
buffer << ", " << attributes[i].value.stringify();
|
||||||
|
}
|
||||||
|
buffer << ">";
|
||||||
|
}
|
||||||
|
|
||||||
|
stringstream tempOutput;
|
||||||
|
|
||||||
|
for(auto &pin: component->component.getPins()) {
|
||||||
|
if(schema->hasConnection(component->name, pin.getName())) {
|
||||||
|
auto conn = schema->getConnection(component->name, pin.getName());
|
||||||
|
auto busConn = dynamic_cast<BusConnectionInstance*>(conn);
|
||||||
|
if(busConn != nullptr) {
|
||||||
|
for(auto wire: busConn->connection.getWires()) {
|
||||||
|
if(wire.isType(Value::ATTRIBUTE_REFERENCE)) {
|
||||||
|
auto attribute = busConn->getAttribute(wire.asReference());
|
||||||
|
if(wire.isType(Value::WIRE_REFERENCE)) {
|
||||||
|
tempOutput << wires[busConn->bus->name + "." + attribute.value.asReference()] << ", ";
|
||||||
|
} else if(wire.isType(Value::NIL)) {
|
||||||
|
tempOutput << "*, ";
|
||||||
|
} else {
|
||||||
|
tempOutput << attribute.value.stringify() << ", ";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(wire.isType(Value::WIRE_REFERENCE)) {
|
||||||
|
tempOutput << wires[busConn->bus->name + "." + wire.asReference()] << ", ";
|
||||||
|
} else if(wire.isType(Value::NIL)) {
|
||||||
|
tempOutput << "*, ";
|
||||||
|
} else {
|
||||||
|
tempOutput << wire.stringify() << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto dirConn = dynamic_cast<DirectConnectionInstance*>(conn);
|
||||||
|
if(dirConn != nullptr) {
|
||||||
|
if(dirConn->bus->bus.getType() == Bus::AUTOMATIC) {
|
||||||
|
generateAutomaticPin(dirConn, component->name, pin.getName(), wires, tempOutput);
|
||||||
|
} else {
|
||||||
|
generateSingleAutomaticPin(dirConn, component->name, pin.getName(), wires, tempOutput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if no connection exists than defaults must exist
|
||||||
|
for(auto& wire: *pin.getWires()) {
|
||||||
|
tempOutput << wire.stringify() << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto wireList = tempOutput.str();
|
||||||
|
wireList.pop_back();
|
||||||
|
wireList.pop_back(); // remove last COMMA(", ")
|
||||||
|
|
||||||
|
buffer << "(" << wireList << ")";
|
||||||
|
|
||||||
|
if(memory.has_value()) {
|
||||||
|
buffer << " uses " << *memory->value.asMemoryReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer << ";" << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateSingleAutomaticPin(DirectConnectionInstance *connection, string name, string pin, map <string, string> &wireNames, stringstream &buffer) {
|
||||||
|
std::vector<Value> wires;
|
||||||
|
std::string selected;
|
||||||
|
std::vector<Value> defaults;
|
||||||
|
if(connection->instance->name == name && connection->connection.getComponent().pin == pin) {
|
||||||
|
wires = connection->connection.getWires();
|
||||||
|
selected = connection->attributes[0].value.asReference();
|
||||||
|
defaults = *connection->instance->component.getPin(pin).getWires();
|
||||||
|
} else {
|
||||||
|
wires = *connection->connection.getSecondWires();
|
||||||
|
selected = connection->attributes[1].value.asReference();
|
||||||
|
defaults = *connection->secondInstance->component.getPin(pin).getWires();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<wires.size(); i++) {
|
||||||
|
if(wires[i].isType(Value::STRING)) {
|
||||||
|
if(wires[i].asString() == selected) {
|
||||||
|
buffer << wireNames[connection->bus->name + "." + connection->bus->bus.getWires()[0].getName()] << ", ";
|
||||||
|
} else {
|
||||||
|
buffer << defaults[i].stringify();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buffer << wires[i].stringify() << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateAutomaticPin(DirectConnectionInstance *connection, string name, string pin, map<string, string> wireNames, stringstream &buffer) {
|
||||||
|
std::vector<Value> wires;
|
||||||
|
if(connection->instance->name == name && connection->connection.getComponent().pin == pin) {
|
||||||
|
wires = connection->connection.getWires();
|
||||||
|
} else {
|
||||||
|
wires = *connection->connection.getSecondWires();
|
||||||
|
}
|
||||||
|
for(auto& wire: wires) {
|
||||||
|
if(wire.isType(Value::ATTRIBUTE_REFERENCE)) {
|
||||||
|
auto attribute = connection->getAttribute(wire.asReference());
|
||||||
|
if(wire.isType(Value::WIRE_REFERENCE)) {
|
||||||
|
buffer << wireNames[connection->bus->name + "." + attribute.value.asReference()] << ", ";
|
||||||
|
} else if(wire.isType(Value::NIL)) {
|
||||||
|
buffer << "*, ";
|
||||||
|
} else {
|
||||||
|
buffer << attribute.value.stringify() << ", ";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(wire.isType(Value::WIRE_REFERENCE)) {
|
||||||
|
buffer << wireNames[connection->bus->name + "." + wire.asReference()] << ", ";
|
||||||
|
} else if(wire.isType(Value::NIL)) {
|
||||||
|
buffer << "*, ";
|
||||||
|
} else {
|
||||||
|
buffer << wire.stringify() << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // domain
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef COMDEL_GENERATOR_H
|
||||||
|
#define COMDEL_GENERATOR_H
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include "schema.h"
|
||||||
|
#include "library.h"
|
||||||
|
|
||||||
|
namespace domain {
|
||||||
|
|
||||||
|
void generateSchemaFile(std::string& librarySource, Schema *schema, std::ostream &buffer);
|
||||||
|
|
||||||
|
void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer);
|
||||||
|
|
||||||
|
} // domain
|
||||||
|
|
||||||
|
#endif //COMDEL_GENERATOR_H
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "comdelvalidator.h"
|
#include "comdelvalidator.h"
|
||||||
|
#include "library.h"
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
@@ -8,13 +9,82 @@ std::vector<ValidationError> ComdelValidator::validateSchema(Schema &schema, Val
|
|||||||
context.instance = nullptr;
|
context.instance = nullptr;
|
||||||
context.attribute = nullptr;
|
context.attribute = nullptr;
|
||||||
|
|
||||||
for(auto &inst: schema.instances) {
|
for(auto &instance: schema.componentInstances) {
|
||||||
auto *instance = dynamic_cast<ComponentInstance*>(inst);
|
auto result = validateComponent(instance.get(), context);
|
||||||
if(instance) {
|
|
||||||
auto result = validateComponent(instance, context);
|
|
||||||
errors.insert(errors.end(), result.begin(), result.end());
|
errors.insert(errors.end(), result.begin(), result.end());
|
||||||
}
|
}
|
||||||
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<ValidationError> ComdelValidator::validateInstanceCount(Schema& schema, Library& library, ValidationContext context) {
|
||||||
|
std::vector<ValidationError> errors;
|
||||||
|
|
||||||
|
// validate instance count
|
||||||
|
std::map<std::string, int> instanceMap;
|
||||||
|
for(auto& inst: schema.componentInstances) {
|
||||||
|
instanceMap[inst->component.getName()]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto comp: library.getComponents()) {
|
||||||
|
int count = instanceMap[comp.getName()];
|
||||||
|
|
||||||
|
context.attributes["componentName"] = Value::fromString(comp.getName());
|
||||||
|
context.attributes["min"] = Value::fromInt(comp.getCount().first);
|
||||||
|
context.attributes["max"] = Value::fromInt(comp.getCount().second);
|
||||||
|
context.attributes["count"] = Value::fromInt(count);
|
||||||
|
|
||||||
|
if(count < comp.getCount().first) {
|
||||||
|
auto message = populateMessage("Not enough instances of component '{componentName}' required at least {min}, found {count}", context);
|
||||||
|
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||||
|
} else if(count > comp.getCount().second) {
|
||||||
|
auto message = populateMessage("To many instances of component '{componentName}' allow at most {max}, found {count}", context);
|
||||||
|
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// validate bus instance count
|
||||||
|
std::map<std::string, int> busInstanceMap;
|
||||||
|
for(auto& inst: schema.busInstances) {
|
||||||
|
busInstanceMap[inst->bus.getName()]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto bus: library.getBuses()) {
|
||||||
|
int count = busInstanceMap[bus.getName()];
|
||||||
|
|
||||||
|
context.attributes["busName"] = Value::fromString(bus.getName());
|
||||||
|
context.attributes["min"] = Value::fromInt(bus.getCount().first);
|
||||||
|
context.attributes["max"] = Value::fromInt(bus.getCount().second);
|
||||||
|
context.attributes["count"] = Value::fromInt(count);
|
||||||
|
|
||||||
|
if(count < bus.getCount().first) {
|
||||||
|
auto message = populateMessage("Not enough instances of bus '{busName}' required at least {min}, found {count}", context);
|
||||||
|
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||||
|
} else if(count > bus.getCount().second) {
|
||||||
|
auto message = populateMessage("To many instances of bus '{busName}' allow at most {max}, found {count}", context);
|
||||||
|
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ValidationError> ComdelValidator::validatePinConnections(Schema &schema, Library &library, ValidationContext context) {
|
||||||
|
std::vector<ValidationError> errors;
|
||||||
|
|
||||||
|
for(auto& inst: schema.componentInstances) {
|
||||||
|
for(auto& pin: inst->component.getPins()) {
|
||||||
|
if(pin.getConnection().getType() == PinConnection::REQUIRED) {
|
||||||
|
if(!connectionExists(schema, inst, pin)) {
|
||||||
|
context.instance = inst.get();
|
||||||
|
context.attributes["instanceName"] = Value::fromString(inst->name);
|
||||||
|
auto message = populateMessage(pin.getConnection().getMessage(), context);
|
||||||
|
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +95,7 @@ std::vector<ValidationError> ComdelValidator::validateComponent(ComponentInstanc
|
|||||||
context.attributes.clear();
|
context.attributes.clear();
|
||||||
|
|
||||||
for(auto &attribute: instance->attributes) {
|
for(auto &attribute: instance->attributes) {
|
||||||
context.attributes[attribute->name] = attribute->value;
|
context.attributes[attribute.name] = attribute.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto &rule: instance->component.getRules()) {
|
for(auto &rule: instance->component.getRules()) {
|
||||||
@@ -36,7 +106,7 @@ std::vector<ValidationError> ComdelValidator::validateComponent(ComponentInstanc
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(auto &attribute: instance->attributes) {
|
for(auto &attribute: instance->attributes) {
|
||||||
auto result = validateAttribute(attribute, context);
|
auto result = validateAttribute(&attribute, context);
|
||||||
errors.insert(errors.end(), result.begin(), result.end());
|
errors.insert(errors.end(), result.begin(), result.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +134,7 @@ std::optional<ValidationError> ComdelValidator::validateRule(Rule rule, Validati
|
|||||||
RuleContext ruleContext;
|
RuleContext ruleContext;
|
||||||
ruleContext.addressSpaces = context.addressSpaces;
|
ruleContext.addressSpaces = context.addressSpaces;
|
||||||
ruleContext.attributes = context.attributes;
|
ruleContext.attributes = context.attributes;
|
||||||
ruleContext.function = callbacks;
|
ruleContext.function = validators;
|
||||||
auto action = rule.evaluate(ruleContext);
|
auto action = rule.evaluate(ruleContext);
|
||||||
if (action) {
|
if (action) {
|
||||||
std::string message = this->populateMessage(action->getMessage(), context);
|
std::string message = this->populateMessage(action->getMessage(), context);
|
||||||
@@ -92,4 +162,26 @@ string ComdelValidator::replacePlaceholder(string source, string key, Value valu
|
|||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ComdelValidator::connectionExists(Schema &schema, shared_ptr<ComponentInstance> &component, Pin &pin) {
|
||||||
|
for(auto conn: schema.connections) {
|
||||||
|
auto busConnection = dynamic_cast<BusConnectionInstance*>(conn.get());
|
||||||
|
if(busConnection != nullptr) {
|
||||||
|
if(busConnection->instance->name == component->name && busConnection->connection.getComponent().pin == pin.getName()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto directConnection = dynamic_cast<DirectConnectionInstance*>(conn.get());
|
||||||
|
if(directConnection != nullptr) {
|
||||||
|
if(directConnection->instance->name == component->name && busConnection->connection.getComponent().pin == pin.getName()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(directConnection->secondInstance->name == component->name && busConnection->connection.getSecondComponent()->pin == pin.getName()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,20 @@
|
|||||||
|
|
||||||
#include "instance.h"
|
#include "instance.h"
|
||||||
#include "schema.h"
|
#include "schema.h"
|
||||||
|
#include "library.h"
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
struct ValidationError
|
struct ValidationError
|
||||||
{
|
{
|
||||||
Instance *instance;
|
ComponentInstance *instance;
|
||||||
InstanceAttribute *attribute;
|
InstanceAttribute *attribute;
|
||||||
Action::ActionType type;
|
Action::ActionType type;
|
||||||
std::string message;
|
std::string message;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ValidationContext {
|
struct ValidationContext {
|
||||||
Instance *instance;
|
ComponentInstance *instance;
|
||||||
InstanceAttribute *attribute;
|
InstanceAttribute *attribute;
|
||||||
std::map<std::string, AddressSpace> addressSpaces;
|
std::map<std::string, AddressSpace> addressSpaces;
|
||||||
std::map<std::string, Value> attributes;
|
std::map<std::string, Value> attributes;
|
||||||
@@ -29,14 +30,24 @@ public:
|
|||||||
std::vector<ValidationError> validateAttribute(InstanceAttribute *attribute, ValidationContext context);
|
std::vector<ValidationError> validateAttribute(InstanceAttribute *attribute, ValidationContext context);
|
||||||
std::optional<ValidationError> validateRule(Rule rule, ValidationContext context);
|
std::optional<ValidationError> validateRule(Rule rule, ValidationContext context);
|
||||||
|
|
||||||
ComdelValidator(std::map<std::string, FunctionCallback> callbacks): callbacks(callbacks) {}
|
std::vector<ValidationError> validateInstanceCount(Schema &schema, Library& library, ValidationContext context);
|
||||||
|
std::vector<ValidationError> validatePinConnections(Schema &schema, Library& library, ValidationContext context);
|
||||||
|
|
||||||
|
ComdelValidator(std::vector<FunctionValidator*> validators) {
|
||||||
|
for(auto* validator: validators) {
|
||||||
|
validator->clear();
|
||||||
|
this->validators.insert(std::make_pair(validator->getName(), validator));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, FunctionCallback> callbacks;
|
std::map<std::string, FunctionValidator*> validators;
|
||||||
|
|
||||||
std::string populateMessage(string basicString, ValidationContext context);
|
std::string populateMessage(string message, ValidationContext context);
|
||||||
|
|
||||||
string replacePlaceholder(string basicString, const string basicString1, Value value);
|
string replacePlaceholder(string message, const string name, Value value);
|
||||||
|
|
||||||
|
bool connectionExists(Schema &schema, shared_ptr <ComponentInstance> &component, Pin &pin);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,12 @@ bool Component::hasAttribute(std::string name, Value::ValueType type) {
|
|||||||
if(attributes[i].getName() == name && attributes[i].getDefault().getType() == type) {
|
if(attributes[i].getName() == name && attributes[i].getDefault().getType() == type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if(attributes[i].getName() == name && (type == Value::NIL && (attributes[i].getDefault().getType() == Value::MEMORY_REFERENCE || attributes[i].getDefault().getType() == Value::WIRE_REFERENCE))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(attributes[i].getName() == name && (type == Value::UNDEFINED && (attributes[i].getDefault().getType() == Value::MEMORY_REFERENCE || attributes[i].getDefault().getType() == Value::WIRE_REFERENCE))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,4 +63,14 @@ bool Connection::isConnecting(ConnectionComponent component, std::string bus, Co
|
|||||||
(this->first == secondComponent && this->bus == bus && this->second == component);
|
(this->first == secondComponent && this->bus == bus && this->second == component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Connection::isConnecting(ConnectionComponent component, ConnectionComponent secondComponent) {
|
||||||
|
if(!second.has_value()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (this->first == component && this->second == secondComponent) ||
|
||||||
|
(this->first == secondComponent && this->second == component);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
@@ -21,6 +21,17 @@ struct ConnectionComponent
|
|||||||
{
|
{
|
||||||
return !operator==(rhs);
|
return !operator==(rhs);
|
||||||
}
|
}
|
||||||
|
bool operator<(const ConnectionComponent& rhs) const
|
||||||
|
{
|
||||||
|
if(component < rhs.component) {
|
||||||
|
return true;
|
||||||
|
} else if(component == rhs.component) {
|
||||||
|
if(pin < rhs.pin) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Connection
|
class Connection
|
||||||
@@ -40,6 +51,7 @@ public:
|
|||||||
bool isConnecting(ConnectionComponent first);
|
bool isConnecting(ConnectionComponent first);
|
||||||
bool isConnecting(ConnectionComponent first, std::string bus);
|
bool isConnecting(ConnectionComponent first, std::string bus);
|
||||||
bool isConnecting(ConnectionComponent first, std::string bus, ConnectionComponent second);
|
bool isConnecting(ConnectionComponent first, std::string bus, ConnectionComponent second);
|
||||||
|
bool isConnecting(ConnectionComponent first, ConnectionComponent second);
|
||||||
|
|
||||||
|
|
||||||
ConnectionComponent getComponent();
|
ConnectionComponent getComponent();
|
||||||
|
|||||||
@@ -3,16 +3,26 @@
|
|||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
|
|
||||||
ConnectionInstance::ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute*> attributes, WireInstance *wire, Connection connection)
|
ConnectionInstance::ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes, Connection connection)
|
||||||
: instance(instance), attributes(attributes), connection(connection), wire(wire)
|
: instance(instance), attributes(attributes), connection(connection)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BusConnectionInstance::BusConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute*> attributes, BusInstance *bus, WireInstance *wire, Connection connection)
|
InstanceAttribute ConnectionInstance::getAttribute(string attribute) {
|
||||||
: ConnectionInstance(instance, attributes, wire, connection), bus(bus)
|
for(auto& attr: attributes) {
|
||||||
|
if(attr.name == attribute) {
|
||||||
|
return attr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw std::exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BusConnectionInstance::BusConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes, BusInstance *bus, Connection connection)
|
||||||
|
: ConnectionInstance(instance, attributes, connection), bus(bus)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DirectConnectionInstance::DirectConnectionInstance(ComponentInstance *instance, ComponentInstance *secondInstance, std::vector<InstanceAttribute*> attributes, BusInstance *bus, WireInstance *wire, Connection connection)
|
DirectConnectionInstance::DirectConnectionInstance(ComponentInstance *instance, ComponentInstance *secondInstance, std::vector<InstanceAttribute> attributes, BusInstance *bus, Connection connection)
|
||||||
: ConnectionInstance(instance, attributes, wire, connection), secondInstance(secondInstance), bus(bus)
|
: ConnectionInstance(instance, attributes, connection), secondInstance(secondInstance), bus(bus)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
#include "instance.h"
|
#include "instance.h"
|
||||||
#include "wireinstance.h"
|
#include "wireinstance.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
class ConnectionInstance
|
class ConnectionInstance
|
||||||
@@ -14,13 +12,17 @@ class ConnectionInstance
|
|||||||
public:
|
public:
|
||||||
ComponentInstance *instance;
|
ComponentInstance *instance;
|
||||||
Connection connection;
|
Connection connection;
|
||||||
WireInstance *wire;
|
|
||||||
|
|
||||||
virtual ~ConnectionInstance() = default;
|
virtual ~ConnectionInstance() = default;
|
||||||
|
|
||||||
std::vector<InstanceAttribute*> attributes;
|
std::vector<InstanceAttribute> attributes;
|
||||||
|
|
||||||
ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute*> attributes, WireInstance *wire, Connection connection);
|
std::pair<int, int> start;
|
||||||
|
std::pair<int, int> end;
|
||||||
|
|
||||||
|
ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes, Connection connection);
|
||||||
|
|
||||||
|
InstanceAttribute getAttribute(string attribute);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ class BusConnectionInstance: public ConnectionInstance
|
|||||||
public:
|
public:
|
||||||
BusInstance *bus;
|
BusInstance *bus;
|
||||||
|
|
||||||
BusConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute*> attributes, BusInstance *bus, WireInstance *wire, Connection connection);
|
BusConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes, BusInstance *bus, Connection connection);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -39,7 +41,7 @@ public:
|
|||||||
BusInstance *bus;
|
BusInstance *bus;
|
||||||
ComponentInstance *secondInstance;
|
ComponentInstance *secondInstance;
|
||||||
|
|
||||||
DirectConnectionInstance(ComponentInstance *instance, ComponentInstance *secondsInstance, std::vector<InstanceAttribute*> attributes, BusInstance *bus, WireInstance *wire, Connection connection);
|
DirectConnectionInstance(ComponentInstance *instance, ComponentInstance *secondsInstance, std::vector<InstanceAttribute> attributes, BusInstance *bus, Connection connection);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+161
-6
@@ -4,6 +4,8 @@
|
|||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
@@ -17,6 +19,14 @@ public:
|
|||||||
void render(QGraphicsItemGroup *group) {
|
void render(QGraphicsItemGroup *group) {
|
||||||
group->addToGroup(new QGraphicsRectItem(x,y,w,h));
|
group->addToGroup(new QGraphicsRectItem(x,y,w,h));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void comdel(std::ostream &buffer, int x, int y) {
|
||||||
|
buffer << "\t\trectangle {\n";
|
||||||
|
buffer << "\t\t\tx: " << (this->x + x) << "; y: " << (this->y + y) << ";\n";
|
||||||
|
buffer << "\t\t\tw: " << w << "; h: " << h << ";\n";
|
||||||
|
buffer << "\t\t}\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Line {
|
class Line {
|
||||||
@@ -28,43 +38,180 @@ public:
|
|||||||
void render(QGraphicsItemGroup *group) {
|
void render(QGraphicsItemGroup *group) {
|
||||||
group->addToGroup(new QGraphicsLineItem(x1, y1, x2, y2));
|
group->addToGroup(new QGraphicsLineItem(x1, y1, x2, y2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void comdel(std::ostream &buffer, int x, int y) {
|
||||||
|
buffer << "\t\tline {\n";
|
||||||
|
buffer << "\t\t\tx1: " << (x1 + x) << "; y1: " << (y1 + y) << ";\n";
|
||||||
|
buffer << "\t\t\tx2: " << (x2 + x) << "; y2: " << (y2 + y) << ";\n";
|
||||||
|
buffer << "\t\t}\n\n";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Orientation {
|
enum PinOrientation {
|
||||||
LEFT, RIGHT, TOP, BOTTOM
|
LEFT, RIGHT, TOP, BOTTOM
|
||||||
};
|
};
|
||||||
|
enum BusOrientation {
|
||||||
|
VERTICAL, HORIZONTAL
|
||||||
|
};
|
||||||
|
|
||||||
enum PinType {
|
enum PinType {
|
||||||
IN, OUT, IN_OUT
|
IN, OUT, IN_OUT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Bus {
|
||||||
|
public:
|
||||||
|
int x, y, w, h;
|
||||||
|
BusOrientation orientation;
|
||||||
|
|
||||||
|
Bus(int x, int y, int w, int h, BusOrientation orientation): x(x), y(y), w(w), h(h), orientation(orientation) {}
|
||||||
|
|
||||||
|
void render(QGraphicsItemGroup *group, int size) {
|
||||||
|
if(orientation == HORIZONTAL) {
|
||||||
|
group->addToGroup(new QGraphicsRectItem(x,y,size, h));
|
||||||
|
} else {
|
||||||
|
group->addToGroup(new QGraphicsRectItem(x,y,w,size));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int getDefaultSize() {
|
||||||
|
if(orientation == HORIZONTAL) {
|
||||||
|
return w;
|
||||||
|
} else {
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void comdel(std::ostream &buffer, int x, int y, int size) {
|
||||||
|
buffer << "\t\trectangle {\n";
|
||||||
|
buffer << "\t\t\tx: " << (this->x + x) << "; y: " << (this->y + y) << ";\n";
|
||||||
|
if(orientation == HORIZONTAL) {
|
||||||
|
buffer << "\t\t\tw: " << size << "; h: " << h << ";\n";
|
||||||
|
} else {
|
||||||
|
buffer << "\t\t\tw: " << w << "; h: " << size << ";\n";
|
||||||
|
}
|
||||||
|
buffer << "\t\t}\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Pin {
|
class Pin {
|
||||||
public:
|
public:
|
||||||
Orientation orientation;
|
PinOrientation orientation;
|
||||||
PinType pinType;
|
PinType pinType;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
|
|
||||||
Pin(int x, int y, int w, int h): x(x), y(y), w(w), h(h) {}
|
Pin(int x, int y, int w, int h, PinOrientation orientation, PinType pinType): x(x), y(y), w(w), h(h), orientation(orientation), pinType(pinType) {}
|
||||||
|
|
||||||
|
void renderIn(QGraphicsItemGroup *group) {
|
||||||
|
QPolygon polygon;
|
||||||
|
|
||||||
|
switch (orientation) {
|
||||||
|
case PinOrientation::TOP:
|
||||||
|
polygon << QPoint(x, y) << QPoint(x, y+h) << QPoint(x+w, y+h) << QPoint(x+w, y) << QPoint(x+w/2, y+h/2);
|
||||||
|
break;
|
||||||
|
case PinOrientation::BOTTOM:
|
||||||
|
polygon << QPoint(x, y) << QPoint(x, y+h) << QPoint(x+w/2, y+h/2) << QPoint(x+w, y+h) << QPoint(x+w, y);
|
||||||
|
break;
|
||||||
|
case PinOrientation::LEFT:
|
||||||
|
polygon << QPoint(x, y) << QPoint(x+w/2, y+h/2) << QPoint(x, y+h) << QPoint(x+w, y+h) << QPoint(x+w, y);
|
||||||
|
break;
|
||||||
|
case PinOrientation::RIGHT:
|
||||||
|
polygon << QPoint(x, y) << QPoint(x, y+h) << QPoint(x+w, y+h) << QPoint(x+w/2, y+h/2) << QPoint(x+w, y);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
group->addToGroup(new QGraphicsPolygonItem(polygon));
|
||||||
|
}
|
||||||
|
|
||||||
|
void renderOut(QGraphicsItemGroup *group) {
|
||||||
|
QPolygon polygon;
|
||||||
|
|
||||||
|
switch (orientation) {
|
||||||
|
case PinOrientation::TOP:
|
||||||
|
polygon << QPoint(x, y+h/2) << QPoint(x, y+h) << QPoint(x+w, y+h) << QPoint(x+w, y+h/2) << QPoint(x+w/2, y);
|
||||||
|
break;
|
||||||
|
case PinOrientation::BOTTOM:
|
||||||
|
polygon << QPoint(x, y) << QPoint(x, y+h/2) << QPoint(x+w/2, y+h) << QPoint(x+w, y+h/2) << QPoint(x+w, y);
|
||||||
|
break;
|
||||||
|
case PinOrientation::LEFT:
|
||||||
|
polygon << QPoint(x+w, y) << QPoint(x+w/2, y) << QPoint(x, y+h/2) << QPoint(x+w/2, y+h) << QPoint(x+w, y+w);
|
||||||
|
break;
|
||||||
|
case PinOrientation::RIGHT:
|
||||||
|
polygon << QPoint(x, y) << QPoint(x, y+h) << QPoint(x+w/2, y+h) << QPoint(x+w, y+h/2) << QPoint(x+w/2, y);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
group->addToGroup(new QGraphicsPolygonItem(polygon));
|
||||||
|
}
|
||||||
|
|
||||||
|
void renderInOut(QGraphicsItemGroup *group) {
|
||||||
|
group->addToGroup(new QGraphicsRectItem(x, y ,w, h));
|
||||||
|
}
|
||||||
|
|
||||||
void render(QGraphicsItemGroup *group) {
|
void render(QGraphicsItemGroup *group) {
|
||||||
group->addToGroup(new QGraphicsRectItem(x,y,w,h));
|
switch (pinType) {
|
||||||
|
case PinType::IN:
|
||||||
|
renderIn(group);
|
||||||
|
break;
|
||||||
|
case PinType::OUT:
|
||||||
|
renderOut(group);
|
||||||
|
break;
|
||||||
|
case PinType::IN_OUT:
|
||||||
|
renderInOut(group);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int getConnectionX() {
|
||||||
|
switch (orientation) {
|
||||||
|
case ui::PinOrientation::TOP:
|
||||||
|
case ui::PinOrientation::BOTTOM:
|
||||||
|
return x+w/2;
|
||||||
|
case ui::PinOrientation::LEFT:
|
||||||
|
return x;
|
||||||
|
case ui::PinOrientation::RIGHT:
|
||||||
|
return x+w;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getConnectionY() {
|
||||||
|
switch (orientation) {
|
||||||
|
case ui::PinOrientation::LEFT:
|
||||||
|
case ui::PinOrientation::RIGHT:
|
||||||
|
return y+h/2;
|
||||||
|
case ui::PinOrientation::TOP:
|
||||||
|
return y;
|
||||||
|
case ui::PinOrientation::BOTTOM:
|
||||||
|
return y+h;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Item {
|
class Item {
|
||||||
public:
|
public:
|
||||||
Item(): rect(std::nullopt), line(std::nullopt), pin(std::nullopt) {}
|
Item(): rect(std::nullopt), line(std::nullopt), pin(std::nullopt), bus(std::nullopt) {}
|
||||||
|
|
||||||
void render(QGraphicsItemGroup *group) {
|
void render(QGraphicsItemGroup *group, int size = 0) {
|
||||||
if(rect) rect->render(group);
|
if(rect) rect->render(group);
|
||||||
if(line) line->render(group);
|
if(line) line->render(group);
|
||||||
if(pin) pin->render(group);
|
if(pin) pin->render(group);
|
||||||
|
if(bus) bus->render(group, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Rect> rect = std::nullopt;
|
std::optional<Rect> rect = std::nullopt;
|
||||||
std::optional<Line> line = std::nullopt;
|
std::optional<Line> line = std::nullopt;
|
||||||
std::optional<Pin> pin = std::nullopt;
|
std::optional<Pin> pin = std::nullopt;
|
||||||
|
std::optional<Bus> bus = std::nullopt;
|
||||||
|
|
||||||
|
void comdel(std::ostream &buffer, int x, int y, int size = 0) {
|
||||||
|
if(rect) rect->comdel(buffer, x, y);
|
||||||
|
if(line) line->comdel(buffer, x, y);
|
||||||
|
// pins aren't exported
|
||||||
|
if(bus) bus->comdel(buffer, x, y, size);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -81,6 +228,14 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void comdel(std::ostream &buffer, int x, int y, int size = 0) {
|
||||||
|
for(auto &item: items) {
|
||||||
|
item.comdel(buffer, x, y, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ui::Item>& getItems() {return items;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<ui::Item> items;
|
std::vector<ui::Item> items;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,45 +1,138 @@
|
|||||||
|
#include <map>
|
||||||
#include "functionsignature.h"
|
#include "functionsignature.h"
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
FunctionSignature add(std::string name, std::vector<Value::ValueType> types, FunctionCallback callback) {
|
class DivisibleValidator: public FunctionValidator {
|
||||||
return {name, types, callback};
|
public:
|
||||||
}
|
DivisibleValidator(): FunctionValidator("divisible", {Value::INT, Value::INT}) {}
|
||||||
|
|
||||||
std::vector<FunctionSignature> getSupportedFunctions() {
|
bool validate(std::vector<Value> values) override {
|
||||||
std::vector<FunctionSignature> s;
|
if(validateSignature(values)) {
|
||||||
s.push_back(add("divisible", std::vector<Value::ValueType>{Value::INT, Value::INT},[](std::vector<Value> values) {
|
|
||||||
long long first = values[0].asInt();
|
long long first = values[0].asInt();
|
||||||
long long second = values[1].asInt();
|
long long second = values[1].asInt();
|
||||||
return (first % second) == 0;
|
return (first % second) == 0;
|
||||||
}));
|
}
|
||||||
s.push_back(add("less_then", std::vector<Value::ValueType>{Value::INT, Value::INT}, [](std::vector<Value> values) {
|
return false;
|
||||||
|
}
|
||||||
|
void clear() override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class LessThenValidator: public FunctionValidator {
|
||||||
|
public:
|
||||||
|
LessThenValidator(): FunctionValidator("less_then", {Value::INT, Value::INT}) {}
|
||||||
|
|
||||||
|
bool validate(std::vector<Value> values) override {
|
||||||
|
if(validateSignature(values)) {
|
||||||
long long first = values[0].asInt();
|
long long first = values[0].asInt();
|
||||||
long long second = values[1].asInt();
|
long long second = values[1].asInt();
|
||||||
return first < second;
|
return first < second;
|
||||||
}));
|
}
|
||||||
s.push_back(add("greater_then", std::vector<Value::ValueType>{Value::INT, Value::INT}, [](std::vector<Value> values) {
|
return false;
|
||||||
|
}
|
||||||
|
void clear() override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class GreaterThenValidator: public FunctionValidator {
|
||||||
|
public:
|
||||||
|
GreaterThenValidator(): FunctionValidator("greater_then", {Value::INT, Value::INT}) {}
|
||||||
|
|
||||||
|
bool validate(std::vector<Value> values) override {
|
||||||
|
if(validateSignature(values)) {
|
||||||
long long first = values[0].asInt();
|
long long first = values[0].asInt();
|
||||||
long long second = values[1].asInt();
|
long long second = values[1].asInt();
|
||||||
return first > second;
|
return first > second;
|
||||||
}));
|
}
|
||||||
s.push_back(add("contains_address", std::vector<Value::ValueType>{Value::ADDRESS_SPACE, Value::INT}, [](std::vector<Value> values) {
|
return false;
|
||||||
|
}
|
||||||
|
void clear() override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ContainsAddressValidator: public FunctionValidator {
|
||||||
|
public:
|
||||||
|
ContainsAddressValidator(): FunctionValidator("contains_address", {Value::ADDRESS_SPACE, Value::INT}) {}
|
||||||
|
|
||||||
|
bool validate(std::vector<Value> values) override {
|
||||||
|
if(validateSignature(values)) {
|
||||||
AddressSpace space = values[0].asAddressSpace();
|
AddressSpace space = values[0].asAddressSpace();
|
||||||
long long address = values[1].asInt();
|
long long address = values[1].asInt();
|
||||||
return space.contains(address);
|
return space.contains(address);
|
||||||
}));
|
}
|
||||||
s.push_back(add("contains", std::vector<Value::ValueType>{Value::ADDRESS_SPACE, Value::INT, Value::INT}, [](std::vector<Value> values) {
|
return false;
|
||||||
|
}
|
||||||
|
void clear() override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ContainsValidator: public FunctionValidator {
|
||||||
|
public:
|
||||||
|
ContainsValidator(): FunctionValidator("contains", {Value::ADDRESS_SPACE, Value::INT, Value::INT}) {}
|
||||||
|
|
||||||
|
bool validate(std::vector<Value> values) override {
|
||||||
|
if(validateSignature(values)) {
|
||||||
AddressSpace space = values[0].asAddressSpace();
|
AddressSpace space = values[0].asAddressSpace();
|
||||||
long long start = values[1].asInt();
|
long long start = values[1].asInt();
|
||||||
long long size = values[1].asInt();
|
long long size = values[1].asInt();
|
||||||
return space.contains(start, start + size);
|
return space.contains(start, start + size);
|
||||||
}));
|
}
|
||||||
s.push_back(add("unique", std::vector<Value::ValueType>{Value::ADDRESS_SPACE, Value::INT, Value::INT}, [](std::vector<Value> values) {
|
return false;
|
||||||
return true;
|
}
|
||||||
}));
|
void clear() override {}
|
||||||
|
};
|
||||||
|
|
||||||
return s;
|
|
||||||
|
|
||||||
|
|
||||||
|
class UniqueValidator: public FunctionValidator {
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::string, std::vector<std::pair<long long int, long long int>>> spaces;
|
||||||
|
|
||||||
|
bool overlaps(long long int start1, long long int end1, long long int start2, long long int end2) {
|
||||||
|
return std::max((long long int)0, std::min(end1, end2) - std::max(start1, start2)) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
UniqueValidator(): FunctionValidator("unique", {Value::ADDRESS_SPACE, Value::INT, Value::INT}) {}
|
||||||
|
|
||||||
|
bool validate(std::vector<Value> values) override {
|
||||||
|
if(validateSignature(values)) {
|
||||||
|
std::string space = values[0].asAddressSpace().getName();
|
||||||
|
long long int start = values[1].asInt();
|
||||||
|
long long int end = start + values[2].asInt();
|
||||||
|
if(spaces.count(space) == 0) {
|
||||||
|
spaces.insert(std::make_pair(space, std::vector<std::pair<long long int, long long int>>{}));
|
||||||
|
}
|
||||||
|
for(auto& s: spaces[space]) {
|
||||||
|
if(overlaps(s.first, s.second, start, end)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
spaces[space].push_back(std::make_pair(start, end));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void clear() override {
|
||||||
|
spaces.clear();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<FunctionValidator*> getSupportedValidators() {
|
||||||
|
std::vector<FunctionValidator*> validators;
|
||||||
|
|
||||||
|
validators.push_back(new DivisibleValidator());
|
||||||
|
validators.push_back(new LessThenValidator());
|
||||||
|
validators.push_back(new GreaterThenValidator());
|
||||||
|
validators.push_back(new ContainsAddressValidator());
|
||||||
|
validators.push_back(new ContainsValidator());
|
||||||
|
validators.push_back(new UniqueValidator());
|
||||||
|
|
||||||
|
return validators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef DOMAIN_FUNCTION_SIGNATURE_H
|
#ifndef DOMAIN_FUNCTION_VALIDATOR_H
|
||||||
#define DOMAIN_FUNCTION_SIGNATURE_H
|
#define DOMAIN_FUNCTION_VALIDATOR_H
|
||||||
|
|
||||||
#include<functional>
|
#include<functional>
|
||||||
#include<vector>
|
#include<vector>
|
||||||
@@ -8,18 +8,46 @@
|
|||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
typedef std::function<bool (std::vector<Value>)> FunctionCallback;
|
class FunctionValidator {
|
||||||
|
private:
|
||||||
struct FunctionSignature {
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<Value::ValueType> params;
|
std::vector<Value::ValueType> signature;
|
||||||
FunctionCallback callback;
|
|
||||||
|
|
||||||
FunctionSignature(std::string name, std::vector<Value::ValueType> params, FunctionCallback callback): name(name), params(params), callback(callback) {}
|
protected:
|
||||||
|
FunctionValidator(std::string name, std::vector<Value::ValueType> signature) {
|
||||||
|
this->name = name;
|
||||||
|
this->signature = signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
std::string getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Value::ValueType> getSignature() {
|
||||||
|
return signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validateSignature(std::vector<Value> signature) {
|
||||||
|
if(this->signature.size() != signature.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<this->signature.size(); i++) {
|
||||||
|
if(this->signature[i] != signature[i].getType()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool validate(std::vector<Value> values) = 0;
|
||||||
|
virtual void clear() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<FunctionSignature> getSupportedFunctions();
|
std::vector<FunctionValidator*> getSupportedValidators();
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|
||||||
#endif // DOMAIN_FUNCTIONSIGNATURE_H
|
#endif // DOMAIN_FUNCTION_VALIDATOR_H
|
||||||
@@ -2,15 +2,18 @@
|
|||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
|
|
||||||
Instance::Instance(std::string name, std::vector<InstanceAttribute*> attributes, std::pair<int, int> position)
|
|
||||||
: name(name), attributes(attributes), position(position)
|
|
||||||
{}
|
|
||||||
BusInstance::BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size)
|
BusInstance::BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size)
|
||||||
: Instance(name, vector<InstanceAttribute*>(), position), bus(bus), size(size)
|
: name(name), position(position), bus(bus), size(size)
|
||||||
{}
|
{
|
||||||
ComponentInstance::ComponentInstance(std::string name, std::vector<InstanceAttribute*> attributes, std::pair<int, int> position, Component component)
|
if(size < 0 && bus.getDisplayBus().has_value()) {
|
||||||
: Instance(name, attributes, position), component(component)
|
this->size = bus.getDisplayBus()->getDefaultSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BusInstance::BusInstance(std::string name, Bus bus): name(name), bus(bus), position(0,0), size(0) {}
|
||||||
|
|
||||||
|
ComponentInstance::ComponentInstance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position, Component component)
|
||||||
|
: name(name), attributes(std::move(attributes)), position(position), component(component)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+12
-19
@@ -12,41 +12,34 @@
|
|||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
class Instance
|
class BusInstance
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<InstanceAttribute*> attributes;
|
|
||||||
std::pair<int, int> position;
|
std::pair<int, int> position;
|
||||||
|
|
||||||
virtual ~Instance() {};
|
|
||||||
|
|
||||||
Instance(std::string name, std::vector<InstanceAttribute*> attributes, std::pair<int, int> position);
|
|
||||||
};
|
|
||||||
|
|
||||||
class BusInstance: public Instance
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Bus bus;
|
Bus bus;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size);
|
BusInstance(std::string name, Bus bus);
|
||||||
|
|
||||||
virtual ~BusInstance() {
|
BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size = -1);
|
||||||
Instance::~Instance();
|
|
||||||
}
|
virtual ~BusInstance() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ComponentInstance: public Instance
|
class ComponentInstance
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
std::string name;
|
||||||
|
std::vector<InstanceAttribute> attributes;
|
||||||
|
std::pair<int, int> position;
|
||||||
|
|
||||||
Component component;
|
Component component;
|
||||||
|
|
||||||
ComponentInstance(std::string name, std::vector<InstanceAttribute*> attributes, std::pair<int, int> position, Component component);
|
ComponentInstance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position, Component component);
|
||||||
|
|
||||||
virtual ~ComponentInstance() {
|
virtual ~ComponentInstance() = default;
|
||||||
Instance::~Instance();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ class InstanceAttribute
|
|||||||
public:
|
public:
|
||||||
InstanceAttribute(std::string name, Value value, Attribute attribute);
|
InstanceAttribute(std::string name, Value value, Attribute attribute);
|
||||||
|
|
||||||
std::string name;
|
std::string name = "";
|
||||||
Value value;
|
Value value;
|
||||||
Attribute attribute;
|
Attribute attribute;
|
||||||
|
|
||||||
|
~InstanceAttribute() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
Library::Library(string name, string libraryInfo, string header, string componentDirectory,
|
Library::Library(string name, string libraryInfo, string header, string componentDirectory, std::optional<std::string> componentHeader,
|
||||||
vector<AddressSpace> addressSpaces, vector<Component> components, vector<Bus> buses, vector<Connection> connections, map<string, string> messages)
|
vector<AddressSpace> addressSpaces, vector<Component> components, vector<Bus> buses, vector<Connection> connections, map<string, string> messages)
|
||||||
: name(name), libraryInfo(libraryInfo), header(header), componentDirectory(componentDirectory), addressSpaces(addressSpaces),
|
: name(name), libraryInfo(libraryInfo), header(header), componentDirectory(componentDirectory), componentHeader(componentHeader), addressSpaces(addressSpaces),
|
||||||
components(components), buses(buses), connections(connections), messages(messages)
|
components(components), buses(buses), connections(connections), messages(messages)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -20,6 +20,9 @@ std::string Library::getHeader() {
|
|||||||
std::string Library::getComponentDirectory() {
|
std::string Library::getComponentDirectory() {
|
||||||
return componentDirectory;
|
return componentDirectory;
|
||||||
}
|
}
|
||||||
|
std::optional<std::string> Library::getComponentHeader() {
|
||||||
|
return componentHeader;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<AddressSpace> Library::getAddressSpaces() {
|
std::vector<AddressSpace> Library::getAddressSpaces() {
|
||||||
return addressSpaces;
|
return addressSpaces;
|
||||||
@@ -110,4 +113,18 @@ std::string Library::getMessage(std::string key) {
|
|||||||
return messages[key];
|
return messages[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Library::hasConnection(ConnectionComponent component, ConnectionComponent secondComponent) {
|
||||||
|
return getConnection(component, secondComponent).has_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<Connection>
|
||||||
|
Library::getConnection(ConnectionComponent component, ConnectionComponent secondComponent) {
|
||||||
|
for(auto & connection : connections) {
|
||||||
|
if(connection.isConnecting(component, secondComponent)) {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
@@ -21,6 +21,7 @@ class Library
|
|||||||
std::string libraryInfo;
|
std::string libraryInfo;
|
||||||
std::string header;
|
std::string header;
|
||||||
std::string componentDirectory;
|
std::string componentDirectory;
|
||||||
|
std::optional<std::string> componentHeader;
|
||||||
|
|
||||||
std::vector<AddressSpace> addressSpaces;
|
std::vector<AddressSpace> addressSpaces;
|
||||||
std::vector<Component> components;
|
std::vector<Component> components;
|
||||||
@@ -30,13 +31,14 @@ class Library
|
|||||||
std::map<std::string, std::string> messages;
|
std::map<std::string, std::string> messages;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Library(string name, string libraryInfo, string header, string componentDirectory,
|
Library(string name, string libraryInfo, string header, string componentDirectory, std::optional<string> componentHeader,
|
||||||
vector<AddressSpace> addressSpaces, vector<Component> components, vector<Bus> buses, vector<Connection> connection, map<string, string> messages);
|
vector<AddressSpace> addressSpaces, vector<Component> components, vector<Bus> buses, vector<Connection> connection, map<string, string> messages);
|
||||||
|
|
||||||
std::string getName();
|
std::string getName();
|
||||||
std::string getLibraryInfo();
|
std::string getLibraryInfo();
|
||||||
std::string getHeader();
|
std::string getHeader();
|
||||||
std::string getComponentDirectory();
|
std::string getComponentDirectory();
|
||||||
|
std::optional<std::string> getComponentHeader();
|
||||||
|
|
||||||
std::vector<AddressSpace> getAddressSpaces();
|
std::vector<AddressSpace> getAddressSpaces();
|
||||||
std::vector<Component> getComponents();
|
std::vector<Component> getComponents();
|
||||||
@@ -58,6 +60,10 @@ public:
|
|||||||
|
|
||||||
bool hasConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
bool hasConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
||||||
std::optional<Connection> getConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
std::optional<Connection> getConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
||||||
|
|
||||||
|
bool hasConnection(ConnectionComponent component, ConnectionComponent secondComponent);
|
||||||
|
std::optional<Connection> getConnection(ConnectionComponent component, ConnectionComponent secondComponent);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ std::string PinConnection::getMessage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Pin::Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display, std::optional<std::vector<Value>> wires)
|
Pin::Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, domain::ui::Pin pin, std::optional<std::vector<Value>> wires)
|
||||||
: name(name), type(type), tooltip(tooltip), connection(connection), display(display), wires(wires)
|
: name(name), type(type), tooltip(tooltip), connection(connection), displayPin(pin), wires(wires)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string Pin::getName() {
|
std::string &Pin::getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
Pin::PinType Pin::getType() {
|
Pin::PinType Pin::getType() {
|
||||||
@@ -27,8 +27,8 @@ Pin::PinType Pin::getType() {
|
|||||||
std::string Pin::getTooltip() {
|
std::string Pin::getTooltip() {
|
||||||
return tooltip;
|
return tooltip;
|
||||||
}
|
}
|
||||||
Display &Pin::getDisplay() {
|
ui::Pin &Pin::getDisplayPin() {
|
||||||
return display;
|
return displayPin;
|
||||||
}
|
}
|
||||||
PinConnection &Pin::getConnection() {
|
PinConnection &Pin::getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
|
|||||||
+6
-6
@@ -14,8 +14,8 @@ class PinConnection
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ConnectionType {
|
enum ConnectionType {
|
||||||
CHECK_ONLY,
|
REQUIRED,
|
||||||
AUTOMATICALLY
|
OPTIONAL
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -43,17 +43,17 @@ private:
|
|||||||
PinType type;
|
PinType type;
|
||||||
std::string tooltip;
|
std::string tooltip;
|
||||||
PinConnection connection;
|
PinConnection connection;
|
||||||
Display display;
|
domain::ui::Pin displayPin;
|
||||||
|
|
||||||
std::optional<std::vector<Value>> wires;
|
std::optional<std::vector<Value>> wires;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display, std::optional<std::vector<Value>> wires);
|
Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, domain::ui::Pin pin, std::optional<std::vector<Value>> wires);
|
||||||
|
|
||||||
std::string getName();
|
std::string &getName();
|
||||||
PinType getType();
|
PinType getType();
|
||||||
std::string getTooltip();
|
std::string getTooltip();
|
||||||
Display &getDisplay();
|
ui::Pin &getDisplayPin();
|
||||||
PinConnection &getConnection();
|
PinConnection &getConnection();
|
||||||
std::optional<std::vector<Value>> &getWires();
|
std::optional<std::vector<Value>> &getWires();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ bool Condition::evaluate(RuleContext &context) {
|
|||||||
request.push_back(params[i]);
|
request.push_back(params[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool result = context.function[function](request);
|
bool result = context.function[function]->validate(request);
|
||||||
return negated ? !result : result;
|
return negated ? !result : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace domain {
|
|||||||
struct RuleContext {
|
struct RuleContext {
|
||||||
std::map<std::string, AddressSpace> addressSpaces;
|
std::map<std::string, AddressSpace> addressSpaces;
|
||||||
std::map<std::string, Value> attributes;
|
std::map<std::string, Value> attributes;
|
||||||
std::map<std::string, FunctionCallback> function;
|
std::map<std::string, FunctionValidator*> function;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Condition {
|
class Condition {
|
||||||
|
|||||||
@@ -6,4 +6,23 @@ Schema::Schema()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Schema::hasConnection(string& component, string& pin) {
|
||||||
|
return getConnection(component, pin) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionInstance* Schema::getConnection(string& component, string& pin) {
|
||||||
|
for(auto& conn: connections) {
|
||||||
|
if(conn->instance->name == component && conn->connection.getComponent().pin == pin) {
|
||||||
|
return conn.get();
|
||||||
|
}
|
||||||
|
auto dirConn = dynamic_cast<DirectConnectionInstance*>(conn.get());
|
||||||
|
if(dirConn != nullptr) {
|
||||||
|
if(dirConn->secondInstance->name == component && conn->connection.getSecondComponent()->pin == pin) {
|
||||||
|
return dirConn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
+20
-21
@@ -9,37 +9,36 @@
|
|||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
class Schema
|
class Schema {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Schema();
|
Schema();
|
||||||
|
|
||||||
std::vector<Instance*> instances;
|
std::vector<shared_ptr<BusInstance>> busInstances;
|
||||||
std::vector<ConnectionInstance*> connections;
|
std::vector<shared_ptr<ComponentInstance>> componentInstances;
|
||||||
std::vector<WireInstance*> wires;
|
|
||||||
|
|
||||||
WireInstance *getWire(std::string name) {
|
std::vector<shared_ptr<ConnectionInstance>> connections;
|
||||||
for(auto wire: wires) {
|
|
||||||
if (wire->name == name) {
|
|
||||||
return wire;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasWire(std::string name) {
|
BusInstance *getBusInstance(std::string &name) {
|
||||||
return getWire(name) != NULL;
|
for (auto &instance: busInstances) {
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Instance *getInstance(std::string name) {
|
|
||||||
for(auto instance: instances) {
|
|
||||||
if (instance->name == name) {
|
if (instance->name == name) {
|
||||||
return instance;
|
return instance.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ComponentInstance *getComponentInstance(std::string &name) {
|
||||||
|
for (auto &instance: componentInstances) {
|
||||||
|
if (instance->name == name) {
|
||||||
|
return instance.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasConnection(string &component, string &pin);
|
||||||
|
|
||||||
|
ConnectionInstance *getConnection(string &component, string &pin);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|||||||
+262
-161
@@ -1,6 +1,7 @@
|
|||||||
#include "schemacreator.h"
|
#include "schemacreator.h"
|
||||||
|
|
||||||
#include<set>
|
#include<set>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
@@ -39,19 +40,31 @@ Value::ValueType toType(ValueNode::ValueType type) {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case ValueNode::BOOL:
|
case ValueNode::BOOL:
|
||||||
return Value::BOOL;
|
return Value::BOOL;
|
||||||
|
case ValueNode::MEMORY:
|
||||||
|
return Value::MEMORY_REFERENCE;
|
||||||
case ValueNode::WIRE:
|
case ValueNode::WIRE:
|
||||||
return Value::WIRE_REFERENCE;
|
return Value::WIRE_REFERENCE;
|
||||||
case ValueNode::STRING:
|
case ValueNode::STRING:
|
||||||
return Value::STRING;
|
return Value::STRING;
|
||||||
case ValueNode::INT:
|
case ValueNode::INT:
|
||||||
return Value::INT;
|
return Value::INT;
|
||||||
|
case ValueNode::NIL:
|
||||||
|
return Value::NIL;
|
||||||
default:
|
default:
|
||||||
return Value::UNDEFINED;
|
return Value::UNDEFINED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Value toType(ValueNode node) {
|
Value toType(ValueNode node, Value::ValueType type = Value::ValueType::UNDEFINED) {
|
||||||
|
if(type == Value::MEMORY_REFERENCE) {
|
||||||
|
if(node.getType() == ValueNode::NIL) {
|
||||||
|
return Value::fromMemoryReference(nullopt);
|
||||||
|
} else {
|
||||||
|
return Value::fromMemoryReference(node.asIdentifier());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(node.getType() == ValueNode::BOOL) {
|
if(node.getType() == ValueNode::BOOL) {
|
||||||
return Value::fromBool(node.asBool());
|
return Value::fromBool(node.asBool());
|
||||||
} else if(node.getType() == ValueNode::INT) {
|
} else if(node.getType() == ValueNode::INT) {
|
||||||
@@ -68,6 +81,8 @@ Value toType(ValueNode node) {
|
|||||||
Bus::BusType toType(BusNode::BusType type) {
|
Bus::BusType toType(BusNode::BusType type) {
|
||||||
if(type == BusNode::AUTOMATIC) {
|
if(type == BusNode::AUTOMATIC) {
|
||||||
return Bus::AUTOMATIC;
|
return Bus::AUTOMATIC;
|
||||||
|
} else if(type == BusNode::SINGLE_AUTOMATIC) {
|
||||||
|
return Bus::SINGLE_AUTOMATIC;
|
||||||
}
|
}
|
||||||
return Bus::REGULAR;
|
return Bus::REGULAR;
|
||||||
}
|
}
|
||||||
@@ -84,10 +99,10 @@ Pin::PinType toType(PinNode::PinType type) {
|
|||||||
|
|
||||||
PinConnection::ConnectionType toType(PinConnectionNode::ConnectionType type)
|
PinConnection::ConnectionType toType(PinConnectionNode::ConnectionType type)
|
||||||
{
|
{
|
||||||
if(type == PinConnectionNode::AUTOMATICALLY) {
|
if(type == PinConnectionNode::OPTIONAL) {
|
||||||
return PinConnection::AUTOMATICALLY;
|
return PinConnection::OPTIONAL;
|
||||||
}
|
}
|
||||||
return PinConnection::CHECK_ONLY;
|
return PinConnection::REQUIRED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -99,22 +114,26 @@ Popup::PopupType toType(PopupNode::PopupType type)
|
|||||||
return Popup::ON_DEMAND;
|
return Popup::ON_DEMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
SchemaCreator::SchemaCreator(std::vector<FunctionSignature> signatures)
|
SchemaCreator::SchemaCreator(std::vector<FunctionValidator*> validators)
|
||||||
: signatures(signatures)
|
: validators(std::move(validators))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::optional<Library> SchemaCreator::loadLibrary(LibraryNode node)
|
std::optional<Library> SchemaCreator::loadLibrary(LibraryNode node)
|
||||||
{
|
{
|
||||||
// library fields
|
// library fields
|
||||||
if(!node.name) {
|
if(!node.name) {
|
||||||
errors.push_back(SourceError{node.span, "missing @name"});
|
errors.emplace_back(node.span, "missing @name");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
} else {
|
} else {
|
||||||
name = node.name->asString();
|
name = node.name->asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(node.componentHeader.has_value()) {
|
||||||
|
componentHeader = node.componentHeader->asString();
|
||||||
|
}
|
||||||
|
|
||||||
if(!node.componentDirectory) {
|
if(!node.componentDirectory) {
|
||||||
errors.push_back(SourceError{node.span, "missing @componentDirectory"});
|
errors.emplace_back(node.span, "missing @componentDirectory");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
} else {
|
} else {
|
||||||
componentDirectory = node.componentDirectory->asString();
|
componentDirectory = node.componentDirectory->asString();
|
||||||
@@ -136,29 +155,29 @@ std::optional<Library> SchemaCreator::loadLibrary(LibraryNode node)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint i=0; i<node.buses.size(); i++) {
|
for(auto& buse : node.buses) {
|
||||||
auto bus = loadBus(node.buses[i]);
|
auto bus = loadBus(buse);
|
||||||
if(bus) {
|
if(bus) {
|
||||||
buses.push_back(*bus);
|
buses.push_back(*bus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint i=0; i<node.connections.size(); i++) {
|
for(auto& connection : node.connections) {
|
||||||
auto conn = loadConnection(node.connections[i]);
|
auto conn = loadConnection(connection);
|
||||||
if(conn) {
|
if(conn) {
|
||||||
connections.push_back(*conn);
|
connections.push_back(*conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint i=0; i<node.messages.size(); i++) {
|
for(auto & message : node.messages) {
|
||||||
if(!node.messages[i].value.is(ValueNode::STRING)) {
|
if(!message.value.is(ValueNode::STRING)) {
|
||||||
errors.push_back(SourceError{node.messages[i].value.span, "expected `string`"});
|
errors.emplace_back(message.value.span, "expected `string`");
|
||||||
} else {
|
} else {
|
||||||
messages[node.messages[i].key.value] = node.messages[i].value.asString();
|
messages[message.key.value] = message.value.asString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Library(name, libraryInfo, header, componentDirectory, addressSpaces, components, buses, connections, messages);
|
return Library(name, libraryInfo, header, componentDirectory, componentHeader, addressSpaces, components, buses, connections, messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Bus> SchemaCreator::loadBus(BusNode node)
|
std::optional<Bus> SchemaCreator::loadBus(BusNode node)
|
||||||
@@ -170,37 +189,42 @@ std::optional<Bus> SchemaCreator::loadBus(BusNode node)
|
|||||||
count = std::make_pair<int, int>(node.count->first.value, node.count->second.value);
|
count = std::make_pair<int, int>(node.count->first.value, node.count->second.value);
|
||||||
}
|
}
|
||||||
if(count.first > count.second || count.first < 0) {
|
if(count.first > count.second || count.first < 0) {
|
||||||
errors.push_back(SourceError{node.count->span, "invalid @size"});
|
errors.emplace_back(node.count->span, "invalid @size");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto type = toType(node.type.value);
|
auto type = toType(node.type.value);
|
||||||
|
|
||||||
if(!node.tooltip && type == Bus::REGULAR) {
|
if(!node.tooltip && type == Bus::REGULAR) {
|
||||||
errors.push_back(SourceError{node.span, "missing @tooltip"});
|
errors.emplace_back(node.span, "missing @tooltip");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
std::string tooltip = node.tooltip->asString();
|
std::string tooltip = node.tooltip->asString();
|
||||||
|
|
||||||
if(!node.display && type == Bus::REGULAR) {
|
if(!node.display && type == Bus::REGULAR) {
|
||||||
errors.push_back(SourceError{node.span, "missing @display"});
|
errors.emplace_back(node.span, "missing @display");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
if(node.display && (type == Bus::AUTOMATIC || type == Bus::AUTOMATIC_SINGLE)) {
|
if(node.display && (type == Bus::AUTOMATIC || type == Bus::SINGLE_AUTOMATIC)) {
|
||||||
errors.push_back(SourceError{node.span, "automatic bus cannot have a @display"});
|
errors.emplace_back(node.span, "automatic bus cannot have a @display");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<Display> display;
|
optional<ui::Bus> displayBus;
|
||||||
if(type == Bus::REGULAR) {
|
if(type == Bus::REGULAR) {
|
||||||
display = loadDisplay(*node.display);
|
auto display = loadDisplay(*node.display);
|
||||||
if(!display) {
|
if(!display) {
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
if(display->getItems().size() != 1 || !display->getItems()[0].bus.has_value()) {
|
||||||
|
errors.emplace_back(node.span, "@display must contain only exactly one bus definition");
|
||||||
|
return nullopt;
|
||||||
|
}
|
||||||
|
displayBus = *display->getItems()[0].bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(node.wires.size() == 0) {
|
if(node.wires.size() == 0) {
|
||||||
errors.push_back(SourceError{node.span, "missing @wires"});
|
errors.emplace_back(node.span, "missing @wires");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
std::vector<Wire> wires;
|
std::vector<Wire> wires;
|
||||||
@@ -211,7 +235,12 @@ std::optional<Bus> SchemaCreator::loadBus(BusNode node)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Bus(name, tooltip, type, count, wires, display);
|
if(type == Bus::SINGLE_AUTOMATIC && wires.size() != 1) {
|
||||||
|
errors.emplace_back(node.span, "singleAutomatic bus must have exactly 1 wire defined");
|
||||||
|
return nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Bus(name, tooltip, type, count, wires, displayBus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -222,7 +251,7 @@ std::optional<AddressSpace> SchemaCreator::loadAddressSpace(AddressSpaceNode nod
|
|||||||
|
|
||||||
std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
||||||
{
|
{
|
||||||
push(ComdelContext("connection", false, true, false));
|
push(ComdelContext("connection", false, true, false, false));
|
||||||
|
|
||||||
std::string bus = node.bus.value;
|
std::string bus = node.bus.value;
|
||||||
auto busInstance = getBus(bus);
|
auto busInstance = getBus(bus);
|
||||||
@@ -230,6 +259,10 @@ std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
|||||||
errors.emplace_back(node.span, "bus does not exist");
|
errors.emplace_back(node.span, "bus does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(busInstance->getType() == Bus::SINGLE_AUTOMATIC) {
|
||||||
|
current().inSingleAutomaticConnection = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(busInstance->getType() == Bus::REGULAR) {
|
if(busInstance->getType() == Bus::REGULAR) {
|
||||||
ConnectionComponent first{node.first.component.value, node.first.pin.value};
|
ConnectionComponent first{node.first.component.value, node.first.pin.value};
|
||||||
|
|
||||||
@@ -284,7 +317,7 @@ std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
|||||||
pop();
|
pop();
|
||||||
|
|
||||||
return Connection(first, nullopt, bus, attributes, wires, nullopt);
|
return Connection(first, nullopt, bus, attributes, wires, nullopt);
|
||||||
} else if(busInstance->getType() == Bus::AUTOMATIC || busInstance->getType() == Bus::AUTOMATIC_SINGLE) {
|
} else if(busInstance->getType() == Bus::AUTOMATIC || busInstance->getType() == Bus::SINGLE_AUTOMATIC) {
|
||||||
ConnectionComponent first{node.first.component.value, node.first.pin.value};
|
ConnectionComponent first{node.first.component.value, node.first.pin.value};
|
||||||
|
|
||||||
if(!node.second.has_value()) {
|
if(!node.second.has_value()) {
|
||||||
@@ -309,6 +342,10 @@ std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
|||||||
current().wires.push_back(wire.getName());
|
current().wires.push_back(wire.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(node.attributes.size() != 2 && busInstance->getType() == Bus::SINGLE_AUTOMATIC) {
|
||||||
|
errors.emplace_back(node.span, "singleAutomatic must contain 2 attributes");
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Attribute> attributes;
|
std::vector<Attribute> attributes;
|
||||||
for(auto & attribute : node.attributes) {
|
for(auto & attribute : node.attributes) {
|
||||||
auto attr = loadAttribute(attribute);
|
auto attr = loadAttribute(attribute);
|
||||||
@@ -329,7 +366,9 @@ std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
|||||||
firstWires.push_back(Value::fromNull());
|
firstWires.push_back(Value::fromNull());
|
||||||
} else if(firstWire.is(ValueNode::INT)) {
|
} else if(firstWire.is(ValueNode::INT)) {
|
||||||
firstWires.push_back(Value::fromInt(firstWire.asInt()));
|
firstWires.push_back(Value::fromInt(firstWire.asInt()));
|
||||||
} else if(firstWire.is(ValueNode::IDENTIFIER)) {
|
} else if(firstWire.is(ValueNode::STRING) && busInstance->getType() == Bus::SINGLE_AUTOMATIC) {
|
||||||
|
firstWires.push_back(Value::fromString(firstWire.asString()));
|
||||||
|
} else if(firstWire.is(ValueNode::IDENTIFIER) && busInstance->getType() == Bus::AUTOMATIC) {
|
||||||
if(attributeNames.count(firstWire.asIdentifier())) {
|
if(attributeNames.count(firstWire.asIdentifier())) {
|
||||||
firstWires.push_back(Value::fromReference(firstWire.asIdentifier(), Value::ATTRIBUTE_REFERENCE));
|
firstWires.push_back(Value::fromReference(firstWire.asIdentifier(), Value::ATTRIBUTE_REFERENCE));
|
||||||
} else if(wireNames.count(firstWire.asIdentifier())) {
|
} else if(wireNames.count(firstWire.asIdentifier())) {
|
||||||
@@ -338,7 +377,7 @@ std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
|||||||
errors.emplace_back(firstWire.span, "unknown identifier");
|
errors.emplace_back(firstWire.span, "unknown identifier");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errors.emplace_back(firstWire.span, "unknown value type");
|
errors.emplace_back(firstWire.span, "unsupported value type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +388,9 @@ std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
|||||||
secondWires.push_back(Value::fromNull());
|
secondWires.push_back(Value::fromNull());
|
||||||
} else if(secondWire.is(ValueNode::INT)) {
|
} else if(secondWire.is(ValueNode::INT)) {
|
||||||
secondWires.push_back(Value::fromInt(secondWire.asInt()));
|
secondWires.push_back(Value::fromInt(secondWire.asInt()));
|
||||||
} else if(secondWire.is(ValueNode::IDENTIFIER)) {
|
} else if(secondWire.is(ValueNode::STRING) && busInstance->getType() == Bus::SINGLE_AUTOMATIC) {
|
||||||
|
secondWires.push_back(Value::fromString(secondWire.asString()));
|
||||||
|
} else if(secondWire.is(ValueNode::IDENTIFIER) && busInstance->getType() == Bus::AUTOMATIC) {
|
||||||
if(attributeNames.count(secondWire.asIdentifier())) {
|
if(attributeNames.count(secondWire.asIdentifier())) {
|
||||||
secondWires.push_back(Value::fromReference(secondWire.asIdentifier(), Value::ATTRIBUTE_REFERENCE));
|
secondWires.push_back(Value::fromReference(secondWire.asIdentifier(), Value::ATTRIBUTE_REFERENCE));
|
||||||
} else if(wireNames.count(secondWire.asIdentifier())) {
|
} else if(wireNames.count(secondWire.asIdentifier())) {
|
||||||
@@ -358,7 +399,25 @@ std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
|||||||
errors.emplace_back(secondWire.span, "unknown identifier");
|
errors.emplace_back(secondWire.span, "unknown identifier");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errors.emplace_back(secondWire.span, "unknown value type");
|
errors.emplace_back(secondWire.span, "unsupported value type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(busInstance->getType() == Bus::SINGLE_AUTOMATIC && attributes.size() == 2) {
|
||||||
|
if(!attributes[0].getPopup().has_value()) {
|
||||||
|
errors.emplace_back(node.attributes[0].span, "@popup is required");
|
||||||
|
} else if(attributes[0].getDefault().getType() != Value::STRING) {
|
||||||
|
errors.emplace_back(node.attributes[0].span, "@attribute must be of type string");
|
||||||
|
} else {
|
||||||
|
attributes[0].getPopup()->setEnumeration(createWireEnumeration(firstWires));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!attributes[1].getPopup().has_value()) {
|
||||||
|
errors.emplace_back(node.attributes[1].span, "@popup is required");
|
||||||
|
} else if(attributes[1].getDefault().getType() != Value::STRING) {
|
||||||
|
errors.emplace_back(node.attributes[1].span, "@attribute must be of type string");
|
||||||
|
} else {
|
||||||
|
attributes[1].getPopup()->setEnumeration(createWireEnumeration(secondWires));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,19 +433,19 @@ std::optional<Connection> SchemaCreator::loadConnection(ConnectionNode node)
|
|||||||
|
|
||||||
std::optional<Component> SchemaCreator::loadComponent(ComponentNode node)
|
std::optional<Component> SchemaCreator::loadComponent(ComponentNode node)
|
||||||
{
|
{
|
||||||
push(ComdelContext(node.name.value, true, false, false));
|
push(ComdelContext(node.name.value, true, false, false, false));
|
||||||
|
|
||||||
std::string name = node.name.value;
|
std::string name = node.name.value;
|
||||||
|
|
||||||
if(!node.tooltip) {
|
if(!node.tooltip) {
|
||||||
errors.push_back(SourceError{node.span, "missing @tooltip"});
|
errors.emplace_back(node.span, "missing @tooltip");
|
||||||
pop();
|
pop();
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
std::string tooltip = node.tooltip->asString();
|
std::string tooltip = node.tooltip->asString();
|
||||||
|
|
||||||
if(!node.source) {
|
if(!node.source) {
|
||||||
errors.push_back(SourceError{node.span, "missing @source"});
|
errors.emplace_back(node.span, "missing @source");
|
||||||
pop();
|
pop();
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
@@ -401,6 +460,9 @@ std::optional<Component> SchemaCreator::loadComponent(ComponentNode node)
|
|||||||
attributes.push_back(*attribute);
|
attributes.push_back(*attribute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(type == Component::PROCESSOR) {
|
||||||
|
attributes.push_back(*createMemoryAttribute());
|
||||||
|
}
|
||||||
|
|
||||||
context[context.size() -1 ].attributes = attributes;
|
context[context.size() -1 ].attributes = attributes;
|
||||||
|
|
||||||
@@ -413,7 +475,7 @@ std::optional<Component> SchemaCreator::loadComponent(ComponentNode node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!node.instanceName) {
|
if(!node.instanceName) {
|
||||||
errors.push_back(SourceError{node.span, "missing @instanceName"});
|
errors.emplace_back(node.span, "missing @instanceName");
|
||||||
pop();
|
pop();
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
@@ -424,13 +486,13 @@ std::optional<Component> SchemaCreator::loadComponent(ComponentNode node)
|
|||||||
count = std::make_pair<int, int>(node.count->first.value, node.count->second.value);
|
count = std::make_pair<int, int>(node.count->first.value, node.count->second.value);
|
||||||
}
|
}
|
||||||
if(count.first > count.second || count.first < 0) {
|
if(count.first > count.second || count.first < 0) {
|
||||||
errors.push_back(SourceError{node.count->first.span, "invalid @size"});
|
errors.emplace_back(node.count->first.span, "invalid @size");
|
||||||
pop();
|
pop();
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!node.display) {
|
if(!node.display) {
|
||||||
errors.push_back(SourceError{node.span, "missing @display"});
|
errors.emplace_back(node.span, "missing @display");
|
||||||
pop();
|
pop();
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
@@ -441,8 +503,8 @@ std::optional<Component> SchemaCreator::loadComponent(ComponentNode node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Pin> pins;
|
std::vector<Pin> pins;
|
||||||
for(uint i=0; i<node.pins.size(); i++) {
|
for(auto &p : node.pins) {
|
||||||
auto pin = loadPin(node.pins[i]);
|
auto pin = loadPin(p);
|
||||||
if(!pin) {
|
if(!pin) {
|
||||||
pop();
|
pop();
|
||||||
return nullopt;
|
return nullopt;
|
||||||
@@ -471,13 +533,13 @@ optional<Pin> SchemaCreator::loadPin(PinNode node)
|
|||||||
Pin::PinType type = toType(node.type.value);
|
Pin::PinType type = toType(node.type.value);
|
||||||
|
|
||||||
if(!node.tooltip) {
|
if(!node.tooltip) {
|
||||||
errors.push_back(SourceError{node.span, "missing @tooltip"});
|
errors.emplace_back(node.span, "missing @tooltip");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
std::string tooltip = node.tooltip->asString();
|
std::string tooltip = node.tooltip->asString();
|
||||||
|
|
||||||
if(!node.display) {
|
if(!node.display) {
|
||||||
errors.push_back(SourceError{node.span, "missing @display"});
|
errors.emplace_back(node.span, "missing @display");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
std::vector<Attribute> attributes;
|
std::vector<Attribute> attributes;
|
||||||
@@ -485,9 +547,15 @@ optional<Pin> SchemaCreator::loadPin(PinNode node)
|
|||||||
if(!display) {
|
if(!display) {
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
if(display->getItems().size() != 1 || !display->getItems()[0].pin.has_value()) {
|
||||||
|
errors.emplace_back(node.span, "@display must contain only exactly one pin definition");
|
||||||
|
return nullopt;
|
||||||
|
}
|
||||||
|
ui::Pin displayPin = *display->getItems()[0].pin;
|
||||||
|
|
||||||
|
|
||||||
if(!node.connection) {
|
if(!node.connection) {
|
||||||
errors.push_back(SourceError{node.span, "missing @connection"});
|
errors.emplace_back(node.span, "missing @connection");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
auto connection = loadPinConnection(*node.connection);
|
auto connection = loadPinConnection(*node.connection);
|
||||||
@@ -508,16 +576,7 @@ optional<Pin> SchemaCreator::loadPin(PinNode node)
|
|||||||
wiresOpt = wires;
|
wiresOpt = wires;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pin(name, type, tooltip, connection, *display, wiresOpt);
|
return Pin(name, type, tooltip, connection, displayPin, wiresOpt);
|
||||||
}
|
|
||||||
|
|
||||||
int getIntProperty(DisplayItemNode &node, std::string property) {
|
|
||||||
for(auto& prop: node.values) {
|
|
||||||
if(prop.key.value == property) {
|
|
||||||
return prop.value.asInt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw std::exception();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node)
|
std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node)
|
||||||
@@ -527,28 +586,73 @@ std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node)
|
|||||||
ui::Item displayItem;
|
ui::Item displayItem;
|
||||||
std::string type = item.type.value;
|
std::string type = item.type.value;
|
||||||
if(type == "rect") {
|
if(type == "rect") {
|
||||||
int x, y, w, h;
|
long long int x, y, w, h;
|
||||||
x = getIntProperty(item, "x");
|
x = item.asInt(&errors, "x");
|
||||||
y = getIntProperty(item, "y");
|
y = item.asInt(&errors, "y");
|
||||||
w = getIntProperty(item, "w");
|
w = item.asInt(&errors, "w");
|
||||||
h = getIntProperty(item, "h");
|
h = item.asInt(&errors, "h");
|
||||||
displayItem.rect = ui::Rect(x, y, w, h);
|
displayItem.rect = ui::Rect(x, y, w, h);
|
||||||
} else if(type == "line") {
|
} else if(type == "line") {
|
||||||
int x1, y1, x2, y2;
|
long long int x1, y1, x2, y2;
|
||||||
x1 = getIntProperty(item, "x1");
|
x1 = item.asInt(&errors, "x1");
|
||||||
y1 = getIntProperty(item, "y1");
|
y1 = item.asInt(&errors, "y1");
|
||||||
x2 = getIntProperty(item, "x2");
|
x2 = item.asInt(&errors, "x2");
|
||||||
y2 = getIntProperty(item, "y2");
|
y2 = item.asInt(&errors, "y2");
|
||||||
displayItem.line = ui::Line(x1, y1, x2, y2);
|
displayItem.line = ui::Line(x1, y1, x2, y2);
|
||||||
} else if(type == "pin") {
|
} else if(type == "pin") {
|
||||||
int x, y, w, h;
|
long long int x, y, w, h;
|
||||||
x = getIntProperty(item, "x");
|
x = item.asInt(&errors, "x");
|
||||||
y = getIntProperty(item, "y");
|
y = item.asInt(&errors, "y");
|
||||||
w = getIntProperty(item, "w");
|
w = item.asInt(&errors, "w");
|
||||||
h = getIntProperty(item, "h");
|
h = item.asInt(&errors, "h");
|
||||||
displayItem.pin = ui::Pin(x, y, w, h);
|
std::string _orientation = item.asString(&errors, "orientation", "bottom");
|
||||||
|
std::string _pinType = item.asString(&errors, "type", "out");
|
||||||
|
|
||||||
|
ui::PinOrientation orientation;
|
||||||
|
if(_orientation == "left") {
|
||||||
|
orientation = ui::PinOrientation::LEFT;
|
||||||
|
} else if(_orientation == "right") {
|
||||||
|
orientation = ui::PinOrientation::RIGHT;
|
||||||
|
} else if(_orientation == "top") {
|
||||||
|
orientation = ui::PinOrientation::TOP;
|
||||||
|
} else if(_orientation == "bottom") {
|
||||||
|
orientation = ui::PinOrientation::BOTTOM;
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError{item.type.span, "unsupported display type"});
|
errors.emplace_back(item.span, "unknown pin orientation type '" + _orientation + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
ui::PinType pinType;
|
||||||
|
if(_pinType == "in") {
|
||||||
|
pinType = ui::PinType::IN;
|
||||||
|
} else if(_pinType == "out") {
|
||||||
|
pinType = ui::PinType::OUT;
|
||||||
|
} else if(_pinType == "in_out") {
|
||||||
|
pinType = ui::PinType::IN_OUT;
|
||||||
|
} else {
|
||||||
|
errors.emplace_back(item.span, "unknown pin type '" + _pinType + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
displayItem.pin = ui::Pin(x, y, w, h, orientation, pinType);
|
||||||
|
} 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");
|
||||||
|
|
||||||
|
ui::BusOrientation orientation;
|
||||||
|
if(_orientation == "horizontal") {
|
||||||
|
orientation = ui::BusOrientation::HORIZONTAL;
|
||||||
|
} else if(_orientation == "vertical") {
|
||||||
|
orientation = ui::BusOrientation::VERTICAL;
|
||||||
|
} else {
|
||||||
|
errors.emplace_back(item.span, "unknown bus orientation type '" + _orientation + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
displayItem.bus = ui::Bus(x, y, w, h, orientation);
|
||||||
|
} else {
|
||||||
|
errors.emplace_back(item.type.span, "unsupported display type");
|
||||||
}
|
}
|
||||||
items.push_back(displayItem);
|
items.push_back(displayItem);
|
||||||
}
|
}
|
||||||
@@ -560,7 +664,7 @@ PinConnection SchemaCreator::loadPinConnection(PinConnectionNode node)
|
|||||||
{
|
{
|
||||||
std::string message = node.message.asString();
|
std::string message = node.message.asString();
|
||||||
PinConnection::ConnectionType type = toType(node.type.value);
|
PinConnection::ConnectionType type = toType(node.type.value);
|
||||||
return PinConnection(message, type);
|
return {message, type};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Attribute> SchemaCreator::loadAttribute(AttributeNode node)
|
std::optional<Attribute> SchemaCreator::loadAttribute(AttributeNode node)
|
||||||
@@ -577,23 +681,30 @@ std::optional<Attribute> SchemaCreator::loadAttribute(AttributeNode node)
|
|||||||
} else if (node.type == ValueNode::STRING) {
|
} else if (node.type == ValueNode::STRING) {
|
||||||
value = Value::fromString(node.defaultValue->asString());
|
value = Value::fromString(node.defaultValue->asString());
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError{node.name.span, "unsupported type"});
|
errors.emplace_back(node.name.span, "unsupported type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(current().inConnection) { // TODO remove identifier
|
if(current().inConnection && !current().inSingleAutomaticConnection) { // TODO remove identifier
|
||||||
if (node.type == ValueNode::WIRE || node.type == ValueNode::IDENTIFIER) {
|
if (node.type == ValueNode::WIRE || node.type == ValueNode::IDENTIFIER) {
|
||||||
if(current().doesWireExists(node.defaultValue->asIdentifier())) {
|
if(current().doesWireExists(node.defaultValue->asIdentifier())) {
|
||||||
value = Value::fromReference(node.defaultValue->asIdentifier(), Value::WIRE_REFERENCE);
|
value = Value::fromReference(node.defaultValue->asIdentifier(), Value::WIRE_REFERENCE);
|
||||||
} else {
|
} else {
|
||||||
value = Value::fromReference("", Value::WIRE_REFERENCE);
|
value = Value::fromReference("", Value::WIRE_REFERENCE);
|
||||||
errors.push_back(SourceError{node.span, "unknown identifier"});
|
errors.emplace_back(node.span, "unknown identifier");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError{node.name.span, "unsupported type"});
|
errors.emplace_back(node.name.span, "unsupported type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(current().inSingleAutomaticConnection) {
|
||||||
|
if (node.type == ValueNode::STRING) {
|
||||||
|
value = Value::fromString(node.defaultValue->asString());
|
||||||
|
} else {
|
||||||
|
errors.emplace_back(node.name.span, "unsupported type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current().attributes.push_back(Attribute(name, value));
|
current().attributes.emplace_back(name, value);
|
||||||
|
|
||||||
std::optional<Popup> popup;
|
std::optional<Popup> popup;
|
||||||
if(node.popup) {
|
if(node.popup) {
|
||||||
@@ -611,16 +722,16 @@ std::optional<Popup> SchemaCreator::loadPopup(PopupNode node, std::string name,
|
|||||||
pushAdditional(name);
|
pushAdditional(name);
|
||||||
|
|
||||||
current().attributes.clear();
|
current().attributes.clear();
|
||||||
current().attributes.push_back(Attribute(name, Value::ofType(type)));
|
current().attributes.emplace_back(name, Value::ofType(type));
|
||||||
|
|
||||||
if(!node.title) {
|
if(!node.title) {
|
||||||
errors.push_back(SourceError{node.span, "missing @title"});
|
errors.emplace_back(node.span, "missing @title");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
std::string title = node.title->asString();
|
std::string title = node.title->asString();
|
||||||
|
|
||||||
if(!node.text) {
|
if(!node.text) {
|
||||||
errors.push_back(SourceError{node.span, "missing @text"});
|
errors.emplace_back(node.span, "missing @text");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
std::string text = node.text->asString();
|
std::string text = node.text->asString();
|
||||||
@@ -635,34 +746,34 @@ std::optional<Popup> SchemaCreator::loadPopup(PopupNode node, std::string name,
|
|||||||
|
|
||||||
std::vector<Enumeration> enumeration;
|
std::vector<Enumeration> enumeration;
|
||||||
if(node.enumerated) {
|
if(node.enumerated) {
|
||||||
for(uint i=0; i<node.enumeration.size(); i++) {
|
for(auto& enumNode : node.enumeration) {
|
||||||
if(type == Value::INT || type == Value::STRING || type == Value::BOOL) {
|
if(type == Value::INT || type == Value::STRING || type == Value::BOOL) {
|
||||||
auto value = toType(node.enumeration[i].value);
|
auto value = toType(enumNode.value);
|
||||||
if(value.getType() == type) {
|
if(value.getType() == type) {
|
||||||
enumeration.push_back(Enumeration(node.enumeration[i].key.asString(), value));
|
enumeration.emplace_back(enumNode.key.asString(), value);
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError{node.enumeration[i].span, "wrong type"});
|
errors.emplace_back(enumNode.span, "wrong type");
|
||||||
}
|
}
|
||||||
} else if(type == Value::WIRE_REFERENCE) {
|
} else if(type == Value::WIRE_REFERENCE) {
|
||||||
auto value = toType(node.enumeration[i].value);
|
auto value = toType(enumNode.value);
|
||||||
if(value.isType(Value::UNDEFINED)) {
|
if(value.isType(Value::UNDEFINED)) {
|
||||||
if(current().doesWireExists(value.asReference())) {
|
if(current().doesWireExists(value.asReference())) {
|
||||||
value = Value::fromReference(value.asReference(), Value::WIRE_REFERENCE);
|
value = Value::fromReference(value.asReference(), Value::WIRE_REFERENCE);
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError{node.enumeration[i].span, "unknown wire"});
|
errors.emplace_back(enumNode.span, "unknown wire");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value.isType(Value::WIRE_REFERENCE) || value.isType(Value::INT) || value.isType(Value::NIL)) {
|
if(value.isType(Value::WIRE_REFERENCE) || value.isType(Value::INT) || value.isType(Value::NIL)) {
|
||||||
enumeration.push_back(Enumeration(node.enumeration[i].key.asString(), value));
|
enumeration.emplace_back(enumNode.key.asString(), value);
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError{node.enumeration[i].span, "wrong type"});
|
errors.emplace_back(enumNode.span, "wrong type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(type == Value::WIRE_REFERENCE && !current().inConnection) {
|
if(type == Value::WIRE_REFERENCE && !current().inConnection) {
|
||||||
errors.push_back(SourceError{node.span, "@enumeration is required for attributes of type wire"});
|
errors.emplace_back(node.span, "@enumeration is required for attributes of type wire");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,7 +789,7 @@ std::optional<Rule> SchemaCreator::loadRule(RuleNode node)
|
|||||||
for(auto& stmt: node.statements) {
|
for(auto& stmt: node.statements) {
|
||||||
auto condition = loadCondition(stmt.condition);
|
auto condition = loadCondition(stmt.condition);
|
||||||
if(condition) {
|
if(condition) {
|
||||||
statements.push_back(IfStatement(*condition, Action(toType(stmt.action.type.value), stmt.action.message.asString())));
|
statements.emplace_back(*condition, Action(toType(stmt.action.type.value), stmt.action.message.asString()));
|
||||||
} else {
|
} else {
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
@@ -691,19 +802,19 @@ std::optional<Condition> SchemaCreator::loadCondition(ConditionNode node)
|
|||||||
{
|
{
|
||||||
std::string function = node.functionName.value;
|
std::string function = node.functionName.value;
|
||||||
|
|
||||||
for(uint i=0; i<signatures.size(); i++) {
|
for(auto & validator : validators) {
|
||||||
if(signatures[i].name == function) {
|
if(validator->getName() == function) {
|
||||||
if(signatures[i].params.size() == node.params.size()) {
|
if(validator->getSignature().size() == node.params.size()) {
|
||||||
std::vector<Value> params;
|
std::vector<Value> params;
|
||||||
for(uint j=0; j<signatures[i].params.size(); j++) {
|
for(uint j=0; j<validator->getSignature().size(); j++) {
|
||||||
bool exists = false;
|
bool exists = false;
|
||||||
auto type = toType(node.params[j]);
|
auto type = toType(node.params[j]);
|
||||||
if (type.getType() == Value::UNDEFINED) {
|
if (type.getType() == Value::UNDEFINED) {
|
||||||
if(current().doesAttributeExists(type.asReference(), signatures[i].params[j])) {
|
if(current().doesAttributeExists(type.asReference(), validator->getSignature()[j])) {
|
||||||
exists = true;
|
exists = true;
|
||||||
type = Value::fromReference(type.asReference(), Value::ATTRIBUTE_REFERENCE);
|
type = Value::fromReference(type.asReference(), Value::ATTRIBUTE_REFERENCE);
|
||||||
}
|
}
|
||||||
if(signatures[i].params[j] == Value::ADDRESS_SPACE) {
|
if(validator->getSignature()[j] == Value::ADDRESS_SPACE) {
|
||||||
if(hasAddressSpace(type.asReference())) {
|
if(hasAddressSpace(type.asReference())) {
|
||||||
exists = true;
|
exists = true;
|
||||||
type = Value::fromReference(type.asReference(), Value::ADDRESS_SPACE_REFERENCE);
|
type = Value::fromReference(type.asReference(), Value::ADDRESS_SPACE_REFERENCE);
|
||||||
@@ -711,76 +822,69 @@ std::optional<Condition> SchemaCreator::loadCondition(ConditionNode node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!exists) {
|
if(!exists) {
|
||||||
errors.push_back(SourceError{node.functionName.span, "unknown reference " + type.asReference()});
|
errors.emplace_back(node.functionName.span, "unknown reference " + type.asReference());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
params.push_back(type);
|
params.push_back(type);
|
||||||
}
|
}
|
||||||
return Condition(function, params, node.negated);
|
return Condition(function, params, node.negated);
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError{node.functionName.span, "wrong number of parameters"});
|
errors.emplace_back(node.functionName.span, "wrong number of parameters");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
errors.push_back(SourceError{node.functionName.span, "unknown function name"});
|
errors.emplace_back(node.functionName.span, "unknown function name");
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Schema* SchemaCreator::loadSchema(SchemaNode node, Library &library)
|
Schema* SchemaCreator::loadSchema(SchemaNode node, Library &library)
|
||||||
{
|
{
|
||||||
Schema *schema = new Schema();
|
auto *schema = new Schema();
|
||||||
|
|
||||||
for(auto &instance: node.instances) {
|
for(auto &instance: node.instances) {
|
||||||
if(library.hasComponent(instance.component.value)) {
|
if(library.hasComponent(instance.component.value)) {
|
||||||
schema->instances.push_back(loadComponentInstance(instance, library));
|
schema->componentInstances.push_back(loadComponentInstance(instance, library));
|
||||||
}
|
}
|
||||||
if(library.hasBus(instance.component.value)) {
|
if(library.hasBus(instance.component.value)) {
|
||||||
schema->instances.push_back(loadBusInstance(instance, library));
|
schema->busInstances.push_back(loadBusInstance(instance, library));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto &wire: node.wires) {
|
|
||||||
auto w = loadWireInstance(wire);
|
|
||||||
if(w) {
|
|
||||||
schema->wires.push_back(*w);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto &conn: node.connections) {
|
for(auto &conn: node.connections) {
|
||||||
auto firstComponent = dynamic_cast<ComponentInstance*>(schema->getInstance(conn.first.instance.value));
|
auto firstComponent = schema->getComponentInstance(conn.first.instance.value);
|
||||||
if(firstComponent == NULL) {
|
if(firstComponent == nullptr) {
|
||||||
errors.push_back(SourceError{conn.first.instance.span, "unknown component"});
|
errors.emplace_back(conn.first.instance.span, "unknown component");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!firstComponent->component.hasPin(conn.first.pin.value)) {
|
if(!firstComponent->component.hasPin(conn.first.pin.value)) {
|
||||||
errors.push_back(SourceError{conn.first.pin.span, "unknown pin"});
|
errors.emplace_back(conn.first.pin.span, "unknown pin");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ComponentInstance *secondComponent = NULL;
|
ComponentInstance *secondComponent = nullptr;
|
||||||
if(conn.second.has_value()) {
|
if(conn.second.has_value()) {
|
||||||
secondComponent = dynamic_cast<ComponentInstance*>(schema->getInstance(conn.second->instance.value));
|
secondComponent = schema->getComponentInstance(conn.second->instance.value);
|
||||||
if(secondComponent == NULL) {
|
if(secondComponent == nullptr) {
|
||||||
errors.push_back(SourceError{conn.second->instance.span, "unknown component"});
|
errors.emplace_back(conn.second->instance.span, "unknown component");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!secondComponent->component.hasPin(conn.second->pin.value)) {
|
if(!secondComponent->component.hasPin(conn.second->pin.value)) {
|
||||||
errors.push_back(SourceError{conn.second->pin.span, "unknown pin"});
|
errors.emplace_back(conn.second->pin.span, "unknown pin");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto bus = dynamic_cast<BusInstance*>(schema->getInstance(conn.bus.value));
|
auto bus = schema->getBusInstance(conn.bus.value);
|
||||||
if(bus == NULL) {
|
if(bus == nullptr) {
|
||||||
errors.push_back(SourceError{conn.bus.span, "unknown bus"});
|
errors.emplace_back(conn.bus.span, "unknown bus");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Connection> connection = std::nullopt;
|
std::optional<Connection> connection = std::nullopt;
|
||||||
if(secondComponent != NULL) {
|
if(secondComponent != nullptr) {
|
||||||
ConnectionComponent firstConn{firstComponent->component.getName(), conn.first.pin.value};
|
ConnectionComponent firstConn{firstComponent->component.getName(), conn.first.pin.value};
|
||||||
ConnectionComponent secondConn{secondComponent->component.getName(), conn.second->pin.value};
|
ConnectionComponent secondConn{secondComponent->component.getName(), conn.second->pin.value};
|
||||||
|
|
||||||
@@ -789,7 +893,7 @@ Schema* SchemaCreator::loadSchema(SchemaNode node, Library &library)
|
|||||||
secondConn)) {
|
secondConn)) {
|
||||||
connection = *library.getConnection(firstConn, bus->bus.getName(), secondConn);
|
connection = *library.getConnection(firstConn, bus->bus.getName(), secondConn);
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError{conn.span, "unknown connection"});
|
errors.emplace_back(conn.span, "unknown connection");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -799,23 +903,12 @@ Schema* SchemaCreator::loadSchema(SchemaNode node, Library &library)
|
|||||||
bus->bus.getName())) {
|
bus->bus.getName())) {
|
||||||
connection = *library.getConnection(firstConn, bus->bus.getName());
|
connection = *library.getConnection(firstConn, bus->bus.getName());
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError{conn.span, "unknown connection"});
|
errors.emplace_back(conn.span, "unknown connection");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!conn.wire) {
|
std::vector<InstanceAttribute> attributes;
|
||||||
errors.push_back(SourceError{conn.span, "missing @wire"});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(!schema->hasWire(conn.wire->value)) {
|
|
||||||
errors.push_back(SourceError{conn.wire->span, "unknown wire"});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto wire = schema->getWire(conn.wire->value);
|
|
||||||
|
|
||||||
std::vector<InstanceAttribute*> attributes;
|
|
||||||
for(auto& attr: conn.attributes) {
|
for(auto& attr: conn.attributes) {
|
||||||
if(connection->hasAttribute(attr.name.value)) {
|
if(connection->hasAttribute(attr.name.value)) {
|
||||||
auto attribute = connection->getAttribute(attr.name.value);
|
auto attribute = connection->getAttribute(attr.name.value);
|
||||||
@@ -827,26 +920,26 @@ Schema* SchemaCreator::loadSchema(SchemaNode node, Library &library)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(value.isType(Value::UNDEFINED)) {
|
if(value.isType(Value::UNDEFINED)) {
|
||||||
errors.push_back(SourceError{attr.span, "invalid value"});
|
errors.emplace_back(attr.span, "invalid value");
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes.push_back(new InstanceAttribute(attribute.getName(), toType(attr.value), attribute));
|
attributes.emplace_back(attribute.getName(), toType(attr.value), attribute);
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError(attr.name.span, "unknown attribute"));
|
errors.emplace_back(attr.name.span, "unknown attribute");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(secondComponent == NULL) {
|
if(secondComponent == nullptr) {
|
||||||
schema->connections.push_back(new BusConnectionInstance(firstComponent, attributes, bus, wire, *connection));
|
schema->connections.push_back(std::make_shared<BusConnectionInstance>(firstComponent, attributes, bus, *connection));
|
||||||
} else {
|
} else {
|
||||||
schema->connections.push_back(new DirectConnectionInstance(firstComponent, secondComponent, attributes, bus, wire, *connection));
|
schema->connections.push_back(std::make_shared<DirectConnectionInstance>(firstComponent, secondComponent, attributes, bus, *connection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentInstance *SchemaCreator::loadComponentInstance(InstanceNode instance, Library &library) {
|
shared_ptr<ComponentInstance> SchemaCreator::loadComponentInstance(InstanceNode instance, Library &library) {
|
||||||
|
|
||||||
auto name = instance.name.value;
|
auto name = instance.name.value;
|
||||||
auto position = std::make_pair(instance.position->first.value, instance.position->second.value);
|
auto position = std::make_pair(instance.position->first.value, instance.position->second.value);
|
||||||
@@ -854,19 +947,27 @@ ComponentInstance *SchemaCreator::loadComponentInstance(InstanceNode instance, L
|
|||||||
auto component = library.getComponent(instance.component.value);
|
auto component = library.getComponent(instance.component.value);
|
||||||
|
|
||||||
// validate attributes
|
// validate attributes
|
||||||
std::vector<InstanceAttribute*> attributes;
|
std::vector<InstanceAttribute> attributes;
|
||||||
for(auto& attr: instance.attributes) {
|
for(auto& attr: instance.attributes) {
|
||||||
if(component.hasAttribute(attr.name.value, toType(attr.value.getType()))) {
|
if(component.hasAttribute(attr.name.value, toType(attr.value.getType()))) {
|
||||||
auto attribute = component.getAttribute(attr.name.value);
|
auto attribute = component.getAttribute(attr.name.value);
|
||||||
attributes.push_back(new InstanceAttribute(attribute.getName(), toType(attr.value), attribute));
|
attributes.emplace_back(attribute.getName(), toType(attr.value, attribute.getDefault().getType()), attribute);
|
||||||
} else {
|
} else {
|
||||||
errors.push_back(SourceError(attr.name.span, "unknown attribute"));
|
errors.emplace_back(SourceError(attr.name.span, "unknown attribute"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ComponentInstance(name, attributes, position, component);
|
if(attributes.size() < component.getAttributes().size()) {
|
||||||
|
for(auto& attr: component.getAttributes()) {
|
||||||
|
if(std::count_if(attributes.begin(), attributes.end(), [&attr](InstanceAttribute& attribute){ return attr.getName() == attribute.name; }) == 0) {
|
||||||
|
errors.emplace_back(SourceError(instance.span, "missing attribute '" + attr.getName() + "'"));
|
||||||
}
|
}
|
||||||
BusInstance *SchemaCreator::loadBusInstance(InstanceNode instance, Library &library) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_shared<ComponentInstance>(name, attributes, position, component);
|
||||||
|
}
|
||||||
|
std::shared_ptr<BusInstance> SchemaCreator::loadBusInstance(InstanceNode instance, Library &library) {
|
||||||
|
|
||||||
auto name = instance.name.value;
|
auto name = instance.name.value;
|
||||||
auto position = std::make_pair(instance.position->first.value, instance.position->second.value);
|
auto position = std::make_pair(instance.position->first.value, instance.position->second.value);
|
||||||
@@ -878,25 +979,25 @@ BusInstance *SchemaCreator::loadBusInstance(InstanceNode instance, Library &libr
|
|||||||
size = instance.size->value;
|
size = instance.size->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BusInstance(name, position, bus, size);
|
return std::make_shared<BusInstance>(name, position, bus, static_cast<int>(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<WireInstance*> SchemaCreator::loadWireInstance(WireInstanceNode node) {
|
vector<Enumeration> SchemaCreator::createWireEnumeration(vector<Value> wireValues) {
|
||||||
|
vector<Enumeration> wires;
|
||||||
if(!node.display) {
|
for(auto& wire: wireValues) {
|
||||||
errors.push_back(SourceError{node.span, "missing @text"});
|
if(wire.isType(Value::STRING)) {
|
||||||
return nullopt;
|
wires.emplace_back(wire.asString(), wire);
|
||||||
}
|
}
|
||||||
auto display = loadDisplay(*node.display);
|
|
||||||
if(!display) {
|
|
||||||
return nullopt;
|
|
||||||
}
|
}
|
||||||
std::pair<int, int> position = std::make_pair(0, 0);
|
return wires;
|
||||||
if(node.position) {
|
|
||||||
position = std::make_pair(node.position->first.value, node.position->second.value);
|
|
||||||
}
|
|
||||||
return std::optional<WireInstance*>(new WireInstance(node.name.value, *display, position));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<Attribute> SchemaCreator::createMemoryAttribute() {
|
||||||
|
return Attribute("_memory", Value::fromMemoryReference(std::nullopt), createMemoryPopup());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<Popup> SchemaCreator::createMemoryPopup() {
|
||||||
|
return Popup("Postavi memoriju", "Postavi memoriju za izabrani procesor", Popup::AUTOMATIC, vector<Rule>{}, vector<Enumeration>{});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
@@ -18,10 +18,11 @@ struct ComdelContext {
|
|||||||
std::string name;
|
std::string name;
|
||||||
bool inComponent;
|
bool inComponent;
|
||||||
bool inConnection;
|
bool inConnection;
|
||||||
|
bool inSingleAutomaticConnection;
|
||||||
bool inBus;
|
bool inBus;
|
||||||
|
|
||||||
ComdelContext(std::string name, bool inComponent, bool inConnection, bool inBus)
|
ComdelContext(std::string name, bool inComponent, bool inConnection, bool inSingleAutomaticConnection, bool inBus)
|
||||||
: name(name), inComponent(inComponent), inConnection(inConnection), inBus(inBus)
|
: name(name), inComponent(inComponent), inConnection(inConnection), inSingleAutomaticConnection(inSingleAutomaticConnection), inBus(inBus)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool doesAttributeExists(std::string name, Value::ValueType type) {
|
bool doesAttributeExists(std::string name, Value::ValueType type) {
|
||||||
@@ -52,6 +53,7 @@ class SchemaCreator
|
|||||||
std::string libraryInfo;
|
std::string libraryInfo;
|
||||||
std::string header;
|
std::string header;
|
||||||
std::string componentDirectory;
|
std::string componentDirectory;
|
||||||
|
std::optional<std::string> componentHeader = nullopt;
|
||||||
std::vector<AddressSpace> addressSpaces;
|
std::vector<AddressSpace> addressSpaces;
|
||||||
std::vector<Component> components;
|
std::vector<Component> components;
|
||||||
std::vector<Bus> buses;
|
std::vector<Bus> buses;
|
||||||
@@ -60,7 +62,7 @@ class SchemaCreator
|
|||||||
|
|
||||||
|
|
||||||
std::vector<SourceError> errors;
|
std::vector<SourceError> errors;
|
||||||
std::vector<FunctionSignature> signatures;
|
std::vector<FunctionValidator*> validators;
|
||||||
|
|
||||||
std::optional<AddressSpace> loadAddressSpace(AddressSpaceNode node);
|
std::optional<AddressSpace> loadAddressSpace(AddressSpaceNode node);
|
||||||
std::optional<Component> loadComponent(ComponentNode node);
|
std::optional<Component> loadComponent(ComponentNode node);
|
||||||
@@ -75,9 +77,10 @@ class SchemaCreator
|
|||||||
std::optional<Connection> loadConnection(ConnectionNode node);
|
std::optional<Connection> loadConnection(ConnectionNode node);
|
||||||
std::optional<Bus> loadBus(BusNode node);
|
std::optional<Bus> loadBus(BusNode node);
|
||||||
|
|
||||||
ComponentInstance *loadComponentInstance(InstanceNode instance, Library &library);
|
std::shared_ptr<ComponentInstance> loadComponentInstance(InstanceNode instance, Library &library);
|
||||||
BusInstance *loadBusInstance(InstanceNode instance, Library &library);
|
std::shared_ptr<BusInstance> loadBusInstance(InstanceNode instance, Library &library);
|
||||||
std::optional<WireInstance*> loadWireInstance(WireInstanceNode node);
|
|
||||||
|
std::optional<Attribute> createMemoryAttribute();
|
||||||
|
|
||||||
std::optional<Bus> getBus(std::string name) {
|
std::optional<Bus> getBus(std::string name) {
|
||||||
for(auto &bus: buses) {
|
for(auto &bus: buses) {
|
||||||
@@ -114,11 +117,11 @@ class SchemaCreator
|
|||||||
this->context.push_back(context);
|
this->context.push_back(context);
|
||||||
}
|
}
|
||||||
void pushAdditional(std::string name) {
|
void pushAdditional(std::string name) {
|
||||||
if(this->context.size() > 0) {
|
if(!this->context.empty()) {
|
||||||
this->context.push_back(current());
|
this->context.push_back(current());
|
||||||
current().name = name;
|
current().name = name;
|
||||||
} else {
|
} else {
|
||||||
ComdelContext con(name, false, false, false);
|
ComdelContext con(name, false, false, false, false);
|
||||||
push(con);
|
push(con);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +133,7 @@ class SchemaCreator
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SchemaCreator(std::vector<FunctionSignature> signatures);
|
SchemaCreator(std::vector<FunctionValidator*> validators);
|
||||||
|
|
||||||
std::vector<SourceError> getErrors() {
|
std::vector<SourceError> getErrors() {
|
||||||
return errors;
|
return errors;
|
||||||
@@ -139,6 +142,10 @@ public:
|
|||||||
std::optional<Library> loadLibrary(LibraryNode node);
|
std::optional<Library> loadLibrary(LibraryNode node);
|
||||||
|
|
||||||
Schema* loadSchema(SchemaNode node, Library &library);
|
Schema* loadSchema(SchemaNode node, Library &library);
|
||||||
|
|
||||||
|
vector <Enumeration> createWireEnumeration(vector<Value> vector1);
|
||||||
|
|
||||||
|
std::optional<Popup> createMemoryPopup();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|||||||
+31
-1
@@ -68,6 +68,16 @@ std::string Value::asReference() {
|
|||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::optional<std::string> Value::asMemoryReference() {
|
||||||
|
return memoryReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
domain::ComponentInstance *Value::asMemory() {
|
||||||
|
return memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Value::setInt(long long value) {
|
void Value::setInt(long long value) {
|
||||||
if(isType(Value::INT)) {
|
if(isType(Value::INT)) {
|
||||||
this->intValue = value;
|
this->intValue = value;
|
||||||
@@ -124,11 +134,11 @@ Value Value::fromReference(std::string value, Value::ValueType type) {
|
|||||||
val.reference = value;
|
val.reference = value;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Value::ofType(Value::ValueType type) {
|
Value Value::ofType(Value::ValueType type) {
|
||||||
Value val;
|
Value val;
|
||||||
val.type = type;
|
val.type = type;
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Value::fromNull() {
|
Value Value::fromNull() {
|
||||||
@@ -151,9 +161,29 @@ std::string Value::stringify() {
|
|||||||
case ADDRESS_SPACE_REFERENCE:
|
case ADDRESS_SPACE_REFERENCE:
|
||||||
case ATTRIBUTE_REFERENCE:
|
case ATTRIBUTE_REFERENCE:
|
||||||
return reference;
|
return reference;
|
||||||
|
case MEMORY_REFERENCE:
|
||||||
|
if(memoryReference.has_value()) {
|
||||||
|
return memoryReference.value();
|
||||||
|
} else {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value Value::fromMemoryReference(std::optional<std::string> value) {
|
||||||
|
Value val;
|
||||||
|
val.type = MEMORY_REFERENCE;
|
||||||
|
val.memoryReference = value;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
Value Value::fromMemory(domain::ComponentInstance *memory) {
|
||||||
|
Value val;
|
||||||
|
val.type = MEMORY;
|
||||||
|
val.memory = memory;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
+42
-6
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
|
class ComponentInstance;
|
||||||
|
|
||||||
class Value
|
class Value
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -19,24 +21,54 @@ public:
|
|||||||
ADDRESS_SPACE,
|
ADDRESS_SPACE,
|
||||||
ADDRESS_SPACE_REFERENCE,
|
ADDRESS_SPACE_REFERENCE,
|
||||||
ATTRIBUTE_REFERENCE,
|
ATTRIBUTE_REFERENCE,
|
||||||
|
MEMORY_REFERENCE,
|
||||||
|
MEMORY,
|
||||||
WIRE_REFERENCE,
|
WIRE_REFERENCE,
|
||||||
NIL,
|
NIL,
|
||||||
UNDEFINED,
|
UNDEFINED,
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long intValue;
|
long long intValue = 0;
|
||||||
std::string stringValue;
|
std::string stringValue;
|
||||||
bool boolValue;
|
bool boolValue = false;
|
||||||
std::optional<AddressSpace> addressSpace;
|
std::optional<AddressSpace> addressSpace = std::nullopt;
|
||||||
std::string reference;
|
std::string reference;
|
||||||
|
domain::ComponentInstance *memory = nullptr;
|
||||||
|
|
||||||
ValueType type;
|
std::optional<std::string> memoryReference = std::nullopt;
|
||||||
|
|
||||||
|
ValueType type = UNDEFINED;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Value() {
|
Value() {}
|
||||||
this->type = UNDEFINED;
|
|
||||||
|
bool equals(Value value) {
|
||||||
|
if(value.getType() == type) {
|
||||||
|
switch (type) {
|
||||||
|
case INT:
|
||||||
|
return value.asInt() == intValue;
|
||||||
|
case STRING:
|
||||||
|
return value.asString() == stringValue;
|
||||||
|
case NIL:
|
||||||
|
case UNDEFINED:
|
||||||
|
return true;
|
||||||
|
case WIRE_REFERENCE:
|
||||||
|
case ATTRIBUTE_REFERENCE:
|
||||||
|
case ADDRESS_SPACE_REFERENCE:
|
||||||
|
return value.asReference() == reference;
|
||||||
|
case MEMORY_REFERENCE:
|
||||||
|
return value.asMemoryReference() == memoryReference;
|
||||||
|
case MEMORY:
|
||||||
|
return value.asMemory() == memory;
|
||||||
|
case BOOL:
|
||||||
|
return value.asBool() == boolValue;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string string();
|
std::string string();
|
||||||
@@ -48,6 +80,8 @@ public:
|
|||||||
std::string asString();
|
std::string asString();
|
||||||
bool asBool();
|
bool asBool();
|
||||||
std::string asReference();
|
std::string asReference();
|
||||||
|
std::optional<std::string> asMemoryReference();
|
||||||
|
domain::ComponentInstance* asMemory();
|
||||||
AddressSpace asAddressSpace();
|
AddressSpace asAddressSpace();
|
||||||
|
|
||||||
void setInt(long long intValue);
|
void setInt(long long intValue);
|
||||||
@@ -64,6 +98,8 @@ public:
|
|||||||
static Value fromAddressSpace(AddressSpace addressSpace);
|
static Value fromAddressSpace(AddressSpace addressSpace);
|
||||||
static Value fromReference(std::string value, ValueType type);
|
static Value fromReference(std::string value, ValueType type);
|
||||||
static Value ofType(ValueType type);
|
static Value ofType(ValueType type);
|
||||||
|
static Value fromMemoryReference(std::optional<std::string> memoryReference);
|
||||||
|
static Value fromMemory(domain::ComponentInstance *memory);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|||||||
@@ -94,9 +94,16 @@ ValueNode ValueNode::ofNull() {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueNode ValueNode::ofWire(std::string _value) {
|
ValueNode ValueNode::ofWire(std::optional<std::string> _value) {
|
||||||
ValueNode value;
|
ValueNode value;
|
||||||
value.type = EnumNode(WIRE);
|
value.type = EnumNode(WIRE);
|
||||||
value.identifierValue = std::optional<std::string>(_value);
|
value.identifierValue = _value;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueNode ValueNode::ofMemory(std::optional<std::string> _value) {
|
||||||
|
ValueNode value;
|
||||||
|
value.type = EnumNode(MEMORY);
|
||||||
|
value.identifierValue = _value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
+57
-15
@@ -2,6 +2,7 @@
|
|||||||
#define AST_NODE_H
|
#define AST_NODE_H
|
||||||
|
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
#include "sourceerror.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -77,6 +78,7 @@ public:
|
|||||||
BOOL,
|
BOOL,
|
||||||
WIRE,
|
WIRE,
|
||||||
IDENTIFIER,
|
IDENTIFIER,
|
||||||
|
MEMORY,
|
||||||
NIL,
|
NIL,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,7 +90,7 @@ private:
|
|||||||
std::optional<std::string> identifierValue;
|
std::optional<std::string> identifierValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ValueNode() = default;;
|
ValueNode() = default;
|
||||||
|
|
||||||
ValueType getType() {
|
ValueType getType() {
|
||||||
return type.value;
|
return type.value;
|
||||||
@@ -104,8 +106,9 @@ public:
|
|||||||
static ValueNode ofInt(long long _value);
|
static ValueNode ofInt(long long _value);
|
||||||
static ValueNode ofString(std::string _value);
|
static ValueNode ofString(std::string _value);
|
||||||
static ValueNode ofIdentifier(std::string _value);
|
static ValueNode ofIdentifier(std::string _value);
|
||||||
|
static ValueNode ofMemory(std::optional<std::string> _value);
|
||||||
static ValueNode ofNull();
|
static ValueNode ofNull();
|
||||||
static ValueNode ofWire(std::string _value);
|
static ValueNode ofWire(std::optional<std::string> _value);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConditionNode
|
struct ConditionNode
|
||||||
@@ -171,6 +174,52 @@ struct DisplayItemNode: public AstNode
|
|||||||
{
|
{
|
||||||
IdentifierNode type;
|
IdentifierNode type;
|
||||||
std::vector<PropertyNode> values;
|
std::vector<PropertyNode> values;
|
||||||
|
|
||||||
|
long long int asInt(std::vector<SourceError>* errors, const std::string& property, long long int _default = 0) {
|
||||||
|
for(auto& prop: values) {
|
||||||
|
if(prop.key.value == property) {
|
||||||
|
if(prop.value.is(ValueNode::INT)) {
|
||||||
|
return prop.value.asInt();
|
||||||
|
} else {
|
||||||
|
if(errors != nullptr) {
|
||||||
|
errors->emplace_back(prop.value.span, "expected number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _default;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string asIdentifier(std::vector<SourceError>* errors, const std::string& property, std::string _default = "") {
|
||||||
|
for(auto& prop: values) {
|
||||||
|
if(prop.key.value == property) {
|
||||||
|
if(prop.value.is(ValueNode::IDENTIFIER)) {
|
||||||
|
return prop.value.asIdentifier();
|
||||||
|
} else {
|
||||||
|
if(errors != nullptr) {
|
||||||
|
errors->emplace_back(prop.value.span, "expected identifier");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _default;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string asString(std::vector<SourceError>* errors, const std::string& property, std::string _default = "") {
|
||||||
|
for(auto& prop: values) {
|
||||||
|
if(prop.key.value == property) {
|
||||||
|
if(prop.value.is(ValueNode::STRING)) {
|
||||||
|
return prop.value.asString();
|
||||||
|
} else {
|
||||||
|
if(errors != nullptr) {
|
||||||
|
errors->emplace_back(prop.value.span, "expected string");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _default;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DisplayNode: public AstNode
|
struct DisplayNode: public AstNode
|
||||||
@@ -181,8 +230,8 @@ struct DisplayNode: public AstNode
|
|||||||
struct PinConnectionNode: public AstNode
|
struct PinConnectionNode: public AstNode
|
||||||
{
|
{
|
||||||
enum ConnectionType {
|
enum ConnectionType {
|
||||||
CHECK_ONLY,
|
REQUIRED,
|
||||||
AUTOMATICALLY
|
OPTIONAL
|
||||||
};
|
};
|
||||||
|
|
||||||
StringNode message;
|
StringNode message;
|
||||||
@@ -217,7 +266,7 @@ struct WireNode: public AstNode
|
|||||||
IdentifierNode name;
|
IdentifierNode name;
|
||||||
NumberNode size;
|
NumberNode size;
|
||||||
|
|
||||||
bool hidden;
|
bool hidden = false;
|
||||||
|
|
||||||
bool hasTerminateWith;
|
bool hasTerminateWith;
|
||||||
ValueNode terminateWith;
|
ValueNode terminateWith;
|
||||||
@@ -273,7 +322,8 @@ struct BusNode: public AstNode
|
|||||||
{
|
{
|
||||||
enum BusType {
|
enum BusType {
|
||||||
AUTOMATIC,
|
AUTOMATIC,
|
||||||
REGULAR
|
REGULAR,
|
||||||
|
SINGLE_AUTOMATIC
|
||||||
};
|
};
|
||||||
|
|
||||||
EnumNode<BusType> type;
|
EnumNode<BusType> type;
|
||||||
@@ -291,6 +341,7 @@ struct LibraryNode: public AstNode
|
|||||||
std::optional<StringNode> libraryInfo;
|
std::optional<StringNode> libraryInfo;
|
||||||
std::optional<StringNode> header;
|
std::optional<StringNode> header;
|
||||||
std::optional<StringNode> componentDirectory;
|
std::optional<StringNode> componentDirectory;
|
||||||
|
std::optional<StringNode> componentHeader;
|
||||||
|
|
||||||
std::vector<AddressSpaceNode> addressSpaces;
|
std::vector<AddressSpaceNode> addressSpaces;
|
||||||
|
|
||||||
@@ -302,13 +353,6 @@ struct LibraryNode: public AstNode
|
|||||||
};
|
};
|
||||||
|
|
||||||
// SCHEMA models
|
// SCHEMA models
|
||||||
struct WireInstanceNode: public AstNode
|
|
||||||
{
|
|
||||||
IdentifierNode name;
|
|
||||||
std::optional<CountNode> position;
|
|
||||||
std::optional<DisplayNode> display;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct InstanceAttributeNode: public AstNode
|
struct InstanceAttributeNode: public AstNode
|
||||||
{
|
{
|
||||||
IdentifierNode name;
|
IdentifierNode name;
|
||||||
@@ -338,7 +382,6 @@ struct ConnectionInstanceNode: public AstNode
|
|||||||
std::optional<ConnectionComponentInstance> second;
|
std::optional<ConnectionComponentInstance> second;
|
||||||
|
|
||||||
IdentifierNode bus;
|
IdentifierNode bus;
|
||||||
std::optional<IdentifierNode> wire;
|
|
||||||
|
|
||||||
std::vector<InstanceAttributeNode> attributes;
|
std::vector<InstanceAttributeNode> attributes;
|
||||||
};
|
};
|
||||||
@@ -349,7 +392,6 @@ struct SchemaNode: public AstNode
|
|||||||
std::optional<StringNode> source;
|
std::optional<StringNode> source;
|
||||||
|
|
||||||
std::vector<InstanceNode> instances;
|
std::vector<InstanceNode> instances;
|
||||||
std::vector<WireInstanceNode> wires;
|
|
||||||
std::vector<ConnectionInstanceNode> connections;
|
std::vector<ConnectionInstanceNode> connections;
|
||||||
|
|
||||||
std::optional<LibraryNode> library;
|
std::optional<LibraryNode> library;
|
||||||
|
|||||||
@@ -243,6 +243,9 @@ std::optional<LibraryNode> ComdelParser::parse()
|
|||||||
} else if(check(TokenType::KW_HEADER)) {
|
} else if(check(TokenType::KW_HEADER)) {
|
||||||
bump();
|
bump();
|
||||||
ASSIGN_OR_SET_ERR(library.header, parseString());
|
ASSIGN_OR_SET_ERR(library.header, parseString());
|
||||||
|
} else if(check(TokenType::KW_COMPONENT_HEADER)) {
|
||||||
|
bump();
|
||||||
|
ASSIGN_OR_SET_ERR(library.componentHeader, parseString());
|
||||||
} else if(check(TokenType::KW_DIRECTORY)) {
|
} else if(check(TokenType::KW_DIRECTORY)) {
|
||||||
bump();
|
bump();
|
||||||
ASSIGN_OR_SET_ERR(library.componentDirectory, parseString());
|
ASSIGN_OR_SET_ERR(library.componentDirectory, parseString());
|
||||||
@@ -438,7 +441,7 @@ PResult<ComponentNode> ComdelParser::parseComponent()
|
|||||||
|
|
||||||
ASSIGN_OR_RETURN_IF_ERR(component.name, parseIdentifier());
|
ASSIGN_OR_RETURN_IF_ERR(component.name, parseIdentifier());
|
||||||
|
|
||||||
auto type = parseComponentType();
|
ASSIGN_OR_RETURN_IF_ERR(component.type, parseComponentType());
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
||||||
|
|
||||||
@@ -465,6 +468,7 @@ PResult<ComponentNode> ComdelParser::parseComponent()
|
|||||||
APPEND_OR_SET_ERR(component.rules, parseRule());
|
APPEND_OR_SET_ERR(component.rules, parseRule());
|
||||||
} else {
|
} else {
|
||||||
err = unexpected();
|
err = unexpected();
|
||||||
|
bump();
|
||||||
}
|
}
|
||||||
if(!err.has_value()) {
|
if(!err.has_value()) {
|
||||||
errors.push_back(err.error());
|
errors.push_back(err.error());
|
||||||
@@ -583,6 +587,7 @@ PResult<BusNode> ComdelParser::parseBus() {
|
|||||||
RETURN_IF_NOT_TOKEN(TokenType::RBRACE);
|
RETURN_IF_NOT_TOKEN(TokenType::RBRACE);
|
||||||
} else {
|
} else {
|
||||||
err = unexpected();
|
err = unexpected();
|
||||||
|
bump();
|
||||||
}
|
}
|
||||||
if(!err.has_value()) {
|
if(!err.has_value()) {
|
||||||
errors.push_back(err.error());
|
errors.push_back(err.error());
|
||||||
@@ -607,11 +612,13 @@ PResult<EnumNode<BusNode::BusType>> ComdelParser::parseBusType() {
|
|||||||
type = EnumNode(BusNode::AUTOMATIC);
|
type = EnumNode(BusNode::AUTOMATIC);
|
||||||
} else if(tokenType.value().value == "regular") {
|
} else if(tokenType.value().value == "regular") {
|
||||||
type = EnumNode(BusNode::REGULAR);
|
type = EnumNode(BusNode::REGULAR);
|
||||||
|
} else if(tokenType.value().value == "singleAutomatic") {
|
||||||
|
type = EnumNode(BusNode::SINGLE_AUTOMATIC);
|
||||||
} else {
|
} else {
|
||||||
type = PError(SourceError{current().span, "expected 'automatic' or 'regular'"});
|
type = PError(SourceError{current().span, "expected 'automatic', 'singleAutomatic' or 'regular'"});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
type = PError(SourceError{current().span, "expected 'automatic' or 'regular'"});
|
type = PError(SourceError{current().span, "expected 'automatic', 'singleAutomatic' or 'regular'"});
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -728,6 +735,7 @@ PResult<PinNode> ComdelParser::parsePin() {
|
|||||||
pin.wires = *wires;
|
pin.wires = *wires;
|
||||||
} else {
|
} else {
|
||||||
err = unexpected();
|
err = unexpected();
|
||||||
|
bump();
|
||||||
}
|
}
|
||||||
if(!err.has_value()) {
|
if(!err.has_value()) {
|
||||||
errors.push_back(err.error());
|
errors.push_back(err.error());
|
||||||
@@ -771,15 +779,15 @@ PResult<EnumNode<PinConnectionNode::ConnectionType>> ComdelParser::parseConnecti
|
|||||||
|
|
||||||
if(check(TokenType::IDENTIFIER)) {
|
if(check(TokenType::IDENTIFIER)) {
|
||||||
auto identifier = parseIdentifier();
|
auto identifier = parseIdentifier();
|
||||||
if(identifier.value().value == "check_only") {
|
if(identifier.value().value == "required") {
|
||||||
type = EnumNode(PinConnectionNode::CHECK_ONLY);
|
type = EnumNode(PinConnectionNode::REQUIRED);
|
||||||
} else if(identifier.value().value == "automatically") {
|
} else if(identifier.value().value == "optional") {
|
||||||
type = EnumNode(PinConnectionNode::AUTOMATICALLY);
|
type = EnumNode(PinConnectionNode::OPTIONAL);
|
||||||
} else {
|
} else {
|
||||||
return PError(SourceError{current().span, "expected identifiers 'check_only' or 'automatically'"});
|
return PError(SourceError{current().span, "expected connection type 'required' or 'optional'"});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return PError(SourceError{current().span, "expected identifiers 'check_only' or 'automatically'"});
|
return PError(SourceError{current().span, "expected connection type 'required' or 'optional'"});
|
||||||
}
|
}
|
||||||
|
|
||||||
return spanner(type);
|
return spanner(type);
|
||||||
@@ -848,13 +856,23 @@ PResult<AttributeNode> ComdelParser::parseAttribute() {
|
|||||||
} else {
|
} else {
|
||||||
return unexpected();
|
return unexpected();
|
||||||
}
|
}
|
||||||
|
} else if(attribute.type == ValueNode::MEMORY) {
|
||||||
|
if(check(TokenType::IDENTIFIER)) {
|
||||||
|
auto identifier = parseIdentifier();
|
||||||
|
attribute.defaultValue = ValueNode::ofMemory(identifier->value);
|
||||||
|
} else if(check(TokenType::NIL)) {
|
||||||
|
bump();
|
||||||
|
attribute.defaultValue = ValueNode::ofMemory(std::nullopt);
|
||||||
|
} else {
|
||||||
|
return unexpected();
|
||||||
|
}
|
||||||
} else if(attribute.type == ValueNode::WIRE) {
|
} else if(attribute.type == ValueNode::WIRE) {
|
||||||
if(check(TokenType::IDENTIFIER)) {
|
if(check(TokenType::IDENTIFIER)) {
|
||||||
auto identifier = parseIdentifier();
|
auto identifier = parseIdentifier();
|
||||||
attribute.defaultValue = ValueNode::ofWire(identifier->value);
|
attribute.defaultValue = ValueNode::ofWire(identifier->value);
|
||||||
} else if(check(TokenType::NIL)) {
|
} else if(check(TokenType::NIL)) {
|
||||||
bump();
|
bump();
|
||||||
attribute.defaultValue = ValueNode::ofNull();
|
attribute.defaultValue = ValueNode::ofWire(std::nullopt);
|
||||||
} else {
|
} else {
|
||||||
return unexpected();
|
return unexpected();
|
||||||
}
|
}
|
||||||
@@ -948,6 +966,7 @@ PResult<PopupNode> ComdelParser::parsePopup() {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err = unexpected();
|
err = unexpected();
|
||||||
|
bump();
|
||||||
}
|
}
|
||||||
if(!err.has_value()) {
|
if(!err.has_value()) {
|
||||||
errors.push_back(err.error());
|
errors.push_back(err.error());
|
||||||
@@ -965,7 +984,7 @@ PResult<PopupNode> ComdelParser::parsePopup() {
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* ConnectionNode := "@connection (" + COMPONENT + "." + PIN + "," + BUS) {" + CONNECTION + "}"
|
* ConnectionNode := "@connection (" + COMPONENT + "." + PIN + "," + BUS [ + "," + COMPONENT2 + "." + "PIN2"] + ") {" + CONNECTION + "}"
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<ConnectionNode> ComdelParser::parseConnection() {
|
PResult<ConnectionNode> ComdelParser::parseConnection() {
|
||||||
@@ -984,7 +1003,6 @@ PResult<ConnectionNode> ComdelParser::parseConnection() {
|
|||||||
if(check(TokenType::COMMA)) {
|
if(check(TokenType::COMMA)) {
|
||||||
auto conn = ConnectionComponentNode{};
|
auto conn = ConnectionComponentNode{};
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::COMMA);
|
RETURN_IF_NOT_TOKEN(TokenType::COMMA);
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::LPAREN);
|
|
||||||
ASSIGN_OR_RETURN_IF_ERR(conn.component, parseIdentifier());
|
ASSIGN_OR_RETURN_IF_ERR(conn.component, parseIdentifier());
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::DOT);
|
RETURN_IF_NOT_TOKEN(TokenType::DOT);
|
||||||
ASSIGN_OR_RETURN_IF_ERR(conn.pin, parseIdentifier());
|
ASSIGN_OR_RETURN_IF_ERR(conn.pin, parseIdentifier());
|
||||||
@@ -1016,6 +1034,7 @@ PResult<ConnectionNode> ComdelParser::parseConnection() {
|
|||||||
wireCount++;
|
wireCount++;
|
||||||
} else {
|
} else {
|
||||||
err = unexpected();
|
err = unexpected();
|
||||||
|
bump();
|
||||||
}
|
}
|
||||||
if(!err.has_value()) {
|
if(!err.has_value()) {
|
||||||
errors.push_back(err.error());
|
errors.push_back(err.error());
|
||||||
@@ -1170,8 +1189,6 @@ std::optional<SchemaNode> ComdelParser::parseSchema() {
|
|||||||
PResult<poly<AstNode>> err;
|
PResult<poly<AstNode>> err;
|
||||||
if(check(TokenType::KW_INSTANCE)){
|
if(check(TokenType::KW_INSTANCE)){
|
||||||
APPEND_OR_SET_ERR(schema.instances, parseInstance());
|
APPEND_OR_SET_ERR(schema.instances, parseInstance());
|
||||||
} else if(check(TokenType::KW_WIRE)) {
|
|
||||||
APPEND_OR_SET_ERR(schema.wires, parseWireInstance());
|
|
||||||
} else if(check(TokenType::KW_CONNECTION)) {
|
} else if(check(TokenType::KW_CONNECTION)) {
|
||||||
APPEND_OR_SET_ERR(schema.connections, parseConnectionInstance());
|
APPEND_OR_SET_ERR(schema.connections, parseConnectionInstance());
|
||||||
} else {
|
} else {
|
||||||
@@ -1181,6 +1198,10 @@ std::optional<SchemaNode> ComdelParser::parseSchema() {
|
|||||||
if(!err.has_value()) {
|
if(!err.has_value()) {
|
||||||
errors.push_back(err.error());
|
errors.push_back(err.error());
|
||||||
skipUntilNextKeyword();
|
skipUntilNextKeyword();
|
||||||
|
if(check(TokenType::END_OF_FILE)) {
|
||||||
|
errors.emplace_back(current().span, "expected `}` reached EOF");
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!check(TokenType::RBRACE)) {
|
if(!check(TokenType::RBRACE)) {
|
||||||
@@ -1199,38 +1220,6 @@ std::optional<SchemaNode> ComdelParser::parseSchema() {
|
|||||||
|
|
||||||
return spanner(schema);
|
return spanner(schema);
|
||||||
}
|
}
|
||||||
PResult<WireInstanceNode> ComdelParser::parseWireInstance() {
|
|
||||||
auto spanner = getSpanner();
|
|
||||||
WireInstanceNode wireInstance;
|
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::KW_WIRE);
|
|
||||||
ASSIGN_OR_RETURN_IF_ERR(wireInstance.name, parseIdentifier());
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
|
||||||
|
|
||||||
while(!check(TokenType::RBRACE)) {
|
|
||||||
PResult<poly<AstNode>> err;
|
|
||||||
if(check(TokenType::KW_POSITION)) {
|
|
||||||
ASSIGN_OR_SET_ERR(wireInstance.position, parsePosition());
|
|
||||||
} else if(check(TokenType::KW_DISPLAY)) {
|
|
||||||
ASSIGN_OR_SET_ERR(wireInstance.display, parseDisplay());
|
|
||||||
} else {
|
|
||||||
err = unexpected();
|
|
||||||
}
|
|
||||||
if(!err.has_value()) {
|
|
||||||
errors.push_back(err.error());
|
|
||||||
skipUntilNextKeyword();
|
|
||||||
if(check(TokenType::END_OF_FILE)) {
|
|
||||||
return PError({Span(spanner.lo), "Reached EOF"});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::RBRACE);
|
|
||||||
|
|
||||||
return spanner(wireInstance);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
@@ -1281,6 +1270,7 @@ PResult<InstanceNode> ComdelParser::parseInstance() {
|
|||||||
instance.size = *number;
|
instance.size = *number;
|
||||||
} else {
|
} else {
|
||||||
err = unexpected();
|
err = unexpected();
|
||||||
|
bump();
|
||||||
}
|
}
|
||||||
if(!err.has_value()) {
|
if(!err.has_value()) {
|
||||||
errors.push_back(err.error());
|
errors.push_back(err.error());
|
||||||
@@ -1333,13 +1323,11 @@ PResult<ConnectionInstanceNode> ComdelParser::parseConnectionInstance() {
|
|||||||
|
|
||||||
while(!check(TokenType::RBRACE)) {
|
while(!check(TokenType::RBRACE)) {
|
||||||
PResult<poly<AstNode>> err;
|
PResult<poly<AstNode>> err;
|
||||||
if(check(TokenType::KW_WIRE)) {
|
if(check(TokenType::KW_ATTRIBUTE)) {
|
||||||
bump();
|
|
||||||
ASSIGN_OR_SET_ERR(connection.wire, parseIdentifier());
|
|
||||||
} else if(check(TokenType::KW_ATTRIBUTE)) {
|
|
||||||
APPEND_OR_SET_ERR(connection.attributes, parseInstanceAttribute());
|
APPEND_OR_SET_ERR(connection.attributes, parseInstanceAttribute());
|
||||||
} else {
|
} else {
|
||||||
err = unexpected();
|
err = unexpected();
|
||||||
|
bump();
|
||||||
}
|
}
|
||||||
if(!err.has_value()) {
|
if(!err.has_value()) {
|
||||||
errors.push_back(err.error());
|
errors.push_back(err.error());
|
||||||
@@ -1356,13 +1344,16 @@ PResult<ConnectionInstanceNode> ComdelParser::parseConnectionInstance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PResult<ValueNode> ComdelParser::parseConnectionWire() {
|
PResult<ValueNode> ComdelParser::parseConnectionWire() {
|
||||||
|
auto spanner = getSpanner();
|
||||||
if(check(TokenType::NUMBER)) {
|
if(check(TokenType::NUMBER)) {
|
||||||
return ValueNode::ofInt(parseNumber()->value);
|
return spanner(ValueNode::ofInt(parseNumber()->value));
|
||||||
} else if(check(TokenType::NIL)) {
|
} else if(check(TokenType::NIL)) {
|
||||||
bump();
|
bump();
|
||||||
return ValueNode::ofNull();
|
return spanner(ValueNode::ofNull());
|
||||||
|
} else if(check(TokenType::STRING)) {
|
||||||
|
return spanner(ValueNode::ofString(parseString()->value));
|
||||||
} else if(check(TokenType::IDENTIFIER)) {
|
} else if(check(TokenType::IDENTIFIER)) {
|
||||||
return ValueNode::ofIdentifier(parseIdentifier()->value);
|
return spanner(ValueNode::ofIdentifier(parseIdentifier()->value));
|
||||||
} else {
|
} else {
|
||||||
return unexpected();
|
return unexpected();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ private:
|
|||||||
PResult<ValueNode> parseValue();
|
PResult<ValueNode> parseValue();
|
||||||
|
|
||||||
|
|
||||||
PResult<WireInstanceNode> parseWireInstance();
|
|
||||||
PResult<CountNode> parsePosition();
|
PResult<CountNode> parsePosition();
|
||||||
PResult<InstanceNode> parseInstance();
|
PResult<InstanceNode> parseInstance();
|
||||||
PResult<InstanceAttributeNode> parseInstanceAttribute();
|
PResult<InstanceAttributeNode> parseInstanceAttribute();
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ enum class TokenType {
|
|||||||
KW_NAME,
|
KW_NAME,
|
||||||
KW_INFO,
|
KW_INFO,
|
||||||
KW_HEADER,
|
KW_HEADER,
|
||||||
|
KW_COMPONENT_HEADER,
|
||||||
KW_DIRECTORY,
|
KW_DIRECTORY,
|
||||||
KW_LIBRARY,
|
KW_LIBRARY,
|
||||||
KW_ADDRESS,
|
KW_ADDRESS,
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ TokenTables::TokenTables() {
|
|||||||
add( TokenType::KW_NAME, "@name", TOKENIZABLE | KEYWORD_NAME),
|
add( TokenType::KW_NAME, "@name", TOKENIZABLE | KEYWORD_NAME),
|
||||||
add( TokenType::KW_INFO, "@info", TOKENIZABLE | KEYWORD_NAME),
|
add( TokenType::KW_INFO, "@info", TOKENIZABLE | KEYWORD_NAME),
|
||||||
add( TokenType::KW_HEADER, "@header", TOKENIZABLE | KEYWORD_NAME),
|
add( TokenType::KW_HEADER, "@header", TOKENIZABLE | KEYWORD_NAME),
|
||||||
|
add( TokenType::KW_COMPONENT_HEADER, "@componentHeader", TOKENIZABLE | KEYWORD_NAME),
|
||||||
add( TokenType::KW_DIRECTORY, "@directory", TOKENIZABLE | KEYWORD_NAME),
|
add( TokenType::KW_DIRECTORY, "@directory", TOKENIZABLE | KEYWORD_NAME),
|
||||||
add( TokenType::KW_LIBRARY, "@library", TOKENIZABLE | KEYWORD_NAME),
|
add( TokenType::KW_LIBRARY, "@library", TOKENIZABLE | KEYWORD_NAME),
|
||||||
add( TokenType::KW_ADDRESS, "@address", TOKENIZABLE | KEYWORD_NAME),
|
add( TokenType::KW_ADDRESS, "@address", TOKENIZABLE | KEYWORD_NAME),
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// Version 0.0.1
|
||||||
|
#include "libraries\frisc\vjezba1\FRISC.cdl"
|
||||||
|
#include "libraries\frisc\vjezba1\memory.cdl"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
component System
|
||||||
|
{
|
||||||
|
clock 100MHz;
|
||||||
|
//directRam
|
||||||
|
wire INT;
|
||||||
|
|
||||||
|
|
||||||
|
//glavnaSabirnica
|
||||||
|
wire<32> ADR;
|
||||||
|
wire<32> DATA;
|
||||||
|
wire READ;
|
||||||
|
wire WRITE;
|
||||||
|
wired_and WAIT;
|
||||||
|
wired_and INT0;
|
||||||
|
wired_and INT1;
|
||||||
|
wired_and INT2;
|
||||||
|
wired_and INT3;
|
||||||
|
wire<3> SIZE;
|
||||||
|
wire --IACK;
|
||||||
|
wire --BREQ;
|
||||||
|
wire --BACK;
|
||||||
|
|
||||||
|
|
||||||
|
// components --------------------------------------------
|
||||||
|
subcomponent Memorija memorija<false, 1, 65536, 8, 0>(ADR, DATA, READ, WRITE, SIZE, WAIT, INT);
|
||||||
|
subcomponent FRISC procesor(ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, --IACK, 1, *, INT) uses memorija;
|
||||||
|
|
||||||
|
display {
|
||||||
|
component { x: -12; y: 68; ref: "memorija"; }
|
||||||
|
component { x: -206; y: -76; ref: "procesor"; }
|
||||||
|
|
||||||
|
// directRam bus
|
||||||
|
|
||||||
|
|
||||||
|
// glavnaSabirnica bus
|
||||||
|
|
||||||
|
rectangle {
|
||||||
|
x: -222; y: 130;
|
||||||
|
w: 100; h: 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
line {x1:-28; y1:96; x2:-90; y2:-26;}
|
||||||
|
line {x1:38; y1:52; x2:-171; y2:140;}
|
||||||
|
line {x1:-156; y1:40; x2:-171; y2:140;}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
@name "Jednostavni FRISC"
|
@name "Jednostavni FRISC"
|
||||||
@info "Ova biblioteka omogućuje kreiranje sustava s procesorom FRISC s pojednostavljenim načinom spajanja bez potrebe da se spajaju pojedine linije sabirnice."
|
@info "Ova biblioteka omogućuje kreiranje sustava s procesorom FRISC s pojednostavljenim načinom spajanja bez potrebe da se spajaju pojedine linije sabirnice."
|
||||||
@directory "libraries\frisc\vjezba1"
|
@directory "libraries\frisc\vjezba1"
|
||||||
|
@header "// Version 0.0.1"
|
||||||
|
@componentHeader " clock 100MHz;"
|
||||||
|
|
||||||
@address glavniAS(0,0xFFFFFFFF)
|
@address glavniAS(0,0xFFFFFFFF)
|
||||||
@address pomocniAS(0xFFFF0000,0xFFFFFFFF)
|
@address pomocniAS(0xFFFF0000,0xFFFFFFFF)
|
||||||
@@ -17,7 +19,7 @@
|
|||||||
|
|
||||||
@component FRISC processor {
|
@component FRISC processor {
|
||||||
@instanceName "procesor"
|
@instanceName "procesor"
|
||||||
@tooltip "procesor FRISC, mora postojati jedan"
|
@tooltip "Procesor FRISC, mora postojati jedan"
|
||||||
@count (1, 1)
|
@count (1, 1)
|
||||||
@source "FRISC.cdl"
|
@source "FRISC.cdl"
|
||||||
@display {
|
@display {
|
||||||
@@ -49,22 +51,26 @@
|
|||||||
x: 0; y:0; w:100; h:100;
|
x: 0; y:0; w:100; h:100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@pin glavniPin inOut {
|
@pin glavniPin in {
|
||||||
@tooltip "pin za spajanje na glavnu sabirnicu"
|
@tooltip "pin za spajanje na glavnu sabirnicu"
|
||||||
@connection check_only("COMDEL se ne može stvoriti. FRISC nije spojen na sabirnicu")
|
@connection required("COMDEL se ne može stvoriti. FRISC nije spojen na sabirnicu")
|
||||||
@display {
|
@display {
|
||||||
/*
|
|
||||||
pin {
|
|
||||||
x: 100; y: 50;
|
|
||||||
fillColor: white;
|
|
||||||
lineColor: red;
|
|
||||||
fillColorConnected: white;
|
|
||||||
lineColorConnected: black;
|
|
||||||
side: left;
|
|
||||||
size: 20;
|
|
||||||
}*/
|
|
||||||
pin {
|
pin {
|
||||||
x: 42; y: 100; w: 16; h:16;
|
x: 42; y: 100; w: 16; h:16;
|
||||||
|
type: "in";
|
||||||
|
orientation: "bottom";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@pin memDirect inOut {
|
||||||
|
@tooltip "pin za izravno spajanje na RAM"
|
||||||
|
@connection optional("COMDEL se ne može stvoriti. FRISC nije spojen na sabirnicu")
|
||||||
|
@display {
|
||||||
|
pin {
|
||||||
|
x: 100; y: 42; w: 16; h:16;
|
||||||
|
type: "in";
|
||||||
|
orientation: "right";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +81,27 @@
|
|||||||
@tooltip "Memorijska komponenta, mora postojati barem jedna"
|
@tooltip "Memorijska komponenta, mora postojati barem jedna"
|
||||||
@count (1,1000)
|
@count (1,1000)
|
||||||
@source "memory.cdl"
|
@source "memory.cdl"
|
||||||
|
|
||||||
|
@attribute sinkroniziran bool default false {
|
||||||
|
@popup automatic {
|
||||||
|
@title "Postavite sinkroniziranost"
|
||||||
|
@text "Zadajte sinkronizaciju"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@attribute brzina int default 1 {
|
||||||
|
@popup automatic {
|
||||||
|
@title "Postavite brzinu memorije"
|
||||||
|
@text "Zadajte brzinu memorije"
|
||||||
|
@enumerated {
|
||||||
|
"Spora" = 1,
|
||||||
|
"Srednja" = 5,
|
||||||
|
"Brza" = 25,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@attribute kapacitet int default 65536 {
|
@attribute kapacitet int default 65536 {
|
||||||
@popup automatic {
|
@popup automatic {
|
||||||
@title "Kapacitet memorije"
|
@title "Kapacitet memorije"
|
||||||
@@ -146,7 +173,7 @@
|
|||||||
|
|
||||||
@pin glavniPin inOut {
|
@pin glavniPin inOut {
|
||||||
@tooltip "pin za spajanje na glavnu sabirnicu"
|
@tooltip "pin za spajanje na glavnu sabirnicu"
|
||||||
@connection check_only("COMDEL se ne može stvoriti. Memorija nije spojena na sabirnicu")
|
@connection required("COMDEL se ne može stvoriti. Memorija nije spojena na sabirnicu")
|
||||||
@display {
|
@display {
|
||||||
/*
|
/*
|
||||||
pin {
|
pin {
|
||||||
@@ -161,6 +188,31 @@
|
|||||||
*/
|
*/
|
||||||
pin {
|
pin {
|
||||||
x: 42; y: -16; w: 16; h:16;
|
x: 42; y: -16; w: 16; h:16;
|
||||||
|
type: "out";
|
||||||
|
orientation: "top";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@pin memDirect inOut {
|
||||||
|
@tooltip "pin za spajanje na procesor"
|
||||||
|
@connection optional("COMDEL se ne može stvoriti. Memorija nije spojena na sabirnicu")
|
||||||
|
@display {
|
||||||
|
/*
|
||||||
|
pin {
|
||||||
|
x: 100; y: 25;
|
||||||
|
fillColor: blue;
|
||||||
|
lineColor: red;
|
||||||
|
fillColorConnected: white;
|
||||||
|
lineColorConnected: black;
|
||||||
|
side: right;
|
||||||
|
size: 20;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
pin {
|
||||||
|
x: -16; y: 20; w: 16; h:16;
|
||||||
|
type: "out";
|
||||||
|
orientation: "left";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,8 +221,9 @@
|
|||||||
@component DMA {
|
@component DMA {
|
||||||
@instanceName "dma"
|
@instanceName "dma"
|
||||||
@tooltip "DMA-kontroler"
|
@tooltip "DMA-kontroler"
|
||||||
@count (1,1000)
|
@count (0,1000)
|
||||||
@source "dma.cdl"
|
@source "dma.cdl"
|
||||||
|
|
||||||
@attribute pocetnaAdresa int default 0 {
|
@attribute pocetnaAdresa int default 0 {
|
||||||
@popup automatic {
|
@popup automatic {
|
||||||
@title "Početna adresa DMA-kontrolera"
|
@title "Početna adresa DMA-kontrolera"
|
||||||
@@ -214,7 +267,7 @@
|
|||||||
|
|
||||||
@pin glavniPin in {
|
@pin glavniPin in {
|
||||||
@tooltip "pin za spajanje na glavnu sabirnicu"
|
@tooltip "pin za spajanje na glavnu sabirnicu"
|
||||||
@connection check_only("COMDEL se ne može stvoriti. DMA nije spojena na sabirnicu")
|
@connection required("COMDEL se ne može stvoriti. DMA nije spojena na sabirnicu")
|
||||||
@display {
|
@display {
|
||||||
/*
|
/*
|
||||||
pin {
|
pin {
|
||||||
@@ -235,7 +288,7 @@
|
|||||||
|
|
||||||
@pin dodatnaPoveznica in {
|
@pin dodatnaPoveznica in {
|
||||||
@tooltip "pin za spajanje na pomocnu sabirnicu"
|
@tooltip "pin za spajanje na pomocnu sabirnicu"
|
||||||
@connection check_only("COMDEL se ne može stvoriti. DMA nije spojen na nesto!")
|
@connection optional("COMDEL se ne može stvoriti. DMA nije spojen na nesto!")
|
||||||
@display {
|
@display {
|
||||||
pin {
|
pin {
|
||||||
x: 0; y: 0; w: 0; h: 0;
|
x: 0; y: 0; w: 0; h: 0;
|
||||||
@@ -257,9 +310,11 @@
|
|||||||
orientation: horizontal;
|
orientation: horizontal;
|
||||||
lineColor: black;
|
lineColor: black;
|
||||||
}*/
|
}*/
|
||||||
rect {
|
bus {
|
||||||
x:0; y:0;
|
x:0; y:0;
|
||||||
h: 20; w: 100;
|
h: 20; w: 100;
|
||||||
|
orientation: "horizontal";
|
||||||
|
resizable: true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@wires {
|
@wires {
|
||||||
@@ -273,12 +328,13 @@
|
|||||||
INT2 wired_and,
|
INT2 wired_and,
|
||||||
INT3 wired_and,
|
INT3 wired_and,
|
||||||
SIZE<3>,
|
SIZE<3>,
|
||||||
IACK,
|
IACK hidden,
|
||||||
BREQ,
|
BREQ hidden,
|
||||||
BACK
|
BACK hidden
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@bus PIOSabirnica automatic {
|
@bus PIOSabirnica automatic {
|
||||||
|
@count (0, 20)
|
||||||
@wires {
|
@wires {
|
||||||
PIO_DATA<8>,
|
PIO_DATA<8>,
|
||||||
READY,
|
READY,
|
||||||
@@ -286,6 +342,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bus directRam automatic {
|
||||||
|
@wires {
|
||||||
|
INT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@connection (FRISC.glavniPin, glavnaSabirnica) {
|
@connection (FRISC.glavniPin, glavnaSabirnica) {
|
||||||
@wires{ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, IACK, 1, null}
|
@wires{ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, IACK, 1, null}
|
||||||
}
|
}
|
||||||
@@ -308,3 +371,13 @@
|
|||||||
}
|
}
|
||||||
@wires{ADR, DATA, READ, WRITE, SIZE, WAIT, interupt, BREQ, BACK}
|
@wires{ADR, DATA, READ, WRITE, SIZE, WAIT, interupt, BREQ, BACK}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@connection (DMA.glavniPin, PIOSabirnica, FRISC.glavniPin) {
|
||||||
|
@wires{PIO_DATA, READY, STROBE}
|
||||||
|
@wires{PIO_DATA, READY, STROBE}
|
||||||
|
}
|
||||||
|
|
||||||
|
@connection (FRISC.memDirect, directRam, Memorija.memDirect) {
|
||||||
|
@wires{INT}
|
||||||
|
@wires{INT}
|
||||||
|
}
|
||||||
@@ -3,13 +3,16 @@
|
|||||||
@schema {
|
@schema {
|
||||||
@instance proc FRISC {
|
@instance proc FRISC {
|
||||||
@position (0, 0)
|
@position (0, 0)
|
||||||
|
@attribute _memory null
|
||||||
}
|
}
|
||||||
|
|
||||||
@instance mem Memorija {
|
@instance mem Memorija {
|
||||||
@position (0, 250)
|
@position (0, 250)
|
||||||
|
@attribute sinkroniziran false
|
||||||
|
@attribute brzina 1
|
||||||
@attribute kapacitet 1024
|
@attribute kapacitet 1024
|
||||||
@attribute size 8
|
@attribute size 8
|
||||||
@attribute pocetnaAdresa 1023
|
@attribute pocetnaAdresa 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
@instance bus glavnaSabirnica {
|
@instance bus glavnaSabirnica {
|
||||||
@@ -17,39 +20,8 @@
|
|||||||
@size 100
|
@size 100
|
||||||
}
|
}
|
||||||
|
|
||||||
@wire wire_001 {
|
|
||||||
@position (50, 116)
|
|
||||||
@display {
|
|
||||||
/*
|
|
||||||
line {
|
|
||||||
color: blue;
|
|
||||||
points: 100;
|
|
||||||
}*/
|
|
||||||
line {
|
|
||||||
x1: 0; y1: 0; x2: 0; y2: 84;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@wire wire_002 {
|
|
||||||
@position (50, 220)
|
|
||||||
@display {
|
|
||||||
/*
|
|
||||||
line {
|
|
||||||
color: blue;
|
|
||||||
points: 100;
|
|
||||||
}*/
|
|
||||||
line {
|
|
||||||
x1: 0; y1: 0; x2: 0; y2: 14;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@connection (proc.glavniPin, bus) {
|
@connection (proc.glavniPin, bus) {
|
||||||
@wire wire_001
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@connection (mem.glavniPin, bus) {
|
@connection (mem.glavniPin, bus) {
|
||||||
@wire wire_002
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,16 @@
|
|||||||
@schema {
|
@schema {
|
||||||
@instance proc FRISC {
|
@instance proc FRISC {
|
||||||
@position (0, 0)
|
@position (0, 0)
|
||||||
|
@attribute _memory null
|
||||||
}
|
}
|
||||||
|
|
||||||
@instance mem Memorija {
|
@instance mem Memorija {
|
||||||
@position (0, 250)
|
@position (0, 250)
|
||||||
|
@attribute sinkroniziran false
|
||||||
|
@attribute brzina 1
|
||||||
@attribute kapacitet 1024
|
@attribute kapacitet 1024
|
||||||
@attribute size 8
|
@attribute size 8
|
||||||
@attribute pocetnaAdresa 1023
|
@attribute pocetnaAdresa 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
@instance bus glavnaSabirnica {
|
@instance bus glavnaSabirnica {
|
||||||
@@ -17,18 +20,6 @@
|
|||||||
@size 100
|
@size 100
|
||||||
}
|
}
|
||||||
|
|
||||||
@wire wire_001 {
|
|
||||||
@position (50, 116)
|
|
||||||
@display {}
|
|
||||||
}
|
|
||||||
@wire wire_002 {
|
|
||||||
@position (50, 220)
|
|
||||||
@display {}
|
|
||||||
}
|
|
||||||
@connection (proc.glavniPin, bus) {
|
|
||||||
@wire wire_001
|
|
||||||
}
|
|
||||||
@connection (mem.glavniPin, bus) {
|
@connection (mem.glavniPin, bus) {
|
||||||
@wire wire_002
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
@source "/home/bbr/Documents/Personal/FER/schema_editor/examples/simplified FRISC model/frisc_library.csl"
|
||||||
|
|
||||||
|
@schema {
|
||||||
|
@instance memorija Memorija {
|
||||||
|
@position (-12, 68)
|
||||||
|
@attribute sinkroniziran false
|
||||||
|
@attribute brzina 1
|
||||||
|
@attribute kapacitet 65536
|
||||||
|
@attribute size 8
|
||||||
|
@attribute pocetnaAdresa 0
|
||||||
|
}
|
||||||
|
|
||||||
|
@instance procesor FRISC {
|
||||||
|
@position (-206, -76)
|
||||||
|
@attribute _memory memorija
|
||||||
|
}
|
||||||
|
|
||||||
|
@instance directRam directRam {
|
||||||
|
@position (0, 0)
|
||||||
|
@size 0
|
||||||
|
}
|
||||||
|
|
||||||
|
@instance glavnaSabirnica glavnaSabirnica {
|
||||||
|
@position (-222, 130)
|
||||||
|
@size 50
|
||||||
|
}
|
||||||
|
|
||||||
|
@connection (memorija.memDirect, directRam, procesor.memDirect) {
|
||||||
|
}
|
||||||
|
@connection (memorija.glavniPin, glavnaSabirnica) {
|
||||||
|
}
|
||||||
|
@connection (procesor.glavniPin, glavnaSabirnica) {
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
-59
@@ -10,20 +10,26 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <sstream>
|
|
||||||
#include <comdel/domain/comdelvalidator.h>
|
#include <comdel/domain/comdelvalidator.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <comdel/domain/comdel_generator.h>
|
||||||
|
|
||||||
|
std::optional<domain::Library> MainWindow::library;
|
||||||
|
domain::Schema* MainWindow::schema;
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
|
schema = nullptr;
|
||||||
|
library = std::nullopt;
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
setupUi();
|
setupUi();
|
||||||
|
|
||||||
// define allowed methods
|
// define allowed methods
|
||||||
signatures = domain::getSupportedFunctions();
|
validators = domain::getSupportedValidators();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setupUi()
|
void MainWindow::setupUi()
|
||||||
@@ -37,6 +43,7 @@ void MainWindow::setupUi()
|
|||||||
ui->toolBar->addAction("Load library", this, &MainWindow::onLoadLibrary);
|
ui->toolBar->addAction("Load library", this, &MainWindow::onLoadLibrary);
|
||||||
ui->toolBar->addAction("Load schema", this, &MainWindow::onLoadSchema);
|
ui->toolBar->addAction("Load schema", this, &MainWindow::onLoadSchema);
|
||||||
ui->toolBar->addAction("Save schema", this, &MainWindow::onStoreScheme);
|
ui->toolBar->addAction("Save schema", this, &MainWindow::onStoreScheme);
|
||||||
|
ui->toolBar->addAction("Generate system", this, &MainWindow::onGenerateComdel);
|
||||||
|
|
||||||
connect(ui->actionValidate, &QAction::triggered, this, &MainWindow::onValidateSchema);
|
connect(ui->actionValidate, &QAction::triggered, this, &MainWindow::onValidateSchema);
|
||||||
|
|
||||||
@@ -77,7 +84,7 @@ void MainWindow::onLoadLibrary() {
|
|||||||
ParseContext parseContext;
|
ParseContext parseContext;
|
||||||
auto libraryNode = loadLibraryFromFile(&parseContext, filename.toStdString().c_str(), buffer);
|
auto libraryNode = loadLibraryFromFile(&parseContext, filename.toStdString().c_str(), buffer);
|
||||||
if(libraryNode) {
|
if(libraryNode) {
|
||||||
domain::SchemaCreator generator(signatures);
|
domain::SchemaCreator generator(validators);
|
||||||
library = generator.loadLibrary(*libraryNode);
|
library = generator.loadLibrary(*libraryNode);
|
||||||
|
|
||||||
for (auto& error : generator.getErrors()) {
|
for (auto& error : generator.getErrors()) {
|
||||||
@@ -89,7 +96,7 @@ void MainWindow::onLoadLibrary() {
|
|||||||
|
|
||||||
// on library load we create a new schema
|
// on library load we create a new schema
|
||||||
schema = new domain::Schema();
|
schema = new domain::Schema();
|
||||||
schemaDisplay->setSchema(schema);
|
schemaDisplay->setSchema(schema, &(*library));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -115,7 +122,7 @@ void MainWindow::onLoadSchema() {
|
|||||||
auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), buffer);
|
auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), buffer);
|
||||||
|
|
||||||
if(schemaNode) {
|
if(schemaNode) {
|
||||||
domain::SchemaCreator generator(signatures);
|
domain::SchemaCreator generator(validators);
|
||||||
library = generator.loadLibrary(*schemaNode->library);
|
library = generator.loadLibrary(*schemaNode->library);
|
||||||
|
|
||||||
librarySource = schemaNode->source->value;
|
librarySource = schemaNode->source->value;
|
||||||
@@ -129,12 +136,16 @@ void MainWindow::onLoadSchema() {
|
|||||||
|
|
||||||
for (auto& error : generator.getErrors()) {
|
for (auto& error : generator.getErrors()) {
|
||||||
parseContext.formatError(error, buffer, "ERROR: ");
|
parseContext.formatError(error, buffer, "ERROR: ");
|
||||||
|
delete schema;
|
||||||
|
schema = nullptr;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
library = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(generator.getErrors().empty()) {
|
if(generator.getErrors().empty()) {
|
||||||
libraryDisplay->setLibrary(library);
|
libraryDisplay->setLibrary(library);
|
||||||
schemaDisplay->setSchema(schema);
|
schemaDisplay->setSchema(schema, &(*library));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,72 +163,41 @@ void MainWindow::onStoreScheme() {
|
|||||||
|
|
||||||
std::ostringstream buffer;
|
std::ostringstream buffer;
|
||||||
|
|
||||||
buffer << "@source " << this->librarySource << std::endl << std::endl;
|
domain::generateSchemaFile(librarySource, schema, buffer);
|
||||||
|
|
||||||
buffer << "@schema {" << std::endl;
|
|
||||||
|
|
||||||
for(auto &instance: schema->instances) {
|
|
||||||
auto componentInstance = dynamic_cast<domain::ComponentInstance*>(instance);
|
|
||||||
if(componentInstance != nullptr) {
|
|
||||||
buffer << "\t" << "@instance " << componentInstance->name << " " << componentInstance->component.getName() << " {" << std::endl;
|
|
||||||
buffer << "\t\t" << "@position (" << componentInstance->position.first << ", " << componentInstance->position.second << ")" << std::endl;
|
|
||||||
|
|
||||||
for(auto &attribute: instance->attributes) {
|
|
||||||
buffer << "\t\t" << "@attribute " << attribute->name << " " << attribute->value.stringify() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer << "\t}" << std::endl << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto busInstance = dynamic_cast<domain::BusInstance*>(instance);
|
|
||||||
if(busInstance != nullptr) {
|
|
||||||
buffer << "\t" << "@instance " << busInstance->name << " " << busInstance->bus.getName() << " {" << std::endl;
|
|
||||||
buffer << "\t\t" << "@position (" << busInstance->position.first << ", " << busInstance->position.second << ")" << std::endl;
|
|
||||||
buffer << "\t\t" << "@size " << busInstance->size << std::endl;
|
|
||||||
buffer << "\t}" << std::endl << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto &wire: schema->wires) {
|
|
||||||
buffer << "\t" << "@wire " << wire->name << " {" << std::endl;
|
|
||||||
buffer << "\t\t" << "@position (" << wire->position.first << ", " << wire->position.second << ")" << std::endl;
|
|
||||||
buffer << "\t\t" << "@display {}" << std::endl;
|
|
||||||
buffer << "\t" << "}" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto &conn: schema->connections) {
|
|
||||||
auto busConn = dynamic_cast<domain::BusConnectionInstance*>(conn);
|
|
||||||
if(busConn) {
|
|
||||||
buffer << "\t" << "@connection (" << busConn->instance->name << "." << busConn->connection.getComponent().pin << ", " << busConn->bus->name << ") {" << std::endl;
|
|
||||||
buffer << "\t\t"<< "@wire " << busConn->wire->name << std::endl;
|
|
||||||
buffer << "\t" << "}" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer << "}" << std::endl;
|
|
||||||
|
|
||||||
auto value = buffer.str();
|
|
||||||
|
|
||||||
std::ofstream out(filename.toStdString(), std::ios::out | std::ios::binary);
|
std::ofstream out(filename.toStdString(), std::ios::out | std::ios::binary);
|
||||||
out<<buffer.str();
|
out<<buffer.str();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onGenerateComdel() {
|
||||||
|
if(schema == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto filename = QFileDialog::getSaveFileName(this,
|
||||||
|
tr("Save schema"), "/home", tr("Comdel system (*.system)"));
|
||||||
|
|
||||||
|
std::ostringstream buffer;
|
||||||
|
|
||||||
|
domain::generateComdelFile(schema, library.value(), buffer);
|
||||||
|
|
||||||
|
std::ofstream out(filename.toStdString(), std::ios::out | std::ios::binary);
|
||||||
|
out<<buffer.str();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::onValidateSchema(bool /*toggled*/) {
|
void MainWindow::onValidateSchema(bool /*toggled*/) {
|
||||||
if(schema == nullptr) {
|
if(schema == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log->clear();
|
||||||
|
|
||||||
this->validationErrors.clear();
|
this->validationErrors.clear();
|
||||||
|
|
||||||
std::map<std::string, domain::FunctionCallback> callbacks;
|
domain::ComdelValidator validator{validators};
|
||||||
auto functions = domain::getSupportedFunctions();
|
|
||||||
for(auto &func: functions) {
|
|
||||||
callbacks[func.name] = func.callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
domain::ComdelValidator validator{callbacks};
|
|
||||||
|
|
||||||
domain::ValidationContext context;
|
domain::ValidationContext context;
|
||||||
context.instance = nullptr;
|
context.instance = nullptr;
|
||||||
@@ -229,6 +209,12 @@ void MainWindow::onValidateSchema(bool /*toggled*/) {
|
|||||||
}
|
}
|
||||||
auto errors = validator.validateSchema(*schema, context);
|
auto errors = validator.validateSchema(*schema, context);
|
||||||
|
|
||||||
|
auto countValidation = validator.validateInstanceCount(*schema, *library, context);
|
||||||
|
errors.insert(errors.end(), countValidation.begin(), countValidation.end());
|
||||||
|
|
||||||
|
auto pinValidation = validator.validatePinConnections(*schema, *library, context);
|
||||||
|
errors.insert(errors.end(), pinValidation.begin(), pinValidation.end());
|
||||||
|
|
||||||
errors.erase(std::remove_if(
|
errors.erase(std::remove_if(
|
||||||
errors.begin(), errors.end(), [](const domain::ValidationError& error) { return error.type == domain::Action::WARNING;}),
|
errors.begin(), errors.end(), [](const domain::ValidationError& error) { return error.type == domain::Action::WARNING;}),
|
||||||
errors.end());
|
errors.end());
|
||||||
@@ -258,11 +244,14 @@ void MainWindow::onValidateSchema(bool /*toggled*/) {
|
|||||||
|
|
||||||
void MainWindow::clear() {
|
void MainWindow::clear() {
|
||||||
validationErrors.clear();
|
validationErrors.clear();
|
||||||
|
if(schema != nullptr) {
|
||||||
|
delete schema;
|
||||||
schema = nullptr;
|
schema = nullptr;
|
||||||
|
}
|
||||||
library = std::nullopt;
|
library = std::nullopt;
|
||||||
|
|
||||||
libraryDisplay->setLibrary(library);
|
libraryDisplay->setLibrary(library);
|
||||||
schemaDisplay->setSchema(schema);
|
schemaDisplay->setSchema(schema, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|||||||
+14
-3
@@ -27,24 +27,35 @@ public:
|
|||||||
display::Library *libraryDisplay;
|
display::Library *libraryDisplay;
|
||||||
display::Schema *schemaDisplay;
|
display::Schema *schemaDisplay;
|
||||||
|
|
||||||
std::optional<domain::Library> library = std::nullopt;
|
static std::optional<domain::Library> library;
|
||||||
domain::Schema* schema = nullptr;
|
static domain::Schema* schema;
|
||||||
|
|
||||||
std::vector<domain::FunctionSignature> signatures;
|
std::vector<domain::FunctionValidator*> validators;
|
||||||
|
|
||||||
void setupUi();
|
void setupUi();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
static domain::Schema* getSchema() {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::optional<domain::Library> getLibrary() {
|
||||||
|
return library;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onLoadLibrary();
|
void onLoadLibrary();
|
||||||
void onLoadSchema();
|
void onLoadSchema();
|
||||||
void onValidateSchema(bool toggled);
|
void onValidateSchema(bool toggled);
|
||||||
void onStoreScheme();
|
void onStoreScheme();
|
||||||
|
void onGenerateComdel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string librarySource;
|
std::string librarySource;
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QPlainTextEdit *log;
|
QPlainTextEdit *log;
|
||||||
std::vector<domain::ValidationError> validationErrors;
|
std::vector<domain::ValidationError> validationErrors;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // MAIN_WINDOW_H
|
#endif // MAIN_WINDOW_H
|
||||||
Reference in new issue
Block a user