Refactored state
This commit is contained in:
1 parent
9e2b0f6c3c
commit
d6c1023df2
23 files changed
+697
-215
No files matched your search
@@ -9,10 +9,10 @@ AddressSpace::AddressSpace(std::string name, long long start, long long end):
|
||||
std::string AddressSpace::getName() {
|
||||
return name;
|
||||
}
|
||||
long long AddressSpace::getStart() {
|
||||
long long AddressSpace::getStart() const {
|
||||
return start;
|
||||
}
|
||||
long long AddressSpace::getEnd() {
|
||||
long long AddressSpace::getEnd() const {
|
||||
return end;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ public:
|
||||
AddressSpace(std::string name, long long start, long long end);
|
||||
|
||||
std::string getName();
|
||||
long long getStart();
|
||||
long long getEnd();
|
||||
long long getStart() const;
|
||||
long long getEnd() const;
|
||||
|
||||
bool contains(long long int address);
|
||||
bool contains(long long int start, long long int end);
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace domain {
|
||||
|
||||
Wire::Wire(std::string name, WireType type, int width, bool hidden, bool hasTermination, long long ifUnterminated)
|
||||
: name(name), type(type), width(width), hidden(hidden), hasTermination(hasTermination), ifUnterminated(ifUnterminated)
|
||||
Wire::Wire(std::string name, WireType type, int width, bool hidden, bool hasTerminate, Value terminateWith)
|
||||
: name(name), type(type), width(width), hidden(hidden), hasTerminate(hasTerminate), terminateWith(terminateWith)
|
||||
{}
|
||||
|
||||
std::string Wire::getName() {
|
||||
@@ -15,18 +15,17 @@ int Wire::getWidth() {
|
||||
bool Wire::isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
bool Wire::getHasTermination() {
|
||||
return hasTermination;
|
||||
|
||||
bool Wire::hasTerminateWith() {
|
||||
return hasTerminate;
|
||||
}
|
||||
long long Wire::getIfUnterminated() {
|
||||
return ifUnterminated;
|
||||
Value Wire::getTerminateWith() {
|
||||
return terminateWith;
|
||||
}
|
||||
Wire::WireType Wire::getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Bus::Bus(std::string name, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires, std::optional<Display> display)
|
||||
: name(name), tooltip(tooltip), type(type), count(count), wires(wires), display(display)
|
||||
{}
|
||||
|
||||
+6
-5
@@ -2,6 +2,7 @@
|
||||
#define DOMAIN_BUS_H
|
||||
|
||||
#include "display.h"
|
||||
#include "value.h"
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
@@ -26,17 +27,17 @@ private:
|
||||
WireType type;
|
||||
int width;
|
||||
bool hidden;
|
||||
bool hasTermination;
|
||||
long long ifUnterminated;
|
||||
bool hasTerminate;
|
||||
Value terminateWith;
|
||||
|
||||
public:
|
||||
Wire(std::string name, WireType type, int width, bool hidden, bool hasTermination, long long ifUnterminated);
|
||||
Wire(std::string name, WireType type, int width, bool hidden, bool hasTerminate, Value terminateWith);
|
||||
|
||||
std::string getName();
|
||||
int getWidth();
|
||||
bool isHidden();
|
||||
bool getHasTermination();
|
||||
long long getIfUnterminated();
|
||||
bool hasTerminateWith();
|
||||
Value getTerminateWith();
|
||||
WireType getType();
|
||||
};
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
Connection connection;
|
||||
WireInstance *wire;
|
||||
|
||||
virtual ~ConnectionInstance() = default;
|
||||
|
||||
std::vector<InstanceAttribute*> attributes;
|
||||
|
||||
ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute*> attributes, WireInstance *wire, Connection connection);
|
||||
|
||||
@@ -174,7 +174,7 @@ std::optional<Bus> SchemaCreator::loadBus(BusNode node)
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
auto type = toType(node.type);
|
||||
auto type = toType(node.type.value);
|
||||
|
||||
if(!node.tooltip && type == Bus::REGULAR) {
|
||||
errors.push_back(SourceError{node.span, "missing @tooltip"});
|
||||
@@ -392,7 +392,7 @@ std::optional<Component> SchemaCreator::loadComponent(ComponentNode node)
|
||||
}
|
||||
std::string source = node.source->asString();
|
||||
|
||||
Component::ComponentType type = toType(node.type);
|
||||
Component::ComponentType type = toType(node.type.value);
|
||||
|
||||
std::vector<Attribute> attributes;
|
||||
for(auto& a: node.attributes) {
|
||||
@@ -457,18 +457,18 @@ std::optional<Component> SchemaCreator::loadComponent(ComponentNode node)
|
||||
std::optional<Wire> SchemaCreator::loadWire(WireNode node) {
|
||||
return Wire(
|
||||
node.name.value,
|
||||
toType(node.type),
|
||||
toType(node.type.value),
|
||||
node.size.value,
|
||||
node.hidden,
|
||||
node.hasTermination,
|
||||
node.isUnterminated
|
||||
node.hasTerminateWith,
|
||||
toType(node.terminateWith)
|
||||
);
|
||||
}
|
||||
|
||||
optional<Pin> SchemaCreator::loadPin(PinNode node)
|
||||
{
|
||||
std::string name = node.name.value;
|
||||
Pin::PinType type = toType(node.type);
|
||||
Pin::PinType type = toType(node.type.value);
|
||||
|
||||
if(!node.tooltip) {
|
||||
errors.push_back(SourceError{node.span, "missing @tooltip"});
|
||||
@@ -559,7 +559,7 @@ std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node)
|
||||
PinConnection SchemaCreator::loadPinConnection(PinConnectionNode node)
|
||||
{
|
||||
std::string message = node.message.asString();
|
||||
PinConnection::ConnectionType type = toType(node.type);
|
||||
PinConnection::ConnectionType type = toType(node.type.value);
|
||||
return PinConnection(message, type);
|
||||
}
|
||||
|
||||
@@ -606,7 +606,7 @@ std::optional<Attribute> SchemaCreator::loadAttribute(AttributeNode node)
|
||||
|
||||
std::optional<Popup> SchemaCreator::loadPopup(PopupNode node, std::string name, Value::ValueType type)
|
||||
{
|
||||
auto popupType = toType(*node.type);
|
||||
auto popupType = toType(node.type.value().value);
|
||||
|
||||
pushAdditional(name);
|
||||
|
||||
@@ -678,7 +678,7 @@ std::optional<Rule> SchemaCreator::loadRule(RuleNode node)
|
||||
for(auto& stmt: node.statements) {
|
||||
auto condition = loadCondition(stmt.condition);
|
||||
if(condition) {
|
||||
statements.push_back(IfStatement(*condition, Action(toType(stmt.action.type), stmt.action.message.asString())));
|
||||
statements.push_back(IfStatement(*condition, Action(toType(stmt.action.type.value), stmt.action.message.asString())));
|
||||
} else {
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
@@ -137,4 +137,23 @@ Value Value::fromNull() {
|
||||
return val;
|
||||
}
|
||||
|
||||
std::string Value::stringify() {
|
||||
switch (type) {
|
||||
case INT:
|
||||
return std::to_string(intValue);
|
||||
case BOOL:
|
||||
return boolValue ? "true" : "false";
|
||||
case STRING:
|
||||
return "\"" + stringValue + "\"";
|
||||
case NIL:
|
||||
return "null";
|
||||
case WIRE_REFERENCE:
|
||||
case ADDRESS_SPACE_REFERENCE:
|
||||
case ATTRIBUTE_REFERENCE:
|
||||
return reference;
|
||||
default:
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace domain
|
||||
@@ -55,6 +55,8 @@ public:
|
||||
void setBool(bool value);
|
||||
void setReference(std::string value);
|
||||
|
||||
std::string stringify();
|
||||
|
||||
static Value fromInt(long long value);
|
||||
static Value fromString(std::string value);
|
||||
static Value fromBool(bool value);
|
||||
|
||||
Reference in new issue
Block a user