From eaa115d115c2151573224d6b66273997f1bec779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borna=20Rajkovi=C4=87?= Date: Tue, 14 Jun 2022 21:27:40 +0200 Subject: [PATCH] Added display name --- comdel/display/component_display.cpp | 14 +++--- comdel/display/library_display.cpp | 4 +- comdel/display/schema_display.cpp | 2 +- comdel/domain/attribute.cpp | 11 ++++- comdel/domain/attribute.h | 5 +- comdel/domain/bus.cpp | 12 ++++- comdel/domain/bus.h | 5 +- comdel/domain/component.cpp | 12 +++-- comdel/domain/component.h | 5 +- comdel/domain/schema_creator.cpp | 30 +++++++++--- comdel/parser/ast_nodes.h | 7 +++ comdel/parser/comdel_parser.cpp | 46 +++++++++++++------ comdel/parser/token.h | 1 + comdel/parser/tokens_type.cpp | 1 + .../simplified FRISC model/frisc_library.csl | 5 ++ 15 files changed, 120 insertions(+), 40 deletions(-) diff --git a/comdel/display/component_display.cpp b/comdel/display/component_display.cpp index cf393f8..a1063d0 100644 --- a/comdel/display/component_display.cpp +++ b/comdel/display/component_display.cpp @@ -19,7 +19,7 @@ namespace display { Component::Component(const std::shared_ptr &instance): instance(instance) { setFlag(ItemSendsGeometryChanges, true); - setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getName())); + setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getDisplayName())); instance->component.getDisplay().render(this, domain::ui::DisplayContext(instance.get())); } @@ -37,7 +37,7 @@ namespace display { auto newName = dialog->getName(); Application::instance()->renameComponent(currentName, newName); - setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getName())); + setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getDisplayName())); }); menu.addSeparator(); for (int i = 0; i < this->instance->attributes.size(); i++) { @@ -51,9 +51,9 @@ namespace display { dialog->exec(); }); } else { - auto action = menu.addAction(QString::fromStdString("Izmjeni '" + attr->name + "'"), + auto action = menu.addAction(QString::fromStdString("Izmjeni '" + attr->attribute.getDisplayName() + "'"), [attr]() { - auto dialog = new AttributeDialog("Izmjeni " + attr->name, "Izmjeni", attr); + auto dialog = new AttributeDialog("Izmjeni " + attr->attribute.getDisplayName(), "Izmjeni", attr); dialog->exec(); }); action->setEnabled(enabled); @@ -109,8 +109,8 @@ namespace display { } for (int i = 0; i < pinConnection->attributes.size(); i++) { auto *attr = &pinConnection->attributes[i]; - menu.addAction(QString::fromStdString("Izmjeni '" + attr->name + "'"),[attr]() { - auto dialog = new AttributeDialog("Izmjeni '" + attr->name + "'", "Izmjeni", attr); + menu.addAction(QString::fromStdString("Izmjeni '" + attr->attribute.getDisplayName() + "'"),[attr]() { + auto dialog = new AttributeDialog("Izmjeni '" + attr->attribute.getDisplayName() + "'", "Izmjeni", attr); dialog->exec(); }); } @@ -198,7 +198,7 @@ namespace display { auto newName = dialog->getName(); Application::instance()->renameBus(currentName, newName); - setToolTip(QString::fromStdString(busInstance->name + "::" + busInstance->bus.getName())); + setToolTip(QString::fromStdString(busInstance->name + "::" + busInstance->bus.getDisplayName())); }); menu.addSeparator(); menu.addAction(QString::fromStdString("Ukloni " + this->busInstance->name), [this]() { diff --git a/comdel/display/library_display.cpp b/comdel/display/library_display.cpp index d362571..ffa4563 100644 --- a/comdel/display/library_display.cpp +++ b/comdel/display/library_display.cpp @@ -33,7 +33,7 @@ namespace display { } for (auto &component: library->getComponents()) { - auto item = new LibraryListItem{component.getName(), "comdel/component", component.getName(), + auto item = new LibraryListItem{component.getDisplayName(), "comdel/component", component.getName(), componentList}; item->setToolTip(QString::fromStdString(component.getTooltip())); componentList->addItem(item); @@ -41,7 +41,7 @@ namespace display { for (auto &bus: library->getBuses()) { if (bus.getType() == domain::Bus::REGULAR) { - auto item = new LibraryListItem{bus.getName(), "comdel/bus", bus.getName(), busList}; + auto item = new LibraryListItem{bus.getDisplayName(), "comdel/bus", bus.getName(), busList}; item->setToolTip(QString::fromStdString(bus.getTooltip())); busList->addItem(item); } diff --git a/comdel/display/schema_display.cpp b/comdel/display/schema_display.cpp index 22af1c0..2c98709 100644 --- a/comdel/display/schema_display.cpp +++ b/comdel/display/schema_display.cpp @@ -282,7 +282,7 @@ namespace display { return {}; } } else { - auto dialog = new AttributeDialog("Postavi " + attribute.name, "Postavi", &attribute); + auto dialog = new AttributeDialog("Postavi " + attribute.attribute.getDisplayName(), "Postavi", &attribute); if(dialog->exec() == QDialog::Rejected) { // if any dialog isn't set, whole creation is rejected return {}; diff --git a/comdel/domain/attribute.cpp b/comdel/domain/attribute.cpp index d780da7..a630972 100644 --- a/comdel/domain/attribute.cpp +++ b/comdel/domain/attribute.cpp @@ -44,8 +44,15 @@ namespace domain { } - Attribute::Attribute(std::string name, Value defaultValue, std::optional popup) - : name(name), defaultValue(defaultValue), popup(popup) {} + Attribute::Attribute(std::string name, std::optional displayName, Value defaultValue, std::optional popup) + : name(name), displayName(displayName), defaultValue(defaultValue), popup(popup) {} + + std::string Attribute::getDisplayName() { + if(displayName.has_value()) { + return *displayName; + } + return name; + } std::string Attribute::getName() { return name; diff --git a/comdel/domain/attribute.h b/comdel/domain/attribute.h index f5e8968..059c59a 100644 --- a/comdel/domain/attribute.h +++ b/comdel/domain/attribute.h @@ -61,13 +61,16 @@ namespace domain { class Attribute { std::string name; + std::optional displayName; Value defaultValue; std::optional popup; public: - Attribute(std::string name, Value defaultValue, std::optional popup = std::nullopt); + Attribute(std::string name, std::optional displayName, Value defaultValue, std::optional popup = std::nullopt); std::string getName(); + std::string getDisplayName(); + Value getDefault(); std::optional getPopup(); diff --git a/comdel/domain/bus.cpp b/comdel/domain/bus.cpp index 10f90e5..5c6fee1 100644 --- a/comdel/domain/bus.cpp +++ b/comdel/domain/bus.cpp @@ -35,14 +35,21 @@ namespace domain { return type; } - Bus::Bus(std::string name, std::string instanceName, std::string tooltip, BusType type, std::pair count, std::vector wires, + Bus::Bus(std::string name, std::optional displayName, std::string instanceName, std::string tooltip, BusType type, std::pair count, std::vector wires, std::optional displayBus) - : name(name), instanceName(instanceName), tooltip(tooltip), type(type), count(count), wires(wires), displayBus(displayBus) {} + : name(name), displayName(displayName), instanceName(instanceName), tooltip(tooltip), type(type), count(count), wires(wires), displayBus(displayBus) {} std::string Bus::getName() { return name; } + std::string Bus::getDisplayName() { + if(displayName.has_value()) { + return *displayName; + } + return name; + } + std::string Bus::getTooltip() { return tooltip; } @@ -62,4 +69,5 @@ namespace domain { std::optional Bus::getDisplayBus() { return displayBus; } + } // namespace domain diff --git a/comdel/domain/bus.h b/comdel/domain/bus.h index 3cc02ab..2048ba9 100644 --- a/comdel/domain/bus.h +++ b/comdel/domain/bus.h @@ -54,6 +54,7 @@ namespace domain { }; private: std::string name; + std::optional displayName; std::string instanceName; std::string tooltip; BusType type; @@ -63,11 +64,13 @@ namespace domain { std::vector wires; public: - Bus(std::string name, std::string instanceName, std::string tooltip, BusType type, std::pair count, std::vector wires, + Bus(std::string name, std::optional displayName, std::string instanceName, std::string tooltip, BusType type, std::pair count, std::vector wires, std::optional display = std::nullopt); std::string getName(); + std::string getDisplayName(); + std::string getInstanceName(); std::string getTooltip(); diff --git a/comdel/domain/component.cpp b/comdel/domain/component.cpp index c3b898a..3a237a1 100644 --- a/comdel/domain/component.cpp +++ b/comdel/domain/component.cpp @@ -2,16 +2,23 @@ namespace domain { - Component::Component(string name, string tooltip, string source, ComponentType type, + Component::Component(string name, optional displayName, string tooltip, string source, ComponentType type, vector rules, string instanceName, pair count, Display display, vector pins, vector attributes) - : name(name), tooltip(tooltip), source(source), type(type), rules(rules), instanceName(instanceName), + : name(name), displayName(displayName), tooltip(tooltip), source(source), type(type), rules(rules), instanceName(instanceName), count(count), display(display), pins(pins), attributes(attributes) {} std::string Component::getName() { return name; } + std::string Component::getDisplayName() { + if(displayName.has_value()) { + return displayName.value(); + } + return name; + } + std::string Component::getTooltip() { return tooltip; } @@ -94,5 +101,4 @@ namespace domain { return false; } - } // namespace domain diff --git a/comdel/domain/component.h b/comdel/domain/component.h index 729b735..f8700e7 100644 --- a/comdel/domain/component.h +++ b/comdel/domain/component.h @@ -23,6 +23,7 @@ namespace domain { private: std::string name; + std::optional displayName; std::string tooltip; std::string source; ComponentType type; @@ -36,12 +37,14 @@ namespace domain { public: - Component(string name, string tooltip, string source, ComponentType type, + Component(string name, optional displayName, string tooltip, string source, ComponentType type, vector rules, string instanceName, pair count, Display display, vector pins, vector attributes); std::string getName(); + std::string getDisplayName(); + std::string getTooltip(); std::string getSource(); diff --git a/comdel/domain/schema_creator.cpp b/comdel/domain/schema_creator.cpp index dfbd9a1..73b210a 100644 --- a/comdel/domain/schema_creator.cpp +++ b/comdel/domain/schema_creator.cpp @@ -199,6 +199,11 @@ namespace domain { std::optional SchemaCreator::loadBus(BusNode node) { std::string busName = node.name.value; + std::optional displayName = nullopt; + if(node.displayName.has_value()) { + displayName = node.displayName->asString(); + } + if (!node.instanceName) { errors.emplace_back(node.span, "missing @instanceName"); return nullopt; @@ -261,7 +266,7 @@ namespace domain { return nullopt; } - return Bus(busName, instanceName, tooltip, type, count, wires, displayBus); + return Bus(busName, displayName, instanceName, tooltip, type, count, wires, displayBus); } std::optional SchemaCreator::loadAddressSpace(AddressSpaceNode node) { @@ -459,6 +464,11 @@ namespace domain { std::string componentName = node.name.value; + std::optional displayName = nullopt; + if (node.displayName.has_value()) { + displayName = node.displayName->asString(); + } + if (!node.tooltip) { errors.emplace_back(node.span, "missing @tooltip"); pop(); @@ -535,7 +545,7 @@ namespace domain { } pop(); - return Component(componentName, tooltip, source, type, rules, instanceName, count, *display, pins, attributes); + return Component(componentName, displayName, tooltip, source, type, rules, instanceName, count, *display, pins, attributes); } std::optional SchemaCreator::loadWire(WireNode node) { @@ -721,6 +731,12 @@ namespace domain { std::optional SchemaCreator::loadAttribute(AttributeNode node) { std::string name = node.name.value; pushAdditional(name); + + std::optional displayName = nullopt; + if (node.displayName.has_value()) { + displayName = node.displayName->asString(); + } + Value value; if (current().inComponent) { @@ -754,7 +770,7 @@ namespace domain { } } - current().attributes.emplace_back(name, value); + current().attributes.emplace_back(name, nullopt, value); std::optional popup; if (node.popup) { @@ -762,7 +778,7 @@ namespace domain { } pop(); - return Attribute(name, value, popup); + return Attribute(name, displayName, value, popup); } std::optional SchemaCreator::loadPopup(PopupNode node, std::string name, Value::ValueType type) { @@ -771,7 +787,7 @@ namespace domain { pushAdditional(name); current().attributes.clear(); - current().attributes.emplace_back(name, Value::ofType(type)); + current().attributes.emplace_back(name, nullopt, Value::ofType(type)); if (!node.title) { errors.emplace_back(node.span, "missing @title"); @@ -1028,7 +1044,7 @@ namespace domain { 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() + "'")); + errors.emplace_back(SourceError(instance.span, "missing attribute '" + attr.getDisplayName() + "'")); } } } @@ -1062,7 +1078,7 @@ namespace domain { } std::optional SchemaCreator::createMemoryAttribute() { - return Attribute("_memory", Value::fromMemoryReference(std::nullopt), createMemoryPopup()); + return Attribute("_memory", nullopt, Value::fromMemoryReference(std::nullopt), createMemoryPopup()); } std::optional SchemaCreator::createMemoryPopup() { diff --git a/comdel/parser/ast_nodes.h b/comdel/parser/ast_nodes.h index 9630f1e..1c410e1 100644 --- a/comdel/parser/ast_nodes.h +++ b/comdel/parser/ast_nodes.h @@ -256,6 +256,8 @@ struct AttributeNode : public AstNode { ValueNode::ValueType type; /** Name of attribute */ IdentifierNode name; + /** Display name */ + std::optional displayName; /** Default type of attribute */ std::optional defaultValue; /** Popup used to change attribute value */ @@ -360,6 +362,8 @@ struct ComponentNode : public AstNode { /** Component name */ IdentifierNode name; + /** Component name */ + std::optional displayName; /** Tooltip displayed on hover */ std::optional tooltip; /** Contains path to COMDEL source containing current component */ @@ -425,7 +429,10 @@ struct BusNode : public AstNode { }; EnumNode type; + /** Bus name */ IdentifierNode name; + /** Display name */ + std::optional displayName; /** Default used to name instances */ std::optional instanceName; /** Tooltip displayed on hover */ diff --git a/comdel/parser/comdel_parser.cpp b/comdel/parser/comdel_parser.cpp index 71c3743..bd668fc 100644 --- a/comdel/parser/comdel_parser.cpp +++ b/comdel/parser/comdel_parser.cpp @@ -481,6 +481,7 @@ PResult ComdelParser::parseAddress() { * * ComponentNode := "@component" + IdentifierNode + ComponentType + "{" * "@instanceName" + IdentifierNode + * ["@displayName" + StringNode]{0,1} * "@tooltip" + StringNode * "@source" + StringNode * "@tooltip" + StringNode @@ -507,6 +508,8 @@ PResult ComdelParser::parseComponent() { PResult> err; if (consume(TokenType::KW_INSTANCE_NAME)) { ASSIGN_OR_SET_ERR(component.instanceName, parseIdentifier()); + } else if (consume(TokenType::KW_DISPLAY_NAME)) { + ASSIGN_OR_SET_ERR(component.displayName, parseString()); } else if (consume(TokenType::KW_TOOLTIP)) { ASSIGN_OR_SET_ERR(component.tooltip, parseString()); } else if (consume(TokenType::KW_SOURCE)) { @@ -608,6 +611,7 @@ PResult ComdelParser::parseDisplayItem() { * BusNode := "@bus " + IdentifierNode + BusType + "{" * "@tooltip" + StringNode * "@instanceName" + StringNode + * ["@displayName" + StringNode]{0,1} * DisplayNode * "@wires {" + [WireNode + ","]{0..N} + WireNode "}" * "}" @@ -628,6 +632,8 @@ PResult ComdelParser::parseBus() { PResult> err; if (consume(TokenType::KW_TOOLTIP)) { ASSIGN_OR_SET_ERR(bus.tooltip, parseString()); + } else if (consume(TokenType::KW_DISPLAY_NAME)) { + ASSIGN_OR_SET_ERR(bus.displayName, parseString()); } else if (consume(TokenType::KW_INSTANCE_NAME)) { ASSIGN_OR_SET_ERR(bus.instanceName, parseIdentifier()); } else if (consume(TokenType::KW_COUNT)) { @@ -810,10 +816,13 @@ PResult ComdelParser::parsePin() { } /**************************************************************************** -* -* AttributeNode := "@attribute " + IdentifierNode + ValueType + ("default" + ValueNode){0,1} + ("{" PopupNode "}"){0,1} -* -****************************************************************************/ + * + * AttributeNode := "@attribute " + IdentifierNode + ValueType + ("default" + ValueNode){0,1} + ("{" + * [PopupNode] + * ["@displayName" + StringNode]{0,1} + * "}"){0,1} + * + ****************************************************************************/ PResult ComdelParser::parseAttribute() { auto spanner = getSpanner(); AttributeNode attribute; @@ -889,16 +898,27 @@ PResult ComdelParser::parseAttribute() { } } - if (check(TokenType::LBRACE)) { - RETURN_IF_NOT_TOKEN(TokenType::LBRACE); - if (!check(TokenType::KW_POPUP)) { - return unexpected(); + if (consume(TokenType::LBRACE)) { + while(!consume(TokenType::RBRACE)) { + PResult> err; + if (check(TokenType::KW_POPUP)) { + PopupNode popup; + ASSIGN_OR_SET_ERR(popup, parsePopup()); + attribute.popup = std::optional(popup); + } else if (consume(TokenType::KW_DISPLAY_NAME)) { + ASSIGN_OR_SET_ERR(attribute.displayName, parseString()); + } else { + err = unexpected(); + bump(); + } + if (!err.has_value()) { + errors.push_back(err.error()); + skipUntilNextKeyword(); + if (check(TokenType::END_OF_FILE)) { + return PError({Span(spanner.lo), "Reached EOF"}); + } + } } - - PopupNode popup; - ASSIGN_OR_RETURN_IF_ERR(popup, parsePopup()); - attribute.popup = std::optional(popup); - RETURN_IF_NOT_TOKEN(TokenType::RBRACE); } return spanner(attribute); diff --git a/comdel/parser/token.h b/comdel/parser/token.h index 4418719..51732ee 100644 --- a/comdel/parser/token.h +++ b/comdel/parser/token.h @@ -101,6 +101,7 @@ enum class TokenType { KW_SCHEMA, KW_POSITION, KW_SIZE, + KW_DISPLAY_NAME, // TYPES INT_TYPE, diff --git a/comdel/parser/tokens_type.cpp b/comdel/parser/tokens_type.cpp index 8edf78d..5994479 100644 --- a/comdel/parser/tokens_type.cpp +++ b/comdel/parser/tokens_type.cpp @@ -106,6 +106,7 @@ TokenTables::TokenTables() { add(TokenType::KW_SCHEMA, "@schema", TOKENIZABLE | KEYWORD_NAME); add(TokenType::KW_POSITION, "@position", TOKENIZABLE | KEYWORD_NAME); add(TokenType::KW_SIZE, "@size", TOKENIZABLE | KEYWORD_NAME); + add(TokenType::KW_DISPLAY_NAME, "@displayName", TOKENIZABLE | KEYWORD_NAME); // All types add(TokenType::INT_TYPE, "int", TOKENIZABLE); diff --git a/examples/simplified FRISC model/frisc_library.csl b/examples/simplified FRISC model/frisc_library.csl index 9ccdb59..60ad043 100644 --- a/examples/simplified FRISC model/frisc_library.csl +++ b/examples/simplified FRISC model/frisc_library.csl @@ -17,6 +17,7 @@ } @component FRISC processor { + @displayName "Frisc procesor" @instanceName procesor @tooltip "Procesor FRISC, mora postojati jedan" @count (1, 1) @@ -131,6 +132,7 @@ } @attribute size int default 8 @attribute pocetnaAdresa int default 0 { + @displayName "Početna adresa" @popup automatic { @title "Početna adresa memorije" @text "Zadajte početnu adresu memorije" @@ -226,12 +228,14 @@ } @component DMA { + @displayName "DMA kontroler" @instanceName dma @tooltip "DMA-kontroler" @count (0,1000) @source "dma.cdl" @attribute pocetnaAdresa int default 0 { + @displayName "Početna adresa" @popup automatic { @title "Početna adresa DMA-kontrolera" @text "Zadajte početnu adresu DMA-kontrolera" @@ -307,6 +311,7 @@ } @bus glavnaSabirnica regular { + @displayName "Glavna sabirnica" @instanceName glavnaSabirnica @tooltip "sabirnica za spajanje FRISC a s memorijama i UI/jedinicama" @count (1,1)