This commit is contained in:
Borna Rajković 2022-06-13 00:55:54 +02:00
parent 1ec0433cfe
commit fe4a39803c
2 changed files with 31 additions and 33 deletions

View File

@ -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<FunctionValidator *> 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<Bus> SchemaCreator::loadBus(BusNode node) {
@ -264,13 +264,12 @@ namespace domain {
return Bus(busName, instanceName, tooltip, type, count, wires, displayBus);
}
std::optional<AddressSpace> SchemaCreator::loadAddressSpace(AddressSpaceNode node) {
return AddressSpace(node.name.value, node.range.first.value, node.range.second.value);
}
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;
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<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;
@ -1008,7 +1006,6 @@ namespace domain {
}
shared_ptr<ComponentInstance> 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);
}
}

View File

@ -13,6 +13,7 @@
namespace domain {
/** Context used for loading model */
struct ComdelContext {
std::vector<Attribute> attributes;
std::vector<std::string> 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<FunctionValidator *> validators);
std::vector<SourceError> getErrors();
std::optional<Library> loadLibrary(LibraryNode node);
Schema *loadSchema(SchemaNode node, Library &library);
private:
std::vector<ComdelContext> context;
std::string name;
@ -43,7 +53,6 @@ namespace domain {
std::vector<Connection> connections;
std::map<std::string, std::string> messages;
std::vector<SourceError> errors;
std::vector<FunctionValidator *> validators;
@ -57,33 +66,25 @@ namespace domain {
std::optional<Display> loadDisplay(DisplayNode node);
std::optional<Wire> loadWire(WireNode node);
std::optional<Pin> loadPin(PinNode pins);
std::optional<Connection> loadConnection(ConnectionNode node);
std::optional<Bus> loadBus(BusNode node);
std::shared_ptr<ComponentInstance> loadComponentInstance(InstanceNode instance, Library &library);
std::shared_ptr<BusInstance> loadBusInstance(InstanceNode instance, Library &library);
/** Utility classes */
std::optional<Bus> getBus(std::string name);
std::optional<Pin> getComponentPin(std::string name, std::string pin);
bool hasAddressSpace(std::string name);
void push(ComdelContext context);
void pushAdditional(std::string name);
ComdelContext &current();
void pop();
std::optional<Attribute> createMemoryAttribute();
vector<Enumeration> createWireEnumeration(vector<Value> enumeration);
std::optional<Popup> createMemoryPopup();
public:
explicit SchemaCreator(std::vector<FunctionValidator *> validators);
std::vector<SourceError> getErrors();
std::optional<Library> loadLibrary(LibraryNode node);
Schema *loadSchema(SchemaNode node, Library &library);
/** Context stack operations */
void push(ComdelContext context);
void pushAdditional(std::string name);
ComdelContext &current();
void pop();
};
} // namespace domain