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