schema_editor/comdel/domain/schemacreator.h

153 lines
4.3 KiB
C
Raw Normal View History

2022-04-08 18:17:58 +00:00
#ifndef DOMAIN_COMDEL_GENERATOR_H
#define DOMAIN_COMDEL_GENERATOR_H
2022-03-31 21:20:41 +00:00
#include "library.h"
2022-04-05 21:48:07 +00:00
#include "schema.h"
#include <set>
2022-03-31 21:20:41 +00:00
#include <comdel/parser/astnode.h>
#include <comdel/parser/parsecontext.h>
#include <comdel/parser/presult.h>
namespace domain {
2022-04-05 21:48:07 +00:00
struct ComdelContext {
std::vector<Attribute> attributes;
std::vector<std::string> wires;
std::string name;
bool inComponent;
bool inConnection;
bool inSingleAutomaticConnection;
2022-04-05 21:48:07 +00:00
bool inBus;
ComdelContext(std::string name, bool inComponent, bool inConnection, bool inSingleAutomaticConnection, bool inBus)
: name(name), inComponent(inComponent), inConnection(inConnection), inSingleAutomaticConnection(inSingleAutomaticConnection), inBus(inBus)
2022-04-05 21:48:07 +00:00
{}
bool doesAttributeExists(std::string name, Value::ValueType type) {
for(auto &attribute: attributes) {
if(attribute.getDefault().getType() == type && attribute.getName() == name) {
return true;
}
}
return false;
}
bool doesWireExists(std::string name) {
for(auto &w: wires) {
if(w == name) {
return true;
}
}
return false;
}
};
2022-04-09 18:03:43 +00:00
class SchemaCreator
2022-03-31 21:20:41 +00:00
{
2022-04-05 21:48:07 +00:00
std::vector<ComdelContext> context;
std::string name;
std::string libraryInfo;
std::string header;
std::string componentDirectory;
std::vector<AddressSpace> addressSpaces;
std::vector<Component> components;
std::vector<Bus> buses;
std::vector<Connection> connections;
std::map<std::string, std::string> messages;
2022-03-31 21:20:41 +00:00
std::vector<SourceError> errors;
2022-05-15 09:17:05 +00:00
std::vector<FunctionValidator*> validators;
2022-03-31 21:20:41 +00:00
std::optional<AddressSpace> loadAddressSpace(AddressSpaceNode node);
std::optional<Component> loadComponent(ComponentNode node);
std::optional<Attribute> loadAttribute(AttributeNode node);
std::optional<Rule> loadRule(RuleNode node);
std::optional<Condition> loadCondition(ConditionNode node);
std::optional<Popup> loadPopup(PopupNode node, std::string name, Value::ValueType type);
std::optional<Display> loadDisplay(DisplayNode node);
2022-04-05 21:48:07 +00:00
std::optional<Wire> loadWire(WireNode node);
2022-03-31 21:20:41 +00:00
std::optional<Pin> loadPin(PinNode pins);
PinConnection loadPinConnection(PinConnectionNode node);
std::optional<Connection> loadConnection(ConnectionNode node);
std::optional<Bus> loadBus(BusNode node);
2022-05-07 12:19:43 +00:00
std::shared_ptr<ComponentInstance> loadComponentInstance(InstanceNode instance, Library &library);
std::shared_ptr<BusInstance> loadBusInstance(InstanceNode instance, Library &library);
2022-04-05 21:48:07 +00:00
2022-05-15 21:55:03 +00:00
std::optional<Attribute> createMemoryAttribute();
2022-04-05 21:48:07 +00:00
std::optional<Bus> getBus(std::string name) {
for(auto &bus: buses) {
if(bus.getName() == name) {
return bus;
}
}
return std::nullopt;
}
std::optional<Pin> getComponentPin(std::string name, std::string pin) {
for(auto &c: components) {
if(c.getName() == name) {
for(auto &p: c.getPins()) {
if(p.getName() == pin) {
return p;
}
}
}
}
return nullopt;
}
bool hasAddressSpace(std::string name) {
for(auto &as: addressSpaces) {
if(as.getName() == name) {
return true;
}
}
return false;
}
void push(ComdelContext context) {
this->context.push_back(context);
}
void pushAdditional(std::string name) {
2022-05-07 12:19:43 +00:00
if(!this->context.empty()) {
2022-04-05 21:48:07 +00:00
this->context.push_back(current());
current().name = name;
} else {
ComdelContext con(name, false, false, false, false);
2022-04-05 21:48:07 +00:00
push(con);
}
}
ComdelContext &current() {
return this->context[this->context.size() - 1];
}
void pop() {
this->context.pop_back();
}
2022-03-31 21:20:41 +00:00
public:
2022-05-15 09:17:05 +00:00
SchemaCreator(std::vector<FunctionValidator*> validators);
2022-03-31 21:20:41 +00:00
std::vector<SourceError> getErrors() {
return errors;
}
2022-04-05 21:48:07 +00:00
std::optional<Library> loadLibrary(LibraryNode node);
2022-04-18 09:41:02 +00:00
Schema* loadSchema(SchemaNode node, Library &library);
2022-05-15 21:55:03 +00:00
vector <Enumeration> createWireEnumeration(vector<Value> vector1);
std::optional<Popup> createMemoryPopup();
2022-03-31 21:20:41 +00:00
};
} // namespace domain
2022-04-08 18:17:58 +00:00
#endif // DOMAIN_COMDEL_GENERATOR_H