diff --git a/comdel/domain/schema_creator.cpp b/comdel/domain/schema_creator.cpp index 292bdfa..dfbd9a1 100644 --- a/comdel/domain/schema_creator.cpp +++ b/comdel/domain/schema_creator.cpp @@ -5,9 +5,8 @@ namespace domain { - - ComdelContext::ComdelContext(std::string name, bool inComponent, bool inConnection, bool inSingleAutomaticConnection, bool inBus) - : name(std::move(name)), inComponent(inComponent), inConnection(inConnection), inSingleAutomaticConnection(inSingleAutomaticConnection), inBus(inBus) {} + ComdelContext::ComdelContext(std::string name, bool inComponent, bool inConnection, bool inSingleAutomaticConnection) + : name(std::move(name)), inComponent(inComponent), inConnection(inConnection), inSingleAutomaticConnection(inSingleAutomaticConnection) {} bool ComdelContext::doesAttributeExists(std::string name, Value::ValueType type) { for (auto &attribute: attributes) { @@ -27,7 +26,9 @@ namespace domain { return false; } - + /*********************************************************************** + * ENUM CONVERSIONS * + ***********************************************************************/ Component::ComponentType toType(ComponentNode::ComponentType type) { if (type == ComponentNode::MEMORY) { return Component::MEMORY; @@ -78,7 +79,6 @@ namespace domain { } } - Value toType(ValueNode node, Value::ValueType type = Value::ValueType::UNDEFINED) { if (type == Value::MEMORY_REFERENCE) { if (node.is(ValueNode::NIL)) { @@ -87,7 +87,6 @@ namespace domain { return Value::fromMemoryReference(node.asIdentifier()); } } - if (node.is(ValueNode::BOOL)) { return Value::fromBool(node.asBool()); } else if (node.is(ValueNode::INT)) { @@ -100,7 +99,6 @@ namespace domain { return Value::fromReference(node.asIdentifier(), Value::UNDEFINED); } - Bus::BusType toType(BusNode::BusType type) { if (type == BusNode::AUTOMATIC) { return Bus::AUTOMATIC; @@ -110,7 +108,6 @@ namespace domain { return Bus::REGULAR; } - Pin::PinType toType(PinNode::PinType type) { if (type == PinNode::IN) { return Pin::IN; @@ -127,6 +124,11 @@ namespace domain { return Popup::ON_DEMAND; } + + /*********************************************************************** + * SCHEMA CREATOR * + ***********************************************************************/ + SchemaCreator::SchemaCreator(std::vector validators) : validators(std::move(validators)) {} @@ -151,7 +153,6 @@ namespace domain { } header = node.header ? node.header->asString() : ""; - libraryInfo = node.libraryInfo ? node.libraryInfo->asString() : ""; for (auto &as: node.addressSpaces) { @@ -193,7 +194,6 @@ namespace domain { } else { return nullopt; } - } std::optional SchemaCreator::loadBus(BusNode node) { @@ -264,13 +264,12 @@ namespace domain { return Bus(busName, instanceName, tooltip, type, count, wires, displayBus); } - std::optional SchemaCreator::loadAddressSpace(AddressSpaceNode node) { return AddressSpace(node.name.value, node.range.first.value, node.range.second.value); } std::optional SchemaCreator::loadConnection(ConnectionNode node) { - push(ComdelContext("connection", false, true, false, false)); + push(ComdelContext("connection", false, true, false)); std::string bus = node.bus.value; auto busInstance = getBus(bus); @@ -445,7 +444,6 @@ namespace domain { attributes[1].setPupup(popup); } } - pop(); return Connection(first, second, bus, attributes, firstWires, secondWires); @@ -457,7 +455,7 @@ namespace domain { } std::optional SchemaCreator::loadComponent(ComponentNode node) { - push(ComdelContext(node.name.value, true, false, false, false)); + push(ComdelContext(node.name.value, true, false, false)); std::string componentName = node.name.value; @@ -1008,7 +1006,6 @@ namespace domain { } shared_ptr SchemaCreator::loadComponentInstance(InstanceNode instance, Library &library) { - auto componentInstanceName = instance.name.value; auto position = std::make_pair(instance.position->first.value, instance.position->second.value); @@ -1113,7 +1110,7 @@ namespace domain { this->context.push_back(current()); current().name = name; } else { - ComdelContext con(name, false, false, false, false); + ComdelContext con(name, false, false, false); push(con); } } diff --git a/comdel/domain/schema_creator.h b/comdel/domain/schema_creator.h index 3066361..44b8884 100644 --- a/comdel/domain/schema_creator.h +++ b/comdel/domain/schema_creator.h @@ -13,6 +13,7 @@ namespace domain { + /** Context used for loading model */ struct ComdelContext { std::vector attributes; std::vector wires; @@ -20,9 +21,8 @@ namespace domain { bool inComponent; bool inConnection; bool inSingleAutomaticConnection; - bool inBus; - ComdelContext(std::string name, bool inComponent, bool inConnection, bool inSingleAutomaticConnection, bool inBus); + ComdelContext(std::string name, bool inComponent, bool inConnection, bool inSingleAutomaticConnection); bool doesAttributeExists(std::string name, Value::ValueType type); bool doesWireExists(std::string name); @@ -30,6 +30,16 @@ namespace domain { }; class SchemaCreator { + + public: + explicit SchemaCreator(std::vector validators); + + std::vector getErrors(); + + std::optional loadLibrary(LibraryNode node); + Schema *loadSchema(SchemaNode node, Library &library); + + private: std::vector context; std::string name; @@ -43,7 +53,6 @@ namespace domain { std::vector connections; std::map messages; - std::vector errors; std::vector validators; @@ -57,33 +66,25 @@ namespace domain { std::optional loadDisplay(DisplayNode node); std::optional loadWire(WireNode node); std::optional loadPin(PinNode pins); - std::optional loadConnection(ConnectionNode node); std::optional loadBus(BusNode node); - std::shared_ptr loadComponentInstance(InstanceNode instance, Library &library); std::shared_ptr loadBusInstance(InstanceNode instance, Library &library); + /** Utility classes */ std::optional getBus(std::string name); std::optional getComponentPin(std::string name, std::string pin); bool hasAddressSpace(std::string name); - void push(ComdelContext context); - void pushAdditional(std::string name); - ComdelContext ¤t(); - void pop(); - std::optional createMemoryAttribute(); vector createWireEnumeration(vector enumeration); std::optional createMemoryPopup(); - public: - explicit SchemaCreator(std::vector validators); - - std::vector getErrors(); - - std::optional loadLibrary(LibraryNode node); - Schema *loadSchema(SchemaNode node, Library &library); + /** Context stack operations */ + void push(ComdelContext context); + void pushAdditional(std::string name); + ComdelContext ¤t(); + void pop(); }; } // namespace domain