Added support for memory attribute

This commit is contained in:
Borna Rajković committed 2022-05-15 23:55:03 +02:00
1 parent bb423c2184
commit 59b19062ff
14 files changed
+293 -70

No files matched your search

+9 -2
View File
@@ -94,9 +94,16 @@ ValueNode ValueNode::ofNull() {
return value;
}
ValueNode ValueNode::ofWire(std::string _value) {
ValueNode ValueNode::ofWire(std::optional<std::string> _value) {
ValueNode value;
value.type = EnumNode(WIRE);
value.identifierValue = std::optional<std::string>(_value);
value.identifierValue = _value;
return value;
}
ValueNode ValueNode::ofMemory(std::optional<std::string> _value) {
ValueNode value;
value.type = EnumNode(MEMORY);
value.identifierValue = _value;
return value;
}
+4 -2
View File
@@ -77,6 +77,7 @@ public:
BOOL,
WIRE,
IDENTIFIER,
MEMORY,
NIL,
};
@@ -88,7 +89,7 @@ private:
std::optional<std::string> identifierValue;
public:
ValueNode() = default;;
ValueNode() = default;
ValueType getType() {
return type.value;
@@ -104,8 +105,9 @@ public:
static ValueNode ofInt(long long _value);
static ValueNode ofString(std::string _value);
static ValueNode ofIdentifier(std::string _value);
static ValueNode ofMemory(std::optional<std::string> _value);
static ValueNode ofNull();
static ValueNode ofWire(std::string _value);
static ValueNode ofWire(std::optional<std::string> _value);
};
struct ConditionNode
+12 -2
View File
@@ -438,7 +438,7 @@ PResult<ComponentNode> ComdelParser::parseComponent()
ASSIGN_OR_RETURN_IF_ERR(component.name, parseIdentifier());
auto type = parseComponentType();
ASSIGN_OR_RETURN_IF_ERR(component.type, parseComponentType());
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
@@ -853,13 +853,23 @@ PResult<AttributeNode> ComdelParser::parseAttribute() {
} else {
return unexpected();
}
} else if(attribute.type == ValueNode::MEMORY) {
if(check(TokenType::IDENTIFIER)) {
auto identifier = parseIdentifier();
attribute.defaultValue = ValueNode::ofMemory(identifier->value);
} else if(check(TokenType::NIL)) {
bump();
attribute.defaultValue = ValueNode::ofMemory(std::nullopt);
} else {
return unexpected();
}
} else if(attribute.type == ValueNode::WIRE) {
if(check(TokenType::IDENTIFIER)) {
auto identifier = parseIdentifier();
attribute.defaultValue = ValueNode::ofWire(identifier->value);
} else if(check(TokenType::NIL)) {
bump();
attribute.defaultValue = ValueNode::ofNull();
attribute.defaultValue = ValueNode::ofWire(std::nullopt);
} else {
return unexpected();
}