#ifndef DOMAIN_COMDEL_GENERATOR_H #define DOMAIN_COMDEL_GENERATOR_H #include "library.h" #include "schema.h" #include #include #include #include namespace domain { struct ComdelContext { std::vector attributes; std::vector wires; std::string name; bool inComponent; bool inConnection; bool inBus; ComdelContext(std::string name, bool inComponent, bool inConnection, bool inBus) : name(name), inComponent(inComponent), inConnection(inConnection), 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 context; std::string name; std::string libraryInfo; std::string header; std::string componentDirectory; std::vector addressSpaces; std::vector components; std::vector buses; std::vector connections; std::map messages; std::vector errors; std::vector signatures; std::optional loadAddressSpace(AddressSpaceNode node); std::optional loadComponent(ComponentNode node); std::optional loadAttribute(AttributeNode node); std::optional loadRule(RuleNode node); std::optional loadCondition(ConditionNode node); std::optional loadPopup(PopupNode node, std::string name, Value::ValueType type); std::optional loadDisplay(DisplayNode node); std::optional loadWire(WireNode node); std::optional loadPin(PinNode pins); PinConnection loadPinConnection(PinConnectionNode node); 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); std::optional getBus(std::string name) { for(auto &bus: buses) { if(bus.getName() == name) { return bus; } } return std::nullopt; } std::optional 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); push(con); } } ComdelContext ¤t() { return this->context[this->context.size() - 1]; } void pop() { this->context.pop_back(); } public: SchemaCreator(std::vector signatures); std::vector getErrors() { return errors; } std::optional loadLibrary(LibraryNode node); Schema* loadSchema(SchemaNode node, Library &library); }; } // namespace domain #endif // DOMAIN_COMDEL_GENERATOR_H