154 lines
4.4 KiB
C++
154 lines
4.4 KiB
C++
#ifndef DOMAIN_COMDEL_GENERATOR_H
|
|
#define DOMAIN_COMDEL_GENERATOR_H
|
|
|
|
#include "library.h"
|
|
#include "schema.h"
|
|
|
|
#include <set>
|
|
|
|
#include <comdel/parser/astnode.h>
|
|
#include <comdel/parser/parsecontext.h>
|
|
#include <comdel/parser/presult.h>
|
|
|
|
namespace domain {
|
|
|
|
struct ComdelContext {
|
|
std::vector<Attribute> attributes;
|
|
std::vector<std::string> wires;
|
|
std::string name;
|
|
bool inComponent;
|
|
bool inConnection;
|
|
bool inSingleAutomaticConnection;
|
|
bool inBus;
|
|
|
|
ComdelContext(std::string name, bool inComponent, bool inConnection, bool inSingleAutomaticConnection, bool inBus)
|
|
: name(name), inComponent(inComponent), inConnection(inConnection), inSingleAutomaticConnection(inSingleAutomaticConnection), inBus(inBus)
|
|
{}
|
|
|
|
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;
|
|
}
|
|
|
|
};
|
|
|
|
class SchemaCreator
|
|
{
|
|
std::vector<ComdelContext> context;
|
|
|
|
std::string name;
|
|
std::string libraryInfo;
|
|
std::string header;
|
|
std::string componentDirectory;
|
|
std::optional<std::string> componentHeader = nullopt;
|
|
std::vector<AddressSpace> addressSpaces;
|
|
std::vector<Component> components;
|
|
std::vector<Bus> buses;
|
|
std::vector<Connection> connections;
|
|
std::map<std::string, std::string> messages;
|
|
|
|
|
|
std::vector<SourceError> errors;
|
|
std::vector<FunctionValidator*> validators;
|
|
|
|
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);
|
|
std::optional<Wire> loadWire(WireNode node);
|
|
std::optional<Pin> loadPin(PinNode pins);
|
|
PinConnection loadPinConnection(PinConnectionNode node);
|
|
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);
|
|
|
|
std::optional<Attribute> createMemoryAttribute();
|
|
|
|
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) {
|
|
if(!this->context.empty()) {
|
|
this->context.push_back(current());
|
|
current().name = name;
|
|
} else {
|
|
ComdelContext con(name, false, false, false, false);
|
|
push(con);
|
|
}
|
|
}
|
|
ComdelContext ¤t() {
|
|
return this->context[this->context.size() - 1];
|
|
}
|
|
void pop() {
|
|
this->context.pop_back();
|
|
}
|
|
|
|
public:
|
|
SchemaCreator(std::vector<FunctionValidator*> validators);
|
|
|
|
std::vector<SourceError> getErrors() {
|
|
return errors;
|
|
}
|
|
|
|
std::optional<Library> loadLibrary(LibraryNode node);
|
|
|
|
Schema* loadSchema(SchemaNode node, Library &library);
|
|
|
|
vector <Enumeration> createWireEnumeration(vector<Value> vector1);
|
|
|
|
std::optional<Popup> createMemoryPopup();
|
|
};
|
|
|
|
} // namespace domain
|
|
|
|
#endif // DOMAIN_COMDEL_GENERATOR_H
|